From acbf3ad1fbace42f395a49586f49a7f1c12480ee Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Thu, 4 Apr 2024 15:54:33 -0700 Subject: [PATCH] glsl: Use a stable attr sort for VS in / FS out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a perpetual bug that hits Windows. In the MSVC CRT, qsort is unstable, where the glibc qsort is stable. So apps run fine on Windows IHV drivers, and on Linux Mesa drivers, and only break down when running on Windows Mesa drivers. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10922 Reviewed-by: Sil Vilerino Reviewed-by: Marek Olšák Cc: mesa-stable Part-of: --- src/compiler/glsl/gl_nir_link_varyings.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/gl_nir_link_varyings.c b/src/compiler/glsl/gl_nir_link_varyings.c index 543cbc074aa..2b930663d7f 100644 --- a/src/compiler/glsl/gl_nir_link_varyings.c +++ b/src/compiler/glsl/gl_nir_link_varyings.c @@ -50,6 +50,7 @@ /* Temporary storage for the set of attributes that need locations assigned. */ struct temp_attr { unsigned slots; + unsigned original_idx; nir_variable *var; }; @@ -61,7 +62,10 @@ compare_attr(const void *a, const void *b) const struct temp_attr *const r = (const struct temp_attr *) b; /* Reversed because we want a descending order sort below. */ - return r->slots - l->slots; + if (r->slots != l->slots) + return r->slots - l->slots; + + return l->original_idx - r->original_idx; } /** @@ -1238,6 +1242,7 @@ assign_attribute_or_color_locations(void *mem_ctx, } to_assign[num_attr].slots = slots; to_assign[num_attr].var = var; + to_assign[num_attr].original_idx = num_attr; num_attr++; }