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

Closed
IlyassRS3 wants to merge 2 commits from upstream-pr/1632 into main
IlyassRS3 commented 2026-11-25 06:31:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T06:31:39Z.


Item ID: SHADER-GETPC-DESTINATIONS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154632603
Addresses the s_getpc_b64 destinations item from https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154337920 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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486416725 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1632). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T06:31:39Z. --- Item ID: `SHADER-GETPC-DESTINATIONS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154632603 Addresses the `s_getpc_b64 destinations` item from https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7154337920 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)
copilot-pull-request-reviewer[bot] commented 2026-11-25 06:31:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T06:31:52Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052871946 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1632#pullrequestreview-6052871946). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T06:31:52Z. **Review:** COMMENTED --- 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.
ecox982745 commented 2026-11-25 06:47:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T06:47:10Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7155155126 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155155126). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-25T06:47:10Z. --- 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.
IlyassRS3 commented 2026-11-25 07:12:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T07:12:03Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7155597711 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155597711). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:12:03Z. --- 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`.
ecox982745 commented 2026-11-25 07:14:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T07:14:45Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7155647552 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7155647552). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-25T07:14:45Z. --- 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.
whoalin1 commented 2026-11-25 10:17:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T10:17:46Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7159500196 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1632#issuecomment-7159500196). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T10:17:46Z. --- 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.
MoonEyes commented 2026-11-28 02:50:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:50:40Z.


Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/design.md, tools/rdna2spirv.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232629931 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1632#issuecomment-7232629931). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:50:40Z. --- Hi @IlyassRS3, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `docs/design.md`, `tools/rdna2spirv.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:47:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:47:49Z.

Review: CHANGES_REQUESTED


This PR cannot merge in its current state:

  • Merge conflicts with main in docs/design.md and tools/rdna2spirv.py.
  • Failing CI (translator-tests, linux-gpu-tools, stdlib-tests-linux, windows, macos, macos-python, check).

Please rebase onto current main and obtain a green CI run.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130620405 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1632#pullrequestreview-6130620405). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:47:49Z. **Review:** CHANGES_REQUESTED --- This PR cannot merge in its current state: - **Merge conflicts** with `main` in `docs/design.md` and `tools/rdna2spirv.py`. - **Failing CI** (`translator-tests`, `linux-gpu-tools`, `stdlib-tests-linux`, `windows`, `macos`, `macos-python`, `check`). Please rebase onto current `main` and obtain a green CI run. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:36:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:36:55Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317898773 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1632#issuecomment-7317898773). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:36:55Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1632
No description provided.