Skip to content

Commit

Permalink
Skip invariant for gl_FragCoord on WebGL2 (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
grovesNL authored Feb 16, 2023
1 parent dce689c commit f48b6bf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,11 +1264,27 @@ impl<'a, W: Write> Writer<'a, W> {
} => (location, interpolation, sampling),
crate::Binding::BuiltIn(built_in) => {
if let crate::BuiltIn::Position { invariant: true } = built_in {
writeln!(
self.out,
"invariant {};",
glsl_built_in(built_in, output, self.options.version.is_webgl())
)?;
match (self.options.version, self.entry_point.stage) {
(
Version::Embedded {
version: 300,
is_webgl: true,
},
ShaderStage::Fragment,
) => {
// `invariant gl_FragCoord` is not allowed in WebGL2 and possibly
// OpenGL ES in general (waiting on confirmation).
//
// See https://github.com/KhronosGroup/WebGL/issues/3518
}
_ => {
writeln!(
self.out,
"invariant {};",
glsl_built_in(built_in, output, self.options.version.is_webgl())
)?;
}
}
}
return Ok(());
}
Expand Down
11 changes: 11 additions & 0 deletions tests/in/invariant.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(
glsl: (
version: Embedded (
version: 300,
is_webgl: true
),
writer_flags: (bits: 0),
binding_map: {},
zero_initialize_workgroup_memory: true,
),
)
7 changes: 7 additions & 0 deletions tests/in/invariant.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@vertex
fn vs() -> @builtin(position) @invariant vec4<f32> {
return vec4<f32>(0.0);
}

@fragment
fn fs(@builtin(position) @invariant position: vec4<f32>) { }
11 changes: 11 additions & 0 deletions tests/out/glsl/invariant.frag_main.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 300 es

precision highp float;
precision highp int;


void main() {
vec4 position = gl_FragCoord;
return;
}

11 changes: 11 additions & 0 deletions tests/out/glsl/invariant.fs.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 300 es

precision highp float;
precision highp int;


void main() {
vec4 position = gl_FragCoord;
return;
}

12 changes: 12 additions & 0 deletions tests/out/glsl/invariant.vs.Vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 300 es

precision highp float;
precision highp int;

invariant gl_Position;

void main() {
gl_Position = vec4(0.0);
return;
}

1 change: 1 addition & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ fn convert_wgsl() {
),
("sprite", Targets::SPIRV),
("force_point_size_vertex_shader_webgl", Targets::GLSL),
("invariant", Targets::GLSL),
];

for &(name, targets) in inputs.iter() {
Expand Down

0 comments on commit f48b6bf

Please sign in to comment.