glsl: move link_assign_subroutine_types() to the nir linker

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-25 17:10:11 +11:00
committed by Marge Bot
parent baf13bff29
commit 2a5ae739ea
2 changed files with 75 additions and 65 deletions
+75
View File
@@ -1466,6 +1466,80 @@ gl_nir_link_spirv(const struct gl_constants *consts,
return true;
}
static void
link_assign_subroutine_types(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;
struct set *fn_decl_set =
_mesa_set_create(NULL, _mesa_hash_string, _mesa_key_string_equal);
p->sh.MaxSubroutineFunctionIndex = 0;
nir_foreach_function(fn, p->nir) {
/* A function might be decalred multiple times but we should only
* process it once
*/
struct set_entry *entry = _mesa_set_search(fn_decl_set, fn->name);
if (entry)
continue;
_mesa_set_add(fn_decl_set, fn->name);
if (fn->is_subroutine)
p->sh.NumSubroutineUniformTypes++;
if (!fn->num_subroutine_types)
continue;
/* these should have been calculated earlier. */
assert(fn->subroutine_index != -1);
if (p->sh.NumSubroutineFunctions + 1 > MAX_SUBROUTINES) {
linker_error(prog, "Too many subroutine functions declared.\n");
return;
}
p->sh.SubroutineFunctions = reralloc(p, p->sh.SubroutineFunctions,
struct gl_subroutine_function,
p->sh.NumSubroutineFunctions + 1);
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].name.string = ralloc_strdup(p, fn->name);
resource_name_updated(&p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].name);
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].num_compat_types = fn->num_subroutine_types;
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].types =
ralloc_array(p, const struct glsl_type *,
fn->num_subroutine_types);
/* From Section 4.4.4(Subroutine Function Layout Qualifiers) of the
* GLSL 4.5 spec:
*
* "Each subroutine with an index qualifier in the shader must be
* given a unique index, otherwise a compile or link error will be
* generated."
*/
for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
if (p->sh.SubroutineFunctions[j].index != -1 &&
p->sh.SubroutineFunctions[j].index == fn->subroutine_index) {
linker_error(prog, "each subroutine index qualifier in the "
"shader must be unique\n");
return;
}
}
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].index =
fn->subroutine_index;
if (fn->subroutine_index > (int)p->sh.MaxSubroutineFunctionIndex)
p->sh.MaxSubroutineFunctionIndex = fn->subroutine_index;
for (int j = 0; j < fn->num_subroutine_types; j++)
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].types[j] = fn->subroutine_types[j];
p->sh.NumSubroutineFunctions++;
}
_mesa_set_destroy(fn_decl_set, NULL);
}
}
static void
verify_subroutine_associated_funcs(struct gl_shader_program *prog)
{
@@ -1716,6 +1790,7 @@ gl_nir_link_glsl(const struct gl_constants *consts,
MESA_TRACE_FUNC();
link_assign_subroutine_types(prog);
verify_subroutine_associated_funcs(prog);
if (!prog->data->LinkStatus)
return false;
-65
View File
@@ -2375,70 +2375,6 @@ check_explicit_uniform_locations(const struct gl_extensions *exts,
prog->NumExplicitUniformLocations = entries_total;
}
static void
link_assign_subroutine_types(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;
p->sh.MaxSubroutineFunctionIndex = 0;
foreach_in_list(ir_instruction, node, prog->_LinkedShaders[i]->ir) {
ir_function *fn = node->as_function();
if (!fn)
continue;
if (fn->is_subroutine)
p->sh.NumSubroutineUniformTypes++;
if (!fn->num_subroutine_types)
continue;
/* these should have been calculated earlier. */
assert(fn->subroutine_index != -1);
if (p->sh.NumSubroutineFunctions + 1 > MAX_SUBROUTINES) {
linker_error(prog, "Too many subroutine functions declared.\n");
return;
}
p->sh.SubroutineFunctions = reralloc(p, p->sh.SubroutineFunctions,
struct gl_subroutine_function,
p->sh.NumSubroutineFunctions + 1);
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].name.string = ralloc_strdup(p, fn->name);
resource_name_updated(&p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].name);
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].num_compat_types = fn->num_subroutine_types;
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].types =
ralloc_array(p, const struct glsl_type *,
fn->num_subroutine_types);
/* From Section 4.4.4(Subroutine Function Layout Qualifiers) of the
* GLSL 4.5 spec:
*
* "Each subroutine with an index qualifier in the shader must be
* given a unique index, otherwise a compile or link error will be
* generated."
*/
for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
if (p->sh.SubroutineFunctions[j].index != -1 &&
p->sh.SubroutineFunctions[j].index == fn->subroutine_index) {
linker_error(prog, "each subroutine index qualifier in the "
"shader must be unique\n");
return;
}
}
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].index =
fn->subroutine_index;
if (fn->subroutine_index > (int)p->sh.MaxSubroutineFunctionIndex)
p->sh.MaxSubroutineFunctionIndex = fn->subroutine_index;
for (int j = 0; j < fn->num_subroutine_types; j++)
p->sh.SubroutineFunctions[p->sh.NumSubroutineFunctions].types[j] = fn->subroutine_types[j];
p->sh.NumSubroutineFunctions++;
}
}
}
void
link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
{
@@ -2636,7 +2572,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
goto done;
check_explicit_uniform_locations(&ctx->Extensions, prog);
link_assign_subroutine_types(prog);
done:
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {