Read-back buffers of textures copied back are kept for the next copy #116

Closed
github-bot wants to merge 0 commits from github-bot/gh-116 into main AGit
Owner

@⁠mgrein on GitHub · 2026-11-30 14:34 UTC · original
mgrein:readback-pool → main · +0 −0 · 0 files · 49 commits · closed without merging

texback::copy_back makes a new read-back buffer with CreateCommittedResource each time a list that wrote one of the VICTORY_TEXTURE_BACK kinds closes. In the world of a new retail game that's ~10 a frame, all of the same few sizes. A profile of the list threads put it at ~3 % of their busy time, and it turned out to cost more than that.

This keeps the buffers instead:

  • Back remembers its size.
  • When a Back is dropped, its buffer goes into a small pool (at most 64). That happens with the list's Deferred at the host list's reset, after the list has run and land() has read the buffer.
  • The next copy of the same size takes a buffer from the pool.

The buffers stay in COPY_DEST as before, and Map/Unmap stay per landing. A Back dropped without its list ever running gives back a buffer nothing wrote, which is harmless.

  • VICTORY_READBACK_POOL=0 makes one buffer per copy, as before.
  • VICTORY_READBACK_POOL=ab switches every 20 seconds and logs each switch (readback-pool switch <unix ms> on|off), for an A/B inside one run.

Measured

RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, VICTORY_SUBMIT_SPLIT=1, VICTORY_ASK_FIRST=1, VICTORY_OFF_LINE=1. One 10-minute idle run in the world with =ab; neighbouring 20 s windows are paired:

per frame change with the pool pairs
list threads' translating (all threads, the VICTORY_THIN line) −12.5 ms (142.8 → 131.1) 24 of 25 lower
frame median −0.85 ms 23 of 25 faster
submitting thread −0.55 ms 22 of 25 faster

The CPU on this machine is saturated (the process keeps ~10.5 of 12 logical cores busy), so CPU taken off the list threads shows up in the frame.

The other read_back_buffer caller, list::read_back (title texture-to-buffer copies), still makes one buffer per copy. It's a candidate for the same treatment.

cargo test -p victory-gpu --lib passes.

🤖 Generated with Claude Code

**@⁠mgrein** on GitHub · 2026-11-30 14:34 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/116) `mgrein:readback-pool` → `main` · +0 −0 · 0 files · 49 commits · closed without merging `texback::copy_back` makes a new read-back buffer with `CreateCommittedResource` each time a list that wrote one of the `VICTORY_TEXTURE_BACK` kinds closes. In the world of a new retail game that's ~10 a frame, all of the same few sizes. A profile of the list threads put it at ~3 % of their busy time, and it turned out to cost more than that. This keeps the buffers instead: - `Back` remembers its size. - When a `Back` is dropped, its buffer goes into a small pool (at most 64). That happens with the list's `Deferred` at the host list's reset, after the list has run and `land()` has read the buffer. - The next copy of the same size takes a buffer from the pool. The buffers stay in `COPY_DEST` as before, and `Map`/`Unmap` stay per landing. A `Back` dropped without its list ever running gives back a buffer nothing wrote, which is harmless. - `VICTORY_READBACK_POOL=0` makes one buffer per copy, as before. - `VICTORY_READBACK_POOL=ab` switches every 20 seconds and logs each switch (`readback-pool switch <unix ms> on|off`), for an A/B inside one run. ## Measured RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, `VICTORY_SUBMIT_SPLIT=1`, `VICTORY_ASK_FIRST=1`, `VICTORY_OFF_LINE=1`. One 10-minute idle run in the world with `=ab`; neighbouring 20 s windows are paired: | per frame | change with the pool | pairs | |---|---|---| | list threads' translating (all threads, the `VICTORY_THIN` line) | −12.5 ms (142.8 → 131.1) | 24 of 25 lower | | frame median | −0.85 ms | 23 of 25 faster | | submitting thread | −0.55 ms | 22 of 25 faster | The CPU on this machine is saturated (the process keeps ~10.5 of 12 logical cores busy), so CPU taken off the list threads shows up in the frame. The other `read_back_buffer` caller, `list::read_back` (title texture-to-buffer copies), still makes one buffer per copy. It's a candidate for the same treatment. `cargo test -p victory-gpu --lib` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each list that copies back a texture shaders wrote (VICTORY_TEXTURE_BACK)
made a new read-back buffer at its close (CreateCommittedResource, a
kernel allocation), ~10 a frame of the same few sizes, about 3 % of the
list threads' busy time in the world. A buffer now goes back to a pool
when its Back is let go (with the list's deferred steps at its reset,
after the list has run and land() has read it) and the next copy of the
same size takes it. At most 64 are kept.

VICTORY_READBACK_POOL=0 makes one for each copy, as before; =ab switches
every 20 seconds and says so in the log.

Measured that way (25 neighbouring 20 s windows in the world, SUBMIT_SPLIT,
ASK_FIRST, OFF_LINE on; RTX 4070, Ryzen 5 5600X): the list threads'
translating 12.5 ms a frame less in all (24 of 25 pairs), frame median
0.85 ms less (23 of 25), the submitting thread 0.55 ms less (22 of 25).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 14:37:53 +00:00
The last run failed in a test this change does not touch (a crash of the
victory-shader test binary, or a watch test that also fails now and then
on main); this runs the checks again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
STATUS_ACCESS_VIOLATION in the victory-shader tests, a crate that does not
depend on victory-gpu, which is all this change touches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠missionarteemis-cloud on GitHub · 2026-11-30 18:35 UTC · original

Measured on an 8-thread CPU (no SMT), in case it helps: about 1.4 % less frame time, consistent with your numbers.

Machine: i7-9700K (8 cores / 8 threads), RTX 4070 12 GB, 32 GB DDR4-3000, Windows 10 22H2 (Agility SDK runtime beside victory.exe), driver 621.40. Series S profile, DLSS Quality, DLSS-FG on, the launcher's v0.8.2 switch set (FAULT_UNLOCKED and STORE_BESIDE on). The game is CPU-bound here: ~72 ms a frame, ~50 ms of it preparing, GPU wait ~0-4 ms.

Method: v0.8.2 diagnostics build with this PR and #93 cherry-picked. Your ab mode and #93's flip on the same wall-clock 20 s windows, so with both on ab they turn on and off together. I bound both to VICTORY_AB bits instead (crate::ab::pick("VICTORY_READBACK_POOL") checked first in read_back_pool()), which gives VICTORY_AB=15,VICTORY_ASK_PRIORITY,VICTORY_READBACK_POOL. That is 15 s phases cycling through all four combinations, standing still after loading a save. Each round is compared against that round's both-off phase. Rounds where draws a frame moved by more than 2 % (a scene change) are left out.

Frame time vs both off, per round (3 steady rounds, ~7,650 draws a frame):

round 1 round 2 round 3 median
READBACK_POOL on -0.8 % -1.4 % -2.1 % -1.4 %
ASK_PRIORITY on (#93) +0.4 % -0.6 % -0.4 % -0.4 %
both -1.3 % -2.1 % -2.1 % -2.1 %

That is about 1 ms a frame, in line with the 0.85 ms you measured on the 5600X. No "texture changed after its upload" warning in any steady phase, no crash.

A small suggestion: binding the ab modes of new switches to crate::ab::pick(...) would let them be measured together with independent bits.

**@⁠missionarteemis-cloud** on GitHub · 2026-11-30 18:35 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/116#issuecomment-7288065057) Measured on an 8-thread CPU (no SMT), in case it helps: **about 1.4 % less frame time, consistent with your numbers.** **Machine:** i7-9700K (8 cores / 8 threads), RTX 4070 12 GB, 32 GB DDR4-3000, Windows 10 22H2 (Agility SDK runtime beside victory.exe), driver 621.40. Series S profile, DLSS Quality, DLSS-FG on, the launcher's v0.8.2 switch set (FAULT_UNLOCKED and STORE_BESIDE on). The game is CPU-bound here: ~72 ms a frame, ~50 ms of it preparing, GPU wait ~0-4 ms. **Method:** v0.8.2 diagnostics build with this PR and #93 cherry-picked. Your `ab` mode and #93's flip on the same wall-clock 20 s windows, so with both on `ab` they turn on and off together. I bound both to `VICTORY_AB` bits instead (`crate::ab::pick("VICTORY_READBACK_POOL")` checked first in `read_back_pool()`), which gives `VICTORY_AB=15,VICTORY_ASK_PRIORITY,VICTORY_READBACK_POOL`. That is 15 s phases cycling through all four combinations, standing still after loading a save. Each round is compared against that round's both-off phase. Rounds where draws a frame moved by more than 2 % (a scene change) are left out. **Frame time vs both off, per round (3 steady rounds, ~7,650 draws a frame):** | | round 1 | round 2 | round 3 | median | |---|---|---|---|---| | READBACK_POOL on | -0.8 % | -1.4 % | -2.1 % | **-1.4 %** | | ASK_PRIORITY on (#93) | +0.4 % | -0.6 % | -0.4 % | -0.4 % | | both | -1.3 % | -2.1 % | -2.1 % | -2.1 % | That is about 1 ms a frame, in line with the 0.85 ms you measured on the 5600X. No "texture changed after its upload" warning in any steady phase, no crash. A small suggestion: binding the `ab` modes of new switches to `crate::ab::pick(...)` would let them be measured together with independent bits.
github-bot closed this pull request 2026-12-01 01:10:29 +00:00
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 01:36 UTC · original

A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection.

Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 01:36 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/116#issuecomment-7297690640) A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection. Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

Pull request closed

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