diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index bc46c3d0e2..9bba3c2414 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -1860,6 +1860,24 @@ impl<'a, W: Write> Writer<'a, W> { _ => unreachable!(), }; + if dim == crate::ImageDimension::Cube + && array_index.is_some() + && depth_ref.is_some() + { + match level { + crate::SampleLevel::Zero + | crate::SampleLevel::Exact(_) + | crate::SampleLevel::Gradient { .. } + | crate::SampleLevel::Bias(_) => { + return Err(Error::Custom(String::from( + "gsamplerCubeArrayShadow isn't supported in textureGrad, \ + textureLod or texture with bias", + ))) + } + crate::SampleLevel::Auto => {} + } + } + // textureLod on sampler2DArrayShadow and samplerCubeShadow does not exist in GLSL. // To emulate this, we will have to use textureGrad with a constant gradient of 0. let workaround_lod_array_shadow_as_grad = (array_index.is_some() @@ -1905,7 +1923,8 @@ impl<'a, W: Write> Writer<'a, W> { if array_index.is_some() { coord_dim += 1; } - if depth_ref.is_some() { + let cube_array_shadow = coord_dim == 4; + if depth_ref.is_some() && !cube_array_shadow { coord_dim += 1; } @@ -1916,12 +1935,21 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, ", ")?; self.write_expr(expr, ctx)?; } - if let Some(expr) = depth_ref { - write!(self.out, ", ")?; - self.write_expr(expr, ctx)?; + if !cube_array_shadow { + if let Some(expr) = depth_ref { + write!(self.out, ", ")?; + self.write_expr(expr, ctx)?; + } } write!(self.out, ")")?; + if cube_array_shadow { + if let Some(expr) = depth_ref { + write!(self.out, ", ")?; + self.write_expr(expr, ctx)?; + } + } + match level { // Auto needs no more arguments crate::SampleLevel::Auto => (), diff --git a/tests/in/cubeArrayShadow.wgsl b/tests/in/cubeArrayShadow.wgsl new file mode 100644 index 0000000000..a2a376564c --- /dev/null +++ b/tests/in/cubeArrayShadow.wgsl @@ -0,0 +1,12 @@ +[[group(0), binding(4)]] +var point_shadow_textures: texture_depth_cube_array; +[[group(0), binding(5)]] +var point_shadow_textures_sampler: sampler_comparison; + +[[stage(fragment)]] +fn fragment() -> [[location(0)]] vec4 { + let frag_ls = vec4(1., 1., 2., 1.).xyz; + let a = textureSampleCompare(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(1), 1.); + + return vec4(a, 1., 1., 1.); +} diff --git a/tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl b/tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl new file mode 100644 index 0000000000..57f8192813 --- /dev/null +++ b/tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl @@ -0,0 +1,17 @@ +#version 310 es +#extension GL_EXT_texture_cube_map_array : require + +precision highp float; +precision highp int; + +uniform highp samplerCubeArrayShadow _group_0_binding_4; + +layout(location = 0) out vec4 _fs2p_location0; + +void main() { + vec3 frag_ls = vec4(1.0, 1.0, 2.0, 1.0).xyz; + float a = texture(_group_0_binding_4, vec4(frag_ls, int(1)), 1.0); + _fs2p_location0 = vec4(a, 1.0, 1.0, 1.0); + return; +} + diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 7a8873f376..a712d7b331 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -505,6 +505,7 @@ fn convert_wgsl() { "texture-arg", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), + ("cubeArrayShadow", Targets::GLSL), ]; for &(name, targets) in inputs.iter() {