Shaders: derive TYPED_UAV_LOADS and ROVs flags from surviving calls #2610

Open
github-bot wants to merge 1 commit from github-bot/gh-2610 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 16:46 UTC · original
fuzeofficlal:fix/shader-dce-typed-uav-loads-flag → main · +93 −7 · 3 files · 1 commits · open

Summary

Shader::finish reconciles module shader flags from Module::uses() so instructions dropped by dead-code elimination or constant-branch folding do not leave stale feature flags behind. TYPED_UAV_LOADS and ROVS were still set imperatively during lowering and were not reconciled against surviving instructions.

When a typed UAV bufferLoad.f32 or textureLoad.f32 has an unused result (dropped by DCE) or sits in an unreachable constant branch, TYPED_UAV_LOADS (1 << 13) remained set in the module flags, causing the Windows SDK DXIL validator (dxil.dll) to reject the shader with Flags must match usage. Likewise, ROVS remained set if every ROV-annotated handle was dropped.

Changes

  • crates/victory-shader/src/emit/bitcode.rs:
    • Add Uses::typed_uav_loads and Uses::rovs.
    • Add Module::resource_props0 to read props0 from a dx.op.annotateHandle call and derive rovs (props0 & 0x2000 != 0) and typed_uav_loads (surviving dx.op.bufferLoad.* / dx.op.textureLoad.* on a typed UAV handle props0 & 0x1000 != 0 && (1..=10).contains(&(props0 & 0xFF))) in Module::uses().
  • crates/victory-shader/src/emit/shader.rs:
    • Sync flags::TYPED_UAV_LOADS and flags::ROVS from uses in Shader::finish.
    • Add typed_uav_load_flags_follow_dce covering dead vs. live typed UAV bufferLoad.f32 and textureLoad.f32 with and without surviving stores and ROV annotations, validated through dxil.dll.
  • crates/victory-shader/src/emit/lower.rs:
    • Drop imperative self.s.flags |= flags::TYPED_UAV_LOADS / flags::ROVS writes and read self.s.m.uses().rovs for test reporting.

Verification

  • Negative control (before fix): DXIL validator rejects the dead typed UAV load cases with Flags must match usage. Flags declared=8192, actual=0.
  • cargo test -p victory-shader --lib emit::shader::tests and pops — pass (dxil.dll validation passes across all buffer/texture/ROV/store/read combinations).
  • cargo clippy -p victory-shader --all-targets -- -D warnings — pass (0 warnings).
  • cargo xtask policy — pass (184 files ok).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/2610) `fuzeofficlal:fix/shader-dce-typed-uav-loads-flag` → `main` · +93 −7 · 3 files · 1 commits · open ## Summary `Shader::finish` reconciles module shader flags from `Module::uses()` so instructions dropped by dead-code elimination or constant-branch folding do not leave stale feature flags behind. `TYPED_UAV_LOADS` and `ROVS` were still set imperatively during lowering and were not reconciled against surviving instructions. When a typed UAV `bufferLoad.f32` or `textureLoad.f32` has an unused result (dropped by DCE) or sits in an unreachable constant branch, `TYPED_UAV_LOADS` (`1 << 13`) remained set in the module flags, causing the Windows SDK DXIL validator (`dxil.dll`) to reject the shader with `Flags must match usage`. Likewise, `ROVS` remained set if every ROV-annotated handle was dropped. ## Changes - `crates/victory-shader/src/emit/bitcode.rs`: - Add `Uses::typed_uav_loads` and `Uses::rovs`. - Add `Module::resource_props0` to read `props0` from a `dx.op.annotateHandle` call and derive `rovs` (`props0 & 0x2000 != 0`) and `typed_uav_loads` (surviving `dx.op.bufferLoad.*` / `dx.op.textureLoad.*` on a typed UAV handle `props0 & 0x1000 != 0 && (1..=10).contains(&(props0 & 0xFF))`) in `Module::uses()`. - `crates/victory-shader/src/emit/shader.rs`: - Sync `flags::TYPED_UAV_LOADS` and `flags::ROVS` from `uses` in `Shader::finish`. - Add `typed_uav_load_flags_follow_dce` covering dead vs. live typed UAV `bufferLoad.f32` and `textureLoad.f32` with and without surviving stores and ROV annotations, validated through `dxil.dll`. - `crates/victory-shader/src/emit/lower.rs`: - Drop imperative `self.s.flags |= flags::TYPED_UAV_LOADS` / `flags::ROVS` writes and read `self.s.m.uses().rovs` for test reporting. ## Verification - Negative control (before fix): DXIL validator rejects the dead typed UAV load cases with `Flags must match usage. Flags declared=8192, actual=0`. - `cargo test -p victory-shader --lib emit::shader::tests` and `pops` — pass (`dxil.dll` validation passes across all buffer/texture/ROV/store/read combinations). - `cargo clippy -p victory-shader --all-targets -- -D warnings` — pass (0 warnings). - `cargo xtask policy` — pass (`184 files ok`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:15 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:15 UTC · original

WARP verification of 0f19565 merged cleanly onto origin/main 13f91ca (detached checkout).

Environment: Windows 11. No physical GPU device was created: VICTORY_WARP=1, VICTORY_D3D12_WARP=1, cargo -j 4, separate CARGO_TARGET_DIR. dxil.dll was present (Windows Kits 10.0.26100.0 x64), so the validator inside typed_uav_load_flags_follow_dce actually ran.

Adapter audit: Host::new in emit/host.rs is the only path in victory-shader that enumerates adapters or calls D3D12CreateDevice. It reads VICTORY_WARP=1 even when called as Host::new(false), so no executed test touched a hardware adapter.

Commands and results:

  • cargo clippy -j 4 -p victory-shader --all-targets: clean.
  • cargo test -j 4 -p victory-shader --lib typed_uav_load_flags: 1 passed.
  • cargo test -j 4 -p victory-shader --lib: 268 passed, 3 failed, 3 ignored. origin/main under the same WARP setup: 267 passed, 3 failed, 3 ignored. The same 3 fail on both: synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number and permutes_read_the_lane_named_and_zero_from_lanes_left_out ("no pipeline for a wave of 32"), and gathers_at_a_level_match_the_hardware. They compare against hardware behaviour WARP does not reproduce, so they are unrelated to this PR.
  • Negative control: dropping the two new (flags::TYPED_UAV_LOADS, ...) / (flags::ROVS, ...) entries from the flag derivation makes the new test fail.

Review notes: no bugs found. The flags are now derived from the instructions that survive DCE (Uses), matching the "Flags must match usage" validator rule. The 0x1000 / 0x2000 props checks and the (1..=10) kind range look consistent with how handle() builds them. No sibling PR overlap found in emit/.

Not tested: hardware-adapter results (the 3 failures above are WARP-only limits), a physical GPU, or a retail title.

Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used.

**@⁠oni-swr** on GitHub · 2026-11-25 17:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2610#issuecomment-7169245359) **WARP verification** of `0f19565` merged cleanly onto `origin/main` `13f91ca` (detached checkout). Environment: Windows 11. No physical GPU device was created: `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `cargo -j 4`, separate `CARGO_TARGET_DIR`. `dxil.dll` was present (Windows Kits 10.0.26100.0 x64), so the validator inside `typed_uav_load_flags_follow_dce` actually ran. Adapter audit: `Host::new` in `emit/host.rs` is the only path in `victory-shader` that enumerates adapters or calls `D3D12CreateDevice`. It reads `VICTORY_WARP=1` even when called as `Host::new(false)`, so no executed test touched a hardware adapter. Commands and results: - `cargo clippy -j 4 -p victory-shader --all-targets`: clean. - `cargo test -j 4 -p victory-shader --lib typed_uav_load_flags`: 1 passed. - `cargo test -j 4 -p victory-shader --lib`: **268 passed, 3 failed, 3 ignored**. `origin/main` under the same WARP setup: 267 passed, 3 failed, 3 ignored. The same 3 fail on both: `synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out` ("no pipeline for a wave of 32"), and `gathers_at_a_level_match_the_hardware`. They compare against hardware behaviour WARP does not reproduce, so they are unrelated to this PR. - Negative control: dropping the two new `(flags::TYPED_UAV_LOADS, ...)` / `(flags::ROVS, ...)` entries from the flag derivation makes the new test fail. Review notes: no bugs found. The flags are now derived from the instructions that survive DCE (`Uses`), matching the "Flags must match usage" validator rule. The `0x1000` / `0x2000` props checks and the `(1..=10)` kind range look consistent with how `handle()` builds them. No sibling PR overlap found in `emit/`. Not tested: hardware-adapter results (the 3 failures above are WARP-only limits), a physical GPU, or a retail title. _Independent review and WARP verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or retail data were used._
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:51 UTC · original

Reviewed: resource_props0 correctly digs the props aggregate out of dx.op.annotateHandle — bit 0x2000 ROV and bit 0x1000 TYPED_UAV_LOADS (gated on a resource-kind range) match the DXIL resource-properties layout, and reading the annotation directly for loads is the right call since lowering builds the handle's index first. Deriving the flags from surviving calls rather than declared usage is the validator-safe direction. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2610#issuecomment-7170086166) Reviewed: `resource_props0` correctly digs the props aggregate out of `dx.op.annotateHandle` — bit 0x2000 ROV and bit 0x1000 TYPED_UAV_LOADS (gated on a resource-kind range) match the DXIL resource-properties layout, and reading the annotation directly for loads is the right call since lowering builds the handle's index first. Deriving the flags from surviving calls rather than declared usage is the validator-safe direction. CI green.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:21 UTC · original

Automated triage for the maintainers.

This moves TYPED_UAV_LOADS and ROVS from imperative sets in Lower (crates/victory-shader/src/emit/lower.rs) into the Module::uses reconciliation in Shader::finish, deriving them from surviving dx.op.annotateHandle / bufferLoad / textureLoad calls via the new Module::resource_props0 (crates/victory-shader/src/emit/bitcode.rs), so a load dropped by DCE no longer leaves a flag the validator rejects. I checked that main still sets these flags imperatively, that the UAV bit (0x1000), ROV bit (0x2000) and typed kind range 1..=10 match how lowering builds props0, and that the new test runs the cases through dxil.dll. One small note: the check ignores the component count in props1, which is fine while lowering always declares four channels (0x409). CI: check passing.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2610#issuecomment-7177442382) <!-- victory-triage v1 head=a954da38408ea2dd65d17c7a83aef0c67043b51a verdict=merge-candidate at=2026-11-25T23:20:57Z --> Automated triage for the maintainers. This moves `TYPED_UAV_LOADS` and `ROVS` from imperative sets in `Lower` (crates/victory-shader/src/emit/lower.rs) into the `Module::uses` reconciliation in `Shader::finish`, deriving them from surviving `dx.op.annotateHandle` / `bufferLoad` / `textureLoad` calls via the new `Module::resource_props0` (crates/victory-shader/src/emit/bitcode.rs), so a load dropped by DCE no longer leaves a flag the validator rejects. I checked that main still sets these flags imperatively, that the UAV bit (0x1000), ROV bit (0x2000) and typed kind range 1..=10 match how lowering builds props0, and that the new test runs the cases through `dxil.dll`. One small note: the check ignores the component count in props1, which is fine while lowering always declares four channels (0x409). CI: `check` passing. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2610/head:github-bot/gh-2610'
git switch 'github-bot/gh-2610'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2610'
git switch 'github-bot/gh-2610'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2610'
git switch 'github-bot/gh-2610'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2610'
git switch 'main'
git merge --squash 'github-bot/gh-2610'
git switch 'main'
git merge --ff-only 'github-bot/gh-2610'
git switch 'main'
git merge 'github-bot/gh-2610'
git push origin 'main'
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!2610
No description provided.