glsl: make glsl_to_nir() more generic
Here we move anything that expects the IR to have already been linked so that in a future patch we can use glsl_to_nir() to convert IR that has only been compiled. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29761>
This commit is contained in:

committed by
Marge Bot

parent
f19ddef76c
commit
0ac0fbc19e
@@ -150,25 +150,21 @@ private:
|
||||
|
||||
nir_shader *
|
||||
glsl_to_nir(const struct gl_constants *consts,
|
||||
const struct gl_shader_program *shader_prog,
|
||||
gl_shader_stage stage,
|
||||
struct exec_list **ir, shader_info *si, gl_shader_stage stage,
|
||||
const nir_shader_compiler_options *options)
|
||||
{
|
||||
struct gl_linked_shader *sh = shader_prog->_LinkedShaders[stage];
|
||||
|
||||
MESA_TRACE_FUNC();
|
||||
|
||||
nir_shader *shader = nir_shader_create(NULL, stage, options,
|
||||
&sh->Program->info);
|
||||
nir_shader *shader = nir_shader_create(NULL, stage, options, si);
|
||||
|
||||
nir_visitor v1(consts, shader);
|
||||
nir_function_visitor v2(&v1);
|
||||
v2.run(sh->ir);
|
||||
visit_exec_list(sh->ir, &v1);
|
||||
v2.run(*ir);
|
||||
visit_exec_list(*ir, &v1);
|
||||
|
||||
/* The GLSL IR won't be needed anymore. */
|
||||
ralloc_free(sh->ir);
|
||||
sh->ir = NULL;
|
||||
ralloc_free(*ir);
|
||||
*ir = NULL;
|
||||
|
||||
nir_validate_shader(shader, "after glsl to nir, before function inline");
|
||||
if (should_print_nir(shader)) {
|
||||
@@ -176,18 +172,8 @@ glsl_to_nir(const struct gl_constants *consts,
|
||||
nir_print_shader(shader, stdout);
|
||||
}
|
||||
|
||||
shader->info.name = ralloc_asprintf(shader, "GLSL%d", shader_prog->Name);
|
||||
if (shader_prog->Label)
|
||||
shader->info.label = ralloc_strdup(shader, shader_prog->Label);
|
||||
|
||||
shader->info.subgroup_size = SUBGROUP_SIZE_UNIFORM;
|
||||
|
||||
if (shader->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
shader->info.fs.pixel_center_integer = sh->Program->info.fs.pixel_center_integer;
|
||||
shader->info.fs.origin_upper_left = sh->Program->info.fs.origin_upper_left;
|
||||
shader->info.fs.advanced_blend_modes = sh->Program->info.fs.advanced_blend_modes;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ struct gl_constants;
|
||||
struct gl_shader_program;
|
||||
|
||||
nir_shader *glsl_to_nir(const struct gl_constants *consts,
|
||||
const struct gl_shader_program *shader_prog,
|
||||
struct exec_list **ir, shader_info *si,
|
||||
gl_shader_stage stage,
|
||||
const nir_shader_compiler_options *options);
|
||||
|
||||
|
@@ -200,7 +200,9 @@ namespace
|
||||
.support_16bit_alu = true,
|
||||
};
|
||||
|
||||
nir = glsl_to_nir(&ctx->Const, whole_program, MESA_SHADER_FRAGMENT, &compiler_options);
|
||||
struct gl_linked_shader *sh = whole_program->_LinkedShaders[MESA_SHADER_FRAGMENT];
|
||||
nir = glsl_to_nir(&ctx->Const, &sh->ir, &sh->Program->info,
|
||||
MESA_SHADER_FRAGMENT, &compiler_options);
|
||||
|
||||
gl_nir_inline_functions(nir);
|
||||
|
||||
|
@@ -121,7 +121,19 @@ load_glsl(unsigned num_files, char *const *files, gl_shader_stage stage)
|
||||
if (!prog)
|
||||
errx(1, "couldn't parse `%s'", files[0]);
|
||||
|
||||
nir_shader *nir = glsl_to_nir(&local_ctx.Const, prog, stage, nir_options);
|
||||
nir_shader *nir = glsl_to_nir(&local_ctx.Const,
|
||||
&prog->_LinkedShaders[stage]->ir,
|
||||
&prog->_LinkedShaders[stage]->Program->info,
|
||||
stage, nir_options);
|
||||
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
nir->info.fs.pixel_center_integer =
|
||||
prog->_LinkedShaders[stage]->Program->info.fs.pixel_center_integer;
|
||||
nir->info.fs.origin_upper_left =
|
||||
prog->_LinkedShaders[stage]->Program->info.fs.origin_upper_left;
|
||||
nir->info.fs.advanced_blend_modes =
|
||||
prog->_LinkedShaders[stage]->Program->info.fs.advanced_blend_modes;
|
||||
}
|
||||
|
||||
gl_nir_inline_functions(nir);
|
||||
|
||||
|
@@ -541,7 +541,19 @@ st_link_glsl_to_nir(struct gl_context *ctx,
|
||||
_mesa_log("\n\n");
|
||||
}
|
||||
|
||||
prog->nir = glsl_to_nir(&st->ctx->Const, shader_program, shader->Stage, options);
|
||||
prog->nir = glsl_to_nir(&st->ctx->Const, &shader->ir,
|
||||
&shader->Program->info, shader->Stage, options);
|
||||
|
||||
prog->nir->info.name =
|
||||
ralloc_asprintf(shader, "GLSL%d", shader_program->Name);
|
||||
if (shader_program->Label)
|
||||
prog->nir->info.label = ralloc_strdup(shader, shader_program->Label);
|
||||
|
||||
if (prog->nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
prog->nir->info.fs.pixel_center_integer = prog->info.fs.pixel_center_integer;
|
||||
prog->nir->info.fs.origin_upper_left = prog->info.fs.origin_upper_left;
|
||||
prog->nir->info.fs.advanced_blend_modes = prog->info.fs.advanced_blend_modes;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(prog->nir->info.source_blake3, shader->linked_source_blake3,
|
||||
|
Reference in New Issue
Block a user