Texture pool: make new blocks with the pool's lock let go #661

Closed
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/661 into main
0xkn0wh3r3 commented 2026-11-28 02:58:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T02:58:26Z.


What

New 64 MiB blocks of the texture pool (and of the staging pool) are now made with the pool's lock let go.

Making a block is a CreateHeap (or a 64 MiB upload buffer), MakeResident, and a wait on a copy queue until the new memory is mapped (host::resident, host::mapped). Until now that ran inside lock(&TEXTURES).take_ripe(..) / lock(&STAGING).take(..), so every thread that took a texture piece or gave one back waited for it. Up to 12 blocks made ahead (VICTORY_RIPE_BLOCKS) were made there too.

Why

A play log on an RTX 5070 Ti, with 13.3 GB in use of a card budget that moved between 14.0 and 14.3 GB every tenth of a second:

new memory waited for (VICTORY_WAIT_RESIDENT=0: not), since the start: 52000 times, 27293.8 ms, the longest 1128.2 ms

Near the budget, MakeResident waits for the system to evict first. A block made at such a moment held the pool's lock for the whole wait.

How

  • take_from(pool, len, align, ripe, make) cuts the piece under the lock. When no block has room, it drops the lock, makes the block, takes the lock again, adds the block and cuts from it.
  • Blocks made ahead are made the same way. Pool::making_ahead counts the ones in progress, so two threads don't both make the same one. It is counted off under the same lock the block is added under, and by a drop guard if make unwinds.
  • A block's ripeness mark (submissions begun when it was made) is now read after the making, not before. A mark read before would be too low.
  • The cutting rules are unchanged. Pool::take/take_ripe stay, test-only, built from the same steps, so the existing tests still cover them.
  • Two threads that both find no room may each make a block. The second one becomes a block made ahead, or a spare that Pool::reclaim lets go.

Tests

  • New pool::tests::blocks_are_made_with_the_pool_let_go checks three things:
    • make finds the pool's lock free (it asserts try_lock() succeeds inside make, so it fails on the old code).
    • A new block's mark is taken after its making.
    • A block made ahead that fails is counted off, and the growth backoff still holds.
  • The 7 existing pool tests pass unchanged. a_texture_gives_its_piece_back_when_it_goes runs against the real D3D12 device.
  • cargo test -p victory-gpu --lib: 442 passed, 2 failed. Both failures fail the same way on main: indirect::tests::host_list_budget_starts_empty_at_each_submission and indirect::tests::warp_batch_charges_every_execution.
  • cargo clippy -p victory-gpu --all-targets, with and without --all-features: no new warnings. (main already has 78 across victory-gpu and victory-shader, so the CI step with -D warnings fails there before this change.)

Performance, before and after

New benchmark pool::tests::waits_for_a_piece_while_blocks_are_made, run with:

cargo test -p victory-gpu --lib -- --ignored waits_for_a_piece_while_blocks_are_made --nocapture

One thread takes 12 whole-block pieces, so each one makes a real 64 MiB heap, made resident and waited for until mapped, as pool::texture does. Meanwhile a second thread cuts 256-byte pieces from a block that has room. "Before" makes the blocks inside the lock (Pool::take_ripe, the old path); "after" uses take_from.

Machine: NVIDIA GeForce RTX 5070 Ti (driver 621.24), Ryzen 9 7900X, Windows 11. Three runs on this branch:

before: longest wait for a piece after: longest wait for a piece before: pieces cut meanwhile after: pieces cut meanwhile
run 1 19.9 ms 0.018 ms 179 27,514
run 2 16.7 ms 0.049 ms 255 32,044
run 3 16.9 ms 0.074 ms 174 36,473

Before, the cutting thread was held for nearly the whole run (12 makes, about 1.4–1.7 ms each). After, its longest wait stays under 0.1 ms. The median take is 0.0004 ms either way.

This machine was far below its budget, so a block took about 1.5 ms to make. Near the budget, a single MakeResident took up to 1,128 ms in the play log above. The old path's wait grows with that time; the new path's doesn't.

Not measured: frame times in the title. I have no in-game before/after numbers for this change yet.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5536017584 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/661). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T02:58:26Z. --- ## What New 64 MiB blocks of the texture pool (and of the staging pool) are now made with the pool's lock let go. Making a block is a `CreateHeap` (or a 64 MiB upload buffer), `MakeResident`, and a wait on a copy queue until the new memory is mapped (`host::resident`, `host::mapped`). Until now that ran inside `lock(&TEXTURES).take_ripe(..)` / `lock(&STAGING).take(..)`, so every thread that took a texture piece or gave one back waited for it. Up to 12 blocks made ahead (`VICTORY_RIPE_BLOCKS`) were made there too. ## Why A play log on an RTX 5070 Ti, with 13.3 GB in use of a card budget that moved between 14.0 and 14.3 GB every tenth of a second: > new memory waited for (VICTORY_WAIT_RESIDENT=0: not), since the start: 52000 times, 27293.8 ms, the longest 1128.2 ms Near the budget, `MakeResident` waits for the system to evict first. A block made at such a moment held the pool's lock for the whole wait. ## How - `take_from(pool, len, align, ripe, make)` cuts the piece under the lock. When no block has room, it drops the lock, makes the block, takes the lock again, adds the block and cuts from it. - Blocks made ahead are made the same way. `Pool::making_ahead` counts the ones in progress, so two threads don't both make the same one. It is counted off under the same lock the block is added under, and by a drop guard if `make` unwinds. - A block's ripeness mark (submissions begun when it was made) is now read after the making, not before. A mark read before would be too low. - The cutting rules are unchanged. `Pool::take`/`take_ripe` stay, test-only, built from the same steps, so the existing tests still cover them. - Two threads that both find no room may each make a block. The second one becomes a block made ahead, or a spare that `Pool::reclaim` lets go. ## Tests - New `pool::tests::blocks_are_made_with_the_pool_let_go` checks three things: - `make` finds the pool's lock free (it asserts `try_lock()` succeeds inside `make`, so it fails on the old code). - A new block's mark is taken after its making. - A block made ahead that fails is counted off, and the growth backoff still holds. - The 7 existing pool tests pass unchanged. `a_texture_gives_its_piece_back_when_it_goes` runs against the real D3D12 device. - `cargo test -p victory-gpu --lib`: 442 passed, 2 failed. Both failures fail the same way on `main`: `indirect::tests::host_list_budget_starts_empty_at_each_submission` and `indirect::tests::warp_batch_charges_every_execution`. - `cargo clippy -p victory-gpu --all-targets`, with and without `--all-features`: no new warnings. (`main` already has 78 across `victory-gpu` and `victory-shader`, so the CI step with `-D warnings` fails there before this change.) ## Performance, before and after New benchmark `pool::tests::waits_for_a_piece_while_blocks_are_made`, run with: ``` cargo test -p victory-gpu --lib -- --ignored waits_for_a_piece_while_blocks_are_made --nocapture ``` One thread takes 12 whole-block pieces, so each one makes a real 64 MiB heap, made resident and waited for until mapped, as `pool::texture` does. Meanwhile a second thread cuts 256-byte pieces from a block that has room. "Before" makes the blocks inside the lock (`Pool::take_ripe`, the old path); "after" uses `take_from`. Machine: NVIDIA GeForce RTX 5070 Ti (driver 621.24), Ryzen 9 7900X, Windows 11. Three runs on this branch: | | before: longest wait for a piece | after: longest wait for a piece | before: pieces cut meanwhile | after: pieces cut meanwhile | |---|---|---|---|---| | run 1 | 19.9 ms | 0.018 ms | 179 | 27,514 | | run 2 | 16.7 ms | 0.049 ms | 255 | 32,044 | | run 3 | 16.9 ms | 0.074 ms | 174 | 36,473 | Before, the cutting thread was held for nearly the whole run (12 makes, about 1.4–1.7 ms each). After, its longest wait stays under 0.1 ms. The median take is 0.0004 ms either way. This machine was far below its budget, so a block took about 1.5 ms to make. Near the budget, a single `MakeResident` took up to 1,128 ms in the play log above. The old path's wait grows with that time; the new path's doesn't. **Not measured:** frame times in the title. I have no in-game before/after numbers for this change yet.
0xkn0wh3r3 commented 2026-11-28 06:57:49 +00:00 (Migrated from github.com)

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


Replaced by #816: the same commit on current main, with concurrency tests for both pools, two benches against main (textures and staging), and the clippy fix that main needs to pass CI.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7235626922 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/661#issuecomment-7235626922). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T06:57:49Z. --- Replaced by #816: the same commit on current main, with concurrency tests for both pools, two benches against main (textures and staging), and the clippy fix that main needs to pass CI.

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