rdna2spirv: v_writelane_b32 keeps its destination's other lanes in read_before_write_vgprs (OLD-9910, SHADER-768) #658
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!658
Loading…
Reference in a new issue
No description provided.
Delete branch "carry-old-9910"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: OLD-9910 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129736114)
Replaces the carried-over draft #175. I'm the original author of old upstream PR 9910.
What and why
SHADER-768:
read_before_write_vgprsintools/rdna2spirv.pytreatedv_writelane_b32as a full write of its destination.v_writelane_b32 vD, sSRC, sLANEwrites one lane ofvDand leaves the other lanes as they were. The translator's own emission already loads the oldvDand selects per lane. So when a shader's first touch of a VGPR is a writelane and it reads that register later, the value from shader entry is read in the lanes that weren't written.Treating every writelane destination as a read goes too far the other way. On the old PR, shdann showed a VS that spills an SGPR into one lane of
v40around the fetch call and reads it back withv_readlane; that VS would be rejected withfetch mapping. So the kept lanes are now carried: they count as a read only when something other thanv_readlane_b32reads the register before a full write.reg_reads_writes(per slice) counts the destination as read.DST_ALSO_READholds the accumulating ops that both functions used to list separately.Known approximation, also written in the docstring: a
v_readlaneof a lane the writelane didn't write reads the entry value, and that read isn't counted.Diff: the old branch's final tree diff applied on current
main(21625bca8), one commit. It applied cleanly.main'sv_swap_b32entry and the d16formatexclusion are kept.Tested
python -I tests/semantic/test_writelane_read_before_write.py: 9 tests OK (carried vs used lanes, the readlane spill, a full write ending the carry, shdann's VS spill and PSv0barycentric cases translated end to end).python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6117 tests, 0 files failed (Linux, Python 3.14.4).python -m compileall -q make_game.py tools tests: OK.GPUs tested: n/a (CPU-only change, no GPU fixture)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: this fixes a register-use analysis, not a translation rule)Checked
f05bc538on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmaind42773d07:tests/semantic/test_writelane_read_before_write.py: 9 tests OK at this head; the same file againstmain's translator fails 4 of 9 (AssertionError: Items in the second set but not the first), so the new assertions do catch the gap.LEONIDA_W64_EMULATE=1, MoltenVK 1.4.2 (subgroup 4..32), binaries frommain:cs_w64x_writelanePASS, words4660 77 99 2748 0 0 4660 99; same onmainon the same filter, so no regression.llvm-mc 23.1.6, SPIRV-Tools v2026.4. Synthetic fixtures only, no game data. AI-assisted.