Shaders: coalesce title-memory dirty marks within a wave #2755

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

@⁠brainbudt on GitHub · 2026-11-25 19:45 UTC · original
brainbudt:perf/shader-wave-dedupe-marks → main · +194 −20 · 2 files · 1 commits · open

Lanes writing the same title-memory page repeatedly issue atomicOr against the same dirty-bitmap word in system RAM, serializing GPU dispatches (reported in #2695).

What changed

  • Inside the existing access guard, check WaveActiveAllEqual on the bitmap word index. When active lanes share a word, combine their masks with WaveActiveBitOr and elect one writer with WaveIsFirstLane; when words differ, each lane keeps its own address and mask.
  • Pre-check the bitmap word before issuing atomicBinOp and skip the atomic when all requested bits are already set.
  • Skip the last-page mark when the first page already covers the write.
  • Set WAVE_OPS (SFI0 0x4000); stays on SM 6.6 with no fixed wave size, and excludes pixel helper lanes.
  • Kept separate from the non-Windows test guards in #2670 (overlaps only with the non-wave pre-check in #2167).

Verification

  • Windows WARP (32-thread, two-store fixture): bitmap atomics dropped from 128 → 1 (repeated page), 128 → 9 (32 pages sharing a bitmap word), and 128 → 32 (32 distinct words), with matching bitmap and title-data readbacks.
  • Microsoft DXIL Validator: accepted synthetic compute, pixel, vertex, and mesh shaders containing the new marks.
  • Cross-platform: Windows x86_64-pc-windows-msvc cargo check --tests passed; macOS ARM64 & Linux x86-64 release test suites (159 passed) and Clippy -D warnings passed (tested with the #2670 validator guards).

Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).

**@⁠brainbudt** on GitHub · 2026-11-25 19:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755) `brainbudt:perf/shader-wave-dedupe-marks` → `main` · +194 −20 · 2 files · 1 commits · open Lanes writing the same title-memory page repeatedly issue `atomicOr` against the same dirty-bitmap word in system RAM, serializing GPU dispatches (reported in #2695). ### What changed - Inside the existing access guard, check `WaveActiveAllEqual` on the bitmap word index. When active lanes share a word, combine their masks with `WaveActiveBitOr` and elect one writer with `WaveIsFirstLane`; when words differ, each lane keeps its own address and mask. - Pre-check the bitmap word before issuing `atomicBinOp` and skip the atomic when all requested bits are already set. - Skip the last-page mark when the first page already covers the write. - Set `WAVE_OPS` (`SFI0 0x4000`); stays on SM 6.6 with no fixed wave size, and excludes pixel helper lanes. - Kept separate from the non-Windows test guards in #2670 (overlaps only with the non-wave pre-check in #2167). ### Verification - **Windows WARP (32-thread, two-store fixture):** bitmap atomics dropped from **128 → 1** (repeated page), **128 → 9** (32 pages sharing a bitmap word), and **128 → 32** (32 distinct words), with matching bitmap and title-data readbacks. - **Microsoft DXIL Validator:** accepted synthetic compute, pixel, vertex, and mesh shaders containing the new marks. - **Cross-platform:** Windows `x86_64-pc-windows-msvc` `cargo check --tests` passed; macOS ARM64 & Linux x86-64 release test suites (159 passed) and Clippy `-D warnings` passed (tested with the #2670 validator guards). Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:26 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:04 UTC · original

Reviewed and verified 26a05508 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll / dxc.exe) against main (13f91ca).

Code review

  • EXEC / guard safety: Lower::memory builds marks (write/active/e.miss) and narrows control flow with begin_guarded(marks) before entering mark_memory_page, so only lanes that actually need to mark participate in waveActiveAllEqual, waveActiveBit(Or), and waveIsFirstLane. When all participating lanes target the same bitmap dword (same), one elected lane (waveIsFirstLane) issues the pre-check + combined atomicBinOp(OR); when divergent, select falls back cleanly to per-lane bit masks and writers with no under-marking.
  • Cross-page writes: the nested begin_guarded(Some(different)) cleanly isolates only lanes whose write crosses into a second page and coalesces those as well, skipping the second wave op entirely for single-page writes and misses.
  • Pre-check monotonicity & stages: since the dirty bitmap only transitions 0 -> 1 on GPU during a submission (cleared on CPU beforehand), a stale L1 rawBufferLoad reading 0 only causes a benign redundant atomicOr, whereas reading 1 guarantees the bit is already set in device memory—no under-marking is possible. All wave intrinsics precede the per-writer branch, WAVE_OPS (SFI0 0x4000) is set without pinning WaveSize (compatible with both 32-lane and 64-lane hosts), and pixel helper lanes are excluded by SM 6.6 wave ops and discard UAV atomics.
  • (Note on merge compatibility): clean git merge-tree against 13f91ca, #2668, #2724, and #2761; touches the same write && bytes > 1 tail-page section of Lower::memory as #2484 (which switches the tail-page lookup to a 64-bit second page-table lookup across 256 MiB / 4 GiB boundaries—easy to reconcile in either merge order).

Verification (Windows 11, RTX 5090 + WARP + dxil.dll)

  • cargo test --locked -p victory-shader --lib --features host emit::tests: 19 passed, 0 failed (including both new tests verifying SFI0 0x4000, dxc -dumpbin IR, and WARP execution across shift = 2/16/21).
  • emit::memory_tests: WARP (VICTORY_WARP=1) 4/4 passed; RTX 5090 3/3 passed (skipping only the pre-existing 13f91ca 0xc0000005 baseline in heap_direct_texture_reads_mark_their_heap_index).
  • Full victory-shader --features host (excluding slow valu_tests & that baseline test): 264 passed, 3 failed (all 3 are pre-existing RTX 5090 13f91ca baselines, 0 regressions).
  • 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:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755#issuecomment-7173142724) Reviewed and verified `26a05508` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll` / `dxc.exe`) against `main` (`13f91ca`). ### Code review - **EXEC / guard safety**: `Lower::memory` builds `marks` (`write`/`active`/`e.miss`) and narrows control flow with `begin_guarded(marks)` *before* entering `mark_memory_page`, so only lanes that actually need to mark participate in `waveActiveAllEqual`, `waveActiveBit(Or)`, and `waveIsFirstLane`. When all participating lanes target the same bitmap dword (`same`), one elected lane (`waveIsFirstLane`) issues the pre-check + combined `atomicBinOp(OR)`; when divergent, `select` falls back cleanly to per-lane bit masks and writers with no under-marking. - **Cross-page writes**: the nested `begin_guarded(Some(different))` cleanly isolates only lanes whose write crosses into a second page and coalesces those as well, skipping the second wave op entirely for single-page writes and misses. - **Pre-check monotonicity & stages**: since the dirty bitmap only transitions `0 -> 1` on GPU during a submission (cleared on CPU beforehand), a stale L1 `rawBufferLoad` reading `0` only causes a benign redundant `atomicOr`, whereas reading `1` guarantees the bit is already set in device memory—no under-marking is possible. All wave intrinsics precede the per-writer branch, `WAVE_OPS` (`SFI0 0x4000`) is set without pinning `WaveSize` (compatible with both 32-lane and 64-lane hosts), and pixel helper lanes are excluded by SM 6.6 wave ops and discard UAV atomics. - *(Note on merge compatibility)*: clean `git merge-tree` against `13f91ca`, `#2668`, `#2724`, and `#2761`; touches the same `write && bytes > 1` tail-page section of `Lower::memory` as `#2484` (which switches the tail-page lookup to a 64-bit second page-table lookup across 256 MiB / 4 GiB boundaries—easy to reconcile in either merge order). ### Verification (Windows 11, RTX 5090 + WARP + `dxil.dll`) - `cargo test --locked -p victory-shader --lib --features host emit::tests`: **19 passed, 0 failed** (including both new tests verifying `SFI0 0x4000`, `dxc -dumpbin` IR, and WARP execution across `shift = 2/16/21`). - `emit::memory_tests`: **WARP** (`VICTORY_WARP=1`) **4/4 passed**; **RTX 5090** **3/3 passed** (skipping only the pre-existing `13f91ca` `0xc0000005` baseline in `heap_direct_texture_reads_mark_their_heap_index`). - Full `victory-shader --features host` (excluding slow `valu_tests` & that baseline test): **264 passed, 3 failed** (all 3 are pre-existing RTX 5090 `13f91ca` baselines, 0 regressions). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **184 files ok**.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:04 UTC · original

Verified the wave logic: WaveActiveAllEqual is a wave-uniform reduction so can't diverge inside the guard; when false every lane falls back to its own atomic (identical to today). The stale-load fast path can only produce an extra OR (idempotent), never a lost mark - the comment says exactly this. Nesting the crossing guard (first != last) inside the marks guard is per-lane correct for per-lane spans. One trade worth noting: the same=false case now pays a rawBufferLoad + atomic where it paid only the atomic - wins big on uniform writes, mildly worse on fully divergent ones. DXIL ops 110/115/120 and the WAVE_OPS flag look right.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755#issuecomment-7173151928) Verified the wave logic: WaveActiveAllEqual is a wave-uniform reduction so can't diverge inside the guard; when false every lane falls back to its own atomic (identical to today). The stale-load fast path can only produce an extra OR (idempotent), never a lost mark - the comment says exactly this. Nesting the crossing guard (first != last) inside the marks guard is per-lane correct for per-lane spans. One trade worth noting: the same=false case now pays a rawBufferLoad + atomic where it paid only the atomic - wins big on uniform writes, mildly worse on fully divergent ones. DXIL ops 110/115/120 and the WAVE_OPS flag look right.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:16 UTC · original

Independent WARP verification: PR head 26a0550

Environment: Windows 11, rustc/cargo 1.98.1, debug build, VICTORY_WARP=1 VICTORY_D3D12_WARP=1 (Microsoft WARP only, no physical GPU), Windows SDK 10.0.26100.0 dxil.dll 1.8.2502.11 on PATH. Tested the PR head itself (single commit directly on origin/main 13f91caee2, so identical to the merge tree). All commands cargo ... --locked.

Baseline on origin/main: test -p victory-shader --lib --features host (and host,diagnostics, and with default features): 267 passed, 3 failed, 3 ignored. The 3 pre-existing failures are WARP-only: emit::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} (hardware: no pipeline for a wave of 32) and gathers_at_a_level_match_the_hardware (lane mismatch). clippy --all-targets --features host,diagnostics -D warnings: clean.

On this PR:

  • test -p victory-shader --lib --features host: 269 passed, 3 failed, 3 ignored. --features host,diagnostics: the same. Default features: the same. The 3 failures are exactly the baseline ones. +2 new tests, both passing.
  • clippy --locked -p victory-shader --all-targets --features host,diagnostics -- -D warnings: clean, and also clean with default features.
  • dxc.exe (SDK 10.0.26100.0) was present, so the dump_dxil IR-order assertions of title_page_marks_use_wave_ops_and_guard_the_atomic actually ran.
  • Negative control: restored emit/lower.rs from origin/main: title_page_marks_use_wave_ops_and_guard_the_atomic fails (the WAVE_OPS flag assert, mod.rs:1673), then restored the PR file. title_page_marks_keep_every_lanes_bit (a runtime result check) also passes on origin/main: it guards against a regression in the dirty bits rather than detecting the old code.

Review: one lane per shared bitmap word ORs the whole wave's bits, and otherwise each lane keeps its own word and bit; the atomic runs only when the bits are not already set. I traced it: waveActiveAllEqual on the word index, waveActiveBit OR (kind 1) over the active lanes, waveIsFirstLane, then a stale-read-safe test before the OR. The second page of a write is marked only when it differs (via a nested guard). I found no correctness issues. The wave ops now run in the access guard, so correctness depends on the active-lane semantics of waveActive* inside branches. The runtime test covers shifts 2, 16 and 21 with 32 lanes, wave size 32 only (WARP), and not a wave of 64. Housekeeping: dump_dxil now panics on dxc spawn or write failures instead of returning None, and the cfg(windows) moves make default non-Windows builds of the tests compile.

Not tested: a physical GPU, any retail title or game behavior, a release build, non-Windows targets, wave64 execution.

AI disclosure: this verification was run by Claude Code (Claude Sonnet 5.5). No game files, dumps, shader names or retail hashes were used.

**@⁠oni-swr** on GitHub · 2026-11-25 20:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755#issuecomment-7173423087) ## Independent WARP verification: PR head `26a0550` **Environment:** Windows 11, rustc/cargo 1.98.1, debug build, `VICTORY_WARP=1 VICTORY_D3D12_WARP=1` (Microsoft WARP only, no physical GPU), Windows SDK 10.0.26100.0 `dxil.dll` 1.8.2502.11 on `PATH`. Tested the PR head itself (single commit directly on `origin/main` 13f91caee25f2fdf2c062be5f7a27f058e51cbca, so identical to the merge tree). All commands `cargo ... --locked`. **Baseline on origin/main:** `test -p victory-shader --lib --features host` (and `host,diagnostics`, and with default features): 267 passed, 3 failed, 3 ignored. The 3 pre-existing failures are WARP-only: `emit::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}` (`hardware: no pipeline for a wave of 32`) and `gathers_at_a_level_match_the_hardware` (lane mismatch). clippy `--all-targets --features host,diagnostics -D warnings`: clean. **On this PR:** - `test -p victory-shader --lib --features host`: 269 passed, 3 failed, 3 ignored. `--features host,diagnostics`: the same. Default features: the same. The 3 failures are exactly the baseline ones. +2 new tests, both passing. - `clippy --locked -p victory-shader --all-targets --features host,diagnostics -- -D warnings`: clean, and also clean with default features. - `dxc.exe` (SDK 10.0.26100.0) was present, so the `dump_dxil` IR-order assertions of `title_page_marks_use_wave_ops_and_guard_the_atomic` actually ran. - **Negative control:** restored `emit/lower.rs` from origin/main: `title_page_marks_use_wave_ops_and_guard_the_atomic` fails (the WAVE_OPS flag assert, `mod.rs:1673`), then restored the PR file. `title_page_marks_keep_every_lanes_bit` (a runtime result check) also passes on origin/main: it guards against a regression in the dirty bits rather than detecting the old code. **Review:** one lane per shared bitmap word ORs the whole wave's bits, and otherwise each lane keeps its own word and bit; the atomic runs only when the bits are not already set. I traced it: `waveActiveAllEqual` on the word index, `waveActiveBit` OR (kind 1) over the active lanes, `waveIsFirstLane`, then a stale-read-safe test before the OR. The second page of a write is marked only when it differs (via a nested guard). I found no correctness issues. The wave ops now run in the access guard, so correctness depends on the active-lane semantics of `waveActive*` inside branches. The runtime test covers shifts 2, 16 and 21 with 32 lanes, wave size 32 only (WARP), and not a wave of 64. Housekeeping: `dump_dxil` now panics on dxc spawn or write failures instead of returning `None`, and the `cfg(windows)` moves make default non-Windows builds of the tests compile. **Not tested:** a physical GPU, any retail title or game behavior, a release build, non-Windows targets, wave64 execution. AI disclosure: this verification was run by Claude Code (Claude Sonnet 5.5). No game files, dumps, shader names or retail hashes were used.
Author
Owner

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

Automated triage for the maintainers. Lower::mark_memory_bit in crates/victory-shader/src/emit/lower.rs now combines title-memory dirty marks within a wave. When all active lanes target the same bitmap dword, one elected lane ORs the wave's bits (waveActiveAllEqual, waveActiveBit OR, waveIsFirstLane). Otherwise each lane keeps its own bit. In both cases the atomic is skipped when a plain load already shows every bit set. Both callers in Lower::memory run it inside the access guard, and because bits only go from 0 to 1 during a submission, a stale load can cause at most an extra OR, never a lost mark. Notes for the maintainer: it was tested on wave32 WARP only, not with wave64 or pixel shaders with helper lanes on hardware. Fully divergent writes now pay an extra load. The cfg(all(test, windows)) and test-import changes in emit/mod.rs are unrelated cleanups. CI: check passing. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755#issuecomment-7177564544) <!-- victory-triage v1 head=347a399f5ee2e7ca7ad0a68a63476af8382c7834 verdict=merge-candidate at=2026-11-25T23:26:22Z --> Automated triage for the maintainers. `Lower::mark_memory_bit` in `crates/victory-shader/src/emit/lower.rs` now combines title-memory dirty marks within a wave. When all active lanes target the same bitmap dword, one elected lane ORs the wave's bits (`waveActiveAllEqual`, `waveActiveBit` OR, `waveIsFirstLane`). Otherwise each lane keeps its own bit. In both cases the atomic is skipped when a plain load already shows every bit set. Both callers in `Lower::memory` run it inside the access guard, and because bits only go from 0 to 1 during a submission, a stale load can cause at most an extra OR, never a lost mark. Notes for the maintainer: it was tested on wave32 WARP only, not with wave64 or pixel shaders with helper lanes on hardware. Fully divergent writes now pay an extra load. The `cfg(all(test, windows))` and test-import changes in `emit/mod.rs` are unrelated cleanups. CI: `check` passing. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Anzymanz on GitHub · 2026-11-26 00:17 UTC · original

From a tester working with Claude (AI-assisted, Claude Code): an in-title measurement on AMD/Linux (RX 9070 XT, RADV via vkd3d-proton), this PR with #2484 on 13f91ca + #1997 + #454 + #2644 against the same base, 30 s of the opening cutscene each, VICTORY_GPU_TIMING=1. Of the two costliest kernels in our world frames, both XboxBvhBuilder.dll compute programs that write title memory: 28918b7150a7aad5 goes from 0.77 to 0.57 ms per dispatch, caa78b8ca62bc3d6 stays at 0.36-0.37 ms. No new fault in the run. The full comparison (with #2175 and a control arm) is on #2804: #2804

**@⁠Anzymanz** on GitHub · 2026-11-26 00:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2755#issuecomment-7178598350) From a tester working with Claude (AI-assisted, Claude Code): an in-title measurement on AMD/Linux (RX 9070 XT, RADV via vkd3d-proton), this PR with #2484 on `13f91ca` + #1997 + #454 + #2644 against the same base, 30 s of the opening cutscene each, `VICTORY_GPU_TIMING=1`. Of the two costliest kernels in our world frames, both `XboxBvhBuilder.dll` compute programs that write title memory: `28918b7150a7aad5` goes from 0.77 to 0.57 ms per dispatch, `caa78b8ca62bc3d6` stays at 0.36-0.37 ms. No new fault in the run. The full comparison (with #2175 and a control arm) is on #2804: https://git.gtahub.st/github/Marvisak--VIctory/pulls/2804
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/2755/head:github-bot/gh-2755'
git switch 'github-bot/gh-2755'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2755'
git switch 'github-bot/gh-2755'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2755'
git switch 'github-bot/gh-2755'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2755'
git switch 'main'
git merge --squash 'github-bot/gh-2755'
git switch 'main'
git merge --ff-only 'github-bot/gh-2755'
git switch 'main'
git merge 'github-bot/gh-2755'
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!2755
No description provided.