gpu: move shadow buffers to DEFAULT VRAM with pooled staging transfers #693
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T06:57:00Z.
Summary
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)Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T07:00:19Z.
Review: COMMENTED
Static review only — this is the deepest change in the current batch (+993/-264, architectural: shadow buffers move from CPU WRITE_BACK system RAM to GPU-local DEFAULT VRAM with pooled UPLOAD/READBACK staging). I can't compile or run victory-gpu on macOS, so nothing here is execution-verified.
What a Windows pass should focus on, in order of risk:
gpu_writes): shader-written ranges now go through pooled READBACK staging and merge into title memory after submission — the merge must not clobber title writes that happened between submit and fence completion.No correctness objection from the static read, but this one needs the Windows runtime evidence before merge.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:12:10Z.
Review: APPROVED
Windows 11 MSVC runtime verification (Rust 1.98.1 x86_64-pc-windows-msvc on D3D12 hardware GPU and WARP):
Addressing the verification checklist:
eadback_arena reside strictly under self.submitted.lock() in host.execute(). They are only reset via rena.reset() after WaitForSingleObject completes the queue fence wait. There is zero risk of early slot recycling or UAF across submissions.
Imported from Marvisak/VIctory. Originally posted by justr4mzi on 2026-11-24T09:21:23Z.
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).
Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T09:21:41Z.
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).
Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T11:01:37Z.
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).
Imported from Marvisak/VIctory. Originally posted by SAitken91 on 2026-11-24T14:56:47Z.
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.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T15:36:41Z.
Review: CHANGES_REQUESTED
Tested
ae39e9con Windows 11, RTX 5070, MSVC: builds;cargo test -p victory-gpu -- --test-threads=145 passed, 1 failed:watch::tests::written_pages_are_reported_to_every_asker(finding 7). The three newshadowtests pass.I read this for ordering first. On the one direct queue it goes upload prelude, then title lists, then readback list, each in its own
ExecuteCommandListscall, and one fence wait covers all three before the CPU reads the readback memory and the arenas are reset. Buffers start in COMMON asshared_bufferdid, and the COPY_DEST to COPY_SOURCE barrier is there. I found no ordering or barrier bug.merge_rangesandcopy_back_rangeare correct on empty, adjacent, overlapping and unaligned ranges. What blocks it is the failure paths, where title data is lost silently:A page is marked current before its upload exists (shadow.rs:327 and :361).
copy_stalesetscopied[page] = nowbeforestage()allocates. Ifalloc(len)returnsNone,stagereturns 0 and records no copy, but the page already counts as copied. The VRAM copy then stays stale until the title happens to write that page again, and shaders read old data. Fix: updatecopiedonly for runs thatstageactually recorded. For example, havestagereturnOption<usize>and set*atafterwards, or roll back that run's entries when it fails.A failed readback allocation drops the shader's writes (host.rs:651-668). If either
readback_arena.allocfails, the range never entersreadback_plans, yetclear_pending(host.rs:876) still runs. The GPU's writes never reach title memory, and the next upload of that page overwrites them in VRAM. The old code had no failure path here. Fix: treat it as fatal (fail()), or at least warn and fall back to a synchronous per-range readback.Likely bug: two uploads of one range in one prelude, with no barrier between them (host.rs:678-686). A NOT_WATCHED buffer, or a page re-dirtied by a
CopyorRunstep in the same batch, can be staged twice with different bytes. TwoCopyBufferRegionwrites to overlapping bytes in one list, with no barrier, have no defined order, whereas the old memcpy always let the last write win. Fix: drop earlierUploadCopyentries that a later one covers, or put a barrier between them.The fence error is only a warning (host.rs:782). If
SignalorSetEventOnCompletionfails, the code goes on to compare readback slots that may still hold the previous submission's bytes, writes the result into title memory, and resets allocators and arenas that may still be in use. Fix:fail()here, as for device removal.Performance risk: merged write ranges for the world heap can be tens of MB. Above the 4 MiB chunk size, each submission creates and destroys two committed READBACK buffers of that size, which makes finding 2 more likely. Pooling the largest one or two buffers by size class would avoid that.
Behaviour change to note: the old
copy_backalso wrote the title's bytes into the shadow (*h = *t). Now, pages with CPU-side differences differ in VRAM until the next refresh. Shaders that read outside their declared ranges (the documented shortcut) see older bytes than before.A new test breaks
watch::tests::written_pages_are_reported_to_every_asker. Alone, the watch test passes. Run in one process aftershadow::tests::default_vram_shadow_uploads_only_dirty_pages(cargo test -p victory-gpu --lib -- --test-threads=1 shadow::tests::default_vram watch::tests), it fails at watch.rs:306 (before.is_empty()), and it fails in the full serial run too. The watch testVirtualAllocs fresh pages and finds writes already reported for them. Most likely the shadow test leaves watched ranges or journal entries behind after its memory is freed, and the address gets reused. Unregister the shadow and its watch at the end of the test. It's also worth checking whetherunregisterin production clears the journal for the range.The new
shadowtests pass silently when there is no device, so the WARP and debug-layer coverage in the description isn't enforced by the tests themselves.It conflicts with our fork's main (upstream plus merged PRs) in
host.rsandshadow.rs, so it isn't merged there.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by ordis-labs on 2026-11-24T15:28:00Z.
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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:16:05Z.
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: passedImported from Marvisak/VIctory. Originally posted by maplerouteadmin-dev on 2026-11-24T21:28:01Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:35:51Z.
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
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.