Skip to content

Tools: wave64_halves, a VGPR written under a narrowed EXEC is tier C once EXEC widens - #4619

Open
fearkov wants to merge 2 commits into
ItsNotRexed:mainfrom
fearkov:fix/wave64-halves-narrowed-writes
Open

fearkov wants to merge 2 commits into
ItsNotRexed:mainfrom
fearkov:fix/wave64-halves-narrowed-writes

Conversation

@fearkov

@fearkov fearkov commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #4571 as: #4571 (comment) (@shdann's finding #4571 (comment))

The other finding, a vote whose mask is rewritten before the branch, is #4620's: it was claimed first. I dropped my commits for it, so the two PRs no longer conflict (git merge-tree exits 0) and the suites below pass on the merge of both.

What and why

tools/wave64_halves.py gave tier A to wave64 programs whose one 64-lane wave and two 32-lane waves export different values, after a VGPR was written under a narrowed EXEC. The lanes that are off still hold what the register held when EXEC narrowed, and they read it again once EXEC widens. put() replaced the register's taint, so a lane id, a readlane or a lane count that a narrowed v_mov covered in one lane was forgotten.

A narrowed write now records the register's taint at the narrowing, per EXEC token (st["p"], carried and joined with the rest of the state). widen() adds that taint back and drops the register's tags, which only described the lanes that were on. It runs where EXEC goes back to an ancestor token and wherever EXEC gets a value of unknown extent.

The finding suggested or-ing the taint at the write. I tried that first, and it breaks the tier B aggregated atomic. Its whole elect / atomic / v_readfirstlane sequence runs under a narrowed EXEC, and its rank and elected-lane tags are right for the lanes that are on. So nothing changes while EXEC is narrowed. The old taint comes back only when the off lanes become readable again, and an elected lane's tag stays, because v_readfirstlane reads that lane.

Listing (from the finding) main this branch 1x64 vs 2x32
lane id (v_mbcnt) covered in lane 1 under a narrowed EXEC A C lane-id 32 lanes differ
v_readlane_b32 s6, v0, 5 covered the same way A C cross-lane 32 differ
s_bcnt1_i32_b64 s6, exec covered the same way A C lane-count 63 differ
a constant covered the same way (control) A A equal

I left out the finding's ds_bpermute_b32 address variant because I didn't rebuild its listing.

Commits:

  1. the narrowed-write rule in tools/wave64_halves.py
  2. NarrowedWrites in tests/semantic/test_wave64_halves_soundness.py: the three listings are tier C and their two runs on the CPU wave interpreter really diverge, plus the control

Tested

Linux, on main d0835dd. Each commit passes tests/semantic/test_wave64_halves*.py and tests/test_wave64_halves_fixtures.py. With main's wave64_halves.py, exactly the 3 bug cases fail. tests/test_wave64_graphics_scan.py and tests/test_make_game_wave64.py are unchanged. Merged with #4620: 110 passed in tests/semantic/test_wave64_halves*.py.

Census needed: the rule can move corpus shaders from tier A or B to C. That's the point of it, but someone with the game should run python tools/wave64_halves.py --census <spirv>/index.json before and after.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.

… lanes

A VGPR written under a narrowed EXEC still holds, in the lanes that are off, what it held when EXEC narrowed, and those lanes read it again once EXEC widens. The write replaced the register's taint, so a lane id, a lane count or a readlane it covered in one lane passed as tier A while one 64-lane wave and two 32-lane ones exported different values (shdann's finding). Each such write now records the old taint per EXEC token, and widening EXEC back adds it and drops the tags, except an elected lane's, which v_readfirstlane reads back.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at a09039c2 on Windows 11: tests/semantic/test_wave64_halves_soundness.py -> 38 tests, OK; git diff --check clean.

The PR covers both shdann findings: a VGPR written under a narrowed EXEC keeps the off-lanes' pre-narrowing taint (st["p"], re-applied by widen() when EXEC widens), and a vote tag on a mask register is dropped when that register or its pair partner is rewritten. The new soundness cases pin the tier-C outcomes and the elected-lane exception. No blocking issue in the change itself.

Duplicate/overlap: #4620 fixes the same rewritten-vote-mask issue alone and conflicts with this branch in tools/wave64_halves.py (git merge-tree --write-tree refs/remotes/pr/4619 refs/remotes/pr/4620 -> exit 1, conflict in that file). #4620 was claimed first for SHADER-820 (03:10 vs this PR's 03:16 claim, which names both findings). If this PR lands, #4620's tool hunk is redundant; if #4620 lands first, this PR should drop its vote-mask hunk and rebase, keeping the narrowed-write part.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested a09039c on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE. compileall clean; the new tests/semantic/test_wave64_halves_soundness.py 38/38, test_wave64_halves.py 73/73, plus _fixtures, test_wave64_cross_half, test_wave64_scmp_masks, test_wave64_subgroup_ops and test_wave64_vcc_data_branch all pass. Negative control: with main's tool the 6 new NarrowedWrites/StaleVotes cases fail while the 73 existing ones pass; at the head all pass. Merge clean.

One issue: tools/wave64_halves.py:904-911 keeps st["p"] entries for a still-live token and only drops them on a matching widen, so entries survive regions that end at :894 - bounded, but growing per VGPR x narrowing site. The unconditional tag drop at :918-920 is conservative only (tier C), which is fine.

AI-assisted review, no game files, no GPU.

@fearkov
fearkov force-pushed the fix/wave64-halves-narrowed-writes branch from a09039c to 302583e Compare November 23, 2026 03:31
@fearkov fearkov changed the title Tools: wave64_halves, a narrowed write's off lanes and a rewritten vote mask are tier C Tools: wave64_halves, a VGPR written under a narrowed EXEC is tier C once EXEC widens Nov 23, 2026
@fearkov

fearkov commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Kam471. You're right, #4620 claimed the vote part first. I dropped my two vote commits, so this PR is now only the narrowed-write rule (302583e). It merges cleanly with #4620 (git merge-tree exit 0), and tests/semantic/test_wave64_halves*.py passes on the merge of both: 110 passed.

@Atomic258

Copy link
Copy Markdown

Tested head 302583ea — Windows, CPython 3.15.2, CPU only, synthetic fixtures, no game files: pass.

  • python -m unittest discover -s tests/semantic -p "test_wave64_halves_soundness.py" -> 34/34 OK.
  • Control (main's tools/wave64_halves.py + this test file): 3 failures — the mask-register-rewrite vote cases are not tier C on main, as intended.
  • git diff --check and scripts/check_no_game_data.py clean.

AI-assisted (Devin).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 302583e merged with main d0835dd on WSL2 Ubuntu (Python 3.12.16) and native Windows 11 (Python 3.13.1): pass. (An earlier head, a09039c, was a larger change; this is the narrowed one, and I tested only this head.)

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.

6 participants