st/mesa: enable state var merging to improve fetch_state performance
The requirement is that drivers must implement finalize_nir for st_finalize_nir to be invoked at link time and before shader variant generation. Without that, _mesa_optimize_state_parameters won't be called. Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8183>
This commit is contained in:
@@ -565,7 +565,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog,
|
||||
st_finalize_nir_before_variants(nir);
|
||||
|
||||
if (st->allow_st_finalize_nir_twice)
|
||||
st_finalize_nir(st, prog, shader_program, nir, true);
|
||||
st_finalize_nir(st, prog, shader_program, nir, true, true);
|
||||
|
||||
if (st->ctx->_Shader->Flags & GLSL_DUMP) {
|
||||
_mesa_log("\n");
|
||||
@@ -1018,7 +1018,8 @@ st_nir_lower_uniforms(struct st_context *st, nir_shader *nir)
|
||||
void
|
||||
st_finalize_nir(struct st_context *st, struct gl_program *prog,
|
||||
struct gl_shader_program *shader_program,
|
||||
nir_shader *nir, bool finalize_by_driver)
|
||||
nir_shader *nir, bool finalize_by_driver,
|
||||
bool is_before_variants)
|
||||
{
|
||||
struct pipe_screen *screen = st->screen;
|
||||
|
||||
@@ -1032,6 +1033,15 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
|
||||
nir->num_uniforms = DIV_ROUND_UP(prog->Parameters->NumParameterValues, 4);
|
||||
|
||||
st_nir_lower_uniforms(st, nir);
|
||||
|
||||
if (is_before_variants && nir->options->lower_uniforms_to_ubo) {
|
||||
/* This must be done after uniforms are lowered to UBO and all
|
||||
* nir_var_uniform variables are removed from NIR to prevent conflicts
|
||||
* between state parameter merging and shader variant generation.
|
||||
*/
|
||||
_mesa_optimize_state_parameters(&st->ctx->Const, prog->Parameters);
|
||||
}
|
||||
|
||||
st_nir_lower_samplers(screen, nir, shader_program, prog);
|
||||
if (!screen->get_param(screen, PIPE_CAP_NIR_IMAGES_AS_DEREF))
|
||||
NIR_PASS_V(nir, gl_nir_lower_images, false);
|
||||
|
||||
@@ -43,7 +43,8 @@ void st_nir_lower_wpos_ytransform(struct nir_shader *nir,
|
||||
|
||||
void st_finalize_nir(struct st_context *st, struct gl_program *prog,
|
||||
struct gl_shader_program *shader_program,
|
||||
struct nir_shader *nir, bool finalize_by_driver);
|
||||
struct nir_shader *nir, bool finalize_by_driver,
|
||||
bool is_before_variants);
|
||||
|
||||
void st_nir_opts(struct nir_shader *nir);
|
||||
|
||||
|
||||
@@ -391,7 +391,7 @@ st_prog_to_nir_postprocess(struct st_context *st, nir_shader *nir,
|
||||
st_finalize_nir_before_variants(nir);
|
||||
|
||||
if (st->allow_st_finalize_nir_twice)
|
||||
st_finalize_nir(st, prog, NULL, nir, true);
|
||||
st_finalize_nir(st, prog, NULL, nir, true, true);
|
||||
|
||||
nir_validate_shader(nir, "after st/glsl finalize_nir");
|
||||
}
|
||||
@@ -785,7 +785,7 @@ st_create_vp_variant(struct st_context *st,
|
||||
|
||||
if (finalize || !st->allow_st_finalize_nir_twice) {
|
||||
st_finalize_nir(st, &stvp->Base, stvp->shader_program, state.ir.nir,
|
||||
true);
|
||||
true, false);
|
||||
|
||||
/* Some of the lowering above may have introduced new varyings */
|
||||
nir_shader_gather_info(state.ir.nir,
|
||||
@@ -1360,7 +1360,7 @@ st_create_fp_variant(struct st_context *st,
|
||||
|
||||
if (finalize || !st->allow_st_finalize_nir_twice) {
|
||||
st_finalize_nir(st, &stfp->Base, stfp->shader_program, state.ir.nir,
|
||||
false);
|
||||
false, false);
|
||||
}
|
||||
|
||||
/* This pass needs to happen *after* nir_lower_sampler */
|
||||
@@ -1761,7 +1761,7 @@ st_get_common_variant(struct st_context *st,
|
||||
|
||||
if (finalize || !st->allow_st_finalize_nir_twice) {
|
||||
st_finalize_nir(st, &prog->Base, prog->shader_program,
|
||||
state.ir.nir, true);
|
||||
state.ir.nir, true, false);
|
||||
}
|
||||
|
||||
if (ST_DEBUG & DEBUG_PRINT_IR)
|
||||
|
||||
Reference in New Issue
Block a user