From d7ba52cce9ea87e042fe07aa0d2ba740cc9e511b Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 24 Aug 2021 15:34:13 -0700 Subject: [PATCH] nir/edgeflags: Add a flag to indicate the edge flag input is needed Most modern hardware needs the edge flag added as a hidden vertex input and needs code added to the vertex shader to copy the input to an output. Intel hardware is a little different. Gfx4 and Gfx5 hardware works in the previously described mannter. Gfx6+ hardware needs the edge flag as a specific vertex shader input, and that input is magically processed by fixed-function hardware without need for extra shader code. This flag signals only that the vertex shader input is needed. It would be nice if we could decouple adding the vertex shader input from generating the copy-to-output code, but that has proven to be challenging. Not having that code causes other passes to want to eliminate that shader input. v2: Convert conditional to assertion. This pass is only called for vertex shaders. Suggested by Ken. Reviewed-by: Kenneth Graunke Part-of: --- src/compiler/nir/nir_lower_passthrough_edgeflags.c | 4 ++++ src/compiler/shader_info.h | 3 +++ src/gallium/drivers/iris/iris_program.c | 1 + 3 files changed, 8 insertions(+) diff --git a/src/compiler/nir/nir_lower_passthrough_edgeflags.c b/src/compiler/nir/nir_lower_passthrough_edgeflags.c index 1fd2cd20014..e6d0b14f26b 100644 --- a/src/compiler/nir/nir_lower_passthrough_edgeflags.c +++ b/src/compiler/nir/nir_lower_passthrough_edgeflags.c @@ -96,5 +96,9 @@ lower_impl(nir_function_impl *impl) void nir_lower_passthrough_edgeflags(nir_shader *shader) { + assert(shader->info.stage == MESA_SHADER_VERTEX); + + shader->info.vs.needs_edge_flag = true; + lower_impl(nir_shader_get_entrypoint(shader)); } diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h index b3aabb9f054..91421db9b74 100644 --- a/src/compiler/shader_info.h +++ b/src/compiler/shader_info.h @@ -297,6 +297,9 @@ typedef struct shader_info { /* True if the shader writes position in window space coordinates pre-transform */ bool window_space_position:1; + + /** Is an edge flag input needed? */ + bool needs_edge_flag:1; } vs; struct { diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index 840a5cb28d4..858294ad2d9 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -2441,6 +2441,7 @@ iris_create_uncompiled_shader(struct iris_screen *screen, simple_mtx_init(&ish->lock, mtx_plain); NIR_PASS(ish->needs_edge_flag, nir, iris_fix_edge_flags); + assert(ish->needs_edge_flag == nir->info.vs.needs_edge_flag); brw_preprocess_nir(screen->compiler, nir, NULL);