Skip to content

Commit

Permalink
feat: Add test
Browse files Browse the repository at this point in the history
- Write warn message if `ClipDistance` and `CullDistance` are used on unsupported version
  • Loading branch information
REASY committed Feb 1, 2023
1 parent bb0ce83 commit cf30dd6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,21 @@ impl<'a, W: Write> Writer<'a, W> {
crate::BuiltIn::ClipDistance
| crate::BuiltIn::CullDistance => {
if self.options.version.is_es() {
// According to https://github.com/KhronosGroup/GLSL/issues/132
/* > We agreed that gl_ClipDistance and gl_CullDistance, and related language,
should not appear in the ESSL spec since it's not part of OpenGL ES 3.2.
*/
if let Version::Embedded {
version,
is_webgl: _,
} = self.options.version
{
if version <= 320 {
log::warn!(
"{:?} is not part of OpenGL ES <= 3.2",
builtin);
}
}
continue;
}
}
Expand Down Expand Up @@ -2087,7 +2102,7 @@ impl<'a, W: Write> Writer<'a, W> {
.contains(WriterFlags::FORCE_POINT_SIZE)
&& !has_point_size
{
writeln!(self.out, "gl_PointSize = 1.0;",)?;
writeln!(self.out, "gl_PointSize = 1.0;")?;
write!(self.out, "{level}")?;
}
writeln!(self.out, "return;")?;
Expand Down
11 changes: 11 additions & 0 deletions tests/in/force_point_size_vertex_shader_webgl.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: 16),
binding_map: {},
zero_initialize_workgroup_memory: true,
),
)
14 changes: 14 additions & 0 deletions tests/in/force_point_size_vertex_shader_webgl.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// AUTHOR: REASY
// ISSUE: https://github.com/gfx-rs/wgpu/issues/3179
// FIX: https://github.com/gfx-rs/wgpu/pull/3440
@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(i32(in_vertex_index) - 1);
let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
return vec4<f32>(x, y, 0.0, 1.0);
}

@fragment
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#version 300 es

precision highp float;
precision highp int;

layout(location = 0) out vec4 _fs2p_location0;

void main() {
_fs2p_location0 = vec4(1.0, 0.0, 0.0, 1.0);
return;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 300 es

precision highp float;
precision highp int;


void main() {
uint in_vertex_index = uint(gl_VertexID);
float x = float((int(in_vertex_index) - 1));
float y = float(((int((in_vertex_index & 1u)) * 2) - 1));
gl_Position = vec4(x, y, 0.0, 1.0);
gl_PointSize = 1.0;
return;
}

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

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

0 comments on commit cf30dd6

Please sign in to comment.