Shaders: emit UAV barrier fence for global flat stores and atomics #2800

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/2802 into main
fuzeofficlal commented 2026-11-25 20:58:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:58:29Z.


What

Include Fields::Flat instructions whose name starts with global_ and contains store or atomic (global_store_*, global_atomic_*) in Lower::new's writes_uavs check (crates/victory-shader/src/emit/lower.rs:533-539), so s_barrier emits dx.op.barrier with UAV_FENCE (mode = 11 = 1 | 2 | 8) instead of TGSM-only (mode = 9 = 1 | 8).

Why

global_store_* and global_atomic_* decode as Fields::Flat and lower to rawBufferStore / atomicBinOp UAV writes via Lower::flat_write. Previously writes_uavs only checked Fields::Image and Fields::Buffer, so a compute shader that wrote UAVs exclusively through global_store_* or global_atomic_* and synchronized across waves with s_barrier emitted dx.op.barrier(80, 9) without a UAV memory fence.

Read-only global_load_* and non-global flat forms remain excluded (mode = 9).

Verification

  • cargo test --locked -p victory-shader --lib emit::lower::tests: 28 passed, 0 failed (including portable global_writes_add_a_uav_fence_to_barriers asserting mode = 11 for global_store_dword / global_atomic_add and mode = 9 for global_load_dword).
  • cargo test --locked -p victory-shader --lib --features host emit::memory_tests::global_store_values_are_visible_across_waves_after_a_barrier (Windows 11, RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll): passed (64-thread [64, 1, 1] cross-wave lane ^ 32 store -> s_barrier -> load -> store verified on both hardware and WARP); VICTORY_WARP=1 full emit::memory_tests::: 5/5 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings.
  • cargo xtask policy: 184 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6613625514 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2802). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T20:58:29Z. --- ## What Include `Fields::Flat` instructions whose name starts with `global_` and contains `store` or `atomic` (`global_store_*`, `global_atomic_*`) in `Lower::new`'s `writes_uavs` check (`crates/victory-shader/src/emit/lower.rs:533-539`), so `s_barrier` emits `dx.op.barrier` with `UAV_FENCE` (`mode = 11 = 1 | 2 | 8`) instead of TGSM-only (`mode = 9 = 1 | 8`). ## Why `global_store_*` and `global_atomic_*` decode as `Fields::Flat` and lower to `rawBufferStore` / `atomicBinOp` UAV writes via `Lower::flat_write`. Previously `writes_uavs` only checked `Fields::Image` and `Fields::Buffer`, so a compute shader that wrote UAVs exclusively through `global_store_*` or `global_atomic_*` and synchronized across waves with `s_barrier` emitted `dx.op.barrier(80, 9)` without a UAV memory fence. Read-only `global_load_*` and non-global flat forms remain excluded (`mode = 9`). ## Verification - `cargo test --locked -p victory-shader --lib emit::lower::tests`: **28 passed, 0 failed** (including portable `global_writes_add_a_uav_fence_to_barriers` asserting `mode = 11` for `global_store_dword` / `global_atomic_add` and `mode = 9` for `global_load_dword`). - `cargo test --locked -p victory-shader --lib --features host emit::memory_tests::global_store_values_are_visible_across_waves_after_a_barrier` (Windows 11, RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`): **passed** (64-thread `[64, 1, 1]` cross-wave `lane ^ 32` store -> `s_barrier` -> load -> store verified on both hardware and WARP); `VICTORY_WARP=1` full `emit::memory_tests::`: **5/5 passed**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**. - `cargo xtask policy`: **184 files ok**.
kotekompotek commented 2026-11-25 22:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:16:07Z.

Review: COMMENTED


Right gap to close: flat global_* stores/atomics write UAV-visible memory just like image/buffer UAV writes, so barriers after them need the UAV fence (mode bit 2 — 11 vs 9). The precedence in the new condition is correct (Image/Buffer OR (Flat AND global_)), and global_load staying at 9 proves loads are not over-classified. The written_calls change to expose args for the barrier-mode assertions is clean. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065093483 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2802#pullrequestreview-6065093483). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T21:16:07Z. **Review:** COMMENTED --- Right gap to close: flat `global_*` stores/atomics write UAV-visible memory just like image/buffer UAV writes, so barriers after them need the UAV fence (mode bit 2 — 11 vs 9). The precedence in the new condition is correct (Image/Buffer OR (Flat AND global_)), and `global_load` staying at 9 proves loads are not over-classified. The `written_calls` change to expose args for the barrier-mode assertions is clean. LGTM.
oni-swr commented 2026-11-25 22:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T21:23:59Z.


Independent WARP/CPU verification of head cdd03309c395c7d73e8cecf606ea603ad1b24479, merged onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca (clean merge).

Environment: Windows 11 Pro 26200, WARP only (VICTORY_WARP=1, which also routes the Host::new(false) hardware passes to WARP, plus VICTORY_D3D12_WARP=1), Windows SDK 10.0.26100.0 x64 dxil.dll 1.8.2502.11 (VICTORY_DXIL).

  • cargo test -j 4 -p victory-shader: 269 passed, 3 failed, 3 ignored. The baseline on origin/main was 267/3/3, so there are 2 new passing tests.
    • The 3 failures are the same pre-existing WARP failures as on the baseline: synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, permutes_read_the_lane_named_and_zero_from_lanes_left_out} (no pipeline for a wave of 32) and gathers_at_a_level_match_the_hardware.
  • global_store_values_are_visible_across_waves_after_a_barrier ran on WARP (not skipped) and passed.
  • Negative control: I took the new Fields::Flat + global_ arm out of writes_uavs.
    • global_writes_add_a_uav_fence_to_barriers then fails: global_store_dword, left: [Some(9)], right: [Some(11)].
    • The cross-wave WARP test still passes without the fence, which is expected since WARP doesn't need it to make the stores visible. So on WARP the regression is caught by the unit test only, and the device test is a functional check rather than a guard.
  • cargo clippy -p victory-shader --all-targets -- -D warnings was clean, with and without --all-features.
  • cargo fmt --all --check: 891 hunks, the same as the baseline (no new hunks).

Diff review: no blocking findings. The new arm matches how instructions are dispatched: non-global Fields::Flat is refused as "flat memory", so leaving it out of writes_uavs is consistent. The || and && grouping is right: (Image | Buffer | Flat && global_) && (store | atomic). The written_calls iterator refactor keeps heap_handles the same through .count(). The test encodings are synthetic, with no data files.

Not tested: physical GPU, retail title.

AI use: Claude Code (Claude Opus 5.5)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175024044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2802#issuecomment-7175024044). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T21:23:59Z. --- Independent WARP/CPU verification of head `cdd03309c395c7d73e8cecf606ea603ad1b24479`, merged onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca` (clean merge). Environment: Windows 11 Pro 26200, WARP only (`VICTORY_WARP=1`, which also routes the `Host::new(false)` hardware passes to WARP, plus `VICTORY_D3D12_WARP=1`), Windows SDK 10.0.26100.0 x64 `dxil.dll` 1.8.2502.11 (`VICTORY_DXIL`). - `cargo test -j 4 -p victory-shader`: 269 passed, 3 failed, 3 ignored. The baseline on `origin/main` was 267/3/3, so there are 2 new passing tests. - The 3 failures are the same pre-existing WARP failures as on the baseline: `synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, permutes_read_the_lane_named_and_zero_from_lanes_left_out}` (`no pipeline for a wave of 32`) and `gathers_at_a_level_match_the_hardware`. - `global_store_values_are_visible_across_waves_after_a_barrier` ran on WARP (not skipped) and passed. - Negative control: I took the new `Fields::Flat` + `global_` arm out of `writes_uavs`. - `global_writes_add_a_uav_fence_to_barriers` then fails: `global_store_dword`, `left: [Some(9)]`, `right: [Some(11)]`. - The cross-wave WARP test **still passes** without the fence, which is expected since WARP doesn't need it to make the stores visible. So on WARP the regression is caught by the unit test only, and the device test is a functional check rather than a guard. - `cargo clippy -p victory-shader --all-targets -- -D warnings` was clean, with and without `--all-features`. - `cargo fmt --all --check`: 891 hunks, the same as the baseline (no new hunks). Diff review: no blocking findings. The new arm matches how instructions are dispatched: non-global `Fields::Flat` is refused as `"flat memory"`, so leaving it out of `writes_uavs` is consistent. The `||` and `&&` grouping is right: `(Image | Buffer | Flat && global_) && (store | atomic)`. The `written_calls` iterator refactor keeps `heap_handles` the same through `.count()`. The test encodings are synthetic, with no data files. Not tested: physical GPU, retail title. AI use: Claude Code (Claude Opus 5.5)
Marvisak commented 2026-11-26 00:03:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:24:27Z.


Automated triage for the maintainers.

In Lower::new (crates/victory-shader/src/emit/lower.rs) writes_uavs now also counts Fields::Flat instructions named global_* that store or are atomic, so s_barrier gets the UAV fence (dx.op.barrier mode 1 | 2 | 8) in programs that write only through global_store_* / global_atomic_*, which do lower to UAV writes. I checked the operator grouping, that non-global flat forms are refused elsewhere so leaving them out is consistent, and that the Module::written_calls iterator change keeps heap_handles the same; the new unit test checks mode 11 for store and atomic and mode 9 for a load. CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177516825 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2802#issuecomment-7177516825). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:24:27Z. --- <!-- victory-triage v1 head=cdd03309c395c7d73e8cecf606ea603ad1b24479 verdict=merge-candidate at=2026-11-25T23:24:17Z --> Automated triage for the maintainers. In `Lower::new` (`crates/victory-shader/src/emit/lower.rs`) `writes_uavs` now also counts `Fields::Flat` instructions named `global_*` that store or are atomic, so `s_barrier` gets the UAV fence (`dx.op.barrier` mode `1 | 2 | 8`) in programs that write only through `global_store_*` / `global_atomic_*`, which do lower to UAV writes. I checked the operator grouping, that non-global flat forms are refused elsewhere so leaving them out is consistent, and that the `Module::written_calls` iterator change keeps `heap_handles` the same; the new unit test checks mode 11 for store and atomic and mode 9 for a load. CI (`check`) passes. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
DenRakEiw commented 2026-11-26 01:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:49:42Z.

Review: APPROVED


Verified against origin/main (63bcca4) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Emitting UAV barrier fences for global flat stores and atomics passes both lowering and live GPU readback tests cleanly.
  • cargo test -p victory-shader emit::lower::tests: 34/34 passed on RTX 5090 and WARP (including global_writes_add_a_uav_fence_to_barriers).
  • emit::memory_tests::global_store_values_are_visible_across_waves_after_a_barrier: passed on RTX 5090 and WARP (memory_tests 6/6 passed on WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067058494 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2802#pullrequestreview-6067058494). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:49:42Z. **Review:** APPROVED --- Verified against `origin/main` (`63bcca4`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Emitting UAV barrier fences for global flat stores and atomics passes both lowering and live GPU readback tests cleanly. - `cargo test -p victory-shader emit::lower::tests`: 34/34 passed on RTX 5090 and WARP (including `global_writes_add_a_uav_fence_to_barriers`). - `emit::memory_tests::global_store_values_are_visible_across_waves_after_a_barrier`: passed on RTX 5090 and WARP (`memory_tests` 6/6 passed on WARP). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2802:upstream-pr/2802'
git switch 'upstream-pr/2802'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2802'
git switch 'upstream-pr/2802'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2802'
git switch 'upstream-pr/2802'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2802'
git switch 'main'
git merge --squash 'upstream-pr/2802'
git switch 'main'
git merge --ff-only 'upstream-pr/2802'
git switch 'main'
git merge 'upstream-pr/2802'
git push origin 'main'
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!2800
No description provided.