Shaders: infer heap UAVs program-wide and emit IsGloballyCoherent on glc UAVs #1354

Closed
wbkepler wants to merge 1 commit from upstream-pr/1354 into main
wbkepler commented 2026-11-24 17:35:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T17:35:15Z.


Summary

Implements #724 and #725 in crates/victory-shader/src/emit/{lower.rs,shader.rs}:

  • #724 (infer_uav_heaps / UavHeaps / is_uav): Program-wide scan marking heap descriptor sources with any store, atomic, or dynamic-heap glc access as UAVs so loads, stores, atomics, descriptor_data, and s_buffer_load* all use UAV handles (0x1000 / 0x100B) instead of SRV/CBV, while read-only non-glc heap descriptors keep SRV/CBV.
  • #725 (IsGloballyCoherent): ORs 0x4000 onto glc UAV buffer, image, and s_buffer_load ResourceProperties (never on SRVs/CBVs).
  • Adds 3 unit + dxil.dll-validation tests (heap_buffer_load_and_store_both_emit_raw_uav_and_validate, heap_s_buffer_load_with_buffer_store_emits_raw_uav_and_validates, glc_uav_buffer_and_image_loads_emit_globally_coherent_and_validate).

Verification

  • cargo clippy -p victory-shader --all-targets -- -D warnings — passed
  • cargo test -p victory-shader — passed (123 passed, 1 ignored)
  • cargo xtask policy — passed (154 files ok)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6587734102 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T17:35:15Z. --- ## Summary Implements #724 and #725 in `crates/victory-shader/src/emit/{lower.rs,shader.rs}`: - **#724 (`infer_uav_heaps` / `UavHeaps` / `is_uav`)**: Program-wide scan marking heap descriptor sources with any store, atomic, or dynamic-heap `glc` access as UAVs so loads, stores, atomics, `descriptor_data`, and `s_buffer_load*` all use UAV handles (`0x1000` / `0x100B`) instead of SRV/CBV, while read-only non-`glc` heap descriptors keep SRV/CBV. - **#725 (`IsGloballyCoherent`)**: ORs `0x4000` onto `glc` UAV buffer, image, and `s_buffer_load` `ResourceProperties` (never on SRVs/CBVs). - Adds 3 unit + `dxil.dll`-validation tests (`heap_buffer_load_and_store_both_emit_raw_uav_and_validate`, `heap_s_buffer_load_with_buffer_store_emits_raw_uav_and_validates`, `glc_uav_buffer_and_image_loads_emit_globally_coherent_and_validate`). ## Verification - `cargo clippy -p victory-shader --all-targets -- -D warnings` — passed - `cargo test -p victory-shader` — passed (123 passed, 1 ignored) - `cargo xtask policy` — passed (154 files ok)
catminou4 commented 2026-11-24 18:04:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T17:42:45Z.

Review: APPROVED


Program-wide heap UAV inference: used_kind_of resolves a descriptor (loaded/fetched/built/phi/select/lanes) back to its used-resource entry, UAVs get raw UAV handles program-wide and glc accesses emit IsGloballyCoherent. Superset of #1271 (approved earlier today) — whichever lands second will need a rebase; consider landing this one and closing #1271. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p <crate> --locked. Shader execution tests (valu_tests/host/diff_tests) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 99 passed, 0 failed; the three new tests are lowering+validator (validator part Windows-gated).

<!-- greyfinch-sync:Marvisak/VIctory:review:6044389302 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354#pullrequestreview-6044389302). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T17:42:45Z. **Review:** APPROVED --- Program-wide heap UAV inference: used_kind_of resolves a descriptor (loaded/fetched/built/phi/select/lanes) back to its used-resource entry, UAVs get raw UAV handles program-wide and glc accesses emit IsGloballyCoherent. Superset of #1271 (approved earlier today) — whichever lands second will need a rebase; consider landing this one and closing #1271. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, `cargo test -p <crate> --locked`. Shader execution tests (valu_tests/host/diff_tests) are `#[cfg(all(test, windows))]`, so macOS covers lowering/decode/unit tests only. 99 passed, 0 failed; the three new tests are lowering+validator (validator part Windows-gated).
wildheathen commented 2026-11-24 19:04:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wildheathen on 2026-11-24T18:19:27Z.


#1271 and #1354 compared: same output on a retail dump, small differences in scope

Both PRs fix #724 and #725 (heap UAV inference, IsGloballyCoherent on glc UAV access) and both are based on main ffe310e. I'm not the author of either. I measured them the same way so review can pick one.

Setup: Windows 11, RTX 5080 (driver 32.0.16.2124), Rust 1.98.1 MSVC, dxil.dll 10.0.26100. Offline translation only (no title run, no world).

Retail dump (victory translate --validate --list, plus VICTORY_EMIT_DUMP to keep every emitted shader)

validated vs main DXIL changed vs main
main ffe310e 21,736
#1271 21,736 0 / 0 176 compute programs
#1354 21,736 0 / 0 176 compute programs
  • The two PRs emit byte-identical DXIL for all 21,882 emitted programs. The 176 they change are the same 176, all compute; no vertex, pixel or mesh program changes.
  • In those 176 programs (disassembled with dxc -dumpbin): 0 → 310 handles with IsGloballyCoherent (0x4000); 1,306 → 1,474 handles with IsUAV (0x1000), i.e. 168 SRV handles become UAVs; barrier counts unchanged.
  • Validation counts don't move, as expected: the change is in handle properties, not in which programs are accepted.

Tests

  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean on both.
  • cargo test -p victory-shader -p victory-gpu: main 170 passed; #1271 173; #1354 173 (0 failed, 2 ignored each).
  • Cross-check: each PR's new tests run against the other PR's lowering, and all pass:
    • #1354's code + #1271's tests (two DXIL-property tests, and glc_heap_uav_loads_stores_and_atomics_execute_on_gpu on the GPU): 5 of 5 pass.
    • #1271's code + #1354's three DXIL tests: all pass.

Differences the dump doesn't show

None of these changes a program in this title. They matter only for code the dump doesn't contain.

  1. Which glc accesses count. #1271 infers a UAV from glc on untyped buffer access, image_load/stores/atomics without a sampler, and s_buffer_load*, and drops any address that is also sampled. #1354 takes glc from any buffer, image or SMEM instruction, unless a used-resource entry declares the view SRV or CBV. So a glc typed-buffer load, or a sample with glc on an undeclared heap descriptor, would make a UAV in #1354 and not in #1271.
  2. Barrier fence. #1271 also counts inferred UAVs (written or glc) when deciding whether a compute s_barrier gets the global UAV fence. #1354 leaves that decision as it is on main. In the dump every changed program already had the global fence, so the output is the same. A compute program that only spin-waits on a glc heap load, with no declared UAV, would get the fence from #1271 only.
  3. Size. #1271 is +558/−31 with a GPU execution test. #1354 is +299/−71: it also moves used_kind out to a free function, and its tests are DXIL-only.

Taken together: on this title either one gives the same shaders. #1271 was opened first, covers the barrier case and has a hardware test. #1354's refactor of used_kind is neutral. Merging one and closing the other seems the cleanest; whatever #1354 has that #1271 lacks (typed-buffer glc) can be a follow-up if a title needs it.

No game data, shader bytes or shader names are included here; counts come from a local dump. I haven't run either in the world yet. If useful, I can run the 9ef9a9d818b27236 loop-hang A/B from #725 on the 5080.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140481855 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354#issuecomment-7140481855). Originally posted by [wildheathen](https://github.com/wildheathen) on 2026-11-24T18:19:27Z. --- ## #1271 and #1354 compared: same output on a retail dump, small differences in scope Both PRs fix #724 and #725 (heap UAV inference, `IsGloballyCoherent` on `glc` UAV access) and both are based on main `ffe310e`. I'm not the author of either. I measured them the same way so review can pick one. Setup: Windows 11, RTX 5080 (driver 32.0.16.2124), Rust 1.98.1 MSVC, dxil.dll 10.0.26100. Offline translation only (no title run, no world). ### Retail dump (`victory translate --validate --list`, plus `VICTORY_EMIT_DUMP` to keep every emitted shader) | | validated | vs main | DXIL changed vs main | |---|---:|---:|---:| | main `ffe310e` | 21,736 | | | | #1271 | 21,736 | 0 / 0 | 176 compute programs | | #1354 | 21,736 | 0 / 0 | 176 compute programs | - **The two PRs emit byte-identical DXIL for all 21,882 emitted programs.** The 176 they change are the same 176, all compute; no vertex, pixel or mesh program changes. - In those 176 programs (disassembled with `dxc -dumpbin`): 0 → 310 handles with `IsGloballyCoherent` (`0x4000`); 1,306 → 1,474 handles with `IsUAV` (`0x1000`), i.e. 168 SRV handles become UAVs; barrier counts unchanged. - Validation counts don't move, as expected: the change is in handle properties, not in which programs are accepted. ### Tests - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings`: clean on both. - `cargo test -p victory-shader -p victory-gpu`: main 170 passed; #1271 173; #1354 173 (0 failed, 2 ignored each). - **Cross-check:** each PR's new tests run against the other PR's lowering, and all pass: - #1354's code + #1271's tests (two DXIL-property tests, and `glc_heap_uav_loads_stores_and_atomics_execute_on_gpu` on the GPU): 5 of 5 pass. - #1271's code + #1354's three DXIL tests: all pass. ### Differences the dump doesn't show None of these changes a program in this title. They matter only for code the dump doesn't contain. 1. **Which `glc` accesses count.** #1271 infers a UAV from `glc` on untyped buffer access, `image_load`/stores/atomics without a sampler, and `s_buffer_load*`, and drops any address that is also sampled. #1354 takes `glc` from any buffer, image or SMEM instruction, unless a used-resource entry declares the view SRV or CBV. So a `glc` typed-buffer load, or a sample with `glc` on an undeclared heap descriptor, would make a UAV in #1354 and not in #1271. 2. **Barrier fence.** #1271 also counts inferred UAVs (written or `glc`) when deciding whether a compute `s_barrier` gets the global UAV fence. #1354 leaves that decision as it is on main. In the dump every changed program already had the global fence, so the output is the same. A compute program that only spin-waits on a `glc` heap load, with no declared UAV, would get the fence from #1271 only. 3. **Size.** #1271 is +558/−31 with a GPU execution test. #1354 is +299/−71: it also moves `used_kind` out to a free function, and its tests are DXIL-only. Taken together: on this title either one gives the same shaders. #1271 was opened first, covers the barrier case and has a hardware test. #1354's refactor of `used_kind` is neutral. Merging one and closing the other seems the cleanest; whatever #1354 has that #1271 lacks (typed-buffer `glc`) can be a follow-up if a title needs it. No game data, shader bytes or shader names are included here; counts come from a local dump. I haven't run either in the world yet. If useful, I can run the `9ef9a9d818b27236` loop-hang A/B from #725 on the 5080. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 21:02:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:10:02Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 99 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Infers heap UAVs program-wide (infer_uav_heaps/used_kind_of walk phi/select/lane sources to the used-resource entry) and emits IsGloballyCoherent on glc UAVs. Tests validate the emitted DXIL for heap buffer load+store, s_buffer_load with buffer_store, and glc image loads. The inference is conservative (first matching used entry by table offset); worth a Windows playability check since it changes resource flags.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046560684 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354#pullrequestreview-6046560684). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:10:02Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 99 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Infers heap UAVs program-wide (infer_uav_heaps/used_kind_of walk phi/select/lane sources to the used-resource entry) and emits IsGloballyCoherent on glc UAVs. Tests validate the emitted DXIL for heap buffer load+store, s_buffer_load with buffer_store, and glc image loads. The inference is conservative (first matching used entry by table offset); worth a Windows playability check since it changes resource flags.
Jitheswar commented 2026-11-24 22:02:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jitheswar on 2026-11-24T21:58:09Z.


I found a synthetic SRV regression on cd9699f. In the existing WATERFALL_INDEXED_WAVE32 fixture, set bit 13 on the image_sample_lz instruction's first dword (0xF09C_0F08 → 0xF09C_2F08) and omit the texture's SRV entry from NativeProgram.used. Keep the bound textures, sampler, UAV, and expected readback unchanged.

On RTX 3050 under Proton, ffe310e and #1271 (25d9e2a) both produced the expected readback. This PR rejected the same program during lowering with sampling a UAV. The glc-only inference includes sampled image operations and promotes their untyped descriptor to UAV. Excluding sampled descriptors from that inference would preserve this path.

Synthetic fixture only. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145627527 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354#issuecomment-7145627527). Originally posted by [Jitheswar](https://github.com/Jitheswar) on 2026-11-24T21:58:09Z. --- I found a synthetic SRV regression on `cd9699f`. In the existing `WATERFALL_INDEXED_WAVE32` fixture, set bit 13 on the `image_sample_lz` instruction's first dword (`0xF09C_0F08` → `0xF09C_2F08`) and omit the texture's SRV entry from `NativeProgram.used`. Keep the bound textures, sampler, UAV, and expected readback unchanged. On RTX 3050 under Proton, `ffe310e` and #1271 (`25d9e2a`) both produced the expected readback. This PR rejected the same program during lowering with `sampling a UAV`. The glc-only inference includes sampled image operations and promotes their untyped descriptor to UAV. Excluding sampled descriptors from that inference would preserve this path. Synthetic fixture only. AI-assisted with Codex.
upstream-sync closed this pull request 2026-11-25 01:06:19 +00:00
Marvisak commented 2026-11-25 01:08:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:38:19Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1271. Same two issues (#724, #725) as #1271, opened 40 minutes later: program-wide heap UAV inference and IsGloballyCoherent on glc UAVs. #1271 has GPU read-back tests; this has unit and validator tests only.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148721202 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1354#issuecomment-7148721202). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:38:19Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1271. Same two issues (#724, #725) as #1271, opened 40 minutes later: program-wide heap UAV inference and IsGloballyCoherent on glc UAVs. #1271 has GPU read-back tests; this has unit and validator tests only. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1354
No description provided.