glsl: switch verify_subroutine_associated_funcs() to nir

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28538>
This commit is contained in:
Timothy Arceri 2024-03-21 11:59:43 +11:00 committed by Marge Bot
parent 1a78e9a7e8
commit 5ea15ded2f
2 changed files with 43 additions and 41 deletions

View file

@ -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;

View file

@ -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++) {