GPU: back shadow buffers, page tables, and dirty bitmaps in VRAM on discrete GPUs #3312
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!3312
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3312"
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?
@danielibabet on GitHub · 2026-11-26 17:03 UTC · original
danielibabet:pr/vram-default-buffers→main· +633 −49 · 3 files · 1 commits · openSummary
Addresses part of #3028 on discrete GPUs where
GPUUploadHeapSupportedisfalse(e.g., NVIDIA RTX 4070 / Ada Lovelace without ReBAR enabled).Root Cause
On discrete GPUs without
GPUUploadHeapSupported,Host::shared_buffer(D3D12_HEAP_TYPE_CUSTOM,WRITE_BACK,MEMORY_POOL_L0) andHost::upload_buffer(MEMORY_POOL_L0) place all shadow buffers, title-memory page tables, and atomic dirty-page bitmaps in system RAM over PCIe. Every shader buffer load, UAV store, page-table lookup, andInterlockedOratomic crosses the PCIe bus instead of hitting local GDDR6X / L2.Changes
host.rs:Host::is_uma()(D3D12_FEATURE_ARCHITECTURE) andHost::vram_shadow_budget()(25% of localDXGI_MEMORY_SEGMENT_GROUP_LOCALbudget on discrete GPUs so streaming textures are not evicted).Host::default_uav_buffer(), reusable 64 MiBUPLOADring (upload_vram_copies), and reusable 32 MiBREADBACKring (readback_vram_copies) synchronized viarun_copy_list.memory.rs:Shared::table(title-memory page table) andBitmap(title-memory dirty-page bitmap) withdefault_uav_bufferon discrete GPUs, synced pre/post submission viaCopyBufferRegion.shadow.rs:shadow::bitmap(VIEW_WRITES/VIEW_READS) withdefault_uav_bufferon discrete GPUs.Shadowallocations (find,loose,Arena) up tovram_shadow_budget()(<= 128 MiBper allocation) inD3D12_HEAP_TYPE_DEFAULTVRAM with demand-committedCpuMem(alloc_zeroed) instead of duplicatingL0D3D12 resources, falling back cleanly toshared_bufferonce the VRAM budget is reached or on UMA/WARP adapters.Measured Results (NVIDIA RTX 4070 12 GB, Windows 11, i9-14900KF)
VICTORY_GPU_TIMING=1) with VRAM-backed shadow buffers + page tables/bitmaps:on the GPU(5.1k–5.3k draws/frame): ~405–417 ms -> ~285–323 ms (total frame time ~545 ms -> ~440 ms).Verification
cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views: 229 passed, 0 failed (the 2 skipped tests requireHEAP_VIEWS <= 1_000_000or WARP on this NVIDIA driver; tested separately on WARP in PR #3218).cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings.cargo run -p xtask --locked -- policy: asset policy: 191 files ok.@Dukestar69 on GitHub · 2026-11-26 17:07 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 with a discrete NVIDIA RTX 5090 (
is_uma() == false, exercising the VRAM-backed shadow buffers, page tables, and dirty bitmaps path):cargo test -p victory-gpu --lib shadow:: -- --test-threads=1(RTX 5090): 10 passed, 0 failed.cargo test -p victory-gpu --lib memory::tests:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views(RTX 5090): 7 passed, 0 failed (pre-existing #1744 test skipped).cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 20 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 20:58 UTC · original · requested changes
Moving hot shadow buffers, page tables, and dirty bitmaps into
DEFAULTVRAM on discrete GPUs (!is_uma()) while keeping UMA/APU/WARP on shared memory is a great direction, and theclippy/policychecks and WARP (UMA=true) suite pass cleanly.Testing on a discrete GPU (
NVIDIA GeForce RTX 5090,UMA=false,vram_shadow_budget=8,236,302,336bytes,VICTORY_D3D12_DEBUG=1) versus WARP (UMA=true) and probing an integrated GPU (AMD Radeon(TM) Graphics,UMA=true) uncovered four blocking correctness/synchronization bugs on the discrete VRAM path:1. Silent data loss for marked-page UAV writes (
VIEW_WRITES) into VRAM shadows (crates/victory-gpu/src/host.rs:1315-1339)Host::executeonly schedules VRAM ->CpuMemreadbacks for explicitStep::GpuWriteentries before runningshadow::copy_back_marks. Any shader write through a heap/bindless/marked UAV that sets a bit inVIEW_WRITESwithout a matchingStep::GpuWriteleavesShadow::data(CpuMem) holding the old pre-GPU bytes;Shadow::copy_back_markedthen compares staleCpuMemagainst title memory and writes back zero bytes.0x1337c0deinto a VRAM shadow and setting itsview_writes(false)bit:is_uma=false):gpu_word=0x1337c0de,title_word=0x00000000(write lost).is_uma=true):gpu_word=0x1337c0de,title_word=0x1337c0de.2. Silent data loss for title-memory shader writes via the page table (
crates/victory-gpu/src/host.rs:1315-1339,crates/victory-gpu/src/memory.rs:689-691)Similarly, shaders writing through the title-memory page table mark pages in
map.dirty(noStep::GpuWrite), andmemory::bind'sdefer_afterclosure callscopies[k].copy_back_page(at). Because those dirty pages are never copied back from VRAM intocopies[k].data(CpuMem) aftersync_vram_postreads back the dirty bitmap,copy_back_pagesees unchangedCpuMemand writes nothing to title memory. (Existing testa_submission_that_missed_leaves_the_copies_at_oncedid not catch this because its non-missed branch only checked GPU-sideread(), not CPUtitle().)memory::tests::WRITEshader storing0xcafef00dthrough the page table:is_uma=false):gpu_word=0xcafef00d,title_word=0x00000000(write lost).is_uma=true):gpu_word=0xcafef00d,title_word=0xcafef00d.3. Global
ACTIVE_BITMAPS.drain(..)drops dirty/missed bitmaps across separate submissions (crates/victory-gpu/src/memory.rs:205, 239-254, 695-703)memory::bindpushes(vram, ram)into the process-globalACTIVE_BITMAPSat record time, andsync_vram_postdrains the entire vector on whicheverHost::executeruns next:L1andL2are both recorded withmemory::bindand submitted separately (host.execute(&[&L1])thenhost.execute(&[&L2])), submittingL1drainsL2's bitmap too. WhenL2later executes, its VRAM dirty bitmap is never zeroed beforeL2and never copied back to RAM afterL2, silently dropping bothL2's missed-region withholding and its page writebacks.ACTIVE_BITMAPSstill holds clones of a bitmap already returned toBITMAP_POOL.L1andL2(L2setting region-1 missed bit inmap2.dirty), then executing[&L1]followed by[&L2]:is_uma=false):missed_regions_delta=0(L2's miss completely lost).is_uma=true):missed_regions_delta=1.(vram, ram)bitmap pair with the specificHostList(Deferred) rather than a global vec, and only zero/read back the bitmaps belonging toruns.4.
ID3D12CommandAllocator::Resetcalled while previous copy list is still executing (crates/victory-gpu/src/host.rs:2861, 2959-2970, 2983-3017)upload_vram_copiessubmits its finalflush(..., wait = false)onstatic CMD's single(alloc, list)without signaling/waiting on a fence, andrun_copy_listunconditionally callslet _ = alloc.Reset();on the next call (also discardingReset/CloseHRESULTs). This immediately violates D3D12 allocator lifetime rules whenever another copy runs before the previous GPU submission finishes (e.g.,Shadow::read_host/write_hostcallingflush_test_vram_uploads()immediately followed bytest_readback_buffer/test_upload_buffer, orHost::execute(&[])).VICTORY_D3D12_DEBUG=1: callingsh.copy(...)+sh.read_host(...)produced 16/16 D3D12 Debug Layer errors:ID3D12CommandAllocator::Reset: A command allocator ... is being reset before previous executions associated with the allocator have completed.(0/16 on WARP).flush_test_vram_uploads(host.rs:2963-2967), falling back tolet mut dummy = 0u64;whenself.submitted.try_lock()fails can signal the monotonicself.fenceto1while the fence is already past1, causingSetEventOnCompletion(1, ...)to return immediately without waiting.Additional notes
crates/victory-gpu/src/shadow.rs:970-975,host.rs:2798, 2867):has_vram_bitmaps()callsbitmap(false)andbitmap(true)on everyHost::execute, eagerly allocating both bitmaps on the first submission and forcing bothupload_vram_copiesand a second synchronousreadback_vram_copies+ fence wait on every single submission on discrete GPUs even when no shader uses view write marks or VRAM shadows. Consider checking whether eitherOnceLockis actually initialized (and whether the submission used view marks/reads) instead.crates/victory-gpu/src/shadow.rs:133-157):try_vram_shadowchecksVRAM_BYTES.load(Relaxed) + size > budgetbeforefetch_add(non-atomic TOCTOU across threads), and ifCpuMem::new(size)fails at line 154,VRAM_BYTESis never decremented. Also noteShadow::peek(underdiagnostics) still readsself.datawithout a VRAM readback.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.