Shaders: declare wave operations from the wave intrinsics made #2105
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2105
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2105/head"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 05:05 UTC · original
0xkn0wh3r3:shaders/wave-ops-flag-from-the-ops-made→main· +25 −12 · 2 files · 1 commits · closed without mergingThe 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 (#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.
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 (#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 #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.@fiestorra on GitHub · 2026-11-25 05:55 UTC · original
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
dxil.dll1.9.Alone, over the whole corpus:
Flags must match usagemain940d32fSo 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
VS_…VfxVBuffer…vertex programs whose mismatch is a different bit (the UAV flag, #2016). Anyone reading "871 flags failures" and this pull request should know it removes three of them.Together with #2016, which merges cleanly onto it (I merged, built and ran):
Flags must match usageand
cargo test -p victory-shader --locked --lib249 passed, 3 ignored. So the two are complementary: mine is the UAV bit, yours is wave ops, and the class closes only with both.Three things I checked in the diff and can vouch for:
WaveIsFirstLane…QuadOp, and 165–167 coversWaveMatch…WaveMultiPrefixBitCount. Quads belong in the same flag —DXIL.rstlistsQuadReadLaneAt,QuadOpandQuadVotein bit 19's criterion — so raising it for 122/123 is correct, not overreach;Lowered.wave_opsatlower.rs:1329, and that field is consulted by tests only (I searched the crates: no production reader), so raising later cannot make a decision stale;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
feature_info, and the pair would then be immune. That is a question, not a finding: I did not find a pruning pass in the time I gave this.No game data is involved: counts, opcode numbers and error text.
Written with an AI assistant.
@0xkn0wh3r3 on GitHub · 2026-11-25 07:21 UTC · original
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 (
emit/bitcode.rs,Module::write). It leaves out two things:live()). A wave op can't be one of those.Shader::opemits a call throughModule::call, whichpushes it into its block's body, and every body instruction is written.Lower::block: "unreachable: none"). The helper blocks it adds (waterfalls, guarded reads) are branched to when they're made. ACondBrkeeps both successors even when its condition is a constant.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
feature_infolands first, I'll rebase this onto it and derive the wave bit there from the instructions that get written.@sinan-cmyk on GitHub · 2026-11-25 08:38 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
21ae3c13ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.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).
@Marvisak on GitHub · 2026-11-25 10:40 UTC · original
Automated triage for the maintainers.
flags::WAVE_OPSis now raised inShader::op(emit/shader.rs) for DXIL opcodes 110-123 and 165-167. The ten places inemit/lower.rsthat raised it early are removed (cross_lane,lane_bit,quad_pick,v_readlane/v_readfirstlane,v_mbcnt, ballots, reductions). I found no wave intrinsic emitted outsideShader::op, and the opcodes it leaves out (135/136, 222) are not used. The new test fails onmainand checks both directions. A commenter's census shows it clears 3 "Flags must match usage" programs, and with #2016 the class goes to zero. CI has not run on this head.Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-25 18:51 UTC · original
Closing: upstream
286a00ecovers this. The wave-operation flag is now derived from the instructions the writer actually writes (Module::usesinShader::finish). That's the serialisation-time derivation discussed above, and it also covers ops in blocks the writer now drops. @fiestorra, together witha1a2077(the UAV bit), theFlags must match usageclass should now be closed onmainitself.Pull request closed