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

Open
github-bot wants to merge 1 commit from github-bot/gh-2802 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:58 UTC · original
fuzeofficlal:fix/shader-global-store-barrier-uav-fence → main · +183 −10 · 3 files · 1 commits · open

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2802) `fuzeofficlal:fix/shader-global-store-barrier-uav-fence` → `main` · +183 −10 · 3 files · 1 commits · open ## 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**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:35 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 21:23 UTC · original

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)

**@⁠oni-swr** on GitHub · 2026-11-25 21:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2802#issuecomment-7175024044) 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)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:24 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2802#issuecomment-7177516825) <!-- 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)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2802/head:github-bot/gh-2802'
git switch 'github-bot/gh-2802'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2802'
git switch 'github-bot/gh-2802'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2802'
git switch 'github-bot/gh-2802'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2802'
git switch 'main'
git merge --squash 'github-bot/gh-2802'
git switch 'main'
git merge --ff-only 'github-bot/gh-2802'
git switch 'main'
git merge 'github-bot/gh-2802'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2802
No description provided.