Shaders: coalesce title-memory dirty marks within a wave #2753
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2755"
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?
Imported from Marvisak/VIctory. Originally posted by brainbudt on 2026-11-25T19:45:08Z.
Lanes writing the same title-memory page repeatedly issue
atomicOragainst the same dirty-bitmap word in system RAM, serializing GPU dispatches (reported in #2695).What changed
WaveActiveAllEqualon the bitmap word index. When active lanes share a word, combine their masks withWaveActiveBitOrand elect one writer withWaveIsFirstLane; when words differ, each lane keeps its own address and mask.atomicBinOpand skip the atomic when all requested bits are already set.WAVE_OPS(SFI0 0x4000); stays on SM 6.6 with no fixed wave size, and excludes pixel helper lanes.Verification
x86_64-pc-windows-msvccargo check --testspassed; macOS ARM64 & Linux x86-64 release test suites (159 passed) and Clippy-D warningspassed (tested with the #2670 validator guards).Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T20:04:02Z.
Reviewed and verified
26a05508on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll/dxc.exe) againstmain(13f91ca).Code review
Lower::memorybuildsmarks(write/active/e.miss) and narrows control flow withbegin_guarded(marks)before enteringmark_memory_page, so only lanes that actually need to mark participate inwaveActiveAllEqual,waveActiveBit(Or), andwaveIsFirstLane. When all participating lanes target the same bitmap dword (same), one elected lane (waveIsFirstLane) issues the pre-check + combinedatomicBinOp(OR); when divergent,selectfalls back cleanly to per-lane bit masks and writers with no under-marking.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.0 -> 1on GPU during a submission (cleared on CPU beforehand), a stale L1rawBufferLoadreading0only causes a benign redundantatomicOr, whereas reading1guarantees 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 pinningWaveSize(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.git merge-treeagainst13f91ca,#2668,#2724, and#2761; touches the samewrite && bytes > 1tail-page section ofLower::memoryas#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 verifyingSFI0 0x4000,dxc -dumpbinIR, and WARP execution acrossshift = 2/16/21).emit::memory_tests: WARP (VICTORY_WARP=1) 4/4 passed; RTX 5090 3/3 passed (skipping only the pre-existing13f91ca0xc0000005baseline inheap_direct_texture_reads_mark_their_heap_index).victory-shader --features host(excluding slowvalu_tests& that baseline test): 264 passed, 3 failed (all 3 are pre-existing RTX 509013f91cabaselines, 0 regressions).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings;cargo xtask policy: 184 files ok.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T20:04:24Z.
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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T20:16:17Z.
Independent WARP verification: PR head
26a0550Environment: 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.0dxil.dll1.8.2502.11 onPATH. Tested the PR head itself (single commit directly onorigin/main13f91caee2, so identical to the merge tree). All commandscargo ... --locked.Baseline on origin/main:
test -p victory-shader --lib --features host(andhost,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) andgathers_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 thedump_dxilIR-order assertions oftitle_page_marks_use_wave_ops_and_guard_the_atomicactually ran.emit/lower.rsfrom origin/main:title_page_marks_use_wave_ops_and_guard_the_atomicfails (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:
waveActiveAllEqualon the word index,waveActiveBitOR (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 ofwaveActive*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_dxilnow panics on dxc spawn or write failures instead of returningNone, and thecfg(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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:26:32Z.
Automated triage for the maintainers.
Lower::mark_memory_bitincrates/victory-shader/src/emit/lower.rsnow 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,waveActiveBitOR,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 inLower::memoryrun 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. Thecfg(all(test, windows))and test-import changes inemit/mod.rsare unrelated cleanups. CI:checkpassing. This is a recommendation for a maintainer to look, not an approval.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Anzymanz on 2026-11-26T00:17:15Z.
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, bothXboxBvhBuilder.dllcompute programs that write title memory:28918b7150a7aad5goes from 0.77 to 0.57 ms per dispatch,caa78b8ca62bc3d6stays 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://github.com/Marvisak/VIctory/pull/2804#issuecomment-7178595888Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:08:24Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib title_page_marks: 2 passed, 0 failed (title_page_marks_use_wave_ops_and_guard_the_atomicandtitle_page_marks_keep_every_lanes_bit).cargo test -p victory-shader --lib emit::memory_tests -- --skip heap_direct_texture_reads_mark_their_heap_index: 4 passed, 0 failed (RTX 5090 hardware + WARP).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:53:24Z.
Review: APPROVED
LGTM — the wave-coalesced dirty-bitmap marking in
mark_memory_bit(crates/victory-shader/src/emit/lower.rs:4721-4774) is sound:begin_guarded,waveActiveAllEqual,waveActiveBit(OR), andwaveIsFirstLanerun over the currently active non-helper lanes at any wave size (verified via custom HLSL+D3D12 probes on both RTX 5090 Wave32 and WARP Wave4 covering inactive lane 0, divergent branches/loops, same-word vs mixed-word multi-page writes, 64 KiB / 256 MiB / 4 GiB boundary straddles, and pixel coverage/discard — zero missed bits).atomicBinOponly when(old & mask) == maskon a monotonically accumulating dirty bitmap guarantees any staleraw_dwordload can only cause a harmless redundant OR, never a missed dirty mark.title_page_marks_*(2/2 on RTX 5090 and WARP),memory_tests(5/5 on WARP; 4/5 on RTX 5090 with only the pre-existingheap_direct_texture_reads_mark_their_heap_indexbaseline failure),clippy(--all-targetsand--all-features), andxtask policyall pass.(Minor non-blocking polish:
rustfmt --edition 2024 --checkflags line wrapping on three lines in the new tests atcrates/victory-shader/src/emit/mod.rs:1677,:1737, and:1748.)Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-27T11:55:41Z.
@brainbudt, a hardware measurement for this PR on an RTX 2080 (Windows 10, 32-lane waves), with GTA VI's console BVH builder (
XboxBvhBuilder.dll). Its compute programs write nothing but title memory, and several are console wave64 programs that run split into two 32-lane halves here, so this covers the case the triage note says wasn't tested.Setup. Same tree, same dump and same settings (
VICTORY_GPU_TIMING=1), three builds:347a399) merged as is;mark_lead, after a load that finds the bit clear), which I'll drop in favour of this PR.Builder time in its first list of about 3,350 builder commands:
Per dispatch, before → this PR:
e63d22c4(radix pass, 512 threads, console wave64): 63.3 → 0.21 msf28a33a8: 2.18 → 0.42 ms6f6a359d: 1.97 → 0.016 msf6e47efa: 1.33 → 0.084 msBefore, a builder frame passed the driver's timeout on its own. The bitmap is a shared buffer in system memory, so each store's atomic crossed the bus.
The device is still lost later in the builder's first frame, with this PR, with my variant and without either. That's a separate hang I'm tracking on #2703. So I can't vouch for the trees' contents end to end yet. With this PR merged, the radix pass's local test (
one_container_radix_pass_matches_its_referenceonlhnizdo:diag/bvh-builder; the real container, 2,048 keys and values sorted at two digit positions, through title memory) passes on the 2080, and so domemory_tests.AI-assisted (Claude Code). No game data.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.