VICTORY_WAIT_RESIDENT's synchronous MakeResident costs 40-80 s in a few minutes of play on an 8 GB NVIDIA card (single waits up to 205 ms) #371

Open
opened 2026-11-26 19:47:02 +00:00 by github-bot · 2 comments
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 19:45 UTC · original

VICTORY_WAIT_RESIDENT (on by default since 0322b39) makes every new heap or resource wait for a synchronous MakeResident on the thread that made it. On an 8 GB NVIDIA card that wait adds up to 40-80 s in a few minutes of play, with single waits up to 205 ms.

Where

crates/victory-gpu/src/host.rs:341-348 at c9c932c:

pub(crate) fn resident(device: &ID3D12Device, object: &impl Interface) -> windows::core::Result<()> {
    if !wait_resident() {
        return Ok(());
    }
    let started = std::time::Instant::now();
    let object: ID3D12Pageable = object.cast()?;
    // SAFETY: a live heap or resource of the device's.
    let made = unsafe { device.MakeResident(&[Some(object)]) };

Why it matters

The switch's own log line, RTX 2070 SUPER 8 GB, Ryzen 7 5800X, 32 GB, driver 621.14:

run length new memory waited for, since the start
c9c932c, Series X about 4.5 min 112,000 times, 41.9 s, the longest 196.5 ms
c9c932c + open PRs, Series S, DLSS about 5 min 300,000 times, 81.1 s, the longest 117.6 ms
same, another run about 4 min 164,000 times, 39.8 s, the longest 205.3 ms

Frames there take 355-430 ms with the card about half idle (see the hardware report #370). These waits are summed over all threads, so not all of them sit on the frame's critical path. Waits of up to 200 ms on whatever thread makes memory are a likely part of the long frames (p90 460-930 ms). On this card the budget is tight: 6.5 GB, 5.5 GB in use, "passes that made none for lack of room: 992".

The wait guards against real device losses (the comment on wait_resident, run n08 on 2026-11-25), so it shouldn't simply be turned off.

Suggestion

  • ID3D12Device3::EnqueueMakeResident with a fence, and a GPU-side wait (ID3D12CommandQueue::Wait) on the queue whose lists name the new memory. That keeps the guarantee (no list runs before the mapping) without a CPU wait. The tree already does this in indirect.rs:1953.
  • Fewer new heaps: count the callers by kind and size first. Sub-allocating from larger pooled heaps (as the texture pool does) would make most of these calls go away.
  • A test: memory made and named by a list in the same submission, with the queue's wait checked on WARP.

Not checked

Only the counters and the source above. I have not timed which thread these waits fall on, or how much of them is on the path to Present. A VICTORY_TIMELINE capture would show that, and I will add it. I have not tried VICTORY_WAIT_RESIDENT=0 here, because of the device losses it guards against.

AI use

AI-assisted (Claude Code): log reading and source reading. Runs played by me; no game files attached.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 19:45 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/371) `VICTORY_WAIT_RESIDENT` (on by default since `0322b39`) makes every new heap or resource wait for a synchronous `MakeResident` on the thread that made it. On an 8 GB NVIDIA card that wait adds up to 40-80 s in a few minutes of play, with single waits up to 205 ms. ## Where `crates/victory-gpu/src/host.rs:341-348` at `c9c932c`: ```rust pub(crate) fn resident(device: &ID3D12Device, object: &impl Interface) -> windows::core::Result<()> { if !wait_resident() { return Ok(()); } let started = std::time::Instant::now(); let object: ID3D12Pageable = object.cast()?; // SAFETY: a live heap or resource of the device's. let made = unsafe { device.MakeResident(&[Some(object)]) }; ``` ## Why it matters The switch's own log line, RTX 2070 SUPER 8 GB, Ryzen 7 5800X, 32 GB, driver 621.14: | run | length | new memory waited for, since the start | |---|---|---| | `c9c932c`, Series X | about 4.5 min | 112,000 times, **41.9 s**, the longest 196.5 ms | | `c9c932c` + open PRs, Series S, DLSS | about 5 min | 300,000 times, **81.1 s**, the longest 117.6 ms | | same, another run | about 4 min | 164,000 times, **39.8 s**, the longest 205.3 ms | Frames there take 355-430 ms with the card about half idle (see the hardware report #370). These waits are summed over all threads, so not all of them sit on the frame's critical path. Waits of up to 200 ms on whatever thread makes memory are a likely part of the long frames (p90 460-930 ms). On this card the budget is tight: 6.5 GB, 5.5 GB in use, "passes that made none for lack of room: 992". The wait guards against real device losses (the comment on `wait_resident`, run n08 on 2026-11-25), so it shouldn't simply be turned off. ## Suggestion - `ID3D12Device3::EnqueueMakeResident` with a fence, and a GPU-side wait (`ID3D12CommandQueue::Wait`) on the queue whose lists name the new memory. That keeps the guarantee (no list runs before the mapping) without a CPU wait. The tree already does this in `indirect.rs:1953`. - Fewer new heaps: count the callers by kind and size first. Sub-allocating from larger pooled heaps (as the texture pool does) would make most of these calls go away. - A test: memory made and named by a list in the same submission, with the queue's wait checked on WARP. ## Not checked Only the counters and the source above. I have not timed which thread these waits fall on, or how much of them is on the path to Present. A `VICTORY_TIMELINE` capture would show that, and I will add it. I have not tried `VICTORY_WAIT_RESIDENT=0` here, because of the device losses it guards against. ## AI use AI-assisted (Claude Code): log reading and source reading. Runs played by me; no game files attached.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:47:02 +00:00
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 20:25 UTC · original

Most of these waits have a known cause now, see #367 (same PC, runs B and D are the ones above):

  • 85-91 % of the "new memory waited for" calls come from shadow::exact's own-bytes copies: about 330 shared buffers a frame, made under one lock, each made resident and mapped (the cause #221 describes).
  • That lock is held on the translation threads, so these waits are on the path to Present: the threads spend 75-85 % of the frame waiting behind it.
  • With pr0vId3nce's own-bytes pool (#221; VIctory-NVIDIA 67a50c6 + 835d4e8) the count fell from 164,000-300,000 to 27,000 in a short run, and the frame from 353 to 266 ms.

So for this issue, what is left is the other 9-15 % of the callers. Moving MakeResident off the CPU (EnqueueMakeResident plus a queue wait) still applies to them, but it matters much less once the pool is in.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 20:25 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/371#issuecomment-7202654005) Most of these waits have a known cause now, see #367 (same PC, runs B and D are the ones above): - 85-91 % of the "new memory waited for" calls come from `shadow::exact`'s own-bytes copies: about 330 shared buffers a frame, made under one lock, each made resident and mapped (the cause #221 describes). - That lock is held on the translation threads, so these waits are on the path to Present: the threads spend 75-85 % of the frame waiting behind it. - With pr0vId3nce's own-bytes pool (#221; VIctory-NVIDIA 67a50c6 + 835d4e8) the count fell from 164,000-300,000 to 27,000 in a short run, and the frame from 353 to 266 ms. So for this issue, what is left is the other 9-15 % of the callers. Moving `MakeResident` off the CPU (`EnqueueMakeResident` plus a queue wait) still applies to them, but it matters much less once the pool is in.
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 21:24 UTC · original

Building on the comment above: what is left with the own-bytes pool in, from an ordinary build on the same PC.

  • Build: local test at b9b32e4 (main with open PRs, the pool from #221, card buffers of 64 KiB to 1024 MB).
  • Run: Series S, DLSS, about 4 minutes of play (run H).
runs B / D above (no pool) run H (pool)
new memory waited for, since the start 164,000-300,000 times, 39.8-81.1 s 38,000 times, 24.7 s, the longest 592 ms
new card memory waited for until mapped — 30,000 times, 7.3 s, the longest 35 ms
frame, median / p90 353-371 ms / 460-930 156 / 238 ms
card busy 30-62 % 98 %
  • The median frame: with the card 98 % busy, the remaining waits no longer set it on this PC.

  • They are still not small: about 6 s a minute summed over threads, with single waits up to 592 ms. Waits that long on a thread the title needs would show as hitches.

  • The timeline can't say which ones those are. host::resident() and mapped() have no timeline span of their own, so their waits show up only as anonymous kernel waits.

  • A useful next step:

    • a timeline::span("new memory: resident") in resident(), and one in mapped();
    • a caller tag on the counter.

    That would show whether the 592 ms waits sit on the path to a Present, and from which kind of memory (textures, upload or card buffers).

AI use: log reading and write-up with AI assistance (Claude Code). The runs are my own.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 21:24 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/issues/371#issuecomment-7203690682) Building on the comment above: what is left with the own-bytes pool in, from an ordinary build on the same PC. - Build: local `test` at `b9b32e4` (main with open PRs, the pool from #221, card buffers of 64 KiB to 1024 MB). - Run: Series S, DLSS, about 4 minutes of play (run H). | | runs B / D above (no pool) | run H (pool) | |---|---|---| | new memory waited for, since the start | 164,000-300,000 times, 39.8-81.1 s | 38,000 times, **24.7 s**, the longest **592 ms** | | new card memory waited for until mapped | — | 30,000 times, 7.3 s, the longest 35 ms | | frame, median / p90 | 353-371 ms / 460-930 | 156 / 238 ms | | card busy | 30-62 % | 98 % | - **The median frame:** with the card 98 % busy, the remaining waits no longer set it on this PC. - **They are still not small:** about 6 s a minute summed over threads, with single waits up to 592 ms. Waits that long on a thread the title needs would show as hitches. - **The timeline can't say which ones those are.** `host::resident()` and `mapped()` have no timeline span of their own, so their waits show up only as anonymous kernel waits. - **A useful next step:** - a `timeline::span("new memory: resident")` in `resident()`, and one in `mapped()`; - a caller tag on the counter. That would show whether the 592 ms waits sit on the path to a Present, and from which kind of memory (textures, upload or card buffers). AI use: log reading and write-up with AI assistance (Claude Code). The runs are my own.
This discussion has been locked. Commenting is limited to contributors.
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/avatarmanz--VIctory-7900XTX#371
No description provided.