GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u250) #849
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!849
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-849"
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?
@Starchaser1024 on GitHub · 2026-11-28 07:42 UTC · original
Starchaser1024:feat/gpu-dirty-bitmap→main· +5297 −214 · 27 files · 3 commits · closed without mergingSummary
Implements the GPU-side dirty-page bitmap noted at
shadow.rs:3444and discussed in #756, eliminating the full-range CPU snapshot (Shadow::before, up to 174 MiB per submission) and full-range CPU diff scan (find_all) on non-cardedShadowbuffers while removing whole-copy snapshot lock contention across overlapping flights.Design
SLOT_DIRTY = 251,256 KiB):SLOT_DIRTY = 251(u251inROOT_CBV_SPACE,DIRTY_WORDS = 65_536dwords =256 KiB) covering all2^21(2,097,152) 64 KiB pages below128 GiB.(addr >> 16) & (MEMORY_PAGES - 1)handles overlapping sub-views of the 174 MiB world heap at arbitrary offsets and multi-buffer dispatches in one bitmap without ambiguity.crates/victory-shader/src/emit/dirty.rs):buffer_store_*(dword..dwordx4,byte,short,format,format_d16),buffer_atomic_*(32/64-bit, includingcmpswap),global_store_*, andglobal_atomic_*(excluding image UAVs andSLOT_FAULTS).Source::Built):USER_ROOT_ADDRESS+ signed constant/dynamic offset + unbiased byte offset (withoutUSER_VIEW_BIAS, sinceUSER_ROOT_ADDRESSalready holds the unaligned low bits), guarded by non-zero base.Source::Loaded):USER_VIEW_ADDRESS+ byte offset (usingSLOT_TABLE_STRIDESelement byte size for typedbuffer_store_format_*), guarded bygetDimensions(opcode 72) and non-zero view address so OOB or null-view stores dropped by hardware never mark pages dirty.SLOT_MEMORY/ spilledroot_memorystores: 40-bit title address guarded by writable page mapping (page_there & !closed).p0 = start >> 16andp1 = (start + bytes - 1) >> 16, coalescing into oneatomicBinOp.i32(Or) when(p0 >> 5) == (p1 >> 5)and emitting a guarded second atomic only across 2 MiB word boundaries.ResourceHeapUAVs or shaders whose root signature withu251+USER_*_ADDRESSwould exceed the D3D12 root-dword budget (64forCs,32per stage forVs/Ps/Ms) cleanly rerun lowering withoutSLOT_DIRTY(HostShader::dirty_tracked = false).DirtySlot& sparse per-pieceDirtyBefore(crates/victory-gpu/src/dirty.rs,shadow.rs,host.rs,draw.rs):HostListlazily acquires a zeroed256 KiBDirtySlotfromdirty::POOLwhen bindingu251and recycles it onreset,Drop, andFlightlanding (zeroing only non-zerou64words).DirtyBeforekeeps a sparse per-64KiB-piece baseline with per-piece locks across waited,relay_merge_dirty,land_dirty, andmerge_under_writes(VICTORY_LATE_WAIT=2) paths, preserving dword-exact merge when CPU/DirectStorage and GPU write different dwords of the same 64 KiB page while taking0snapshot bytes duringShadow::writing_with(..., true).Shadow::snapshottedandShadow::outside.VICTORY_DIRTY_BITMAP(default on, included inshader_cachebuild key andHostShadercache serialization;=0falls back toShadow::before) andVICTORY_DIRTY_CHECK=1(runs bothbeforeandSLOT_DIRTYand verifies zero missed pieces).Benchmark & Verification (RTX 5060 Ti 16 GB, Windows 11)
dirty::tests::bench_174mb_non_carded_shadow_dirty_bitmap_vs_before(174 MiB/0x0AE0_0000non-cardedShadow,11overlapping sub-view declarations per submission,2compute dispatches touching8dirty 64 KiB pages,6measured rounds after warm-up):VICTORY_DIRTY_BITMAP=0(Shadow::before+find_all)VICTORY_DIRTY_BITMAP=1(SLOT_DIRTY+DirtyBefore)--release15.681 msmean)0.114 msmean)-15.55 ms/ submission)debug15.976 msmean)0.427 msmean)cargo test -p victory-shader --locked: 303 passed, 0 failed (5 newdxil.dll+ RTX 5060 Ti + WARP execution tests inemit::dirty_testscovering overlapping sub-views, cross-64KiB-page and cross-2MiB-word stores, OOB drops, narrowbyte/short+ atomics, unaligned root UAVUSER_VIEW_BIAS,SLOT_MEMORYread-only/unmapped guards, and root-budget/bindless fallbacks).cargo test -p victory-gpu --locked: 458 passed, 0 failed (5 new tests indirty::testsincluding concurrent CPU+GPU same-page preservation,VICTORY_DIRTY_CHECK=1zero-missed-piece verification, mixed tracked/untracked +relay+landpaths, and the 174 MiB benchmark).cargo clippy --workspace --all-targets --all-features --locked: 0 warnings in all new and modified files.cargo xtask policy: 297 files ok.@shiman1901 on GitHub · 2026-11-28 13:43 UTC · original
@Starchaser1024 Huge props for building this out so cleanly — 141.8x on the 174 MiB repro with 761 passing tests and the unified 256 KiB address-space map is an awesome design!
Saw @465d6a0eac's note below that
#849dropped a livefps-prsrun to 1.8 FPS ("submitting thread waits for flights"), so we audited commit759e1893to find why the hot path was blocking. Found a concrete smoking gun indirty.rs+host.rsthat doesn't show up in unit tests / microbenches (which only use 1 list, not 632 live lists):Why live gameplay stalls on
victory-submit(1.8 FPS)WaitForSingleObject(INFINITE)insidedirty::acquire():HostList::dirty_gpu()->dirty::acquire()callshost.shared_buffer_now(256 KiB)->Host::mapped()(host.rs:313-315) -> synchronousWaitForSingleObject(event, INFINITE)right on thevictory-submitthread.clone()instead oftake():dirty_slots_of(runs)cloneslist.dirty_slot(), whileHostList.dirtykeeps holding its ownArc<DirtySlot>untilHostList::reset()(which sits behindbury_lag = 16/64and the 512 idle-list pool). So when aFlightlands and callsdirty::release(),Arc::try_unwrapfails and the slot is NOT returned to the pool.POOL_MAX = 128vs ~632 live host lists (host.rs:780-781): Even when lists eventually reset, any slot beyond 128 is dropped instead of recycled — so every frame forces freshshared_buffer_now->Host::mapped()stalls (plus ~158 MiB across 632 × 256 KiB buffers).picked.writtenathost.rs:6225still calls the oldshadow.writing(...)rather thanwriting_with(..., false)— worth checking so mixed tracked/untracked submits don't unexpectedly snapshot 174 MiB.Minimal fix to unblock live testing
VICTORY_DIRTY_BITMAPopt-in (default 0) until live-validated withVICTORY_DIRTY_CHECK=1.take()the slot out ofHostListon submit soFlightis the sole owner andtry_unwrapsucceeds immediately on landing (or even better, assign one slot per Flight/submission rather than perHostList, which drops peak concurrent slots from ~632 down to ~16–32!).mapped()on the hot path: either pre-allocate a single shared buffer (e.g.N × 256 KiBsuballocated by GPU VA offset, mapped once inHost::new— zeroWaitForSingleObjectever!) or pre-warm the pool without discarding slots above 128, and haveacquire()returnNone(graceful fallback to untracked) if exhausted instead of callingshared_buffer_now().With that hot-path
mapped()stall removed,#849should actually deliver that microbench speedup in live gameplay without touching the submitting thread!@Starchaser1024 on GitHub · 2026-11-28 15:31 UTC · original
Huge thanks @shiman1901 (and @465d6a0eac for the live
fps-prsrun)! That root-cause audit nailed the exact mismatch between single-list microbenches and 632 liveHostLists in gameplay:dirty_slots_ofclonedHostList.dirty, soHostListheld onto a secondArc<DirtySlot>acrossbury_lag(16..64 submissions) and the 512-entrylist::IDLEpool — causingArc::try_unwrapinsidedirty::releaseto fail on everyFlightlanding (and waited submissions didn't release immediately afterhand_backeither).POOL_MAX = 128dropping anything past 128 on eventualreset(),dirty::acquire()fell through toshared_buffer_now(256 KiB)->Host::mapped()-> synchronousWaitForSingleObject(INFINITE)on the submitting/recording path every frame.Fixed in
481afd8:VICTORY_DIRTY_BITMAP=1(default0) + pre-warmed cache compatibility: off by default until live A/B numbers confirm the win, andshader_cacheonly hashesVICTORY_DIRTY_BITMAP=1when enabled (matchingVICTORY_EARLY_DEPTH=1) so existing pre-warmed caches stay untouched on default runs.16 MiBslab sub-allocator (64 × 256 KiBper slab, up to16slabs =1,024slots, zero eviction) + non-blockingsink_gpu()fallback: oneshared_buffer_now(16 MiB)populates 63 usable slots + permanent sink slot 0 at once,release()never drops slab slots, and if all slabs are ever simultaneously checked outacquire()returnsNonewithout blocking whileHostList::dirty_gpu()bindssink_gpu()and falls back cleanly toShadow::before(dirty_overflowed, zero dropped draws, zeroWaitForSingleObject).HostList::take_dirty_slot):dirty_slots_ofmoves theArc<DirtySlot>out ofHostListon submit (strong_count == 1), releasing immediately afterhand_backon waited submits and succeedingArc::try_unwrap100% of the time onFlightlanding without waiting forbury_lagorlist::IDLE(Shadow::writingonpicked.writtenalready delegates towriting_with(..., false)).Verified on RTX 5060 Ti (
--release) with a new 650-live-HostListstress test (dirty::tests::six_hundred_fifty_live_lists_recycle_slots_on_landing_without_stalls: 650 liveHostLists, 784 list executions across asyncVICTORY_RELAY=1Flights while holding 512 submittedHostLists un-reset in a simulatedBURY/IDLEqueue):slabs_allocated == 1(1 × 16 MiBslab total across the entire 784-execution run,0slab allocations /0mapped()waits after submission 0), completing all 784 executions +DirtyBeforemerges in 53.5 ms total (0.068 ms/list).Ready for live A/B re-testing with
VICTORY_DIRTY_BITMAP=1(andVICTORY_DIRTY_CHECK=1)!@shiman1901 on GitHub · 2026-11-28 15:34 UTC · original
@Starchaser1024 That turnaround is awesome — 1 slab across 784 async executions with 650 live lists, 0
mapped()stalls after submission 0, and0.068 ms/listis super clean! Love thesink_gpu()non-blocking fallback and keeping pre-warmed caches intact whenVICTORY_DIRTY_BITMAPis off.@465d6a0eac if you get a chance to re-test
481afd8on top offps-prswithVICTORY_DIRTY_BITMAP=1(andVICTORY_DIRTY_CHECK=1), curious to see how it holds up in live gameplay now that themapped()stall is gone!@wojtek2407 on GitHub · 2026-11-28 18:42 UTC · original · edited 2026-11-28 19:12 UTC
Test report for #849 at
481afd8, with two follow-up patches (happy to push them as a branch if you want them).Hardware: RTX 4070 SUPER 12 GB (driver 610.88, Resizable BAR on,
GPUUploadHeapSupported), i5-12400F, Windows 11 26200. Title build v1.0.2.1, launched withscripts/play-foxhound.ps1: Series X profile, 2560x1440, DLSS Quality, no F1 settings file. Standing still at one spot in the boat mission. Numbers are medians of the frame-rate lines over the last ~75 s of each run, after the pipeline queue was empty.481afd8withVICTORY_DIRTY_BITMAP=1: ~2.4 fps, then a crash63b902f481afd8, bitmap onThe CPU side is fine. The card is saturated. The title crashed after ~3.5 min (
VCRUNTIME140.dll+0x1cc66, read of0x0). I did not establish whether the crash came from the bitmap or from running at 2 fps.Probable cause:
emit/dirty.rsemits oneatomicBinOpOR per lane per store, and the slabs live in PC memory (shared_buffer_now: CUSTOM, WRITE_BACK, L0), so every one of those atomics crosses PCIe.Patch 1: one atomic per wave (
VICTORY_DIRTY_WAVE, on by default, part of the shader-cache key)The lanes that hit the same dword as the first active lane OR their masks with
waveActiveBitand send a single atomic. The other lanes still send one each. Pixel shaders keep one atomic per lane, because a helper lane could be the first lane and its UAV writes are dropped. New test: 64 lanes, each writing a page of its own, split across two bitmap dwords, checked on the hardware and on WARP, plus the SFI0 wave-ops flag.Result: 16.6 fps, CPU preparing 24.8 ms, card 90 % busy.
Patch 2: slabs in card memory, counters, and the card compare
VICTORY_DIRTY_VRAM(on by default with the bitmap) allocates the slabs withmapped_card_buffer(…, true)(GPU_UPLOAD) when the driver supports it. CPU reads go through the BAR and are uncached, so a released slot is cleared whole with plain stores and never read. Result: 22.9 fps, the same as without the bitmap.Shadow::beforeonly for copies in PC memory. In this title nearly all written buffers are copies in card memory, and those are compared on the card (CARD_COMPARE, ~6,300 pieces of 64 KiB a frame).VICTORY_DIRTY_CARD=checkcompilesCARD_COMPAREwithDIRTY_CHECK. It joins the submission's slots on the card and counts, per piece, whether the page's bit was set and whether the piece changed. Measured over 160 frame-rate lines:VICTORY_DIRTY_CARD=1skips reading and hashing pieces that have no bit in clean ranges. The walk is empty, so the barrier stays uniform: an early return beforeGroupMemoryBarrierWithGroupSyncfailed FXC.differsis set to 0 and the hash is kept. Skipping is off whileVICTORY_FETCH_CHECKis on. A/B with bitmap only vs bitmap plus skip: 22.7 / 22.2 vs 22.1 / 21.9 fps, 92 % of clean pieces skipped, no crash. There is no gain because the submitting thread (~43 of ~45 ms) bounds the frame, not the card.Tests:
cargo test --release --locked -p victory-shader --lib: 299 passed, 5 ignored.-p victory-gpu --lib: 461 passed, 36 ignored (once,watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_viewfailed in a full run and passed 5/5 alone). New WARP test for the counting and skipping compare.Not tested: AMD, cards without GPU_UPLOAD, Series S, moving or dense scenes, scenes bound by the card (where the skip should matter),
VICTORY_DIRTY_CHECK=1in game.AI use: Claude Code (Claude Opus 5.5) wrote both patches and this report, and diagnosed the PCIe atomics. The runs were made on the PC above; the numbers come from their logs.
GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u251)to [pr-performance][memory][shaders][NVIDIA] GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u251)[pr-performance][memory][shaders][NVIDIA] GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u251)to GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u251)GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u251)to GPU, shaders: track shader buffer writes in a 64 KiB dirty-page bitmap (u250)481afd8d05to37c2f61960@Starchaser1024 on GitHub · 2026-11-29 02:36 UTC · original
Huge thanks @wojtek2407 for that phenomenal live-gameplay diagnosis and A/B test report on RTX 4070 SUPER (and confirming 0.00 missed pieces across ~1,000,000+ pieces / 92% clean
CARD_COMPAREpieces in live play)!Rebased onto current
main(0338ec6, movingSLOT_DIRTYto250/u250alongside upstreamSLOT_SAMPLED = 251andSLOT_MEET = 252) and integrated all three upgrades in37c2f61:VICTORY_DIRTY_WAVE, default1whenVICTORY_DIRTY_BITMAP=1, registered inshader_cache::ELSEWHERE):waveReadLaneFirst.i32+waveActiveBit.i32(Or) +waveIsFirstLane, leaving only lanes on a different dword to issue individual atomics, while pixel shaders preserve per-lane atomics so quad helper lanes cannot drop UAV stores.GPU_UPLOADVRAM slabs + telemetry (VICTORY_DIRTY_VRAM, default1):16 MiBslabs viamapped_card_buffer(SLAB_BYTES, true)(D3D12_HEAP_TYPE_GPU_UPLOAD) when supported so shader atomics stay in local VRAM L2 instead of crossing PCIe, clearing released VRAM slots with pure write-combining stores (write_bytes, zero uncached BAR reads) and falling back automatically toshared_buffer_nowwhenGPU_UPLOADis unavailable.dirty::line) counting tracked/untracked declarations, MiB not snapshotted, pieces merged,CARD_COMPAREclean pieces skipped, and sink fallbacks.VICTORY_DIRTY_CARD(=1clean-piece skip,=checkaccuracy counter; off whenVICTORY_FETCH_CHECKis on):DirtySlots on the GPU (DIRTY_MERGE,cs_5_1) whendirty_slots.len() > 1(or binds the single slot directly asSRV(t1)), marks aCardRangeeligible only when all writes to that copy in the submission are tracked, and setssteps = 0insideCARD_COMPAREfor clean pieces while keepingGroupMemoryBarrierWithGroupSyncuniform (preserving stored baseline hashes without FXC early-return errors).Verified on RTX 5060 Ti 16 GB + WARP +
dxil.dll+ FXCcs_5_1(399victory-shader+597victory-gpulib tests passing):ShadowCARD_COMPARE(4,096pieces,8dirty):1.085 ms->0.283 ms(3.83xspeedup) withVICTORY_DIRTY_CARD=1, and0missed pieces underVICTORY_DIRTY_CARD=check(including skewed+0x4008copies and 6-listDIRTY_MERGE).Shadow(11overlapping views,8dirty pages):15.914 ms->0.226 ms(70.4xspeedup) withVICTORY_DIRTY_WAVE=1+GPU_UPLOADVRAM slab.Pull request closed