From ed3fe89562ff6dcf56ccbc4f69862a4797e3fb89 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 22 Jun 2023 14:26:12 +1000 Subject: [PATCH] glsl: move store_fragdepth_layout() to nir linker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/gl_nir_link_varyings.c | 39 +++++++++++++++++ src/compiler/glsl/linker.cpp | 53 ------------------------ 2 files changed, 39 insertions(+), 53 deletions(-) diff --git a/src/compiler/glsl/gl_nir_link_varyings.c b/src/compiler/glsl/gl_nir_link_varyings.c index 4018652d86c..b1c84d1f972 100644 --- a/src/compiler/glsl/gl_nir_link_varyings.c +++ b/src/compiler/glsl/gl_nir_link_varyings.c @@ -3653,6 +3653,43 @@ link_varyings(struct gl_shader_program *prog, unsigned first, return true; } +/** + * Store the gl_FragDepth layout in the gl_shader_program struct. + */ +static void +store_fragdepth_layout(struct gl_shader_program *prog) +{ + if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) { + return; + } + + nir_shader *nir = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program->nir; + nir_foreach_shader_out_variable(var, nir) { + if (strcmp(var->name, "gl_FragDepth") == 0) { + switch (var->data.depth_layout) { + case nir_depth_layout_none: + prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE; + return; + case nir_depth_layout_any: + prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY; + return; + case nir_depth_layout_greater: + prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER; + return; + case nir_depth_layout_less: + prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS; + return; + case nir_depth_layout_unchanged: + prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED; + return; + default: + assert(0); + return; + } + } + } +} + bool gl_assign_attribute_or_color_locations(const struct gl_constants *consts, struct gl_shader_program *prog) @@ -3686,6 +3723,8 @@ gl_nir_link_varyings(const struct gl_constants *consts, MESA_TRACE_FUNC(); + store_fragdepth_layout(prog); + first = MESA_SHADER_STAGES; last = 0; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 5d0536e580e..12446d785d4 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -3088,57 +3088,6 @@ assign_attribute_or_color_locations(void *mem_ctx, return true; } -/** - * Store the gl_FragDepth layout in the gl_shader_program struct. - */ -static void -store_fragdepth_layout(struct gl_shader_program *prog) -{ - if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) { - return; - } - - struct exec_list *ir = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir; - - /* We don't look up the gl_FragDepth symbol directly because if - * gl_FragDepth is not used in the shader, it's removed from the IR. - * However, the symbol won't be removed from the symbol table. - * - * We're only interested in the cases where the variable is NOT removed - * from the IR. - */ - foreach_in_list(ir_instruction, node, ir) { - ir_variable *const var = node->as_variable(); - - if (var == NULL || var->data.mode != ir_var_shader_out) { - continue; - } - - if (strcmp(var->name, "gl_FragDepth") == 0) { - switch (var->data.depth_layout) { - case ir_depth_layout_none: - prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE; - return; - case ir_depth_layout_any: - prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY; - return; - case ir_depth_layout_greater: - prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER; - return; - case ir_depth_layout_less: - prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS; - return; - case ir_depth_layout_unchanged: - prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED; - return; - default: - assert(0); - return; - } - } - } -} - /** * Initializes explicit location slots to INACTIVE_UNIFORM_EXPLICIT_LOCATION @@ -3764,8 +3713,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) /* Check and validate stream emissions in geometry shaders */ validate_geometry_shader_emissions(consts, prog); - store_fragdepth_layout(prog); - for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue;