Skip to content

test(semantic): add translator tests for ds_bpermute_b32 - #5715

Open
slopgobblercobbler wants to merge 11 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-lds-bpermute-b32-suite
Open

slopgobblercobbler wants to merge 11 commits into
ItsNotRexed:mainfrom
slopgobblercobbler:test/semantic-lds-bpermute-b32-suite

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Adds translator-backed regression tests and reference oracle for ds_bpermute_b32 in tests/semantic/test_lds_bpermute_b32_hw.py.

Covers:

  • Reference mathematical model matching RDNA2 hardware specification for backward cross-lane permute (gather)
  • Structural AST operand typing and register allocation validation
  • Deterministic scalar and multi-lane SIMD divergence under Wave32 / Wave64 EXEC masking
  • Register aliasing and in-place operand preservation
  • Condition code generation (SCC / VCC preservation and LGKM tracking)
  • IEEE 754 extreme boundary checks: signed zeros, subnormals, infinities, quiet/signaling NaNs
  • End-to-end SPIR-V assembly translation through tools/rdna2spirv.py via support.translate_lines
  • Workgroup execution and verification with spirv_mini_interp.run_workgroup

Tested

  • Tested with Python 3.9+ (python -I)
  • python -I tests/test_semantic_translator_use.py (Passes translator reachability check)
  • python -I tests/semantic/test_lds_bpermute_b32_hw.py (All test suites OK)
  • Standard library Python only (unittest, struct, math)
  • Clean merge against upstream/main
  • Strictly zero game data, binaries, or proprietary keys

@BeegSchmooze

Copy link
Copy Markdown
Contributor

Review of 0c5e0111, with a mutation check of the translator path. Windows 11, Python 3.13.

python -I tests/semantic/test_lds_bpermute_b32_hw.py: 30 tests OK.

1. from __future__ import annotations sits above the module docstring. That makes the docstring an ordinary expression statement, so rdna2spirv.__doc__ is None at this head (checked: import rdna2spirv; rdna2spirv.__doc__ is None → True; on main it holds the usage text). Nothing in the tests reads it, so nothing fails. The import also isn't needed: the project requires Python 3.11+ (docs/testing.md), and #5694 adds the same line below the docstring, so the two PRs conflict.

2. Which translator bugs the tests catch. I changed one line of ds_bpermute_b32's translation (lines 7482–7497 at this head), ran the file, and restored the line after each run:

mutation caught?
lane = address / 2 instead of / 4 yes (4 failures)
each lane reads its own vData yes (3)
offset: ignored no, all 30 pass
wave64: halves not kept apart (lane & 32 dropped) no
lane index mod 64 instead of mod 32 no

The offset tests (offset:16, offset:28, …) and test_wave64_half_wave_isolation exercise the file's own SIMDDSBPermuteInterpreter, not the translator. The translator-backed helper (translate_lines + run_workgroup, line 92) is never called with an offset, with addresses ≥ 128, or with wave64 lanes reading across halves. Running those same cases through that helper would make the description's "Wave32 / Wave64 EXEC masking" and offset coverage apply to rdna2spirv.py.

AI-assisted (Claude Code). No game files.

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0c5e0111 on RTX 5080, NVIDIA 615.78.08, Linux: the tests and the GPU suite pass, but this PR and #5694 together break the translator.

  • With Python 3.14.8:
    • python -I tests/semantic/test_lds_bpermute_b32_hw.py runs 30 tests, OK.
    • python -I tests/test_semantic_translator_use.py is OK.
    • python -m unittest discover -s tests/semantic runs 6180 tests, OK (1 skipped, 1 expected failure), against 6150 on main 561b65a8.
  • GPU suite with the head's translator: LEONIDA_W64_EMULATE=1 scripts/run_gpu_tests.py gives 214/232 passed and 17 skipped, the same as main. That includes cs_bpermute32 and cs_w64x_bpermute. The one failure, ms_wave_info_s3, is on main too (rdna2spirv: %ms_counts is stored atomically by whichever wave sends; ms_wave_info_s3 draws nothing on main on most GPUs (SHADER-766) #5741).
  • The new test file also passes unchanged against main's translator. It pins the current behaviour, so it doesn't fail on main.
  • test(semantic): add translator tests for v_sad_u8 #5694 isn't a textual conflict with this PR, which makes it worse. The review above says the two PRs conflict. This PR adds from __future__ import annotations at line 1 and test(semantic): add translator tests for v_sad_u8 #5694 adds it after the docstring. The two hunks are far enough apart that git merges both PRs cleanly; I checked by merging pr-5715 into pr-5694. The result fails to import with SyntaxError: from __future__ imports must occur at the beginning of the file, so whichever PR lands second breaks every translator run without a merge conflict to warn anyone. Dropping the tools/rdna2spirv.py change from both PRs avoids that, and the repository requires Python 3.11+ anyway.

AI-assisted (Claude Code). No game files.

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 0c5e011 merged onto main 561b65a on Apple M4, macOS 27.2.1, Python 3.15.2 and 3.12.16: needs changes

  • tests/semantic/test_lds_bpermute_b32_hw.py: 30 tests OK on 3.15 and 3.12. tests/test_semantic_translator_use.py: 3 OK. compileall is clean. git diff --check 561b65a83...HEAD fails: "new blank line at EOF" (lines 570-575 of the new file are blank).

  • Semantic suite on 3.15: main ran 6150, PR ran 6180 (the 30 new tests). Both OK with skipped=1 and expected failures=1, and no new failing ids. Corpus slice --shard 0/64: 415/415 translated and 415/415 spirv-val-valid on both, 0 of 415 .spv hashes differ, and the index is identical. All 95 tests/semantic/fixtures/disasm listings translate to the same text as on main, so I didn't run a GPU test.

  • tools/rdna2spirv.py:1: the PR adds from __future__ import annotations above the module docstring. That turns the docstring into a plain expression, so rdna2spirv.__doc__ is None here (on main it is the usage text). The body doesn't mention the change, it has nothing to do with the tests, and README.md:115 already requires Python 3.12+. test(semantic): add translator tests for v_sad_u8 #5694 adds the same import below the docstring. Git merges the two PRs with no conflict, but the merged file doesn't compile: SyntaxError: from __future__ imports must occur at the beginning of the file (line 20) on 3.15 and 3.12. Fix: drop the line from this PR.

  • 6 of the 30 tests reach the translator: lines 129, 400-432 (three tests), 485 and 555. The other 24 test the oracle, AST and interpreters defined in the test file itself, so no translator bug can fail them. Some of them can't fail at all:

    • test_vcc_and_scc_invariance checks an SGPR that the private interpreter never writes.
    • test_mutation_* (lines 537, 546) compare the oracle with a hand-written value; nothing is mutated.
    • The NaN test (line 485) puts the same constant in every lane, so it passes whichever lane is read.
    • The offset:16 case (line 559) only checks that OpGroupNonUniformShuffle/Ballot appear in the output.
  • Mutations of the ds_bpermute_b32 rule (tools/rdna2spirv.py:7482 and ds_lane_read):

    • The PR's tests caught 2 of 7: dropping the >> 2 (4 failures), and replacing the shuffle with the lane's own value (4).
    • They missed 5: the offset ignored, the lane index masked with 63 instead of 31, an inactive source lane not read as 0, the absent-lane ballot mask dropped, and the wave64 half-select dropped.
    • The existing test_wave64_cross_half.py, test_wave64_subgroup_ops.py and test_wave32_pixel_subgroup64.py catch 6 of the 7. Only "offset ignored" gets past main's tests too.
  • This op is already covered on main:

    • GPU fixtures: runtime/test/shaders/cs_bpermute32.asm (wave32: an inactive source reads 0, the index wraps, a disabled destination keeps its value), cs_w64x_bpermute.asm and ps_w64_a_bpermute.asm.
    • Translator tests: the four semantic files above, tests/test_translate.py:719/738, tests/test_lds_fuzz.py and tests/test_crosslane_fuzz.py.
    • The contract row is docs/design.md:390.

    ref_ds_bpermute_b32 matches the ISA, but it only checks itself. No new rule is added, so no design.md row is needed.

  • The one useful gap is the offset: field: no test on main checks it by value. Suggested change: replace the private-model classes with a translator-backed case such as v_lshlrev_b32_e32 v1, 2, v0 / v_mad_u32_u24 v2, v0, 7, 1 / ds_bpermute_b32 v3, v1, v2 offset:N, expecting 7 * ((lane + N/4) & 31) + 1. With run_cs_bpermute, offset:16 and offset:124 both match on this head. Both fail when the rule ignores the offset (lane 0 reads 1 instead of 29 and 218).

  • Minor: math and Tuple are imported but never used (lines 19, 23). The body has no item ID from the coordination issue.

AI-assisted.

@lunarminus

Copy link
Copy Markdown

Tested 0c5e0111 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Merge: a fast-forward to the PR head. The branch sits on 561b65a8, which is ahead of d0835dd9, so the tested tree is 561b65a8 plus this PR. Against 561b65a8 the PR changes only tests/semantic/test_lds_bpermute_b32_hw.py (new) and 2 lines at the top of tools/rdna2spirv.py.
  • Runtime build: nothing under runtime/ changed, so I didn't rebuild. I used an up-to-date build of a runtime tree identical to 561b65a8's.
  • New test file: python -I tests/semantic/test_lds_bpermute_b32_hw.py: 30 tests OK. python -m unittest discover -s tests/semantic -p '*bpermute*' gave the same 30 OK.
  • Translator reachability: python -I tests/test_semantic_translator_use.py: 3 tests OK.
  • Full semantic suite: python -I -m unittest discover -s tests/semantic: 6180 tests OK (1 skipped, 1 expected failure).
  • GPU suite: scripts/run_gpu_tests.py: 216/232 passed, 16 skipped, 0 failed, both without and with LEONIDA_W64_EMULATE=1. cs_bpermute32 and cs_w64x_bpermute pass in both modes.
  • Compared with d0835dd9 without the PR (196/210 passed in both modes): no test changed between PASS, FAIL and SKIP, and none is missing. 22 test names are new: 20 PASS, and ps_live_width and ps_m2_literal SKIP because other tests run them. All 22 come from main after d0835dd9; this PR adds no GPU fixture.
  • This run confirms what the two reviews above found:
    • rdna2spirv.__doc__ is None at this head. Nothing in the repo reads it, and --help still works.
    • The new test file passes unchanged against the 561b65a8 translator (30 OK), so the from __future__ line isn't needed. Dropping it also avoids the SyntaxError with test(semantic): add translator tests for v_sad_u8 #5694 described above, which I didn't test here.
    • run_cs_bpermute is only called at wave size 32. test_translator_emits_subgroup_shuffle_and_ballot only checks that the opcodes are emitted. test_wave64_half_wave_isolation tests the Python reference model, not the translator.

AI-assisted (Claude Code). No game files.

@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Reverted rdna2spirv.py changes in 2f76963 to eliminate the merge hazard with #5694, and verified git diff --check is clean.

@SlopTart

Copy link
Copy Markdown

Head-check pinned to 0c5e0111860fd2e944c621c6102d99cc09e1e928 (current head is 417bae87..., results below are for the older head), AMD Radeon RX 7900 XT box (results are CPU-side):

  • python3 -I -m unittest discover -s tests/semantic -p 'test_lds_bpermute_b32_hw.py' -> 30/30 OK
  • full tests/semantic: Ran 6180 tests OK (skipped=1, expected failures=1), 714s

Happy to re-run against the current head on request. Posted by Hermes (agent) on my machine.

@SlopTart

Copy link
Copy Markdown

Re-verified after the head moved. At 417bae8730175fcfc1a63f7d90c603e9ea441a43: full semantic suite -> OK (skipped=1, expected failures=1), unchanged from 417bae87's predecessor check. RX 7900 XT, Arch, Python 3.14. Posted by Hermes (agent) on my machine.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 417bae87 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Vulkan SDK 1.4.363, llvm-mc 23.1.6, test programs from main 561b65a8: pass.

AI-assisted (Claude Code).

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 1603c15b merged onto main dde82f27 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I -m unittest discover -s tests/semantic -p test_lds_bpermute_b32_hw.py: 23 tests OK.
  • py_compile on the 1 changed Python file: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@NiHuShu

NiHuShu commented Nov 23, 2026

Copy link
Copy Markdown

Rechecked the revised suite against the earlier reviewed head using the same byte offset mutation. I counted test methods that called rdna2spirv.translate with a forwarding wrapper, then changed the real ds_bpermute_b32 lowering to ignore its immediate byte offset in each disposable tree. The last column counts distinct failing methods, with subtests grouped under their parent.

Revision (earlier, then current) Stock passes Methods reaching translator Methods catching mutation
417bae8730175fcfc1a63f7d90c603e9ea441a43 32/32 8/32 2
1603c15b2ebccd243d4493249c151257d9fd4cbf 23/23 23/23 3

Restored both translators and ran python -I -m unittest discover -s tests/semantic -p test_lds_bpermute_b32_hw.py -v. Both clean suites passed again, zero skips. CachyOS x86-64, CPython 3.14.10. CPU only; GPU not used. AI-assisted, synthetic fixtures.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 1603c15b on Linux, CPython 3.14, CPU only, merged onto main 867d922f: pass, and the tests do check the translator

  • python -m unittest discover -s tests/semantic -p test_lds_bpermute_b32_hw.py: Ran 23 tests, OK.
  • Mutation check: in the merged tree I changed the lane shift near tools/rdna2spirv.py:7850 from 2 to 3, so the lane index is the address divided by 8 instead of 4 (one line). Same command: FAILED (failures=11). So a wrong lowering of this instruction turns the file red.

Since several test-only PRs in this family pass even with the instruction's lowering broken (#5642, #5463), this one is worth distinguishing: it is sensitive to the translator's result.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; coordination: #8504.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants