rdna2spirv: put back the instructions llvm-mc's junk swallowed after a tuple into vcc (SHADER-VCC-TUPLE-RESYNC) #674
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!674
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/674/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@DadaCap on GitHub · 2026-11-24 11:30 UTC · original
DadaCap:vcc-tuple-resync→main· +378 −79 · 6 files · 8 commits · merged 2026-11-25 19:07 UTCClaimed in the coordination issue as: SHADER-VCC-TUPLE-RESYNC (#14)
Depends on: #596 (its two commits come first here; this pull request is the last commit)
What and why
llvm-mc rejects a scalar tuple that runs into
vccand prints the tuple's second word as junk. #596 decodes the tuple from the blob and drops the junk. But the junk is often longer than that word (an 8-byteexp, for example), so it also covers the instruction after the tuple: ans_mov_b32, ans_waitcnt, av_fma_f32. Nothing printed that instruction at its own place, so it stayed missing and the program was refused with "fall-through into undecodable words".restore_vcc_tuplesnow decodes the words after a restored tuple from the blob, the same way, until the stream is back at an instruction llvm-mc printed there. A word llvm-mc itself rejected, with no junk printed over it, is not taken for swallowed code and stays refused.Tested
Whole pipeline library (1.0.2.1, own copy), all 2,684 compute programs, llvm-mc 21.1.8,
--wave64-emulate,main+ #596 without and with this commit:spirv-val0 programs lost, and the 1,816 modules are byte-identical. What is left: 80
s_load_dword*with avccbase or destination (#647 has the bases), 18s_flbit_i32_b64and 6s_bitreplicate_b64_b32(#593), 9 that cannot be re-anchored, 3 fall-throughs, 1s_sethalt. The 26,503 main-corpus listings have no undecodable words with this disassembler, so this path does not run on them.tests/semantic/test_vcc_tuple_fallback.py: 7 tests pass; the new case is red without the fix, and a second one checks that a rejected word after a tuple is still refused.test_image_cube_store_glc, which fails here withFileNotFoundErrorstarting an external program, onmaintoo.tests/test_docs_*.pyset,test_text_write_line_endings.py,compileall,check_no_game_data.py: clean.The new modules are checked by
spirv-valonly; none was compared with hardware.GPUs tested: n/a
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
091cd9680); restore_vcc_tuples decodes for the shader's wave size 30450e0e96@trigger337 on GitHub · 2026-11-24 11:38 UTC · original
agent: yes
AI-assisted: yes
Hardware validation on Linux (AMD Radeon RX 6900 XT / RADV Navi 21, Mesa 26.2.5, Vulkan 1.4.333):
python3 -m unittest discover -s tests/semantic -p test_vcc_tuple_fallback.py -v: 7/7 passed.scripts/run_gpu_tests.py):spirv-val.cs_imgload_tfe,cs_imgload_d16_tfe, matching #31 across all drivers). No regressions againstmain.scripts/check_no_game_data.py: clean.tests/test_docs_*.py: 47/47 passed.@qhukz13 on GitHub · 2026-11-24 14:26 UTC · original · reviewed
Reviewed the last commit (
f605f8aee, on top of #596) on Linux, CPU only, no game files.tests/semantic/test_vcc_tuple_fallback.py: 7 tests OK.I ran
--function restore_vcc_tupleswithsemantic_mutantsfrom #734 (it adds Python-logic mutations) against that file: 32 of 41 mutants caught. The survivors that touch this commit's new logic:starts.add(ins["pc"])removed: no case checks that the resync stops at an instruction llvm-mc printed (at not in starts), which is the condition the description rests on;unplaced = Noneremoved: no case has two separate junk regions, so a junk range running on into the next one is not caught;resync = Falseremoved: no case where a decode fails in the middle of a resync and the scan has to drop out of it;<=-><: nothing at the very end of the code range;resync = False->True: nothing starts atcode_startinside junk.(From #596: line 17189 survives
in->not inandor->and, so the tests use only one ofvcc_lo/vcc_hi; line 17180 survives removingcovered.update.)One question on the resync itself: in resync mode a decoded instruction is accepted when it ends before
stop, but nothing checks that it does not run across the start of the next printed instruction (at < s < at + lenfor somesinstarts). Line 17202 then drops every printed instruction that overlaps a restored one, so a misaligned resync would remove a printed instruction silently instead of stopping. Your corpus numbers (0 programs lost, byte-identical modules) suggest it does not happen there, but a check, or a case showing why it cannot, would make that explicit.Looks right otherwise; the corpus result is a big step.
@DadaCap on GitHub · 2026-11-24 15:45 UTC · original
@qhukz13 thank you, that was a careful read.
688674095adds tests for the survivors in this commit's logic:starts.add,unplaced = None,resync = False, the initialresync, and<=. Each of the five mutations now fails; I checked them by hand, not with #734. The survivors from #596 are left to that pull request.On the question: I tried the check (stop when a decoded instruction runs across a printed start), and it breaks a correct case that the test file already has ("12 bytes, then 4" in
test_junk_that_swallows_the_next_instructions). The junk after a tuple can end on the first word of an 8-byte instruction. llvm-mc then prints that instruction's literal as an instruction of its own, so the real one legitimately runs across a printed start, and the printed one is the wrong one to keep.test_crosses_a_start_that_is_a_literal_printed_on_its_ownnow states that.So there is no local rule that tells the two apart: what keeps the resync in step is that it starts at the end of a restored tuple, which is an instruction boundary, and decodes every word from there. A misaligned step would need a wrong length for one instruction. The evidence that it does not happen is the corpus run, not a proof.
Tests:
python -I tests/semantic/test_vcc_tuple_fallback.py, 14 OK. No change totools/rdna2spirv.py.AI-assisted (Claude Code, Opus 5.5).
@qhukz13 on GitHub · 2026-11-24 15:55 UTC · original
Thanks — confirmed on
688674095withsemantic_mutantsfrom #734:test_vcc_tuple_fallback.pypasses (14), and--function restore_vcc_tuplesnow catches 37 of 41; all five survivors from this commit fail now, and the four left (lines 17180 and 17189) are #596's, as you say. The literal-printed-on-its-own case answers my question: crossing a printed start is legitimate there, so a local check would be wrong, and the new test documents it. LGTM.@Snooozs on GitHub · 2026-11-24 16:54 UTC · original
One case that gets worse with
restore_vcc_tuples(this head, and #596'sf7a338b14too), found with a synthetic listing: a data word that happens to equal the first dword of a vcc-tuple load, skipped by a branch, with real code right after it.main82a2aabcc(restore call disabled in the merged tree): translates, and the interpreter stores 7.Unsupported: branch into data.The data word is offered to the decoder because it is not covered; it decodes as
s_buffer_load_dwordx8using the target instruction as its second dword, and the target (a matched instruction and a branch target) is then dropped as "printed inside a restored one". In this case it ends as a refusal, not as wrong code, and I do not know whether any library program has such a word. A guard that keeps it out: do not restore an instruction whose later dwords contain the start of a matched instruction that a branch targets (or only offer words reachable by fall-through from the previous instruction).Otherwise: merged onto
main82a2aabcc,tests/semantic/test_vcc_tuple_fallback.pyis green here (14 tests; #596: 5), and red withmain's tools (20 errors; #596: 10). Windows 10 19045, CPython 3.12.10, CPU only, no game files.AI-assisted (Claude Code); run on that machine.
@madhyn on GitHub · 2026-11-24 17:02 UTC · original
Independently tested stacking
#593(1ea2ffbca) +#596(ce98fbefe,f7a338b14) +#674(f605f8aee,688674095) +#647(a4c00f4f4) on our local frame-loop stack (Arch Linux, Wine 11.22, RTX 3060 Ti, retail 1.0.2.1):test_lane_mask_bitreplicate_flbit.py,test_vcc_tuple_fallback.py,test_sload_vcc_base.py): 22/22 passed.rdna2spirv.py --wave64-emulate): translated compute programs increased from 2,528 to 2,632 (all passingspirv-val), eliminating alls_load_dwordx4 operands sgpr vcc,s_flbit_i32_b64, ands_bitreplicate_b64_b32rejections.slot 67,DeserializeComputePipelineStateX):no translated compute shadermisses dropped from 34 to 0.AI-assisted: yes
@thesubtleties on GitHub · 2026-11-24 17:12 UTC · original
Review of
688674095merged onmain98a977b4: one wrong-value bug in wave64.restore_vcc_tuplescallsrdna2_decode.decode_bytes(...)withoutwave32=, which defaults toTrue, so in a wave64 shader a swallowed VOP3 compare comes back with a one-SGPR mask. Reproduction (hand-built listing, spirv_mini_interp, wave64): avcctuple02192cf4000000fa, thenv_cmp_gt_u32_e64 s[12:13], 40, v0swallowed by a junkexp.s13keeps its old value, ands_bcnt1_i32_b64 s[12:13]gives 0x28 in lane 0 but 8 in lanes 40 and 63, instead of 0x28. Forcingwave32=Falseat that call makes the compare cases match the intact listing, so passing the shader's wave size should fix it.Also: this branch contains the commits of #596, and #327's tests pass on it, while #596 and #327 fail some of its tests, so with that fixed it looks like the one to keep of the three.
Not checked: real output of an older llvm-mc (23.1.5 here prints these tuples), or any corpus. No game files. AI-assisted (Claude Code).
@towade on GitHub · 2026-11-24 17:24 UTC · original
checked:
688674095on the full 1.0.2.1 pipeline library (2,684 compute programs), and its effect on a retail boot. Windows 11 26300, Python 3.15,llvm-mc21.1.8 (the listingsmake_game.pywrites,gfx1013),spirv-valfrom Vulkan SDK 1.4.363,--wave64-emulate, 8 shards then--merge. Counts only.spirv-valmaina289278492f5b49c4e)None of the 1,685 that
maintranslates is lost, and all of them are byte-identical with this PR and with this PR + #985.On @thesubtleties' wave64 finding: of the 914 programs this PR adds, 54 are wave64 (index field
wave64) and 860 are wave32. So thewave32=default can affect at most those 54 in this library. I haven't checked how many of them have a swallowed VOP3 compare.Retail. On an AMD Radeon RX 9070 XT,
main+ #511 (LEONIDA_LAZY_PSO=1) + the open boot pull requests of my ladder on #14 + #469, the title asks device slot 67 for 1,142 pipeline-library compute programs that amainlibrary lacks. With the library from this PR + #985 in the work folder:mainlibraryslot 67 ... failedlines in the runno translated compute shader for FSPXlinesThe run still ends at the later
int3in the title that I described on #14. One moreint3comes before it now, at another place; I haven't looked at it yet. So this shows the programs are found and created, not that they compute the right thing.Not run: the semantic suite on this head, and anything on a GPU beyond the boot.
AI-assisted (Claude Code).
@Snooozs on GitHub · 2026-11-24 18:00 UTC · original
#596 fixed the skipped-data-word case in
091cd9680(checked: my listing translates again and stores 7). This head still has the older #596 commits and refuses it withbranch into data, so rebasing onto #596's current head would pick up the fix, next to the wave64 point above. AI-assisted (Claude Code).@DadaCap on GitHub · 2026-11-24 20:30 UTC · original
@thesubtleties @Snooozs thank you, both fixed in
30450e0e9, andbc245e504merges currentmain.restore_vcc_tuplesnow decodes for the program's own wave size (FSSM header, FSPX dispatch state, else the code-marker rule). Your repro istest_swallowed_compare_in_wave64_writes_a_pair: 0x28 in all 64 lanes, red with the wave32 default.091cd9680. The resync now runs inside its reachable walk: swallowed branches are followed, an offset that failed once can still be reached through a tuple, and when a branch lands inside a restored instruction the rest of that run is dropped with it. Each has a test; @Snooozs' listing is one of #596's tests and passes.Run (Windows 11, CPython 3.14, CPU only):
test_vcc_tuple_fallback.py23 OK. Whole translator suite 471 files, 6,191 tests; onlytest_image_cube_store_glcfails, with theFileNotFoundErrorfrom the description.test_docs_*,test_text_write_line_endings,test_rdna2_decode,compileall,check_no_game_data.py: clean.--wave64-emulate, the previous head merged on the samemainagainst this one: 2,647 translated andspirv-val-valid with both, none lost or gained, 3 modules differ, all wave64.Not run: GPU tests, a boot, and VS/MS/PS library programs. The 3 changed modules were not compared with hardware.
AI-assisted (Claude Code, Opus 5.5).
@Snooozs on GitHub · 2026-11-24 20:54 UTC · original
Rechecked
bc245e504merged on main66d4f5aa3(clean): my synthetic case (a branch whose target lies inside the swallowed words) now translates and stores 7, andtest_vcc_tuple_fallback.pygives 23 OK (Windows 10 19045, CPython 3.12.10, CPU only, no llvm-mc on this PC). I read the newrdna2spirv.pydiff too and have nothing further on it.AI-assisted (Claude Code, Claude Opus 5.5).
@DadaCap on GitHub · 2026-11-24 23:07 UTC · original
Merged current
main(with #1021) into the branch; no force-push.Two conflicts in
tools/rdna2spirv.py, both "keep both sides":restore_vcc_tuplesand #1021'swiden_wave64_maskswere added at the same place, and the wave size of a program without a header or dispatch state stays this branch'smarker_wave64(...), followed by main'sif g.wave64: widen_wave64_masks(insns). A restored VOP3 compare is already decoded for the shader's wave size, so in wave64 it carries its pair and the widening (which only touches one-register operands) leaves it alone.On the merged head, Windows 11, CPython, CPU only:
python -I scripts/run_semantic_tests.py tests/semanticgives 475 files, 6,217 tests, 1 file failed:test_image_cube_store_glc, which startsllvm-mcand fails the same way onmainon this machine.test_vcc_tuple_fallback.py23 OK,test_wave64_single_sdst.py3 OK.Not run: the game corpus on this head, GPU tests.
AI-assisted (Claude Code).
@DadaCap on GitHub · 2026-11-25 02:40 UTC · original
Status after #984: this branch conflicts with
mainintools/rdna2spirv.py,tests/semantic/test_vcc_tuple_fallback.pyanddocs/design.md, because #984 brought an earlier version of the same recovery (restore_skipped_instructions, which also takes the DPP compares and thev_dot4_i32_i8form from the blob).#1495 already carries this branch's head (
686f914b7) merged with that: thererestore_vcc_tuplesreplacesrestore_skipped_instructionsand askipped_formhelper keeps the two other forms. I tried the merge here as well and it comes to the same decision, so I am not pushing a second resolution of the same three files that could differ from #1495's in details.If you would rather merge this one on its own before #1495, tell me and I will merge
maininto the branch with #1495's resolution of these files (no force-push). AI-assisted (Claude Code).@DadaCap on GitHub · 2026-11-25 04:03 UTC · original
Update: #1495 now conflicts with
mainitself, so I mergedmaininto this branch after all (heada6b851dff, no force-push; the reviewed commits are untouched). Theneeds rebaselabel is stale: GitHub reports it mergeable.How the conflict with #984's
restore_skipped_instructionsis resolved, the same way #1495 did it:restore_vcc_tuplesstays the one recovery function. The two extra formsmain's function took from the blob (a VOPC f32 compare in DPP form, the measuredv_dot4_i32_i8) go throughskipped_form(), the helper from #1495;restore_skipped_instructionsis gone.main's tests that called it by name (test_library_compute_forms.py,test_vcc_tuple_fallback.py) callrestore_vcc_tuples; the DPP recovery test's hand-built listing entry gets the fields a printed instruction has, as in #1495.docs/design.md:main's new "Pipeline-library scalar operands" row, then this branch's wording of the "Scalar/buffer memory" row.Tested on the merged head (Windows 11, Python 3, no GPU needed):
scripts/run_semantic_tests.py tests/semantic487 files, 6,297 tests, 0 failed;tests/test_rdna2spirv_decode.py25 tests OK;compileallclean. On one of 40 slices of my own library listings it translates 62 programs wheremaintranslates 49, and none thatmaintranslates is lost (counts only). AI-assisted (Claude Code).@Tyrannys on GitHub · 2026-11-25 11:09 UTC · original
Data from one machine, counts only. Windows 11, RTX 4070 SUPER (NVIDIA 621.01), own 1.0.2.1 copy,
make_game.py --stages shaders --jobs 16,--wave64-emulate.main(25 Nov, before3de22a190)main3de22a190+ this PR + #1662On the second tree the whole shaders stage translated 29,279 of 29,280 modules, and all 29,279 pass
spirv-val(BVH 52/52, executable 12/12).Caveat: both PRs were applied together, so this does not separate this PR's share of the 820 recovered library programs from #1662's (the signed-byte
v_dot4op_sel re-anchor). I can rerun with each PR alone if that helps the review.AI-assisted (Claude Code).
@DadaCap on GitHub · 2026-11-25 12:31 UTC · original
Thank you for the corpus numbers: 29,279 of 29,280 translated and all valid, 2,683 library and 29 of 29 FSPX with this and #1662. It matches what I see here with the same two branches (29 of 29 FSPX against 22 on plain
main). If you have the time, a run with this pull request alone would help the review, since it would show its own share of the 820. AI-assisted (Claude Code).@Tyrannys on GitHub · 2026-11-25 17:02 UTC · original
Follow-up to my counts above: both of those runs used
llvm-mc21.1.8 (the versionscripts/build_llvm_mc.ps1builds by default today). #1923 shows that with LLVM 23.1.5, plainmainalready gets 2,683 of 2,684 library programs. So on 21.1.8, this PR plus #1662 recovers the 820 programs that 21.1.8 garbles, and on 23.1.5 that gap doesn't appear in the first place. My table compares translator trees at 21.1.8 only, and doesn't measure this PR on 23.1.5.AI-assisted (Claude Code).
@Tyrannys on GitHub · 2026-11-25 18:12 UTC · original · edited 2026-11-25 18:55 UTC
Test report from a combined build on a second NVIDIA machine. Counts only.
Machine: Windows 11, RTX 4070 SUPER, NVIDIA 621.01, 64 GB, own 1.0.2.1 copy.
Build:
mainfe1553456(already contains #1827 and #1893), plus #674, #1662, #1851, #1849, #1905, #1957, #1950, #1886 and #1894. All of them merged without conflicts.Shaders: translated on
3de22a190+ #674 + #1662 with--wave64-emulate. 29,279 of 29,280 translated, and all 29,279 passspirv-val. That is 2,683 library programs and 29 of 29 FSPX.main's translator changes since then are correctness fixes only.Pipeline cache: warm and complete, 26,503 of 26,503 (9.6 GB).
ActivateRays,ActivateProbesandActivateProbesTargetprograms of indirect diffuse lighting.Recipe:
scripts/windows-boot/boot.ps1 -Seconds 480,LEONIDA_KEYBOARD_PAD=1 LEONIDA_SKIP_INT3=1 LEONIDA_TITLE_WINDOWS_MB=1024 LEONIDA_MAP_READBACK=1,LEONIDA_PIPELINE_CACHE_DIRpointing at the offline cache. Host image copy:off (auto: NVIDIA)from #1851. One run per row.LEONIDA_TITLE_WATCHDOG=0)game_scarlett_master.exe+0x23cf683)main42537e7b6+ #1631; my run table of 07:54 in #1608).AI-assisted (Claude Code).
@aslan2142 on GitHub · 2026-11-25 19:07 UTC · original
Merged, thanks! Reviewed
a6b851dffonmain:test_vcc_tuple_fallback.pyhas 23 tests; 18 of them fail withmain'srestore_skipped_instructions, including the data word before a branch target.restore_vcc_tuplesonly runs on 21.x-style listings (still whatscripts/build_llvm_mc.ps1builds by default). On 23.1.5 listings these all translate and passspirv-valbefore and after, with 0 modules changed: a 400-listing corpus slice, all 1,451 corpus listings with rejected words, and the 21 library ones.mainc37374180+a6b851dff: the semantic suite passes (490 files, 6,310 tests, 0 files failed);test_rdna2spirv_decodepass; the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 6 changed files.docs/shader_library.md§5 saying this recovery matters for llvm-mc 21.x listings would help.AI-assisted (Claude Code, Claude Opus 5.5).