From 129e37bab6e011cd8e78a8139a34f04212b424ad Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Fri, 13 Dec 2024 18:48:51 +0800 Subject: [PATCH] nir: do not generate b2i64 when driver want to lower it This is found on GFX12 by: KHR-GL43.shader_ballot_tests.ShaderBallotBitmasks ACO does not support it. Part-of: --- src/compiler/nir/nir_opt_algebraic.py | 44 ++++++++++++++++----------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index de6a4dd622d..3e462b7ce89 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -1417,6 +1417,33 @@ for op in [ ((op[0] + '16', a, b), vector_cmp(op[2], op[1], 'abcdefghijklmnop'), 'options->lower_vector_cmp'), ]) +# D3D Boolean emulation +for s in [8, 16, 32, 64]: + cond = 'true' + if s == 64: + cond = '!(options->lower_int64_options & nir_lower_conv64)' + + optimizations.extend([ + (('bcsel@{}'.format(s), a, -1, 0), ('ineg', ('b2i', 'a@1')), cond), + (('bcsel@{}'.format(s), a, 0, -1), ('ineg', ('b2i', ('inot', a))), cond), + (('bcsel@{}'.format(s), a, 1, 0), ('b2i', 'a@1'), cond), + (('bcsel@{}'.format(s), a, 0, 1), ('b2i', ('inot', a)), cond), + ]) + +optimizations.extend([ + (('iand', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), + ('ineg', ('b2i', ('iand', a, b)))), + (('ior', ('ineg', ('b2i','a@1')), ('ineg', ('b2i', 'b@1'))), + ('ineg', ('b2i', ('ior', a, b)))), + (('ieq', ('ineg', ('b2i', 'a@1')), -1), a), + (('ine', ('ineg', ('b2i', 'a@1')), -1), ('inot', a)), + (('ige', ('ineg', ('b2i', 'a@1')), 0), ('inot', a)), + (('ilt', ('ineg', ('b2i', 'a@1')), 0), a), + (('ult', 0, ('ineg', ('b2i', 'a@1'))), a), + (('iand', ('ineg', ('b2i', a)), 1.0), ('b2f', a)), + (('iand', ('ineg', ('b2i', a)), 1), ('b2i', a)), +]) + optimizations.extend([ (('feq', ('seq', a, b), 1.0), ('feq', a, b)), (('feq', ('sne', a, b), 1.0), ('fneu', a, b)), @@ -1681,23 +1708,6 @@ optimizations.extend([ (('bcsel', a, b, b), b), (('~fcsel', a, b, b), b), - # D3D Boolean emulation - (('bcsel', a, -1, 0), ('ineg', ('b2i', 'a@1'))), - (('bcsel', a, 0, -1), ('ineg', ('b2i', ('inot', a)))), - (('bcsel', a, 1, 0), ('b2i', 'a@1')), - (('bcsel', a, 0, 1), ('b2i', ('inot', a))), - (('iand', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), - ('ineg', ('b2i', ('iand', a, b)))), - (('ior', ('ineg', ('b2i','a@1')), ('ineg', ('b2i', 'b@1'))), - ('ineg', ('b2i', ('ior', a, b)))), - (('ieq', ('ineg', ('b2i', 'a@1')), -1), a), - (('ine', ('ineg', ('b2i', 'a@1')), -1), ('inot', a)), - (('ige', ('ineg', ('b2i', 'a@1')), 0), ('inot', a)), - (('ilt', ('ineg', ('b2i', 'a@1')), 0), a), - (('ult', 0, ('ineg', ('b2i', 'a@1'))), a), - (('iand', ('ineg', ('b2i', a)), 1.0), ('b2f', a)), - (('iand', ('ineg', ('b2i', a)), 1), ('b2i', a)), - # With D3D booleans, imax is AND and umax is OR (('imax', ('ineg', ('b2i', 'a@1')), ('ineg', ('b2i', 'b@1'))), ('ineg', ('b2i', ('iand', a, b)))),