Module: Mesa Branch: staging/23.0 Commit: b96362381bcfb2e7e3c8eded353b6ac1d72bb105 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b96362381bcfb2e7e3c8eded353b6ac1d72bb105
Author: antonino <[email protected]> Date: Mon Feb 20 19:26:20 2023 +0100 nir: avoid generating conflicting output variables Because not all vertex outputs can have corresponding fragment inputs (eg. edgeflags) some logic is needed to correctly generate variables in a passthough gs. Before this change some output variables ened up with the same location. Fixes: d0342e28b32 ("nir: Add helper to create passthrough GS shader") Acked-by: Mike Blumenkrantz <[email protected]> Reviewed-by: Erik Faye-Lund <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21238> (cherry picked from commit edecb66b01849effdf859f3cfaeebb9af5e1c1da) --- .pick_status.json | 2 +- src/compiler/nir/nir_passthrough_gs.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ecdc0883d11..fc5b7e2e637 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2731,7 +2731,7 @@ "description": "nir: avoid generating conflicting output variables", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "d0342e28b32d7aa4b25cf045ac9933348ec053a9" }, diff --git a/src/compiler/nir/nir_passthrough_gs.c b/src/compiler/nir/nir_passthrough_gs.c index 4ba4f2c8380..82ff849911a 100644 --- a/src/compiler/nir/nir_passthrough_gs.c +++ b/src/compiler/nir/nir_passthrough_gs.c @@ -49,7 +49,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, nir_variable *in_vars[VARYING_SLOT_MAX]; nir_variable *out_vars[VARYING_SLOT_MAX]; - unsigned num_vars = 0; + unsigned num_inputs = 0, num_outputs = 0; /* Create input/output variables. */ nir_foreach_shader_out_variable(var, prev_stage) { @@ -72,6 +72,15 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, in->data.interpolation = var->data.interpolation; in->data.compact = var->data.compact; + in_vars[num_inputs++] = in; + + nir->num_inputs++; + if (in->data.location == VARYING_SLOT_EDGE) + continue; + + if (var->data.location != VARYING_SLOT_POS) + nir->num_outputs++; + if (var->name) snprintf(name, sizeof(name), "out_%s", var->name); else @@ -85,8 +94,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, out->data.interpolation = var->data.interpolation; out->data.compact = var->data.compact; - in_vars[num_vars] = in; - out_vars[num_vars++] = out; + out_vars[num_outputs++] = out; } unsigned int start_vert = 0; @@ -109,11 +117,15 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, for (unsigned i = start_vert; i < end_vert; i += vert_step) { /* Copy inputs to outputs. */ - for (unsigned j = 0; j < num_vars; ++j) { + for (unsigned j = 0, oj = 0; j < num_inputs; ++j) { + if (in_vars[j]->data.location == VARYING_SLOT_EDGE) { + continue; + } /* no need to use copy_var to save a lower pass */ nir_ssa_def *value = nir_load_array_var_imm(&b, in_vars[j], i); - nir_store_var(&b, out_vars[j], value, + nir_store_var(&b, out_vars[oj], value, (1u << value->num_components) - 1); + ++oj; } nir_emit_vertex(&b, 0); }
