From 58cbf10cdb1cc8b591ffd5931c0a014d52d67889 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 2 Jun 2021 14:52:36 -0400 Subject: [PATCH] panfrost: Correctly size varyings The same slot could be specified multiple times with different location_frac out of order, so we use two passes. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/lib/pan_shader.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/panfrost/lib/pan_shader.c b/src/panfrost/lib/pan_shader.c index f8fa8ad8f51..4cf91c7769c 100644 --- a/src/panfrost/lib/pan_shader.c +++ b/src/panfrost/lib/pan_shader.c @@ -87,13 +87,13 @@ collect_varyings(nir_shader *s, nir_variable_mode varying_mode, { *varying_count = 0; + unsigned comps[MAX_VARYING] = { 0 }; + nir_foreach_variable_with_modes(var, s, varying_mode) { unsigned loc = var->data.driver_location; - unsigned sz = glsl_count_attribute_slots(var->type, FALSE); const struct glsl_type *column = glsl_without_array_or_matrix(var->type); unsigned chan = glsl_get_components(column); - enum glsl_base_type base_type = glsl_get_base_type(column); /* If we have a fractional location added, we need to increase the size * so it will fit, i.e. a vec3 in YZW requires us to allocate a vec4. @@ -101,7 +101,16 @@ collect_varyings(nir_shader *s, nir_variable_mode varying_mode, * packed varyings will be aligned. */ chan += var->data.location_frac; - assert(chan >= 1 && chan <= 4); + comps[loc] = MAX2(comps[loc], chan); + } + + nir_foreach_variable_with_modes(var, s, varying_mode) { + unsigned loc = var->data.driver_location; + unsigned sz = glsl_count_attribute_slots(var->type, FALSE); + const struct glsl_type *column = + glsl_without_array_or_matrix(var->type); + enum glsl_base_type base_type = glsl_get_base_type(column); + unsigned chan = comps[loc]; nir_alu_type type = nir_get_nir_type_for_glsl_base_type(base_type);