perf(victory-gpu): pool D3D12 readback buffers across texback copy-backs #436

Closed
Lewandox wants to merge 2 commits from upstream-pr/436 into main
Lewandox commented 2026-11-26 18:45:06 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T18:45:06Z.


Summary

Pools D3D12 read-back buffers across texture copy-backs (VICTORY_OCEAN_READBACK=1) instead of calling CreateCommittedResource(D3D12_HEAP_TYPE_READBACK) and destroying a committed buffer on every command list every frame.

Changes

  1. Bounded D3D12 read-back buffer pool (ReadbackPool) in texback.rs:
    • Added a capped pool (READBACK_POOL_MAX_BYTES = 16 MiB, READBACK_POOL_MAX_BUFFERS = 32) reused by texback::record for best-fit buffers in [total, 2 * total].
    • Returned completed read-back buffers to the pool in impl Drop for Back (which only runs once the command list has finished executing on the GPU and is reset/recycled).
    • Dropped unneeded footprints / rows Vecs immediately when packed_linear is true.
  2. Test verification (texback/tests.rs):
    • Extended packed_linear_readbacks_skip_cpu_scratch to assert that 128 consecutive ocean heightmap/displacement readbacks (64 rounds × 2 textures) allocate at most 2 D3D12 read-back buffers instead of 128.

Verification

  • cargo test -p victory-gpu --lib texback::tests (default and --features diagnostics)
  • cargo xtask policy

Relates to #413.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5515478187 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/436). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-26T18:45:06Z. --- ## Summary Pools D3D12 read-back buffers across texture copy-backs (`VICTORY_OCEAN_READBACK=1`) instead of calling `CreateCommittedResource(D3D12_HEAP_TYPE_READBACK)` and destroying a committed buffer on every command list every frame. ### Changes 1. **Bounded D3D12 read-back buffer pool (`ReadbackPool`) in `texback.rs`**: - Added a capped pool (`READBACK_POOL_MAX_BYTES = 16 MiB`, `READBACK_POOL_MAX_BUFFERS = 32`) reused by `texback::record` for best-fit buffers in `[total, 2 * total]`. - Returned completed read-back buffers to the pool in `impl Drop for Back` (which only runs once the command list has finished executing on the GPU and is reset/recycled). - Dropped unneeded `footprints` / `rows` `Vec`s immediately when `packed_linear` is true. 2. **Test verification (`texback/tests.rs`)**: - Extended `packed_linear_readbacks_skip_cpu_scratch` to assert that 128 consecutive ocean heightmap/displacement readbacks (64 rounds × 2 textures) allocate at most 2 D3D12 read-back buffers instead of 128. ## Verification - `cargo test -p victory-gpu --lib texback::tests` (default and `--features diagnostics`) - `cargo xtask policy` Relates to #413.
akimfomin commented 2026-11-26 22:42:25 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-26T22:42:25Z.


@Lewandox, I ran your texback::tests at c60ae2c8bf0c1ab96710e12e5955c51adade8431 on a physical RTX 4070 Ti SUPER (617.14). All three passed. The pool test landed 128 readbacks with two resource allocations, 50,331,648 allocated bytes, and no CPU scratch allocation. The tests cover different payloads and guard padding. Exact command and scope.

Each test batch waits through host.execute(). The remaining lifetime check is two distinct readbacks outstanding before the first fence completes, with a different payload in each. spk-c's VIctory #1376 offers a pattern for stale-mapping versus fresh-readback controls at a different boundary. If useful, the two-input PortBridge check also confirms this PR merges cleanly against the restored receiving commit.

AI-assisted source review. Hardware result from the run above.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7204915059 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7204915059). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-26T22:42:25Z. --- @Lewandox, I ran your `texback::tests` at `c60ae2c8bf0c1ab96710e12e5955c51adade8431` on a physical RTX 4070 Ti SUPER (617.14). All three passed. The pool test landed 128 readbacks with two resource allocations, 50,331,648 allocated bytes, and no CPU scratch allocation. The tests cover different payloads and guard padding. [Exact command and scope](https://github.com/akimfomin/PortBridge/blob/e4963fffb7dd5188e9b54f60c67665f314a3ce14/audit/evidence/anyxboxx-409-after-revert.md#independent-gpu-check-for-436). Each test batch waits through `host.execute()`. The remaining lifetime check is two distinct readbacks outstanding before the first fence completes, with a different payload in each. [spk-c's VIctory #1376](https://github.com/fxceless/victory-fork/pull/1376) offers a pattern for stale-mapping versus fresh-readback controls at a different boundary. If useful, [the two-input PortBridge check](https://github.com/akimfomin/PortBridge/issues/98) also confirms this PR merges cleanly against the restored receiving commit. AI-assisted source review. Hardware result from the run above.
Lewandox commented 2026-11-26 22:50:41 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Lewandox on 2026-11-26T22:50:41Z.


Thanks for the RTX 4070 Ti SUPER verification, @akimfomin! Added \ exback::tests::overlapping_in_flight_readbacks_keep_distinct_buffers_until_fence_completes\ in $sha\ covering two same-sized readbacks simultaneously in flight before the first fence completes (distinct payloads + distinct COM resource identity + zero new D3D12 allocations on the second overlapping pair once both return to the pool).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7205033607 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205033607). Originally posted by [Lewandox](https://github.com/Lewandox) on 2026-11-26T22:50:41Z. --- Thanks for the RTX 4070 Ti SUPER verification, @akimfomin! Added \ exback::tests::overlapping_in_flight_readbacks_keep_distinct_buffers_until_fence_completes\ in \$sha\ covering two same-sized readbacks simultaneously in flight before the first fence completes (distinct payloads + distinct COM resource identity + zero new D3D12 allocations on the second overlapping pair once both return to the pool).
akimfomin commented 2026-11-26 23:03:18 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-26T23:03:18Z.


The new overlapping-readback test passes on an independent RTX 4070 Ti SUPER at 137dd1522cc32f8f0f3cc057bc1cadcf61cf941b. All 4 texback tests passed with cargo test --locked -p victory-gpu texback::tests -- --test-threads=1 --nocapture. Your new test covers distinct data and buffers before either fence, and reuse after both fences. The separate 128-readback test reported zero CPU scratch allocation; its allocation count is affected by which tests warmed the pool in that process.

One useful next action if #454 becomes the base: keep this exact regression when resolving the conflicts in texback.rs and texback/tests.rs. Conflict check against Vice-Tay · Your pinned test. PortBridge · AI-assisted report of a local hardware run.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7205213561 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205213561). Originally posted by [akimfomin](https://github.com/akimfomin) on 2026-11-26T23:03:18Z. --- The new overlapping-readback test passes on an independent RTX 4070 Ti SUPER at `137dd1522cc32f8f0f3cc057bc1cadcf61cf941b`. All 4 texback tests passed with `cargo test --locked -p victory-gpu texback::tests -- --test-threads=1 --nocapture`. Your new test covers distinct data and buffers before either fence, and reuse after both fences. The separate 128-readback test reported zero CPU scratch allocation; its allocation count is affected by which tests warmed the pool in that process. One useful next action if #454 becomes the base: keep this exact regression when resolving the conflicts in `texback.rs` and `texback/tests.rs`. [Conflict check against Vice-Tay](https://github.com/LooperSalty/AnyXboxX/pull/454#issuecomment-7205087487) · [Your pinned test](https://github.com/LooperSalty/AnyXboxX/blob/137dd1522cc32f8f0f3cc057bc1cadcf61cf941b/third_party/victory/crates/victory-gpu/src/texback/tests.rs#L271). [PortBridge](https://github.com/akimfomin/PortBridge) · AI-assisted report of a local hardware run.
LooperSalty commented 2026-11-26 23:09:01 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T23:09:01Z.


Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

texback.rs was rewritten on the new base and the change came without a measurement (rule 2 of AGENTS.md asks for one for performance work).

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7205296487 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205296487). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T23:09:01Z. --- Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). `texback.rs` was rewritten on the new base and the change came without a measurement (rule 2 of AGENTS.md asks for one for performance work). Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

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
LooperSalty/AnyXboxX!436
No description provided.