Shaders: one heap descriptor gets an SRV handle for its loads and a UAV handle for its stores #724
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#724
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@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_kindreturnsNonefor any root parameter that isn't a table (crates/victory-shader/src/emit/lower.rs:3257-3259).uavis true only for stores and atomics: buffers at:6075, images at:5470-5475, descriptor data at:2943-2946.s_buffer_loadtakes 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 (
annotateHandlewithoutIsUAV, bit0x1000) and its stores a UAV handle. The annotation doesn't match the descriptor's type, which is undefined in D3D12.Example
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 inheap_handle.Suggested fix
Before lowering, mark every descriptor source that has any store, atomic or
glcaccess as a UAV, and give every access through it the UAV form. A UAVs_buffer_loadthen 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
glcloads not globally coherent) needs this inference to know which loads are UAV loads.github-bot referenced this issue2026-11-26 04:25:49 +00:00
@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 10:10 UTC · original
Checked the
readonlyconcern against Microsoft's compiler. SDK DXC 1.8.2502.11 compiled a syntheticgloballycoherent RWByteAddressBufferstore/load/store and polling loop at both-O3and-Od. It emitsrawBufferLoadwith{ 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:readonlydescribes 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.
@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 raws_buffer_loadpath all look right.One gap: the pre-pass marks only
store/atomicaccesses, but the issue asks for "any store, atomic orglcaccess". A heap descriptor whose only write-adjacent access is aglcload — the spin-wait in #725's example — is never inferred as a UAV:heap_uavis false andresource_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):
Two smaller notes on the same branch:
s_buffer_loadpath keepsAttr::ReadOnlyonrawBufferLoadeven when the handle is a UAV the program stores through — the scalar read may be hoisted over the write;Not tested on a GPU. AI-assisted.
@dpalacios69 on GitHub · 2026-11-24 10:22 UTC · original
Prepared a standalone branch on
ffe310ecovering both #724 and #725 (including theglc-only heap load spin-wait case noted above):dpalacios69/VIctory@fix/shader-glc-globally-coherent.Lower::new(crates/victory-shader/src/emit/lower.rs) infers resource-heap UAVs keyed by(param, byte_offset, dynamic)fromstore,atomic, orglcloads (excludingimage_sample*and descriptor loadss_load_dword*), and routess_buffer_loadon UAVs to raw UAV handles instead of CBV.IsGloballyCoherent(0x4000) into UAV handle properties whencache.glcis set on buffer, image, ands_buffer_loadaccesses.glcloads matches #724/#725 soglc-only heap spin-waits get0x500B, with the caveat noted by @Hiiva that aglcload on a read-only heap SRV would be annotated as a UAV.cargo test -p victory-shader --locked: 101 passed, 0 failed, 1 ignored, including 5 new tests;clippy -D warningsclean onlower.rs;cargo xtask policyok). DXIL validator (dxil.dll) and GPU execution were not run locally.AI-assisted; no game data used.
@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). Incrates/victory-shader/src/emit/lower.rs:Lower::used_kindstill returnsNonefor a descriptor not loaded from a table (rp.root != RootType::Table), so a heap descriptor has no known kind.Lower::buffersetsuav = store || atomic.is_some() || used is a UAV, andLower::descriptor_datadecides the same way from the instruction name. So one heap descriptor gets SRV props for its loads and UAV props (0x1000) for its stores.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
glcaccesses. It's labelled as needing a rebase onto currentmain. The fork branches in the comments (Hiiva, dpalacios69) are alternatives. Hiiva's comment points out the tradeoff that inferring a UAV from aglcload alone can mislabel a real SRV. The maintainers should weigh that when reviewing #1271.Generated by Claude Code