Skip to content

Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent - #1271

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-uav-globally-coherent-725
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-uav-globally-coherent-725

Conversation

@fuzeofficlal

@fuzeofficlal fuzeofficlal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #724.
Part of #725.

Summary

  • Written heap-descriptor UAV propagation (#724): Pre-scan Role::Resource descriptor leaves by tracked (param, offset + 4 * first, dynamic) address (written_uavs) so any heap descriptor accessed with a store or atomic operation lowers consistently as a UAV across vector loads, scalar s_buffer_load_dword*, descriptor_data, and separate reloads of the same heap address. Read-only heap descriptors (including glc-only reads without stores or atomics) remain SRVs.
  • IsGloballyCoherent (0x4000) on glc UAV handles (#725): Set 0x1000 | 0x4000 in dx.types.ResourceProperties word 0 whenever uav && cache.glc across buffer (raw, structured, typed), image (image_load, image_store, image_atomic_*), and smem (s_buffer_load_dword*).

Verification

  • emit::lower::tests::heap_uav_inference_and_glc_coherence_set_handle_properties and glc_only_heap_reads_stay_srv_and_table_uavs_are_globally_coherent (dxil.dll validated): verify written-UAV reload propagation, 0x500B / 0x500C / 0x500A / 0x5002 IsGloballyCoherent handle properties, and that read-only glc heap descriptors stay SRVs (0x000B / 0x0002).
  • emit::valu_tests::glc_heap_uav_loads_stores_and_atomics_execute_on_gpu: multi-group ([2, 1, 1]) synthetic compute readback on NVIDIA GeForce RTX 5090 and D3D12 WARP.
  • cargo clippy -p victory-shader --tests --locked -- -D warnings and cargo xtask policy: passed.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heap UAV inference: descriptors written/atomically-modified or accessed with glc (and never sampled) get UAV_PROP, glc ones also GLOBALLY_COHERENT_PROP; sampled descriptors are excluded, image glc counts for stores and image_load only. Same family as #1055/#1015 (descriptor-kind inference) — the three touch neighboring hunks in lower.rs, so merge order will need rebases. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed (2 lowering tests on macOS; the glc load/store/atomic execution test is Windows-gated).

@pablogonz12

Copy link
Copy Markdown
Contributor

Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 (main's host build fails without it: E0425 host_resource), then the four-stage offline check over 768 programs (751-program world dump + 52-program BVH capture, 35 duplicate containers skipped).

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost and the failure table is identical to the base, reason for reason: nothing in this capture reaches the class you handle, so this is a no-regression result only (same 10 SPIR-V validation failures as the base).

Not tested: in-game.

@wildheathen

Copy link
Copy Markdown

#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

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. Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent #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. Shaders: infer heap UAVs program-wide and emit IsGloballyCoherent on glc UAVs #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 Shaders: infer heap UAVs program-wide and emit IsGloballyCoherent on glc UAVs #1354 and not in Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent #1271.
  2. Barrier fence. Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent #1271 also counts inferred UAVs (written or glc) when deciding whether a compute s_barrier gets the global UAV fence. Shaders: infer heap UAVs program-wide and emit IsGloballyCoherent on glc UAVs #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 Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent #1271 only.
  3. Size. Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent #1271 is +558/−31 with a GPU execution test. Shaders: infer heap UAVs program-wide and emit IsGloballyCoherent on glc UAVs #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).

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
Code tree of fxceless/victory-fork 4e17478 (all rendering work by its author and
the VIctory contributors) with, on top:
- AMD fixes: skip of 39f0e9aeb156a61c, 32-lane programs per half wave and NaN/Inf
  filter, configurable texture upload queue, VIctory Marvisak#1599
- upstream VIctory Marvisak#334 (buffer-state tracking) and Marvisak#1271 (globally coherent glc UAVs)
- fork PRs Marvisak#95, Marvisak#71, Marvisak#32, Marvisak#86; VIctory Marvisak#1696, Marvisak#1338, Marvisak#1291, Marvisak#1732
- DirectStorage page lists read at the title's submit (analysis by JappertjeV, klbf-lab#3)
- offline pipeline pre-build that saves as it goes and skips driver-crashing pipelines
- Series S plane composition, VICTORY_FFX_SIMPLE, scripted keys in release builds
- docs/klbf/skip-amd.txt: AMD skip list used for our runs

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. The written-UAV propagation (written_uavs / Lower::is_uav) and IsGloballyCoherent on glc UAV handles (uav_bits) in crates/victory-shader/src/emit/lower.rs are unchanged from the head judged sound before. The second-look point is fixed: Shader::heap_handle (emit/shader.rs) now records texture_index for texture kinds 1-9 whether or not IsUAV is set, and Lower::image sets read marks only for instructions that are not image_store* / image_atomic_*. As a result, a heap-direct image_load of a written descriptor keeps its read mark, and a texture that is only stored gets none. heap_direct_image_load_and_store_keeps_view_read_marks in the new emit/lower/glc_tests.rs covers both cases.

On your reply: confirmed. The branch merges cleanly with current main, and with this PR merged emit/lower.rs is 523,001 bytes, under the 524,288-byte limit in xtask/src/policy.rs. The margin is only about 1.3 KB. #1540 and #1315 also grow this file, so whichever of them lands second will need lower.rs split first. That is a note for ordering, not a blocker for this PR. A blank line was left before the closing } of mod tests. It is cosmetic.

CI: passing (check).


Generated by Claude Code

triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
Pre-scan resource descriptors by tracked heap address so any heap descriptor accessed with a store, atomic, or non-sampled glc load lowers consistently as a UAV across vector loads, scalar s_buffer_load_dword, and descriptor_data queries (fxceless#724). OR IsGloballyCoherent (0x4000) into UAV handle properties when cache.glc is set on buffer, image, or scalar buffer accesses, and fence UAVs on compute barriers when glc UAV accesses are present (fxceless#725).

(cherry picked from commit 25d9e2add72c6f92bd83381eb4224da344486b98)

Ported from Marvisak/VIctory#1271. Conflicts with the fork's buffers picked
by index: a scalar load through a descriptor inferred as an unordered
access view takes the view's raw read, not the guarded pair of buffer and
constant buffer reads; two tests' handle lists follow the fork's raw reads
of structured buffers and its picked loads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBDcuSkQXqyyY47pR31
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-uav-globally-coherent-725 branch from 25d9e2a to 1ef830d Compare November 25, 2026 04:05
triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
The port of Marvisak/VIctory#1271 (edbfae6) put the globally coherent bit
into the handle properties of every glc access through an unordered view.
A root view has one handle for all its accesses, and the match that picks
it knew only the properties without that bit: a glc store through a root
UAV fell to "a typed root view is not supported" and the program did not
translate. Four programs of the ray-tracing structure builder do that
(93be497edd442293, 5552dac6a2b7a1fd, 5279ae36796c31fc, ffd93c8a029ff016);
its stages run all or none, so with VICTORY_BVH_BUILDER=1 the builder
stayed off (run main-9e6137f-builder: missing=4 of=53; all 53 had host
pipelines on Nov 24).

The bit is left out when a root view's handle is picked, as before the
port.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBDcuSkQXqyyY47pR31
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-uav-globally-coherent-725 branch from 1ef830d to 1db404e Compare November 25, 2026 09:49
@fuzeofficlal fuzeofficlal changed the title Shaders: infer heap UAVs and mark glc UAV handles globally coherent Shaders: propagate written heap UAVs and mark glc UAV handles globally coherent Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Updated in 1db404e0 per triage feedback:

  • Removed the unconfirmed glc_uavs rule so untyped heap descriptors that are only read with glc (never stored to or used atomically) stay SRVs instead of risking an SRV/UAV descriptor mismatch at runtime (deferred to a separate follow-up once runtime view evidence is available; updated PR link from Fixes #725 to Part of #725).
  • Kept the two confirmed parts intact: written_uavs propagation across reloads of heap descriptors with stores/atomics (#724) and IsGloballyCoherent (0x4000) on UAV handles accessed with glc.
  • Inverted the glc-only heap test (glc_only_heap_reads_stay_srv_and_table_uavs_are_globally_coherent) to assert that read-only buffer_load_dword glc, s_buffer_load_dword glc, and image_load glc heap handles remain SRVs.

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
… reads with glc are UAVs program-wide, and glc UAV accesses are globally coherent (upstream VIctory Marvisak#1271 by fuzeofficlal, for Marvisak#724 and Marvisak#725, onto this tree): descriptor addresses are scanned once per program, a handle on one of them is a UAV (0x1000) wherever it is loaded again, and a buffer, image or scalar buffer access with glc on a UAV sets IsGloballyCoherent (0x4000), so a load in another workgroup sees what one wrote (RDNA keeps glc loads in its per-workgroup caches otherwise); a compute program that writes or spin-waits on inferred UAVs gets the global UAV fence at s_barrier. A heap-picked scalar load of a UAV reads through the UAV handle instead of the buffer-view-or-constant-buffer pick. Marvisak#1271 over Marvisak#1354: the same output on a retail dump, and it also covers the barrier fence and keeps sampled descriptors as SRVs
@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-uav-globally-coherent-725 branch from 1db404e to 0f84157 Compare November 25, 2026 21:55
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against main, with the PR built and tested).

This is right (written heap UAVs are propagated, and glc handles are marked globally coherent). The review was of 1db404e; at the current head the test expectation is already the one main needs. One change is still needed before it can be merged: heap-direct texture loads that now get a UAV handle lose the read mark main gives them (in a probe, view_marks was true on main and false with this PR). In Shader::heap_handle (emit/shader.rs), note texture_index for texture kinds 1-9 whatever the IsUAV bit, or push the mark for UAV texture handles in Lower::image's load path, and add a test that a heap-direct image_load plus image_store of one descriptor still sets view_marks.

Two more things to know. It conflicts with main again in emit/valu_tests.rs after today's merges. And emit/lower.rs is now within a few kilobytes of the repository's 512 KiB file limit (cargo xtask policy), while this PR adds about 12 KB to it, so it can only land once that file has been split.

Push the change and it will be reviewed again. Thank you for the contribution.

@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-uav-globally-coherent-725 branch from 0f84157 to db3ebea Compare November 25, 2026 22:10
…y coherent

Pre-scan resource descriptors by tracked heap address so any heap descriptor accessed with a store or atomic lowers consistently as a UAV across vector loads, scalar s_buffer_load_dword, and descriptor_data queries, including across reloads (Marvisak#724). OR IsGloballyCoherent (0x4000) into UAV handle properties when cache.glc is set on buffer, image, or scalar buffer accesses, while keeping read-only glc heap descriptors as SRVs (Marvisak#725).
@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto main (f3578e3) in 0dc4320 per second-look feedback:

  • Shader::heap_handle (emit/shader.rs) now records texture_index for all texture kinds 1..=9 regardless of IsUAV, and Lower::image (emit/lower.rs) emits read marks for non-store/non-atomic texture operations so heap-direct image_load on a descriptor that is also stored keeps view_marks = true while store-only texture UAVs keep view_marks = false.
  • Added heap_direct_image_load_and_store_keeps_view_read_marks in emit/lower/glc_tests.rs covering both the load+store (view_marks == true) and store-only (view_marks == false) heap-direct 2D cases with DXIL validation.
  • Split the unit tests into crates/victory-shader/src/emit/lower/glc_tests.rs so emit/lower.rs stays under the 512 KiB policy cap (523,001 bytes; cargo xtask policy: 191 files ok).
  • Re-verified emit::lower::glc_tests (3/3), --features host glc (4/4 on RTX 5090 + WARP), and cargo clippy -p victory-shader --all-targets -- -D warnings (0 warnings).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I independently verified 0dc4320 combined with current upstream 63bcca4. For the baseline I added the same three test bodies and the test-only heap-property recorder to main.

  • Baseline: 0/3. The coherent UAV property was absent, and the mixed image load/store produced separate SRV and UAV handles.
  • Integrated head: 3/3. Read-only descriptors use SRVs, the written UAV handles carry the requested coherence bit, and the review's mixed image load/store keeps view_marks. A store-only texture stays free of read marks.
  • WARP 1.0.22 with Agility 1.620.2: the two-group load/store/atomic readback passed. All 36 VALU tests and 33 lowerer tests passed, along with strict shader Clippy and policy.

The tests used synthetic shaders and verified the read-mark case on the current tree.

AI-assisted with Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

6 participants