Skip to content

rdna2spirv: a compare or a lane mask into a VGPR or vcc_hi stores the -1/0 word (RT-5) - #9474

Closed
glitterfartz wants to merge 1 commit into
ProjectLeonida:mainfrom
glitterfartz:shader-cmp-vgpr-destination
Closed

glitterfartz wants to merge 1 commit into
ProjectLeonida:mainfrom
glitterfartz:shader-cmp-vgpr-destination

Conversation

@glitterfartz

Copy link
Copy Markdown

Claimed in the coordination issue as: RT-5 (#7599)

What and why

v_cmp_*/v_cmp_class_* with a VGPR destination, and vcc_hi as any mask destination, were Unsupported (v_cmp destination / mask destination).

  • A VOP3 compare whose destination is a VGPR is the hardware's v_cmp_* vN, ... form: it writes the comparison result per lane as -1/0, not a wave mask. That is the same all-ones/zero word the translator already builds for the mask, so it now stores it (store_reg("vgpr", r, …)); a 64-bit mask destination takes the pair at r and r + 1.
  • vcc_hi is the upper half of VCC: bits 32..63 of the wave mask in wave64 (put_mask keeps the low half) and the scratch SGPR a wave32 shader uses for a second live mask. It now does the mask update and then OpStore %vcc_hi.

Four of the programs this unblocks are the ones the retail executable asks for through device slot 67 while booting (RT-5): with the change, 632 more pipeline-library programs translate, and the boot's remaining slot 67 … 0x80070057 comes from the CS thread-group-size SGPR bucket alone, which the last hunk only documents (evidence for the packing in the comment; not fixed here).

Tested

  • Translator counts over the 2,684 compute programs of 1.0.2.1's pipeline library (tools/shader_library.py, gfx1013 listings carved from the retail package), same command before and after (tools/rdna2spirv.py <work>/shaders/library/disasm --no-asm --shard i/4 ×4, then --merge): 1,773 of 2,684 translated and passed spirv-val before, 2,405 after (603 + 592 + 609 + 601, every one spirv-val valid). The 606 v_cmp destination and 66 mask destination refusals are gone; the next bucket (s_load_dwordx4 operands sgpr vcc) grows 34 → 73 because programs that used to stop at the compare now get that far.
  • tests/semantic/test_v_cmp_vgpr_destination.py (new): the four stores of v_cmp_lt_u32 / v_cmp_eq_u32 / v_cmp_lt_f32 into VGPRs on the interpreter in wave32 and wave64, a whole-wave v_cmp_eq_u32_e64 into a VGPR (s_bcnt1_i32_b32 of its word must see all lanes set), and the wave64-emulated module translating.
  • tests/semantic/test_cmp_f64.py: the f64 VGPR destination moved out of test_rejected_forms into test_vgpr_destination.
  • python -I scripts/run_semantic_tests.py tests/semantic: 448 files, 5,961 tests, 2 files failed — test_image_atomics_guard and test_image_store_d16, which fail identically on origin/main without this change (git stash baseline, same 47 + 1 failures).
  • GPU: none — the semantics are the ISA's -1/0 word, checked in the mini interpreter; no AMD/NVIDIA run of this specific rule yet, and the four boot programs that need it are blocked before dispatch anyway.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. (Only counts and .code file names of my own work folder are quoted; no bytes, no addresses.)
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed ("Compare into a VGPR or vcc_hi": corpus count over the pipeline library, plus the two test files).

… -1/0 word (RT-5)

`v_cmp_*`/`v_cmp_class_*` (and the lane-mask writers: `v_cmpx`, `v_mbcnt`,
`v_mad_u64_u32`'s sdst) refused a VGPR destination with `v_cmp destination` /
`mask destination`, and `vcc_hi` with the same messages. A VGPR destination is
the hardware's `v_cmp_* vN, ...` form: the comparison result per lane as -1/0,
which is exactly the all-ones/zero word the translator already builds for the
mask, so it stores that word (a 64-bit mask destination takes the pair at r and
r+1). `vcc_hi` is the upper half of VCC: bits 32..63 of the wave mask in wave64
(`put_mask` keeps the low half) and the scratch SGPR a wave32 shader uses for a
second live mask, so `OpStore %vcc_hi` follows the mask update.

Counted over the 2,684 compute programs of 1.0.2.1's pipeline library
(`tools/shader_library.py`), gfx1013 listings from the retail package:
1,773 of 2,684 translated and passed `spirv-val` before, 2,405 after (603 + 592
+ 609 + 601 over four shards, every one `spirv-val` valid). The 606 `v_cmp
destination` and 66 `mask destination` refusals are gone; the next bucket
(`s_load_dwordx4 operands sgpr vcc`) grows 34 -> 73 because programs that used
to stop at the compare now get that far.

Four of the programs this unblocks are the ones the retail executable asks for
through device slot 67 while booting (RT-5). Those four still refuse for the
unrelated reason in the last hunk's comment (`CS thread-group-size SGPR`).

Tests: tests/semantic/test_v_cmp_vgpr_destination.py (new: the four stores of
v_cmp_lt_u32/v_cmp_eq_u32/v_cmp_lt_f32 into VGPRs on the interpreter in wave32
and wave64, a whole-wave v_cmp_eq_u32_e64 into a VGPR, and the wave64-emulated
module translating) and tests/semantic/test_cmp_f64.py (the f64 VGPR
destination moved from test_rejected_forms to test_vgpr_destination).
python -I scripts/run_semantic_tests.py tests/semantic: 448 files, 5,961 tests,
2 files failed (test_image_atomics_guard, test_image_store_d16), both of which
fail identically on origin/main without this change.
@fengyansama

Copy link
Copy Markdown
Contributor

Tested ae34b1573 on NVIDIA RTX 4070 Ti (Driver 621.24 / Vulkan 1.4.357, Windows 11 Build 26300): pass

  • Semantic tests: tests/semantic/test_v_cmp_vgpr_destination.py (3/3 OK), tests/semantic/test_cmp_f64.py (6/6 OK).
  • GPU regression checks (scripts/run_gpu_tests.py, CI runtime-windows run 45037994684, llvm-mc 23.1.6, spirv-as/spirv-val 2026.4):
    • --filter ps_vcmp: 8/8 passed (ps_vcmp_64, ps_vcmp_f16, ps_vcmp_f16_e64, ps_vcmp_f32_nan, ps_vcmp_int32, ps_vcmpx_f16, ps_vcmpx_f16_e64, ps_vcmpx_forms, all 4096/4096 pixels exact, 8/8 spirv-val pass).
    • --filter ps_vcc: 1/1 passed (ps_vcc_x2).
    • --filter cs_mask_vgpr_exec: 1/1 passed.
    • --filter cs_w32_mask: 1/1 passed (cs_w32_mask_imm).
    • LEONIDA_W64_EMULATE=1 --filter cs_w64_mask: 2/2 passed (cs_w64_mask_detect, cs_w64_mask_imm).
  • AI-assisted run.

@renzyxx

renzyxx commented Nov 23, 2026

Copy link
Copy Markdown

Review of ae34b1573 (code read + toolchain check; no GPU run possible, see below). Windows 11 25H2, LLVM 23.1.6 llvm-mc from conda-forge llvm-tools (AMDGPU target), Python 3.14.

The PR's own tests pass here: test_v_cmp_vgpr_destination and test_cmp_f64, 12 of 12.

The vcc_hi half looks right. llvm-mc -mcpu=gfx1030 -mattr=+wavefrontsize32 assembles v_cmp_lt_u32_e64 vcc_hi, 3, v0 ([0x6b,0x00,0xc1,0xd4,...]), and the same SDST 107 is an invalid encoding in wave64, which matches "the scratch SGPR a wave32 shader uses".

The VGPR-destination half: I could not find that form in the ISA.

  • llvm-mc refuses to assemble it on gfx1013 and gfx1030, wave32 and wave64: v_cmp_lt_u32_e64 v1, 3, v0 -> error: invalid operand for instruction. That also means a GPU fixture for it can't be built with runtime/test/shaders/build.py, which is why I have no GPU result.
  • The other direction: I disassembled every VOP3 compare encoding on gfx1013 (all 256 opcodes of the VOPC range at VOP3 opcodes 0x000-0x0FF, times SDST field values 0-254, src0 = inline 3, src1 = v0; 65,280 words) in wave32 and wave64. That gives 45,980 / 45,505 v_cmp* lines and 0 with a VGPR destination. The 7-bit SDST field decodes only as sN/s[N:N+1], vcc_lo/vcc_hi/vcc, m0, null or exec*; 128+ prints Invalid immediate, and 255 crashes llvm-mc 23.1.6.

So with this LLVM, shader_disasm (the --disasm path of tools/shader_library.py, --mcpu gfx1013) should never print a v_cmp_* vN, ... line. Which llvm-mc version produced the listings with the 606 v_cmp destination refusals? If it is a different version, a line or two of the compare's encoding (from the ; encoding: comment, no surrounding code) would show what it really is. If the field really holds a VGPR-looking value, I'd suspect a desync in those listings (a misplaced code start, or a literal read as an instruction) rather than a real per-lane -1/0 form. Translating it would then make 632 programs spirv-val-valid while computing the wrong thing, and the boot's slot 67 programs would get that code.

Suggestion: split the PR. Merge the vcc_hi part (it has an assembler-confirmed encoding), and keep the VGPR-destination rule until the listing question is answered. The contract row in docs/design.md would then say how the form was confirmed beyond the corpus count.

Not tested: a GPU run (the form can't be assembled), and the full translator suite with this PR on my machine.

AI-assisted (Claude Code). Every result above comes from real llvm-mc and unittest runs on this machine. No game data used or quoted.

@sean4586

Copy link
Copy Markdown

Tested ae34b1573 on NVIDIA GeForce RTX 5070 Ti, driver 616.56, Vulkan SDK 1.4.363.0, Windows x64, Python 3.15.2: pass.

  • python -I -m compileall -q tools tests: clean (exit 0).
  • python -I tests/semantic/test_v_cmp_vgpr_destination.py: 3/3 OK; python -I tests/semantic/test_cmp_f64.py: 6/6 OK.
  • runtime/test/shaders/build.py + check.py: 176/211 pass (35 skipped) native; 207/211 pass (4 skipped) with LEONIDA_W64_EMULATE=1.
  • scripts/run_gpu_tests.py: 192/241 pass (48 skipped) native; 223/241 pass (17 skipped) with LEONIDA_W64_EMULATE=1 — only the pre-existing ms_wave_info_s3 failure on this host (identical to main).

AI-assisted.

@thesubtleties

Copy link
Copy Markdown

Tested ae34b157 applied to main 5d74c272: no regressions, but the VGPR-destination form is not confirmed. on CachyOS Linux 7.3.5, LLVM 23.1.5: RTX 3080 (subgroup 32..32, driver 620.73.04, LEONIDA_W64_EMULATE=1) and an RDNA2 iGPU (Ryzen 7 7800X3D, gfx1036, RADV Mesa 26.3.1, subgroup 32..64, native).

  • GPU suite: 3080 223/241 passed, 17 skipped, 1 failed; iGPU 225/241 passed, 16 skipped, 0 failed. The one 3080 failure is ms_wave_info_s3, which main 5d74c272 also fails here. Per-test status otherwise matches main on both GPUs.
  • The PR's two test files: 9 passed. Full tests/semantic has the same 48 failures as main 5d74c272 (47 in test_image_atomics_guard, 1 in test_image_store_d16), none new.
  • None of this exercises the new form: no GPU fixture uses it. I can confirm @renzyxx's finding on a smaller scale: llvm-mc 23.1.5 rejects v_cmp_lt_u32_e64 v2, v0, 16 (and f64 and class variants) on gfx1010, gfx1013, gfx1030, gfx1036 and gfx1100, in wave32 and wave64. It accepts vcc_hi in wave32 on gfx1030, and rejects it there in wave64.

I'd agree with splitting out the vcc_hi part until the listings are explained. No game files. AI-assisted (Claude Code).

@andreencar

Copy link
Copy Markdown

Tested ae34b1573 (merged onto main 5d74c2723) on Apple M1 Max, macOS 27.2.1, MoltenVK 1.4.2, Python 3.14.8, Homebrew llvm-mc 23.1.4, SPIRV-Tools v2026.4: pass. First Apple/MoltenVK check on this head.

  • python -m pytest tests/semantic/test_v_cmp_vgpr_destination.py tests/semantic/test_cmp_f64.py: 9 passed (53 subtests). Negative control: the PR's test files on unpatched main give 4 failed, 5 passed.
  • python -I scripts/run_gpu_tests.py --build runtime/build/linux: 179/241 passed, 60 skipped, same as main on this machine (only the known MoltenVK failures cs_fma_fused and ps_ssharp).

AI-assisted check (Claude Code); I reviewed the diff and the results.

@RAINighty

Copy link
Copy Markdown

Tested ae34b1573 merged with main 5d74c2723 (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1; venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/semantic/test_cmp_f64.py with this PR: passes (Ran 6 tests in 0.278s, OK). On main: passes (Ran 5 tests in 0.277s, OK).
  • tests/semantic/test_v_cmp_vgpr_destination.py with this PR: passes (Ran 3 tests in 0.126s, OK). On main: a new file, so there is nothing to run there.
  • Negative control: this PR's test with main's version of docs/design.md, tools/rdna2spirv.py fails (Ran 6 tests in 0.275s, FAILED (errors=1)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@pablo-biasco-411953

Copy link
Copy Markdown

checked: #9474ae34b15 | with: PR diff applied on main 5d74c27, python -m pytest -q tests/semantic/test_cmp_f64.py tests/semantic/test_v_cmp_vgpr_destination.py | on: Windows 11, CPython 3.11.9, pytest 9.2.0, CPU only, no game files | result: pass, 9 passed, 53 subtests passed; no new failures against the same tests on main | agent: yes

@matheusfermiano-source

Copy link
Copy Markdown

Tested ae34b1573 (the PR's diff applied on main 6312c057f), full python -I scripts/run_gpu_tests.py on three GPUs, each compared with main on the same machine, Linux (CachyOS): pass.

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 225/241 passed, 16 skipped same results as main
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 192/241 passed, 48 skipped fails on main too: ms_wave_info_s3 (#6172)
AMD Radeon Vega 8 (GCN 5 iGPU, gfx90c), subgroup 64 RADV, Mesa 26.2.6 193/241 passed, 48 skipped 193/241 passed, 48 skipped same results as main

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

@EdouardSence

EdouardSence commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Full-corpus counts for this PR (head ae34b1573) against main (5d74c2723), on Linux with llvm-mc 23.1.5, --no-asm, run as 8 shards per side.

Input main this PR
Game corpus, <work>/shaders/dxbc/disasm 26,503 / 26,503 translated, 26,503 pass spirv-val 26,503 / 26,503 translated, 26,503 pass spirv-val
Pipeline-library compute programs (#7529's tools/shader_library.py --stages cs --disasm --carve) 1,773 / 2,684 translated, all pass spirv-val 2,405 / 2,684 translated, all pass spirv-val

So nothing regresses on the game corpus, and on the library's compute programs this clears every v_cmp destination (606 on main) and mask destination (66) refusal. What still stops the other 279 there: CS thread-group-size SGPR 91, s_load_dwordx4 operands sgpr vcc 73, fall-through into undecodable words 51, ds_append 28, s_bitreplicate_b64_b32 on a lane mask 26, s_load_dwordx8 operands sgpr vcc 6, s_flbit_i32_b64 of a lane mask 3.

Why it matters for the boot: with a stack of open runtime PRs (listed in #7232), the retail executable under Wine 11.22 (AMD RX 9070 XT, RADV) gets to its pipeline-library compute pipelines (device slot 67). With the library translated by main's translator, 13 of those slot-67 calls (8 distinct programs) still fail for want of a module. Correction: an earlier version of this comment said this PR covers them; I checked since, and it does not: none of the 8 is among the programs shader_library.py extracts from shaders.rpf, so they come from another source and this PR's library gain does not reach them.

Counts only; no game data. AI-assisted (Claude Code), run and checked by me.

@OGShotz

OGShotz commented Nov 23, 2026

Copy link
Copy Markdown

Code review of ae34b15, checked with llvm-mc 21.1.8 (AMDGPU target) for gfx1013. AI-assisted.

The VGPR-destination half doesn't match what llvm-mc can produce for GFX10. A VOP3 VOPC's destination is the 8-bit SDST field, which can't name a VGPR. I assembled and disassembled every class of SDST byte for v_cmp_lt_u32_e64 on gfx1013:

assemble  v_cmp_lt_u32_e64 v0, v1, v2              wave32 / wave64: error: invalid operand for instruction
disasm    SDST 0x00  -> s0 (w32), s[0:1] (w64)
          SDST 0x6a  -> vcc_lo (w32), vcc (w64)
          SDST 0x6b  -> vcc_hi (w32);  w64: invalid instruction encoding
          SDST 0x7c  -> m0 (w32);      w64: invalid instruction encoding
          SDST 0x7d  -> null;  0x7e -> exec_lo / exec
          SDST 0x80, 0xc1, 0xf0 -> "0/*Invalid immediate*/", "-1/*Invalid immediate*/", "0.5/*Invalid immediate*/"
          SDST 0xff  -> llvm-mc crashes ("PLEASE submit a bug report")

So shader_disasm.py's listings shouldn't contain a v_cmp_* vN, ... at all, and the 606 v_cmp destination refusals in the pipeline-library count are probably something else that the operand parser lands on the else branch. Candidates are m0 in wave32 and an Invalid immediate destination. If it's the latter, storing r into a VGPR would silently translate a mis-decoded instruction instead of refusing it. Could you post just the destination operand text from one of those 606 lines? A single operand is the kind of short excerpt CONTRIBUTING.md allows. Then the rule can be matched to what's really there, and the GFX10 ISA reference (VOP3B SDST field) can go in the design.md row.

The vcc_hi half looks right in wave32: llvm-mc decodes SDST 0x6b as vcc_hi there, and it's a plain SGPR. In wave64, llvm-mc calls that byte an invalid encoding, so the self.wave64 and self.vcc_half_keeps_mask() branch can't be reached from a real listing. That's harmless, but the comment could say it's wave32-only.

The added comment on TG_SIZE_EN is useful as it stands.

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.