pco: fix clamping the array index when shaderImageGatherExtended is enabled

The array index value is a signed integer but the compiler was using
the unsigned version of the clamp helper function meaning the value
was not been clamped to 0 when its value was < 0.

Fix the following deqp test cases when shaderImageGatherExtended is enabled
dEQP-VK.glsl.texture_gather.basic.2d_array.*
dEQP-VK.glsl.texture_gather.offset.*.2d_array.*
dEQP-VK.glsl.texture_gather.offset_dynamic.*.2d_array.*
dEQP-VK.glsl.texture_gather.offsets.*.2d_array.*

Fixes: 854563f0f8 ("pco: fully switch over to common smp emission code")
Signed-off-by: Nick Hamilton <nick.hamilton@imgtec.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40687>
This commit is contained in:
Nick Hamilton 2026-04-15 15:11:28 +01:00 committed by Simon Perretta
parent 56b8dc92a9
commit b80a5f9b7d

View file

@ -661,7 +661,7 @@ static bool lower_tex(nir_builder *b, nir_tex_instr *tex, void *cb_data)
assert(array_index);
nir_def *array_max = usclib_tex_state_array_max(b, tex_state);
array_index = nir_uclamp(b, array_index, nir_imm_int(b, 0), array_max);
array_index = nir_iclamp(b, array_index, nir_imm_int(b, 0), array_max);
if (is_cube_array)
array_index = nir_imul_imm(b, array_index, 6);
@ -1183,7 +1183,7 @@ lower_image(nir_builder *b, nir_intrinsic_instr *intr, void *cb_data)
if (is_array) {
assert(array_index);
nir_def *array_max = usclib_tex_state_array_max(b, tex_state);
array_index = nir_uclamp(b, array_index, nir_imm_int(b, 0), array_max);
array_index = nir_iclamp(b, array_index, nir_imm_int(b, 0), array_max);
nir_def *tex_meta = nir_load_tex_meta_pco(b,
PCO_IMAGE_META_COUNT,
@ -1366,7 +1366,7 @@ lower_image(nir_builder *b, nir_intrinsic_instr *intr, void *cb_data)
assert(array_index);
nir_def *array_max = usclib_tex_state_array_max(b, tex_state);
array_index = nir_uclamp(b, array_index, nir_imm_int(b, 0), array_max);
array_index = nir_iclamp(b, array_index, nir_imm_int(b, 0), array_max);
nir_def *tex_meta = nir_load_tex_meta_pco(b,
PCO_IMAGE_META_COUNT,