Repository navigation
Conversation
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.
catminou4
left a comment
There was a problem hiding this comment.
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:
- Readback merge correctness (
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. - Staging pool lifetime vs. list submission: pooled UPLOAD/READBACK buffers reused across submissions need fence-safe retirement; a pool slot recycled before its list's fence signals is the classic UAF here.
- Performance: the old path was CPU-visible memory (zero-copy on some paths); DEFAULT VRAM adds upload+readback traffic per frame. Worth a frame-time comparison on the RTX test machine, not just correctness.
- The doc-comment rewrite at the top of shadow.rs accurately describes the new flow — good.
No correctness objection from the static read, but this one needs the Windows runtime evidence before merge.
LAKSHYA-cmd-tech
left a comment
There was a problem hiding this comment.
Windows 11 MSVC runtime verification (Rust 1.98.1 x86_64-pc-windows-msvc on D3D12 hardware GPU and WARP):
Addressing the verification checklist:
- Readback merge correctness (gpu_writes): Shadow::copy_back_range correctly computes diffs between the pre-submission snapshot (�efore_ptr) and post-submission snapshot (�fter_ptr), applying only modified GPU bytes into title memory. Verified by est shadow::tests::gpu_writes_readback_merges_and_preserves_concurrent_cpu_writes where concurrent CPU writes outside the GPU-modified range remain untouched and dirty flags trigger subsequent uploads.
- Staging pool lifetime vs. list submission: upload_arena and
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. - Barriers and state decay: Upload copies run on a separate command list (shadow_upload_list) submitted in its own ExecuteCommandLists call preceding title command lists, allowing DEFAULT buffers to decay back to COMMON per D3D12 rules.
- Test suite results:
- cargo test -p victory-gpu --lib shadow: 3 passed, 0 failed
- cargo test -p victory-gpu: 46 passed, 0 failed, 1 ignored
- cargo xtask policy: 151 files ok
|
Tested PR #693 ( Test results (
|
|
Tested Verification
Code-review notes
AI-assisted; synthetic tests only, no game files (world runtime perf not measured). |
|
Tested head
AI-assisted (Claude Code). |
…s (PR Marvisak#693) Allocate Shadow host copies in D3D12_HEAP_TYPE_DEFAULT VRAM and stage dirty 64 KiB page uploads and pre/post GPU-write readbacks through pooled 4 MiB StagingArenas, integrated with bindless prepare (Marvisak#413), page-coalesced refreshes (Marvisak#393), and lock-free retirement (Marvisak#609). Update raw_view_tests::unknown_stride_reads to stage via DEFAULT buffers.
…transfers (PR Marvisak#693)" This reverts commit ac574a3.
|
In-game results for #693 on an RX 6950 XT (RDNA2), Windows 11,
For 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 |
|
In-game A/B of this PR on Windows 10 19045, RX 6700 XT (driver 32.0.21045.29003),
At 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 Tested and written up with Claude's help. |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested ae39e9c on Windows 11, RTX 5070, MSVC: builds; cargo test -p victory-gpu -- --test-threads=1 45 passed, 1 failed: watch::tests::written_pages_are_reported_to_every_asker (finding 7). The three new shadow tests 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 ExecuteCommandLists call, and one fence wait covers all three before the CPU reads the readback memory and the arenas are reset. Buffers start in COMMON as shared_buffer did, and the COPY_DEST to COPY_SOURCE barrier is there. I found no ordering or barrier bug. merge_ranges and copy_back_range are 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 shadow tests 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.rs and shadow.rs, so it isn't merged there.
AI-assisted (Claude Code).
…d watch cleanup Address review findings on PR Marvisak#693 (`gpu/default-vram-shadow-buffers`): - `crates/victory-gpu/src/shadow.rs`: - Have `Shadow::stage` return `Option<usize>` and update `copied[page]` in `Shadow::copy_stale` only after staging allocation succeeds, so failed allocations never mark dirty pages current. - Add `trim_overlapping_uploads` so earlier `UploadCopy` ranges overwritten by later uploads to the same shadow buffer are trimmed or dropped before recording `CopyBufferRegion` commands (ensuring disjoint destination bytes and last-write-wins order without extra barriers). - Clear freed test page entries from the write-watch journal in `WatchedAlloc::drop` so serial test runs reusing the same virtual address do not report stale writes in `watch::tests`. - Add unit tests for failed upload staging allocation retry and overlapping upload trimming. - `crates/victory-gpu/src/host.rs`: - Pool oversized (`> 4 MiB`) staging buffers in `StagingArena` by size class (retaining up to 4 large buffers and 8x 4 MiB chunks across submissions) to avoid per-submission creation/destruction churn. - Treat `readback_arena.alloc` failure and fence `Signal` / `SetEventOnCompletion` / `WaitForSingleObject` errors as fatal via `fail()` instead of silently dropping GPU writes or resetting in-flight arenas. - Call `shadow::trim_overlapping_uploads` before recording the upload prelude list. - Add a unit test verifying oversized staging buffer reuse across submissions. - `crates/victory-gpu/src/watch.rs`: - Add `#[cfg(test)] pub(crate) fn forget_pages` to remove freed test pages from `JOURNAL` and `GUARDS`.
The title's own crash report records system.memory.free 26472 KB of 31233028 KB total at 99 percent loaded. Our startup check only knows the first boot's 6.1 GiB, so a run can pass the gate and still die in the world. That matters because every buffer a draw uses gets a full-size host copy (shadow.rs), so the README's measured 17.7 GB world peak exists twice on a 32 GB machine. Records PR Marvisak#693 (default-heap shadow buffers, with pooled staging) as the candidate fix and why it is not merged: its reviewed version left shadows in COPY_SOURCE with no transition back to COMMON.
|
Reviewed and verified While running
Verification
|
|
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, #952's log line, in the world: World frames (frame-rate lines over 500 ms):
So on this card the shadows in A budget check would probably make the PR safe on 8-12 GB cards: for example keep new shadows in |
…y unchanged pages current) onto Marvisak#346 + Marvisak#334 + integ/next Taken instead of Marvisak#693 (shadow buffers in DEFAULT VRAM with staging readback): both rewrite how shaders' writes reach title memory, on incompatible models (Marvisak#1024 stores from the CPU-mapped host copy; Marvisak#693 has no CPU mapping and merges from readback snapshots), so only one can land. Marvisak#693 has unfixed in-title regressions on its last head's predecessor and no title run since: about 2x slower frames and 5-7x GPU time on an RX 6700 XT (Marvisak#693 (comment)), GPU page faults inside freed `shadow readback/upload staging` on RX 6950 XT and RX 6700 XT (Marvisak#693 (comment)), and a changes-requested review (mercuryVM). Its last commit (1c94839) fixes the review's failure paths but not the performance loss, and was not run in the title. Marvisak#1024 has no negative report; its tests pass on RTX 4090/Wine, RTX 5070 Ti, RX 7700 XT, RTX 5090/Wine, and a title run with it (and Marvisak#472, Marvisak#322) had shorter frames and less copy-back time (AgneyaK). Conflicts, crates/victory-gpu/src/shadow.rs: 1. `Shadow::copy_back`: the stack (Marvisak#124, TG0000) skips pages already found unchanged against this submission's snapshot (`UnchangedPages`) and allocates the title buffer lazily, by PAGE; Marvisak#1024 writes back only the runs of bytes the GPU changed (`write_runs`) and marks a synced page current only if title memory still equals the copy after the final write-watch query. Independent: both kept. The loop keeps the stack's `unchanged.differs` guard and lazy buffer, with Marvisak#1024's run collection and `write_runs` inside; the final check takes the (by then allocated) lazy buffer for its page re-reads. 2. Tests: the stack's `mod tests` and Marvisak#1024's `mod copy_back_tests` at the same place. The shared text holds the closing `);`, `}` and `}`, so the stack's module is closed in the hunk and Marvisak#1024's module follows as its own `#[cfg(test)]` item (not nested). No other non-textual fix needed (cargo check --all-targets --all-features).
…sak#98, Marvisak#334 to Marvisak#492, validation) The line rebuilt on the bundles' current heads (Marvisak#1402 119b763, Marvisak#1492 5bbc098 without Marvisak#98, Marvisak#1504 1d41891, Marvisak#1511 ca601f0) with every merge replayed, and the merges after this file's first version (Marvisak#334, Marvisak#346, Marvisak#1024, Marvisak#211, Marvisak#492): merge order, the runner's numbers on 967d3ae (RTX 571, WARP 570 + the known Marvisak#1084 failure, all features 580; Marvisak#98's one test leaves), what is not included (Marvisak#98, Marvisak#282 for Marvisak#346, Marvisak#693 for Marvisak#1024, Marvisak#306's latest commit), and the open pull requests whose head is contained here (109, from the 18:24 collection). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
…d-d16-440-111a Shaders: keep image_load d16 high half and saturate integer texels (Marvisak#440)
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)