ac/nir/ngg: Add upper limit to reusable uniforms.

This is a heuristic to try to reduce SGPR spilling.

While the stats changes on this commit are not impressive,
this is mainly meant to reduce the regressions from the
next few commits which will find more of these
reusable uniforms.

Fossil DB stats on GFX10.3:

Totals from 567 (0.42% of 134913) affected shaders:
VGPRs: 32528 -> 32608 (+0.25%)
SpillSGPRs: 291 -> 247 (-15.12%); split: -49.14%, +34.02%
CodeSize: 3956896 -> 4006552 (+1.25%); split: -0.07%, +1.33%
MaxWaves: 10508 -> 10486 (-0.21%)
Instrs: 756092 -> 764613 (+1.13%); split: -0.09%, +1.22%
Latency: 2533679 -> 2544752 (+0.44%); split: -0.09%, +0.52%
InvThroughput: 733729 -> 733690 (-0.01%); split: -0.06%, +0.06%
VClause: 4853 -> 4861 (+0.16%); split: -1.36%, +1.52%
SClause: 15627 -> 17485 (+11.89%); split: -0.01%, +11.90%
Copies: 62584 -> 65345 (+4.41%); split: -1.61%, +6.02%
Branches: 17356 -> 17405 (+0.28%); split: -0.10%, +0.39%
PreSGPRs: 46758 -> 43465 (-7.04%); split: -8.37%, +1.33%
PreVGPRs: 28944 -> 28931 (-0.04%); split: -0.08%, +0.04%

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23946>
This commit is contained in:
Timur Kristóf 2023-04-01 03:30:28 +02:00 committed by Marge Bot
parent ddeabcc19b
commit 91b28fc621

View file

@ -1204,6 +1204,9 @@ save_reusable_variables(nir_builder *b, lower_ngg_nogs_state *s)
ASSERTED int vec_ok = u_vector_init(&s->reusable_nondeferred_variables, 4, sizeof(reusable_nondeferred_variable));
assert(vec_ok);
/* Upper limit on reusable uniforms in order to reduce SGPR spilling. */
unsigned remaining_reusable_uniforms = 48;
nir_block *block = nir_start_block(b->impl);
while (block) {
/* Process the instructions in the current block. */
@ -1222,6 +1225,13 @@ save_reusable_variables(nir_builder *b, lower_ngg_nogs_state *s)
if (!t)
continue;
if (!ssa->divergent) {
if (remaining_reusable_uniforms < ssa->num_components)
continue;
remaining_reusable_uniforms -= ssa->num_components;
}
reusable_nondeferred_variable *saved = (reusable_nondeferred_variable *) u_vector_add(&s->reusable_nondeferred_variables);
assert(saved);