Repository navigation
Conversation
…t asymmetric DPP row_mask Fixes partial-destination writes in tools/wave64_halves.py that dropped prior taint and falsely marked divergent VGPRs uniform (miscompiling v_readlane_b32 in rdna2spirv.py): - Track destination read in operands() for SDWA dst_unused:UNUSED_PRESERVE with sub-dword dst_sel, single-half 16-bit VALU ops (including 8-byte VOP3 / _nc_16 / v_interp_p2_f16), partial-lane DPP (row_mask/bank_mask != 0xf or bound_ctrl:0), v_fmac_legacy_f32, and partial d16 loads. - Flag half-asymmetric DPP row_mask ((row_mask & 3) != (row_mask >> 2)) and dpp8 in transfer(). Verified locally (CPU-only): - tests/semantic/test_wave64_halves_partial_dst.py (13 OK) - tests/semantic/test_wave64_halves_soundness.py (30 OK) - tests/semantic/test_wave64_halves.py (73 OK) - tests/semantic/test_wave64_cross_half.py (9 OK) - tests/semantic/test_wave64_subgroup_ops.py (6 OK) - pytest tests/test_wave64_halves_fixtures.py tests/test_wave64_graphics_scan.py (25 passed, 1 skipped) - docs, line-ending, resource hygiene, tool startup, compileall, git diff --check
…es a wave-uniform VGPR A v_readfirstlane_b32 / v_readlane_b32 of a VGPR that a buffer_load loaded was tier C (cross-lane, tainted-branch) even when every lane loaded the same word, because only VALU results of scalars entered the uniform set st["u"]. Analysis.uniform_load puts the destination of a load into st["u"] when all of these hold: - a MUBUF buffer_load_* with idxen (idxen ignores ADD_TID_ENABLE; without idxen a run-time V# can add the lane number), not a d16 form; - EXEC is the launch mask; - the index and offset VGPRs are uniform, the descriptor and soffset are untainted scalars; - the shader has no store and no atomic (the two halves read the word one after the other). tests/semantic/spirv_wave_interp.py gets a read-only memory (OpConvertUToPtr, OpAccessChain and OpLoad through a PhysicalStorageBuffer pointer), so that tests/semantic/test_wave64_uniform_load.py runs each hand-written vertex shader as one 64-lane wave and as two 32-lane waves: 5 accepted shapes are tier B and equal, 5 near misses are tier C and differ, 2 are classification only. Builds on ItsNotRexed#4373: without its partial-write rule an index written in part by an SDWA UNUSED_PRESERVE counts as uniform (test_c_index_written_in_part). No game data. The corpus effect is not measured. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Kam471
left a comment
There was a problem hiding this comment.
Ran this at f99eb65f on Windows 11. All four suites pass:
tests/semantic/test_wave64_halves_partial_dst.py-> 13 tests, OKtests/semantic/test_wave64_uniform_load.py-> 12 tests, OKtests/semantic/test_spirv_wave_interp.py-> 15 tests, OKtests/semantic/test_wave64_halves.py-> 73 tests, OKgit diff --checkclean.
The new _preserves_dst covers the partial-destination forms (RMW ops, SDWA with UNUSED_PRESERVE, asymmetric DPP row/bank masks, _e64/op_sel 16-bit writes, f16/u16/i16 results, d16 loads, image_load/image_sample with an odd dmask) and makes the preserved destination a source; uniform_load recognises a buffer_load with idxen from a wave-uniform address, excluding any memory the shader itself writes (MEM_WRITES). The interpreter is extended to run the partial-dst cases.
Merge check: git merge-tree with #4619, #4624 -> clean; with #4620 -> conflict only in docs/design.md (both edit rows there), no code conflict. No blocking issue.
|
BLOCKED: it needs a rebase and depends on #4373. The rule itself is sound: with But: it conflicts with current AI-assisted review, no game files, no GPU. |
|
Tested f99eb65 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. |
Claimed in the coordination issue as: new SHADER item (claim)
Depends on: #4373
The first commit of this branch is #4373 (
47b43d81). The change of this pull request is the commit after it.What and why
tools/wave64_halves.pyknows that a VGPR is the same in each lane only when a VALU instruction wrote it from immediates, scalars and other such VGPRs (st["u"]). A VGPR that abuffer_loadwrote is never in that set. Thus this code is tier C (cross-lane, ortainted-branchwhen the scalar goes to a branch), although each lane loads the same word:The research note for #94 names this as a probable cause of many tier C shaders (not measured).
The rule.
Analysis.uniform_loadputs the destination of a load intost["u"]when all of these conditions are true:buffer_load_*withidxen, and not ad16form (those keep half of the destination).st["f"]), so each lane that the program runs does the load.st["u"]. The descriptor andsoffsetare scalars that are not a lane mask. No operand has a taint bit.MEM_WRITES).After that, the rules that are already there do the work:
v_readfirstlane_b32andv_readlane_b32of the VGPR are tier B (readfirstlane-uniform,readlane-uniform), and the translator makes av_readlane_b32of it read the lane's own copy.Why it is exact.
idxen: the "Swizzled buffer addressing" row ofdocs/design.md(measured on RDNA2) says thatidxenignores ADD_TID_ENABLE. Withoutidxen, a V# with ADD_TID_ENABLE adds the lane number to the index, and the V# is a run-time value. Thus a load withoutidxenis not accepted. The new test shows the two cases with one V#.Tested
Windows 11 Pro (10.0.26200), Python 3.14.7, CPU only. No GPU, no
llvm-mc, no SPIRV-Tools on this machine, so I did not build the GPU fixtures and I did not runspirv-val. No game files.New test file
tests/semantic/test_wave64_uniform_load.py(12 tests). Each program is a hand-written vertex shader. It is translated and then run onspirv_wave_interp.pyas one 64-lane wave and as two 32-lane waves. The memory is a structured buffer of 16 records, record i = 1000 + i.v_readfirstlane_b32of a load at a constant indexv_readlane_b32at lanes 40 and 7 of a load at a scalar index (s4 = 5)idxenandoffen(index 3, offset 4, records of 8 bytes)cross-lanecross-lanecross-lanev_mov_b32_sdwa ... UNUSED_PRESERVE)cross-lanesoffsetiss_bcnt1_i32_b64of EXEClane-countbuffer_store_dwordor abuffer_atomic_addidxencross-lanelanein lanelane, and theidxenload with the same V# is tier B and equalNegative controls.
idxenpart of the last row.maind0835dd9without wave64_halves: preserve destination taint on partial writes and reject asymmetric DPP row_mask #4373, 1 test fails: the index that is written in part is tier B, and the two runs differ. This is why this pull request depends on wave64_halves: preserve destination taint on partial writes and reject asymmetric DPP row_mask #4373.747b4313has a rule of its own for partial writes. With this commit cherry-picked on that head (without wave64_halves: preserve destination taint on partial writes and reject asymmetric DPP row_mask #4373), all 12 tests pass also. Thus one of the two pull requests is sufficient, and this branch is on wave64_halves: preserve destination taint on partial writes and reject asymmetric DPP row_mask #4373 because that one is the smaller base.The wave interpreter.
spirv_wave_interp.pyhad no memory, so it could not run abuffer_load. It now takesmemory(byte address to 32-bit word, read-only):OpConvertUToPtrto a PhysicalStorageBuffer pointer,OpAccessChaininto it andOpLoadof one 4-byte element. A load from an address that the memory does not hold raises, and so does a store.tests/semantic/test_spirv_wave_interp.pyhas 4 new tests on a hand-written module (15 tests, all pass).Other runs.
tests/semantic/test_wave64_halves.py,test_wave64_halves_soundness.py,test_wave64_halves_partial_dst.pypython -I -m unittest discover -s tests/semantic47b43d81gives 7,469 tests with the same 7 failures and 3 errors on this machine, compared by test name:test_loop_ballot_barrier(5),test_cmp_class_f64(2),test_mutations(2),test_vcmp16_opsel(1). None of them is in a file that this pull request changespytestontests/test_wave64_halves_fixtures.py,test_w64_graphics_args.py,test_w64_graphics_reference.py,test_wave64_graphics_scan.py, the docs row tests,test_semantic_translator_use.py,test_text_write_line_endings.py,test_resource_hygiene.pyllvm-mc)python -I -m compileall -q make_game.py tools tests,git diff --check,scripts/check_no_game_data.pyThe 9 more listings: an index from an SGPR that is set in a skip region (tier C, different); a descriptor word from
v_readfirstlane_b32of a varying value (tier C, different); a load whose destination is its index register (tier B, equal); a load in a loop with a scalar trip count (tier B, equal);v_readfirstlane_b32of the loaded VGPR under a narrowed EXEC (tier B, equal, as for a VGPR written from a scalar). One listing is tier B and the two runs differ: the load is in the run side of an EXEC vote that restores the launch mask before the join. That is the defect that #4541 corrects; the same listing withv_mov_b32_e32 v4, s4in the place of the load is tier B onmainand differs also. In a local merge of this branch with #4541, the two listings are tier Cunconfined-vote-sideand all tests of the two pull requests pass.Effect on the emitted SPIR-V. The rule changes the tier metadata, and it adds instructions to the set whose
v_readlane_b32reads the lane's own copy (the rewrite that thereadlane-uniformidiom already uses). No other emitted code changes.Not measured: the corpus
I have no copy of the game, so I cannot say how many shaders this rule moves from tier C. If you have your own copy, please run the census before and after, counts only:
on an index translated with #4373
47b43d81and on one translated with this branch. The numbers of interest are tier A/B/C for each stage, the reasonscross-lane,tainted-branch,tainted-execandwaterfall-scalar, and the idiom tagsreadfirstlane-uniformandreadlane-uniform. A shader that has other reasons too stays tier C, so the reason counts can move more than the tiers.Limits
buffer_load_*withidxen.tbuffer_load_format_*,global_load_*and the image loads with an explicit level are possible later, each with its own test.idxen(a raw buffer) stays out because of ADD_TID_ENABLE. If the census shows that such loads are frequent, that needs a decision about run-time V#s.st["ua"]) is the work for values that are uniform in the lanes that are on.Overlap
st["u"]for its uniform compares. With this commit on wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) #4138747b4313, a loaded value that goes to a uniform compare and ans_cbranch_vcczif/else is tier A and the two runs are equal (it is tier Cunsafe-vote-branchwithout wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) #4138). The only text conflict is the SHADER-10 row.tools/wave64_halves.py. The SHADER-10 row is one line ofdocs/design.md, so each of these pull requests conflicts there with the others.Checklist
docs/design.md, with how it was confirmed.AI-assisted (Claude Code): it wrote the change and ran all the checks above on this machine.
🤖 Generated with Claude Code