From 5ea15ded2fce12012f118c0114192decb7b1e837 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 21 Mar 2024 11:59:43 +1100 Subject: [PATCH] glsl: switch verify_subroutine_associated_funcs() to nir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acked-by: Marek Olšák Part-of: --- src/compiler/glsl/gl_nir_linker.c | 43 +++++++++++++++++++++++++++++++ src/compiler/glsl/linker.cpp | 41 ----------------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index 6b7455f96f4..48390b7da11 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -1466,6 +1466,45 @@ gl_nir_link_spirv(const struct gl_constants *consts, return true; } +static void +verify_subroutine_associated_funcs(struct gl_shader_program *prog) +{ + unsigned mask = prog->data->linked_stages; + while (mask) { + const int i = u_bit_scan(&mask); + struct gl_program *p = prog->_LinkedShaders[i]->Program; + + /* Section 6.1.2 (Subroutines) of the GLSL 4.00 spec says: + * + * "A program will fail to compile or link if any shader + * or stage contains two or more functions with the same + * name if the name is associated with a subroutine type." + */ + for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) { + unsigned definitions = 0; + char *name = p->sh.SubroutineFunctions[j].name.string; + + /* Calculate number of function definitions with the same name */ + nir_foreach_function(fn, p->nir) { + /* If the function is only declared not implemented continue */ + if (fn->impl != NULL) + continue; + + if (strcmp(fn->name, name) == 0) { + if (++definitions > 1) { + linker_error(prog, "%s shader contains two or more function " + "definitions with name `%s', which is " + "associated with a subroutine type.\n", + _mesa_shader_stage_to_string(i), + fn->name); + return; + } + } + } + } + } +} + /** * Validate shader image resources. */ @@ -1677,6 +1716,10 @@ gl_nir_link_glsl(const struct gl_constants *consts, MESA_TRACE_FUNC(); + verify_subroutine_associated_funcs(prog); + if (!prog->data->LinkStatus) + return false; + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index c19acc30823..b4afec18873 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -2439,43 +2439,6 @@ link_assign_subroutine_types(struct gl_shader_program *prog) } } -static void -verify_subroutine_associated_funcs(struct gl_shader_program *prog) -{ - unsigned mask = prog->data->linked_stages; - while (mask) { - const int i = u_bit_scan(&mask); - gl_program *p = prog->_LinkedShaders[i]->Program; - glsl_symbol_table *symbols = prog->_LinkedShaders[i]->symbols; - - /* Section 6.1.2 (Subroutines) of the GLSL 4.00 spec says: - * - * "A program will fail to compile or link if any shader - * or stage contains two or more functions with the same - * name if the name is associated with a subroutine type." - */ - for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) { - unsigned definitions = 0; - char *name = p->sh.SubroutineFunctions[j].name.string; - ir_function *fn = symbols->get_function(name); - - /* Calculate number of function definitions with the same name */ - foreach_in_list(ir_function_signature, sig, &fn->signatures) { - if (sig->is_defined) { - if (++definitions > 1) { - linker_error(prog, "%s shader contains two or more function " - "definitions with name `%s', which is " - "associated with a subroutine type.\n", - _mesa_shader_stage_to_string(i), - fn->name); - return; - } - } - } - } - } -} - void link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) { @@ -2674,10 +2637,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) check_explicit_uniform_locations(&ctx->Extensions, prog); link_assign_subroutine_types(prog); - verify_subroutine_associated_funcs(prog); - - if (!prog->data->LinkStatus) - goto done; done: for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {