gpu: move shadow buffers to DEFAULT VRAM with pooled staging transfers #693
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!693
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-693"
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?
@wbkepler on GitHub · 2026-11-24 06:57 UTC · original
wbkepler:gpu/default-vram-shadow-buffers→main· +1316 −280 · 3 files · 2 commits · openSummary
Moves registered and loose
Shadowbuffers from CPUWRITE_BACKL0 system RAM to GPU-localD3D12_HEAP_TYPE_DEFAULTVRAM (withALLOW_UNORDERED_ACCESS) inhost.rsandshadow.rs:Host::default_buffer,Host::readback_buffer, and a reusable 4 MiBStagingArena(capped at 4 pooled chunks; oversized allocations transient) for dirty 64 KiB page upload staging and pre/post-submission GPU-write readback snapshots.COPY_DEST -> COPY_SOURCEbarriers andCOMMONdecay betweenExecuteCommandListscalls.merge_rangesand merges only GPU-modified bytes into title memory viacopy_back_rangewhile preserving concurrent CPU writes.Verification
cargo clippy --workspace --all-targets— passed (zero new warnings)cargo clippy -p victory --features diagnostics --all-targets— passedcargo test --workspace— passed (hardware GPU)VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib shadow— passed (3/3)VICTORY_D3D12_DEBUG=1clean on both hardware GPU and WARPcargo xtask policy— passed (151 files ok)Allocate `Shadow` host copies of title buffers in GPU-local VRAM (`D3D12_HEAP_TYPE_DEFAULT`) instead of CPU-visible `WRITE_BACK` L0 system memory, eliminating PCIe reads on every shader buffer access. - `crates/victory-gpu/src/host.rs`: - Add `Host::default_buffer` (`D3D12_HEAP_TYPE_DEFAULT`, `ALLOW_UNORDERED_ACCESS`, initial state `COMMON`) and `Host::readback_buffer` (`D3D12_HEAP_TYPE_READBACK`, mapped). - Add a reusable `StagingArena` (4 MiB pooled chunks, capped at 4 chunks; oversized allocations released per submission) for both `UPLOAD` and `READBACK` shadow transfers. - Record dirty-page `CopyBufferRegion` uploads (and pre-submission `before` readback snapshots when shaders write a buffer, with `COPY_DEST -> COPY_SOURCE` barriers where needed) onto a dedicated upload prelude list, and post-submission `after` snapshots onto a dedicated readback list. Separate `ExecuteCommandLists` calls on the same queue let default-heap buffers implicitly decay to `COMMON` between phases with a single fence wait. - `crates/victory-gpu/src/shadow.rs`: - Allocate registered and loose `Shadow` buffers via `Host::default_buffer`, removing CPU-mapped `data` and `before` snapshot pools. - Stage dirty 64 KiB write-watched pages into pooled `UPLOAD` staging memory (`UploadCopy`). - Add `merge_ranges` to coalesce overlapping/adjacent GPU-write ranges per submission and `Shadow::copy_back_range` to merge only GPU-modified bytes into title memory while preserving concurrent CPU writes (leaving concurrently CPU-modified pages dirty so the next submission uploads them back to VRAM). - Add unit and live D3D12 (hardware + WARP, debug layer) tests verifying range coalescing, `DEFAULT` heap allocation, dirty-page staging with zero-copy on clean pages, GPU UAV readback merge, and concurrent CPU write preservation.@justr4mzi on GitHub · 2026-11-24 09:21 UTC · original
Tested PR #693 (
ae39e9c1) merged cleanly on currentmain(02f404e) on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2) and Rust 1.98.1 (x86_64-pc-windows-msvc), againstmain(02f404e) as negative control.Test results (
victory-gpu)main(02f404e,--test-threads=1):49 passed, 0 failed, 1 ignored(with--features diagnostics:52 passed, 0 failed, 1 ignored).ae39e9c1, default parallelcargo test -p victory-gpu):52 passed, 0 failed, 1 ignored(including all 3 newshadow::tests::*).ae39e9c1, sequentialcargo test -p victory-gpu -- --test-threads=1): fails (51 passed, 1 failed, 1 ignored; with--features diagnostics:54 passed, 1 failed, 1 ignored):watch::tests::written_pages_are_reported_to_every_askerpanics atcrates/victory-gpu/src/watch.rs:306(assertion failed: before.is_empty()).written_pages_are_reported_to_every_askerin isolation passes (1 passed).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy:152 files ok.Why
--test-threads=1failsIn
shadow::tests(which run alphabetically beforewatch::testsunder--test-threads=1),WatchedAllocallocates withMEM_WRITE_WATCHand triggerswatch::writes(...), inserting those page numbers intowatch::JOURNAL.WatchedAlloc::dropfrees the pages viaVirtualFree(..., MEM_RELEASE)without clearingwatch::JOURNALentries for that range. Windows then reuses the same virtual address forwatch::tests::written_pages_are_reported_to_every_asker, so its initialwrites(start, end, false)sees staleJOURNALentries fromshadow::testsand failsbefore.is_empty(). (More broadly, if title allocations are freed and reallocated at the same VA,watch::JOURNALwould carry stale write records unless cleared on free.)No game data included; the title itself was not launched. AI-assisted test execution and root-cause analysis (reviewed locally).
@geiyiliyabumo on GitHub · 2026-11-24 09:21 UTC · original
Tested
ae39e9c14merged withmain(8e79c80, clean merge) on Windows 11 Pro (26100), Rust1.98.1(x86_64-pc-windows-msvc), AMD Radeon RX 9060 XT (RDNA4, driver32.0.32029.2010): PASS (with two non-blocking code-review notes below).Verification
cargo xtask policy→asset policy: 153 files okcargo clippy --workspace --all-targets --locked -- -D warnings→ pass (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings→ pass (0 warnings)cargo test --workspace --locked→ 314 passed, 0 failed, 6 ignored (all 3 newshadow::tests::*pass on RX 9060 XT)VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib --locked shadow→ 3 passed, 0 failed on RX 9060 XT (0.17s), zero debug-layer messagesVICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib --locked shadow→ 3 passed, 0 failed on WARP (0.11s), zero debug-layer messagesCode-review notes
>4 MiBshader-written ranges (host.rs,StagingArena::alloc/reset): oversized allocations (alloc_len > STAGING_CHUNK, 4 MiB) are pushed toself.transientand dropped every submission. BecauseReadbackPlanallocates bothbeforeandafterreadback buffers per coalesced GPU-write range, any world pass writing into a large heap (>4 MiB; the removedPOOLcomment inshadow.rsnoted the 174 MiB heap previously hit ~2.3M page faults/frame without reuse) willCreateCommittedResource+Mapand release two largeREADBACKbuffers on every submission. Keeping a small capacity-reused slot for oversized readback/upload buffers (or raising/pooling a large chunk) would avoid that churn on world frames.copiedtimestamp if staging allocation fails (shadow.rs,copy_stale→stage):copy_staleadvancescopied[page - base] = nowbefore callingself.stage(...). Ifalloc(len)returnsNone,stagereturns0without pushing anUploadCopy, leaving those pages marked up-to-date so subsequent submissions will not retry uploading them.AI-assisted; synthetic tests only, no game files (world runtime perf not measured).
@DeerSilver on GitHub · 2026-11-24 11:01 UTC · original
Tested head
ae39e9cmerged ontomainffe310e(clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: pass. No game files: the test suite only.merge_ranges_coalesces_overlapping_and_adjacentdefault_vram_shadow_uploads_only_dirty_pagesgpu_writes_readback_merges_and_preserves_concurrent_cpu_writescargo test --workspace --locked: 345 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored onmain.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@SAitken91 on GitHub · 2026-11-24 14:56 UTC · original
In-game results for #693 on an RX 6950 XT (RDNA2), Windows 11,
diagbuild withVICTORY_D3D12_DRED=1, scripted input into the first mission. Basemainffe310e+ #693 + #687 + #635 + my open shader PRs, plus the PRs noted per run.8e79c80)shadow readback staging(8 entries)shadow readback staging0x887A0006), no page faultVICTORY_SHADER_LOOP_LIMIT=1000shadow readback stagingFor comparison, the same base without #693 (with #609) ran out of memory after ~13 s in one run and didn't get past the menus with scripted input in two others.
The recurring
shadow readback stagingentries in the "inside freed" lists look like a pooled readback staging buffer being released or recycled while a submitted list still uses it. #575 (release behind the queue) covers descriptor slots and title-buffer shadow copies, not this pool, and #609/#431 don't merge with this PR as they stand. Happy to rerun a newer head on this card; logs available.@ordis-labs on GitHub · 2026-11-24 15:28 UTC · original
In-game A/B of this PR on Windows 10 19045, RX 6700 XT (driver 32.0.21045.29003),
diagbuild,VICTORY_D3D12_DRED=1, identical scripted input. Base = mainffe310e+ #175 (needed on Windows 10). Two runs each, alternating A/B/A/B. Averages over the world phase:shadow readback staging/shadow upload staging0x887A0006), no page faultAt comparable load (base run 2 vs both #693 runs), frames are about 2x slower, GPU time is 5–7x higher, and copy time doesn't drop, so on this machine it's a regression. The freed
shadow readback/upload stagingentries match what @SAitken91 saw on an RX 6950 XT: a pooled staging buffer seems to be released or reused while a submitted list still uses it.Tested and written up with Claude's help.
@fuzeofficlal on GitHub · 2026-11-24 17:16 UTC · original
Reviewed and verified
1c94839merged cleanly ontomain(ffe310e) across NVIDIA GeForce RTX 5090 (D3D12 Debug Layer), AMD Radeon(TM) Graphics iGPU (D3D12 Debug Layer), and Microsoft D3D12 WARP (D3D12 Debug Layer).While running
clippy, parallelwatch::testsstress runs, and multi-submission VRAM shadow tests, I found and fixed six edge cases on top of1c94839infuzeofficlal/VIctory@322724b(branchfix/pr693-watch-and-vram-verify):clippy::undocumented_unsafe_blocksfailure (watch.rs:386):assert_eq!(unsafe { ... }, ...)expanded inside the macro without seeing the preceding// SAFETY:comment; bindinglet got = unsafe { ... };first satisfies Clippy cleanly.shadow.rsWatchedAlloc::drop,watch.rs,resource.rsMemory::drop):forget_pagesafterVirtualFreeallowed another thread's concurrentVirtualAllocto reuse the same address and write to it beforeforget_pagescleared its fresh journal/guard state;written_pages_are_reported_to_every_askeralso omittedforget_pagesbeforeVirtualFree.Memory::dropalso neededwatch::forget_pagesbefore releasing owned resource backing memory, with inward whole-page rounding(start.div_ceil(PAGE), end / PAGE)so sub-64 KiB edge allocations never clear neighboring live allocations sharing a page.host.rsStagingArena::reset): Clearingentry.3(in_use) before sorting/truncatingself.largecaused steady-state oversized buffers that were smaller than historical idle peak allocations to be evicted and reallocated every submission. Sorting byReverse((entry.3, entry.2))before clearingentry.3retains active buffers first.ExecuteCommandListsfence ordering (host.rsHost::execute): Handlinggroups.len() <= 1in the fast path ensuresupload_list/readback_liststill wait on the queue fence whengroupsis empty, and waiting onhas_uploadbefore the multi-groupVICTORY_GPU_TIMINGloop avoids folding upload prelude GPU time intogroups[0].shadow.rsShadow::copy_back_range): Restrictingsyncedto fulln == PAGEslices with!cpu_diffand resettingwatch::writes(..., true)per contiguous synced page run avoids clearing write-watch state on partial boundary ranges.Verification
cargo test -p victory-gpu(61 passed, 0 failed, including a new multi-submission compute SRV/UAV + concurrent CPU write + overlapping-upload roundtrip test and 8x parallelwatch/shadowstress loops):0debug layer errors)0debug layer errors)0debug layer errors)cargo clippy --workspace --all-targets&--all-features:0warningscargo xtask policy: passed@maplerouteadmin-dev on GitHub · 2026-11-24 21:28 UTC · original
In-game result on a 12 GB NVIDIA card, where #693 goes far over the video-memory budget.
Setup: RTX 5070 12 GB (driver 32.0.16.2114), Ryzen 5 5600X, 32 GB, Windows 11; Xbox Series 1.0.2.1; diag build,
VICTORY_D3D12_DRED=1, scripted input (VICTORY_KEYS), 240 s. Base:mainffe310e+ #966 + Peppacodesexp/mesh-host-lanes+ a #951 port (needed to reach the world on NVIDIA). Test: base + #952 + #693 (1c94839) + #454 withVICTORY_NO_WATCHDOG=1(without it, the title's watchdog ended the first try at loading). Merges were union-only plus one test updated to the base'sindirect::bound/donesignatures;cargo test -p victory-gpupasses. No game data used.#952's log line, in the world:
World frames (frame-rate lines over 500 ms):
So on this card the shadows in
DEFAULTheaps ask for about 19 GB of local memory against a 10.6 GB budget. Windows then pages local memory, the copies and the GPU both slow down by 3-4x, and a submission runs past the timeout. The AMD results above were on cards with more VRAM (or with less of the world), which may be why they did not show this.A budget check would probably make the PR safe on 8-12 GB cards: for example keep new shadows in
WRITE_BACKsystem memory (as before) onceQueryVideoMemoryInfo's current usage passes the budget (#952 already queries it), or move only shadows that are refreshed often. Happy to run a build with such a check on this card.@Marvisak on GitHub · 2026-11-25 00:35 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/host.rs,crates/victory-gpu/src/shadow.rs,crates/victory-gpu/src/watch.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.