[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:
João Capucho
2021-09-21 16:57:37 +01:00
committed by Dzmitry Malyshau
parent 63a8463edd
commit 6a57559070
4 changed files with 62 additions and 4 deletions

View File

@@ -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 => (),

View 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.);
}

View 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;
}

View File

@@ -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() {