Shaders: one heap descriptor gets an SRV handle for its loads and a UAV handle for its stores #724

Open
opened 2026-11-26 04:13:53 +00:00 by github-bot · 5 comments
Owner

@⁠Dufftwt on GitHub · 2026-11-24 08:26 UTC · original

What's wrong

For a descriptor that comes from the SM 6.6 resource heap, rather than a table, the lowering decides SRV or UAV per instruction, from that instruction's name alone:

  • used_kind returns None for any root parameter that isn't a table (crates/victory-shader/src/emit/lower.rs:3257-3259).
  • So uav is true only for stores and atomics: buffers at :6075, images at :5470-5475, descriptor data at :2943-2946.
  • s_buffer_load takes a raw SRV handle only for a known SRV (:2830). Everything else, including a UAV, gets a constant-buffer handle (:2851).

The title holds one UAV descriptor in the heap. Its loads get an SRV-annotated handle (annotateHandle without IsUAV, bit 0x1000) and its stores a UAV handle. The annotation doesn't match the descriptor's type, which is undefined in D3D12.

Example

s_mov_b32 s5, 0                                    BE850380
s_load_dwordx4 s[8:11], s[4:5], 0                  F4080202 FA000000
v_mov_b32 v0, 0                                    7E000280
buffer_load_dword v1, v0, s[8:11], 0 offen         E0301000 80020100
buffer_store_dword v1, v0, s[8:11], 0 offen offset:4   E0701004 80020100
s_endpgm

With the heap layout, the handles' props come out as (0xB, 0) for the load (a raw SRV) and (0x100B, 0) for the store (a raw UAV), for one and the same descriptor. I recorded these with a temporary print in heap_handle.

  • Console: dword 1 = dword 0.
  • Host: whatever the driver does with a UAV descriptor read through an SRV handle.

Suggested fix

Before lowering, mark every descriptor source that has any store, atomic or glc access as a UAV, and give every access through it the UAV form. A UAV s_buffer_load then uses the raw (11 | 0x1000) path instead of a constant buffer. Heap descriptors that are only ever read stay as they are now.

Not tested: on a GPU. How often titles use heap descriptors this way, and what each vendor's driver does with the mismatch, are unknown.

  • #180 and #307 change this code; neither infers UAVs across instructions.
  • #725 (glc loads not globally coherent) needs this inference to know which loads are UAV loads.
**@⁠Dufftwt** on GitHub · 2026-11-24 08:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/724) ## What's wrong For a descriptor that comes from the SM 6.6 resource heap, rather than a table, the lowering decides SRV or UAV **per instruction**, from that instruction's name alone: - `used_kind` returns `None` for any root parameter that isn't a table (`crates/victory-shader/src/emit/lower.rs:3257-3259`). - So `uav` is true only for stores and atomics: buffers at `:6075`, images at `:5470-5475`, descriptor data at `:2943-2946`. - `s_buffer_load` takes a raw SRV handle only for a known SRV (`:2830`). Everything else, including a UAV, gets a constant-buffer handle (`:2851`). The title holds one UAV descriptor in the heap. Its loads get an **SRV**-annotated handle (`annotateHandle` without `IsUAV`, bit `0x1000`) and its stores a **UAV** handle. The annotation doesn't match the descriptor's type, which is undefined in D3D12. ## Example ``` s_mov_b32 s5, 0 BE850380 s_load_dwordx4 s[8:11], s[4:5], 0 F4080202 FA000000 v_mov_b32 v0, 0 7E000280 buffer_load_dword v1, v0, s[8:11], 0 offen E0301000 80020100 buffer_store_dword v1, v0, s[8:11], 0 offen offset:4 E0701004 80020100 s_endpgm ``` With the heap layout, the handles' props come out as `(0xB, 0)` for the load (a raw SRV) and `(0x100B, 0)` for the store (a raw UAV), for one and the same descriptor. I recorded these with a temporary print in `heap_handle`. - Console: dword 1 = dword 0. - Host: whatever the driver does with a UAV descriptor read through an SRV handle. ## Suggested fix Before lowering, mark every descriptor source that has any store, atomic or `glc` access as a UAV, and give every access through it the UAV form. A UAV `s_buffer_load` then uses the raw `(11 | 0x1000)` path instead of a constant buffer. Heap descriptors that are only ever read stay as they are now. **Not tested:** on a GPU. How often titles use heap descriptors this way, and what each vendor's driver does with the mismatch, are unknown. ## Related - #180 and #307 change this code; neither infers UAVs across instructions. - #725 (`glc` loads not globally coherent) needs this inference to know which loads are UAV loads.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:53 +00:00
Author
Owner

@⁠Hiiva on GitHub · 2026-11-24 09:05 UTC · original · edited 2026-11-24 09:32 UTC

Implemented pre-lowering inference of written heap descriptors on https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence. The initial fa119dd/5c26db0 changes have been extended by e67ffc6: inference keys on the tracked heap address, so separate scalar loads of the same descriptor retain UAV classification. Different heap addresses remain distinct. Scalar s_buffer_load also preserves GLC when reading an inferred UAV (#725).

Verification now checks emitted DXIL, not only successful lowering. Scalar-GLC and descriptor-reload regressions fail before the fixes and pass afterward; vector GLC and distinct-address SRV/UAV controls pass. An isolated one-thread WARP dispatch wrote 0x12345678, reloaded the descriptor into different SGPRs, performed a scalar GLC load, and read back [0x12345678, 0x12345678, 0, 0]. The GPU test is opt-in to avoid concurrent device dispatches in the ordinary suite. Clippy passes with warnings denied.

The branch also includes Ortomanic's #177 handle-property-key fix, preserving authorship, plus an SDK-disassembly regression verifying that an integer texture atomic does not reuse a float-typed handle. Five emitted-DXIL resource tests pass.

A descriptor only read by a shader still needs positive type evidence. GLC alone does not establish UAV class, so the unknown scalar-only case is not claimed fixed. All added fixtures are synthetic; these tests do not establish gameplay. External PR creation remains collaborators-only.

**@⁠Hiiva** on GitHub · 2026-11-24 09:05 UTC · [original](https://github.com/Marvisak/VIctory/issues/724#issuecomment-7126943064) · edited 2026-11-24 09:32 UTC Implemented pre-lowering inference of written heap descriptors on https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence. The initial fa119dd/5c26db0 changes have been extended by e67ffc6: inference keys on the tracked heap address, so separate scalar loads of the same descriptor retain UAV classification. Different heap addresses remain distinct. Scalar s_buffer_load also preserves GLC when reading an inferred UAV (#725). Verification now checks emitted DXIL, not only successful lowering. Scalar-GLC and descriptor-reload regressions fail before the fixes and pass afterward; vector GLC and distinct-address SRV/UAV controls pass. An isolated one-thread WARP dispatch wrote 0x12345678, reloaded the descriptor into different SGPRs, performed a scalar GLC load, and read back [0x12345678, 0x12345678, 0, 0]. The GPU test is opt-in to avoid concurrent device dispatches in the ordinary suite. Clippy passes with warnings denied. The branch also includes Ortomanic's #177 handle-property-key fix, preserving authorship, plus an SDK-disassembly regression verifying that an integer texture atomic does not reuse a float-typed handle. Five emitted-DXIL resource tests pass. A descriptor only read by a shader still needs positive type evidence. GLC alone does not establish UAV class, so the unknown scalar-only case is not claimed fixed. All added fixtures are synthetic; these tests do not establish gameplay. External PR creation remains collaborators-only.
Author
Owner

@⁠Hiiva on GitHub · 2026-11-24 10:10 UTC · original

Checked the readonly concern against Microsoft's compiler. SDK DXC 1.8.2502.11 compiled a synthetic globallycoherent RWByteAddressBuffer store/load/store and polling loop at both -O3 and -Od. It emits rawBufferLoad with { nounwind readonly }, stores with { nounwind }, and barriers with { noduplicate nounwind }. The optimized output retains the store-before-load order and the polling load inside the loop. This matches DXC's operation definitions: readonly describes the load's effects, not immutable resource contents. No attribute change is needed.

GLC-only inference still needs descriptor-type evidence. The RDNA2 ISA defines GLC as cache policy for reads/writes, so it does not establish SRV versus UAV class. Marking every GLC read as UAV could mismatch an actual SRV. The implementation uses known UAV metadata or stores/atomics at the same tracked heap address, including descriptor reloads. A scalar-only unknown descriptor remains unresolved until its actual view kind is established.

**@⁠Hiiva** on GitHub · 2026-11-24 10:10 UTC · [original](https://github.com/Marvisak/VIctory/issues/724#issuecomment-7128422811) Checked the `readonly` concern against Microsoft's compiler. SDK DXC 1.8.2502.11 compiled a synthetic `globallycoherent RWByteAddressBuffer` store/load/store and polling loop at both `-O3` and `-Od`. It emits `rawBufferLoad` with `{ nounwind readonly }`, stores with `{ nounwind }`, and barriers with `{ noduplicate nounwind }`. The optimized output retains the store-before-load order and the polling load inside the loop. This matches [DXC's operation definitions](https://github.com/microsoft/DirectXShaderCompiler/blob/main/lib/DXIL/DxilOperations.cpp): `readonly` describes the load's effects, not immutable resource contents. No attribute change is needed. GLC-only inference still needs descriptor-type evidence. The [RDNA2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) defines GLC as cache policy for reads/writes, so it does not establish SRV versus UAV class. Marking every GLC read as UAV could mismatch an actual SRV. The implementation uses known UAV metadata or stores/atomics at the same tracked heap address, including descriptor reloads. A scalar-only unknown descriptor remains unresolved until its actual view kind is established.
Author
Owner

@⁠RID-Games on GitHub · 2026-11-24 09:45 UTC · original · edited 2026-11-24 10:21 UTC

Verified https://github.com/Hiiva/VIctory@hiiva/heap-uav-coherence ([fa119dd](https://github.com/Hiiva/VIctory/commit/fa119dd) + [5c26db0](https://github.com/Hiiva/VIctory/commit/5c26db0)) on Linux (rustc 1.100): cargo test -p victory-shader — 72 passed, 1 ignored. The inference, the shared-handle regression test and the raw s_buffer_load path all look right.

One gap: the pre-pass marks only store/atomic accesses, but the issue asks for "any store, atomic or glc access". A heap descriptor whose only write-adjacent access is a glc load — the spin-wait in #725's example — is never inferred as a UAV: heap_uav is false and resource_flags(false, true) returns 0 (the unit test asserts that), so it keeps a plain SRV handle and #725's coherence fix never reaches heap descriptors — which is what #725 says is required ("they first have to be known as UAVs").

One line in the filter (tested on top of the branch: 72 pass):

.filter(|d| {
    let inst = &p.blocks[d.site.0].insts[d.site.1];
    let name = inst.name();
    name.contains("store")
        || name.contains("atomic")
        || matches!(inst.fields, Fields::Buffer { cache, .. } | Fields::Image { cache, .. } if cache.glc)
})

Two smaller notes on the same branch:

  • the raw s_buffer_load path keeps Attr::ReadOnly on rawBufferLoad even when the handle is a UAV the program stores through — the scalar read may be hoisted over the write;
  • known table UAVs now take the raw path too (they used the constant-buffer path before); probably an improvement, but it is a behaviour change beyond the issue.

Not tested on a GPU. AI-assisted.

**@⁠RID-Games** on GitHub · 2026-11-24 09:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/724#issuecomment-7127838325) · edited 2026-11-24 10:21 UTC Verified [https://github.com/Hiiva/VIctory@hiiva/heap-uav-coherence](https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence) (`[fa119dd](https://github.com/Hiiva/VIctory/commit/fa119dd)` + `[5c26db0](https://github.com/Hiiva/VIctory/commit/5c26db0)`) on Linux (rustc 1.100): `cargo test -p victory-shader` — 72 passed, 1 ignored. The inference, the shared-handle regression test and the raw `s_buffer_load` path all look right. One gap: the pre-pass marks only `store`/`atomic` accesses, but the issue asks for "any store, atomic **or `glc`** access". A heap descriptor whose only write-adjacent access is a `glc` load — the spin-wait in #725's example — is never inferred as a UAV: `heap_uav` is false and `resource_flags(false, true)` returns 0 (the unit test asserts that), so it keeps a plain SRV handle and #725's coherence fix never reaches heap descriptors — which is what #725 says is required ("they first have to be known as UAVs"). One line in the [filter](https://github.com/Hiiva/VIctory/blob/5c26db0/crates/victory-shader/src/emit/lower.rs) (tested on top of the branch: 72 pass): ```rust .filter(|d| { let inst = &p.blocks[d.site.0].insts[d.site.1]; let name = inst.name(); name.contains("store") || name.contains("atomic") || matches!(inst.fields, Fields::Buffer { cache, .. } | Fields::Image { cache, .. } if cache.glc) }) ``` Two smaller notes on the same branch: - the raw `s_buffer_load` path keeps `Attr::ReadOnly` on `rawBufferLoad` even when the handle is a UAV the program stores through — the scalar read may be hoisted over the write; - known table UAVs now take the raw path too (they used the constant-buffer path before); probably an improvement, but it is a behaviour change beyond the issue. Not tested on a GPU. AI-assisted.
Author
Owner

@⁠dpalacios69 on GitHub · 2026-11-24 10:22 UTC · original

Prepared a standalone branch on ffe310e covering both #724 and #725 (including the glc-only heap load spin-wait case noted above): dpalacios69/VIctory@fix/shader-glc-globally-coherent.

  • Pre-lowering pass in Lower::new (crates/victory-shader/src/emit/lower.rs) infers resource-heap UAVs keyed by (param, byte_offset, dynamic) from store, atomic, or glc loads (excluding image_sample* and descriptor loads s_load_dword*), and routes s_buffer_load on UAVs to raw UAV handles instead of CBV.
  • ORs IsGloballyCoherent (0x4000) into UAV handle properties when cache.glc is set on buffer, image, and s_buffer_load accesses.
  • Tradeoff documented in code: inferring UAV from glc loads matches #724/#725 so glc-only heap spin-waits get 0x500B, with the caveat noted by @⁠Hiiva that a glc load on a read-only heap SRV would be annotated as a UAV.
  • Verified with synthetic tests on Linux only (cargo test -p victory-shader --locked: 101 passed, 0 failed, 1 ignored, including 5 new tests; clippy -D warnings clean on lower.rs; cargo xtask policy ok). DXIL validator (dxil.dll) and GPU execution were not run locally.

AI-assisted; no game data used.

**@⁠dpalacios69** on GitHub · 2026-11-24 10:22 UTC · [original](https://github.com/Marvisak/VIctory/issues/724#issuecomment-7128686874) Prepared a standalone branch on `ffe310e` covering both #724 and #725 (including the `glc`-only heap load spin-wait case noted above): `dpalacios69/VIctory@fix/shader-glc-globally-coherent`. - Pre-lowering pass in `Lower::new` (`crates/victory-shader/src/emit/lower.rs`) infers resource-heap UAVs keyed by `(param, byte_offset, dynamic)` from `store`, `atomic`, or `glc` loads (excluding `image_sample*` and descriptor loads `s_load_dword*`), and routes `s_buffer_load` on UAVs to raw UAV handles instead of CBV. - ORs `IsGloballyCoherent` (`0x4000`) into UAV handle properties when `cache.glc` is set on buffer, image, and `s_buffer_load` accesses. - Tradeoff documented in code: inferring UAV from `glc` loads matches #724/#725 so `glc`-only heap spin-waits get `0x500B`, with the caveat noted by @⁠Hiiva that a `glc` load on a read-only heap SRV would be annotated as a UAV. - Verified with synthetic tests on Linux only (`cargo test -p victory-shader --locked`: 101 passed, 0 failed, 1 ignored, including 5 new tests; `clippy -D warnings` clean on `lower.rs`; `cargo xtask policy` ok). **DXIL validator (`dxil.dll`) and GPU execution were not run locally.** AI-assisted; no game data used.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:48 UTC · original

Automated triage for the maintainers.

Confirmed on current main (line numbers have moved since the report). In crates/victory-shader/src/emit/lower.rs:

  • Lower::used_kind still returns None for a descriptor not loaded from a table (rp.root != RootType::Table), so a heap descriptor has no known kind.
  • Lower::buffer sets uav = store || atomic.is_some() || used is a UAV, and Lower::descriptor_data decides the same way from the instruction name. So one heap descriptor gets SRV props for its loads and UAV props (0x1000) for its stores.
  • The s_buffer_load_dword* lowering takes the raw view only for a known SRV or a root UAV. Anything else, including a heap UAV, goes through the constant-buffer path.

No per-descriptor inference across instructions exists yet. The fix is in an open pull request: #1271 (also #725) infers heap UAVs by descriptor address from stores, atomics and glc accesses. It's labelled as needing a rebase onto current main. The fork branches in the comments (Hiiva, dpalacios69) are alternatives. Hiiva's comment points out the tradeoff that inferring a UAV from a glc load alone can mislabel a real SRV. The maintainers should weigh that when reviewing #1271.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/724#issuecomment-7149982853) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T10:22:22Z at=2026-11-25T01:52:45Z --> Automated triage for the maintainers. Confirmed on current `main` (line numbers have moved since the report). In `crates/victory-shader/src/emit/lower.rs`: - `Lower::used_kind` still returns `None` for a descriptor not loaded from a table (`rp.root != RootType::Table`), so a heap descriptor has no known kind. - `Lower::buffer` sets `uav = store || atomic.is_some() || used is a UAV`, and `Lower::descriptor_data` decides the same way from the instruction name. So one heap descriptor gets SRV props for its loads and UAV props (`0x1000`) for its stores. - The `s_buffer_load_dword*` lowering takes the raw view only for a known SRV or a root UAV. Anything else, including a heap UAV, goes through the constant-buffer path. No per-descriptor inference across instructions exists yet. The fix is in an open pull request: #1271 (also #725) infers heap UAVs by descriptor address from stores, atomics and `glc` accesses. It's labelled as needing a rebase onto current `main`. The fork branches in the comments (Hiiva, dpalacios69) are alternatives. Hiiva's comment points out the tradeoff that inferring a UAV from a `glc` load alone can mislabel a real SRV. The maintainers should weigh that when reviewing #1271. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#724
No description provided.