texback: reuse read-back buffers instead of making one per copy-back #1359

Open
github-bot wants to merge 1 commit from github-bot/gh-1359 into main AGit
Owner

@⁠fxceless on GitHub · 2026-11-26 18:09 UTC · original
fxceless:claude/project-thread-hxiqdc → main · +111 −6 · 1 files · 1 commits · open

Requested by ELEVEN · project thread

Addresses #1340.

Problem

With VICTORY_TEXTURE_BACK on, texback::record called host.read_back_buffer(total) (a CreateCommittedResource on a read-back heap) for every copy-back, and the buffer was released at the list's reset: ~966,000 buffers in a 21-minute run. On Linux with NVIDIA's open kernel module that churn contributes to the driver running out of DMA mappings.

Change (crates/victory-gpu/src/texback.rs only)

  • Read-back buffers of up to 16 MiB are kept by power-of-two size (minimum 64 KiB) and handed out again, as the texture staging pool does.
  • A buffer returns to the spare ones in Drop for Back. A Back lives in the list's Deferred until HostList::reset (only after the list's last submission has run) or until the list is dropped, so a closed list that is submitted more than once lands every run from the same buffer, and no buffer is reused while a list that may still run holds it.
  • Read-back buffers always stay in COPY_DEST, and land reads only the footprints the copies wrote, so reuse needs no clearing or barriers.
  • VICTORY_READBACK_POOL=0: made and released each time, as before. VICTORY_READBACK_POOL_MB: the most bytes kept spare (256).
  • The texture readback landed log line now also reports buffers_reused and buffers_made, so a run shows whether the churn is gone.

Testing

  • cargo clippy -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings: clean.
  • Added readback_buffers_pool_by_power_of_two_up_to_16_mib. Unit tests were not run (no Windows linker in the environment); CI will run them.
  • Not tested in game. Per #1340 the churn is one contributor, not the only cause: a separate Xid 31 fault was seen with a similar patch.

Generated by Claude Code

**@⁠fxceless** on GitHub · 2026-11-26 18:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/1359) `fxceless:claude/project-thread-hxiqdc` → `main` · +111 −6 · 1 files · 1 commits · open <!-- claude-projects-attribution: {"github_login":"fxceless"} --> _Requested by **ELEVEN** · [project thread](https://claude.ai/code/project/chan_01X5mdrDBPSw6f8UR5PM4z8d?thread=cmsg_01X5mdrDBPSw6f8UR5PM4z8d7fH3hyHfzyEzftAXxFyJ3g)_ Addresses #1340. ## Problem With `VICTORY_TEXTURE_BACK` on, `texback::record` called `host.read_back_buffer(total)` (a `CreateCommittedResource` on a read-back heap) for every copy-back, and the buffer was released at the list's reset: ~966,000 buffers in a 21-minute run. On Linux with NVIDIA's open kernel module that churn contributes to the driver running out of DMA mappings. ## Change (`crates/victory-gpu/src/texback.rs` only) - Read-back buffers of up to 16 MiB are kept by power-of-two size (minimum 64 KiB) and handed out again, as the texture staging pool does. - A buffer returns to the spare ones in `Drop for Back`. A `Back` lives in the list's `Deferred` until `HostList::reset` (only after the list's last submission has run) or until the list is dropped, so a closed list that is submitted more than once lands every run from the same buffer, and no buffer is reused while a list that may still run holds it. - Read-back buffers always stay in `COPY_DEST`, and `land` reads only the footprints the copies wrote, so reuse needs no clearing or barriers. - `VICTORY_READBACK_POOL=0`: made and released each time, as before. `VICTORY_READBACK_POOL_MB`: the most bytes kept spare (256). - The `texture readback landed` log line now also reports `buffers_reused` and `buffers_made`, so a run shows whether the churn is gone. ## Testing - `cargo clippy -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings`: clean. - Added `readback_buffers_pool_by_power_of_two_up_to_16_mib`. Unit tests were **not run** (no Windows linker in the environment); CI will run them. - Not tested in game. Per #1340 the churn is one contributor, not the only cause: a separate `Xid 31` fault was seen with a similar patch. --- _Generated by [Claude Code](https://claude.ai/code)_
Every list that copies a texture back made a committed read-back buffer
and released it at its reset (~966,000 in a 21-minute run). Buffers of up
to 16 MiB are now kept by power-of-two size and handed out again; a buffer
goes back to the spare ones when its Back is dropped, which is at the
list's reset (after its last submission has run, so a closed list run
more than once lands every run from the same buffer) or when the list
itself goes.

VICTORY_READBACK_POOL=0 restores the old behaviour; VICTORY_READBACK_POOL_MB
caps the bytes kept spare (256). The "texture readback landed" line now
also reports buffers reused and made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015kFDn3KnDp64NePrXjVuZ2
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:09:43 +00:00
Author
Owner

@⁠fxceless on GitHub · 2026-11-26 18:12 UTC · original

CI note: both clippy steps (default and --all-features, -D warnings) pass. The only failure is policy::tests::repository_passes_policy, which flags crates/victory-gpu/src/host.rs (528,954 bytes) and crates/victory-shader/src/emit/lower.rs (535,588 bytes) over the 512 KiB limit. This PR touches neither file (only texback.rs), and main fails the same check (#1342 tracks the split). Not fixed here to keep the change scoped.

Also worth knowing: CI's cargo test run doesn't include victory-gpu's unit tests, so the new readback_buffers_pool_by_power_of_two_up_to_16_mib test isn't exercised by CI.


Generated by Claude Code

**@⁠fxceless** on GitHub · 2026-11-26 18:12 UTC · [original](https://github.com/fxceless/victory-fork/pull/1359#issuecomment-7200173874) CI note: both clippy steps (default and `--all-features`, `-D warnings`) pass. The only failure is `policy::tests::repository_passes_policy`, which flags `crates/victory-gpu/src/host.rs` (528,954 bytes) and `crates/victory-shader/src/emit/lower.rs` (535,588 bytes) over the 512 KiB limit. This PR touches neither file (only `texback.rs`), and main fails the same check (#1342 tracks the split). Not fixed here to keep the change scoped. Also worth knowing: CI's `cargo test` run doesn't include `victory-gpu`'s unit tests, so the new `readback_buffers_pool_by_power_of_two_up_to_16_mib` test isn't exercised by CI. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠rafaconvaitis on GitHub · 2026-11-26 18:30 UTC · original

I ran a same-binary Windows Series S comparison on an RTX 4070 12 GB while testing the related Cool Fox port (DoubleGhosty/cool_fox#27). Both arms loaded the same checkpoint bytes, ran with the async logger, and had a warm D3D12 pipeline library. The pool flag was the configuration change.

  • Four tests passed on WARP and on the physical RTX 4070. The D3D12 test executes a closed list twice, runs a second list with distinct data, checks both destinations, and checks reuse after the first list resets.
  • At the bridge in Follow the plane, both arms completed 14,208 texture reads over roughly 60 seconds. The 128 MiB pool arm recorded 14,208 reuses and zero new allocations. Pool disabled recorded 14,200 new allocations. The pooled run peaked at 14.5 MiB of idle buffer widths. There were zero allocation failures.
  • The one pair measured 15.35/14.90 median FPS with pool on/off and differing draw counts. Both arms had the same flat-water and dark-sun-reflection symptom, so it reproduces with buffer reuse disabled. A cold host pipeline run is underway. The data here measures allocation behavior on Windows. Linux DMA exhaustion and the remaining Xid fault require separate validation.
**@⁠rafaconvaitis** on GitHub · 2026-11-26 18:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/1359#issuecomment-7200536990) I ran a same-binary Windows Series S comparison on an RTX 4070 12 GB while testing the related Cool Fox port ([DoubleGhosty/cool_fox#27](https://github.com/DoubleGhosty/cool_fox/pull/27)). Both arms loaded the same checkpoint bytes, ran with the async logger, and had a warm D3D12 pipeline library. The pool flag was the configuration change. - Four tests passed on WARP and on the physical RTX 4070. The D3D12 test executes a closed list twice, runs a second list with distinct data, checks both destinations, and checks reuse after the first list resets. - At the bridge in **Follow the plane**, both arms completed 14,208 texture reads over roughly 60 seconds. The 128 MiB pool arm recorded 14,208 reuses and zero new allocations. Pool disabled recorded 14,200 new allocations. The pooled run peaked at 14.5 MiB of idle buffer widths. There were zero allocation failures. - The one pair measured 15.35/14.90 median FPS with pool on/off and differing draw counts. Both arms had the same flat-water and dark-sun-reflection symptom, so it reproduces with buffer reuse disabled. A cold host pipeline run is underway. The data here measures allocation behavior on Windows. Linux DMA exhaustion and the remaining Xid fault require separate validation.
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-26 19:24 UTC · original

Linux/NVIDIA qualification of the authored pool change (game-free)

Complementing the Windows comparison above and the allocation-accounting discussion in #1340, I ran a matched test on an RTX 4060 8 GB / 16 GB RAM Linux workstation. Windows-target victory-gpu tests under GE-Proton 11-14 (Wine 11.0 Staging, vkd3d-proton build 71cae091b06571e, NVIDIA driver 620.73.04, kernel 7.3.5-zen1-1-zen). DXGI reported the physical NVIDIA adapter, not a software device.

Compared the exact PR parent e4245f3c1b0490250d9cf0946a2113000be98687 with authored head b3694a26942d1fe403ecf6d41408fb874a57b265, not with the newer advertised base. Both used an identical fixture and common test-only allocation/list instrumentation, with candidate-only pool-accounting assertions. Separate Cargo targets, identical starting Wine-prefix contents and graphics DLLs, and empty per-case driver-cache directories were used. The candidate had no additional production changes.

The workload records three ordinary committed 512x128 RGBA8 textures with four mips in each of 24 batches. Each closed list is submitted twice, with a completed fence and device-status check before each landing; its buffers remain owned until reset. The three textures have distinct deterministic byte patterns. Every landing checks all 348,160 texel bytes and a 64-byte untouched tail against a CPU oracle. Successful new readback-resource creation is counted separately from pool reuse and landing count. Idle-buffer count and width are checked at every reset, and the pool must stay empty while the closed list owns the buffers.

Configuration Recorded buffers Completed landings New buffers Reuses Peak total idle buffer width Focused tests
Exact parent 72 144 72 0 0 2 passed
PR default 72 144 3 69 1.5 MiB 3 passed
PR VICTORY_READBACK_POOL=0 72 144 72 0 0 3 passed
PR VICTORY_READBACK_POOL_MB=1 72 144 26 46 1 MiB 3 passed

All 576 completed GPU readbacks matched, including the untouched tails (200,577,024 checked bytes total). Default pooling eliminated 95.8% of successful new readback allocations in this workload. The opt-out restores the baseline allocation frequency, and the tighter idle cap still permits reuse while retaining only two 512 KiB buffers. The allocation-invalidation test passed in every process, as did the new pool-size unit test in all three candidate processes.

Two separate Windows-target test builds succeeded; all four test processes exited 0. The external host-memory floor remained 512 MiB, with no additional cgroup memory or swap caps. Across the two supervised scopes (including builds), minimum sampled available host RAM was 8,344.6 / 8,745.1 MiB; peak sampled GPU memory usage during GPU phases was 924 MiB in both. No host OOM kills, matching kernel GPU-fault events, or device-removal failures were observed. Idle width is not a measurement of driver DMA mapping count or physical VRAM savings.

This is evidence for the intended allocation reduction and closed-list/reset lifetime behavior on this Linux/Proton stack. It is not a test of overlapping independent in-flight lists, a full renderer regression suite, prolonged memory pressure, title lighting/water correctness, or FPS. In particular it does not establish that #1340's mapping exhaustion or remaining Xid faults are fixed. The landing count alone can also overstate allocation count: here 144 landings came from 72 recordings even with pooling disabled.

AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol Max).

**@⁠ArturoWolff** on GitHub · 2026-11-26 19:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/1359#issuecomment-7201541334) **Linux/NVIDIA qualification of the authored pool change (game-free)** Complementing the Windows comparison above and the allocation-accounting discussion in #1340, I ran a matched test on an RTX 4060 8 GB / 16 GB RAM Linux workstation. Windows-target `victory-gpu` tests under GE-Proton 11-14 (Wine 11.0 Staging, vkd3d-proton build `71cae091b06571e`, NVIDIA driver `620.73.04`, kernel `7.3.5-zen1-1-zen`). DXGI reported the physical NVIDIA adapter, not a software device. Compared the exact PR parent `e4245f3c1b0490250d9cf0946a2113000be98687` with authored head `b3694a26942d1fe403ecf6d41408fb874a57b265`, not with the newer advertised base. Both used an identical fixture and common test-only allocation/list instrumentation, with candidate-only pool-accounting assertions. Separate Cargo targets, identical starting Wine-prefix contents and graphics DLLs, and empty per-case driver-cache directories were used. The candidate had no additional production changes. The workload records three ordinary committed 512x128 RGBA8 textures with four mips in each of 24 batches. Each closed list is submitted twice, with a completed fence and device-status check before each landing; its buffers remain owned until reset. The three textures have distinct deterministic byte patterns. Every landing checks all 348,160 texel bytes and a 64-byte untouched tail against a CPU oracle. Successful new readback-resource creation is counted separately from pool reuse and landing count. Idle-buffer count and width are checked at every reset, and the pool must stay empty while the closed list owns the buffers. | Configuration | Recorded buffers | Completed landings | New buffers | Reuses | Peak total idle buffer width | Focused tests | |---|---:|---:|---:|---:|---:|---:| | Exact parent | 72 | 144 | 72 | 0 | 0 | 2 passed | | PR default | 72 | 144 | 3 | 69 | 1.5 MiB | 3 passed | | PR `VICTORY_READBACK_POOL=0` | 72 | 144 | 72 | 0 | 0 | 3 passed | | PR `VICTORY_READBACK_POOL_MB=1` | 72 | 144 | 26 | 46 | 1 MiB | 3 passed | All 576 completed GPU readbacks matched, including the untouched tails (200,577,024 checked bytes total). Default pooling eliminated 95.8% of successful new readback allocations in this workload. The opt-out restores the baseline allocation frequency, and the tighter idle cap still permits reuse while retaining only two 512 KiB buffers. The allocation-invalidation test passed in every process, as did the new pool-size unit test in all three candidate processes. Two separate Windows-target test builds succeeded; all four test processes exited 0. The external host-memory floor remained 512 MiB, with no additional cgroup memory or swap caps. Across the two supervised scopes (including builds), minimum sampled available host RAM was 8,344.6 / 8,745.1 MiB; peak sampled GPU memory usage during GPU phases was 924 MiB in both. No host OOM kills, matching kernel GPU-fault events, or device-removal failures were observed. Idle width is not a measurement of driver DMA mapping count or physical VRAM savings. This is evidence for the intended allocation reduction and closed-list/reset lifetime behavior on this Linux/Proton stack. It is not a test of overlapping independent in-flight lists, a full renderer regression suite, prolonged memory pressure, title lighting/water correctness, or FPS. In particular it does **not** establish that #1340's mapping exhaustion or remaining Xid faults are fixed. The landing count alone can also overstate allocation count: here 144 landings came from 72 recordings even with pooling disabled. AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol Max).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1359/head:github-bot/gh-1359'
git switch 'github-bot/gh-1359'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1359'
git switch 'github-bot/gh-1359'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1359'
git switch 'github-bot/gh-1359'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1359'
git switch 'main'
git merge --squash 'github-bot/gh-1359'
git switch 'main'
git merge --ff-only 'github-bot/gh-1359'
git switch 'main'
git merge 'github-bot/gh-1359'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.