Repository navigation
Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER) - #2958
Shaders: one lane of a wave sets a mark its wave shares (frames 411 -> 283 ms on an RTX 4070 SUPER)#2958moe-miau wants to merge 2 commits into
Conversation
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 <noreply@anthropic.com>
9d4bf36 to
2b48889
Compare
fuzeofficlal
left a comment
There was a problem hiding this comment.
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
waveReadLaneAtlane index (u32::MAX) on all-helper waves:- When a pixel-shader wave reaches
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. - Passing
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). - Guarding the lane index (e.g., clamping
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.
- When a pixel-shader wave reaches
- 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_leadunderdxil.dlland GPU execution.
Dukestar69
left a comment
There was a problem hiding this comment.
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 (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_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).
kotekompotek
left a comment
There was a problem hiding this comment.
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.
|
@moe-miau @fuzeofficlal I exercised both cases from the review on
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 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 -- --nocaptureThe 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 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 |
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 <noreply@anthropic.com>
|
@fuzeofficlal Good catch, fixed in @steven-seagull27 @Dukestar69 @kotekompotek thanks for the runs and the review. |
|
Automated triage for the maintainers. This cuts down write- and read-mark traffic to the system-memory bitmap. In One suggestion: @steven-seagull27's GPU readback tests for partial groups and partially covered quads ( Verdict: merge candidate. Recommending a look, not approving. Generated by Claude Code |
|
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).
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 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. |
|
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" ( 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. |
|
Verified Tests
Live Title Verification (RX 9070 XT)
Hardware runs were performed by me on my 7950X / RX 9070 XT; comment drafted with Antigravity. |
…y where one is missing Every access by address (global and scalar loads, stores and atomics on title memory, the ray-tracing node reads) stored a dword to the fault notes in every lane: the page's number at a place by the number where the page had no copy, and a sink dword (0, which the host never reads) for every other lane. The notes are a buffer in the host's memory (the host reads them after each frame), so nearly every access of every wave wrote across the bus, all waves to the same sink dword. Now only lanes whose page has no copy, and that run, store, in a block of their own; the notes the host reads are the same (dword 0 was never read). The idea is Marvisak/VIctory pull request Marvisak#2958 (moe-miau, RTX 4070 SUPER: its write and read marks, a load and an atomic OR in system memory per lane, cut to one lane per wave; frame 411 -> 330 ms). This tree has no such marks: what shaders wrote is found by the host's compares of the views' ranges, so the per-lane traffic across the bus here was this store. The directory look stays per lane: the lanes of a wave read the same entry, which the card's loads coalesce. Five of the 60 costliest passes of the first room's timing runs of 2026-11-25 access title memory by address (CS_Primary_GatherVBuffer_WithFar 3592426e3e9142d8, CS_IrradianceCache_GatherVBuffer_WithFar b58eb3ca6ee46427, CS_ScreenProbes_TraceRays_..._WithFar f22a76fcb967ee59, CS_RaytraceVBuffer_..._WithFar 6d7fe7745ab9c6d8, CS_RaytraceShadows_Mixed 0873f80dd84a3c5c; together up to about 8 ms a frame then). The callers of the look go on in the block it ends in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 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 (Shader tests: heap_direct_texture_reads_mark_their_heap_index kills the test process on a real GPU (RTX 5070, main 67e8ae1) #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