spirv: Fix cooperative matrix in OpVariable initializer

Check for cooperative matrix types first in the
nir_lower_variable_initializers pass, since they are also considered
to be scalar types.

Fixes: 7e6cd395c7 ("nir: Handle cmat types in lower_variable_initializers")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13388
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35668>
This commit is contained in:
James Price 2025-06-20 23:18:07 -04:00 committed by Marge Bot
parent 4008300672
commit 10ae673368

View file

@ -27,7 +27,13 @@
static void
build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c)
{
if (glsl_type_is_vector_or_scalar(deref->type)) {
if (glsl_type_is_cmat(deref->type)) {
const struct glsl_type *elem_type = glsl_get_cmat_element(deref->type);
assert(glsl_type_is_scalar(elem_type));
const unsigned bit_size = glsl_get_bit_size(elem_type);
nir_def *elem = nir_build_imm(b, 1, bit_size, c->values);
nir_cmat_construct(b, &deref->def, elem);
} else if (glsl_type_is_vector_or_scalar(deref->type)) {
const unsigned num_components = glsl_get_vector_elements(deref->type);
const unsigned bit_size = glsl_get_bit_size(deref->type);
nir_def *imm = nir_build_imm(b, num_components, bit_size, c->values);
@ -38,12 +44,6 @@ build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c)
build_constant_load(b, nir_build_deref_struct(b, deref, i),
c->elements[i]);
}
} else if (glsl_type_is_cmat(deref->type)) {
const struct glsl_type *elem_type = glsl_get_cmat_element(deref->type);
assert(glsl_type_is_scalar(elem_type));
const unsigned bit_size = glsl_get_bit_size(elem_type);
nir_def *elem = nir_build_imm(b, 1, bit_size, c->values);
nir_cmat_construct(b, &deref->def, elem);
} else {
assert(glsl_type_is_array(deref->type) ||
glsl_type_is_matrix(deref->type));