From 027ba4ccefbefe468ca6c198b7a3404b3a0c3f23 Mon Sep 17 00:00:00 2001 From: antonino Date: Tue, 7 Feb 2023 17:01:52 +0100 Subject: [PATCH] zink: fix flat shading on filled quads Quads emulated by zink will now have the correct provoking vertex. Also outputs of the previous shader stage that would normally not be passed down to the FS (when no GS is bound) will now be skipped. Different provoking vertex modes are not handled yet. Acked-by: Mike Blumenkrantz Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/zink/zink_compiler.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index e869c10..a2afd76 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -913,7 +913,7 @@ zink_create_quads_emulation_gs(const nir_shader_compiler_options *options, nir->info.gs.input_primitive = SHADER_PRIM_LINES_ADJACENCY; nir->info.gs.output_primitive = SHADER_PRIM_TRIANGLE_STRIP; nir->info.gs.vertices_in = 4; - nir->info.gs.vertices_out = 4; + nir->info.gs.vertices_out = 6; nir->info.gs.invocations = 1; nir->info.gs.active_stream_mask = 1; @@ -959,9 +959,10 @@ zink_create_quads_emulation_gs(const nir_shader_compiler_options *options, out_vars[num_vars++] = out; } - for (unsigned i = 0; i < 4; ++i) { + int mapping[] = {0, 1, 2, 0, 2, 3}; + for (unsigned i = 0; i < 6; ++i) { /* swap indices 2 and 3 */ - int idx = i == 2 ? 3 : (i == 3 ? 2 : i); + int idx = mapping[i]; /* Copy inputs to outputs. */ for (unsigned j = 0; j < num_vars; ++j) { if (in_vars[j]->data.location == VARYING_SLOT_EDGE) { @@ -973,6 +974,8 @@ zink_create_quads_emulation_gs(const nir_shader_compiler_options *options, (1u << value->num_components) - 1); } nir_emit_vertex(&b, 0); + if (i == 2) + nir_end_primitive(&b, 0); } nir_end_primitive(&b, 0); -- 2.7.4