Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER) #2958
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2958
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2958"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@moe-miau on GitHub · 2026-11-26 01:30 UTC · original
moe-miau:perf/mark-lead→main· +70 −0 · 2 files · 2 commits · openProblem
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 ashared_bufferin 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, solower.rsstays 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 bywaveActiveOpmin, thenwaveReadLaneAt).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:
mainf3578e3+ #2464 + #2098 + #2626 + #2628 + #2711 + #2851 + #2705 (VICTORY_CARD_COPIES=1) + #2925, then + this.No device removal in any run. Picture at the same scripted moments matches the run without this PR (the prologue cell).
victory translate --validateon the light-volume pixel shader (a885ba5d98ce46bf) and the clear (a7eeed0646be1ab7): both validate.writes_through_views_mark_their_pagesandstraddling_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 asmainon 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 onmainhere 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
@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.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:
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, usingWaveReadLaneFirstandWaveIsFirstLane. I checked the emitted pixel DXIL: helpers bypass the election, providefalseat 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:
@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, andwaveReadLaneAtreads 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.
@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_writeandLower::mark_view_read, the bitmap load and atomic now sit behindmark_lead(newemit/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 keyedwaveActiveOpminimum.1f9c4b3fixes the all-helper case, so the read-lane index always names a real lane. Keeping it in a submodule keepslower.rsunder 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
@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).
main63bcca4+ #463 (Agility runtime, needed on Windows 10) + #2626, then + this PR at1f9c4b3. 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:7dcc595,VICTORY_CARD_COPIES=1)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 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" (
main63bcca4+ #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.
@MeMako on GitHub · 2026-11-26 07:00 UTC · original
Verified
#2958(1f9c4b3) on AMD RDNA 4 (Windows 1110.0.26200, Ryzen 9 7950X, RX 9070 XT, driver32.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, andheap_direct_texture_reads_mark_their_heap_index).victory translate --cache(0 crashes / 0 regressions).Live Title Verification (RX 9070 XT)
main63bcca4+#2051+#2472+#2918+#1010+#2130with VRAM upload flags off +#3055+#2914+#2985+#2849+#3035), before vs. after merging#2958(n=65world /n=53heavy frames vs.n=54/n=38baseline).>=4kdraws): median 166.9 → 162.2 ms, avg 194.7 → 169.9 ms (-24.8 ms on streaming spikes)290 → 151 mson 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 msavg) and zero regressions.Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity.
@fuzeofficlal on GitHub · 2026-11-26 01:59 UTC · original · reviewed
Reviewed and tested updated commit
2b48889aagainstmain(63bcca43) on Windows 11 (RTX 5090 + WARP +dxil.dll). The non-pixel path (waveReadLaneFirst+waveIsFirstLanewith(n != f) || first) is clean, splitting the helper intoemit/lower/marks.rskeepsemit/lower.rssafely below the 512 KiB cap (520,878 B), andemit::memory_testspass (4/4, skipping the pre-existing Win11 WARPheap_direct_texture_reads_mark_their_heap_indexcrash).One edge case to address in the newly added pixel-shader branch (
crates/victory-shader/src/emit/lower/marks.rs:19-45):waveReadLaneAtlane index (u32::MAX) on all-helper waves:mark_lead(n)with only helper lanes active (for instance, in unguardedmark_view_read, or afterdiscard/divergent control flow where only helper lanes remain in the block), every lane produceskey = u32::MAX, sowaveActiveOp.i32(min, unsigned)returnslead = 0xFFFF_FFFF.lead = 0xFFFF_FFFFtodx.op.waveReadLaneAt.i32(n, lead)(marks.rs:38-44) is an out-of-bounds lane index (undefined behavior in DXIL/D3D12), and if the undefinedfdiffers fromn, helper lanes will also fall through and execute the system-memory bitmap load (raw_dword).leadto0whenlead == u32::MAX, and returningfalsefor helper lanes via!helper && (differ || first)since helper-lane writes are dropped anyway) avoids both UB and unnecessary helper-lane bitmap traffic.mark_leadunderdxil.dlland GPU execution.@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.dllvalidator active):cargo test -p victory-shader --lib emit::memory_tests -- --skip heap_direct_texture_reads_mark_their_heap_index: 4 passed, 0 failed (includingwrites_through_views_mark_their_pageson 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#2571skips 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_leadis sound: in non-pixel shaders,waveReadLaneFirst(n)+waveIsFirstLane()lets one active lane handle the common bit while any lane withn != fstill 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).
@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.
@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:
mainplus 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.diagbuild.VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1, giving per-command GPU time.Untimed (what a player would see):
That's 23% less frame time. No device removal, Xid or refused pipeline in either run, and the yard renders the same.
Timed:
[mesh b7a81f5b96f4ca93, pixel 43e24028d4a1faef](G-buffer, 151 draws/frame)CS_ResetTilesMask(a7eeed0646be1ab7)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_pagesand 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 tomain+ 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 17:02 UTC · original
The GPU test I mentioned now builds on
main+ this PR alone:test/2958-bitmap, one test-only commit1fee6b7on top of your1f9c4b3. Feel free to cherry-pick it.wave_coalesced_marks_equal_per_lane_marks_on_the_gpulowers the same program twice, once as is and once with the leader election disabled through a#[cfg(test)]hook inlower::marks, and compares the written bitmaps word for word.Root::UavDatais a small addition to the test host that presets a root UAV.--all-features), policy and formatting are clean.AI-assisted (Claude); measured on my machine, no game data shared.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.