Shaders: declare wave operations from the wave intrinsics made #2105

Closed
github-bot wants to merge 1 commit from gh-pr/2105/head into gh-pr/2105/base
Owner

@⁠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 merging

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 that ds_swizzle, v_readlane, v_mbcnt, DPP and the like pass before reading their sources, raised it;
  • so did the host-lane v_readlane and v_mbcnt branches.

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::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).
  • The ten places that raised it beforehand no longer do. cross_lane is 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

  • New test emit::lower::tests::a_cross_lane_operation_left_out_declares_no_wave_operations: swizzles a register holding s0 (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 on main, so the test fails there. It then swizzles the thread id and checks the flag is up.
  • The existing tests that check Lowered::wave_ops (the waterfall loops, ballots, lane reads) pass unchanged.
  • cargo test --release -p victory-shader --lib on 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 on main on this GPU (#1835).
  • cargo clippy -p victory-shader --all-targets --features host: clean.

#2056 fixes the 64-bit flag; the "none of 123,669" figure above is with both.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 05:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105) `0xkn0wh3r3:shaders/wave-ops-flag-from-the-ops-made` → `main` · +25 −12 · 2 files · 1 commits · closed without merging ## 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 that `ds_swizzle`, `v_readlane`, `v_mbcnt`, DPP and the like pass before reading their sources, raised it; - so did the host-lane `v_readlane` and `v_mbcnt` branches. 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::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`). - The ten places that raised it beforehand no longer do. `cross_lane` is 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 - New test `emit::lower::tests::a_cross_lane_operation_left_out_declares_no_wave_operations`: swizzles a register holding `s0` (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 on `main`, so the test fails there. It then swizzles the thread id and checks the flag is up. - The existing tests that check `Lowered::wave_ops` (the waterfall loops, ballots, lane reads) pass unchanged. - `cargo test --release -p victory-shader --lib` on 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 on `main` on 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:58 +00:00
github-bot closed this pull request 2026-11-26 04:54:58 +00:00
Author
Owner

@⁠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.dll 1.9.

Alone, over the whole corpus:

build Flags must match usage validated
main 940d32f 871 23,918
this branch 868 23,918

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 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):

build Flags must match usage validated
#2105 + #2016 0 24,785

and cargo test -p victory-shader --locked --lib 249 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:

  • the opcode ranges are the right ones: 110–123 covers WaveIsFirstLane … QuadOp, and 165–167 covers WaveMatch … WaveMultiPrefixBitCount. Quads belong in the same flag — DXIL.rst lists QuadReadLaneAt, QuadOp and QuadVote in bit 19's criterion — so raising it for 122/123 is correct, not overreach;
  • nothing reads the flag mid-emission in a way this breaks: the only remaining read is Lowered.wave_ops at lower.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;
  • the ten eager sites are gone on the branch, so there is no path left that declares the flag without emitting one.

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.

**@⁠fiestorra** on GitHub · 2026-11-25 05:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105#issuecomment-7154272386) **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.dll` 1.9. **Alone**, over the whole corpus: | build | `Flags must match usage` | validated | |---|---|---| | `main` `940d32f` | 871 | 23,918 | | this branch | **868** | 23,918 | 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 `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): | build | `Flags must match usage` | validated | |---|---|---| | #2105 + #2016 | **0** | **24,785** | and `cargo test -p victory-shader --locked --lib` **249 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: - **the opcode ranges are the right ones**: 110–123 covers `WaveIsFirstLane` … `QuadOp`, and 165–167 covers `WaveMatch` … `WaveMultiPrefixBitCount`. Quads belong in the same flag — `DXIL.rst` lists `QuadReadLaneAt`, `QuadOp` and `QuadVote` in bit 19's criterion — so raising it for 122/123 is correct, not overreach; - **nothing reads the flag mid-emission** in a way this breaks: the only remaining read is `Lowered.wave_ops` at `lower.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; - **the ten eager sites are gone** on the branch, so there is no path left that declares the flag without emitting one. 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.
Author
Owner

@⁠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:

  • Phis nothing reads (live()). A wave op can't be one of those. Shader::op emits a call through Module::call, which pushes it into its block's body, and every body instruction is written.
  • Blocks not reachable from the entry. Layout is a DFS from block 0, so a block nothing branches to is never written, and neither are its instructions. Lowering makes no DXIL block for an unreachable IR block (Lower::block: "unreachable: none"). The helper blocks it adds (waterfalls, guarded reads) are branched to when they're made. A CondBr keeps 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_info lands first, I'll rebase this onto it and derive the wave bit there from the instructions that get written.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105#issuecomment-7155767577) 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: - **Phis nothing reads** (`live()`). A wave op can't be one of those. `Shader::op` emits a call through `Module::call`, which `push`es it into its block's body, and every body instruction is written. - **Blocks not reachable from the entry.** Layout is a DFS from block 0, so a block nothing branches to is never written, and neither are its instructions. Lowering makes no DXIL block for an unreachable IR block (`Lower::block`: "unreachable: none"). The helper blocks it adds (waterfalls, guarded reads) are branched to when they're made. A `CondBr` keeps 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_info` lands first, I'll rebase this onto it and derive the wave bit there from the instructions that get written.
Author
Owner

@⁠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 21ae3c13 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105#issuecomment-7157295595) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 21ae3c13 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:40 UTC · original

Automated triage for the maintainers.

flags::WAVE_OPS is now raised in Shader::op (emit/shader.rs) for DXIL opcodes 110-123 and 165-167. The ten places in emit/lower.rs that 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 outside Shader::op, and the opcodes it leaves out (135/136, 222) are not used. The new test fails on main and 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

**@⁠Marvisak** on GitHub · 2026-11-25 10:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105#issuecomment-7160014215) <!-- victory-triage v1 head=21ae3c138d9e4cc052a8c1209c83362a1433ebe1 verdict=merge-candidate at=2026-11-25T10:40:11Z --> Automated triage for the maintainers. `flags::WAVE_OPS` is now raised in `Shader::op` (`emit/shader.rs`) for DXIL opcodes 110-123 and 165-167. The ten places in `emit/lower.rs` that 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 outside `Shader::op`, and the opcodes it leaves out (135/136, 222) are not used. The new test fails on `main` and 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](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 18:51 UTC · original

Closing: upstream 286a00e covers this. The wave-operation flag is now derived from the instructions the writer actually writes (Module::uses in Shader::finish). That's the serialisation-time derivation discussed above, and it also covers ops in blocks the writer now drops. @⁠fiestorra, together with a1a2077 (the UAV bit), the Flags must match usage class should now be closed on main itself.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 18:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2105#issuecomment-7171489797) Closing: upstream 286a00e covers this. The wave-operation flag is now derived from the instructions the writer actually writes (`Module::uses` in `Shader::finish`). That's the serialisation-time derivation discussed above, and it also covers ops in blocks the writer now drops. @⁠fiestorra, together with a1a2077 (the UAV bit), the `Flags must match usage` class should now be closed on `main` itself.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2105
No description provided.