Repository navigation
rdna2spirv: restrict restore_skipped_instructions to reachable offsets and protect branch targets (OLD-10062) - #596
Conversation
|
Measured on the full pipeline-library compute set of our own 1.0.2.1 copy (Windows 11, llvm-mc 21.1.8, Most of the remaining failures (766 of 782 on the batch) are one gap: when llvm-mc 21 rejects an SMEM word whose SGPR tuple runs into vcc, it prints that SMEM's second dword (SOFFSET=null reads as the A follow-through step (after each restored instruction, keep decoding with AI-assisted (Claude Code). |
|
Thanks @lines9686-rgb for benchmarking this on a full 1.0.2.1 compute set (+84 translated shaders, 0 regressions, byte-identical on all previously translated modules)! That analysis of |
SweatierKey
left a comment
There was a problem hiding this comment.
Independent verification on origin/main@1504c1af6 (LEONIDA_REQUIRE_SPIRV_TOOLS=1):
tests/semantic/test_vcc_tuple_fallback.py:5/5PASS (test_load_into_a_tuple_ending_in_vcc,test_buffer_resource_in_vcc,test_image_resource_in_vcc,test_nsa_mimg_with_vcc_tuple_does_not_read_past_code_end,test_other_undecodable_words_are_still_refused).scripts/check_no_game_data.py: clean.
Clean fallback decoding VCC-overlapping tuples via rdna2_decode with proper code_end bounds checking on NSA1 MIMG instructions.
AI-assisted: yes
|
A synthetic case that |
…ect branch targets Do not scan unreachable embedded data words skipped by s_branch or after s_endpgm / s_setpc_b64 in restore_vcc_tuples. Walk only offsets reachable from code_start via matched instructions, fall-through, and direct/folded far branches, and discard any restored instruction whose interior dwords are targeted by a reachable branch. Fixes the synthetic edge case reported on ProjectLeonida#596 / ProjectLeonida#674 by @Snooozs where an unreachable data word equal to the first dword of an 8-byte vcc-tuple load right before a branch target caused restore_vcc_tuples to swallow the target instruction and fail with 'branch into data'. Adds regression tests covering: skipped data word before a matched branch target, skipped data word before a vcc-tuple load at the branch target, data word after s_endpgm before a branch target, and fall-through into a data word directly before a branch target.
|
Thanks @Snooozs for catching that synthetic edge case and pinning down the exact cause! Fixed in
Verification (Windows 11, CPython 3.12.14, SPIRV-Tools
AI-assisted: yes (JARVIX). |
|
Confirmed at 091cd96: merged onto |
|
Measured
With LLVM 23.1.5 listings this PR changes nothing, which matches what I measured for #327 (#327 (comment)).
The gains reported above were presumably measured with AI-assisted. |
… for the shader's wave size ProjectLeonida#596 walks only reachable offsets. The resync after a restored tuple now runs inside that walk, follows swallowed branches, and drops the rest of a run when a branch targets an instruction's interior. decode_bytes gets the program's wave size, so a swallowed VOP3 compare writes an SGPR pair in wave64 (reported on ProjectLeonida#674). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
091cd96 to
6cdec63
Compare
…ect branch targets Do not scan unreachable embedded data words skipped by s_branch or after s_endpgm / s_setpc_b64 in restore_vcc_tuples. Walk only offsets reachable from code_start via matched instructions, fall-through, and direct/folded far branches, and discard any restored instruction whose interior dwords are targeted by a reachable branch. Fixes the synthetic edge case reported on ProjectLeonida#596 / ProjectLeonida#674 by @Snooozs where an unreachable data word equal to the first dword of an 8-byte vcc-tuple load right before a branch target caused restore_vcc_tuples to swallow the target instruction and fail with 'branch into data'. Adds regression tests covering: skipped data word before a matched branch target, skipped data word before a vcc-tuple load at the branch target, data word after s_endpgm before a branch target, and fall-through into a data word directly before a branch target.
…s and protect branch targets ProjectLeonida#984 merged the base skipped-instruction recovery (VCC tuples, DPP compares, and v_dot4_i32_i8) together with the code_end slice bound, but restore_skipped_instructions() still linearly scans every uncovered dword before reachable_code(). An unreachable embedded data word skipped by a branch or placed after s_endpgm whose bytes happen to start a recoverable instruction can be decoded across the following branch target instruction, dropping that target and failing later with 'branch into data'. Walk only uncovered offsets reachable from code_start via fall-through and branches (including folded far branches), reject any restored instruction whose interior dwords are a reachable branch target, preserve O(N) linear span filtering by sorting restored instructions by pc, and skip partial synthetic dicts lacking 'op' (e.g. test_library_compute_forms). Adds 4 regression tests in tests/semantic/test_vcc_tuple_fallback.py covering skipped data before a matched branch target, skipped data before a VCC-tuple load at a branch target, data after s_endpgm before a branch target, and fall-through into a data word directly before a branch target.
6cdec63 to
57f5947
Compare
|
Rebased & narrowed onto current #984 merged @tedin7's base skipped-instruction recovery (renamed This PR now carries only that remaining fix on top of Re-verified locally with Khronos SPIRV-Tools (
|
|
Closing as superseded by merged #674 (\490f5b9ec), which incorporates the reachability walk, interior branch-target protection, and all 4 regression tests in \ ests/semantic/test_vcc_tuple_fallback.py. Thanks @DadaCap, @Snooozs, @SweatierKey, @lines9686-rgb, and @kawaii-shakal for the reviews and measurements! |
Claimed in the coordination issue as: OLD-10062
What and why
Carries forward
old-pr/10062(draft #327) ontomain(d7576d56a), preservingtedin7's original commit verbatim perCONTRIBUTING.mdand adding one focused hardening commit on top:tedin7):restore_vcc_tuples()intools/rdna2spirv.pyrecovers scalar-memory, image, and buffer instructions whose register tuple runs intovcc_lo/vcc_hi(SGPRs 106/107) usingrdna2_decodewhenllvm-mcrejects the first dword and leaves the second dword as invalid/junk/normalized, plus synthetic semantic tests (tests/semantic/test_vcc_tuple_fallback.py) and thedocs/shader_library.mdupdate.JARVIX): Clamps therdna2_decode.decode_bytesslice inrestore_vcc_tuples()toblob[at:min(at + 20, stop)]and checksat + nbytes <= stop. Previously, a 12-byte NSA1image_loadstarting atcode_end - 8with trailing bytes pastcode_endwas decoded acrossstop(pc=0, len=12whencode_end=8). Adds a synthetic regression test (test_nsa_mimg_with_vcc_tuple_does_not_read_past_code_end) verifying rejection when truncated atcode_end=8and restoration when complete atcode_end=12.Tested
All synthetic CPU/stdlib/docs/runtime-path checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files):
python -I tests/semantic/test_vcc_tuple_fallback.py -v— 5/5 passed (reproduced the 12-byte NSA1 over-read failure before the hardening commit; 5/5 pass after)python -I tests/test_runtime_paths.py— 5/5 passedpython -I tests/test_ci_registration.py— 15/15 passedpython -I scripts/check_no_game_data.py— passed (0 forbidden tracked extensions)python -m compileall -q make_game.py tools tests— passedpython -I tests/test_text_write_line_endings.py,tests/test_report_paths.py,tests/test_i18n_index.py, and alltests/test_docs_*.py— passednode --test tests/test_viewer_streaming.cjs— passedspirv-valrerun: not run (no game files / LLVM / SPIRV-Tools on this host).GPUs tested: n/a (CPU/semantic interpreter tests only)
AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (Reuses the existingVCCTuple[s100,...,vcc_lo,vcc_hi]contract documented indocs/design.mdScalar/buffer memory anddocs/shader_library.md.)