Skip to content
Permalink
Browse files

Set the correct Angle GLSL output when using WebGL 2

  • Loading branch information
MortimerGoro committed Nov 13, 2017
1 parent bc58e18 commit c22674481b04a017576174376b4258edde1c4127
Showing with 99 additions and 621 deletions.
  1. +23 −4 components/canvas/webgl_thread.rs
  2. +11 −0 components/canvas_traits/webgl.rs
  3. +3 −1 components/script/dom/bindings/trace.rs
  4. +4 −2 components/script/dom/webglrenderingcontext.rs
  5. +32 −11 components/script/dom/webglshader.rs
  6. +3 −11 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-as-return-value.html.ini
  7. +0 −7 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-assign-constructor.html.ini
  8. +3 −5 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-assign.html.ini
  9. +3 −8 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-complex-indexing.html.ini
  10. +0 −6 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-element-increment.html.ini
  11. +3 −5 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-equality.html.ini
  12. +3 −5 .../wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/array-in-complex-expression.html.ini
  13. +0 −34 ...ozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/bool-type-cast-bug-uint-ivec-uvec.html.ini
  14. +0 −433 ...lla/meta/webgl/conformance-2.0.0/conformance2/glsl3/compound-assignment-type-combination.html.ini
  15. +3 −8 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/const-array-init.html.ini
  16. +0 −4 ...s/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/no-attribute-vertex-shader.html.ini
  17. +6 −0 .../wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/texture-offset-out-of-range.html.ini
  18. +0 −22 ...eta/webgl/conformance-2.0.0/conformance2/glsl3/texture-offset-uniform-texture-coordinate.html.ini
  19. +0 −48 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/glsl3/tricky-loop-conditions.html.ini
  20. +2 −4 tests/wpt/mozilla/meta/webgl/conformance-2.0.0/conformance2/rendering/attrib-type-match.html.ini
  21. +0 −3 ...lla/meta/webgl/conformance-2.0.0/conformance2/rendering/rendering-sampling-feedback-loop.html.ini
@@ -91,13 +91,18 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
match msg {
WebGLMsg::CreateContext(version, size, attributes, result_sender) => {
let result = self.create_webgl_context(version, size, attributes);
result_sender.send(result.map(|(id, limits, share_mode)|
result_sender.send(result.map(|(id, limits, share_mode)| {
let ctx = Self::make_current_if_needed(id, &self.contexts, &mut self.bound_context_id)
.expect("WebGLContext not found");
let glsl_version = Self::get_glsl_version(ctx);

WebGLCreateContextResult {
sender: WebGLMsgSender::new(id, webgl_chan.clone()),
limits: limits,
share_mode: share_mode,
limits,
share_mode,
glsl_version,
}
)).unwrap();
})).unwrap();
},
WebGLMsg::ResizeContext(ctx_id, size, sender) => {
self.resize_webgl_context(ctx_id, size, sender);
@@ -519,6 +524,20 @@ impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> WebGLThread<VR,
byte_swap(&mut pixels);
pixels
}

/// Gets the GLSL Version supported by a GLContext.
fn get_glsl_version(context: &GLContextWrapper) -> WebGLSLVersion {
let version = context.gl().get_string(gl::SHADING_LANGUAGE_VERSION);
// Fomat used by SHADING_LANGUAGE_VERSION query : major.minor[.release] [vendor info]
let mut values = version.split(&['.', ' '][..]);
let major = values.next().and_then(|v| v.parse::<u32>().ok()).unwrap_or(1);
let minor = values.next().and_then(|v| v.parse::<u32>().ok()).unwrap_or(20);

WebGLSLVersion {
major,
minor,
}
}
}

impl<VR: WebVRRenderHandler + 'static, OB: WebGLThreadObserver> Drop for WebGLThread<VR, OB> {
@@ -63,6 +63,8 @@ pub struct WebGLCreateContextResult {
pub limits: GLLimits,
/// How the WebGLContext is shared with WebRender.
pub share_mode: WebGLContextShareMode,
/// The GLSL version supported by the context.
pub glsl_version: WebGLSLVersion
}

#[derive(Clone, Copy, Deserialize, MallocSizeOf, Serialize)]
@@ -84,6 +86,15 @@ pub enum WebGLVersion {
WebGL2,
}

/// Defines the GLSL version supported by the WebGL backend contexts.
#[derive(Clone, Copy, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
pub struct WebGLSLVersion {
/// Major GLSL version
pub major: u32,
/// Minor GLSL version
pub minor: u32,
}

/// Helper struct to send WebGLCommands to a specific WebGLContext.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct WebGLMsgSender {
@@ -33,8 +33,9 @@ use app_units::Au;
use canvas_traits::canvas::{CanvasGradientStop, LinearGradientStyle, RadialGradientStyle};
use canvas_traits::canvas::{CompositionOrBlending, LineCapStyle, LineJoinStyle, RepetitionStyle};
use canvas_traits::webgl::{WebGLBufferId, WebGLFramebufferId, WebGLProgramId, WebGLRenderbufferId};
use canvas_traits::webgl::{WebGLChan, WebGLContextShareMode, WebGLError, WebGLPipeline, WebGLMsgSender, WebGLVersion};
use canvas_traits::webgl::{WebGLChan, WebGLContextShareMode, WebGLError, WebGLPipeline, WebGLMsgSender};
use canvas_traits::webgl::{WebGLReceiver, WebGLSender, WebGLShaderId, WebGLTextureId, WebGLVertexArrayId};
use canvas_traits::webgl::{WebGLSLVersion, WebGLVersion};
use cssparser::RGBA;
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
use dom::abstractworker::SharedRt;
@@ -412,6 +413,7 @@ unsafe_no_jsmanaged_fields!(WebGLShaderId);
unsafe_no_jsmanaged_fields!(WebGLTextureId);
unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
unsafe_no_jsmanaged_fields!(WebGLVersion);
unsafe_no_jsmanaged_fields!(WebGLSLVersion);
unsafe_no_jsmanaged_fields!(MediaList);
unsafe_no_jsmanaged_fields!(WebVRGamepadHand);
unsafe_no_jsmanaged_fields!(ScriptToConstellationChan);
@@ -4,7 +4,7 @@

use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
use canvas_traits::canvas::{byte_swap, multiply_u8_pixel};
use canvas_traits::webgl::{WebGLContextShareMode, WebGLCommand, WebGLError, WebGLVersion};
use canvas_traits::webgl::{WebGLContextShareMode, WebGLCommand, WebGLError, WebGLVersion, WebGLSLVersion};
use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSender, WebGLParameter, WebVRCommand};
use canvas_traits::webgl::DOMToTextureCommand;
use canvas_traits::webgl::WebGLError::*;
@@ -187,6 +187,7 @@ pub struct WebGLRenderingContext {
webrender_image: Cell<Option<webrender_api::ImageKey>>,
share_mode: WebGLContextShareMode,
webgl_version: WebGLVersion,
glsl_version: WebGLSLVersion,
#[ignore_malloc_size_of = "Defined in offscreen_gl_context"]
limits: GLLimits,
canvas: Dom<HTMLCanvasElement>,
@@ -236,6 +237,7 @@ impl WebGLRenderingContext {
webrender_image: Cell::new(None),
share_mode: ctx_data.share_mode,
webgl_version,
glsl_version: ctx_data.glsl_version,
limits: ctx_data.limits,
canvas: Dom::from_ref(canvas),
last_error: Cell::new(None),
@@ -1914,7 +1916,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn CompileShader(&self, shader: Option<&WebGLShader>) {
if let Some(shader) = shader {
shader.compile(self.webgl_version, &self.extension_manager)
shader.compile(self.webgl_version, self.glsl_version, &self.extension_manager)
}
}

@@ -4,8 +4,8 @@

// https://www.khronos.org/registry/webgl/specs/latest/1.0/webgl.idl
use angle::hl::{BuiltInResources, Output, ShaderValidator};
use canvas_traits::webgl::{WebGLSLVersion, WebGLVersion};
use canvas_traits::webgl::{webgl_channel, WebGLCommand, WebGLMsgSender, WebGLParameter, WebGLResult, WebGLShaderId};
use canvas_traits::webgl::WebGLVersion;
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::WebGLShaderBinding;
use dom::bindings::reflector::reflect_dom_object;
@@ -40,12 +40,6 @@ pub struct WebGLShader {
renderer: WebGLMsgSender,
}

#[cfg(not(target_os = "android"))]
const SHADER_OUTPUT_FORMAT: Output = Output::Glsl;

#[cfg(target_os = "android")]
const SHADER_OUTPUT_FORMAT: Output = Output::Essl;

static GLSLANG_INITIALIZATION: Once = ONCE_INIT;

impl WebGLShader {
@@ -100,7 +94,12 @@ impl WebGLShader {
}

/// glCompileShader
pub fn compile(&self, version: WebGLVersion, ext: &WebGLExtensions) {
pub fn compile(
&self,
webgl_version: WebGLVersion,
glsl_version: WebGLSLVersion,
ext: &WebGLExtensions
) {
if self.compilation_status.get() != ShaderCompilationStatus::NotCompiled {
debug!("Compiling already compiled shader {}", self.id);
}
@@ -109,15 +108,37 @@ impl WebGLShader {
let mut params = BuiltInResources::default();
params.FragmentPrecisionHigh = 1;
params.OES_standard_derivatives = ext.is_enabled::<OESStandardDerivatives>() as i32;
let validator = match version {
let validator = match webgl_version {
WebGLVersion::WebGL1 => {
let output_format = if cfg!(any(target_os = "android", target_os = "ios")) {
Output::Essl
} else {
Output::Glsl
};
ShaderValidator::for_webgl(self.gl_type,
SHADER_OUTPUT_FORMAT,
output_format,
&params).unwrap()
},
WebGLVersion::WebGL2 => {
let output_format = if cfg!(any(target_os = "android", target_os = "ios")) {
Output::Essl
} else {
match (glsl_version.major, glsl_version.minor) {
(1, 30) => Output::Glsl130,
(1, 40) => Output::Glsl140,
(1, 50) => Output::Glsl150Core,
(3, 30) => Output::Glsl330Core,
(4, 0) => Output::Glsl400Core,
(4, 10) => Output::Glsl410Core,
(4, 20) => Output::Glsl420Core,
(4, 30) => Output::Glsl430Core,
(4, 40) => Output::Glsl440Core,
(4, _) => Output::Glsl450Core,
_ => Output::Glsl140
}
};
ShaderValidator::for_webgl2(self.gl_type,
SHADER_OUTPUT_FORMAT,
output_format,
&params).unwrap()
},
};
@@ -1,13 +1,5 @@
[array-as-return-value.html]
[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Expression where a returned array is not used]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Expression where a returned array is compared]
expected: FAIL

[WebGL test #2: [unexpected fragment shader compile status\] (expected: true) Expression where a returned array is returned again]
expected: FAIL

[WebGL test #3: [unexpected fragment shader compile status\] (expected: true) Expression where a returned array is passed as a parameter]
expected: FAIL
expected: ERROR
[Overall test]
expected: NOTRUN

This file was deleted.

@@ -1,7 +1,5 @@
[array-assign.html]
[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Arrays of integers]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Arrays of structs]
expected: FAIL
expected: ERROR
[Overall test]
expected: NOTRUN

@@ -1,10 +1,5 @@
[array-complex-indexing.html]
[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Test indexing a variable assignment: (a = b)[0\]]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Test indexing a function return with a side-effect: (functionReturnArray())[0\]]
expected: FAIL

[WebGL test #2: [unexpected fragment shader compile status\] (expected: true) Test indexing an array initialization: (float[3\](2.0, 1.0, 0.0))[0\]]
expected: FAIL
expected: ERROR
[Overall test]
expected: NOTRUN

@@ -3,9 +3,3 @@
[Overall test]
expected: NOTRUN

[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Increment an element of a vector array]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Increment an element of a vector array]
expected: FAIL

@@ -1,7 +1,5 @@
[array-equality.html]
[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Arrays of integers]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Arrays of structs]
expected: FAIL
expected: ERROR
[Overall test]
expected: NOTRUN

@@ -1,7 +1,5 @@
[array-in-complex-expression.html]
[WebGL test #0: [unexpected fragment shader compile status\] (expected: true) Expression where an array is returned from a function call in an operand of a ternary operator that doesn't get evaluated]
expected: FAIL

[WebGL test #1: [unexpected fragment shader compile status\] (expected: true) Expression where first operand of a sequence operator has side effects which affect the second operand that returns an array]
expected: FAIL
expected: ERROR
[Overall test]
expected: NOTRUN

This file was deleted.

0 comments on commit c226744

Please sign in to comment.
You can’t perform that action at this time.