nir/opt_algebraic_tests: Add support for expression swizzles.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39369>
This commit is contained in:
Emma Anholt 2026-01-14 09:48:03 -08:00 committed by Marge Bot
parent c30c383d4d
commit a90163a15a
2 changed files with 10 additions and 8 deletions

View file

@ -431,6 +431,8 @@ class Expression(Value):
self.nnan = cond.pop('nnan', False)
self.ninf = cond.pop('ninf', False)
self.contract = cond.pop('contract', False)
# Single component index of the swizzle of the output of this
# expression, or -1 if no swizzle (all components)
self.swizzle = - \
1 if m.group('swizzle') is None else swizzles[m.group(
'swizzle').removeprefix('.')]
@ -1342,9 +1344,6 @@ def expression_is_unsupported(expr):
if any(expression_is_unsupported(src) for src in expr.sources):
return True
if expr.swizzle != -1:
return True
broken_opcodes = [
# medium precision means that the compiler can do whatever it wants which makes it unsuitable for testing.
"f2fmp", "i2imp", "f2imp", "f2ump", "i2fmp", "u2fmp",
@ -1480,6 +1479,9 @@ def get_expression_def(expr, name, value_comps, variable_map, defs, expr_conds,
defs.append(f"nir_def *{def_name} = nir_{opcode}(b, {', '.join(srcs)});")
if expr.swizzle != -1:
def_name = f"nir_channel(b, {def_name}, {expr.swizzle})"
if expr.cond != None and isinstance(expr, Expression):
# These do not matter for correctness
if expr.cond not in ["is_used_once", "is_not_used_by_if"]:

View file

@ -2048,7 +2048,7 @@ for pack, bits, compbits in [('pack_64_2x32', 64, 32), ('pack_32_2x16', 32, 16)]
((unpack, (pack + '_split', a, b)), ('vec2', a, b)),
((unpack, (pack, a)), a),
((pack + '_split', (unpack + '_split_x', a), (unpack + '_split_y', a)), a),
((pack + '_split', (unpack, a), (unpack + '.y', a)), a, 'true', TestStatus.UNSUPPORTED),
((pack + '_split', (unpack, a), (unpack + '.y', a)), a),
((pack, ('vec2', (unpack + '_split_x', a), (unpack + '_split_y', a))), a),
((pack, (unpack, a)), a),
]
@ -2180,13 +2180,13 @@ optimizations.extend([
# Mixed 16-bit/8-bit loads vectorized to 8-bit vector load and then lowered to 32-bit
(('ior', ('u2u16', ('unpack_32_4x8', a)), ('ishl', ('u2u16', ('unpack_32_4x8.y', a)), 8)),
('unpack_32_2x16_split_x', a), '!options->lower_unpack_32_2x16_split', TestStatus.UNSUPPORTED),
('unpack_32_2x16_split_x', a), '!options->lower_unpack_32_2x16_split'),
(('ior', ('u2u16', ('unpack_32_4x8.z', a)), ('ishl', ('u2u16', ('unpack_32_4x8.w', a)), 8)),
('unpack_32_2x16_split_y', a), '!options->lower_unpack_32_2x16_split', TestStatus.UNSUPPORTED),
('unpack_32_2x16_split_y', a), '!options->lower_unpack_32_2x16_split'),
# Prefer 16bit unpack/extract because it's easier to vectorize
(('i2i16', ('unpack_32_4x8(xz_components_unused).y', a)), ('extract_i8', ('unpack_32_2x16.x', a), 1), '!options->lower_extract_byte', TestStatus.UNSUPPORTED),
(('i2i16', ('unpack_32_4x8(xz_components_unused).w', a)), ('extract_i8', ('unpack_32_2x16.y', a), 1), '!options->lower_extract_byte', TestStatus.UNSUPPORTED),
(('i2i16', ('unpack_32_4x8(xz_components_unused).y', a)), ('extract_i8', ('unpack_32_2x16.x', a), 1), '!options->lower_extract_byte'),
(('i2i16', ('unpack_32_4x8(xz_components_unused).w', a)), ('extract_i8', ('unpack_32_2x16.y', a), 1), '!options->lower_extract_byte'),
(('extract_u16', ('extract_i16', a, b), 0), ('extract_u16', a, b)),
(('extract_u16', ('extract_u16', a, b), 0), ('extract_u16', a, b)),