Module: Mesa Branch: main Commit: 6167f6e0962f6d60553f021c7e8d91edbbd9dba8 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=6167f6e0962f6d60553f021c7e8d91edbbd9dba8
Author: Pavel Ondračka <pavel.ondra...@gmail.com> Date: Sat Dec 16 17:00:39 2023 +0100 r300: lower flrp in NIR Shader-db RV370: total instructions in shared programs: 82071 -> 82155 (0.10%) instructions in affected programs: 792 -> 876 (10.61%) helped: 0 HURT: 12 total temps in shared programs: 12775 -> 12778 (0.02%) temps in affected programs: 27 -> 30 (11.11%) helped: 0 HURT: 3 total cycles in shared programs: 128403 -> 128499 (0.07%) cycles in affected programs: 864 -> 960 (11.11%) helped: 0 HURT: 12 The same regression for the few GTK shaders that happens with the R500 nir fcsel lowering also happens here due to the nir_move_vec_src_uses_to_dest. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6126 Reviewed-by: Filip Gawin <filip.ga...@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26816> --- src/gallium/drivers/r300/compiler/nir_to_rc.c | 1 + src/gallium/drivers/r300/compiler/r300_nir.h | 2 ++ src/gallium/drivers/r300/compiler/r300_nir_algebraic.py | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/src/gallium/drivers/r300/compiler/nir_to_rc.c b/src/gallium/drivers/r300/compiler/nir_to_rc.c index a54cd0c2f0d..1345b99859e 100644 --- a/src/gallium/drivers/r300/compiler/nir_to_rc.c +++ b/src/gallium/drivers/r300/compiler/nir_to_rc.c @@ -2451,6 +2451,7 @@ const void *nir_to_rc_options(struct nir_shader *s, if (s->info.stage == MESA_SHADER_VERTEX) { if (is_r500) NIR_PASS_V(s, r300_nir_lower_fcsel_r500); + NIR_PASS_V(s, r300_nir_lower_flrp); } NIR_PASS_V(s, nir_opt_dce); diff --git a/src/gallium/drivers/r300/compiler/r300_nir.h b/src/gallium/drivers/r300/compiler/r300_nir.h index b546a35077d..bf31307fdcc 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir.h +++ b/src/gallium/drivers/r300/compiler/r300_nir.h @@ -83,4 +83,6 @@ extern bool r300_nir_post_integer_lowering(struct nir_shader *shader); extern bool r300_nir_lower_fcsel_r500(nir_shader *shader); +extern bool r300_nir_lower_flrp(nir_shader *shader); + #endif /* R300_NIR_H */ diff --git a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py index 361549bd419..d2c83cdf56f 100644 --- a/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py +++ b/src/gallium/drivers/r300/compiler/r300_nir_algebraic.py @@ -94,6 +94,11 @@ r300_nir_clean_double_fneg = [ (('fneg', ('fneg', a)), a) ] +# This is very late flrp lowering to clean up after bcsel->fcsel->flrp. +r300_nir_lower_flrp = [ + (('flrp', a, b, c), ('ffma', b, c, ('ffma', ('fneg', a), c, a))) +] + r300_nir_post_integer_lowering = [ # If ffloor result is used only for indirect constant load, we can get rid of it # completelly as ntt emits ARL by default which already does the flooring. @@ -160,5 +165,8 @@ def main(): f.write(nir_algebraic.AlgebraicPass("r300_nir_post_integer_lowering", r300_nir_post_integer_lowering).render()) + f.write(nir_algebraic.AlgebraicPass("r300_nir_lower_flrp", + r300_nir_lower_flrp).render()) + if __name__ == '__main__': main()