From e5097a7c9dc69833dd2a42937bed1bb2983ebc53 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 24 Mar 2025 19:55:04 -0400 Subject: [PATCH] glsl_to_nir: upcast array indices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit array indices need to match the pointer size, otherwise we fail NIR assertions. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6075 Signed-off-by: Alyssa Rosenzweig Reviewed-by: Marek Olšák Tested-by: Dieter Nützel Part-of: --- src/compiler/glsl/glsl_to_nir.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index fe70c0f34ad..bfe7b9d5f16 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -2796,6 +2796,12 @@ nir_visitor::visit(ir_dereference_array *ir) { nir_def *index = evaluate_rvalue(ir->array_index); + /* In NIR, array indices must match the pointer size (32-bits for arrays), + * but in GLSL IR, we might "optimize" the array index to a 16-bit integer. + * We need to upcast in that case to keep the NIR valid. + */ + index = nir_i2iN(&b, index, this->deref->def.bit_size); + ir->array->accept(this); this->deref = nir_build_deref_array(&b, this->deref, index);