gpu: move shadow buffers to DEFAULT VRAM with pooled staging transfers #693

Open
github-bot wants to merge 2 commits from github-bot/gh-693 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 06:57 UTC · original
wbkepler:gpu/default-vram-shadow-buffers → main · +1316 −280 · 3 files · 2 commits · open

Summary

Moves registered and loose Shadow buffers from CPU WRITE_BACK L0 system RAM to GPU-local D3D12_HEAP_TYPE_DEFAULT VRAM (with ALLOW_UNORDERED_ACCESS) in host.rs and shadow.rs:

  • Adds Host::default_buffer, Host::readback_buffer, and a reusable 4 MiB StagingArena (capped at 4 pooled chunks; oversized allocations transient) for dirty 64 KiB page upload staging and pre/post-submission GPU-write readback snapshots.
  • Records upload and readback transfers via dedicated upload/readback command lists with proper COPY_DEST -> COPY_SOURCE barriers and COMMON decay between ExecuteCommandLists calls.
  • Coalesces overlapping/adjacent GPU-write ranges via merge_ranges and merges only GPU-modified bytes into title memory via copy_back_range while preserving concurrent CPU writes.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (hardware GPU)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib shadow — passed (3/3)
  • VICTORY_D3D12_DEBUG=1 clean on both hardware GPU and WARP
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 06:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/693) `wbkepler:gpu/default-vram-shadow-buffers` → `main` · +1316 −280 · 3 files · 2 commits · open ## Summary Moves registered and loose `Shadow` buffers from CPU `WRITE_BACK` L0 system RAM to GPU-local `D3D12_HEAP_TYPE_DEFAULT` VRAM (with `ALLOW_UNORDERED_ACCESS`) in `host.rs` and `shadow.rs`: - Adds `Host::default_buffer`, `Host::readback_buffer`, and a reusable 4 MiB `StagingArena` (capped at 4 pooled chunks; oversized allocations transient) for dirty 64 KiB page upload staging and pre/post-submission GPU-write readback snapshots. - Records upload and readback transfers via dedicated upload/readback command lists with proper `COPY_DEST -> COPY_SOURCE` barriers and `COMMON` decay between `ExecuteCommandLists` calls. - Coalesces overlapping/adjacent GPU-write ranges via `merge_ranges` and merges only GPU-modified bytes into title memory via `copy_back_range` while preserving concurrent CPU writes. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (hardware GPU) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib shadow` — passed (3/3) - `VICTORY_D3D12_DEBUG=1` clean on both hardware GPU and WARP - `cargo 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.
Address review findings on PR #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`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:15 +00:00
Author
Owner

@⁠justr4mzi on GitHub · 2026-11-24 09:21 UTC · original

Tested PR #693 (ae39e9c1) merged cleanly on current main (02f404e) on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2) and Rust 1.98.1 (x86_64-pc-windows-msvc), against main (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).
  • PR #693 (ae39e9c1, default parallel cargo test -p victory-gpu): 52 passed, 0 failed, 1 ignored (including all 3 new shadow::tests::*).
  • PR #693 (ae39e9c1, sequential cargo 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_asker panics at crates/victory-gpu/src/watch.rs:306 (assertion failed: before.is_empty()).
    • Running written_pages_are_reported_to_every_asker in isolation passes (1 passed).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 152 files ok.

Why --test-threads=1 fails

In shadow::tests (which run alphabetically before watch::tests under --test-threads=1), WatchedAlloc allocates with MEM_WRITE_WATCH and triggers watch::writes(...), inserting those page numbers into watch::JOURNAL. WatchedAlloc::drop frees the pages via VirtualFree(..., MEM_RELEASE) without clearing watch::JOURNAL entries for that range. Windows then reuses the same virtual address for watch::tests::written_pages_are_reported_to_every_asker, so its initial writes(start, end, false) sees stale JOURNAL entries from shadow::tests and fails before.is_empty(). (More broadly, if title allocations are freed and reallocated at the same VA, watch::JOURNAL would 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).

**@⁠justr4mzi** on GitHub · 2026-11-24 09:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7127298979) Tested PR #693 (`ae39e9c1`) merged cleanly on current `main` (`02f404e`) on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2) and Rust 1.98.1 (`x86_64-pc-windows-msvc`), against `main` (`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`). - PR #693 (`ae39e9c1`, default parallel `cargo test -p victory-gpu`): `52 passed, 0 failed, 1 ignored` (including all 3 new `shadow::tests::*`). - PR #693 (`ae39e9c1`, sequential `cargo 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_asker` panics at `crates/victory-gpu/src/watch.rs:306` (`assertion failed: before.is_empty()`). - Running `written_pages_are_reported_to_every_asker` in isolation passes (`1 passed`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: `152 files ok`. ### Why `--test-threads=1` fails In `shadow::tests` (which run alphabetically before `watch::tests` under `--test-threads=1`), `WatchedAlloc` allocates with `MEM_WRITE_WATCH` and triggers `watch::writes(...)`, inserting those page numbers into `watch::JOURNAL`. `WatchedAlloc::drop` frees the pages via `VirtualFree(..., MEM_RELEASE)` without clearing `watch::JOURNAL` entries for that range. Windows then reuses the same virtual address for `watch::tests::written_pages_are_reported_to_every_asker`, so its initial `writes(start, end, false)` sees stale `JOURNAL` entries from `shadow::tests` and fails `before.is_empty()`. (More broadly, if title allocations are freed and reallocated at the same VA, `watch::JOURNAL` would 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).*
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 09:21 UTC · original

Tested ae39e9c14 merged with main (8e79c80, clean merge) on Windows 11 Pro (26100), Rust 1.98.1 (x86_64-pc-windows-msvc), AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010): PASS (with two non-blocking code-review notes below).

Verification

  • cargo xtask policy → asset policy: 153 files ok
  • cargo 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 new shadow::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 messages
  • VICTORY_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 messages

Code-review notes

  1. Per-submission transient allocations for >4 MiB shader-written ranges (host.rs, StagingArena::alloc / reset): oversized allocations (alloc_len > STAGING_CHUNK, 4 MiB) are pushed to self.transient and dropped every submission. Because ReadbackPlan allocates both before and after readback buffers per coalesced GPU-write range, any world pass writing into a large heap (>4 MiB; the removed POOL comment in shadow.rs noted the 174 MiB heap previously hit ~2.3M page faults/frame without reuse) will CreateCommittedResource + Map and release two large READBACK buffers 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.
  2. Stale copied timestamp if staging allocation fails (shadow.rs, copy_stale → stage): copy_stale advances copied[page - base] = now before calling self.stage(...). If alloc(len) returns None, stage returns 0 without pushing an UploadCopy, 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).

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 09:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7127305466) Tested `ae39e9c14` merged with `main` (`8e79c80`, clean merge) on Windows 11 Pro (`26100`), Rust `1.98.1` (`x86_64-pc-windows-msvc`), **AMD Radeon RX 9060 XT** (RDNA4, driver `32.0.32029.2010`): **PASS** (with two non-blocking code-review notes below). ### Verification - `cargo xtask policy` → `asset policy: 153 files ok` - `cargo 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 new `shadow::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 messages - `VICTORY_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 messages ### Code-review notes 1. **Per-submission transient allocations for `>4 MiB` shader-written ranges (`host.rs`, `StagingArena::alloc` / `reset`)**: oversized allocations (`alloc_len > STAGING_CHUNK`, 4 MiB) are pushed to `self.transient` and dropped every submission. Because `ReadbackPlan` allocates both `before` and `after` readback buffers per coalesced GPU-write range, any world pass writing into a large heap (>4 MiB; the removed `POOL` comment in `shadow.rs` noted the 174 MiB heap previously hit ~2.3M page faults/frame without reuse) will `CreateCommittedResource` + `Map` and release two large `READBACK` buffers 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. 2. **Stale `copied` timestamp if staging allocation fails (`shadow.rs`, `copy_stale` → `stage`)**: `copy_stale` advances `copied[page - base] = now` before calling `self.stage(...)`. If `alloc(len)` returns `None`, `stage` returns `0` without pushing an `UploadCopy`, 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).
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 11:01 UTC · original

Tested head ae39e9c merged onto main ffe310e (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.

  • The PR's new tests pass. The ones that use the host GPU ran on the RTX 5060 (DXGI adapter 0 on this laptop, so the host-device helpers return a device and the tests don't take their early return):
    • merge_ranges_coalesces_overlapping_and_adjacent
    • default_vram_shadow_uploads_only_dirty_pages
    • gpu_writes_readback_merges_and_preserves_concurrent_cpu_writes
  • cargo test --workspace --locked: 345 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored on main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 11:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7129557218) Tested head `ae39e9c` merged onto `main` `ffe310e` (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. - The PR's new tests pass. The ones that use the host GPU ran on the RTX 5060 (DXGI adapter 0 on this laptop, so the host-device helpers return a device and the tests don't take their early return): - `merge_ranges_coalesces_overlapping_and_adjacent` - `default_vram_shadow_uploads_only_dirty_pages` - `gpu_writes_readback_merges_and_preserves_concurrent_cpu_writes` - `cargo test --workspace --locked`: **345 passed, 0 failed, 6 ignored**, against 342 passed / 6 ignored on `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠SAitken91 on GitHub · 2026-11-24 14:56 UTC · original

In-game results for #693 on an RX 6950 XT (RDNA2), Windows 11, diag build with VICTORY_D3D12_DRED=1, scripted input into the first mission. Base main ffe310e + #693 + #687 + #635 + my open shader PRs, plus the PRs noted per run.

extra PRs time in world how it ended
— (on 8e79c80) ≥165 s no failure, stopped at my 6-min limit
#568 ~48 s page fault inside freed shadow readback staging (8 entries)
#568 #180 ~131 s page fault inside freed 1024×1024 textures + freed shadow readback staging
#568 #180 #575 ~89 s GPU hang (0x887A0006), no page fault
same, VICTORY_SHADER_LOOP_LIMIT=1000 ~73 s page fault inside freed textures + freed shadow readback staging

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 shadow readback staging entries 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.

**@⁠SAitken91** on GitHub · 2026-11-24 14:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7135206500) In-game results for #693 on an **RX 6950 XT (RDNA2)**, Windows 11, `diag` build with `VICTORY_D3D12_DRED=1`, scripted input into the first mission. Base `main` `ffe310e` + #693 + #687 + #635 + my open shader PRs, plus the PRs noted per run. | extra PRs | time in world | how it ended | |---|---|---| | — (on `8e79c80`) | ≥165 s | no failure, stopped at my 6-min limit | | #568 | ~48 s | page fault inside freed `shadow readback staging` (8 entries) | | #568 #180 | ~131 s | page fault inside freed 1024×1024 textures + freed `shadow readback staging` | | #568 #180 #575 | ~89 s | GPU hang (`0x887A0006`), no page fault | | same, `VICTORY_SHADER_LOOP_LIMIT=1000` | ~73 s | page fault inside freed textures + freed `shadow readback staging` | 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 `shadow readback staging` entries 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.
Author
Owner

@⁠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), diag build, VICTORY_D3D12_DRED=1, identical scripted input. Base = main ffe310e + #175 (needed on Windows 10). Two runs each, alternating A/B/A/B. Averages over the world phase:

run time in world draws/frame frame GPU copies ended with
base 168 s 572 1,236 ms 212 ms 381 ms page fault inside freed textures
base 213 s 2,431 1,654 ms 314 ms 663 ms page fault inside freed textures
+#693 91 s 2,282 3,597 ms 2,165 ms 766 ms page fault inside freed texture + freed shadow readback staging / shadow upload staging
+#693 114 s 2,870 3,243 ms 1,714 ms 920 ms GPU hang (0x887A0006), no page fault

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 shadow readback/upload staging entries 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.

**@⁠ordis-labs** on GitHub · 2026-11-24 15:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7136073380) In-game A/B of this PR on **Windows 10 19045, RX 6700 XT** (driver 32.0.21045.29003), `diag` build, `VICTORY_D3D12_DRED=1`, identical scripted input. Base = main `ffe310e` + #175 (needed on Windows 10). Two runs each, alternating A/B/A/B. Averages over the world phase: | run | time in world | draws/frame | frame | GPU | copies | ended with | |---|---|---|---|---|---|---| | base | 168 s | 572 | 1,236 ms | 212 ms | 381 ms | page fault inside freed textures | | base | 213 s | 2,431 | 1,654 ms | 314 ms | 663 ms | page fault inside freed textures | | +#693 | 91 s | 2,282 | 3,597 ms | 2,165 ms | 766 ms | page fault inside freed texture **+ freed `shadow readback staging` / `shadow upload staging`** | | +#693 | 114 s | 2,870 | 3,243 ms | 1,714 ms | 920 ms | GPU hang (`0x887A0006`), no page fault | 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 `shadow readback/upload staging` entries 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 17:16 UTC · original

Reviewed and verified 1c94839 merged cleanly onto main (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, parallel watch::tests stress runs, and multi-submission VRAM shadow tests, I found and fixed six edge cases on top of 1c94839 in fuzeofficlal/VIctory@322724b (branch fix/pr693-watch-and-vram-verify):

  1. CI clippy::undocumented_unsafe_blocks failure (watch.rs:386): assert_eq!(unsafe { ... }, ...) expanded inside the macro without seeing the preceding // SAFETY: comment; binding let got = unsafe { ... }; first satisfies Clippy cleanly.
  2. Parallel VA-reuse race on release (shadow.rs WatchedAlloc::drop, watch.rs, resource.rs Memory::drop):
    • Calling forget_pages after VirtualFree allowed another thread's concurrent VirtualAlloc to reuse the same address and write to it before forget_pages cleared its fresh journal/guard state; written_pages_are_reported_to_every_asker also omitted forget_pages before VirtualFree.
    • Production Memory::drop also needed watch::forget_pages before 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.
  3. Active oversized staging eviction churn (host.rs StagingArena::reset): Clearing entry.3 (in_use) before sorting/truncating self.large caused steady-state oversized buffers that were smaller than historical idle peak allocations to be evicted and reallocated every submission. Sorting by Reverse((entry.3, entry.2)) before clearing entry.3 retains active buffers first.
  4. Timed / empty-group ExecuteCommandLists fence ordering (host.rs Host::execute): Handling groups.len() <= 1 in the fast path ensures upload_list / readback_list still wait on the queue fence when groups is empty, and waiting on has_upload before the multi-group VICTORY_GPU_TIMING loop avoids folding upload prelude GPU time into groups[0].
  5. Partial-page readback watch reset (shadow.rs Shadow::copy_back_range): Restricting synced to full n == PAGE slices with !cpu_diff and resetting watch::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 parallel watch/shadow stress loops):
    • NVIDIA GeForce RTX 5090 + D3D12 Debug Layer (0 debug layer errors)
    • AMD Radeon(TM) Graphics + D3D12 Debug Layer (0 debug layer errors)
    • D3D12 WARP + D3D12 Debug Layer (0 debug layer errors)
  • cargo clippy --workspace --all-targets & --all-features: 0 warnings
  • cargo xtask policy: passed
**@⁠fuzeofficlal** on GitHub · 2026-11-24 17:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7138938367) Reviewed and verified `1c94839` merged cleanly onto `main` (`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`, parallel `watch::tests` stress runs, and multi-submission VRAM shadow tests, I found and fixed six edge cases on top of `1c94839` in [`fuzeofficlal/VIctory@322724b`](https://github.com/fuzeofficlal/VIctory/commit/322724b4aefecc8df7481e25b7258f17f5e3ba24) (branch [`fix/pr693-watch-and-vram-verify`](https://github.com/fuzeofficlal/VIctory/tree/fix/pr693-watch-and-vram-verify)): 1. **CI `clippy::undocumented_unsafe_blocks` failure (`watch.rs:386`)**: `assert_eq!(unsafe { ... }, ...)` expanded inside the macro without seeing the preceding `// SAFETY:` comment; binding `let got = unsafe { ... };` first satisfies Clippy cleanly. 2. **Parallel VA-reuse race on release (`shadow.rs` `WatchedAlloc::drop`, `watch.rs`, `resource.rs` `Memory::drop`)**: - Calling `forget_pages` *after* `VirtualFree` allowed another thread's concurrent `VirtualAlloc` to reuse the same address and write to it before `forget_pages` cleared its fresh journal/guard state; `written_pages_are_reported_to_every_asker` also omitted `forget_pages` before `VirtualFree`. - Production `Memory::drop` also needed `watch::forget_pages` before 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. 3. **Active oversized staging eviction churn (`host.rs` `StagingArena::reset`)**: Clearing `entry.3` (`in_use`) *before* sorting/truncating `self.large` caused steady-state oversized buffers that were smaller than historical idle peak allocations to be evicted and reallocated every submission. Sorting by `Reverse((entry.3, entry.2))` before clearing `entry.3` retains active buffers first. 4. **Timed / empty-group `ExecuteCommandLists` fence ordering (`host.rs` `Host::execute`)**: Handling `groups.len() <= 1` in the fast path ensures `upload_list` / `readback_list` still wait on the queue fence when `groups` is empty, and waiting on `has_upload` before the multi-group `VICTORY_GPU_TIMING` loop avoids folding upload prelude GPU time into `groups[0]`. 5. **Partial-page readback watch reset (`shadow.rs` `Shadow::copy_back_range`)**: Restricting `synced` to full `n == PAGE` slices with `!cpu_diff` and resetting `watch::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 parallel `watch`/`shadow` stress loops): - **NVIDIA GeForce RTX 5090** + D3D12 Debug Layer (`0` debug layer errors) - **AMD Radeon(TM) Graphics** + D3D12 Debug Layer (`0` debug layer errors) - **D3D12 WARP** + D3D12 Debug Layer (`0` debug layer errors) - `cargo clippy --workspace --all-targets` & `--all-features`: `0` warnings - `cargo xtask policy`: passed
Author
Owner

@⁠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: main ffe310e + #966 + Peppacodes exp/mesh-host-lanes + a #951 port (needed to reach the world on NVIDIA). Test: base + #952 + #693 (1c94839) + #454 with VICTORY_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's indirect::bound/done signatures; cargo test -p victory-gpu passes. No game data used.

#952's log line, in the world:

video memory: 16906 MB of a 10524 MB budget on the adapter, 1949 MB in system memory
video memory: 17400 MB of a 10570 MB budget on the adapter, 2117 MB in system memory
video memory: 19042 MB of a 10570 MB budget on the adapter, 2299 MB in system memory

World frames (frame-rate lines over 500 ms):

base (2 runs) + #693 (1 run)
ms/frame 4 667 21 350
copies, ms/frame 4 240 14 663
on the GPU, ms/frame 521 1 499
world lines before the end 30 3
ended with device removed in 1 of 2 runs device removed (TDR)

So on this card the shadows in DEFAULT heaps 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_BACK system memory (as before) once QueryVideoMemoryInfo'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.

**@⁠maplerouteadmin-dev** on GitHub · 2026-11-24 21:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7144966536) 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: `main` `ffe310e` + #966 + Peppacodes `exp/mesh-host-lanes` + a #951 port (needed to reach the world on NVIDIA). Test: base + #952 + #693 (`1c94839`) + #454 with `VICTORY_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's `indirect::bound`/`done` signatures; `cargo test -p victory-gpu` passes. No game data used. **#952's log line, in the world:** ``` video memory: 16906 MB of a 10524 MB budget on the adapter, 1949 MB in system memory video memory: 17400 MB of a 10570 MB budget on the adapter, 2117 MB in system memory video memory: 19042 MB of a 10570 MB budget on the adapter, 2299 MB in system memory ``` **World frames** (frame-rate lines over 500 ms): | | base (2 runs) | + #693 (1 run) | |---|---|---| | ms/frame | 4 667 | **21 350** | | copies, ms/frame | 4 240 | 14 663 | | on the GPU, ms/frame | 521 | 1 499 | | world lines before the end | 30 | 3 | | ended with | device removed in 1 of 2 runs | device removed (TDR) | So on this card the shadows in `DEFAULT` heaps 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_BACK` system memory (as before) once `QueryVideoMemoryInfo`'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.
Author
Owner

@⁠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

**@⁠Marvisak** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/693#issuecomment-7148677702) <!-- victory-triage v1 head=1c94839f9a15b4ab9a31fabc51c04a515e6d0030 verdict=needs-rebase at=2026-11-25T00:13:20Z --> 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](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/watch.rs
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.
git fetch -u origin '+refs/pull/693/head:github-bot/gh-693'
git switch 'github-bot/gh-693'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-693'
git switch 'github-bot/gh-693'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-693'
git switch 'github-bot/gh-693'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-693'
git switch 'main'
git merge --squash 'github-bot/gh-693'
git switch 'main'
git merge --ff-only 'github-bot/gh-693'
git switch 'main'
git merge 'github-bot/gh-693'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!693
No description provided.