Texture and staging blocks made with the pool's lock let go #816

Merged
0xkn0wh3r3 merged 3 commits from upstream-pr/816 into main 2026-11-28 19:39:38 +00:00
0xkn0wh3r3 commented 2026-11-28 06:49:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T06:49:29Z.


Replaces #683, #684 and #685 with one smaller change. It is based directly on main and doesn't depend on #630.

Why

A new 64 MiB block of textures, or of staging memory, is created, made resident and waited for until it is mapped. Usually that is a tenth of a millisecond, but near the card's budget MakeResident waits for the system to evict first. One play log had a wait of 1,128 ms with 13.3 of 14.0 GB in use. Each block was made inside the pool's lock, so every thread that took or gave back a texture piece waited behind it. With VICTORY_RIPE_BLOCKS above 0, up to 12 blocks made ahead were made there too.

What

  • take_from cuts pieces under the lock and makes blocks outside it, both the needed ones and those made ahead. Both pools, textures and staging, use it.
  • A block's ripeness mark is taken after it is made, never before, so it counts as ripe no sooner than it should.
  • Blocks being made ahead are counted, so two threads don't make the same one. A drop guard counts one off even if making it unwinds.
  • The 500 ms backoff after a refused block stays. So do the staging pool's gate on speculative prefetch and main's pool census.
  • There is no switch. Unlike #683–685, there is also no separate thread that makes a block ahead.
  • The in-lock Pool::take/take_ripe stay, test-only, for the tests of the cutting rules.
  • Clippy: the four findings that stop CI on main: the same commit as in #630. Without it, main itself fails clippy on Rust 1.98. Drop it if main fixes them first.

Before / after

cargo test --release -p victory-gpu --lib -- bench_ --ignored --nocapture with VICTORY_RIPE_BLOCKS=0 (the launcher's setting). It ran on an RTX card, with the main and branch binaries run alternately, three runs each. main was measured with the bench commit added on top of it.

bench_textures_placed_while_another_thread_makes_blocks: one thread places 256 KiB textures, which blocks that already hold pieces have room for. Another places 24 MiB textures, which need a new block every second one. Times for placing the small textures:

mean median 99th percentile longest
main 2.4–11.4 ms 0.016–0.037 ms 23–75 ms 26–2,765 ms
this branch 0.009–0.023 ms 0.007–0.012 ms 0.04–0.20 ms 0.08–0.83 ms

bench_staging_while_another_thread_makes_blocks: one thread stages 64 KiB pieces. Another stages 8 MiB pieces and keeps 64 of them, so new staging blocks keep being made. Times for staging the small pieces:

mean 99th percentile longest
main 2.1–2.8 ms 27–122 ms 192–537 ms
this branch 0.037–0.041 ms 0.001–0.003 ms 37–41 ms

The branch's longest staging time, about 40 ms, is a small piece that also found no room and made a block of its own.

Correctness

  • blocks_are_made_with_the_pool_let_go (unit test, no GPU) checks four things:
    • make never runs with the pool's lock held.
    • A block's mark is the submission count from after it was made.
    • A block made ahead is counted off whether or not it was made.
    • A refused block starts the backoff.
  • threads_that_place_textures_at_once_make_blocks_and_keep_their_pieces_apart: eight threads place 192 textures of 4 MiB at once, several of them making blocks. Every texture is placed and the pieces held cover all of them. The device isn't removed, and the debug layer reports nothing.
  • threads_that_stage_at_once_get_zeroed_pieces_of_their_own: eight threads stage 64 MiB each at once, making new blocks. Every piece starts as zeros and holds only what its own thread wrote. It is sampled every 4 KiB, because the CPU reads write-combined memory slowly.
  • The pool tests pass with VICTORY_RIPE_BLOCKS unset and set to 0. They also pass with VICTORY_D3D12_DEBUG=1 in a diagnostics build.
  • CI steps run locally on this branch: clippy in both builds with -D warnings passes. cargo test --workspace --locked passes (1,129 tests, none failed).
  • Not yet measured in play.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5537603117 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/816). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T06:49:29Z. --- Replaces #683, #684 and #685 with one smaller change. It is based directly on `main` and doesn't depend on #630. ## Why A new 64 MiB block of textures, or of staging memory, is created, made resident and waited for until it is mapped. Usually that is a tenth of a millisecond, but near the card's budget `MakeResident` waits for the system to evict first. One play log had a wait of 1,128 ms with 13.3 of 14.0 GB in use. Each block was made inside the pool's lock, so every thread that took or gave back a texture piece waited behind it. With `VICTORY_RIPE_BLOCKS` above 0, up to 12 blocks made ahead were made there too. ## What - `take_from` cuts pieces under the lock and makes blocks outside it, both the needed ones and those made ahead. Both pools, textures and staging, use it. - A block's ripeness mark is taken after it is made, never before, so it counts as ripe no sooner than it should. - Blocks being made ahead are counted, so two threads don't make the same one. A drop guard counts one off even if making it unwinds. - The 500 ms backoff after a refused block stays. So do the staging pool's gate on speculative prefetch and `main`'s pool census. - There is no switch. Unlike #683–685, there is also no separate thread that makes a block ahead. - The in-lock `Pool::take`/`take_ripe` stay, test-only, for the tests of the cutting rules. - `Clippy: the four findings that stop CI on main`: the same commit as in #630. Without it, `main` itself fails clippy on Rust 1.98. Drop it if `main` fixes them first. ## Before / after `cargo test --release -p victory-gpu --lib -- bench_ --ignored --nocapture` with `VICTORY_RIPE_BLOCKS=0` (the launcher's setting). It ran on an RTX card, with the `main` and branch binaries run alternately, three runs each. `main` was measured with the bench commit added on top of it. **`bench_textures_placed_while_another_thread_makes_blocks`**: one thread places 256 KiB textures, which blocks that already hold pieces have room for. Another places 24 MiB textures, which need a new block every second one. Times for placing the small textures: | | mean | median | 99th percentile | longest | |---|---|---|---|---| | `main` | 2.4–11.4 ms | 0.016–0.037 ms | 23–75 ms | 26–2,765 ms | | this branch | 0.009–0.023 ms | 0.007–0.012 ms | 0.04–0.20 ms | 0.08–0.83 ms | **`bench_staging_while_another_thread_makes_blocks`**: one thread stages 64 KiB pieces. Another stages 8 MiB pieces and keeps 64 of them, so new staging blocks keep being made. Times for staging the small pieces: | | mean | 99th percentile | longest | |---|---|---|---| | `main` | 2.1–2.8 ms | 27–122 ms | 192–537 ms | | this branch | 0.037–0.041 ms | 0.001–0.003 ms | 37–41 ms | The branch's longest staging time, about 40 ms, is a small piece that also found no room and made a block of its own. ## Correctness - `blocks_are_made_with_the_pool_let_go` (unit test, no GPU) checks four things: - `make` never runs with the pool's lock held. - A block's mark is the submission count from after it was made. - A block made ahead is counted off whether or not it was made. - A refused block starts the backoff. - `threads_that_place_textures_at_once_make_blocks_and_keep_their_pieces_apart`: eight threads place 192 textures of 4 MiB at once, several of them making blocks. Every texture is placed and the pieces held cover all of them. The device isn't removed, and the debug layer reports nothing. - `threads_that_stage_at_once_get_zeroed_pieces_of_their_own`: eight threads stage 64 MiB each at once, making new blocks. Every piece starts as zeros and holds only what its own thread wrote. It is sampled every 4 KiB, because the CPU reads write-combined memory slowly. - The pool tests pass with `VICTORY_RIPE_BLOCKS` unset and set to 0. They also pass with `VICTORY_D3D12_DEBUG=1` in a diagnostics build. - CI steps run locally on this branch: clippy in both builds with `-D warnings` passes. `cargo test --workspace --locked` passes (1,129 tests, none failed). - Not yet measured in play.
nick0451 commented 2026-11-28 09:21:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nick0451 on 2026-11-28T09:21:43Z.


Tested in the game: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. Release builds, each of #797, #801, #814 and #816 merged on its own onto main at 63b902f.

How: the same frozen save, outdoors on a balcony by the water, about 5,900-6,100 draws a frame (corrected: I first wrote "an interior"). Series S, DLSS Performance, frame generation off, standing still. Each build is started once first as a warm-up (a new build's first start is slow), then the five builds are run in turn, three rounds. Each run is 40 s to settle, then 60 s measured, and the figures are medians of the frame lines. An A/A run of main against itself the same way differed by 2-3%, so smaller differences are noise.

Build fps, 3 runs median frame preparing card busy
main 63b902f 25.5, 24.7, 25.1 25.1 39.8 ms 25.6 ms 95%
#814 25.3, 25.6, 26.4 25.6 39.1 ms 25.1 ms 97%
#801 25.4, 25.8, 25.2 25.4 39.5 ms 25.8 ms 95%
#797 25.3, 25.2, 23.9 25.2 39.7 ms 26.8 ms 95%
#816 24.0, 25.4, 24.2 24.2 41.3 ms 25.0 ms 94%

For this PR: about 3.6% lower fps here (24.2 against 25.1). That is just past the noise of this setup, but one of its three runs was at main's level (25.4), so I would read it as "no clear gain, maybe a small cost" rather than a regression. Preparing is unchanged. The long MakeResident waits it fixes come near the card's budget, and with 24 GB this scene never gets near it.

In this scene the card is about 95% busy, so the frame is the card's. Work saved on the CPU side would show in "preparing" more than in fps.

No crashes, device losses or ERROR lines in any build: about 7 minutes in the world each, warm-up included.

Tested with an AI assistant (Claude Code); results are from this PC.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7237188865 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/816#issuecomment-7237188865). Originally posted by [nick0451](https://github.com/nick0451) on 2026-11-28T09:21:43Z. --- Tested in the game: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. Release builds, each of #797, #801, #814 and #816 merged on its own onto main at `63b902f`. **How:** the same frozen save, outdoors on a balcony by the water, about 5,900-6,100 draws a frame (corrected: I first wrote "an interior"). Series S, DLSS Performance, frame generation off, standing still. Each build is started once first as a warm-up (a new build's first start is slow), then the five builds are run in turn, three rounds. Each run is 40 s to settle, then 60 s measured, and the figures are medians of the frame lines. An A/A run of main against itself the same way differed by 2-3%, so smaller differences are noise. | Build | fps, 3 runs | median | frame | preparing | card busy | |---|---|---|---|---|---| | main `63b902f` | 25.5, 24.7, 25.1 | 25.1 | 39.8 ms | 25.6 ms | 95% | | #814 | 25.3, 25.6, 26.4 | 25.6 | 39.1 ms | 25.1 ms | 97% | | #801 | 25.4, 25.8, 25.2 | 25.4 | 39.5 ms | 25.8 ms | 95% | | #797 | 25.3, 25.2, 23.9 | 25.2 | 39.7 ms | 26.8 ms | 95% | | #816 | 24.0, 25.4, 24.2 | 24.2 | 41.3 ms | 25.0 ms | 94% | **For this PR:** about 3.6% lower fps here (24.2 against 25.1). That is just past the noise of this setup, but one of its three runs was at main's level (25.4), so I would read it as "no clear gain, maybe a small cost" rather than a regression. Preparing is unchanged. The long `MakeResident` waits it fixes come near the card's budget, and with 24 GB this scene never gets near it. In this scene the card is about 95% busy, so the frame is the card's. Work saved on the CPU side would show in "preparing" more than in fps. No crashes, device losses or `ERROR` lines in any build: about 7 minutes in the world each, warm-up included. Tested with an AI assistant (Claude Code); results are from this PC.
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!816
No description provided.