mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-out] Improve handling of samplerCubeArrayShadow
Adds checks that it isn't used in an unsupported function and emits the depth_ref as a separate argument.
This commit is contained in:
committed by
Dzmitry Malyshau
parent
63a8463edd
commit
6a57559070
@@ -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 => (),
|
||||
|
||||
12
tests/in/cubeArrayShadow.wgsl
Normal file
12
tests/in/cubeArrayShadow.wgsl
Normal file
@@ -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<f32> {
|
||||
let frag_ls = vec4<f32>(1., 1., 2., 1.).xyz;
|
||||
let a = textureSampleCompare(point_shadow_textures, point_shadow_textures_sampler, frag_ls, i32(1), 1.);
|
||||
|
||||
return vec4<f32>(a, 1., 1., 1.);
|
||||
}
|
||||
17
tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl
Normal file
17
tests/out/glsl/cubeArrayShadow.fragment.Fragment.glsl
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user