From 0c8492cd3b2899c3512f5c9050041041d9dcfcb3 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 22 Aug 2022 11:10:19 +1000 Subject: [PATCH] glsl: fix location for array subscript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit xfb_decl_assign_location() assumes that arrays are going to be packed. But some conditions might prevent packing (e.g: explicit location or smooth interpolation mode). Instead of assuming that packing will happen, this commit adds a check to determine if it'll happen and use the result to compute the proper location. Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2214 Acked-by: Marek Olšák Part-of: --- src/compiler/glsl/gl_nir_link_varyings.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_varyings.c b/src/compiler/glsl/gl_nir_link_varyings.c index 37df1640275..015b419bfe7 100644 --- a/src/compiler/glsl/gl_nir_link_varyings.c +++ b/src/compiler/glsl/gl_nir_link_varyings.c @@ -310,7 +310,8 @@ xfb_decl_num_components(struct xfb_decl *xfb_decl) static bool xfb_decl_assign_location(struct xfb_decl *xfb_decl, const struct gl_constants *consts, - struct gl_shader_program *prog) + struct gl_shader_program *prog, + bool disable_varying_packing, bool xfb_enabled) { assert(xfb_decl_is_varying(xfb_decl)); @@ -358,8 +359,17 @@ xfb_decl_assign_location(struct xfb_decl *xfb_decl, actual_array_size); return false; } + + bool array_will_be_lowered = + lower_packed_varying_needs_lowering(prog->last_vert_prog->nir, + xfb_decl->matched_candidate->toplevel_var, + nir_var_shader_out, + disable_varying_packing, + xfb_enabled) || + strcmp(xfb_decl->matched_candidate->toplevel_var->name, "gl_ClipDistance") == 0; + unsigned array_elem_size = xfb_decl->lowered_builtin_array_variable ? - 1 : vector_elements * matrix_cols * dmul; + 1 : (array_will_be_lowered ? vector_elements : 4) * matrix_cols * dmul; fine_location += array_elem_size * xfb_decl->array_subscript; xfb_decl->size = 1; } else { @@ -2780,7 +2790,8 @@ assign_final_varying_locations(const struct gl_constants *consts, for (unsigned i = 0; i < num_xfb_decls; ++i) { if (xfb_decl_is_varying(&xfb_decls[i])) { - if (!xfb_decl_assign_location(&xfb_decls[i], consts, prog)) + if (!xfb_decl_assign_location(&xfb_decls[i], consts, prog, + vm->disable_varying_packing, vm->xfb_enabled)) return false; } }