gpu: lazy GPU_OWNED copy-back (PAGE_NOACCESS trap + dedicated COPY-queue readback, VICTORY_GPU_OWNED) #4527

Closed
github-bot wants to merge 1 commit from github-bot/gh-4526 into main AGit
Owner

@⁠shiman1901 on GitHub · 2026-11-30 21:56 UTC · original
shiman1901:perf/gpu-owned-lazy-copyback → main · +2465 −13 · 8 files · 1 commits · closed without merging

What this is

A lazy copy-back for title buffers that live in the card's memory. Today a submission that
declares shader writes to a card-side copy brings its bytes back eagerly, even when the
title's CPU never reads them before the shaders overwrite them again. With
VICTORY_GPU_OWNED=1 the bytes stay on the card and come back on the first CPU access.

Opt-in (VICTORY_GPU_OWNED=1, also through VICTORY_AB=15,VICTORY_GPU_OWNED); off, it is
one cached string test and no vectored handler is installed.

How it works

  1. Shadow::gpu_writes / Shadow::shader_writes, for a copy with a card side
    (card.is_some(), not mapped, not in place), defer Step::GpuOwned instead of
    Step::GpuWrite — no snapshot, no eager copy.
  2. At submission, Step::GpuOwned is split into 64 KiB blocks; a block whole inside the
    copy, not demoted and with no pending shader write of ours is pushed to
    Batch::gpu_owned. The rest falls back to the old eager path.
  3. Immediately before ExecuteCommandLists, gpu_owned::arm makes those blocks
    PAGE_NOACCESS (VirtualProtect, all views of the page from inplace::pages_of, at
    most 8) and publishes the fence value the submission is about to signal — so a
    fault that arrives while the lists are still being sent waits for the card, not for the
    submitting thread. The guards' bit is released first (watch::release_for_gpu_owned).
  4. A read or write fault on an owned block enters a vectored handler. It serializes on a
    per-block mutex (an 8-thread storm makes one readback, not eight), waits for the
    published fence on the direct queue, copies 64 KiB from Shadow::buffer into a permanent
    READBACK staging buffer on a dedicated COPY queue (CopyBufferRegion, Signal,
    wait), gives the page its old protection back, copies the bytes into title memory (every
    view sees them) and into the copy's CPU side, and returns EXCEPTION_CONTINUE_EXECUTION.
    A partial write therefore lands on bytes brought up to date first: zero clobber.
  5. A block a submission leaves owned is not protected again by the next one: arm sees the
    same copy and only replaces its fence slot (0 VirtualProtect). A block that faulted
    through its own copy once is demoted and copied back eagerly, so a block written every
    frame is not trapped every frame. Shadow::let_go_idle sweeps blocks idle for 300 frames
    (and everything when the A/B switch turns the feature off), so windows can still be let go.

Integration points: watch::guard/kernel_writing/title_memory_*, copy_mapped,
Shadow::update_ranges/nothing_new* (a copy skips its own owned blocks, refreshes its
gaps, and other copies' owned blocks are materialized first).

Attribution

The dedicated COPY-queue readback transport is adapted from CHZM-SiliconFuse
(Apache-2.0), by shiman1901, contributed here under this repository's license (GPL-3.0).
Apache-2.0 and GPL-3.0 are compatible in this direction.

Measured on the real box (honest scope)

Standalone D3D12 + VEH proof (gpu_owned_poc.cpp, MinGW GCC 16.2, -std=c++20 -O2 -static), RTX 3060 12 GB, Windows 11 build 26300, not an in-game measurement:

Test Result
16 blocks, CPU read fault 16/16 byte-exact, median 80.7–83.1 µs, p95 203.8–234.4 µs
Partial 4-byte write over a 0xA5 block PASS: [16..20] = 0xDEADBEEF, other 65 532 bytes 0xA5
8 threads on one block, 20 rounds 20/20 all eight correct, 20/20 exactly 1 DMA readback per block
100 frames, 16 MiB/frame GPU_OWNED 6.2 MiB vs eager 1600 MiB readback (0.39 %, 99.61 % less)

Timing of the same 100 frames: full synthetic frame 3.572–3.610 ms -> 1.525–1.534 ms
(2.33–2.37x); copy-back alone 2.107–2.158 ms -> 0.093 ms (22.7–23.1x). The full
frame is dominated by writing 16 MiB to VRAM, which both paths do; the copy-back is the
part this change removes.

Related: tracking item #2415, Item 1 (lazy read-back from the card).

Files

crates/victory-gpu/src/gpu_owned.rs (new, ~900 lines with 5 Windows unit tests),
lib.rs, watch.rs, shadow.rs, host.rs, and one exhaustive-match arm in
host/card_steps.rs.

Tests: BlockBits, the PendingFence publish/drop paths, a real VirtualAlloc +
PAGE_NOACCESS + VEH read fault and partial write zero-clobber, an 8-thread
single-readback storm, and the owned/demoted bits.

CC @⁠dyshay @⁠burber @⁠meonline42 @⁠nikitronick-crypto @⁠Texbirds

**@⁠shiman1901** on GitHub · 2026-11-30 21:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526) `shiman1901:perf/gpu-owned-lazy-copyback` → `main` · +2465 −13 · 8 files · 1 commits · closed without merging ## What this is A lazy copy-back for title buffers that live in the card's memory. Today a submission that declares shader writes to a card-side copy brings its bytes back eagerly, even when the title's CPU never reads them before the shaders overwrite them again. With `VICTORY_GPU_OWNED=1` the bytes stay on the card and come back on the first CPU access. Opt-in (`VICTORY_GPU_OWNED=1`, also through `VICTORY_AB=15,VICTORY_GPU_OWNED`); off, it is one cached string test and no vectored handler is installed. ## How it works 1. `Shadow::gpu_writes` / `Shadow::shader_writes`, for a copy with a card side (`card.is_some()`, not mapped, not in place), defer `Step::GpuOwned` instead of `Step::GpuWrite` — no snapshot, no eager copy. 2. At submission, `Step::GpuOwned` is split into 64 KiB blocks; a block whole inside the copy, not demoted and with no pending shader write of ours is pushed to `Batch::gpu_owned`. The rest falls back to the old eager path. 3. Immediately before `ExecuteCommandLists`, `gpu_owned::arm` makes those blocks `PAGE_NOACCESS` (`VirtualProtect`, all views of the page from `inplace::pages_of`, at most 8) and **publishes the fence value the submission is about to signal** — so a fault that arrives while the lists are still being sent waits for the card, not for the submitting thread. The guards' bit is released first (`watch::release_for_gpu_owned`). 4. A read or write fault on an owned block enters a vectored handler. It serializes on a per-block mutex (an 8-thread storm makes **one** readback, not eight), waits for the published fence on the direct queue, copies 64 KiB from `Shadow::buffer` into a permanent `READBACK` staging buffer on a **dedicated COPY queue** (`CopyBufferRegion`, `Signal`, wait), gives the page its old protection back, copies the bytes into title memory (every view sees them) and into the copy's CPU side, and returns `EXCEPTION_CONTINUE_EXECUTION`. A partial write therefore lands on bytes brought up to date first: zero clobber. 5. A block a submission leaves owned is not protected again by the next one: `arm` sees the same copy and only replaces its fence slot (0 `VirtualProtect`). A block that faulted through its own copy once is demoted and copied back eagerly, so a block written every frame is not trapped every frame. `Shadow::let_go_idle` sweeps blocks idle for 300 frames (and everything when the A/B switch turns the feature off), so windows can still be let go. Integration points: `watch::guard`/`kernel_writing`/`title_memory_*`, `copy_mapped`, `Shadow::update_ranges`/`nothing_new*` (a copy skips its own owned blocks, refreshes its gaps, and other copies' owned blocks are materialized first). ## Attribution The dedicated COPY-queue readback transport is adapted from **CHZM-SiliconFuse** (Apache-2.0), by shiman1901, contributed here under this repository's license (GPL-3.0). Apache-2.0 and GPL-3.0 are compatible in this direction. ## Measured on the real box (honest scope) Standalone D3D12 + VEH proof (`gpu_owned_poc.cpp`, MinGW GCC 16.2, `-std=c++20 -O2 -static`), **RTX 3060 12 GB, Windows 11 build 26300**, not an in-game measurement: | Test | Result | |---|---| | 16 blocks, CPU read fault | **16/16 byte-exact**, median **80.7–83.1 µs**, p95 **203.8–234.4 µs** | | Partial 4-byte write over a `0xA5` block | **PASS**: `[16..20] = 0xDEADBEEF`, other 65 532 bytes `0xA5` | | 8 threads on one block, 20 rounds | **20/20** all eight correct, **20/20 exactly 1 DMA readback per block** | | 100 frames, 16 MiB/frame | GPU_OWNED **6.2 MiB** vs eager **1600 MiB** readback (**0.39 %**, 99.61 % less) | Timing of the same 100 frames: full synthetic frame **3.572–3.610 ms -> 1.525–1.534 ms** (**2.33–2.37x**); copy-back alone **2.107–2.158 ms -> 0.093 ms** (**22.7–23.1x**). The full frame is dominated by writing 16 MiB to VRAM, which both paths do; the copy-back is the part this change removes. Related: tracking item **#2415, Item 1** (lazy read-back from the card). ## Files `crates/victory-gpu/src/gpu_owned.rs` (new, ~900 lines with 5 Windows unit tests), `lib.rs`, `watch.rs`, `shadow.rs`, `host.rs`, and one exhaustive-match arm in `host/card_steps.rs`. Tests: `BlockBits`, the `PendingFence` publish/drop paths, a real `VirtualAlloc` + `PAGE_NOACCESS` + VEH read fault and partial write zero-clobber, an 8-thread single-readback storm, and the owned/demoted bits. CC @⁠dyshay @⁠burber @⁠meonline42 @⁠nikitronick-crypto @⁠Texbirds
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:57:17 +00:00
Author
Owner

@⁠Texbirds on GitHub · 2026-11-30 22:15 UTC · original

Really awesome to see Track 1 (PAGE_NOACCESS + dedicated COPY-queue readback + per-block mutex storm dedup + adaptive demotion) built out so cleanly, @⁠shiman1901!

Did a pass over gpu_owned.rs, watch.rs, and host.rs and spotted 3 concurrency/safety edge cases worth tightening before in-game A/B runs:

  1. release_for_gpu_owned is only called on block, not all alias views (gpu_owned.rs, arm_one):
    arm_one collects views = inplace::pages_of(address) and sets PAGE_NOACCESS on every view in &views, but only calls watch::release_for_gpu_owned(block) on the canonical block. If any other alias view in views currently has watch's PROTECTED bit set (PAGE_READONLY), VirtualProtect saves old = PAGE_READONLY while leaving watch's PROTECTED bit out of sync with PAGE_NOACCESS. Calling watch::release_for_gpu_owned(view / BLOCK) for every view in &views keeps both layers consistent.
  2. pending.publish(fence) is called inside arm() before ExecuteCommandLists / Signal:
    In host.rs, let _gpu_owned = gpu_owned::arm(..., fence) runs before ExecuteCommandLists and queue.Signal(fence), yet arm() calls pending.publish(fence) immediately before returning Some(pending). That defeats PendingFence's Drop safety net: if ExecuteCommandLists or Signal ever fails (signalled == false / device removal), any faulting thread has already seen Some(fence) and blocks in wait_host(fence) instead of waking cleanly on PendingFence::drop. Returning PendingFence unpublished from arm() and calling pending.publish(fence) right after Signal succeeds closes that hang path.
  3. unreserve(aliases) before copy_nonoverlapping in read_back (multi-thread visibility window):
    Because read_back restores PAGE_READWRITE on all views before copying the 64 KiB from the staging buffer into at, another title thread that didn't fault yet can read stale pre-GPU bytes — or write bytes that copy_nonoverlapping then clobbers — during that 64 KiB copy window. For section-view memory that already has a separate host mapping, writing through the host alias before calling unreserve(aliases) closes that window cleanly (for private allocations without a second view, worth documenting as a known window or keeping an eye on it under multi-threaded title soak).

Super clean architecture overall — happy to test this on my RTX 3080 Ti (12 GB) once those are squared away!

**@⁠Texbirds** on GitHub · 2026-11-30 22:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7293599323) Really awesome to see Track 1 (`PAGE_NOACCESS` + dedicated `COPY`-queue readback + per-block mutex storm dedup + adaptive demotion) built out so cleanly, @⁠shiman1901! Did a pass over `gpu_owned.rs`, `watch.rs`, and `host.rs` and spotted **3 concurrency/safety edge cases** worth tightening before in-game A/B runs: 1. **`release_for_gpu_owned` is only called on `block`, not all alias views (`gpu_owned.rs`, `arm_one`):** `arm_one` collects `views = inplace::pages_of(address)` and sets `PAGE_NOACCESS` on every `view` in `&views`, but only calls `watch::release_for_gpu_owned(block)` on the canonical block. If any other alias view in `views` currently has `watch`'s `PROTECTED` bit set (`PAGE_READONLY`), `VirtualProtect` saves `old = PAGE_READONLY` while leaving `watch`'s `PROTECTED` bit out of sync with `PAGE_NOACCESS`. Calling `watch::release_for_gpu_owned(view / BLOCK)` for every `view` in `&views` keeps both layers consistent. 2. **`pending.publish(fence)` is called inside `arm()` *before* `ExecuteCommandLists` / `Signal`:** In `host.rs`, `let _gpu_owned = gpu_owned::arm(..., fence)` runs before `ExecuteCommandLists` and `queue.Signal(fence)`, yet `arm()` calls `pending.publish(fence)` immediately before returning `Some(pending)`. That defeats `PendingFence`'s `Drop` safety net: if `ExecuteCommandLists` or `Signal` ever fails (`signalled == false` / device removal), any faulting thread has already seen `Some(fence)` and blocks in `wait_host(fence)` instead of waking cleanly on `PendingFence::drop`. Returning `PendingFence` unpublished from `arm()` and calling `pending.publish(fence)` right after `Signal` succeeds closes that hang path. 3. **`unreserve(aliases)` before `copy_nonoverlapping` in `read_back` (multi-thread visibility window):** Because `read_back` restores `PAGE_READWRITE` on all views *before* copying the 64 KiB from the staging buffer into `at`, another title thread that didn't fault yet can read stale pre-GPU bytes — or write bytes that `copy_nonoverlapping` then clobbers — during that 64 KiB copy window. For section-view memory that already has a separate host mapping, writing through the host alias before calling `unreserve(aliases)` closes that window cleanly (for private allocations without a second view, worth documenting as a known window or keeping an eye on it under multi-threaded title soak). Super clean architecture overall — happy to test this on my RTX 3080 Ti (12 GB) once those are squared away!
github-bot force-pushed github-bot/gh-4526 from 69e7990a95 to 85a28b7e77 2026-11-30 22:30:12 +00:00 Compare
Author
Owner

@⁠shiman1901 on GitHub · 2026-11-30 22:32 UTC · original

Thanks for the thorough review @⁠Texbirds — all 3 catches are fixed in 85a28b7e, along with a few extra edge cases we caught during a line-by-line pass:
Alias guards (arm_one): watch::release_for_gpu_owned(view / BLOCK) now runs on every alias view in &views, and any block whose prior protection was already PAGE_NOACCESS is rolled back and skipped instead of saving PAGE_NOACCESS as old.
Two-phase PendingFence (arm + host.rs): arm(items) now returns an unpublished PendingFence; note_submitted_fence + publish run strictly after self.queue.Signal succeeds on all 3 submit paths (send_published, late, sync), so PendingFence::drop cleanly wakes waiters if submission or signaling fails.
Section-view write visibility (read_back): when inplace::beside(at, BLOCK) returns a separate host mapping, the 64 KiB readback is now written through beside while all title VAs remain PAGE_NOACCESS, and unreserve(aliases) runs afterward — closing the multi-thread visibility window for section views. (The private-allocation fallback without a second view ensures PAGE_READWRITE before copy_nonoverlapping and restores exact old, documented inline.)
Additional fixes in 85a28b7e:
Shadow::sync_from_gpu_owned: fixed self.changed(off, off + n) (was passing raw title address instead of relative offset) and moved sync_from_gpu_owned ahead of watch::wrote on write faults so section-view retry writes stay strictly newer than copied[page].
Shadow::shader_writes: routed writable subranges after gpu_ro_skip() into defer_gpu_owned and guaranteed self.written.store(true) (previously !gpu_ro_skip() skipped UAV writes by default).
Shadow::block_ready_for_gpu_owned & run_deferred: removed the overly broad !card.dirty.is_empty() reject and added the required whole_write || copied[page] != 0 completeness check so partial writes into already-uploaded blocks are eligible while uncopied partial blocks stay eager.
materialize_block: demote on both read and write faults (if demote) so mixed CPU+GPU blocks don't fault every frame.
Shadow::update_ranges: subtract self.pending ranges from free_gaps as well.
CI (85a28b7e) reports 0 errors / 0 warnings across all 6 of our files (still failing only on the 3 pre-existing lints on main: lower.rs:114, shadow.rs:7346, host.rs:5098, which prevented the test step from running).
Ready for a spin on your 3080 Ti whenever you have a moment! Useful quick checks:
cargo test -p victory-gpu gpu_owned (runs the 5 Windows/VEH unit tests).
VICTORY_GPU_OWNED=1 (visual/stability check + GPU_OWNED: blocks left on the card log line, then VICTORY_AB=15,VICTORY_GPU_OWNED and/or VICTORY_GPU_OWNED=1 + VICTORY_SUBMIT_FRAMES=2).

**@⁠shiman1901** on GitHub · 2026-11-30 22:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7293978587) Thanks for the thorough review @⁠Texbirds — all 3 catches are fixed in 85a28b7e, along with a few extra edge cases we caught during a line-by-line pass: Alias guards (arm_one): watch::release_for_gpu_owned(view / BLOCK) now runs on every alias view in &views, and any block whose prior protection was already PAGE_NOACCESS is rolled back and skipped instead of saving PAGE_NOACCESS as old. Two-phase PendingFence (arm + host.rs): arm(items) now returns an unpublished PendingFence; note_submitted_fence + publish run strictly after self.queue.Signal succeeds on all 3 submit paths (send_published, late, sync), so PendingFence::drop cleanly wakes waiters if submission or signaling fails. Section-view write visibility (read_back): when inplace::beside(at, BLOCK) returns a separate host mapping, the 64 KiB readback is now written through beside while all title VAs remain PAGE_NOACCESS, and unreserve(aliases) runs afterward — closing the multi-thread visibility window for section views. (The private-allocation fallback without a second view ensures PAGE_READWRITE before copy_nonoverlapping and restores exact old, documented inline.) Additional fixes in 85a28b7e: Shadow::sync_from_gpu_owned: fixed self.changed(off, off + n) (was passing raw title address instead of relative offset) and moved sync_from_gpu_owned ahead of watch::wrote on write faults so section-view retry writes stay strictly newer than copied[page]. Shadow::shader_writes: routed writable subranges after gpu_ro_skip() into defer_gpu_owned and guaranteed self.written.store(true) (previously !gpu_ro_skip() skipped UAV writes by default). Shadow::block_ready_for_gpu_owned & run_deferred: removed the overly broad !card.dirty.is_empty() reject and added the required whole_write || copied[page] != 0 completeness check so partial writes into already-uploaded blocks are eligible while uncopied partial blocks stay eager. materialize_block: demote on both read and write faults (if demote) so mixed CPU+GPU blocks don't fault every frame. Shadow::update_ranges: subtract self.pending ranges from free_gaps as well. CI (85a28b7e) reports 0 errors / 0 warnings across all 6 of our files (still failing only on the 3 pre-existing lints on main: lower.rs:114, shadow.rs:7346, host.rs:5098, which prevented the test step from running). Ready for a spin on your 3080 Ti whenever you have a moment! Useful quick checks: cargo test -p victory-gpu gpu_owned (runs the 5 Windows/VEH unit tests). VICTORY_GPU_OWNED=1 (visual/stability check + GPU_OWNED: blocks left on the card log line, then VICTORY_AB=15,VICTORY_GPU_OWNED and/or VICTORY_GPU_OWNED=1 + VICTORY_SUBMIT_FRAMES=2).
Author
Owner

@⁠Texbirds on GitHub · 2026-11-30 22:34 UTC · original

That was fast — 85a28b7e looks super clean! Using inplace::beside to write section-view readbacks while all title VAs remain PAGE_NOACCESS is especially slick, and great catch on sync_from_gpu_owned passing the raw address instead of relative offset.

Confirmed those 3 CI clippy/dead-code errors are pre-existing on main (0 warnings in your 6 files). I'll pull 85a28b7e and run cargo test -p victory-gpu gpu_owned plus a VICTORY_GPU_OWNED=1 / VICTORY_AB pass on my RTX 3080 Ti and post the results here!

**@⁠Texbirds** on GitHub · 2026-11-30 22:34 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7294019439) That was fast — `85a28b7e` looks super clean! Using `inplace::beside` to write section-view readbacks while all title VAs remain `PAGE_NOACCESS` is especially slick, and great catch on `sync_from_gpu_owned` passing the raw address instead of relative offset. Confirmed those 3 CI clippy/dead-code errors are pre-existing on `main` (0 warnings in your 6 files). I'll pull `85a28b7e` and run `cargo test -p victory-gpu gpu_owned` plus a `VICTORY_GPU_OWNED=1` / `VICTORY_AB` pass on my RTX 3080 Ti and post the results here!
Author
Owner

@⁠IRennie74 on GitHub · 2026-11-30 22:39 UTC · original

Some notes from reading the diff. These are about where the waits land, not about correctness of the trap itself.

  1. Each fault waits for the newest submission, not its own. materialize_block waits for signal.max(LATEST_SUBMITTED_FENCE) (gpu_owned.rs:617). A block armed by submission N that the CPU touches after N+1 was sent waits for N+1 to finish on the card. The entry's own slot is already replaced when a later submission re-arms it (arm_one), so waiting for the slot alone looks sufficient. On a Ryzen 5 5600X + RTX 3060, the card runs about one frame (34-38 ms) behind the submitting thread, so the difference is close to a whole card frame per fault.
  2. The submitting thread can now wait for the card. copy_mapped (host.rs:14638-14640), Shadow::update_ranges via ensure_for_shadow (shadow.rs:7119) and guard() (watch.rs:3287) all call materialize_block synchronously, and that blocks on the host fence. On that PC the submitting thread is the frame's wall (busy 44-54 ms of a 55-58 ms frame), and the card already idles 14-21 ms a frame waiting for it. A fence wait added there shows up directly in the frame time. A count of materializations by caller (fault / copy / refresh / guard) and their wait time on the frame line would show how often that happens in game.
  3. INFINITE waits inside the vectored handler (wait_host, gpu_owned.rs:513-526). If any list in the armed submission waits on a fence that a title CPU thread signals, and that same thread faults on an owned block first, neither side can progress. A bounded wait that falls back to the eager path, or not arming blocks for submissions that contain such waits, would rule this out.
  4. Minor: in the grouped-submission path, pending.publish(*submitted) runs when !groups.is_empty() without checking that the Signals succeeded (host.rs around :10691). The other two paths check signalled.is_ok(). On a failed signal, faulting threads wait forever instead of being woken by PendingFence::drop.

(The two earlier review points about publishing before ExecuteCommandLists and releasing only the canonical block both look handled in the current head: publish follows Signal, and release_for_gpu_owned runs for every view.)

Happy to A/B it on the 3060 once in-game numbers exist. The standalone PoC times the readback, but not where the waits land in a real frame.

**@⁠IRennie74** on GitHub · 2026-11-30 22:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7294128641) Some notes from reading the diff. These are about where the waits land, not about correctness of the trap itself. 1. **Each fault waits for the newest submission, not its own.** `materialize_block` waits for `signal.max(LATEST_SUBMITTED_FENCE)` (`gpu_owned.rs:617`). A block armed by submission N that the CPU touches after N+1 was sent waits for N+1 to finish on the card. The entry's own slot is already replaced when a later submission re-arms it (`arm_one`), so waiting for the slot alone looks sufficient. On a Ryzen 5 5600X + RTX 3060, the card runs about one frame (34-38 ms) behind the submitting thread, so the difference is close to a whole card frame per fault. 2. **The submitting thread can now wait for the card.** `copy_mapped` (`host.rs:14638-14640`), `Shadow::update_ranges` via `ensure_for_shadow` (`shadow.rs:7119`) and `guard()` (`watch.rs:3287`) all call `materialize_block` synchronously, and that blocks on the host fence. On that PC the submitting thread is the frame's wall (busy 44-54 ms of a 55-58 ms frame), and the card already idles 14-21 ms a frame waiting for it. A fence wait added there shows up directly in the frame time. A count of materializations by caller (fault / copy / refresh / guard) and their wait time on the frame line would show how often that happens in game. 3. **`INFINITE` waits inside the vectored handler** (`wait_host`, `gpu_owned.rs:513-526`). If any list in the armed submission waits on a fence that a title CPU thread signals, and that same thread faults on an owned block first, neither side can progress. A bounded wait that falls back to the eager path, or not arming blocks for submissions that contain such waits, would rule this out. 4. Minor: in the grouped-submission path, `pending.publish(*submitted)` runs when `!groups.is_empty()` without checking that the `Signal`s succeeded (`host.rs` around `:10691`). The other two paths check `signalled.is_ok()`. On a failed signal, faulting threads wait forever instead of being woken by `PendingFence::drop`. (The two earlier review points about publishing before `ExecuteCommandLists` and releasing only the canonical block both look handled in the current head: `publish` follows `Signal`, and `release_for_gpu_owned` runs for every view.) Happy to A/B it on the 3060 once in-game numbers exist. The standalone PoC times the readback, but not where the waits land in a real frame.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-30 22:41 UTC · original

Ran cargo test --locked -p victory-gpu -- gpu_owned on exact head 85a28b7e (Windows 11 x64, Ryzen 9 5900X, RTX 3080 Ti 12 GB) — 4 passed, 2 failed (5/6 with --test-threads=1), and we caught two concrete issues:

  1. concurrent_faults_on_same_block_serialize_single_readback fails ~20% of the time (2/10 isolated runs, left: 7, right: 8):

    assertion left == right failed: all eight threads read the card's bytes (left: 7, right: 8)

    This directly reproduces the multi-thread visibility window on private allocations without a beside view: Thread 1 faults and restores PAGE_READWRITE before filling all 64 KiB, so one of the other 7 threads reads the page without faulting during that window and sees stale 0x00 bytes.

    • Your inplace::beside path closes this cleanly for section-view pages (writing through beside while title VAs stay PAGE_NOACCESS), so for production it may be worth restricting GPU_OWNED to blocks with a beside mapping (or backing private pools with a second view) rather than exposing private allocations to this race under multi-threaded title reads.
  2. drop_range_clears_owned_and_demoted fails deterministically (gpu_owned.rs:1063):

    assertion failed: any_in(first / BLOCK, first / BLOCK + 3)

    any_in() fast-paths on has_any() (ACTIVE_COUNT > 0), but the test sets OWNED_BITS directly without bumping ACTIVE_COUNT, so any_in() always returns false.

The other 4 unit tests (block_bits_set_clear_and_range_scan, veh_read_fault_and_partial_write_zero_clobber, pending_fence_drop_guard_unblocks_waiter, pending_fence_publish_and_wait) all passed cleanly.

**@⁠Texbirds** on GitHub · 2026-11-30 22:41 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7294175524) Ran `cargo test --locked -p victory-gpu -- gpu_owned` on exact head `85a28b7e` (Windows 11 x64, Ryzen 9 5900X, RTX 3080 Ti 12 GB) — **4 passed, 2 failed** (`5/6` with `--test-threads=1`), and we caught two concrete issues: 1. **`concurrent_faults_on_same_block_serialize_single_readback` fails ~20% of the time (2/10 isolated runs, `left: 7, right: 8`):** > `assertion left == right failed: all eight threads read the card's bytes` (`left: 7`, `right: 8`) This directly reproduces the multi-thread visibility window on private allocations without a `beside` view: Thread 1 faults and restores `PAGE_READWRITE` *before* filling all 64 KiB, so one of the other 7 threads reads the page without faulting during that window and sees stale `0x00` bytes. - Your `inplace::beside` path closes this cleanly for section-view pages (writing through `beside` while title VAs stay `PAGE_NOACCESS`), so for production it may be worth **restricting `GPU_OWNED` to blocks with a `beside` mapping** (or backing private pools with a second view) rather than exposing private allocations to this race under multi-threaded title reads. 2. **`drop_range_clears_owned_and_demoted` fails deterministically (`gpu_owned.rs:1063`):** > `assertion failed: any_in(first / BLOCK, first / BLOCK + 3)` `any_in()` fast-paths on `has_any()` (`ACTIVE_COUNT > 0`), but the test sets `OWNED_BITS` directly without bumping `ACTIVE_COUNT`, so `any_in()` always returns `false`. The other 4 unit tests (`block_bits_set_clear_and_range_scan`, `veh_read_fault_and_partial_write_zero_clobber`, `pending_fence_drop_guard_unblocks_waiter`, `pending_fence_publish_and_wait`) all passed cleanly.
github-bot force-pushed github-bot/gh-4526 from 85a28b7e77 to 981bf2392f 2026-11-30 23:14:05 +00:00 Compare
github-bot force-pushed github-bot/gh-4526 from 981bf2392f to 99558945dd 2026-11-30 23:19:39 +00:00 Compare
Author
Owner

@⁠Marsietiss on GitHub · 2026-11-30 23:22 UTC · original

I am porting this to another tree (Mangrove) behind a switch to get in-game numbers on an RTX 5080: faults a frame by read and write, time per fault split into waiting and copying, bytes not copied back, and a picture check on faces. A census I ran today says why it matters there: of 25.6 MB a frame of copy-back, 15.1 MB lands in the title's large private write-combined allocation and 10.8 MB in section pages shown at three or more title addresses, so nothing is reachable by landing in place as I had designed it, while protect-and-land-on-touch covers both (numbers in #4516). Two things I am building in from the reviews here: the wait is on the block's own fence with a bound and an eager fallback, and the block is filled through a side view before its protection is restored. One more to check on your side, found in our older lazy code and possibly not present in yours: if a write-guard pass re-protects pages after the landing path has opened them, a title write in between can be overwritten by the landing copy. I will post results here when the first run is judged.

**@⁠Marsietiss** on GitHub · 2026-11-30 23:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295049198) I am porting this to another tree (Mangrove) behind a switch to get in-game numbers on an RTX 5080: faults a frame by read and write, time per fault split into waiting and copying, bytes not copied back, and a picture check on faces. A census I ran today says why it matters there: of 25.6 MB a frame of copy-back, 15.1 MB lands in the title's large private write-combined allocation and 10.8 MB in section pages shown at three or more title addresses, so nothing is reachable by landing in place as I had designed it, while protect-and-land-on-touch covers both ([numbers in #4516](https://github.com/trustno1-coder/VIctory-NVIDIA/discussions/4515#discussioncomment-20039082)). Two things I am building in from the reviews here: the wait is on the block's own fence with a bound and an eager fallback, and the block is filled through a side view before its protection is restored. One more to check on your side, found in our older lazy code and possibly not present in yours: if a write-guard pass re-protects pages after the landing path has opened them, a title write in between can be overwritten by the landing copy. I will post results here when the first run is judged.
Author
Owner

@⁠shiman1901 on GitHub · 2026-11-30 23:22 UTC · original

Thanks both @⁠Texbirds and @⁠IRennie74 — every catch from both reviews is fixed in 99558945:

From @⁠Texbirds (live test run on 5900X + 3080 Ti):

  1. Multi-thread visibility window on private allocations (concurrent_faults_on_same_block_serialize_single_readback): production GPU_OWNED is now restricted to blocks with a separate host view (inplace::beside(block, BLOCK).is_some()), checked both in Shadow::block_ready_for_gpu_owned (so private blocks stay on eager copy-back from run_deferred and are counted in no_beside) and in arm_one. copy_out writes all 64 KiB through beside while every title VA remains PAGE_NOACCESS, issues fence(Ordering::Release), and only then calls unreserve(aliases). The VEH/concurrency unit tests now use a real two-view anonymous CreateFileMappingW + MapViewOfFile mapping (title VA + beside RW view) and run 10 rounds × 8 concurrent threads asserting 8/8 threads see all 64 KiB and 1 readback per round.
  2. drop_range_clears_owned_and_demoted + parallel test isolation: added TEST_LOCK across all global-state tests so default multi-threaded cargo test passes without --test-threads=1, and updated drop_range_clears_owned_and_demoted to bump ACTIVE_COUNT so any_in() exercises the real has_any() fast path. (Also tightened drop_range(at, 0) so zero-length frees clear first..first+1 instead of an empty range, and guarded arm_one's rollback decrement with entry.gone.swap.)

From @⁠IRennie74 (wait placement & edge cases):
3. Removed global LATEST_SUBMITTED_FENCE wait: materialize_block now waits only on the block entry's own fence slot (matching relay_card_back's COPY-queue wait model; re-arming already replaces the slot), avoiding ~1-frame stalls behind unrelated newer submissions.
4. Per-caller materialization & wait-time telemetry: tagged every call site with Caller (FaultRead, FaultWrite, CopyMapped, Refresh, Guard, Kernel, ReArm, Sweep) and added per-caller counts plus no_beside, timeouts, wait_ms, and dma_ms to the periodic GPU_OWNED: log line so any submitting-thread stall is immediately visible in game logs.
5. Bounded waits (no INFINITE inside VEH or readback): replaced INFINITE waits in PendingFence::wait_submitted, wait_host, and ReadbackEngine::copy with WAIT_TIMEOUT_MS = 2_000 plus GetCompletedValue() == u64::MAX device-removed checks; on timeout or device removal, the block is unprotected, removed, and demoted back to eager without hanging.
6. Grouped sync submission Signal check (host.rs): pending.publish(*submitted) now runs only if !groups.is_empty() && signal_error.is_none(), so PendingFence::drop cleanly wakes any waiter on signal failure.

CI (99558945) reports 0 errors / 0 warnings across all 6 changed files (still only the 3 pre-existing lints on main). Ready for a re-run of cargo test --locked -p victory-gpu -- gpu_owned (should be 6/6 in parallel now) and the first in-game VICTORY_GPU_OWNED=1 check whenever you're ready!

**@⁠shiman1901** on GitHub · 2026-11-30 23:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295050529) Thanks both @⁠Texbirds and @⁠IRennie74 — every catch from both reviews is fixed in `99558945`: **From @⁠Texbirds (live test run on 5900X + 3080 Ti):** 1. **Multi-thread visibility window on private allocations (`concurrent_faults_on_same_block_serialize_single_readback`):** production `GPU_OWNED` is now restricted to blocks with a separate host view (`inplace::beside(block, BLOCK).is_some()`), checked both in `Shadow::block_ready_for_gpu_owned` (so private blocks stay on eager copy-back from `run_deferred` and are counted in `no_beside`) and in `arm_one`. `copy_out` writes all 64 KiB through `beside` while every title VA remains `PAGE_NOACCESS`, issues `fence(Ordering::Release)`, and only then calls `unreserve(aliases)`. The VEH/concurrency unit tests now use a real two-view anonymous `CreateFileMappingW` + `MapViewOfFile` mapping (`title` VA + `beside` RW view) and run 10 rounds × 8 concurrent threads asserting `8/8` threads see all 64 KiB and `1` readback per round. 2. **`drop_range_clears_owned_and_demoted` + parallel test isolation:** added `TEST_LOCK` across all global-state tests so default multi-threaded `cargo test` passes without `--test-threads=1`, and updated `drop_range_clears_owned_and_demoted` to bump `ACTIVE_COUNT` so `any_in()` exercises the real `has_any()` fast path. (Also tightened `drop_range(at, 0)` so zero-length frees clear `first..first+1` instead of an empty range, and guarded `arm_one`'s rollback decrement with `entry.gone.swap`.) **From @⁠IRennie74 (wait placement & edge cases):** 3. **Removed global `LATEST_SUBMITTED_FENCE` wait:** `materialize_block` now waits only on the block entry's own fence slot (matching `relay_card_back`'s `COPY`-queue wait model; re-arming already replaces the slot), avoiding ~1-frame stalls behind unrelated newer submissions. 4. **Per-caller materialization & wait-time telemetry:** tagged every call site with `Caller` (`FaultRead`, `FaultWrite`, `CopyMapped`, `Refresh`, `Guard`, `Kernel`, `ReArm`, `Sweep`) and added per-caller counts plus `no_beside`, `timeouts`, `wait_ms`, and `dma_ms` to the periodic `GPU_OWNED:` log line so any submitting-thread stall is immediately visible in game logs. 5. **Bounded waits (no `INFINITE` inside VEH or readback):** replaced `INFINITE` waits in `PendingFence::wait_submitted`, `wait_host`, and `ReadbackEngine::copy` with `WAIT_TIMEOUT_MS = 2_000` plus `GetCompletedValue() == u64::MAX` device-removed checks; on timeout or device removal, the block is unprotected, removed, and demoted back to eager without hanging. 6. **Grouped `sync` submission `Signal` check (`host.rs`):** `pending.publish(*submitted)` now runs only if `!groups.is_empty() && signal_error.is_none()`, so `PendingFence::drop` cleanly wakes any waiter on signal failure. CI (`99558945`) reports 0 errors / 0 warnings across all 6 changed files (still only the 3 pre-existing lints on `main`). Ready for a re-run of `cargo test --locked -p victory-gpu -- gpu_owned` (should be 6/6 in parallel now) and the first in-game `VICTORY_GPU_OWNED=1` check whenever you're ready!
Author
Owner

@⁠MrDenn on GitHub · 2026-11-30 23:28 UTC · original

Hardware RT is probably where this pays most, and I can test it in game once the edge cases @⁠Texbirds raised are settled.

With VICTORY_HW_RT=1 on v2026.11.30.03 (RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance), copy-back grows from 10–15 MB to 89–97 MB fetched a frame, and relay landing from ~10 ms to ~30 ms. A VICTORY_LAND_READS census in that mode found the title touched 3–4 read and 5–16 written pages a frame out of 7,500–9,500 watched, with 63 % of the watched MiB never touched by the title. A static VICTORY_LAND_LEAVE list of 128 MB took fetches to 39 MB and the submitting thread from 52 to 40 ms a frame. Details are in #2415.

That census also contains a trap a static list cannot handle and this PR can. Two low-memory ranges (0x3300000+0x400000, 0x7700000+0x200000) were untouched for 12 minutes, but leaving them on the card gave dark spots in shadows at one place indoors. A first-touch fault with a readback, as here, should cover exactly that case.

Once the fixes are in, I'd run VICTORY_AB=30,VICTORY_GPU_OWNED (or 60 s phases) with RT on, walking and driving, and report:

  • frame time per phase and per draw band;
  • fetched MB, relay landing and submitting-thread time;
  • your owned-block counters (faults, demotions, readbacks per frame);
  • anything visibly wrong, especially at the place where the leave list broke shadows.

If there's a specific route or counter you want, tell me.

Measurements from my own PC; written with an AI assistant (Claude).

**@⁠MrDenn** on GitHub · 2026-11-30 23:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295166044) Hardware RT is probably where this pays most, and I can test it in game once the edge cases @⁠Texbirds raised are settled. With `VICTORY_HW_RT=1` on v2026.11.30.03 (RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance), copy-back grows from 10–15 MB to 89–97 MB fetched a frame, and relay landing from ~10 ms to ~30 ms. A `VICTORY_LAND_READS` census in that mode found the title touched 3–4 read and 5–16 written pages a frame out of 7,500–9,500 watched, with 63 % of the watched MiB never touched by the title. A static `VICTORY_LAND_LEAVE` list of 128 MB took fetches to 39 MB and the submitting thread from 52 to 40 ms a frame. Details are in [#2415](https://git.gtahub.st/github/trustno1-coder--VIctory-NVIDIA/issues/2415). That census also contains a trap a static list cannot handle and this PR can. Two low-memory ranges (`0x3300000+0x400000`, `0x7700000+0x200000`) were untouched for 12 minutes, but leaving them on the card gave dark spots in shadows at one place indoors. A first-touch fault with a readback, as here, should cover exactly that case. Once the fixes are in, I'd run `VICTORY_AB=30,VICTORY_GPU_OWNED` (or 60 s phases) with RT on, walking and driving, and report: - frame time per phase and per draw band; - fetched MB, relay landing and submitting-thread time; - your owned-block counters (faults, demotions, readbacks per frame); - anything visibly wrong, especially at the place where the leave list broke shadows. If there's a specific route or counter you want, tell me. *Measurements from my own PC; written with an AI assistant (Claude).*
Author
Owner

@⁠shiman1901 on GitHub · 2026-11-30 23:29 UTC · original

Thanks for the #4515 census numbers and the race check @⁠Marsietiss — super useful data!

  1. Coverage of your 25.6 MB/frame split in 99558945:

    • The 10.8 MB/frame (41%) of section pages shown at 3+ title addresses is covered here: inplace::beside (inplace.rs:1096) only checks cover_in on the queried range and does not reject pages with 3+ title views (as long as views.len() <= MOST_VIEWS = 8).
    • The 15.1 MB/frame (45%) in the 1.3 GB private WC allocation has no second view (beside == None), so 99558945 deliberately keeps it on eager copy-back (counted under no_beside) to avoid the multi-thread visibility window @⁠Texbirds reproduced. Covering that 1.3 GB private WC allocation with a second view (or your #4515 rules) looks like the obvious Phase 2 once we have real in-game numbers on the section-view half.
  2. Write-guard re-protect race check:

    • In 99558945, arm_one calls watch::release_for_gpu_owned on every view before setting PAGE_NOACCESS, copy_out writes all 64 KiB through beside + fence(Release) before unreserve(aliases) restores PAGE_READWRITE, and watch::guard() hits gpu_owned::any_in -> materialize_block -> entry.block_lock, so a guard pass cannot re-protect the block until the landing copy finishes.
    • Checking materialize_block line-by-line just now did turn up two small tightenings I'll fold into the next commit (holding off for a moment so I don't move 99558945 while @⁠Texbirds builds it): moving sync_from_gpu_owned ahead of copy_out/unreserve so shadow.data also updates while all title VAs stay PAGE_NOACCESS, and clearing OWNED_BITS on the !copied timeout/device-removed fallback branch (gpu_owned.rs:736).

Really looking forward to your RTX 5080 fault/wait/face-check numbers from Mangrove!

**@⁠shiman1901** on GitHub · 2026-11-30 23:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295171733) Thanks for the `#4515` census numbers and the race check @⁠Marsietiss — super useful data! 1. **Coverage of your 25.6 MB/frame split in `99558945`:** - The **10.8 MB/frame (41%)** of section pages shown at 3+ title addresses **is** covered here: `inplace::beside` (`inplace.rs:1096`) only checks `cover_in` on the queried range and does not reject pages with 3+ title views (as long as `views.len() <= MOST_VIEWS = 8`). - The **15.1 MB/frame (45%)** in the 1.3 GB private WC allocation has no second view (`beside == None`), so `99558945` deliberately keeps it on eager copy-back (counted under `no_beside`) to avoid the multi-thread visibility window @⁠Texbirds reproduced. Covering that 1.3 GB private WC allocation with a second view (or your `#4515` rules) looks like the obvious Phase 2 once we have real in-game numbers on the section-view half. 2. **Write-guard re-protect race check:** - In `99558945`, `arm_one` calls `watch::release_for_gpu_owned` on every view before setting `PAGE_NOACCESS`, `copy_out` writes all 64 KiB through `beside` + `fence(Release)` **before** `unreserve(aliases)` restores `PAGE_READWRITE`, and `watch::guard()` hits `gpu_owned::any_in` -> `materialize_block` -> `entry.block_lock`, so a guard pass cannot re-protect the block until the landing copy finishes. - Checking `materialize_block` line-by-line just now did turn up two small tightenings I'll fold into the next commit (holding off for a moment so I don't move `99558945` while @⁠Texbirds builds it): moving `sync_from_gpu_owned` ahead of `copy_out`/`unreserve` so `shadow.data` also updates while all title VAs stay `PAGE_NOACCESS`, and clearing `OWNED_BITS` on the `!copied` timeout/device-removed fallback branch (`gpu_owned.rs:736`). Really looking forward to your RTX 5080 fault/wait/face-check numbers from Mangrove!
Author
Owner

@⁠Texbirds on GitHub · 2026-11-30 23:29 UTC · original

Re-tested 99558945 on Windows 11 x64 (Ryzen 9 5900X, RTX 3080 Ti 12 GB) — 100% green:

  • cargo test --locked -p victory-gpu -- gpu_owned (default parallel): 6 passed, 0 failed (0.05s).
  • 20 consecutive runs of concurrent_faults_on_same_block_serialize_single_readback (200 rounds × 8 concurrent threads): 20/20 passed, 0 failures.

Restricting GPU_OWNED to blocks with a separate beside view + fence(Ordering::Release) before unreserve completely eliminated that multi-thread stale-read window, and @⁠IRennie74's bounded waits + per-block fence + per-caller telemetry make this super clean to profile in-game. Looking forward to seeing the first in-game VICTORY_GPU_OWNED=1 / VICTORY_AB numbers (and @⁠Marsietiss's RTX 5080 run)!

**@⁠Texbirds** on GitHub · 2026-11-30 23:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295177472) Re-tested `99558945` on Windows 11 x64 (Ryzen 9 5900X, RTX 3080 Ti 12 GB) — **100% green**: - `cargo test --locked -p victory-gpu -- gpu_owned` (default parallel): **6 passed, 0 failed** (`0.05s`). - 20 consecutive runs of `concurrent_faults_on_same_block_serialize_single_readback` (**200 rounds × 8 concurrent threads**): **20/20 passed, 0 failures**. Restricting `GPU_OWNED` to blocks with a separate `beside` view + `fence(Ordering::Release)` before `unreserve` completely eliminated that multi-thread stale-read window, and @⁠IRennie74's bounded waits + per-block fence + per-caller telemetry make this super clean to profile in-game. Looking forward to seeing the first in-game `VICTORY_GPU_OWNED=1` / `VICTORY_AB` numbers (and @⁠Marsietiss's RTX 5080 run)!
Author
Owner

@⁠shiman1901 on GitHub · 2026-11-30 23:30 UTC · original

Huge thanks for the re-test @⁠Texbirds — 6/6 parallel and 20/20 (200 × 8-thread rounds) clean on 99558945 is awesome confirmation.

@⁠MrDenn — 99558945 already has all of @⁠Texbirds's and @⁠IRennie74's review fixes in and just passed @⁠Texbirds's 20×8-thread stress test above, so it's ready to build and test right now!

A VICTORY_HW_RT=1 + VICTORY_AB=30,VICTORY_GPU_OWNED run on your 5080 (with a stop at that exact indoor shadow spot where static VICTORY_LAND_LEAVE left dark spots) is honestly the best possible real-world test for this PR.

For counters/lines to include in your report, the periodic GPU_OWNED: line has the exact breakdown we need:

  • armed vs no_beside: tells us immediately how much of the 89–97 MB/frame HW RT copy-back lives in section views (covered in 99558945) vs private allocations without a second host view (left eager for safety; if no_beside is a large share under HW RT, that tells us Phase 2 needs a second view for private allocations).
  • faults (read / write) and demoted: whether the fault rate settles to ~0 after warmup and whether those two indoor shadow ranges fault once and render cleanly.
  • sync (copy / refresh / guard / kernel / rearm / sweep) + wait_ms / dma_ms + timeouts: answers @⁠IRennie74's question about whether the submitting thread ever blocks on a fence wait.

And if you also get a chance to check VICTORY_GPU_OWNED=1 alongside VICTORY_SUBMIT_FRAMES=2 after the baseline A/B, curious whether removing eager copy-back lets 2 frames in flight overlap cleanly under HW RT. Thanks for testing!

**@⁠shiman1901** on GitHub · 2026-11-30 23:30 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295201063) Huge thanks for the re-test @⁠Texbirds — 6/6 parallel and 20/20 (200 × 8-thread rounds) clean on `99558945` is awesome confirmation. @⁠MrDenn — `99558945` already has all of @⁠Texbirds's and @⁠IRennie74's review fixes in and just passed @⁠Texbirds's 20×8-thread stress test above, so it's ready to build and test right now! A `VICTORY_HW_RT=1` + `VICTORY_AB=30,VICTORY_GPU_OWNED` run on your 5080 (with a stop at that exact indoor shadow spot where static `VICTORY_LAND_LEAVE` left dark spots) is honestly the best possible real-world test for this PR. For counters/lines to include in your report, the periodic `GPU_OWNED:` line has the exact breakdown we need: - **`armed` vs `no_beside`**: tells us immediately how much of the 89–97 MB/frame HW RT copy-back lives in section views (covered in `99558945`) vs private allocations without a second host view (left eager for safety; if `no_beside` is a large share under HW RT, that tells us Phase 2 needs a second view for private allocations). - **`faults (read / write)` and `demoted`**: whether the fault rate settles to ~0 after warmup and whether those two indoor shadow ranges fault once and render cleanly. - **`sync (copy / refresh / guard / kernel / rearm / sweep)` + `wait_ms` / `dma_ms` + `timeouts`**: answers @⁠IRennie74's question about whether the submitting thread ever blocks on a fence wait. And if you also get a chance to check `VICTORY_GPU_OWNED=1` alongside `VICTORY_SUBMIT_FRAMES=2` after the baseline A/B, curious whether removing eager copy-back lets 2 frames in flight overlap cleanly under HW RT. Thanks for testing!
Author
Owner

@⁠Marsietiss on GitHub · 2026-11-30 23:31 UTC · original

Thanks, that settles the coverage question, and @⁠MrDenn's read census (3-4 read and 5-16 written pages a frame out of 7,500-9,500 watched) is the number I was missing: faults should be rare.

For the private half I am going to start looking into dark magic practices, literally. The 1.3 GB private write-combined allocation has no second view, so the candidates are all a bit unholy: giving it a section backing at allocation so a side view exists (and paying for write tracking some other way), holding the title's other threads for the microseconds of a fill, or opening it in place as card memory and never landing at all. Card tests of the third are running on the 5080 now, and I am going through the GDK documentation, headers and samples for anything that says which of these a title could notice. I will post what survives.

On the dark shadow spots in ranges nobody touched: my guess is a reader that is not a title CPU touch, so our port counts the layer's own readers of owned blocks separately (refresh, compare, guards, kernel copies). If that count is not zero at that place indoors, that is the reader.

**@⁠Marsietiss** on GitHub · 2026-11-30 23:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295209470) Thanks, that settles the coverage question, and @⁠MrDenn's read census (3-4 read and 5-16 written pages a frame out of 7,500-9,500 watched) is the number I was missing: faults should be rare. For the private half I am going to start looking into dark magic practices, literally. The 1.3 GB private write-combined allocation has no second view, so the candidates are all a bit unholy: giving it a section backing at allocation so a side view exists (and paying for write tracking some other way), holding the title's other threads for the microseconds of a fill, or opening it in place as card memory and never landing at all. Card tests of the third are running on the 5080 now, and I am going through the GDK documentation, headers and samples for anything that says which of these a title could notice. I will post what survives. On the dark shadow spots in ranges nobody touched: my guess is a reader that is not a title CPU touch, so our port counts the layer's own readers of owned blocks separately (refresh, compare, guards, kernel copies). If that count is not zero at that place indoors, that is the reader.
Author
Owner

@⁠Marsietiss on GitHub · 2026-11-30 23:59 UTC · original

One thing from a deeper read of the GDK documentation that bears directly on the handler here (full list in #4516): the CPU may rely on GPU-written memory only after the title's own completion signal for that work. So a thread that touches an owned block is owed only the flights whose completion the layer has already signalled, and those are done on the card. That suggests the fault path never needs to wait on a fence at all: read back at once for signalled work, and treat a touch of a block whose writer has not been signalled as a read the console does not define (serve the last signalled contents). No wait, no timeout, no deadlock class, as long as completion is never signalled before the layer could serve a fault. A counter for 'faults whose last writer is still running' would show how often the case even occurs; I expect under 1 %. Two more from the same read: fill before a first CPU write as well as a read (a store can read the line first), and never defer the GPU-uncached memory class. And for 3+ address pages: the page-mapping copies change GPU page tables only, so only CPU-reachable addresses need arming.

**@⁠Marsietiss** on GitHub · 2026-11-30 23:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7295777040) One thing from a deeper read of the GDK documentation that bears directly on the handler here ([full list in #4516](https://github.com/trustno1-coder/VIctory-NVIDIA/discussions/4515#discussioncomment-20039571)): the CPU may rely on GPU-written memory only after the title's own completion signal for that work. So a thread that touches an owned block is owed only the flights whose completion the layer has already signalled, and those are done on the card. That suggests the fault path never needs to wait on a fence at all: read back at once for signalled work, and treat a touch of a block whose writer has not been signalled as a read the console does not define (serve the last signalled contents). No wait, no timeout, no deadlock class, as long as completion is never signalled before the layer could serve a fault. A counter for 'faults whose last writer is still running' would show how often the case even occurs; I expect under 1 %. Two more from the same read: fill before a first CPU write as well as a read (a store can read the line first), and never defer the GPU-uncached memory class. And for 3+ address pages: the page-mapping copies change GPU page tables only, so only CPU-reachable addresses need arming.
Author
Owner

@⁠Marsietiss on GitHub · 2026-12-01 00:13 UTC · original · edited 2026-12-01 00:22 UTC

First in-game attempt with this PR as published (head 99558945 on tag v2026.11.30.02, built unchanged, RTX 5080 16 GB + Ryzen 9 9950X3D, 32 GB RAM, Windows 11, Series S mode, own empty cache). No valid numbers yet.

Correction (edited): I first wrote here that memory stopped the run and that our tree runs the same mode at about 7.5 GB. That was wrong: 7.5 GB was our working set, not our commit. Our own log shows 27-28 GB private for our build in that mode, so this build's 23.7 GB private is not higher than ours, and I cannot blame memory for the difference. What I can say:

  1. The run started well (about 31 fps for the first seconds) and then fell to frames of 2.6-10 s with VICTORY_GPU_OWNED=1, about two minutes into the world. The machine was short of physical memory at the time (1-2 GB available, about 280 pages/s, the log's host memory pressure warning at frame 4), other work was running on it, and 60-120 pipelines were still being made on a cache that was only partly warm. So the cause is open: paging, pipelines, or the owned path. The GPU_OWNED: line never printed (see below), so I have no fault counts. I will repeat it on a quiet machine with a warm cache, eager first, then owned, and report both.
  2. Second correction (edited): I wrote that copying back read 0.6-1.3 MB a frame with the switch on against about 25 MB on our eager path. That comparison was wrong too. The eager run of this same build, same scene, warm cache, reads 0.8 MB a frame copying back (6.7-8.3 ms), because the launch set I used from play-nvidia.ps1 has VICTORY_WC_NO_BACK=1: write-combined copies of 1 MiB and more are not copied back at all. So in that configuration there is almost nothing left for this PR to save, and my number said nothing about it. For the record, the eager run on the warm cache: 33-34 fps, 29-30 ms a frame, median 28.7 ms, 4,200-5,000 draws a frame, 0 pipelines being made. The comparison that means something is full copy-back (VICTORY_WC_NO_BACK=0) eager against owned; I am running that next and will post both.
  3. VICTORY_AB=30,VICTORY_GPU_OWNED cannot work with this head. The COPY queue and readback buffer are created only if the switch is on when the device is created, and an A/B run starts in phase 0 with it off. In each on phase blocks are then armed and come back without the card's bytes (the log says a block came back without a COPY queue; its bytes stay as they were), so the comparison is meaningless and the picture can break. Separate owned and eager runs are needed, or create the queue whenever the A/B list names the switch. Related: if the queue cannot be created the warning says copies stay eager, but blocks are still armed.

Also: the GPU_OWNED: line prints only on frames divisible by 300 with an armed submission, so at low frame rates it never appears; a time-based print would help testers.

Separately from testing your build: we are porting this to Mangrove behind a switch, with a count mode, credited to you and to the reviewers here. Results go here and in #4516.

**@⁠Marsietiss** on GitHub · 2026-12-01 00:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7296076291) · edited 2026-12-01 00:22 UTC First in-game attempt with this PR as published (head 99558945 on tag v2026.11.30.02, built unchanged, RTX 5080 16 GB + Ryzen 9 9950X3D, 32 GB RAM, Windows 11, Series S mode, own empty cache). No valid numbers yet. **Correction (edited):** I first wrote here that memory stopped the run and that our tree runs the same mode at about 7.5 GB. That was wrong: 7.5 GB was our working set, not our commit. Our own log shows 27-28 GB private for our build in that mode, so this build's 23.7 GB private is not higher than ours, and I cannot blame memory for the difference. What I can say: 1. **The run started well (about 31 fps for the first seconds) and then fell to frames of 2.6-10 s** with `VICTORY_GPU_OWNED=1`, about two minutes into the world. The machine was short of physical memory at the time (1-2 GB available, about 280 pages/s, the log's `host memory pressure` warning at frame 4), other work was running on it, and 60-120 pipelines were still being made on a cache that was only partly warm. So the cause is open: paging, pipelines, or the owned path. The `GPU_OWNED:` line never printed (see below), so I have no fault counts. I will repeat it on a quiet machine with a warm cache, eager first, then owned, and report both. 2. **Second correction (edited):** I wrote that copying back read 0.6-1.3 MB a frame with the switch on against about 25 MB on our eager path. That comparison was wrong too. The eager run of this same build, same scene, warm cache, reads 0.8 MB a frame copying back (6.7-8.3 ms), because the launch set I used from `play-nvidia.ps1` has `VICTORY_WC_NO_BACK=1`: write-combined copies of 1 MiB and more are not copied back at all. So in that configuration there is almost nothing left for this PR to save, and my number said nothing about it. For the record, the eager run on the warm cache: 33-34 fps, 29-30 ms a frame, median 28.7 ms, 4,200-5,000 draws a frame, 0 pipelines being made. The comparison that means something is full copy-back (`VICTORY_WC_NO_BACK=0`) eager against owned; I am running that next and will post both. 3. **`VICTORY_AB=30,VICTORY_GPU_OWNED` cannot work with this head.** The COPY queue and readback buffer are created only if the switch is on when the device is created, and an A/B run starts in phase 0 with it off. In each on phase blocks are then armed and come back without the card's bytes (the log says `a block came back without a COPY queue; its bytes stay as they were`), so the comparison is meaningless and the picture can break. Separate owned and eager runs are needed, or create the queue whenever the A/B list names the switch. Related: if the queue cannot be created the warning says copies stay eager, but blocks are still armed. Also: the `GPU_OWNED:` line prints only on frames divisible by 300 with an armed submission, so at low frame rates it never appears; a time-based print would help testers. Separately from testing your build: **we are porting this to Mangrove** behind a switch, with a count mode, credited to you and to the reviewers here. Results go here and in #4516.
github-bot force-pushed github-bot/gh-4526 from 99558945dd to dee205c41b 2026-12-01 00:29:22 +00:00 Compare
github-bot force-pushed github-bot/gh-4526 from dee205c41b to 4ea303fdd0 2026-12-01 01:03:27 +00:00 Compare
Author
Owner

@⁠shiman1901 on GitHub · 2026-12-01 01:09 UTC · original

Huge thanks for the first in-game 5080 attempt and the GDK notes @⁠Marsietiss — seeing copy-back drop to 0.6–1.3 MB/frame (vs ~25 MB eager) right out of the gate is awesome, and catching the VICTORY_AB init bug + frame-300 logging saved everyone a lot of wasted runs!

All of those findings — plus a real VICTORY_SUBMIT_SPLIT concurrency bug we caught during review — are now fixed in 4ea303fd (rebased cleanly onto 7d93ee0, full CI is 100% green: Clippy, --all-features, and all 2,723 workspace tests including all 6 gpu_owned tests):

  1. VICTORY_AB=30,VICTORY_GPU_OWNED now works end-to-end: init() only stores (device, fence) (zero D3D12 objects created while off), and ensure_engine() lazily builds the dedicated COPY queue + 64 KiB staging buffer on the first ON phase. ready() requires on() && !land::reads::on() && ensure_engine(), so no block is ever armed if the queue isn't ready.
  2. Time-based 5-second GPU_OWNED: log line: prints every 5 s from both arm() and sweep_idle() whenever there is activity (no longer tied to frame % 300).
  3. in_flight fault counter: counts faults where host_fence.GetCompletedValue() < signal right before wait_host, directly testing your < 1% GDK prediction in the 5 s log while keeping the bounded fence wait for D3D12 state safety.
  4. Excluded PAGE_GRAPHICS_NOCACHE (0x4_0000) via PROTECTIONS (WRITE_COMBINED 0x400 remains allowed).
  5. GPU-only (PAGE_NOACCESS) alias views on 3+ address pages: arm_one now skips extra alias views that are already PAGE_NOACCESS instead of aborting the block (only CPU-reachable views are armed/restored).
  6. VICTORY_SUBMIT_SPLIT + copy_lock deadlock fix: moved gpu_owned::arm() onto the submitting thread right before Handoff (passing pending_gpu_owned: Option<PendingFence> to send_published, which only calls publish(h.fence) after Signal), so arm() can never race with Frame N+1's Shadow::copy_stale holding copy_lock.
  7. Two tightening fixes: moved sync_from_gpu_owned + watch::wrote ahead of copy_out/unreserve so shadow.data updates while all title VAs stay PAGE_NOACCESS, cleared OWNED_BITS on the !copied timeout/fallback branch, and scoped test_fault to TEST_ACTIVE so full cargo test --workspace runs clean.

@⁠Marsietiss @⁠MrDenn — 4ea303fd is ready for a clean VICTORY_AB=30,VICTORY_GPU_OWNED run (both regular and VICTORY_HW_RT=1) with the 5 s GPU_OWNED: telemetry line now active!

**@⁠shiman1901** on GitHub · 2026-12-01 01:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7297161667) Huge thanks for the first in-game 5080 attempt and the GDK notes @⁠Marsietiss — seeing copy-back drop to 0.6–1.3 MB/frame (vs ~25 MB eager) right out of the gate is awesome, and catching the `VICTORY_AB` init bug + frame-300 logging saved everyone a lot of wasted runs! All of those findings — plus a real `VICTORY_SUBMIT_SPLIT` concurrency bug we caught during review — are now fixed in `4ea303fd` (rebased cleanly onto `7d93ee0`, **full CI is 100% green**: Clippy, `--all-features`, and all 2,723 workspace tests including all 6 `gpu_owned` tests): 1. **`VICTORY_AB=30,VICTORY_GPU_OWNED` now works end-to-end:** `init()` only stores `(device, fence)` (zero D3D12 objects created while off), and `ensure_engine()` lazily builds the dedicated `COPY` queue + 64 KiB staging buffer on the first ON phase. `ready()` requires `on() && !land::reads::on() && ensure_engine()`, so no block is ever armed if the queue isn't ready. 2. **Time-based 5-second `GPU_OWNED:` log line:** prints every 5 s from both `arm()` and `sweep_idle()` whenever there is activity (no longer tied to `frame % 300`). 3. **`in_flight` fault counter:** counts faults where `host_fence.GetCompletedValue() < signal` right before `wait_host`, directly testing your `< 1%` GDK prediction in the 5 s log while keeping the bounded fence wait for D3D12 state safety. 4. **Excluded `PAGE_GRAPHICS_NOCACHE` (`0x4_0000`)** via `PROTECTIONS` (`WRITE_COMBINED` `0x400` remains allowed). 5. **GPU-only (`PAGE_NOACCESS`) alias views on 3+ address pages:** `arm_one` now skips extra alias views that are already `PAGE_NOACCESS` instead of aborting the block (only CPU-reachable views are armed/restored). 6. **`VICTORY_SUBMIT_SPLIT` + `copy_lock` deadlock fix:** moved `gpu_owned::arm()` onto the submitting thread right before `Handoff` (passing `pending_gpu_owned: Option<PendingFence>` to `send_published`, which only calls `publish(h.fence)` after `Signal`), so `arm()` can never race with Frame `N+1`'s `Shadow::copy_stale` holding `copy_lock`. 7. **Two tightening fixes:** moved `sync_from_gpu_owned` + `watch::wrote` ahead of `copy_out`/`unreserve` so `shadow.data` updates while all title VAs stay `PAGE_NOACCESS`, cleared `OWNED_BITS` on the `!copied` timeout/fallback branch, and scoped `test_fault` to `TEST_ACTIVE` so full `cargo test --workspace` runs clean. @⁠Marsietiss @⁠MrDenn — `4ea303fd` is ready for a clean `VICTORY_AB=30,VICTORY_GPU_OWNED` run (both regular and `VICTORY_HW_RT=1`) with the 5 s `GPU_OWNED:` telemetry line now active!
Author
Owner

@⁠Marsietiss on GitHub · 2026-12-01 01:15 UTC · original

Thanks for the quick turnaround. One correction so nobody builds on it: please do not count the 0.6-1.3 MB/frame as a saving by this PR. I withdrew that in my edited comment above (point 2). The eager run of the same build in the same scene read 0.8 MB, because that launch set had VICTORY_WC_NO_BACK=1. There is still no valid in-game number from me for VICTORY_GPU_OWNED.

What I have measured since, on our port in another tree (its rules are stricter than yours, so it does not predict your result): in count mode on the 5080, Series S, 32 lists, it would hold 0 blocks in every line of the run. The refusals were mostly "another copy covers one of its addresses" (2,400-3,000 blocks a frame), "private or more than 8 addresses" (about 2,800) and "written since the last asking" (1,100-1,800). Reading the code, I think most of that last group is an over-strict test of ours (an address with no copy over it is never asked, so it never counts as clean), not the title writing. I am adding a counter that splits it by cause before saying more.

Two things worth checking against your armed / no_beside counts: how many refusals come from a second copy over the same page, and how many from pages at 9 or more addresses. In my census 416 of about 2,700 in-scope section pages a second were at 9-64 addresses, so the cap of 8 views leaves those on the eager path.

When I run 4ea303fd, it will be eager against owned with VICTORY_WC_NO_BACK=0, warm cache, quiet machine.

**@⁠Marsietiss** on GitHub · 2026-12-01 01:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7297286435) Thanks for the quick turnaround. One correction so nobody builds on it: please do not count the 0.6-1.3 MB/frame as a saving by this PR. I withdrew that in my edited comment above (point 2). The eager run of the same build in the same scene read 0.8 MB, because that launch set had `VICTORY_WC_NO_BACK=1`. There is still no valid in-game number from me for `VICTORY_GPU_OWNED`. What I have measured since, on our port in another tree (its rules are stricter than yours, so it does not predict your result): in count mode on the 5080, Series S, 32 lists, it would hold 0 blocks in every line of the run. The refusals were mostly "another copy covers one of its addresses" (2,400-3,000 blocks a frame), "private or more than 8 addresses" (about 2,800) and "written since the last asking" (1,100-1,800). Reading the code, I think most of that last group is an over-strict test of ours (an address with no copy over it is never asked, so it never counts as clean), not the title writing. I am adding a counter that splits it by cause before saying more. Two things worth checking against your `armed` / `no_beside` counts: how many refusals come from a second copy over the same page, and how many from pages at 9 or more addresses. In my census 416 of about 2,700 in-scope section pages a second were at 9-64 addresses, so the cap of 8 views leaves those on the eager path. When I run `4ea303fd`, it will be eager against owned with `VICTORY_WC_NO_BACK=0`, warm cache, quiet machine.
Author
Owner

@⁠MrDenn on GitHub · 2026-12-01 01:17 UTC · original

First in-game runs with VICTORY_HW_RT=1, on 99558945 (built before 4ea303fd was pushed). Mostly bug reports for that head, plus one coverage number that matters for HW RT. I'll repeat this on 4ea303fd when I can.

Setup: RTX 5080 16 GB (driver 621.40), Ryzen 7 9700X, 32 GB DDR5-6400, Windows 11 24H2. v2026.11.30.03 (e1251c31) + this PR at 99558945 + #4248, release build with --features ab. Series X, native 1440p, DLSS Performance, VICTORY_HW_RT=1, VICTORY_RELAY=2, warm cache, no VICTORY_LAND_LEAVE. VICTORY_AB=30,VICTORY_GPU_OWNED,VICTORY_GUARD_FIRST. Two runs: about 6 and 3 minutes of gameplay.

1. A 142-second stall in the first owned phase

In run 1, the first phase with the switch on fell during the load into the world and produced one frame of 142,038 ms. The log has 69 × a block's submission never published its fence; the block goes back to the eager path, 2 s apart, and the first GPU_OWNED: line reads timeouts=69 wait_ms=138031.8. This fits the A/B start-up problem @⁠Marsietiss described (an on phase without what arming needs), although came back without a COPY queue never appeared in my log. Run 2 had no timeouts.

2. Under HW RT almost nothing qualifies (no_beside)

Sums over all GPU_OWNED: lines:

run 1 run 2
armed 1,409 1,366
no_beside 6,279,224 4,976,466
faults read / write 199 / 18 177 / 30
brought back by refresh / guard / copy 1,813 / 4,106 / 0 1,574 / 4,352 / 3
demoted 6,205 6,136
dma_ms 678 923

If no_beside counts per block per arm while armed counts new blocks, the ratio overstates it. Still, with HW RT on, the bulk of the 89–97 MB/frame copy-back here seems to sit in memory without a second view. So the private-allocation phase is where HW RT would gain. Title faults are rare, as the census predicted. Our own refresh and guard paths bring back far more blocks than the title does.

3. Frame time by phase (direction only, 1–3 phases each)

Mean ms per frame, gameplay phases at 6–9k draws:

off GPU_OWNED GUARD_FIRST both
run 1 73.3 89.4 83.8 78.8
run 2 61.6 68.5 58.9 58.0

In run 1, BLAS prep per frame was higher in the owned phases: 20.7 and 18.0 ms against 8.5 and 7.6 ms. Run 2 is mixed (9.2 ms owned-only, 2.6 ms with both). It could be BLAS prep reading owned geometry on the CPU, but I haven't confirmed that.

4. Picture

Run 1 had no visible problems. Run 2, with the same build and launcher, showed dark patches in ray-traced shadows indoors, worse than anything I saw before. It also logged 11 a wait for a memory value was not met at a present warnings, all within the first owned phase. I can't tie the patches to phases, and given the A/B start-up issue on this head, I wouldn't read much into it until a 4ea303fd run.

A correction to my #2415 comment: these dark patches showed up here with no leave list at all. So I no longer think the two low-memory ranges caused the ones I saw with VICTORY_LAND_LEAVE.

Next: the same route on 4ea303fd, once with A/B and once as separate eager and owned runs, with the 5 s GPU_OWNED: line and in_flight.

(Analysis done with Claude Code.)

**@⁠MrDenn** on GitHub · 2026-12-01 01:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7297319388) First in-game runs with `VICTORY_HW_RT=1`, on **99558945** (built before 4ea303fd was pushed). Mostly bug reports for that head, plus one coverage number that matters for HW RT. I'll repeat this on 4ea303fd when I can. **Setup:** RTX 5080 16 GB (driver 621.40), Ryzen 7 9700X, 32 GB DDR5-6400, Windows 11 24H2. v2026.11.30.03 (`e1251c31`) + this PR at `99558945` + #4248, release build with `--features ab`. Series X, native 1440p, DLSS Performance, `VICTORY_HW_RT=1`, `VICTORY_RELAY=2`, warm cache, no `VICTORY_LAND_LEAVE`. `VICTORY_AB=30,VICTORY_GPU_OWNED,VICTORY_GUARD_FIRST`. Two runs: about 6 and 3 minutes of gameplay. ### 1. A 142-second stall in the first owned phase In run 1, the first phase with the switch on fell during the load into the world and produced **one frame of 142,038 ms**. The log has 69 × `a block's submission never published its fence; the block goes back to the eager path`, 2 s apart, and the first `GPU_OWNED:` line reads `timeouts=69 wait_ms=138031.8`. This fits the A/B start-up problem @⁠Marsietiss described (an on phase without what arming needs), although `came back without a COPY queue` never appeared in my log. Run 2 had no timeouts. ### 2. Under HW RT almost nothing qualifies (`no_beside`) Sums over all `GPU_OWNED:` lines: | | run 1 | run 2 | |---|---:|---:| | armed | 1,409 | 1,366 | | **no_beside** | **6,279,224** | **4,976,466** | | faults read / write | 199 / 18 | 177 / 30 | | brought back by refresh / guard / copy | 1,813 / 4,106 / 0 | 1,574 / 4,352 / 3 | | demoted | 6,205 | 6,136 | | dma_ms | 678 | 923 | If `no_beside` counts per block per arm while `armed` counts new blocks, the ratio overstates it. Still, with HW RT on, the bulk of the 89–97 MB/frame copy-back here seems to sit in memory without a second view. So the private-allocation phase is where HW RT would gain. Title faults are rare, as the census predicted. Our own refresh and guard paths bring back far more blocks than the title does. ### 3. Frame time by phase (direction only, 1–3 phases each) Mean ms per frame, gameplay phases at 6–9k draws: | | off | GPU_OWNED | GUARD_FIRST | both | |---|---:|---:|---:|---:| | run 1 | 73.3 | 89.4 | 83.8 | 78.8 | | run 2 | 61.6 | 68.5 | 58.9 | 58.0 | In run 1, BLAS prep per frame was higher in the owned phases: 20.7 and 18.0 ms against 8.5 and 7.6 ms. Run 2 is mixed (9.2 ms owned-only, 2.6 ms with both). It could be BLAS prep reading owned geometry on the CPU, but I haven't confirmed that. ### 4. Picture Run 1 had no visible problems. Run 2, with the same build and launcher, showed dark patches in ray-traced shadows indoors, worse than anything I saw before. It also logged 11 `a wait for a memory value was not met at a present` warnings, all within the first owned phase. I can't tie the patches to phases, and given the A/B start-up issue on this head, I wouldn't read much into it until a 4ea303fd run. A correction to my #2415 comment: these dark patches showed up here with **no** leave list at all. So I no longer think the two low-memory ranges caused the ones I saw with `VICTORY_LAND_LEAVE`. **Next:** the same route on 4ea303fd, once with A/B and once as separate eager and owned runs, with the 5 s `GPU_OWNED:` line and `in_flight`. (Analysis done with Claude Code.)
Author
Owner

@⁠shiman1901 on GitHub · 2026-12-01 01:26 UTC · original

Massive thanks for the real in-game telemetry @⁠MrDenn and the honest correction @⁠Marsietiss — those GPU_OWNED: counters just paid for themselves immediately!

  1. Root cause of the 142 s (69 × 2 s) stall found: that wasn't the A/B COPY-queue init bug — it's a self-deadlock inside arm() itself! When two overlapping Shadows declare the same 64 KiB block in the same arm(&items) call, the first arms the block with the submission's still-unpublished PendingFence, and a few iterations later the second hits arm_one's else { materialize_block(..., Caller::ReArm) } and waits the full 2,000 ms timeout on its own thread's unpublished PendingFence (69 overlapping blocks = 138 s). Easy 3-line fix (dedup items by block in arm() keeping the last writer + never wait on own slot) — I'll push that before you spend time re-running 4ea303f!
  2. Huge takeaway from the HW RT counters:
    • Title CPU faults are indeed tiny (199/18 and 177/30 over whole runs!).
    • Under VICTORY_HW_RT=1, the bulk of the 89–97 MB/frame copy-back sits in no_beside (6.28M / 4.98M skips) — confirming @⁠Marsietiss's census that private allocations are where the big HW RT win lives.
    • Our own guard (4,106 / 4,352) and refresh (1,813 / 1,574) paths are materializing (and demoting!) ~30× more blocks than the title CPU does, matching @⁠Marsietiss's "another copy covers one of its addresses" count and @⁠dyshay's note about internal readers.

I'll push the arm() same-submission dedup fix (and check MOST_VIEWS / internal-reader demotion) next so 4ea303f doesn't hit that 2 s × N stall on your next run. Thanks again for the crisp numbers!

**@⁠shiman1901** on GitHub · 2026-12-01 01:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7297502539) Massive thanks for the real in-game telemetry @⁠MrDenn and the honest correction @⁠Marsietiss — those `GPU_OWNED:` counters just paid for themselves immediately! 1. **Root cause of the 142 s (`69 × 2 s`) stall found:** that wasn't the A/B `COPY`-queue init bug — it's a self-deadlock inside `arm()` itself! When two overlapping `Shadow`s declare the same 64 KiB block in the same `arm(&items)` call, the first arms the block with the submission's still-unpublished `PendingFence`, and a few iterations later the second hits `arm_one`'s `else { materialize_block(..., Caller::ReArm) }` and waits the full 2,000 ms timeout on its own thread's unpublished `PendingFence` (69 overlapping blocks = 138 s). Easy 3-line fix (dedup `items` by block in `arm()` keeping the last writer + never wait on own `slot`) — I'll push that before you spend time re-running `4ea303f`! 2. **Huge takeaway from the HW RT counters:** - Title CPU faults are indeed tiny (`199/18` and `177/30` over whole runs!). - Under `VICTORY_HW_RT=1`, the bulk of the 89–97 MB/frame copy-back sits in `no_beside` (`6.28M` / `4.98M` skips) — confirming @⁠Marsietiss's census that private allocations are where the big HW RT win lives. - Our own `guard` (`4,106` / `4,352`) and `refresh` (`1,813` / `1,574`) paths are materializing (and demoting!) ~30× more blocks than the title CPU does, matching @⁠Marsietiss's "another copy covers one of its addresses" count and @⁠dyshay's note about internal readers. I'll push the `arm()` same-submission dedup fix (and check `MOST_VIEWS` / internal-reader demotion) next so `4ea303f` doesn't hit that 2 s × N stall on your next run. Thanks again for the crisp numbers!
Author
Owner

@⁠MrDenn on GitHub · 2026-12-01 01:51 UTC · original

@⁠shiman1901 thanks, that diagnosis fits. The first GPU_OWNED: line of my 99558945 run 1 has rearm=69 next to timeouts=69 and wait_ms=138031.8, so every timeout was a ReArm wait. I'd already run 4ea303fd before your reply, so here is that result as a check for the dedup fix.

4ea303fd reproduces it, and doesn't recover. Build: v2026.11.30.03 (e1251c31) + only 4ea303fd (cherry-picked cleanly; the branch's new base changes the translator), release with --features ab. RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance, VICTORY_HW_RT=1, warm cache, no leave list, VICTORY_AB=30,VICTORY_GPU_OWNED.

  • Phase 0 (off) covered the menu and the start of the load. When phase 1 (on) began, the per-second frame_times lines stopped and no frame was presented again.
  • After that the log has only a block's submission never published its fence, every 2.0 s, 15 times, until I closed the game after about 35 s. No GPU_OWNED: stat line came out, so there are no counters for this head.
  • On screen: heavy stutter, flickering black patches in the RT shadows, and blown-out highlights, as if auto-exposure were broken.

On 99558945 the same stall ended after 69 waits. Here it kept going, so on this head the scene seems to keep handing arm() overlapping blocks. Once the dedup fix is pushed I'll rerun this exact setup.

A correction to my previous comment. I wrote that the dark shadow patches appeared without a leave list, so the two low ranges probably weren't the cause. Since then:

  • The plain v2026.11.30.03 release, with and without VICTORY_LAND_LEAVE, loaded and played with no picture problems. The leave run used all 16 ranges, including the two low ones.
  • The bad patches only appeared with test builds: card-side geometry decode once, and this PR's head in every run where it switched on.

So the patches I reported look like stale bytes, not a general HW RT problem, and probably not the low ranges.

What's at stake under HW RT on this PC. The same release, same settings, back to back, short runs (2.6 and 3.0 min of play) on different routes:

eager static leave list (16 ranges, 134 MB)
fps 14.5 17.5
median frame 66.6 ms 55.0 ms
frames over 100 ms a minute 90 28

A lazy path that covers what the leave list covers, plus the private memory it can't, should be worth at least that.

@⁠Marsietiss: my counters only give no_beside, so I can't split refusals into "second copy over the page" against "9+ addresses". If a counter for that lands with the fix, I'll include it in the rerun.

(Analysis done with Claude Code.)

**@⁠MrDenn** on GitHub · 2026-12-01 01:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7297973949) @⁠shiman1901 thanks, that diagnosis fits. The first `GPU_OWNED:` line of my 99558945 run 1 has **`rearm=69` next to `timeouts=69`** and `wait_ms=138031.8`, so every timeout was a `ReArm` wait. I'd already run `4ea303fd` before your reply, so here is that result as a check for the dedup fix. **4ea303fd reproduces it, and doesn't recover.** Build: v2026.11.30.03 (`e1251c31`) + only `4ea303fd` (cherry-picked cleanly; the branch's new base changes the translator), release with `--features ab`. RTX 5080 16 GB, Ryzen 7 9700X, Series X 1440p, DLSS Performance, `VICTORY_HW_RT=1`, warm cache, no leave list, `VICTORY_AB=30,VICTORY_GPU_OWNED`. - Phase 0 (off) covered the menu and the start of the load. When phase 1 (on) began, the per-second `frame_times` lines stopped and no frame was presented again. - After that the log has only `a block's submission never published its fence`, every 2.0 s, 15 times, until I closed the game after about 35 s. No `GPU_OWNED:` stat line came out, so there are no counters for this head. - On screen: heavy stutter, flickering black patches in the RT shadows, and blown-out highlights, as if auto-exposure were broken. On 99558945 the same stall ended after 69 waits. Here it kept going, so on this head the scene seems to keep handing `arm()` overlapping blocks. Once the dedup fix is pushed I'll rerun this exact setup. **A correction to my previous comment.** I wrote that the dark shadow patches appeared without a leave list, so the two low ranges probably weren't the cause. Since then: - The plain v2026.11.30.03 release, with and without `VICTORY_LAND_LEAVE`, loaded and played with no picture problems. The leave run used all 16 ranges, including the two low ones. - The bad patches only appeared with test builds: card-side geometry decode once, and this PR's head in every run where it switched on. So the patches I reported look like stale bytes, not a general HW RT problem, and probably not the low ranges. **What's at stake under HW RT on this PC.** The same release, same settings, back to back, short runs (2.6 and 3.0 min of play) on different routes: | | eager | static leave list (16 ranges, 134 MB) | |---|---:|---:| | fps | 14.5 | 17.5 | | median frame | 66.6 ms | 55.0 ms | | frames over 100 ms a minute | 90 | 28 | A lazy path that covers what the leave list covers, plus the private memory it can't, should be worth at least that. @⁠Marsietiss: my counters only give `no_beside`, so I can't split refusals into "second copy over the page" against "9+ addresses". If a counter for that lands with the fix, I'll include it in the rerun. (Analysis done with Claude Code.)
Author
Owner

@⁠Marsietiss on GitHub · 2026-12-01 02:06 UTC · original

@⁠MrDenn @⁠shiman1901 something that may help with the stale-looking shadow patches. An independent code review of our own land-on-touch port tonight found these ways a held block goes stale. They come from reading our code, none has been seen in a game run, and I have not checked your head for them, so please treat them as things to look for:

  1. The hold test may prove too little. Ours proved that nobody wrote the block since the last asking, not that the owning copy took the whole block. If a refresh copies only 4 KiB of a 64 KiB block and the whole block is then held, later refreshes skip the rest and the card keeps old bytes in it. No race needed. Test: refresh 4 KiB, hold, read another 4 KiB of the block through the copy.
  2. Textures placed over a held page. If holding gives no write notice, a texture over the same memory is never marked due and keeps old texels. For a block written every frame, our idle sweep would never bring it back. This would look like dark patches that move with what is sampled. Test: a texture at a second address of a held page must show the new bytes.
  3. A second copy's refresh may be dropped before any hook. If the caller skips a refresh because title memory has not changed, a held page brings no change to title memory, so the second copy's draw reads its old bytes. A test that calls the refresh function directly will pass anyway; it has to go through the normal batch, with a copy that was already clean.
  4. DirectStorage to physical pages. A request whose destination is page numbers does not touch a CPU address, so nothing faults. If the landing hook runs after the data is in, the card's older bytes get merged over the new data.
  5. A released copy's flights. A buffer can leave the tables with a landing still in the air. Asking only the copies in the table misses it, and an older landing can end on top of a newer one.

On the stall, our send step takes the block's slot with a try-lock and sends a busy block to the late path, so it never waits on a fence. That may be a simpler shape than dedup: an overlapping block becomes late instead of waiting.

@⁠MrDenn for splitting refusals: the first two counts I would add are "another copy covers an address of this page" and "page at 9 or more addresses". In our count run the first was 2,400-3,000 blocks a frame. I will report our next split here once it is measured.

**@⁠Marsietiss** on GitHub · 2026-12-01 02:06 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7298248439) @⁠MrDenn @⁠shiman1901 something that may help with the stale-looking shadow patches. An independent code review of our own land-on-touch port tonight found these ways a held block goes stale. They come from reading our code, none has been seen in a game run, and I have not checked your head for them, so please treat them as things to look for: 1. **The hold test may prove too little.** Ours proved that nobody wrote the block since the last asking, not that the owning copy took the whole block. If a refresh copies only 4 KiB of a 64 KiB block and the whole block is then held, later refreshes skip the rest and the card keeps old bytes in it. No race needed. Test: refresh 4 KiB, hold, read another 4 KiB of the block through the copy. 2. **Textures placed over a held page.** If holding gives no write notice, a texture over the same memory is never marked due and keeps old texels. For a block written every frame, our idle sweep would never bring it back. This would look like dark patches that move with what is sampled. Test: a texture at a second address of a held page must show the new bytes. 3. **A second copy's refresh may be dropped before any hook.** If the caller skips a refresh because title memory has not changed, a held page brings no change to title memory, so the second copy's draw reads its old bytes. A test that calls the refresh function directly will pass anyway; it has to go through the normal batch, with a copy that was already clean. 4. **DirectStorage to physical pages.** A request whose destination is page numbers does not touch a CPU address, so nothing faults. If the landing hook runs after the data is in, the card's older bytes get merged over the new data. 5. **A released copy's flights.** A buffer can leave the tables with a landing still in the air. Asking only the copies in the table misses it, and an older landing can end on top of a newer one. On the stall, our send step takes the block's slot with a try-lock and sends a busy block to the late path, so it never waits on a fence. That may be a simpler shape than dedup: an overlapping block becomes late instead of waiting. @⁠MrDenn for splitting refusals: the first two counts I would add are "another copy covers an address of this page" and "page at 9 or more addresses". In our count run the first was 2,400-3,000 blocks a frame. I will report our next split here once it is measured.
github-bot force-pushed github-bot/gh-4526 from 4ea303fdd0 to 5592660778 2026-12-01 02:19:53 +00:00 Compare
Author
Owner

@⁠Marsietiss on GitHub · 2026-12-01 02:57 UTC · original

Update from our side, in case it helps the next heads of this PR.

  • I skimmed the doc comments of the diff of 559266077 against 4ea303fd (not the code line by line): the block dedup in arm() (last declaration wins), keeping and waking replaced slots, and the extra refusal counters for blocks at more addresses than the view cap and GPU-uncached pages are what MrDenn's 142 s stall asked for. I have not built or run it.
  • On our tree (code read, not a test) I looked for ways the title can learn a submission is done before its landing. Two are worth checking here too, since a held block makes them matter more:
    1. The null-event fence wait gives up after its timed window and returns an error; the title can go on while a block is still owned.
    2. Present and the frame origin return with submissions in flight unless a frame throttle is on; in our default it is off.
      Both exist on the eager path as well. A held block that the title reuses after one of these has no completion signal behind it. Suggested test: a held block, a flight that never finishes, a null-event wait; after it returns, the block must be brought back or the title's reuse refused.
  • File reads, DirectStorage and frees/remaps do not look at flights in our tree: a block that is owned when one of those lands under it needs its own rule.
  • Still true from my earlier note: we have no in-game number for the owned path, and our own port held 0 blocks. I am building a count that splits the refusals; it will be posted here.
**@⁠Marsietiss** on GitHub · 2026-12-01 02:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7299175727) Update from our side, in case it helps the next heads of this PR. - I skimmed the doc comments of the diff of `559266077` against `4ea303fd` (not the code line by line): the block dedup in `arm()` (last declaration wins), keeping and waking replaced slots, and the extra refusal counters for blocks at more addresses than the view cap and GPU-uncached pages are what MrDenn's 142 s stall asked for. I have not built or run it. - On our tree (code read, not a test) I looked for ways the title can learn a submission is done before its landing. Two are worth checking here too, since a held block makes them matter more: 1. The **null-event fence wait gives up** after its timed window and returns an error; the title can go on while a block is still owned. 2. **Present and the frame origin** return with submissions in flight unless a frame throttle is on; in our default it is off. Both exist on the eager path as well. A held block that the title reuses after one of these has no completion signal behind it. Suggested test: a held block, a flight that never finishes, a null-event wait; after it returns, the block must be brought back or the title's reuse refused. - File reads, DirectStorage and frees/remaps do not look at flights in our tree: a block that is owned when one of those lands under it needs its own rule. - Still true from my earlier note: we have no in-game number for the owned path, and our own port held 0 blocks. I am building a count that splits the refusals; it will be posted here.
github-bot force-pushed github-bot/gh-4526 from 5592660778 to 7afc5dd258 2026-12-01 10:30:40 +00:00 Compare
github-bot force-pushed github-bot/gh-4526 from 7afc5dd258 to b92e818831 2026-12-01 10:41:38 +00:00 Compare
github-bot force-pushed github-bot/gh-4526 from b92e818831 to c98eb22781 2026-12-01 10:59:02 +00:00 Compare
Author
Owner

@⁠shiman1901 on GitHub · 2026-12-01 11:04 UTC · original

Massive thanks @⁠MrDenn and @⁠Marsietiss — your live 5080 repro + stale-byte checklist caught every remaining bug, and all of them are now fixed in c98eb227:

1. Eliminated the 2 s × N arm() self-deadlock (a block's submission never published its fence):

  • arm() now iterates items.iter().rev() (last writer wins) tracking all armed blocks and their alias views in seen_blocks, checks Arc::ptr_eq(&f, slot) before taking block_lock or calling materialize_block(..., Caller::ReArm), and passes superseded slots into PendingFence::adopt so they wake cleanly on publish/drop.

2. Eliminated Caller::Guard = 4,106 stalls and HW RT geometry drops (hwrt.rs):

  • watch::guard() now skips GPU_OWNED blocks cleanly via is_owned / owned_word (keeping writes() returning Some so Memory::possible never poisons refused).
  • hwrt::readable_len and hwrt::read_geometries now materialize overlapping blocks via Caller::Hwrt.
  • Raised MOST_VIEWS from 8 → 64 and added many_views, uncached, hwrt, texture, and external counters to the 5 s GPU_OWNED: log line.

3. Closed all 5 stale-byte traps (flickering dark spots / overexposure):

  • Trap 1 (partial/whole overwrite & 4 KiB diff-merge): block_ready_for_gpu_owned now unconditionally requires copied[block / PAGE - start / PAGE] != 0 (also fixed an off-by-one for unaligned self.start; copy_stale only stamps a 64 KiB copied slot when the whole 64 KiB block was copied). More importantly, read_back no longer blindly memcpys 64 KiB: Shadow::merge_from_gpu_owned now diff-merges 4 KiB KERNEL_PAGE by 4 KiB KERNEL_PAGE against self.data, writing only GPU-changed bytes through beside (leaving untouched bytes/CPU writes intact) and returning the exact 16-bit changed_mask matching watch::PARTS / VICTORY_PAGE_PARTS=1.
  • Trap 2 (placed textures & writes_since + unconditional journal update): arm() notifies descriptor::host::remapped_ranges on the submitting thread (outside VEH) for all armed blocks/aliases; watch::writes_since materializes overlapping GPU_OWNED blocks (Caller::Texture); and watch::note_gpu_owned_landed unconditionally updates LANDED + JOURNAL/WRITTEN_EPOCHS (no is_kept() guard!) and returns (now, prev) so stamp_gpu_owned_pages only advances copied when prev <= cur (matching landed_beside — overlapping Shadow B always refreshes, unrefreshed CPU writes are never swallowed, and Shadow A doesn't echo).
  • Trap 3 (VICTORY_NEW_BATCH=1 / Shadow::new_look): added the all_owned_by / any_in_range gate to Shadow::new_look so batched nothing_new_all never skips a refresh on a block owned by another Shadow, and closed a copy_lock self-deadlock window in Shadow::update_ranges.
  • Trap 4 (DirectStorage / external writes): hooked gpu_owned::on_external_write(at, len) at the very top of both watch::title_memory_written (before mode & 4 == 0) and watch::stream_written (before !light()): full-block overwrites unreserve/discard without readback so stale GPU bytes never overwrite fresh DirectStorage loads, partial overlaps skip-merge around the external range, and ranges > 4096 blocks iterate ENTRIES so saturated lengths never hang.
  • Timeout behavior & 8th unit test (@⁠Marsietiss): wait_host now distinguishes device-removed (u64::MAX) from genuine GPU progress (up to 5 × 2 s windows while completed > prev, failing early only on zero progress for 2 s and logging at/shadow_id/value/completed), and added unpublished_fence_drop_or_timeout_unprotects_and_demotes (8 unit tests total).

Note: c98eb227 still keeps beside-only safety (so private WC allocations stay eager in no_beside for Phase 2 — getting section-view GPU_OWNED 100% stall-free and artifact-free first). CI Clippy confirms 0 errors / 0 warnings across all 8 changed files in both lib and lib test (only the 5 unrelated F1-menu Clippy lints currently on main 5fabb46e). Ready for a clean re-test whenever you have a moment!

**@⁠shiman1901** on GitHub · 2026-12-01 11:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7309132435) Massive thanks @⁠MrDenn and @⁠Marsietiss — your live 5080 repro + stale-byte checklist caught every remaining bug, and all of them are now fixed in `c98eb227`: **1. Eliminated the 2 s × N `arm()` self-deadlock (`a block's submission never published its fence`):** - `arm()` now iterates `items.iter().rev()` (last writer wins) tracking all armed blocks and their alias views in `seen_blocks`, checks `Arc::ptr_eq(&f, slot)` before taking `block_lock` or calling `materialize_block(..., Caller::ReArm)`, and passes superseded slots into `PendingFence::adopt` so they wake cleanly on publish/drop. **2. Eliminated `Caller::Guard = 4,106` stalls and HW RT geometry drops (`hwrt.rs`):** - `watch::guard()` now skips `GPU_OWNED` blocks cleanly via `is_owned` / `owned_word` (keeping `writes()` returning `Some` so `Memory::possible` never poisons `refused`). - `hwrt::readable_len` and `hwrt::read_geometries` now materialize overlapping blocks via `Caller::Hwrt`. - Raised `MOST_VIEWS` from `8` → `64` and added `many_views`, `uncached`, `hwrt`, `texture`, and `external` counters to the 5 s `GPU_OWNED:` log line. **3. Closed all 5 stale-byte traps (flickering dark spots / overexposure):** - **Trap 1 (partial/whole overwrite & 4 KiB diff-merge):** `block_ready_for_gpu_owned` now unconditionally requires `copied[block / PAGE - start / PAGE] != 0` (also fixed an off-by-one for unaligned `self.start`; `copy_stale` only stamps a 64 KiB `copied` slot when the whole 64 KiB block was copied). More importantly, `read_back` no longer blindly `memcpy`s 64 KiB: `Shadow::merge_from_gpu_owned` now diff-merges 4 KiB `KERNEL_PAGE` by 4 KiB `KERNEL_PAGE` against `self.data`, writing **only GPU-changed bytes** through `beside` (leaving untouched bytes/CPU writes intact) and returning the exact 16-bit `changed_mask` matching `watch::PARTS` / `VICTORY_PAGE_PARTS=1`. - **Trap 2 (placed textures & `writes_since` + unconditional journal update):** `arm()` notifies `descriptor::host::remapped_ranges` on the submitting thread (outside VEH) for all armed blocks/aliases; `watch::writes_since` materializes overlapping `GPU_OWNED` blocks (`Caller::Texture`); and `watch::note_gpu_owned_landed` unconditionally updates `LANDED` + `JOURNAL`/`WRITTEN_EPOCHS` (no `is_kept()` guard!) and returns `(now, prev)` so `stamp_gpu_owned_pages` only advances `copied` when `prev <= cur` (matching `landed_beside` — overlapping `Shadow B` always refreshes, unrefreshed CPU writes are never swallowed, and `Shadow A` doesn't echo). - **Trap 3 (`VICTORY_NEW_BATCH=1` / `Shadow::new_look`):** added the `all_owned_by` / `any_in_range` gate to `Shadow::new_look` so batched `nothing_new_all` never skips a refresh on a block owned by another `Shadow`, and closed a `copy_lock` self-deadlock window in `Shadow::update_ranges`. - **Trap 4 (DirectStorage / external writes):** hooked `gpu_owned::on_external_write(at, len)` at the very top of both `watch::title_memory_written` (before `mode & 4 == 0`) and `watch::stream_written` (before `!light()`): full-block overwrites unreserve/discard without readback so stale GPU bytes never overwrite fresh DirectStorage loads, partial overlaps skip-merge around the external range, and ranges > 4096 blocks iterate `ENTRIES` so saturated lengths never hang. - **Timeout behavior & 8th unit test (@⁠Marsietiss):** `wait_host` now distinguishes device-removed (`u64::MAX`) from genuine GPU progress (up to 5 × 2 s windows while `completed > prev`, failing early only on zero progress for 2 s and logging `at`/`shadow_id`/`value`/`completed`), and added `unpublished_fence_drop_or_timeout_unprotects_and_demotes` (8 unit tests total). Note: `c98eb227` still keeps `beside`-only safety (so private WC allocations stay eager in `no_beside` for Phase 2 — getting section-view `GPU_OWNED` 100% stall-free and artifact-free first). CI Clippy confirms **0 errors / 0 warnings** across all 8 changed files in both `lib` and `lib test` (only the 5 unrelated F1-menu Clippy lints currently on `main` `5fabb46e`). Ready for a clean re-test whenever you have a moment!
Author
Owner

@⁠Marsietiss on GitHub · 2026-12-01 11:05 UTC · original · edited 2026-12-01 11:20 UTC

Thanks for going through all of them, and for the 64-view change and the diff-merge in merge_from_gpu_owned.

I have not run c98eb227 yet and won't promise a date, my test queue is full today. When I do, I'll use the RTX 5080 and the setup I used before, and I'll report counts (held blocks, the refusal reasons, Caller::* stalls) and what the picture does, including if it holds nothing.

Two questions I'd like to check there, not findings:

  1. Holding now needs the whole 64 KiB block copied (copied[...] != 0). Does that raise the refusals for blocks that a copy covers only in part, and is that visible in the 5 s line?
  2. In wait_host, up to 5 windows of 2 s while progress is seen: what happens to the title thread that waits on the fence meanwhile, does the title's own wait limit (about 2 s on some paths) run out first?
**@⁠Marsietiss** on GitHub · 2026-12-01 11:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7309165818) · edited 2026-12-01 11:20 UTC Thanks for going through all of them, and for the 64-view change and the diff-merge in `merge_from_gpu_owned`. I have not run `c98eb227` yet and won't promise a date, my test queue is full today. When I do, I'll use the RTX 5080 and the setup I used before, and I'll report counts (held blocks, the refusal reasons, `Caller::*` stalls) and what the picture does, including if it holds nothing. Two questions I'd like to check there, not findings: 1. Holding now needs the whole 64 KiB block copied (`copied[...] != 0`). Does that raise the refusals for blocks that a copy covers only in part, and is that visible in the 5 s line? 2. In `wait_host`, up to 5 windows of 2 s while progress is seen: what happens to the title thread that waits on the fence meanwhile, does the title's own wait limit (about 2 s on some paths) run out first?
Author
Owner

@⁠shiman1901 on GitHub · 2026-12-01 11:18 UTC · original

Thanks @⁠Marsietiss — no rush at all, whenever it fits your queue! Quick answers to your two questions:

  1. copied[...] != 0 refusals & telemetry: blocks only partly covered by a copy are already rejected earlier by block < start || block_end > end (and copy_stale only stamps a 64 KiB copied slot when the whole 64 KiB block was copied). Removing the !whole_write bypass can increase rejections for whole-inside-copy blocks that were never uploaded from CPU first (copied[idx] == 0, e.g. GPU-initialized UAVs). Right now those early rejections aren't broken out on the 5 s GPU_OWNED: line (only no_beside, many_views, and uncached are) — happy to add an uncopied= counter in the next pass if armed drops noticeably on your 5080 run.
  2. Up to 5 × 2 s windows in wait_host: inside VEH, the faulting title thread is suspended inside our handler (not running its own wait loop), though another title thread waiting on that thread or on a GPU fence could hit a ~2 s timeout if the card genuinely stalls > 2 s. Normal in-flight frames finish in ~30–60 ms (well inside window 1); the extra windows only trigger if the fence is visibly advancing (completed > prev, e.g. heavy shader compile) and log slow to reach a block's fence, still waiting on the very first 2 s mark so any real stall is immediately visible and tunable.
**@⁠shiman1901** on GitHub · 2026-12-01 11:18 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7309471264) Thanks @⁠Marsietiss — no rush at all, whenever it fits your queue! Quick answers to your two questions: 1. **`copied[...] != 0` refusals & telemetry:** blocks only partly covered by a copy are already rejected earlier by `block < start || block_end > end` (and `copy_stale` only stamps a 64 KiB `copied` slot when the whole 64 KiB block was copied). Removing the `!whole_write` bypass can increase rejections for whole-inside-copy blocks that were never uploaded from CPU first (`copied[idx] == 0`, e.g. GPU-initialized UAVs). Right now those early rejections aren't broken out on the 5 s `GPU_OWNED:` line (only `no_beside`, `many_views`, and `uncached` are) — happy to add an `uncopied=` counter in the next pass if `armed` drops noticeably on your 5080 run. 2. **Up to 5 × 2 s windows in `wait_host`:** inside VEH, the faulting title thread is suspended inside our handler (not running its own wait loop), though another title thread waiting on that thread or on a GPU fence could hit a ~2 s timeout if the card genuinely stalls > 2 s. Normal in-flight frames finish in ~30–60 ms (well inside window 1); the extra windows only trigger if the fence is visibly advancing (`completed > prev`, e.g. heavy shader compile) and log `slow to reach a block's fence, still waiting` on the very first 2 s mark so any real stall is immediately visible and tunable.
Author
Owner

@⁠Ondra97 on GitHub · 2026-12-01 15:07 UTC · original

On head c98eb227, I reproduced an alias-unmap bug in GPU_OWNED. When one title view of an owned physical page is unmapped, drop_range removes the entry for every alias and clears its ownership bits, but a surviving view remains PAGE_NOACCESS. Its next CPU access has no handler entry. A Windows regression with two title views and a separate host view fails on the PR head (PAGE_NOACCESS 1 vs PAGE_READWRITE 4). A local fix materializes GPU bytes before removing the entry when any alias survives. The test verifies both restored protection and updated bytes; all 9 gpu_owned tests and targeted Clippy pass. This is synthetic validation; I have not run the game. I can share the one-file diff.

**@⁠Ondra97** on GitHub · 2026-12-01 15:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7315396364) On head `c98eb227`, I reproduced an alias-unmap bug in `GPU_OWNED`. When one title view of an owned physical page is unmapped, `drop_range` removes the entry for every alias and clears its ownership bits, but a surviving view remains `PAGE_NOACCESS`. Its next CPU access has no handler entry. A Windows regression with two title views and a separate host view fails on the PR head (`PAGE_NOACCESS` 1 vs `PAGE_READWRITE` 4). A local fix materializes GPU bytes before removing the entry when any alias survives. The test verifies both restored protection and updated bytes; all 9 `gpu_owned` tests and targeted Clippy pass. This is synthetic validation; I have not run the game. I can share the one-file diff.
github-bot force-pushed github-bot/gh-4526 from c98eb22781 to 66b4b14b6a 2026-12-01 16:23:31 +00:00 Compare
Author
Owner

@⁠shiman1901 on GitHub · 2026-12-01 16:26 UTC · original

Great catch @⁠Ondra97 — fixed in 66b4b14b along with a 9th unit test (unmapping_one_alias_materializes_and_unprotects_surviving_view):

  • drop_range with surviving aliases (gpu_owned.rs): entries overlapping the dropped range [first, last) are now partitioned into surviving (at least one alias view lies outside first..last) and gone (all views lie inside first..last). For surviving entries, drop_range calls materialize_block(canonical, true, false, Caller::Sweep) before removal — writing the card's bytes through beside, restoring the saved protection (PAGE_READWRITE) on surviving views via unreserve, and demoting the surviving view to eager — and then clears OWNED_BITS / DEMOTED_BITS on the unmapped range first..last.
  • Unit test #9: maps two title views (view1, view2) + a separate host view (beside) over one 64 KiB section, arms both title views as PAGE_NOACCESS, calls drop_range(view1, BLOCK), and asserts VirtualQuery(view2).Protect == PAGE_READWRITE (4) and all 64 KiB read through view2 match the materialized pattern (0x7B).

CI Clippy (66b4b14b) confirms 0 errors / 0 warnings across all 8 files in lib and lib test (only the 5 unrelated F1-menu lints currently on main 5fabb46e).

**@⁠shiman1901** on GitHub · 2026-12-01 16:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7317623952) Great catch @⁠Ondra97 — fixed in `66b4b14b` along with a 9th unit test (`unmapping_one_alias_materializes_and_unprotects_surviving_view`): - **`drop_range` with surviving aliases (`gpu_owned.rs`):** entries overlapping the dropped range `[first, last)` are now partitioned into `surviving` (at least one alias view lies outside `first..last`) and `gone` (all views lie inside `first..last`). For `surviving` entries, `drop_range` calls `materialize_block(canonical, true, false, Caller::Sweep)` before removal — writing the card's bytes through `beside`, restoring the saved protection (`PAGE_READWRITE`) on surviving views via `unreserve`, and demoting the surviving view to eager — and then clears `OWNED_BITS` / `DEMOTED_BITS` on the unmapped range `first..last`. - **Unit test #9:** maps two title views (`view1`, `view2`) + a separate host view (`beside`) over one 64 KiB section, arms both title views as `PAGE_NOACCESS`, calls `drop_range(view1, BLOCK)`, and asserts `VirtualQuery(view2).Protect == PAGE_READWRITE (4)` and all 64 KiB read through `view2` match the materialized pattern (`0x7B`). CI Clippy (`66b4b14b`) confirms 0 errors / 0 warnings across all 8 files in `lib` and `lib test` (only the 5 unrelated F1-menu lints currently on `main` `5fabb46e`).
github-bot closed this pull request 2026-12-01 18:43:11 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:38 UTC · original

Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4526#issuecomment-7321267939) Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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/trustno1-coder--VIctory-NVIDIA!4527
No description provided.