Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Skip invariant for gl_FragCoord on WebGL2 #2254

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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