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

Closed
github-bot wants to merge 2 commits from github-bot/gh-436 into main AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 18:45 UTC · original
Lewandox:perf/victory-gpu-texback-readback-pool → main · +178 −8 · 2 files · 2 commits · closed without merging

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.

**@⁠Lewandox** on GitHub · 2026-11-26 18:45 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/436) `Lewandox:perf/victory-gpu-texback-readback-pool` → `main` · +178 −8 · 2 files · 2 commits · closed without merging ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:47:00 +00:00
github-bot force-pushed github-bot/gh-436 from af066a043c to 79fa7087f8 2026-11-26 19:35:18 +00:00 Compare
github-bot force-pushed github-bot/gh-436 from 79fa7087f8 to 137dd1522c 2026-11-27 00:35:55 +00:00 Compare
github-bot closed this pull request 2026-11-27 00:35:56 +00:00
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 22:42 UTC · original

@⁠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.

**@⁠akimfomin** on GitHub · 2026-11-26 22:42 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7204915059) @⁠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.
Author
Owner

@⁠Lewandox on GitHub · 2026-11-26 22:50 UTC · original

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).

**@⁠Lewandox** on GitHub · 2026-11-26 22:50 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205033607) 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).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-26 23:03 UTC · original

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.

**@⁠akimfomin** on GitHub · 2026-11-26 23:03 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205213561) 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://git.gtahub.st/github/LooperSalty--AnyXboxX/pulls/454) · [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.
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:09 UTC · original

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

**@⁠LooperSalty** on GitHub · 2026-11-26 23:09 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/436#issuecomment-7205296487) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.