Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER) #2958

Open
github-bot wants to merge 2 commits from github-bot/gh-2958 into main AGit
Owner

@⁠moe-miau on GitHub · 2026-11-26 01:30 UTC · original
moe-miau:perf/mark-lead → main · +70 −0 · 2 files · 2 commits · open

Problem

Every store through a heap view sets its 64 KiB page's bit in the write-mark bitmap, and every heap-direct texture read sets its slot's read mark (Lower::mark_view_write, Lower::mark_view_read). Each is a load of the bitmap word, plus an atomic OR where the bit is clear. The bitmap is a shared_buffer in system memory, because the CPU reads and clears it after each submission. So each of those loads crosses the bus, once per lane, for every marked store or read.

Most lanes of a wave write the same page or read the same slot. On an RTX 4070 SUPER the passes that store the most were far slower than the same passes in other trees: a 1.5M-thread clear of three R32_UINT buffers (a7eeed0646be1ab7) took 20-41 ms.

Codex pointed at the mark traffic. I confirmed it by moving the bitmap into video memory (GPU upload heap) in a local build. GPU time dropped sharply (b58eb3ca6ee46427: 236 → 11 ms per dispatch), but CPU copy-back went to 2.8 s a frame, because the CPU's reads of that memory are uncached. So the bitmap stays where it is, and fewer lanes touch it.

Change

A lane whose mark bit equals the leading lane's leaves the load and the atomic to that lane; lanes with other bits still set their own (new lower/marks.rs, so lower.rs stays under the asset-policy size limit). The leading lane is the first active one (waveReadLaneFirst, waveIsFirstLane), and in pixel shaders the first that is no helper, since a helper's writes are dropped (lowest lane index among non-helpers by waveActiveOp min, then waveReadLaneAt).

Tested

RTX 4070 SUPER, driver 32.0.16.1742, Windows 11 26300. Title 1.0.2.1, Series X profile, diag build, scripted Enter presses, 15-minute runs. Tree: main f3578e3 + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 (VICTORY_CARD_COPIES=1) + #2925, then + this.

ms per frame (last samples) on the GPU fps over the last 12 min
without this PR 411-414 290-292 2.4-2.5
with this PR, run 1 323-331 198-208 3.0
with this PR, run 2 ~330 2.9-3.1
with this PR incl. pixel shaders (head) 281-283 151 3.3-3.6

No device removal in any run. Picture at the same scripted moments matches the run without this PR (the prologue cell).

  • victory translate --validate on the light-volume pixel shader (a885ba5d98ce46bf) and the clear (a7eeed0646be1ab7): both validate.
  • writes_through_views_mark_their_pages and straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages (they check marks on the GPU): pass.
  • cargo test -p victory-shader --lib --skip heap_direct_texture_reads_mark_their_heap_index: 298 passed, 3 failed: the same three as main on NVIDIA (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware). The skipped test crashes the process on main here too (#2571).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean. cargo xtask policy: ok.

AI-assisted (Claude Code; diagnosis with Codex). Runs done on my machine.

🤖 Generated with Claude Code

**@⁠moe-miau** on GitHub · 2026-11-26 01:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958) `moe-miau:perf/mark-lead` → `main` · +70 −0 · 2 files · 2 commits · open ## Problem Every store through a heap view sets its 64 KiB page's bit in the write-mark bitmap, and every heap-direct texture read sets its slot's read mark (`Lower::mark_view_write`, `Lower::mark_view_read`). Each is a load of the bitmap word, plus an atomic OR where the bit is clear. The bitmap is a `shared_buffer` in system memory, because the CPU reads and clears it after each submission. So each of those loads crosses the bus, once per lane, for every marked store or read. Most lanes of a wave write the same page or read the same slot. On an RTX 4070 SUPER the passes that store the most were far slower than the same passes in other trees: a 1.5M-thread clear of three R32_UINT buffers (`a7eeed0646be1ab7`) took 20-41 ms. Codex pointed at the mark traffic. I confirmed it by moving the bitmap into video memory (GPU upload heap) in a local build. GPU time dropped sharply (`b58eb3ca6ee46427`: 236 → 11 ms per dispatch), but CPU copy-back went to 2.8 s a frame, because the CPU's reads of that memory are uncached. So the bitmap stays where it is, and fewer lanes touch it. ## Change A lane whose mark bit equals the leading lane's leaves the load and the atomic to that lane; lanes with other bits still set their own (new `lower/marks.rs`, so `lower.rs` stays under the asset-policy size limit). The leading lane is the first active one (`waveReadLaneFirst`, `waveIsFirstLane`), and in pixel shaders the first that is no helper, since a helper's writes are dropped (lowest lane index among non-helpers by `waveActiveOp` min, then `waveReadLaneAt`). ## Tested RTX 4070 SUPER, driver 32.0.16.1742, Windows 11 26300. Title 1.0.2.1, Series X profile, diag build, scripted Enter presses, 15-minute runs. Tree: `main` `f3578e3` + #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 (`VICTORY_CARD_COPIES=1`) + #2925, then + this. | | ms per frame (last samples) | on the GPU | fps over the last 12 min | |---|---:|---:|---| | without this PR | 411-414 | 290-292 | 2.4-2.5 | | with this PR, run 1 | 323-331 | 198-208 | 3.0 | | with this PR, run 2 | ~330 | | 2.9-3.1 | | with this PR incl. pixel shaders (head) | 281-283 | 151 | 3.3-3.6 | No device removal in any run. Picture at the same scripted moments matches the run without this PR (the prologue cell). - `victory translate --validate` on the light-volume pixel shader (`a885ba5d98ce46bf`) and the clear (`a7eeed0646be1ab7`): both validate. - `writes_through_views_mark_their_pages` and `straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages` (they check marks on the GPU): pass. - `cargo test -p victory-shader --lib --skip heap_direct_texture_reads_mark_their_heap_index`: 298 passed, 3 failed: the same three as `main` on NVIDIA (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`). The skipped test crashes the process on `main` here too (#2571). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. `cargo xtask policy`: ok. AI-assisted (Claude Code; diagnosis with Codex). Runs done on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Every store through a heap view sets its page's bit in the write-mark
bitmap, and every heap-direct texture read its slot's read mark: a load of
the bitmap word, and an atomic OR where the bit is clear. The bitmap is in
system memory (the CPU reads and clears it after each submission), so on
the GPU each of those loads crosses the bus, once per lane. Most lanes of a
wave write the same 64 KiB page or read the same slot.

Lanes whose bit equals the first active lane's now leave the load and the
atomic to that lane (`waveReadLaneFirst`, `waveIsFirstLane`). In pixel
shaders the leading lane is the first that is no helper (a helper's writes
are dropped): the lowest lane index among non-helpers, by `waveActiveOp`
min, and `waveReadLaneAt` of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:38 +00:00
A pixel wave of helpers only had no non-helper lane, so the minimum key was
u32::MAX and waveReadLaneAt read past the wave. A helper's key is now its
lane with bit 30 set: the minimum is the first non-helper, or a helper that
no lane matches as leader, at a lane index that exists (bit 30 masked off).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:31 UTC · original · edited 2026-11-26 02:40 UTC

@⁠moe-miau @⁠fuzeofficlal I exercised both cases from the review on 2b48889a, with synthetic guest instructions and GPU readback of the actual write-mark bitmap.

Adapter Compute groups with correct stores and page bits Pixel draws with correct color, atomic count and page bit
RTX 5080 9/9 5/5
Windows built-in WARP 9/9 5/5
Microsoft.Warp 1.0.22 9/9 5/5

Compute. Group sizes were 1, 3, 7, 31, 32, 33, 63, 64 and 65. Lanes whose thread ID is a multiple of four skip the store, including thread 0. The remaining three classes write different 64 KiB pages of one view, crossing a bitmap-word boundary at bits 31–33. For 3 threads, bits 31 and 32 were set. For 7 threads, bits 31, 32 and 33 were set. All nine cases also passed with fixed-width compute shaders on RTX Wave32, built-in WARP Wave4, and portable WARP Wave4/32/64. A control that kept only the leader lost bit 32 in the 3-thread dispatch on all three adapters, even though both stores landed.

Pixel. Four draws each covered one pixel, moving it through all four corners of the same quad. A fifth triangle put its edge through several quads and covered 21 pixels. Each covered pixel did a bounded UAV atomic add. The counts were 1, 1, 1, 1, 21, and exactly page bit 31 was set on every draw. A control that selected physical lane zero lost the mark on the top-right single-pixel draw on all three adapters; the color and atomic count still showed the draw executed. These draws cover mixed real/helper quads. They cannot observe what an all-helper wave computes for its source index, so the reviewer's range-guard question remains open.

Compute regression ead53d4 and pixel regression dc84e33. The second commit adds test-host readback for graphics UAVs. To run both from this PR head:

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2958-mixed-marks
git cherry-pick ead53d4 dc84e33
cargo test -p victory-shader --lib divergent_view_writes_mark_each_page_in_partial_groups -- --nocapture
cargo test -p victory-shader --lib partially_covered_quads_mark_their_pixel_store -- --nocapture

The shader crate passed Clippy with warnings denied. These are correctness readbacks; I didn't measure frame time.

Follow-up for the helper-lane review. Source-only commit 3c30d80 elects the pixel leader inside !isHelperLane, using WaveReadLaneFirst and WaveIsFirstLane. I checked the emitted pixel DXIL: helpers bypass the election, provide false at the join and skip the bitmap load/atomic. The marker emits no indexed lane read, so an all-helper wave has no source index to clamp. The RTX and both WARP versions still passed all five pixel draws. A second version of the 21-pixel triangle sent alternate columns to two pages; all three adapters returned 9 and 12 atomic increments and exactly bits 31 and 32 both before and after the change. The nine compute groups, original write-mark test and strict Clippy also passed on the candidate. I haven't measured the extra branch on a game frame.

The source commit cherry-picks independently of the test commits:

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2958-pixel-real-mark
git cherry-pick 3c30d80
**@⁠steven-seagull27** on GitHub · 2026-11-26 02:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7180876247) · edited 2026-11-26 02:40 UTC @⁠moe-miau @⁠fuzeofficlal I exercised both cases from the review on `2b48889a`, with synthetic guest instructions and GPU readback of the actual write-mark bitmap. | Adapter | Compute groups with correct stores and page bits | Pixel draws with correct color, atomic count and page bit | |---|---:|---:| | RTX 5080 | 9/9 | 5/5 | | Windows built-in WARP | 9/9 | 5/5 | | Microsoft.Warp 1.0.22 | 9/9 | 5/5 | **Compute.** Group sizes were 1, 3, 7, 31, 32, 33, 63, 64 and 65. Lanes whose thread ID is a multiple of four skip the store, including thread 0. The remaining three classes write different 64 KiB pages of one view, crossing a bitmap-word boundary at bits 31–33. For 3 threads, bits 31 and 32 were set. For 7 threads, bits 31, 32 and 33 were set. All nine cases also passed with fixed-width compute shaders on RTX Wave32, built-in WARP Wave4, and portable WARP Wave4/32/64. A control that kept only the leader lost bit 32 in the 3-thread dispatch on all three adapters, even though both stores landed. **Pixel.** Four draws each covered one pixel, moving it through all four corners of the same quad. A fifth triangle put its edge through several quads and covered 21 pixels. Each covered pixel did a bounded UAV atomic add. The counts were `1, 1, 1, 1, 21`, and exactly page bit 31 was set on every draw. A control that selected physical lane zero lost the mark on the top-right single-pixel draw on all three adapters; the color and atomic count still showed the draw executed. These draws cover mixed real/helper quads. They cannot observe what an all-helper wave computes for its source index, so the reviewer's range-guard question remains open. [Compute regression ead53d4](https://github.com/steven-seagull27/VIctory/commit/ead53d4eaee103b33597e27b94b8334b2200ed7c) and [pixel regression dc84e33](https://github.com/steven-seagull27/VIctory/commit/dc84e33c56026e0ac9173455068d26ca3ebe7afb). The second commit adds test-host readback for graphics UAVs. To run both from this PR head: ```sh git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2958-mixed-marks git cherry-pick ead53d4 dc84e33 cargo test -p victory-shader --lib divergent_view_writes_mark_each_page_in_partial_groups -- --nocapture cargo test -p victory-shader --lib partially_covered_quads_mark_their_pixel_store -- --nocapture ``` The shader crate passed Clippy with warnings denied. These are correctness readbacks; I didn't measure frame time. **Follow-up for the helper-lane review.** [Source-only commit 3c30d80](https://github.com/steven-seagull27/VIctory/commit/3c30d800e43b7f31dabb3a2a1ad91c93ae239715) elects the pixel leader inside `!isHelperLane`, using `WaveReadLaneFirst` and `WaveIsFirstLane`. I checked the emitted pixel DXIL: helpers bypass the election, provide `false` at the join and skip the bitmap load/atomic. The marker emits no indexed lane read, so an all-helper wave has no source index to clamp. The RTX and both WARP versions still passed all five pixel draws. A second version of the 21-pixel triangle sent alternate columns to two pages; all three adapters returned 9 and 12 atomic increments and exactly bits 31 and 32 both before and after the change. The nine compute groups, original write-mark test and strict Clippy also passed on the candidate. I haven't measured the extra branch on a game frame. The source commit cherry-picks independently of the test commits: ```sh git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2958-pixel-real-mark git cherry-pick 3c30d80 ```
Author
Owner

@⁠moe-miau on GitHub · 2026-11-26 04:26 UTC · original

@⁠fuzeofficlal Good catch, fixed in 1f9c4b3: a helper's key is now its lane with bit 30 set, so the minimum is the first non-helper, or in an all-helper wave a helper no lane matches as leader, and waveReadLaneAt reads at that key with bit 30 masked off (a lane that exists). The light-volume pixel shader still validates (victory translate --validate), and the two GPU mark tests pass.

@⁠steven-seagull27 @⁠Dukestar69 @⁠kotekompotek thanks for the runs and the review.

**@⁠moe-miau** on GitHub · 2026-11-26 04:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7182595836) @⁠fuzeofficlal Good catch, fixed in `1f9c4b3`: a helper's key is now its lane with bit 30 set, so the minimum is the first non-helper, or in an all-helper wave a helper no lane matches as leader, and `waveReadLaneAt` reads at that key with bit 30 masked off (a lane that exists). The light-volume pixel shader still validates (`victory translate --validate`), and the two GPU mark tests pass. @⁠steven-seagull27 @⁠Dukestar69 @⁠kotekompotek thanks for the runs and the review.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:28 UTC · original

Automated triage for the maintainers.

This cuts down write- and read-mark traffic to the system-memory bitmap. In Lower::mark_view_write and Lower::mark_view_read, the bitmap load and atomic now sit behind mark_lead (new emit/lower/marks.rs). A lane skips them only when its mark bit equals that of the leading lane, so every distinct bit is still set by at least one active lane. The marks themselves don't change. In compute, the leader is the first active lane (waveReadLaneFirst/waveIsFirstLane). In pixel shaders, it is the first non-helper lane, picked with a keyed waveActiveOp minimum. 1f9c4b3 fixes the all-helper case, so the read-lane index always names a real lane. Keeping it in a submodule keeps lower.rs under the policy size limit. CI: passing.

One suggestion: @⁠steven-seagull27's GPU readback tests for partial groups and partially covered quads (ead53d4, dc84e33, linked in the thread) would pin this behaviour in the repo. Pulling them in would be worthwhile.

Verdict: merge candidate. Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7183520037) <!-- victory-triage v1 head=1f9c4b3771cec8a429bf9a8dd26bfc525c224b05 verdict=merge-candidate at=2026-11-26T05:28:29Z --> Automated triage for the maintainers. This cuts down write- and read-mark traffic to the system-memory bitmap. In `Lower::mark_view_write` and `Lower::mark_view_read`, the bitmap load and atomic now sit behind `mark_lead` (new `emit/lower/marks.rs`). A lane skips them only when its mark bit equals that of the leading lane, so every distinct bit is still set by at least one active lane. The marks themselves don't change. In compute, the leader is the first active lane (`waveReadLaneFirst`/`waveIsFirstLane`). In pixel shaders, it is the first non-helper lane, picked with a keyed `waveActiveOp` minimum. `1f9c4b3` fixes the all-helper case, so the read-lane index always names a real lane. Keeping it in a submodule keeps `lower.rs` under the policy size limit. CI: passing. One suggestion: @⁠steven-seagull27's GPU readback tests for partial groups and partially covered quads (`ead53d4`, `dc84e33`, linked in the thread) would pin this behaviour in the repo. Pulling them in would be worthwhile. **Verdict: merge candidate.** Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠walterwallaceson on GitHub · 2026-11-26 05:52 UTC · original

RTX 3070 8 GB, Windows 10: GPU time goes down as intended (~370 → 260-290 ms a frame), but the frame gets 2-3× slower overall. Copy-back rises from ~60 to 470-690 ms a frame, and host copies run at about a fifth of their usual throughput. Two runs each.

Setup: RTX 3070 8 GB, driver 621.14, Windows 10 22H2 (19045). main 63bcca4 + #463 (Agility runtime, needed on Windows 10) + #2626, then + this PR at 1f9c4b3. Diag build, Enter scripted at 17, 30 and 60 s, nothing skipped. Averages over minutes 5-10 of each run, from the frame-rate lines:

fps ms/frame on the GPU preparing copies (ms / MB / throughput) copying back (ms / MB)
without this PR, run 1 1.79 562 364 134 46 / 104 / 2.3 GB/s 62 / 0.0
without this PR, run 2 1.73 582 383 138 41 / 111 / 2.7 GB/s 59 / 0.0
with this PR, run 1 0.60 1,697 293 456 215 / 108 / 0.5 GB/s 691 / 0.2
with this PR, run 2 0.74 1,376 261 487 225 / 99 / 0.44 GB/s 470 / 0.1
with this PR + #2705 (7dcc595, VICTORY_CARD_COPIES=1) 0.84 1,225 211 533 167 / – 357 / –

No device removal or errors in any run. The amount copied is the same with and without the PR. What changes is the time: the copies and the copy-back both slow down while barely any more data comes back.

Your tree had #2705 with VICTORY_CARD_COPIES=1, so I added it (last row; the log shows card copies on, 7.5-8.6 MB a frame up). That brings GPU time down further, but copy-back stays around 360 ms and the frame is still about twice as slow as without this PR. Your tree also had #2098/#2464/#2628, which ours doesn't, so one of those may be what keeps copy-back short there.

Not tested: why the copy-back slows (no profile); #2705 without this PR on this card (running now); a third run; the picture.

No game data attached. I'm testing with Claude's help, and Claude drafted this comment.

**@⁠walterwallaceson** on GitHub · 2026-11-26 05:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7183882982) **RTX 3070 8 GB, Windows 10: GPU time goes down as intended (~370 → 260-290 ms a frame), but the frame gets 2-3× slower overall. Copy-back rises from ~60 to 470-690 ms a frame, and host copies run at about a fifth of their usual throughput. Two runs each.** **Setup:** RTX 3070 8 GB, driver 621.14, Windows 10 22H2 (19045). `main` `63bcca4` + #463 (Agility runtime, needed on Windows 10) + #2626, then + this PR at `1f9c4b3`. Diag build, Enter scripted at 17, 30 and 60 s, nothing skipped. Averages over minutes 5-10 of each run, from the frame-rate lines: | | fps | ms/frame | on the GPU | preparing | copies (ms / MB / throughput) | copying back (ms / MB) | |---|---|---|---|---|---|---| | without this PR, run 1 | 1.79 | 562 | 364 | 134 | 46 / 104 / 2.3 GB/s | 62 / 0.0 | | without this PR, run 2 | 1.73 | 582 | 383 | 138 | 41 / 111 / 2.7 GB/s | 59 / 0.0 | | with this PR, run 1 | 0.60 | 1,697 | 293 | 456 | 215 / 108 / 0.5 GB/s | 691 / 0.2 | | with this PR, run 2 | 0.74 | 1,376 | 261 | 487 | 225 / 99 / 0.44 GB/s | 470 / 0.1 | | with this PR + #2705 (`7dcc595`, `VICTORY_CARD_COPIES=1`) | 0.84 | 1,225 | 211 | 533 | 167 / – | 357 / – | No device removal or errors in any run. The amount copied is the same with and without the PR. What changes is the time: the copies and the copy-back both slow down while barely any more data comes back. Your tree had #2705 with `VICTORY_CARD_COPIES=1`, so I added it (last row; the log shows card copies on, 7.5-8.6 MB a frame up). That brings GPU time down further, but copy-back stays around 360 ms and the frame is still about twice as slow as without this PR. Your tree also had #2098/#2464/#2628, which ours doesn't, so one of those may be what keeps copy-back short there. Not tested: why the copy-back slows (no profile); #2705 without this PR on this card (running now); a third run; the picture. No game data attached. I'm testing with Claude's help, and Claude drafted this comment.
Author
Owner

@⁠walterwallaceson on GitHub · 2026-11-26 06:20 UTC · original

Correction to my comment above: don't count the slowdown against this PR yet. A control run of the exact tree I called "without this PR" (main 63bcca4 + #463 + #2626, same binary as the 1.79 fps run) came out at 0.93 fps, with copy-back at 280 ms, about the same as the runs with this PR. On this RTX 3070, frame rate swings between roughly 0.7 and 1.8 fps from run to run of the same build, for a reason I haven't found yet (the memory use and draws per frame look alike). My two "without" runs happened to be fast ones.

What still holds: GPU time per frame was lower in every run with this PR (211-293 ms against 333-383 without), which is the part this PR changes. I'll come back with numbers once I can measure the run-to-run spread on this card.

I'm testing with Claude's help, and Claude drafted this comment.

**@⁠walterwallaceson** on GitHub · 2026-11-26 06:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7184335309) **Correction to my comment above: don't count the slowdown against this PR yet.** A control run of the exact tree I called "without this PR" (`main` `63bcca4` + #463 + #2626, same binary as the 1.79 fps run) came out at **0.93 fps, with copy-back at 280 ms**, about the same as the runs with this PR. On this RTX 3070, frame rate swings between roughly 0.7 and 1.8 fps from run to run of the same build, for a reason I haven't found yet (the memory use and draws per frame look alike). My two "without" runs happened to be fast ones. What still holds: GPU time per frame was lower in every run with this PR (211-293 ms against 333-383 without), which is the part this PR changes. I'll come back with numbers once I can measure the run-to-run spread on this card. I'm testing with Claude's help, and Claude drafted this comment.
Author
Owner

@⁠MeMako on GitHub · 2026-11-26 07:00 UTC · original

Verified #2958 (1f9c4b3) on AMD RDNA 4 (Windows 11 10.0.26200, Ryzen 9 7950X, RX 9070 XT, driver 32.0.32029.2010, 32 GB RAM).

Tests

  • cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets --locked -- -D warnings: clean.
  • cargo test -p victory-shader --lib --locked: 305/305 passed, 0 failed — including all 3 GPU mark tests (writes_through_views_mark_their_pages, straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages, and heap_direct_texture_reads_mark_their_heap_index).
  • Translated all 25,985 shaders cleanly via victory translate --cache (0 crashes / 0 regressions).

Live Title Verification (RX 9070 XT)

  • Setup: Local integration branch (main 63bcca4 + #2051 + #2472 + #2918 + #1010 + #2130 with VRAM upload flags off + #3055 + #2914 + #2985 + #2849 + #3035), before vs. after merging #2958 (n=65 world / n=53 heavy frames vs. n=54 / n=38 baseline).
  • Result: 0 crashes, 0 device removals, 0 visual regressions through the intro and opening world scene.
  • GPU time:
    • Heavy frames (>=4k draws): median 166.9 → 162.2 ms, avg 194.7 → 169.9 ms (-24.8 ms on streaming spikes)
    • Steady tail (last 20 heavy, ~6,056 vs. 6,186 draws): median 162.5 → 158.4 ms (-4.1 ms), avg 162.3 → 159.9 ms
  • Cross-vendor note: Unlike NVIDIA (290 → 151 ms on RTX 4070 SUPER), RDNA 4's L2 + Infinity Cache already kept GPU time near ~162 ms before this PR, so the steady-state GPU delta on RX 9070 XT is small (-4.1 ms) with stronger improvement on heavy spikes (-24.8 ms avg) and zero regressions.

Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.

**@⁠MeMako** on GitHub · 2026-11-26 07:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7185003944) Verified `#2958` (`1f9c4b3`) on AMD RDNA 4 (Windows 11 `10.0.26200`, Ryzen 9 7950X, RX 9070 XT, driver `32.0.32029.2010`, 32 GB RAM). ### Tests - `cargo clippy -p victory-shader -p victory-gpu -p victory --all-targets --locked -- -D warnings`: clean. - `cargo test -p victory-shader --lib --locked`: **305/305 passed**, 0 failed — including all 3 GPU mark tests (`writes_through_views_mark_their_pages`, `straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages`, and `heap_direct_texture_reads_mark_their_heap_index`). - Translated all **25,985** shaders cleanly via `victory translate --cache` (0 crashes / 0 regressions). ### Live Title Verification (RX 9070 XT) - **Setup:** Local integration branch (`main` `63bcca4` + `#2051` + `#2472` + `#2918` + `#1010` + `#2130` with VRAM upload flags off + `#3055` + `#2914` + `#2985` + `#2849` + `#3035`), before vs. after merging `#2958` (`n=65` world / `n=53` heavy frames vs. `n=54` / `n=38` baseline). - **Result:** 0 crashes, 0 device removals, 0 visual regressions through the intro and opening world scene. - **GPU time:** - Heavy frames (`>=4k` draws): median **166.9 → 162.2 ms**, avg **194.7 → 169.9 ms** (**-24.8 ms** on streaming spikes) - Steady tail (last 20 heavy, ~6,056 vs. 6,186 draws): median **162.5 → 158.4 ms** (**-4.1 ms**), avg **162.3 → 159.9 ms** - **Cross-vendor note:** Unlike NVIDIA (`290 → 151 ms` on RTX 4070 SUPER), RDNA 4's L2 + Infinity Cache already kept GPU time near ~162 ms before this PR, so the steady-state GPU delta on RX 9070 XT is small (`-4.1 ms`) with stronger improvement on heavy spikes (`-24.8 ms` avg) and zero regressions. *Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.*
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:59 UTC · original · reviewed

Reviewed and tested updated commit 2b48889a against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll). The non-pixel path (waveReadLaneFirst + waveIsFirstLane with (n != f) || first) is clean, splitting the helper into emit/lower/marks.rs keeps emit/lower.rs safely below the 512 KiB cap (520,878 B), and emit::memory_tests pass (4/4, skipping the pre-existing Win11 WARP heap_direct_texture_reads_mark_their_heap_index crash).

One edge case to address in the newly added pixel-shader branch (crates/victory-shader/src/emit/lower/marks.rs:19-45):

  • Out-of-range waveReadLaneAt lane index (u32::MAX) on all-helper waves:
    • When a pixel-shader wave reaches mark_lead(n) with only helper lanes active (for instance, in unguarded mark_view_read, or after discard/divergent control flow where only helper lanes remain in the block), every lane produces key = u32::MAX, so waveActiveOp.i32(min, unsigned) returns lead = 0xFFFF_FFFF.
    • Passing lead = 0xFFFF_FFFF to dx.op.waveReadLaneAt.i32(n, lead) (marks.rs:38-44) is an out-of-bounds lane index (undefined behavior in DXIL/D3D12), and if the undefined f differs from n, helper lanes will also fall through and execute the system-memory bitmap load (raw_dword).
    • Guarding the lane index (e.g., clamping lead to 0 when lead == u32::MAX, and returning false for helper lanes via !helper && (differ || first) since helper-lane writes are dropped anyway) avoids both UB and unnecessary helper-lane bitmap traffic.
  • Adding a pixel-shader test (with helper lanes or a partial quad) plus a divergent-lane test writing two distinct pages/slots would also directly cover both branches of mark_lead under dxil.dll and GPU execution.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#pullrequestreview-6067549825) · **reviewed** Reviewed and tested updated commit `2b48889a` against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`). The non-pixel path (`waveReadLaneFirst` + `waveIsFirstLane` with `(n != f) || first`) is clean, splitting the helper into `emit/lower/marks.rs` keeps `emit/lower.rs` safely below the 512 KiB cap (`520,878 B`), and `emit::memory_tests` pass (`4/4`, skipping the pre-existing Win11 WARP `heap_direct_texture_reads_mark_their_heap_index` crash). One edge case to address in the newly added pixel-shader branch (`crates/victory-shader/src/emit/lower/marks.rs:19-45`): - **Out-of-range `waveReadLaneAt` lane index (`u32::MAX`) on all-helper waves**: - When a pixel-shader wave reaches `mark_lead(n)` with only helper lanes active (for instance, in unguarded `mark_view_read`, or after `discard`/divergent control flow where only helper lanes remain in the block), every lane produces `key = u32::MAX`, so `waveActiveOp.i32(min, unsigned)` returns `lead = 0xFFFF_FFFF`. - Passing `lead = 0xFFFF_FFFF` to `dx.op.waveReadLaneAt.i32(n, lead)` (`marks.rs:38-44`) is an out-of-bounds lane index (undefined behavior in DXIL/D3D12), and if the undefined `f` differs from `n`, helper lanes will also fall through and execute the system-memory bitmap load (`raw_dword`). - Guarding the lane index (e.g., clamping `lead` to `0` when `lead == u32::MAX`, and returning `false` for helper lanes via `!helper && (differ || first)` since helper-lane writes are dropped anyway) avoids both UB and unnecessary helper-lane bitmap traffic. - Adding a pixel-shader test (with helper lanes or a partial quad) plus a divergent-lane test writing two distinct pages/slots would also directly cover both branches of `mark_lead` under `dxil.dll` and GPU execution.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 02:01 UTC · original · approved these changes

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::memory_tests -- --skip heap_direct_texture_reads_mark_their_heap_index: 4 passed, 0 failed (including writes_through_views_mark_their_pages on RTX 5090 hardware + WARP).
  • VICTORY_WARP=1 cargo test -p victory-shader --lib emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index: 1 passed, 0 failed (pre-existing #2571 skips hardware run on NVIDIA).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

The wave-coalescing logic in Lower::mark_lead is sound: in non-pixel shaders, waveReadLaneFirst(n) + waveIsFirstLane() lets one active lane handle the common bit while any lane with n != f still marks its own bit; in pixel shaders, selecting the minimum non-helper lane index avoids delegating a write mark to a helper lane whose UAV atomic would be dropped.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 02:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#pullrequestreview-6067567270) · **approved these changes** Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::memory_tests -- --skip heap_direct_texture_reads_mark_their_heap_index`: **4 passed, 0 failed** (including `writes_through_views_mark_their_pages` on RTX 5090 hardware + WARP). - `VICTORY_WARP=1 cargo test -p victory-shader --lib emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index`: **1 passed, 0 failed** (pre-existing `#2571` skips hardware run on NVIDIA). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. The wave-coalescing logic in `Lower::mark_lead` is sound: in non-pixel shaders, `waveReadLaneFirst(n)` + `waveIsFirstLane()` lets one active lane handle the common bit while any lane with `n != f` still marks its own bit; in pixel shaders, selecting the minimum non-helper lane index avoids delegating a write mark to a helper lane whose UAV atomic would be dropped. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:24 UTC · original · reviewed

Verified: one lane per wave does the bitmap load+atomic instead of all 32 — the dedup rule (lane marks iff it leads OR its bit differs from the lead's) is exactly right. Pixel path correctly excludes helper lanes via isHelperLane+waveActiveOp(min)+waveReadLaneAt, non-pixel uses waveReadLaneFirst/waveIsFirstLane. Setting WAVE_OPS flag is necessary and done. re-binding c after begin_guarded matches the surrounding idiom.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#pullrequestreview-6067730546) · **reviewed** Verified: one lane per wave does the bitmap load+atomic instead of all 32 — the dedup rule (lane marks iff it leads OR its bit differs from the lead's) is exactly right. Pixel path correctly excludes helper lanes via isHelperLane+waveActiveOp(min)+waveReadLaneAt, non-pixel uses waveReadLaneFirst/waveIsFirstLane. Setting WAVE_OPS flag is necessary and done. re-binding c after begin_guarded matches the surrounding idiom.
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 16:58 UTC · original

In-game measurements of this PR on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's lit prison yard after the opening.

Setup:

  • Build: main plus a few unmerged PRs needed on this setup (#2723, #439, #2118, #2703, #2101, #2312 and others), with this PR (1f9c4b3) merged on top. No conflicts. diag build.
  • Untimed runs: 10 minutes, medians over the last 30 frame-rate lines, warm caches.
  • Timed runs: with VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1, giving per-command GPU time.

Untimed (what a player would see):

without this PR with this PR
ms/frame 871.3 (1.1 fps) 672.9 (1.5 fps)
on the GPU 755.3 459.1
preparing / copying back 67.3 / 47.6 62.1 / 44.3

That's 23% less frame time. No device removal, Xid or refused pipeline in either run, and the yard renders the same.

Timed:

marks per lane this PR
GPU command time per frame 579 ms 346 ms
[mesh b7a81f5b96f4ca93, pixel 43e24028d4a1faef] (G-buffer, 151 draws/frame) 49.7 ms 8.3 ms
CS_ResetTilesMask (a7eeed0646be1ab7) top-25 entry 3.4 ms

How much the marks cost: before finding this PR, I measured the marks themselves with a measurement-only switch that turns view marks off; that breaks copy-back, so it's for measurement only. The same frame took 251 ms of GPU command time with marks off, against 579 ms with per-lane marks. So on NVIDIA the marks cost about 320 ms/frame, and this PR recovers most of it (346 ms). The marks bitmap here is in system memory (CUSTOM heap, WRITE_BACK, L0), which is why #2465's video-memory bitmap looks complementary. That's untested here so far.

Same approach, independently: I'd written a wave-coalesced version independently (a vote on the bitmap word, then one atomic of the OR of the lanes' bits). It measured 352 ms of GPU commands and 9.0 ms for the G-buffer pair, so slightly behind this PR. I'm not posting it. I also wrote a GPU test that compares coalesced marks with per-lane marks word for word: preset bits, divergent branches, lanes on the same and on different words. It passes on this PR's lowering, together with your writes_through_views_mark_their_pages and the 256 MiB/4 GiB straddling test, under Wine on the RTX 5090 and on WARP. It currently builds only on my test base; I'm adapting it to main + this PR and will link it here if you want it.

This also explains the per-draw NVIDIA cost in #3028: the same G-buffer pair is the top entry there.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 16:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7198330874) In-game measurements of this PR on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's lit prison yard after the opening. **Setup:** - **Build:** `main` plus a few unmerged PRs needed on this setup (#2723, #439, #2118, #2703, #2101, #2312 and others), with this PR (`1f9c4b3`) merged on top. No conflicts. `diag` build. - **Untimed runs:** 10 minutes, medians over the last 30 frame-rate lines, warm caches. - **Timed runs:** with `VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1`, giving per-command GPU time. **Untimed** (what a player would see): | | without this PR | with this PR | |---|---|---| | ms/frame | 871.3 (1.1 fps) | **672.9 (1.5 fps)** | | on the GPU | 755.3 | **459.1** | | preparing / copying back | 67.3 / 47.6 | 62.1 / 44.3 | That's 23% less frame time. No device removal, Xid or refused pipeline in either run, and the yard renders the same. **Timed:** | | marks per lane | this PR | |---|---|---| | GPU command time per frame | 579 ms | **346 ms** | | `[mesh b7a81f5b96f4ca93, pixel 43e24028d4a1faef]` (G-buffer, 151 draws/frame) | 49.7 ms | **8.3 ms** | | `CS_ResetTilesMask` (`a7eeed0646be1ab7`) | top-25 entry | 3.4 ms | **How much the marks cost:** before finding this PR, I measured the marks themselves with a measurement-only switch that turns view marks off; that breaks copy-back, so it's for measurement only. The same frame took **251 ms** of GPU command time with marks off, against 579 ms with per-lane marks. So on NVIDIA the marks cost about 320 ms/frame, and this PR recovers most of it (346 ms). The marks bitmap here is in system memory (CUSTOM heap, WRITE_BACK, L0), which is why #2465's video-memory bitmap looks complementary. That's untested here so far. **Same approach, independently:** I'd written a wave-coalesced version independently (a vote on the bitmap word, then one atomic of the OR of the lanes' bits). It measured 352 ms of GPU commands and 9.0 ms for the G-buffer pair, so slightly behind this PR. I'm not posting it. I also wrote a GPU test that compares coalesced marks with per-lane marks word for word: preset bits, divergent branches, lanes on the same and on different words. It passes on this PR's lowering, together with your `writes_through_views_mark_their_pages` and the 256 MiB/4 GiB straddling test, under Wine on the RTX 5090 and on WARP. It currently builds only on my test base; I'm adapting it to `main` + this PR and will link it here if you want it. This also explains the per-draw NVIDIA cost in #3028: the same G-buffer pair is the top entry there. _AI-assisted (Claude); measured on my machine, no game data shared._
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 17:02 UTC · original

The GPU test I mentioned now builds on main + this PR alone:

  • Branch: neonbyte1/VIctory test/2958-bitmap, one test-only commit 1fee6b7 on top of your 1f9c4b3. Feel free to cherry-pick it.
  • What it does: wave_coalesced_marks_equal_per_lane_marks_on_the_gpu lowers the same program twice, once as is and once with the leader election disabled through a #[cfg(test)] hook in lower::marks, and compares the written bitmaps word for word.
    • It covers a 64-lane wave32 dispatch with lanes on the same and on different words, divergent branches, and bits 5, 11 and 320 already set before the dispatch.
    • Root::UavData is a small addition to the test host that presets a root UAV.
  • Result: passes on an RTX 5090 under Wine with vkd3d-proton, along with your two marks tests. Clippy (default and --all-features), policy and formatting are clean.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 17:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2958#issuecomment-7198403694) The GPU test I mentioned now builds on `main` + this PR alone: - **Branch:** [neonbyte1/VIctory `test/2958-bitmap`](https://github.com/neonbyte1/VIctory/commits/test/2958-bitmap), one test-only commit `1fee6b7` on top of your `1f9c4b3`. Feel free to cherry-pick it. - **What it does:** `wave_coalesced_marks_equal_per_lane_marks_on_the_gpu` lowers the same program twice, once as is and once with the leader election disabled through a `#[cfg(test)]` hook in `lower::marks`, and compares the written bitmaps word for word. - It covers a 64-lane wave32 dispatch with lanes on the same and on different words, divergent branches, and bits 5, 11 and 320 already set before the dispatch. - `Root::UavData` is a small addition to the test host that presets a root UAV. - **Result:** passes on an RTX 5090 under Wine with vkd3d-proton, along with your two marks tests. Clippy (default and `--all-features`), policy and formatting are clean. _AI-assisted (Claude); measured on my machine, no game data shared._
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/2958/head:github-bot/gh-2958'
git switch 'github-bot/gh-2958'

Merge

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