perf: make textures picked by index ready off the recording thread (VICTORY_TEXTURE_PREPARE_THREADS) #395

Merged
Skyfrye merged 3 commits from upstream-pr/395 into main 2026-11-26 18:07:40 +00:00
Skyfrye commented 2026-11-26 16:18:07 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T16:18:07Z.


Change

VICTORY_TEXTURE_PREPARE_THREADS=N (off by default: unset or 0 runs today's code).

The pass over the heap's texture views (State::heap_textures, draw.rs) runs on the thread that records the frame. For each texture it brings in, it makes:

  • the host copy: CreateCommittedResource, or a reserved texture (resource::hosted);
  • a staging buffer: an upload buffer, new, or pooled and zeroed (texture::staging).

Then it records the copy. While a long queue is due, the pass may spend 250 ms (VICTORY_TEXTURE_STAGE_MS), or 1.5 s while catching up, and it spent all of it. In the world of the title this fork works on (RTX 5080, Series X), the frame line read "heap buffers … passes 964-1740 ms" in the opening cutscene, with frames at 0.3-0.6 fps for a minute or two. Later in play, every newly streamed area gave dips to 0.6-1 fps, with passes of 678-975 ms.

Where the time goes, measured with the ignored benchmark below (512 textures, 170 MB, RTX 5080, card idle):

Recording thread At submission (detile)
Today, cold (no host copies, no pooled buffers) 417 ms 118 ms
Today, warm 34 ms 114 ms
2 prepare threads, cold 36 ms 31 ms
4 prepare threads, cold 36 ms 29 ms

Cold, today's 417 ms were mostly two driver calls:

  • 127 ms making 512 host copies (0.25 ms each);
  • 225 ms making 512 new upload buffers (0.44 ms each).

The detile itself runs at submission, on the submitting thread.

With the switch, texture/prepare.rs hands each texture the pass would make to N threads of their own. They:

  • make the host copy, only while the card has room, asking room_lately() again before a new one;
  • make the staging buffer;
  • detile the title's memory into it.

The pass records the uploads of the ones that are ready and passes over the others, which stay due. What is handed out in a frame, and what is out at once, is held to the pass's bytes a frame (VICTORY_TEXTURE_STAGE_MB; 512 MB while catching up). The pass still asks room() every 32 MiB handed out, and its full-card refusal runs unchanged before any hand-out. A bake draw's run still makes its textures at once.

What stays as it was:

  • the list that records an upload holds its staging buffer until it has run;
  • a title write after the detile is still found at submission (write watch, guards, hash) and by the looks after the upload (texture_slots_rechecked);
  • a partly mapped texture is read again at its submission;
  • title resources are held while a worker uses them.

texture::staging is split so that a prepared staging buffer enters the table only when its upload is recorded.

In every build, two new frame lines:

  • where the pass's time goes: looking at slots, making host copies, staging and recording, the rest, with counts and times of host copies, staging buffers and new upload buffers;
  • with the switch, the prepare threads' load, the times they found the card without room, and what they made ready and let go untaken.

A texture now shows at least one frame later than before: it is handed out in one pass and recorded in a later one.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream main at f088a43 (the in-game runs below were on 84aa3c3; built and tested again after each rebase), from third_party/victory:

cargo build --locked --release -p victory                                               -> Finished; the 2 warnings main has, no new one
VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib -- prepare heap_texture   -> 3 passed, 1 ignored (the benchmark); with `texture::` too: 9 passed

New tests:

  • prepare_threads_make_the_textures_off_the_recording_thread runs in a child process with the switch at 2. Over four rounds it checks that:

    • the recording thread makes no host copy and no staging buffer;
    • every slot is made, and none is left due, within two passes;
    • every level reads back as written.

    It does not build without the change. With the switch unset, the code it replaces fails its first check.

  • prepare_threads_are_off_unless_set.

  • heap_texture_pass_benchmark (ignored: run by hand, on an idle card) gave the table above.

In the world, my copy of the game, Series X, with the launcher's switches and #386's three. Two runs of the same stretch, the first 540 s, with screen captures every 15 s.

  • Without this PR: main at 84aa3c3 with #354, #381, #382 and #392.
  • With it: the same plus this PR at VICTORY_TEXTURE_PREPARE_THREADS=2, and the rebased #360 and #362.
Frame lines (5 s each) Without With, 2 threads
Median fps 12.7 13.4
10th percentile fps 1.4 4.1
25th percentile fps 5.2 10.3
Lines under 3 fps 15 of 100 6 of 101
Lines with the texture pass over 250 ms 11 0
Longest texture pass 1,576 ms 213 ms
Mean texture pass 108 ms 25.5 ms
  • The texture-pass rows are this PR's alone. #360 and #362 do not touch that pass.
  • The frame-rate rows are the stack's.
  • In the second run, the prepare threads took about 11 ms of their own time a frame: 8 ms making host copies, 2 ms reading and detiling. They never found the card without room and let nothing go untaken. The recording thread's part of the pass was 1-2 ms.
  • Picture: checked from the captures (the opening cutscene, the cell, the corridor, a later cutscene), and watched live by the person I work with. Textures are drawn.
    • Some textures still show black for a moment, as before, fewer than before.
    • No exception, no device lost.
  • One run per build, not alternating, and the second run's scenes were not identical. The lows are the clearest difference.

Stacking note: #354 changes texture::staging (base_mip, a guarded insert into the table). On top of it, this PR's split of staging needs that guard in the shared insert and #354's lookup test in prepared_staging. I did that for the run above. Whichever of the two is merged second, I can rebase it.

Oracle and test data

No game file. The figures come from my own runs of my copy of the game.

Checklist

  • The PR covers a single reviewable behaviour: textures picked by index are made ready off the recording thread, behind a switch.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: pass timings and frame rates; no title code.
  • Code taken from another project: none.

AI assistance:

  • A Claude Opus 5.5 subagent in Claude Code found where the pass's time goes, wrote the change, its tests and the benchmark.
  • Claude Opus 5.5 (coordinating) checked it, stacked it for the game run, ran the game and wrote this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6630783304 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/395). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T16:18:07Z. --- ## Change `VICTORY_TEXTURE_PREPARE_THREADS=N` (off by default: unset or 0 runs today's code). The pass over the heap's texture views (`State::heap_textures`, draw.rs) runs on the thread that records the frame. For each texture it brings in, it makes: - the host copy: `CreateCommittedResource`, or a reserved texture (`resource::hosted`); - a staging buffer: an upload buffer, new, or pooled and zeroed (`texture::staging`). Then it records the copy. While a long queue is due, the pass may spend 250 ms (`VICTORY_TEXTURE_STAGE_MS`), or 1.5 s while catching up, and it spent all of it. In the world of the title this fork works on (RTX 5080, Series X), the frame line read "heap buffers … passes 964-1740 ms" in the opening cutscene, with frames at 0.3-0.6 fps for a minute or two. Later in play, every newly streamed area gave dips to 0.6-1 fps, with passes of 678-975 ms. Where the time goes, measured with the ignored benchmark below (512 textures, 170 MB, RTX 5080, card idle): | | Recording thread | At submission (detile) | |---|---|---| | Today, cold (no host copies, no pooled buffers) | 417 ms | 118 ms | | Today, warm | 34 ms | 114 ms | | 2 prepare threads, cold | 36 ms | 31 ms | | 4 prepare threads, cold | 36 ms | 29 ms | Cold, today's 417 ms were mostly two driver calls: - 127 ms making 512 host copies (0.25 ms each); - 225 ms making 512 new upload buffers (0.44 ms each). The detile itself runs at submission, on the submitting thread. With the switch, `texture/prepare.rs` hands each texture the pass would make to N threads of their own. They: - make the host copy, only while the card has room, asking `room_lately()` again before a new one; - make the staging buffer; - detile the title's memory into it. The pass records the uploads of the ones that are ready and passes over the others, which stay due. What is handed out in a frame, and what is out at once, is held to the pass's bytes a frame (`VICTORY_TEXTURE_STAGE_MB`; 512 MB while catching up). The pass still asks `room()` every 32 MiB handed out, and its full-card refusal runs unchanged before any hand-out. A bake draw's run still makes its textures at once. What stays as it was: - the list that records an upload holds its staging buffer until it has run; - a title write after the detile is still found at submission (write watch, guards, hash) and by the looks after the upload (`texture_slots_rechecked`); - a partly mapped texture is read again at its submission; - title resources are held while a worker uses them. `texture::staging` is split so that a prepared staging buffer enters the table only when its upload is recorded. In every build, two new frame lines: - where the pass's time goes: looking at slots, making host copies, staging and recording, the rest, with counts and times of host copies, staging buffers and new upload buffers; - with the switch, the prepare threads' load, the times they found the card without room, and what they made ready and let go untaken. A texture now shows at least one frame later than before: it is handed out in one pass and recorded in a later one. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream `main` at `f088a43` (the in-game runs below were on `84aa3c3`; built and tested again after each rebase), from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished; the 2 warnings main has, no new one VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib -- prepare heap_texture -> 3 passed, 1 ignored (the benchmark); with `texture::` too: 9 passed ``` New tests: - `prepare_threads_make_the_textures_off_the_recording_thread` runs in a child process with the switch at 2. Over four rounds it checks that: - the recording thread makes no host copy and no staging buffer; - every slot is made, and none is left due, within two passes; - every level reads back as written. It does not build without the change. With the switch unset, the code it replaces fails its first check. - `prepare_threads_are_off_unless_set`. - `heap_texture_pass_benchmark` (ignored: run by hand, on an idle card) gave the table above. In the world, my copy of the game, Series X, with the launcher's switches and #386's three. Two runs of the same stretch, the first 540 s, with screen captures every 15 s. - **Without this PR:** `main` at `84aa3c3` with #354, #381, #382 and #392. - **With it:** the same plus this PR at `VICTORY_TEXTURE_PREPARE_THREADS=2`, and the rebased #360 and #362. | Frame lines (5 s each) | Without | With, 2 threads | |---|---|---| | Median fps | 12.7 | 13.4 | | 10th percentile fps | 1.4 | 4.1 | | 25th percentile fps | 5.2 | 10.3 | | Lines under 3 fps | 15 of 100 | 6 of 101 | | Lines with the texture pass over 250 ms | 11 | 0 | | Longest texture pass | 1,576 ms | 213 ms | | Mean texture pass | 108 ms | 25.5 ms | - The texture-pass rows are this PR's alone. #360 and #362 do not touch that pass. - The frame-rate rows are the stack's. - In the second run, the prepare threads took about 11 ms of their own time a frame: 8 ms making host copies, 2 ms reading and detiling. They never found the card without room and let nothing go untaken. The recording thread's part of the pass was 1-2 ms. - Picture: checked from the captures (the opening cutscene, the cell, the corridor, a later cutscene), and watched live by the person I work with. Textures are drawn. - Some textures still show black for a moment, as before, fewer than before. - No exception, no device lost. - One run per build, not alternating, and the second run's scenes were not identical. The lows are the clearest difference. Stacking note: #354 changes `texture::staging` (`base_mip`, a guarded insert into the table). On top of it, this PR's split of `staging` needs that guard in the shared insert and #354's lookup test in `prepared_staging`. I did that for the run above. Whichever of the two is merged second, I can rebase it. ## Oracle and test data No game file. The figures come from my own runs of my copy of the game. ## Checklist - [x] The PR covers a single reviewable behaviour: textures picked by index are made ready off the recording thread, behind a switch. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: pass timings and frame rates; no title code. - [x] Code taken from another project: none. AI assistance: - A Claude Opus 5.5 subagent in Claude Code found where the pass's time goes, wrote the change, its tests and the benchmark. - Claude Opus 5.5 (coordinating) checked it, stacked it for the game run, ran the game and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
LooperSalty/AnyXboxX!395
No description provided.