From 01e050b701f022afdffe922cf4318c7b669f0627 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 24 Aug 2021 19:28:24 +0200 Subject: [PATCH] shader: Sort FS color outputs NIR-to-TGSI doesn't necessarily sort the outputs, and that breaks some CTS tests. Signed-off-by: Gert Wollny Reviewed-by: John Bates --- src/vrend_shader.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 8dd0f70..782a334 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -7138,6 +7138,17 @@ static bool vrend_patch_vertex_shader_interpolants(const struct vrend_shader_cfg const char *oprefix, bool flatshade); +static int compare_sid(const void *lhs, const void *rhs) +{ + const struct vrend_shader_io *l = (struct vrend_shader_io *)lhs; + const struct vrend_shader_io *r = (struct vrend_shader_io *)rhs; + + if (l->name != r->name) + return l->name - r->name; + + return l->sid - r->sid; +} + bool vrend_convert_shader(const struct vrend_context *rctx, const struct vrend_shader_cfg *cfg, const struct tgsi_token *tokens, @@ -7217,6 +7228,9 @@ bool vrend_convert_shader(const struct vrend_context *rctx, for (size_t i = 0; i < ARRAY_SIZE(ctx.src_bufs); ++i) strbuf_free(ctx.src_bufs + i); + if (ctx.prog_type == TGSI_PROCESSOR_FRAGMENT) + qsort(ctx.outputs, ctx.num_outputs, sizeof(struct vrend_shader_io), compare_sid); + emit_header(&ctx, &ctx.glsl_strbufs); ctx.glsl_ver_required = emit_ios(&ctx, &ctx.glsl_strbufs, &ctx.generic_ios, ctx.front_back_color_emitted_flags,