Shaders: glc loads aren't marked globally coherent, so cross-workgroup waits may never see the write #725

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

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

What's wrong

On RDNA2, glc on a buffer or image load means "skip the per-CU (L0) cache". It's how one workgroup sees another workgroup's writes: LLVM's GFX10 memory model (AMDGPUUsage) lowers an agent-scope atomic load to buffer/global/flat_load glc=1 dlc=1. Titles use it for cross-workgroup spin waits and look-back scans.

The lowering never marks a handle globally coherent (IsGloballyCoherent, props bit 0x4000, in DXC's DxilResourceProperties.h):

  • Buffer handles (crates/victory-shader/src/emit/lower.rs:6075-6076) and image handles (:5470-5475) only set IsUAV.
  • glc is looked at only to decide whether an atomic returns its old value (:5519, :5546, :6095).

So a glc load becomes an ordinary, group-coherent UAV load. The host compiler may keep it in a register or a non-coherent cache, or hoist it out of a loop.

Example

A spin wait such as the one in #452:

buffer_load_dword v1, v0, s[8:11], 0 idxen glc     E0306000 80020100   (repeated until v1 changes)
  • Console: sees the other group's write once it reaches L2.
  • Ours: may never see it. #452 measured loops like this running until its iteration cap.

I haven't shown that the missing flag is the cause of #452's hangs: it's one plausible cause.

Suggested fix

OR 0x4000 into a UAV handle's props when the access has glc (props are already part of the handle cache key). For that to reach heap descriptors, they first have to be known as UAVs (#724).

Not tested: a test asserting the props (as in #724) would show the missing flag. A behavioural test on WARP would depend on timing, so I haven't written one.

  • #452 caps spin loops but doesn't add coherence.
  • #190 writes root-UAV metadata with globally coherent set to false.
**@⁠Dufftwt** on GitHub · 2026-11-24 08:26 UTC · [original](https://github.com/Marvisak/VIctory/issues/725) ## What's wrong On RDNA2, `glc` on a buffer or image load means "skip the per-CU (L0) cache". It's how one workgroup sees another workgroup's writes: LLVM's GFX10 memory model (AMDGPUUsage) lowers an agent-scope atomic load to `buffer/global/flat_load glc=1 dlc=1`. Titles use it for cross-workgroup spin waits and look-back scans. The lowering never marks a handle globally coherent (`IsGloballyCoherent`, props bit `0x4000`, in DXC's `DxilResourceProperties.h`): - Buffer handles (`crates/victory-shader/src/emit/lower.rs:6075-6076`) and image handles (`:5470-5475`) only set `IsUAV`. - `glc` is looked at only to decide whether an atomic returns its old value (`:5519`, `:5546`, `:6095`). So a `glc` load becomes an ordinary, group-coherent UAV load. The host compiler may keep it in a register or a non-coherent cache, or hoist it out of a loop. ## Example A spin wait such as the one in #452: ``` buffer_load_dword v1, v0, s[8:11], 0 idxen glc E0306000 80020100 (repeated until v1 changes) ``` - Console: sees the other group's write once it reaches L2. - Ours: may never see it. #452 measured loops like this running until its iteration cap. I haven't shown that the missing flag **is** the cause of #452's hangs: it's one plausible cause. ## Suggested fix OR `0x4000` into a UAV handle's props when the access has `glc` (props are already part of the handle cache key). For that to reach heap descriptors, they first have to be known as UAVs (#724). **Not tested:** a test asserting the props (as in #724) would show the missing flag. A behavioural test on WARP would depend on timing, so I haven't written one. ## Related - #452 caps spin loops but doesn't add coherence. - #190 writes root-UAV metadata with globally coherent set to false.
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

Implemented DXIL IsGloballyCoherent (0x4000) on GLC UAV buffer and image accesses, including image atomics. Regression test checks the SRV/UAV property bits, and shader Clippy passes. The change is combined with heap UAV inference for #724 on https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence (fa119dd, 5c26db0). GPU behavioral improvement is not yet established. AI-assisted; no game assets.

**@⁠Hiiva** on GitHub · 2026-11-24 09:05 UTC · [original](https://github.com/Marvisak/VIctory/issues/725#issuecomment-7126945044) Implemented DXIL IsGloballyCoherent (0x4000) on GLC UAV buffer and image accesses, including image atomics. Regression test checks the SRV/UAV property bits, and shader Clippy passes. The change is combined with heap UAV inference for #724 on https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence (fa119dd, 5c26db0). GPU behavioral improvement is not yet established. AI-assisted; no game assets.
Author
Owner

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

Same note as on #724: the branch marks glc UAV accesses coherently, but a heap descriptor read only by glc loads (the spin-wait in this issue's example) is never inferred as a UAV — the pre-pass filter is store || atomic, and resource_flags(false, true) is 0 — so it still gets a plain SRV handle and no 0x4000. Marking glc accesses in the #724 pre-pass (as the issue prescribes: "store, atomic or glc") is what makes this fix reach heap descriptors. Verified the branch's tests on Linux: 72 passed. AI-assisted.

**@⁠RID-Games** on GitHub · 2026-11-24 09:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/725#issuecomment-7127842304) · edited 2026-11-24 10:22 UTC Same note as on #724: the [branch](https://github.com/Hiiva/VIctory/tree/hiiva/heap-uav-coherence) marks glc UAV accesses coherently, but a heap descriptor read only by `glc` loads (the spin-wait in this issue's example) is never inferred as a UAV — the pre-pass filter is `store || atomic`, and `resource_flags(false, true)` is 0 — so it still gets a plain SRV handle and no `0x4000`. Marking `glc` accesses in the #724 pre-pass (as the issue prescribes: "store, atomic or glc") is what makes this fix reach heap descriptors. Verified the branch's tests on Linux: 72 passed. 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/725#issuecomment-7128687380) 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

@⁠Wasler on GitHub · 2026-11-24 12:04 UTC · original

Confirmed empirically on RTX 5060 Ti (origin/main ffe310e + PR #568 + PR #334): ORing 0x4000 (IsGloballyCoherent) into image/buffer UAV handle props when glc is set cleared the 11-list compute loop hang (9ef9a9d818b27236 / 4fcf26015f70eecf) without VICTORY_SHADER_LOOP_LIMIT (full report in #732).

**@⁠Wasler** on GitHub · 2026-11-24 12:04 UTC · [original](https://github.com/Marvisak/VIctory/issues/725#issuecomment-7130938114) Confirmed empirically on RTX 5060 Ti (`origin/main` `ffe310e` + PR `#568` + PR `#334`): ORing `0x4000` (`IsGloballyCoherent`) into image/buffer UAV handle props when `glc` is set cleared the `11`-list compute loop hang (`9ef9a9d818b27236` / `4fcf26015f70eecf`) without `VICTORY_SHADER_LOOP_LIMIT` (full report in #732).
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 13:13 UTC · original

Some data on how often this shader shows up in hangs. 9ef9a9d818b27236, the program Wasler's run stopped looping in once glc was marked coherent, is also in the failing work in other reports:

  • #781 (RTX 3060, ffe310e): it's the dispatch in list 10 of 11 when the device is removed (0x887A0006).
  • #59, PastiiJay (RX 9070 XT, fa5ef73 with the debug layer): the fault is in list 10 of 11, whose compute dispatches are 82849f7a614208eb, 9afd549c4f530901, 2dc602192abf6288, 9ef9a9d818b27236, 4fcf26015f70eecf and ba4e20a2fd348338. #781 has ba4e20a2fd348338 in the same list.
  • #653: Dufftwt asked that reporter to grep for it.

AwkGrep256 still hangs on RX 9070 XT under vkd3d-proton with the fix (3 of 3, 13–17 s after this pipeline is created). So it doesn't look like the whole story on AMD, but it is the same shader on both vendors. There's no PR for this yet. dpalacios69's fix/shader-glc-globally-coherent also covers the glc-only heap load case RID-Games pointed out.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 13:13 UTC · [original](https://github.com/Marvisak/VIctory/issues/725#issuecomment-7132522874) Some data on how often this shader shows up in hangs. `9ef9a9d818b27236`, the program Wasler's run stopped looping in once `glc` was marked coherent, is also in the failing work in other reports: - #781 (RTX 3060, `ffe310e`): it's the dispatch in list 10 of 11 when the device is removed (0x887A0006). - #59, PastiiJay (RX 9070 XT, `fa5ef73` with the debug layer): the fault is in list 10 of 11, whose compute dispatches are `82849f7a614208eb`, `9afd549c4f530901`, `2dc602192abf6288`, `9ef9a9d818b27236`, `4fcf26015f70eecf` and `ba4e20a2fd348338`. #781 has `ba4e20a2fd348338` in the same list. - #653: Dufftwt asked that reporter to grep for it. AwkGrep256 still hangs on RX 9070 XT under vkd3d-proton with the fix (3 of 3, 13–17 s after this pipeline is created). So it doesn't look like the whole story on AMD, but it is the same shader on both vendors. There's no PR for this yet. dpalacios69's `fix/shader-glc-globally-coherent` also covers the glc-only heap load case RID-Games pointed out.
Author
Owner

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

Automated triage for the maintainers.

Confirmed on current main. In crates/victory-shader/src/emit/lower.rs, UAV handle props are built only from 0x1000 (IsUAV) in Lower::buffer, the image lowering and Lower::descriptor_data. Nothing in the file sets IsGloballyCoherent (0x4000), and glc doesn't change a handle's props. So a glc load is lowered as an ordinary UAV load. For heap descriptors, this also depends on #724, since their loads aren't known to be UAV loads at all.

Evidence that it matters in the title: in the comments, marking glc UAV handles coherent ended the compute loop hang in 9ef9a9d818b27236 on an RTX 5060 Ti, and that program appears in the failing list in other hang reports (#59, #781). It wasn't enough on an RX 9070 XT under vkd3d-proton, so it may be one cause among several there.

The fix is in an open pull request: #1271 (with #724) sets 0x1000 | 0x4000 on glc UAV accesses and infers heap UAVs first. It's labelled as needing a rebase onto current main. The fork branches in the comments (Hiiva, dpalacios69) are alternatives.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/725#issuecomment-7149987125) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T13:13:26Z at=2026-11-25T01:53:30Z --> Automated triage for the maintainers. Confirmed on current `main`. In `crates/victory-shader/src/emit/lower.rs`, UAV handle props are built only from `0x1000` (`IsUAV`) in `Lower::buffer`, the image lowering and `Lower::descriptor_data`. Nothing in the file sets `IsGloballyCoherent` (`0x4000`), and `glc` doesn't change a handle's props. So a `glc` load is lowered as an ordinary UAV load. For heap descriptors, this also depends on #724, since their loads aren't known to be UAV loads at all. Evidence that it matters in the title: in the comments, marking `glc` UAV handles coherent ended the compute loop hang in `9ef9a9d818b27236` on an RTX 5060 Ti, and that program appears in the failing list in other hang reports (#59, #781). It wasn't enough on an RX 9070 XT under vkd3d-proton, so it may be one cause among several there. The fix is in an open pull request: #1271 (with #724) sets `0x1000 | 0x4000` on `glc` UAV accesses and infers heap UAVs first. It's labelled as needing a rebase onto current `main`. The fork branches in the comments (Hiiva, dpalacios69) are alternatives. --- _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#725
No description provided.