rdna2spirv: support vcc and null destinations on s_getpc_b64 and reject odd pairs #1632

Open
github-bot wants to merge 2 commits from github-bot/gh-1632 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 06:31 UTC · original
IlyassRS3:feat/s-getpc-b64-destinations → main · +720 −17 · 5 files · 2 commits · open

Item ID: SHADER-GETPC-DESTINATIONS
Claim: #1608
Addresses the s_getpc_b64 destinations item from #1608 and review feedback on odd-aligned pairs ([s105,vcc_lo], s[1:2]).

Summary

  • tools/rdna2spirv.py (s_getpc_b64 lowering): accept even-aligned 2-SGPR pairs (s[0:1]..s[104:105]), vcc (s[106:107] -> %vcc / %vcc_hi), and null (sdst=125, discarded without setting uses_codebase, while still requiring ; encoding: bytes). Keep odd-aligned SGPR pairs (s[1:2], s[105:106]) and slist ([s105,vcc_lo] from raw SDST 105) Unsupported per AMD RDNA 2 ISA §§3.2 and 3.6.3 so both disassembler paths agree in refusing them.
  • tools/rdna2spirv.py (translate wave-size detection): exclude s_getpc_b64, s_setpc_b64, and s_swappc_b64 from code_w64 since PC is 64-bit in wave32 too.
  • tools/rdna2spirv.py (Gen.global_address): accept vcc as a 64-bit saddr (refusing an emulated wave64 lane-mask pointer, matching s_load_*).
  • tools/rdna2spirv.py (fold_far_branches): fold s_getpc_b64..s_setpc_b64 far branches using even-aligned 2-SGPR pairs or vcc (leaving odd pairs unfolded).
  • tools/lane_masks.py: clear wave32 vcc_hi mask state when s_getpc_b64 vcc / s_load_dwordx2 vcc / s_buffer_load_dwordx2 vcc writes raw 64-bit data into vcc.
  • tools/wave64_emulate_opt.py: mark s_getpc_b64 vcc as raw VCC data in mark_vcc_data_moves() and preserve raw-VCC tracking across s_add_u32/s_addc_u32/s_sub_u32/s_subb_u32 updates to vcc_lo/vcc_hi.
  • docs/design.md: document the s_getpc_b64 destination contract row.
  • tests/semantic/test_s_getpc_destinations.py: 12 synthetic semantic tests across wave32, wave64, and --wave64-emulate, including raw-byte regressions covering both tools/rdna2_decode.py and the LLVM + check_printed_encodings path (plus live llvm-mc when installed).

Verification

  • python3 -W error -I tests/semantic/test_s_getpc_destinations.py -v: 12 passed, 0 failed (0.942s).
  • Mutation check against unpatched main (42537e7b6): 14 failed, 25 errors; against prior PR head 3966cb6a1: 17 failed (confirming odd-pair/raw-byte regressions catch the old acceptance).
  • python3 -I scripts/run_semantic_tests.py tests/semantic: 488 files, 6291 tests, 0 files failed (132s).
  • python3 -m pytest tests/test_shader_meta.py tests/test_rdna2_decode.py tests/test_pc_tail_ubo.py -q: 48 passed, 8 skipped, 653 subtests passed.
  • python3 -m compileall -q tools tests, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.
  • Prior GPU check by @⁠ecox982745 on RTX 4090 (NVIDIA 616.64, LLVM 23.1.6) passed s[104:105], vcc, and null in wave32 and emulated wave64.

AI-assisted: yes
GPUs tested: none locally (CPU interpreter + synthetic fixtures only; vcc/null/s[104:105] checked on RTX 4090 by @⁠ecox982745 in review; no game data)

**@⁠IlyassRS3** on GitHub · 2026-11-25 06:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632) `IlyassRS3:feat/s-getpc-b64-destinations` → `main` · +720 −17 · 5 files · 2 commits · open Item ID: `SHADER-GETPC-DESTINATIONS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 Addresses the `s_getpc_b64 destinations` item from https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 and review feedback on odd-aligned pairs (`[s105,vcc_lo]`, `s[1:2]`). ## Summary - **`tools/rdna2spirv.py` (`s_getpc_b64` lowering)**: accept even-aligned 2-SGPR pairs (`s[0:1]`..`s[104:105]`), `vcc` (`s[106:107]` -> `%vcc` / `%vcc_hi`), and `null` (`sdst=125`, discarded without setting `uses_codebase`, while still requiring `; encoding:` bytes). Keep odd-aligned SGPR pairs (`s[1:2]`, `s[105:106]`) and `slist` (`[s105,vcc_lo]` from raw SDST 105) `Unsupported` per AMD RDNA 2 ISA §§3.2 and 3.6.3 so both disassembler paths agree in refusing them. - **`tools/rdna2spirv.py` (`translate` wave-size detection)**: exclude `s_getpc_b64`, `s_setpc_b64`, and `s_swappc_b64` from `code_w64` since PC is 64-bit in wave32 too. - **`tools/rdna2spirv.py` (`Gen.global_address`)**: accept `vcc` as a 64-bit `saddr` (refusing an emulated wave64 lane-mask pointer, matching `s_load_*`). - **`tools/rdna2spirv.py` (`fold_far_branches`)**: fold `s_getpc_b64`..`s_setpc_b64` far branches using even-aligned 2-SGPR pairs or `vcc` (leaving odd pairs unfolded). - **`tools/lane_masks.py`**: clear wave32 `vcc_hi` mask state when `s_getpc_b64 vcc` / `s_load_dwordx2 vcc` / `s_buffer_load_dwordx2 vcc` writes raw 64-bit data into `vcc`. - **`tools/wave64_emulate_opt.py`**: mark `s_getpc_b64 vcc` as raw VCC data in `mark_vcc_data_moves()` and preserve raw-VCC tracking across `s_add_u32`/`s_addc_u32`/`s_sub_u32`/`s_subb_u32` updates to `vcc_lo`/`vcc_hi`. - **`docs/design.md`**: document the `s_getpc_b64` destination contract row. - **`tests/semantic/test_s_getpc_destinations.py`**: 12 synthetic semantic tests across wave32, wave64, and `--wave64-emulate`, including raw-byte regressions covering both `tools/rdna2_decode.py` and the LLVM + `check_printed_encodings` path (plus live `llvm-mc` when installed). ## Verification - `python3 -W error -I tests/semantic/test_s_getpc_destinations.py -v`: **12 passed, 0 failed** (0.942s). - Mutation check against unpatched `main` (`42537e7b6`): **14 failed, 25 errors**; against prior PR head `3966cb6a1`: **17 failed** (confirming odd-pair/raw-byte regressions catch the old acceptance). - `python3 -I scripts/run_semantic_tests.py tests/semantic`: **488 files, 6291 tests, 0 files failed** (132s). - `python3 -m pytest tests/test_shader_meta.py tests/test_rdna2_decode.py tests/test_pc_tail_ubo.py -q`: **48 passed, 8 skipped, 653 subtests passed**. - `python3 -m compileall -q tools tests`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. - Prior GPU check by @⁠ecox982745 on RTX 4090 (NVIDIA 616.64, LLVM 23.1.6) passed `s[104:105]`, `vcc`, and `null` in wave32 and emulated wave64. AI-assisted: yes GPUs tested: none locally (CPU interpreter + synthetic fixtures only; `vcc`/`null`/`s[104:105]` checked on RTX 4090 by @⁠ecox982745 in review; no game data)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:58:52 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 06:31 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 06:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632#pullrequestreview-6052871946) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-25 06:47 UTC · original

The vcc and null cases passed on my RTX 4090. I found one issue with the [s105,vcc_lo] case: the two project disassemblers disagree on the same input bytes, and AMD requires an even-aligned register pair for program-counter transfers. I would keep odd pairs unsupported in the lowering and far-branch folding, and add a raw-byte regression covering both disassemblers. AMD RDNA 2 ISA, §§3.2 and 3.6.3

Tested PR 3966cb6a1 against parent 42537e7b6 on Windows, LLVM 23.1.6 (gfx1013), NVIDIA driver 616.64. I initialized s104, s105, vcc_lo and vcc_hi to distinct values, executed one s_getpc_b64 at byte offset 16, and read all four words back from every lane. The synthetic code base was zero, so the next PC was 20.

Synthetic destination LLVM path on PR head Python decoder on PR head
s[104:105] control Both waves wrote (20,0) to the expected pair Same
vcc Both waves wrote (20,0) to VCC and kept both SGPRs Same
null Both waves kept all four sentinels Same
Raw SDST 105 (00 1f e9 be) LLVM prints s[104:105] and re-encodes SDST 104. The translator’s byte check refuses the listing. LLVM also rejects the explicit [s105,vcc_lo] spelling at assembly. Prints [s105,vcc_lo] and translates it. The GPU returned (17,20,0,47), placing the PC in that odd pair.

I ran native wave32 and emulated wave64 with 32-wide hardware subgroups. The 14 modules the head accepted passed SPIR-V validation and exact readback. The parent accepted only the aligned control through both decoders. The 11 PR semantic tests passed locally with SPIR-V Tools installed. The GPU check measures the translated SPIR-V behavior; native RDNA2 behavior for the odd encoding remains unmeasured here. AI-assisted verification.

**@⁠ecox982745** on GitHub · 2026-11-25 06:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155155126) The `vcc` and `null` cases passed on my RTX 4090. I found one issue with the `[s105,vcc_lo]` case: the two project disassemblers disagree on the same input bytes, and AMD requires an even-aligned register pair for program-counter transfers. I would keep odd pairs unsupported in the lowering and far-branch folding, and add a raw-byte regression covering both disassemblers. [AMD RDNA 2 ISA, §§3.2 and 3.6.3](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) Tested PR `3966cb6a1` against parent `42537e7b6` on Windows, LLVM 23.1.6 (`gfx1013`), NVIDIA driver 616.64. I initialized `s104`, `s105`, `vcc_lo` and `vcc_hi` to distinct values, executed one `s_getpc_b64` at byte offset 16, and read all four words back from every lane. The synthetic code base was zero, so the next PC was 20. | Synthetic destination | LLVM path on PR head | Python decoder on PR head | | --- | --- | --- | | `s[104:105]` control | Both waves wrote `(20,0)` to the expected pair | Same | | `vcc` | Both waves wrote `(20,0)` to VCC and kept both SGPRs | Same | | `null` | Both waves kept all four sentinels | Same | | Raw SDST 105 (`00 1f e9 be`) | LLVM prints `s[104:105]` and re-encodes SDST 104. The translator’s byte check refuses the listing. LLVM also rejects the explicit `[s105,vcc_lo]` spelling at assembly. | Prints `[s105,vcc_lo]` and translates it. The GPU returned `(17,20,0,47)`, placing the PC in that odd pair. | I ran native wave32 and emulated wave64 with 32-wide hardware subgroups. The 14 modules the head accepted passed SPIR-V validation and exact readback. The parent accepted only the aligned control through both decoders. The 11 PR semantic tests passed locally with SPIR-V Tools installed. The GPU check measures the translated SPIR-V behavior; native RDNA2 behavior for the odd encoding remains unmeasured here. AI-assisted verification.
Author
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 07:12 UTC · original

Thanks for the RTX 4090 + LLVM 23.1.6 check and for catching the odd-pair discrepancy, @⁠ecox982745!

Pushed 39f3139da to address this:

  • Tightened s_getpc_b64 lowering and _far_branch_pair / fold_far_branches to accept only even-aligned 2-SGPR pairs (s[0:1]..s[104:105]), vcc, and null, keeping [s105,vcc_lo] and odd pairs (s[1:2], s[105:106]) Unsupported per AMD RDNA 2 ISA §§3.2 and 3.6.3 so both disassembler paths agree in refusing them.
  • Updated docs/design.md and added test_odd_register_pairs_rejected_in_lowering_and_far_branch plus test_raw_bytes_across_both_disassemblers in tests/semantic/test_s_getpc_destinations.py covering SDST 104, vcc (106), null (125), odd SDST 105 (00 1f e9 be), and odd SDST 1 (00 1f 81 be) across wave32, wave64, and --wave64-emulate through both tools/rdna2_decode.py and the LLVM + check_printed_encodings path (plus live llvm-mc when present).
  • Re-verified: test_s_getpc_destinations.py 12/12 (-W error -I), mutation vs 3966cb6a1 fails 17 subtests, full semantic suite 488 files, 6291 tests, 0 files failed.
**@⁠IlyassRS3** on GitHub · 2026-11-25 07:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155597711) Thanks for the RTX 4090 + LLVM 23.1.6 check and for catching the odd-pair discrepancy, @⁠ecox982745! Pushed `39f3139da` to address this: - Tightened `s_getpc_b64` lowering and `_far_branch_pair` / `fold_far_branches` to accept only even-aligned 2-SGPR pairs (`s[0:1]`..`s[104:105]`), `vcc`, and `null`, keeping `[s105,vcc_lo]` and odd pairs (`s[1:2]`, `s[105:106]`) `Unsupported` per AMD RDNA 2 ISA §§3.2 and 3.6.3 so both disassembler paths agree in refusing them. - Updated `docs/design.md` and added `test_odd_register_pairs_rejected_in_lowering_and_far_branch` plus `test_raw_bytes_across_both_disassemblers` in `tests/semantic/test_s_getpc_destinations.py` covering SDST 104, `vcc` (106), `null` (125), odd SDST 105 (`00 1f e9 be`), and odd SDST 1 (`00 1f 81 be`) across wave32, wave64, and `--wave64-emulate` through both `tools/rdna2_decode.py` and the LLVM + `check_printed_encodings` path (plus live `llvm-mc` when present). - Re-verified: `test_s_getpc_destinations.py` 12/12 (`-W error -I`), mutation vs `3966cb6a1` fails 17 subtests, full semantic suite `488 files, 6291 tests, 0 files failed`.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-25 07:14 UTC · original

Confirmed the fix in 39f3139da on the RTX 4090 (Windows, NVIDIA 616.64). On the previous head the Python decoder accepted raw SDST 105 while the LLVM path refused it. Both paths now refuse the same synthetic bytes in native wave32 and emulated wave64.

The aligned control, vcc, and null still produce exact four-word readbacks in every lane through both decoders: 12 modules passed SPIR-V validation and all 576 lane results matched. The focused CPU suite also passed 12/12 with live LLVM 23.1.6 and SPIR-V Tools available. This resolves my earlier review finding.

**@⁠ecox982745** on GitHub · 2026-11-25 07:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155647552) Confirmed the fix in `39f3139da` on the RTX 4090 (Windows, NVIDIA 616.64). On the previous head the Python decoder accepted raw SDST 105 while the LLVM path refused it. Both paths now refuse the same synthetic bytes in native wave32 and emulated wave64. The aligned control, `vcc`, and `null` still produce exact four-word readbacks in every lane through both decoders: 12 modules passed SPIR-V validation and all 576 lane results matched. The focused CPU suite also passed 12/12 with live LLVM 23.1.6 and SPIR-V Tools available. This resolves my earlier review finding.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 10:17 UTC · original

Independent verification (native Windows; RTX 4070 SUPER + AMD gfx1036 iGPU): contract row added matching code (even-aligned SGPR pairs s[0:1]..s[104:105], vcc, null enc 125, odd-pair rejection per RDNA2 ISA). Odd-pair rejection verified in lowering + fold_far_branches (which also fixes the hardcoded +4 folded-target offset); wave64-marker/vcc-data-move interactions consistent. New test_s_getpc_destinations.py 12/12 incl. raw-byte dual-disassembler regressions; FULL semantic suite 488 files / 6,291 tests / 0 failed — matches claim. GPU: rebuilt runtime, run_gpu_tests.py --filter ps_far_branch --require-pass -> PASS 4096/4096 pixels exact on BOTH GPUs. No vcc/null GPU fixture exists; semantic coverage is thorough. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 10:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7159500196) Independent verification (native Windows; RTX 4070 SUPER + AMD gfx1036 iGPU): contract row added matching code (even-aligned SGPR pairs s[0:1]..s[104:105], vcc, null enc 125, odd-pair rejection per RDNA2 ISA). Odd-pair rejection verified in lowering + fold_far_branches (which also fixes the hardcoded +4 folded-target offset); wave64-marker/vcc-data-move interactions consistent. New `test_s_getpc_destinations.py` 12/12 incl. raw-byte dual-disassembler regressions; FULL semantic suite 488 files / 6,291 tests / 0 failed — matches claim. GPU: rebuilt runtime, `run_gpu_tests.py --filter ps_far_branch --require-pass` -> **PASS 4096/4096 pixels exact on BOTH GPUs**. No vcc/null GPU fixture exists; semantic coverage is thorough. AI-assisted verification.
This pull request has changes conflicting with the target branch.
  • docs/design.md
  • tools/rdna2spirv.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1632/head:github-bot/gh-1632'
git switch 'github-bot/gh-1632'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1632'
git switch 'github-bot/gh-1632'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1632'
git switch 'github-bot/gh-1632'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1632'
git switch 'main'
git merge --squash 'github-bot/gh-1632'
git switch 'main'
git merge --ff-only 'github-bot/gh-1632'
git switch 'main'
git merge 'github-bot/gh-1632'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.