CPU-bound frames: read-back lock fix, drop causes and refresh census, opt-in APU async and upload headroom #3271

Open
B0tis wants to merge 9 commits from upstream-pr/3271 into main
B0tis commented 2026-11-29 21:11:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by B0tis on 2026-11-29T21:11:30Z.


[pr-performance] [pr-diagnostics]

What it changes

In heavy open-world scenes the frame is CPU-bound: lowering the render resolution does not raise fps. This PR removes one lock that held list threads up, adds two cheap log lines that show where the CPU time goes, and adds two opt-in switches. Defaults change nowhere except the lock fix and the log lines.

Fix

  • Read backs no longer hold the pool's lock while a buffer is created (Host::read_back_buffer). The lock was held across CreateCommittedResource, even with the pool off, so every list thread that closed a list with read backs waited for the other threads' buffer creations. This hurts most under host memory pressure, when read-back buffers are made anew every frame.

Diagnostics (release builds, every 5 s)

  • dropped draws and dispatches by cause, per frame: every silent exit in prepare_for, bind, rectangles and dispatch now records a cause (no pipeline, root, table slots, memory views, index, builder stage off, …). This separates real losses from expected ones. In the scenes measured, nearly all drops were ray-tracing builder stages that are switched off.
  • refresh census per frame and refresh census by kind per frame (VICTORY_REFRESH_CENSUS=0 turns them off):
    • the host copies with the most refreshed bytes;
    • per kind (write-watched or guarded, with or without a card copy): updates, MB and ms;
    • the asking time, split into three parts: waiting for another thread's asking, the kernel's write watch, and the guards.

Opt-in switches (off by default)

  • VICTORY_TEXTURE_FIRST_UPLOAD_CARD_HEADROOM_MB=<MB>: first uploads leave this much of the card's budget free. The existing 80% ceiling counts texture copies only, so a burst of first uploads can fill a small card, and every upload after it waits. On 8 GB cards, 768 kept the upload queue moving.
  • VICTORY_APU_ASYNC=1: each XApu connection gets a worker thread that produces the results (Opus decode, conversion), as the console's audio processor does. The title dequeues a result once it is ready. This takes most of a core's work off the title's busiest thread. Whether fps rises depends on whether that thread limits the frame.

Bench

  • bench.ps1 -SeriesS and -Dlss ultraperformance.

How it was tested

  • GPU and profile:
    • RTX 3070 8 GB, Ryzen 7 5800X3D, 32 GB DDR4-3200.
    • Series S, DLSS performance, frame generation off (the bench reports rendered fps).
    • A heavy spot from a fixed save: about 8,000 draws a frame.
  • Bench command: bench.ps1 -SeriesS -Dlss performance -FrameGen off -Seconds 150 -Warmup 45. The diagnostics build needs #2498 (or #2744 / #2593 / #2386) and the frame-line wording from #2475. Identical runs differ by up to ±0.6 fps.
  • Before: 15.8–15.9 fps median.
  • After, with this fix plus the existing switches listed below as helping: about 16.5–17 fps. The resolution test: DLSS ultra performance gave no gain.
  • cargo test -p victory-gpu --lib: 914 pass. The one failure, every_switch_of_the_translator_is_in_the_key, also fails on main, because VICTORY_SCALAR_SPLITS stayed in the key list after the revert a1fe8350.
  • cargo test -p victory-hle --lib: 423 pass.
  • cargo clippy -p victory-gpu -p victory-hle --lib --no-deps -D warnings: clean on the lines this PR touches.

Notes for further CPU work (not part of the diff)

  • Existing switches that helped in the bench:

    • VICTORY_READ_BACK_POOL=1
    • TABLE_SAME, ROOT_SAME, ROOT_TAILS, THIN_COALESCE
    • VICTORY_SETTLE_UNLOCKED=1: in WPR, the submitting thread's waits inside submit fell from 67 to 11.5 ms/s.
  • No gain or worse in the bench:

    • more or fewer list threads (THIN_THREADS)
    • TITLE_AFFINITY, SUBMIT_CORE_ALONE
    • KEEP_GUARD_LOCK + ALIAS_DIRECT
    • LAZY_COMPARE
  • Where the time goes: on a timeline of heavy frames, the critical chain was spread across these:

    • long list calls;
    • threads woken but not yet running (CPU oversubscription);
    • refreshes;
    • translation of single big lists on one thread;
    • the card itself.

    The card's idle time is mostly the submitting thread. Only about 7% of lists repeat word for word, so translation reuse would not pay.

  • Guarded view memory: the streamed windows, remapped page by page, are the costliest kind of refresh. The cost is guards-mutex contention and VirtualProtect under the lock, not copying.

  • Tried for guarded view memory and dropped:

    • Leaving hot blocks unguarded: they never became clean, so every asking took the slow path.
    • A try-lock in publish(): publishings were skipped and refreshes got slower.
    • A lock-free "open for the frame" state: whole 64 KiB blocks were copied instead of 4 KiB parts.

    In-place reads are not possible for these windows (scattered single 64 KiB views). For the constants heap they lose on Ampere (#1223).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    • #2498, #2744, #2593, #2386: the diagnostics build fix
    • #2475: the bench frame-line wording
    • #2334: performance on 8 GB cards
    • #2015: read-back buffers under pressure (a different change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555164772 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3271). Originally posted by [B0tis](https://github.com/B0tis) on 2026-11-29T21:11:30Z. --- [pr-performance] [pr-diagnostics] ## What it changes In heavy open-world scenes the frame is CPU-bound: lowering the render resolution does not raise fps. This PR removes one lock that held list threads up, adds two cheap log lines that show where the CPU time goes, and adds two opt-in switches. Defaults change nowhere except the lock fix and the log lines. **Fix** - **Read backs no longer hold the pool's lock while a buffer is created** (`Host::read_back_buffer`). The lock was held across `CreateCommittedResource`, even with the pool off, so every list thread that closed a list with read backs waited for the other threads' buffer creations. This hurts most under host memory pressure, when read-back buffers are made anew every frame. **Diagnostics** (release builds, every 5 s) - `dropped draws and dispatches by cause, per frame`: every silent exit in `prepare_for`, `bind`, `rectangles` and `dispatch` now records a cause (no pipeline, root, table slots, memory views, index, builder stage off, …). This separates real losses from expected ones. In the scenes measured, nearly all drops were ray-tracing builder stages that are switched off. - `refresh census per frame` and `refresh census by kind per frame` (`VICTORY_REFRESH_CENSUS=0` turns them off): - the host copies with the most refreshed bytes; - per kind (write-watched or guarded, with or without a card copy): updates, MB and ms; - the asking time, split into three parts: waiting for another thread's asking, the kernel's write watch, and the guards. **Opt-in switches** (off by default) - `VICTORY_TEXTURE_FIRST_UPLOAD_CARD_HEADROOM_MB=<MB>`: first uploads leave this much of the card's budget free. The existing 80% ceiling counts texture copies only, so a burst of first uploads can fill a small card, and every upload after it waits. On 8 GB cards, 768 kept the upload queue moving. - `VICTORY_APU_ASYNC=1`: each XApu connection gets a worker thread that produces the results (Opus decode, conversion), as the console's audio processor does. The title dequeues a result once it is ready. This takes most of a core's work off the title's busiest thread. Whether fps rises depends on whether that thread limits the frame. **Bench** - `bench.ps1 -SeriesS` and `-Dlss ultraperformance`. ## How it was tested - GPU and profile: - RTX 3070 8 GB, Ryzen 7 5800X3D, 32 GB DDR4-3200. - Series S, DLSS performance, frame generation off (the bench reports rendered fps). - A heavy spot from a fixed save: about 8,000 draws a frame. - Bench command: `bench.ps1 -SeriesS -Dlss performance -FrameGen off -Seconds 150 -Warmup 45`. The diagnostics build needs #2498 (or #2744 / #2593 / #2386) and the frame-line wording from #2475. Identical runs differ by up to ±0.6 fps. - Before: 15.8–15.9 fps median. - After, with this fix plus the existing switches listed below as helping: about 16.5–17 fps. The resolution test: DLSS ultra performance gave no gain. - `cargo test -p victory-gpu --lib`: 914 pass. The one failure, `every_switch_of_the_translator_is_in_the_key`, also fails on main, because `VICTORY_SCALAR_SPLITS` stayed in the key list after the revert a1fe8350. - `cargo test -p victory-hle --lib`: 423 pass. - `cargo clippy -p victory-gpu -p victory-hle --lib --no-deps -D warnings`: clean on the lines this PR touches. ### Notes for further CPU work (not part of the diff) - **Existing switches that helped in the bench:** - `VICTORY_READ_BACK_POOL=1` - `TABLE_SAME`, `ROOT_SAME`, `ROOT_TAILS`, `THIN_COALESCE` - `VICTORY_SETTLE_UNLOCKED=1`: in WPR, the submitting thread's waits inside `submit` fell from 67 to 11.5 ms/s. - **No gain or worse in the bench:** - more or fewer list threads (`THIN_THREADS`) - `TITLE_AFFINITY`, `SUBMIT_CORE_ALONE` - `KEEP_GUARD_LOCK` + `ALIAS_DIRECT` - `LAZY_COMPARE` - **Where the time goes:** on a timeline of heavy frames, the critical chain was spread across these: - long list calls; - threads woken but not yet running (CPU oversubscription); - refreshes; - translation of single big lists on one thread; - the card itself. The card's idle time is mostly the submitting thread. Only about 7% of lists repeat word for word, so translation reuse would not pay. - **Guarded view memory:** the streamed windows, remapped page by page, are the costliest kind of refresh. The cost is guards-mutex contention and `VirtualProtect` under the lock, not copying. - **Tried for guarded view memory and dropped:** - **Leaving hot blocks unguarded:** they never became clean, so every asking took the slow path. - **A try-lock in `publish()`:** publishings were skipped and refreshes got slower. - **A lock-free "open for the frame" state:** whole 64 KiB blocks were copied instead of 4 KiB parts. In-place reads are not possible for these windows (scattered single 64 KiB views). For the constants heap they lose on Ampere (#1223). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - #2498, #2744, #2593, #2386: the diagnostics build fix - #2475: the bench frame-line wording - #2334: performance on 8 GB cards - #2015: read-back buffers under pressure (a different change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
madvillain91 commented 2026-11-29 23:19:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by madvillain91 on 2026-11-29T23:19:19Z.


System Information:

  • GPU: NVIDIA GeForce RTX 3070 Ti 8GB
  • Windows 11 Pro, Build 26300.9711

Summary of Test Session:

  • FPS: Held almost static at 15 FPS in open world.
  • Gameplay/Feel: No stutter spikes, hitches, lock-ups, or severe micro-pauses detected. Performance was extremely consistent, even if capped/low. Movement (vehicular/on-foot) remained smooth for the full session.
  • Stability: No crash or freeze. Game started cleanly; no device errors, read-back lock errors, or submission issues in log.
  • Visuals: Asset streaming, shadow rendering, and LOD selection appeared stable. No new artefacts detected.

Technical Highlights from Log:

  • All "queue," "frame," "async," "lock," and "read-back" log lines completed without warning or error.
  • The system utilized VICTORY_ASYNC_SUBMIT (async submit logic) and managed frames/submissions according to PR goals.
  • Median/p95 frametimes (GPU-side) were extremely low (1–2 ms, p99 up to 12 ms), indicating true CPU-side cap or scheduler bottleneck, not a rendering/sync bug.
  • Log indicates subtle improvement in frame pacing—frames presented and dispatched in sync, little evidence of CPU-GPU sync slippage or excessive flushes.

Notes/Outcome:

    • Game is now very consistent and stable from a CPU submission perspective.
  • – Overall FPS is unusually capped/low for this GPU, but this appears unrelated to submission, lock, or read-back errors.
  • Would recommend investigating further or combining with profiling/optimization PRs to push FPS up while maintaining current smoothness and stability.

Attachment:
victory-nvidia-play-20261129-231142-33492.log

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7264370873 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3271#issuecomment-7264370873). Originally posted by [madvillain91](https://github.com/madvillain91) on 2026-11-29T23:19:19Z. --- System Information: - GPU: NVIDIA GeForce RTX 3070 Ti 8GB - Windows 11 Pro, Build 26300.9711 Summary of Test Session: - FPS: Held almost static at 15 FPS in open world. - Gameplay/Feel: No stutter spikes, hitches, lock-ups, or severe micro-pauses detected. Performance was extremely consistent, even if capped/low. Movement (vehicular/on-foot) remained smooth for the full session. - Stability: No crash or freeze. Game started cleanly; no device errors, read-back lock errors, or submission issues in log. - Visuals: Asset streaming, shadow rendering, and LOD selection appeared stable. No new artefacts detected. Technical Highlights from Log: - All "queue," "frame," "async," "lock," and "read-back" log lines completed without warning or error. - The system utilized VICTORY_ASYNC_SUBMIT (async submit logic) and managed frames/submissions according to PR goals. - Median/p95 frametimes (GPU-side) were extremely low (1–2 ms, p99 up to 12 ms), indicating true CPU-side cap or scheduler bottleneck, not a rendering/sync bug. - Log indicates subtle improvement in frame pacing—frames presented and dispatched in sync, little evidence of CPU-GPU sync slippage or excessive flushes. Notes/Outcome: - + Game is now very consistent and stable from a CPU submission perspective. - – Overall FPS is unusually capped/low for this GPU, but this appears unrelated to submission, lock, or read-back errors. - Would recommend investigating further or combining with profiling/optimization PRs to push FPS up while maintaining current smoothness and stability. Attachment: [victory-nvidia-play-20261129-231142-33492.log](https://github.com/user-attachments/files/35586014/victory-nvidia-play-20261129-231142-33492.log)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3271:upstream-pr/3271'
git switch 'upstream-pr/3271'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3271'
git switch 'upstream-pr/3271'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3271'
git switch 'upstream-pr/3271'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3271'
git switch 'main'
git merge --squash 'upstream-pr/3271'
git switch 'main'
git merge --ff-only 'upstream-pr/3271'
git switch 'main'
git merge 'upstream-pr/3271'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!3271
No description provided.