Skip to content

rdna2spirv: interp_ij_analysis reaching_write misses a write at instruction 0 and loop back-edge writes - #3309

Closed
kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-interp-reaching
Closed

kapitche wants to merge 1 commit into
ItsNotRexed:mainfrom
kapitche:kap-interp-reaching

Conversation

@kapitche

Copy link
Copy Markdown
Contributor

Fixes the finding #3232 (comment) (Vonsek).

What broke. interp_ij_analysis::reaching_write tested predecessor blocks with any(w for w in ws if blk[w] == p), so a write at instruction index 0 (falsy) never counted. It also seeded the search with seen = {b}, so a write later in the site's own block that a loop back-edge brings round was never seen. In both cases a program that overwrites v0/v1 before a v_interp_p1/p2 pair was treated as pristine instead of computed. Repro: a v_mov_b32 v0, ... at index 0, then s_branch to a block holding the interp pair; interp_ij_analysis returned no per-vertex attributes (expected {0}).

Fix. Test membership (blk[w] == p) instead of truthiness, and start the search with an empty seen so the site block is reached again through a back-edge.

Tests. New tests/semantic/test_interp_reaching_write.py (hand-built instruction lists, no game data): write at index 0, write at index 1 (control), no write (stays pristine), loop back-edge write after the site. Python 3.12.16, Linux (WSL2): new file 4/4 OK; -p "test_interp*.py" 161 tests OK. Negative control: with tools/rdna2spirv.py reverted, 2 of the 4 fail (index 0 and back-edge).

AI-assisted.

…ack-edge writes

any(w for w in ws ...) dropped index 0 (falsy) and the search was seeded with the
site's own block, so a write after the site brought round by a loop never counted.
Both left a computed I/J pair classified as pristine.
@MiguelMatMar

Copy link
Copy Markdown

Tested d7c0d4b on Windows 11 Pro build 26300, Python 3.14 (CPU only): pass

  • tests/semantic/test_interp_reaching_write.py: 4/4 OK. unittest discover -s tests/semantic -p "test_interp*.py": 161 OK.
  • Negative control (the base's tools/rdna2spirv.py through LEONIDA_TOOLS_DIR): exactly the two expected failures, test_write_at_index_zero_reaches_branch_target and test_loop_back_edge_write_after_site.
  • Code read: LGTM. Both bugs are real: any(w for w in ws ...) drops index 0, and seen = {b} never re-enters the site block. With seen empty, b is only visited again if it is its own predecessor through some path, which means a cycle. So a write anywhere in b reaching the site is right there, and writes before the site already return early. The analysis also stays conservative: a true result marks the pair as computed.

@kapitche

Copy link
Copy Markdown
Contributor Author

Closing in favour of @Vonsek's #3287 (SHADER-616): it was his finding with first refusal, and his PR came first. Sorry for the duplicate. If anything here is useful to #3287, for example the two cases in tests/semantic/test_interp_reaching_write.py (a write at instruction index 0, and a loop back-edge write after the site), feel free to take them.

@kapitche kapitche closed this Nov 22, 2026
kapitche added a commit to kapitche/Leonida that referenced this pull request Nov 22, 2026
@kapitche

kapitche commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Added two GPU fixtures, drawn like ps_ij_computed: ps_ij_reach_zero (v0 = 0.25 is the first instruction, a branch starts a new block with the interp pair; expected mrt0.x = 0.5 everywhere) and ps_ij_reach_loop (v0 is rewritten after the interp, loop runs twice; expected u + 0.5, u = (x + 0.5) / 64). Expected from the VINTRP equations.

with this PR without it (parent translator)
RTX 4080 SUPER both PASS (all 4096 pixels within 1e-6) both FAIL: zero gives u instead of 0.5, loop gives 2u
UHD 770 SKIP: the Windows driver has no VK_KHR_fragment_shader_barycentric, so computed I/J pairs cannot run (ps_ij_computed skips there too) SKIP

Note for the fixtures: a register that only a v_interp reads (v1 in the zero case, v0/v1 in the loop) is not seeded with the hardware barycentric, it reads 0, so each fixture also does a plain v_mov of it to seed it (explained in the .asm headers). That is a separate gap from this PR. The GPU agrees with the interpreter. AI-assisted.

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.

2 participants