Skip to content

rdna2spirv: interp_ij_analysis pairs v_interp ops through an index, not a scan of every site (SHADER-722 follow-up) - #4024

Open
tedin7 wants to merge 1 commit into
ItsNotRexed:mainfrom
tedin7:shader-722-partner
Open

tedin7 wants to merge 1 commit into
ItsNotRexed:mainfrom
tedin7:shader-722-partner

Conversation

@tedin7

@tedin7 tedin7 commented Nov 22, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: new item, follow-up of SHADER-722 (#3918 (comment))

What and why

interp_ij_analysis (tools/rdna2spirv.py) pairs each v_interp_p1* with its p2 (and back) through partner(), which rebuilt its candidate list by scanning every v_interp site of the shader, once per site: O(sites²). After #3964 removes the per-block rescan, this is the largest remaining cost of the pass on large pixel shaders.

The sites are now grouped once by (op, anchor register, attribute, channel), in program order; the anchor is the f16 p2's partial (the p1's vdst it names) and the vdst for every other op, exactly as the old filter compared them. The nearest p2 after a p1 (or p1 before a p2) is a bisect in that group. Same pairs, same annotations, same exceptions. Independent of #3964 (different lines of the same function); both apply cleanly.

Tested

No GPU or game files needed (analysis pass only).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule: a performance change only.)

Prepared with the help of an AI coding agent; reviewed and tested as above.

…ot a scan of every site

partner() rebuilt its candidate list by scanning every v_interp site of the shader for each site
(O(sites^2)). The sites are now grouped once by (op, anchor register, attribute, channel) in program
order, and the nearest p2 after a p1 (or p1 before a p2) is a binary search in that group.
Follow-up of SHADER-722 (ItsNotRexed#3964).
@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 96c1d55 on Windows, CPython 3.14.7, CPU only (no GPU, no game files): pass.

python -m pytest -q tests/semantic/test_interp_computed_ij.py tests/semantic/test_interp_reaching_write.py tests/semantic/test_interp_p1lv_f16.py gives 60 tests passed and 30 subtests passed. I used a virtual environment with tests/requirements.txt.

I also measured interp_ij_analysis with 128, 512 and 1024 adjacent f32 interpolation pairs. Each pair writes v2 and reads v0 and v1 for attr0.x.
This head and the merge base (aa2988c) return the same empty set of computed attributes.
Median time for three calls at this head: 0.64 ms, 2.64 ms and 5.56 ms.
Median time at the merge base: 8.65 ms, 127.47 ms and 521.24 ms.
These times are for the analysis function only.

I found no defect. AI-assisted.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: 96c1d557 merged onto main aa2988cc on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @tedin7.

At 96c1d557, all 26,244 partner selections matched base aa2988cc, including the exact instruction index when a match existed. I compared the two revisions’ partner() functions and the new index construction on all 6,561 four-site sequences from nine synthetic site variants. These covered competing f16 p1ll/p1lv producers, a p2 whose destination differs from its partial register, missing partials, repeated f32 destinations, and attribute/channel mismatches.

As a sensitivity check, choosing the earlier of two eligible f16 producers instead of the nearest one changed the result in 64 sequences. Equal instruction indices cannot occur in this pass because the site builder appends at most one site per enumerated instruction. This was a CPU check of partner identity.

AI-assisted.

@whattheflop

Copy link
Copy Markdown
Contributor

Independent Windows 11 CPU check of #4024 96c1d557 on aa2988cc and its clean composition with #3964 af2b82a2 (tree 8a60eeeb). uv-managed CPython 3.12.13, WSL LLVM 21.1.8 for assembly. Each of the three trees passed 228 tests and 169 subtests across the 13 focused interpolation suites.

To complement the partner-only comparison, I ran 24 hand-authored cases through the full analysis. All trees matched 17 returns, seven exact errors, and all 47 instruction-indexed I/J annotations. The cases distinguish nearest producer/completion choices, differing f16 partial and destination registers, diamond joins, loop latches, and an unreachable sibling write. The probe caught 10/10 deliberately perturbed selection or analysis rules. Scope was CPU correctness, with synthetic inputs only. AI-assisted (Codex).

@chpeu

chpeu commented Nov 22, 2026

Copy link
Copy Markdown

Tested 96c1d557 (main aa2988cc is an ancestor, no rebase needed) on Linux, no game files.

GPU tests (RTX 3080, driver 615.71.09, Vulkan 1.4.351) — identical to current main on this machine:

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc
    → 195/210 passed, 15 skipped, 0 failed
  • without the variable → 164/210 passed, 46 skipped, 0 failed
  • main aa2988cc with the same commands gives exactly 195/210 and 164/210, 0 failed.

The RTX 5080 was not run in this pass: it is holding ~15.6 GB for another job on this box, so I skipped it
rather than turn an allocation failure into a verdict on your change. I'll cover it on a free pass.

Semantic side, which is what your change actually touches: python -m unittest discover -s tests/semantic

  • your branch: 7456 tests, 8 failures, 2 errors in 292 s;
  • main aa2988cc, same command: 7456 tests, 8 failures, 2 errors in 286 s.

Same set on both, so the index-based pairing changes no translated result here. The names we see failing on this
machine, for the record: two test_mutations cases on the v_mul_legacy_f32 anchor (already covered by #3883),
one test_fma_khr case where our Ubuntu spirv-as (SPIRV-Tools 2025.1~rc1) reports Invalid capability 'FMAKHR'
— a gap in our tooling, not in the repository — five test_loop_ballot_barrier cases in the wave64-emulate modes,
two test_cmp_class_f64.test_rejected_forms lines, and one test_anchors_match_crlf_translator_copies. If the
last three groups are already known, ignore this paragraph; if not, they reproduce on a plain Linux checkout with
llvm-mc 20.1.2 and no game data.

Translator pytest side: 1592 passed, 1 failed on your branch and the same 1592 passed, 1 failed on main
(the one failure is test_u16_high_half::test_d16_buffer_store_no_redundant_extract_after_shr16, which #3902
fixes). python -m compileall -q make_game.py tools tests: clean.

Machine: Linux Mint 22 (Ubuntu 24.04 base), llvm-mc 20.1.2, SPIRV-Tools 2025.1~rc1, GCC 13.3, Python 3.12.3 with
pytest 9.2.0 and numpy 2.5.5, built with cmake -S runtime -B runtime/build/linux -DLEONIDA_VULKAN_HEADERS_FETCH=ON.
AI-assisted testing, counts read through by hand.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Code read of 96c1d557. partner() now looks up the nearest p2 after a p1 (or p1 before a p2) with bisect over sites grouped by (op, anchor register, attribute, channel), with the same anchor rule as the old filter (partial for v_interp_p2_f16, vdst otherwise); the lists are built in program order, which bisect needs, and min/max across p1ll_f16/p1lv_f16 keeps the old "nearest" choice.
Ran on Windows 11, Python 3.14, llvm-mc 23.1.6: all 12 tests/semantic/test_interp*.py files pass (212 tests). Differential on the whole runtime/test/shaders corpus (234 shaders, 50 with v_interp_p1/p2): translating with this head and with main's tools/rdna2spirv.py gives 479 .spv/.spvasm files, none different, 234/234 spirv-val. compileall and git diff --check clean.
Mutation check, for information: making p2 take the next site instead of the previous one fails 9 test files, but dropping attr from the key, or anchoring p2_f16 on vdst instead of its partial, is not caught by any of the 212 tests (the old filter was equally unguarded); only the external equivalence runs already posted cover them. A small test with two attributes and a p2_f16 whose partial differs from its vdst would pin them. Not run: the full semantic suite, GPU.
AI-assisted code read (Claude).

@bielfreedom

Copy link
Copy Markdown

Checked over the full game corpus (my own 1.0.2.1 copy, counts and hashes only) on Windows 11, AMD RX 9070 XT machine, wave64 emulation off: byte-identical output to main.

Same disassembly (26,503 .s from shader_disasm.py, llvm-mc 23.1.6), translated by rdna2spirv.py in 8 shards + --merge, no extra flags, once with main aa2988cc (via make_game.py --stages shaders) and once with this PR's head 96c1d557:

translated pass spirv-val index.json entries
main aa2988cc 26,503 26,422 26,422
this PR 26,503 26,422 26,422

So "same pairs, same annotations" holds over the whole corpus. I didn't time the two runs under the same load, so this says nothing about the speed-up itself.

AI-assisted (Claude Code).

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.

8 participants