nir/nir_group_loads: reduce chance of max_distance check overflow

Helps for the case when max_distance is set to ~0, where the pass would now
only create groups of two loads together due to overflow. Found while
experimenting with this pass on r300, however the only driver currently
affected is i915.

With i915 this change gains around 20 shaders in my small shader-db
(most notably some GLMark2, Unigine Tropics, Tesseract, Amnesia) at
the expense of increased register pressure in few other cases.
I'm assuming this is a good deal for such old HW, and this seems like what
was intended when the pass was introduced to i915, but anyway this
could be tweaked further driver side with a more optimized max_distance
value. Only shader-db tested.

Relevant i915 shader-db stats (lpt):
total tex_indirect in shared programs: 1529 -> 1493 (-2.35%)
tex_indirect in affected programs: 96 -> 60 (-37.50%)
helped: 29
HURT: 2
total temps in shared programs: 3015 -> 3200 (6.14%)
temps in affected programs: 465 -> 650 (39.78%)
helped: 1
HURT: 91

GAINED: 20

Signed-off-by: Pavel Ondračka <pavel.ondracka@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Tested-by: GKraats <vd.kraats@hccnet.nl>
Fixes: 33b4eb149e
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31529>
This commit is contained in:
Pavel Ondračka 2024-06-17 11:49:01 +02:00 committed by Marge Bot
parent 0317c44872
commit 33c8dc4f18

View file

@ -289,8 +289,9 @@ static void
handle_load_range(nir_instr **first, nir_instr **last,
nir_instr *current, unsigned max_distance)
{
assert(!current || !*first || current->index >= (*first)->index);
if (*first && *last &&
(!current || current->index > (*first)->index + max_distance)) {
(!current || current->index - (*first)->index > max_distance)) {
assert(*first != *last);
group_loads(*first, *last);
set_instr_indices((*first)->block);