pco: restrict shadow sampler comparator clamping to unorm formats

Only clamp shadow sampler comparators for "unsigned normalized
fixed-point format[s]" as per the Vulkan spec.

Fixes: 69a56d33de ("pco: Fix for shadow sampler comparison not clamping the compare value")
Reported-by: Georg Lehmann <dadschoorse@gmail.com>
Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39389>
This commit is contained in:
Simon Perretta 2026-01-16 11:59:08 +00:00 committed by Marge Bot
parent adec216eb0
commit 52ddc40a75
2 changed files with 20 additions and 4 deletions

View file

@ -429,9 +429,6 @@ static nir_def *lower_tex_shadow(nir_builder *b,
{
nir_def *result_comps[NIR_MAX_VEC_COMPONENTS];
/* Need to clamp the comparator to the range 0.0 - 1.0 */
comparator = nir_fsat(b, comparator);
for (unsigned u = 0; u < data->num_components; ++u) {
result_comps[u] =
nir_alphatst_pco(b, nir_channel(b, data, u), comparator, compare_op);
@ -745,6 +742,21 @@ static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
.binding = smp_binding,
.component = PCO_SAMPLER_META_COMPARE_OP);
/*
* From the Vulkan 1.4.339 spec, 17.2.4. Depth Compare Operation:
*
* "If the image being sampled has an unsigned normalized fixed-point
* format, then Dref is clamped to [0,1] before the compare operation."
*
* -> Clamp the comparator to the range 0.0 - 1.0 for unorm formats.
*/
nir_def *pck_info = nir_channel(b, tex_meta, PCO_IMAGE_META_PCK_INFO);
nir_def *is_unorm = nir_ubitfield_extract_imm(b, pck_info, 8, 1);
is_unorm = nir_ine_imm(b, is_unorm, 0);
comparator = nir_bcsel(b, is_unorm, nir_fsat(b, comparator), comparator);
result = lower_tex_shadow(b, result, comparator, compare_op);
}

View file

@ -135,8 +135,9 @@ static uint32_t setup_pck_info(VkFormat vk_format)
break;
}
/* Invalidate the format bits, but clear the rest so they can still be set. */
if (pck_format == ~0)
return pck_format;
pck_format = 0b11111;
uint32_t pck_info = pck_format;
if (split)
@ -148,6 +149,9 @@ static uint32_t setup_pck_info(VkFormat vk_format)
if (roundzero)
pck_info |= BITFIELD_BIT(7);
if (util_format_is_unorm(format))
pck_info |= BITFIELD_BIT(8);
return pck_info;
}