From c495c6c2957c7c30cedeaa218c2caf443ac04797 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 12 May 2020 19:07:48 -0400 Subject: [PATCH] pan/mdg: Add pack_unorm_4x8 via 8-bit More efficient than the 32-bit version in NIR. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/midgard/midgard_compile.c | 2 ++ src/panfrost/midgard/midgard_nir.h | 1 + src/panfrost/midgard/midgard_nir_algebraic.py | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 68af4859da2..59341feba9b 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -383,6 +383,8 @@ optimise_nir(nir_shader *nir, unsigned quirks) if (quirks & MIDGARD_BROKEN_LOD) NIR_PASS_V(nir, midgard_nir_lod_errata); + NIR_PASS(progress, nir, midgard_nir_lower_algebraic_early); + do { progress = false; diff --git a/src/panfrost/midgard/midgard_nir.h b/src/panfrost/midgard/midgard_nir.h index 4efd3c5c9f1..e31949c0c2b 100644 --- a/src/panfrost/midgard/midgard_nir.h +++ b/src/panfrost/midgard/midgard_nir.h @@ -1,6 +1,7 @@ #include #include "nir.h" +bool midgard_nir_lower_algebraic_early(nir_shader *shader); bool midgard_nir_lower_algebraic_late(nir_shader *shader); bool midgard_nir_scale_trig(nir_shader *shader); bool midgard_nir_cancel_inot(nir_shader *shader); diff --git a/src/panfrost/midgard/midgard_nir_algebraic.py b/src/panfrost/midgard/midgard_nir_algebraic.py index 11d2a91fed7..b611ba5a94c 100644 --- a/src/panfrost/midgard/midgard_nir_algebraic.py +++ b/src/panfrost/midgard/midgard_nir_algebraic.py @@ -30,6 +30,10 @@ a = 'a' b = 'b' c = 'c' +algebraic = [ + (('pack_unorm_4x8', a), ('pack_32_4x8', ('f2u8', ('fround_even', ('fmul', ('fsat', a), 255.0))))) +] + algebraic_late = [ # ineg must be lowered late, but only for integers; floats will try to # have modifiers attached... hence why this has to be here rather than @@ -141,6 +145,9 @@ def run(): print('#include "midgard_nir.h"') + print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic_early", + algebraic).render()) + print(nir_algebraic.AlgebraicPass("midgard_nir_lower_algebraic_late", algebraic_late + converts + constant_switch).render()) -- 2.30.2