From ea6ccb862877d6cf5cab66953691956d91906d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Ondra=C4=8Dka?= Date: Sat, 18 Jan 2025 09:51:59 +0100 Subject: [PATCH] nir: add support for clamping in nir_lower_tex_shadow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From OpenGL 4.6 - 8.23.1 Depth Texture Comparison Mode Let Dt be the depth texture value and St be the stencil index component. If there is no stencil component, the value of St is undefined. Let Dref be the reference value, provided by the shader’s texture lookup function. If the texture’s internal format indicates a fixed-point depth texture, then Dt and Dref are clamped to the range [0, 1]; otherwise no clamping is performed. Signed-off-by: Pavel Ondračka Reviewed-by: Lucas Stach Part-of: --- src/compiler/nir/nir.h | 3 ++- src/compiler/nir/nir_lower_tex_shadow.c | 9 +++++++-- src/gallium/drivers/d3d12/d3d12_compiler.cpp | 8 ++++++-- src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index e507ec6aa8c..813e6bd8e6f 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6472,7 +6472,8 @@ bool nir_lower_tex_shadow(nir_shader *s, unsigned n_states, enum compare_func *compare_func, - nir_lower_tex_shadow_swizzle *tex_swizzles); + nir_lower_tex_shadow_swizzle *tex_swizzles, + bool is_fixed_point_format); typedef struct nir_lower_image_options { /** diff --git a/src/compiler/nir/nir_lower_tex_shadow.c b/src/compiler/nir/nir_lower_tex_shadow.c index ec077a60d97..7e772f5570c 100644 --- a/src/compiler/nir/nir_lower_tex_shadow.c +++ b/src/compiler/nir/nir_lower_tex_shadow.c @@ -69,6 +69,7 @@ typedef struct { unsigned n_states; enum compare_func *compare_func; nir_lower_tex_shadow_swizzle *tex_swizzles; + bool is_fixed_point_format; } sampler_state; static nir_def * @@ -106,6 +107,9 @@ nir_lower_tex_shadow_impl(nir_builder *b, nir_instr *instr, void *options) if (proj_index >= 0) cmp = nir_fmul(b, cmp, nir_frcp(b, tex->src[proj_index].src.ssa)); + if (state->is_fixed_point_format) + cmp = nir_fsat(b, cmp); + nir_def *result = nir_compare_func(b, sampler_binding < state->n_states ? state->compare_func[sampler_binding] : COMPARE_FUNC_ALWAYS, @@ -142,9 +146,10 @@ bool nir_lower_tex_shadow(nir_shader *s, unsigned n_states, enum compare_func *compare_func, - nir_lower_tex_shadow_swizzle *tex_swizzles) + nir_lower_tex_shadow_swizzle *tex_swizzles, + bool is_fixed_point_format) { - sampler_state state = { n_states, compare_func, tex_swizzles }; + sampler_state state = { n_states, compare_func, tex_swizzles, is_fixed_point_format }; bool result = nir_shader_lower_instructions(s, diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp index 02b7859c805..0b0bfdfca47 100644 --- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp +++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp @@ -1125,8 +1125,12 @@ select_shader_variant(struct d3d12_selection_context *sel_ctx, d3d12_shader_sele STATIC_ASSERT(sizeof(dxil_texture_swizzle_state) == sizeof(nir_lower_tex_shadow_swizzle)); - NIR_PASS_V(new_nir_variant, nir_lower_tex_shadow, key.n_texture_states, - key.sampler_compare_funcs, (nir_lower_tex_shadow_swizzle *)key.swizzle_state); + NIR_PASS_V(new_nir_variant, + nir_lower_tex_shadow, + key.n_texture_states, + key.sampler_compare_funcs, + (nir_lower_tex_shadow_swizzle *) key.swizzle_state, + false); } if (key.stage == PIPE_SHADER_FRAGMENT) { diff --git a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c index 692bfff6d49..1d03c2a1c35 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c +++ b/src/gallium/drivers/etnaviv/etnaviv_nir_lower_texture.c @@ -42,7 +42,8 @@ etna_nir_lower_texture(nir_shader *s, struct etna_shader_key *key) if (key->has_sample_tex_compare) NIR_PASS(progress, s, nir_lower_tex_shadow, key->num_texture_states, key->tex_compare_func, - key->tex_swizzle); + key->tex_swizzle, + false); NIR_PASS(progress, s, nir_shader_instructions_pass, lower_txs, nir_metadata_control_flow, NULL);