nir: add support for clamping in nir_lower_tex_shadow

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 <pavel.ondracka@gmail.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33140>
This commit is contained in:
Pavel Ondračka
2025-01-18 09:51:59 +01:00
committed by Marge Bot
parent 9091bb9fab
commit ea6ccb8628
4 changed files with 17 additions and 6 deletions
+2 -1
View File
@@ -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 {
/**
+7 -2
View File
@@ -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,
+6 -2
View File
@@ -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) {
@@ -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);