nir/lower_io_to_vector: Only call glsl_get_length() on arrays

We assumed that calling it on vectors would return 0 and then did a
MAX2(length, 1) to get 1 for vectors.  Instead, use a ternary so we
don't make assumptions about non-sensical values.

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22580>
This commit is contained in:
Faith Ekstrand 2023-04-27 14:51:49 -05:00 committed by Marge Bot
parent 5db458eb2d
commit 1e1c450659

View file

@ -309,7 +309,8 @@ create_new_io_vars(nir_shader *shader, nir_variable_mode mode,
var->type = flat_type;
nir_shader_add_variable(shader, var);
unsigned num_slots = MAX2(glsl_get_length(flat_type), 1);
unsigned num_slots =
glsl_type_is_array(flat_type) ? glsl_get_length(flat_type) : 1;
for (unsigned i = 0; i < num_slots; i++) {
for (unsigned j = 0; j < 4; j++)
new_vars[loc + i][j] = var;