Texture pool: make new blocks with the pool's lock let go #661
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/661"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 insidelock(&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:
Near the budget,
MakeResidentwaits 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.Pool::making_aheadcounts 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 ifmakeunwinds.Pool::take/take_ripestay, test-only, built from the same steps, so the existing tests still cover them.Pool::reclaimlets go.Tests
pool::tests::blocks_are_made_with_the_pool_let_gochecks three things:makefinds the pool's lock free (it assertstry_lock()succeeds insidemake, so it fails on the old code).a_texture_gives_its_piece_back_when_it_goesruns against the real D3D12 device.cargo test -p victory-gpu --lib: 442 passed, 2 failed. Both failures fail the same way onmain:indirect::tests::host_list_budget_starts_empty_at_each_submissionandindirect::tests::warp_batch_charges_every_execution.cargo clippy -p victory-gpu --all-targets, with and without--all-features: no new warnings. (mainalready has 78 acrossvictory-gpuandvictory-shader, so the CI step with-D warningsfails there before this change.)Performance, before and after
New benchmark
pool::tests::waits_for_a_piece_while_blocks_are_made, run with: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::texturedoes. 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" usestake_from.Machine: NVIDIA GeForce RTX 5070 Ti (driver 621.24), Ryzen 9 7900X, Windows 11. Three runs on this branch:
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
MakeResidenttook 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.
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.
Pull request closed