From 15b3d77b403b06da18029985ba40df7447263dd3 Mon Sep 17 00:00:00 2001 From: antonino Date: Thu, 30 Mar 2023 17:45:15 +0200 Subject: [PATCH] nir: only handle flat interpolation when needed in `nir_create_passthrough_gs` When turning primitives into line strips this function needs to move attributes around, but this is not needed in other cases. Fixes: 1a5bdca2dda ("zink: implement flat shading using inlined uniforms") Reviewed-by: Erik Faye-Lund Part-of: --- src/compiler/nir/nir_passthrough_gs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_passthrough_gs.c b/src/compiler/nir/nir_passthrough_gs.c index 85e5429..aebf75d 100644 --- a/src/compiler/nir/nir_passthrough_gs.c +++ b/src/compiler/nir/nir_passthrough_gs.c @@ -139,6 +139,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, unsigned int vertices_out = vertices_for_prim(primitive_type); emulate_edgeflags = emulate_edgeflags && (prev_stage->info.outputs_written & VARYING_BIT_EDGE); bool needs_closing = (force_line_strip_out || emulate_edgeflags) && vertices_out >= 3; + enum shader_prim original_our_prim = gs_out_prim_for_topology(primitive_type); nir_builder b = nir_builder_init_simple_shader(MESA_SHADER_GEOMETRY, options, "gs passthrough"); @@ -146,7 +147,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, nir_shader *nir = b.shader; nir->info.gs.input_primitive = gs_in_prim_for_topology(primitive_type); nir->info.gs.output_primitive = (force_line_strip_out || emulate_edgeflags) ? - SHADER_PRIM_LINE_STRIP : gs_out_prim_for_topology(primitive_type); + SHADER_PRIM_LINE_STRIP : original_our_prim; nir->info.gs.vertices_in = vertices_out; nir->info.gs.vertices_out = needs_closing ? vertices_out + 1 : vertices_out; nir->info.gs.invocations = 1; @@ -158,6 +159,8 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, nir->xfb_info = mem_dup(prev_stage->xfb_info, sizeof(nir_xfb_info)); } + bool handle_flat = nir->info.gs.output_primitive == SHADER_PRIM_LINE_STRIP && + nir->info.gs.output_primitive != original_our_prim; nir_variable *in_vars[VARYING_SLOT_MAX]; nir_variable *out_vars[VARYING_SLOT_MAX]; unsigned num_inputs = 0, num_outputs = 0; @@ -252,7 +255,7 @@ nir_create_passthrough_gs(const nir_shader_compiler_options *options, } /* no need to use copy_var to save a lower pass */ nir_ssa_def *index; - if (in_vars[j]->data.location == VARYING_SLOT_POS) + if (in_vars[j]->data.location == VARYING_SLOT_POS || !handle_flat) index = nir_imm_int(&b, idx); else { unsigned mask = 1u << (of++); -- 2.7.4