Texture blocks made with the pool's lock let go #683

Closed
0xkn0wh3r3 wants to merge 7 commits from upstream-pr/683 into main
0xkn0wh3r3 commented 2026-11-28 03:32:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T03:32:45Z.


Stacked on #630. Its commits come first on this branch; it needs Made::Block from there. New here: the last two commits, Texture blocks made with the pool's lock let go and its bench.

Why

A new 64 MiB block of textures was made inside Pool::take_ripe, under the texture pool's lock: CreateHeap, then MakeResident, then a mapping copy waited for. Every other thread that placed a texture, whether a block had room for it or not, waited until the new block was resident and mapped. That wait is as long as the paging queued before it, which is longest while a scene loads, when most textures are made.

What

  • take_ripe is split into place (where a piece goes, or "a new block is needed"), the block, and finish (the ripe blocks made ahead, bookkeeping). Its behaviour is unchanged, and the existing pool unit tests cover it.
  • pool::texture makes the block with the lock released (VICTORY_BLOCKS_UNLOCKED=0: under it, as before), then takes the lock again to add it. If two threads both found no room, both make a block; the second one is just one more empty block, kept or released by the usual spare rule. The failure backoff (500 ms) is kept.
  • A block made this way is stamped with the submission count from after it was made, so with VICTORY_RIPE_BLOCKS above 0 it counts as ripe no sooner than it should.
  • Merged with main's pool census (VICTORY_POOL_STATS): both are kept.

Before / after

bench_textures_placed_while_another_thread_makes_blocks (--ignored --nocapture, VICTORY_RIPE_BLOCKS=0 VICTORY_BLOCK_AHEAD=0): one thread places 256 KiB textures that blocks with pieces have room for, while another places 24 MiB textures that need a new block every second one. RTX card. Latency of the small textures' placing:

mean 99th percentile longest
block made under the lock (VICTORY_BLOCKS_UNLOCKED=0), 4 runs 0.99–2.55 ms 7.4–37.5 ms 8.2–43.8 ms
lock released, 4 runs 0.008–0.014 ms 0.03–0.08 ms 0.07–0.44 ms

Correctness

  • 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, the pieces held cover all of them, the device stays, and the debug layer reports nothing. It passes with the switch either way.
  • The existing pool tests pass, with VICTORY_RIPE_BLOCKS unset and with =0 (the launcher's setting).
  • CI steps run locally on this branch: clippy in both builds with -D warnings, and cargo test --workspace --locked, all pass.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536263413 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/683). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T03:32:45Z. --- **Stacked on #630.** Its commits come first on this branch; it needs `Made::Block` from there. New here: the last two commits, `Texture blocks made with the pool's lock let go` and its bench. ## Why A new 64 MiB block of textures was made inside `Pool::take_ripe`, under the texture pool's lock: `CreateHeap`, then `MakeResident`, then a mapping copy waited for. Every other thread that placed a texture, whether a block had room for it or not, waited until the new block was resident and mapped. That wait is as long as the paging queued before it, which is longest while a scene loads, when most textures are made. ## What - `take_ripe` is split into `place` (where a piece goes, or "a new block is needed"), the block, and `finish` (the ripe blocks made ahead, bookkeeping). Its behaviour is unchanged, and the existing pool unit tests cover it. - `pool::texture` makes the block with the lock released (`VICTORY_BLOCKS_UNLOCKED=0`: under it, as before), then takes the lock again to add it. If two threads both found no room, both make a block; the second one is just one more empty block, kept or released by the usual spare rule. The failure backoff (500 ms) is kept. - A block made this way is stamped with the submission count from *after* it was made, so with `VICTORY_RIPE_BLOCKS` above 0 it counts as ripe no sooner than it should. - Merged with `main`'s pool census (`VICTORY_POOL_STATS`): both are kept. ## Before / after `bench_textures_placed_while_another_thread_makes_blocks` (`--ignored --nocapture`, `VICTORY_RIPE_BLOCKS=0 VICTORY_BLOCK_AHEAD=0`): one thread places 256 KiB textures that blocks with pieces have room for, while another places 24 MiB textures that need a new block every second one. RTX card. Latency of the small textures' placing: | | mean | 99th percentile | longest | |---|---|---|---| | block made under the lock (`VICTORY_BLOCKS_UNLOCKED=0`), 4 runs | 0.99–2.55 ms | 7.4–37.5 ms | 8.2–43.8 ms | | lock released, 4 runs | 0.008–0.014 ms | 0.03–0.08 ms | 0.07–0.44 ms | ## Correctness - `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, the pieces held cover all of them, the device stays, and the debug layer reports nothing. It passes with the switch either way. - The existing pool tests pass, with `VICTORY_RIPE_BLOCKS` unset and with `=0` (the launcher's setting). - CI steps run locally on this branch: clippy in both builds with `-D warnings`, and `cargo test --workspace --locked`, all pass.
0xkn0wh3r3 commented 2026-11-28 06:49:47 +00:00 (Migrated from github.com)

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


Replaced by #816, one smaller change of the same kind (blocks made with the pool's lock let go, for both textures and staging). It has no switch and no separate thread making blocks ahead, and comes with before/after numbers against current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7235543588 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/683#issuecomment-7235543588). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T06:49:47Z. --- Replaced by #816, one smaller change of the same kind (blocks made with the pool's lock let go, for both textures and staging). It has no switch and no separate thread making blocks ahead, and comes with before/after numbers against current main.

Pull request closed

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!683
No description provided.