Shaders: coalesce title-memory dirty marks within a wave #2755
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!2755
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@brainbudt on GitHub · 2026-11-25 19:45 UTC · original
brainbudt:perf/shader-wave-dedupe-marks→main· +194 −20 · 2 files · 1 commits · openLanes 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).
@fuzeofficlal on GitHub · 2026-11-25 20:04 UTC · original
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.@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.
@oni-swr on GitHub · 2026-11-25 20:16 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 23:26 UTC · original
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
@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, 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: #2804View 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.