Repository navigation
Shaders: declare wave operations from the wave intrinsics made - #2105
0xkn0wh3r3 wants to merge 1 commit into
Conversation
The module's wave operation flag (`flags::WAVE_OPS`) was raised by the
lowerings that make cross-lane operations, at their start: `cross_lane`,
the gate `ds_swizzle`, `v_readlane`, `v_mbcnt`, DPP and the like pass
before reading their sources, raised it, and so did the host-lane
`v_readlane` and `v_mbcnt` branches. When a source then had no DXIL
value the instruction was left out, and when nothing read its result the
program translated with the flag and no wave operation. The validator
refuses such a module ("Flags must match usage", bit 19 declared and not
used).
`Shader::op` now raises the flag as it makes a wave or quad intrinsic
(DXIL operations 110 to 123, `WaveIsFirstLane` .. `QuadOp`, and 165 to
167, `WaveMatch` .. `WaveMultiPrefixBitCount`), and the ten places that
raised it beforehand no longer do; `cross_lane` is only the check.
Found by validating random programs (Marvisak#1335's generator with a validation
pass, validator 1.6): 2 of 164,934 translated programs out of 2,000,000
had the flag without a wave operation. With this, none of 123,669 out of
1,500,000 has a flag mismatch either way (with Marvisak#2056 for the 64-bit
flag).
The new test swizzles a register holding `s0` (user SGPRs no root
parameter fills: no value), left out, and checks the flag stays down (it
is up on `main`); of the thread id, that it is up.
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-shader --lib a_cross_lane_operation_left_out_declares_no_wave_operations— passedcargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean fix declaring WAVE_OPS only when wave intrinsics are actually emitted. Looks good.
AI-assisted (Gemini 4 Neon).
|
Reviewed with the census: the change is right, it clears three programs on its own, and with #2016 the class goes to zero The direction is the one that has cost this tree the most this week — declare what the module actually contains, not what the lowering intended — so I measured it rather than argued about it, on a local 1.0.2.1 archive (26,503 containers), validator SDK 10.0.26100 Alone, over the whole corpus:
So it clears three programs here. That is not a criticism — it is the size of the problem it names — but it is worth putting in the record, because the remaining 868 are all Together with #2016, which merges cleanly onto it (I merged, built and ran):
and Three things I checked in the diff and can vouch for:
One residual risk, which I would write down rather than "fix": the flag is now raised when the op is emitted, so an op that is emitted and then discarded by a later pass would bring the original error back. Does anything drop emitted ops today? If the answer is "structurisation can prune a block", then the correct place is the same place the module's flags are serialised — which is what my #2016 turned into No game data is involved: counts, opcode numbers and error text. Written with an AI assistant. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.
145 passed / 0 failed / 2 ignored. Wave operations declared from wave intrinsics masks (+1 test) — capability declaration from actual intrinsic usage.
|
Thanks for the census numbers, and for running it with #2016. Good to have on record that this PR clears 3 and the other 868 are the UAV bit. On the question: I checked the writer (
So today nothing drops an op after it's emitted, and I didn't find a pruning pass either. Still, block reachability in the writer is the one place it could happen: a future change that emits into a block and then never branches to it would bring the error back. I agree the robust place is wherever the flags are serialised. If #2016's |
Offline measurement on a retail dumpResult: no count change against I merged head 21ae3c1 onto No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
|
Automated triage for the maintainers.
Generated by Claude Code |
The problem
Some translated programs are refused by the DXIL validator: the module declares wave operations (bit 19,
flags::WAVE_OPS) but contains none. The validator reports "Flags must match usage".The flag was raised by the lowerings that make cross-lane operations, at their start, before the operation was made:
cross_lane, the gate thatds_swizzle,v_readlane,v_mbcnt, DPP and the like pass before reading their sources, raised it;v_readlaneandv_mbcntbranches.When a source then had no DXIL value, the instruction was left out. When nothing read its result, the program translated with the flag up and no wave operation in it.
How it was found
By validating random programs (#1335's generator with a validation pass, validator 1.6): 2 of 164,934 translated programs out of 2,000,000 had the flag without a wave operation.
The fix
Shader::opnow raises the flag as it makes a wave or quad intrinsic: DXIL operations 110 to 123 (WaveIsFirstLane..QuadOp) and 165 to 167 (WaveMatch..WaveMultiPrefixBitCount).cross_laneis now only the check.The flag now follows the operations actually in the module. With this, none of 123,669 translated programs out of 1,500,000 has a flag mismatch either way (with #2056 for the 64-bit flag).
Testing
emit::lower::tests::a_cross_lane_operation_left_out_declares_no_wave_operations: swizzles a register holdings0(user SGPRs no root parameter fills, so no value). The swizzle is left out, and the test checks the flag stays down; it is up onmain, so the test fails there. It then swizzles the thread id and checks the flag is up.Lowered::wave_ops(the waterfall loops, ballots, lane reads) pass unchanged.cargo test --release -p victory-shader --libon an RTX 5070 Ti: 245 passed. The 3 failures (emit::stride_tests::*x2,emit::synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way onmainon this GPU (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).cargo clippy -p victory-shader --all-targets --features host: clean.Related
#2056 fixes the 64-bit flag; the "none of 123,669" figure above is with both.