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