From fba82797d720c930051d1593062840713e874250 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Tue, 23 May 2023 15:49:38 -0700 Subject: [PATCH] nir: Optimize unpacking 16 bit values that were originally packed I was seeing u2u64 still in my final shader after pack/unpack were lowered, which sounds to me like some other optimizations are missing for detecting the post-lowering pack/unpack patterns, but let's at least add some patterns for the simple cases. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index f0cba7467af..c308db36a74 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1601,6 +1601,10 @@ optimizations.extend([ (('pack_64_2x32', ('unpack_64_2x32', a)), a), (('pack_double_2x32_dxil', ('unpack_double_2x32_dxil', a)), a), + (('unpack_64_4x16', ('pack_64_4x16', a)), a), + (('unpack_64_4x16', ('pack_64_2x32', ('vec2', ('pack_32_2x16_split', a, b), ('pack_32_2x16_split', c, d)))), ('vec4', a, b, c, d)), + (('unpack_64_4x16', ('pack_64_2x32_split', ('pack_32_2x16_split', a, b), ('pack_32_2x16_split', c, d))), ('vec4', a, b, c, d)), + # Comparing two halves of an unpack separately. While this optimization # should be correct for non-constant values, it's less obvious that it's # useful in that case. For constant values, the pack will fold and we're