From 52ddc40a759c1a9a1002ecca6ba6c64b3b09ed66 Mon Sep 17 00:00:00 2001 From: Simon Perretta Date: Fri, 16 Jan 2026 11:59:08 +0000 Subject: [PATCH] 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: 69a56d33def ("pco: Fix for shadow sampler comparison not clamping the compare value") Reported-by: Georg Lehmann Signed-off-by: Simon Perretta Acked-by: Frank Binns Part-of: --- src/imagination/pco/pco_nir_tex.c | 18 +++++++++++++++--- src/imagination/vulkan/pvr_arch_tex_state.c | 6 +++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/imagination/pco/pco_nir_tex.c b/src/imagination/pco/pco_nir_tex.c index 5420f2b3d7d..8065189d3f7 100644 --- a/src/imagination/pco/pco_nir_tex.c +++ b/src/imagination/pco/pco_nir_tex.c @@ -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); } diff --git a/src/imagination/vulkan/pvr_arch_tex_state.c b/src/imagination/vulkan/pvr_arch_tex_state.c index f4544955f63..724616e6739 100644 --- a/src/imagination/vulkan/pvr_arch_tex_state.c +++ b/src/imagination/vulkan/pvr_arch_tex_state.c @@ -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; }