Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ jobs:
tests/startup_stream_fetch_check.py \
tests/compute_entry_layout_check.py \
tests/startup_ngg_slice_check.py \
tests/startup_gfx2hlsl_handler_arity_check.py \
tests/run_checks_parallel_check.py
build-and-test:
name: Build and test on Windows
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ python3 -m venv out/pe-env
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_f32_lg_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_f32_nan_check.py
./out/pe-env/bin/python -B tests/run_checks_parallel_check.py
./out/pe-env/bin/python -B tests/startup_gfx2hlsl_handler_arity_check.py
```

`tests/pixel_aot_check.py binary` additionally needs LLVM with gfx1013 support
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,8 @@ if(EXISTS "${INTAKE_PYTHON}")
# gfx2hlsl lowers s_bitcmp1_b32 and s_bitcmp0_b32 (SOPC): CPU evaluation of the translated SCC test.
add_test(NAME startup_gfx2hlsl_s_bitcmp COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_bitcmp_check.py")
add_test(NAME startup_gfx2hlsl_handler_arity COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_handler_arity_check.py")
# VOP1/VOP2 sub-dword addressing (SDWA) in the translator (#1141), checked against the pixel AOT
# lowering of the same selections.
add_test(NAME startup_gfx2hlsl_sdwa COMMAND "${INTAKE_PYTHON}" -B
Expand Down
47 changes: 47 additions & 0 deletions tests/startup_gfx2hlsl_handler_arity_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Verify scalar operand counts through the startup translator's Stage entry point."""
import sys
from pathlib import Path
from types import SimpleNamespace

HERE = Path(__file__).resolve().parent
sys.path.insert(0, str(HERE.parent / 'tools'))
sys.path.insert(0, str(HERE.parent / 'tools' / 'startup'))
import gfx2hlsl as G # noqa: E402


def translate(name, operands):
pipe = SimpleNamespace(root={'params': [], 'flags': 0})
text = ' '.join((name, ', '.join(operands))).strip()
refusals = []
stage = G.Stage(pipe, 'ps', b'', refusals=refusals, decoded=[(0, 4, name, text)])
return refusals, stage.blocks


def check(name, operands, expected_output):
refusals, blocks = translate(name, operands)
assert not refusals, (name, operands, refusals)
assert any(expected_output in line for _, lines, _ in blocks for line in lines), (name, blocks)

for invalid in ((), operands[:-1], (*operands, 's18')):
refusals, blocks = translate(name, invalid)
expected = 'with %d operands, expected %d' % (len(invalid), len(operands))
assert len(refusals) == 1 and expected in refusals[0][0], (name, invalid, refusals)
assert not blocks, (name, invalid, blocks)


def main():
for condition in ('eq', 'lg', 'gt', 'ge', 'lt', 'le'):
for kind in ('i32', 'u32'):
check(f's_cmp_{condition}_{kind}', ('s12', 's14'), 'scc = ')
check(f's_cmpk_{condition}_{kind}', ('s12', '5'), 'scc = ')

for width, dst, src in ((32, 's12', 's14'), (64, 's[12:13]', 's[14:15]')):
for operation in ('and_saveexec', 'or_saveexec', 'andn2_wrexec'):
check(f's_{operation}_b{width}', (dst, src), 'exec = ')
check(f's_cselect_b{width}', (dst, src, '1'), 'scc ? ')
check('s_andn2_saveexec_b64', ('s[12:13]', 's[14:15]'), 'exec = ')
print('startup gfx2hlsl scalar arity: 33 accepted instructions and 99 refusals')


if __name__ == '__main__':
main()
12 changes: 11 additions & 1 deletion tools/startup/gfx2hlsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,8 @@ def src_sym(t):
return None

def op_s_and_saveexec_b64(self, ops, mods, text='exec & {0}'):
if len(ops) != 2:
raise Unsupported('saveexec with %d operands, expected 2' % len(ops))
dst = reg_range(ops[0])
if not dst or dst[0] != 's':
raise Unsupported('saveexec destination %s' % ops[0])
Expand All @@ -929,6 +931,8 @@ def op_s_andn2_saveexec_b64(self, ops, mods):
self.op_s_and_saveexec_b64(ops, mods, '{0} & ~exec')

def op_s_andn2_wrexec_b64(self, ops, mods):
if len(ops) != 2:
raise Unsupported('wrexec with %d operands, expected 2' % len(ops))
dst = reg_range(ops[0])
if not dst or dst[0] != 's':
raise Unsupported('wrexec destination %s' % ops[0])
Expand All @@ -950,6 +954,8 @@ def op_s_cselect_b64(self, ops, mods):
self.scalar_select(ops, True)

def scalar_select(self, ops, pair):
if len(ops) != 3:
raise Unsupported('scalar select with %d operands, expected 3' % len(ops))
low = [('s%d' % reg_range(t)[1]) if reg_range(t) and reg_range(t)[0] == 's' else t for t in ops]
if pair and 'm0' in low:
raise Unsupported('64-bit scalar operand m0')
Expand Down Expand Up @@ -1973,8 +1979,12 @@ def declarations(self):
SHIFT_ADD = {'s_lshl1_add_u32': 1, 's_lshl2_add_u32': 2, 's_lshl3_add_u32': 3, 's_lshl4_add_u32': 4}
for _name, _op in (('eq', '=='), ('lg', '!='), ('gt', '>'), ('ge', '>='), ('lt', '<'), ('le', '<=')):
for _typ, _cast in (('i32', 'int({0}) %s int({1})'), ('u32', '{0} %s {1}')):
def _make(op=_op, cast=_cast):
def _make(op=_op, cast=_cast, name='s_cmp_%s_%s' % (_name, _typ)):
def handler(self, ops, mods):
# A scalar compare reads exactly two sources; refusing any other count keeps a malformed
# instruction a refusal rather than an index error in the batch translator.
if len(ops) != 2:
raise Unsupported('%s with %d operands, expected 2' % (name, len(ops)))
self.set_scc((cast % op).format(self.u(ops[0]), self.u(ops[1])))
return handler
setattr(Stage, 'op_s_cmp_%s_%s' % (_name, _typ), _make())
Expand Down
Loading