d3d12: reuse readback buffers and skip publications that change nothing #392

Merged
NickStallman merged 1 commit from upstream-pr/392 into main 2026-11-28 12:07:42 +00:00
NickStallman commented 2026-11-28 09:32:11 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T09:32:11Z.


Summary

A batch that writes placed textures records a copy of each into a new readback buffer. Creating that buffer, with its allocator and list, is most of the "placement readback" time on the submitting thread.

  • Measured: on an RTX 5090 (GE-Proton 11-14), a 925 MiB buffer took 52–67 ms to create.
  • In ProjectScarlett: the world's largest publications are 925 MiB, and a profile of ExecuteCommandLists showed up to 72 ms for this step in a single batch.

Changes:

  • Reuse readback buffers. Each queue's publication worker keeps finished buffers, allocators and lists for 2 s, up to 1 GiB. The next readback on that queue takes the smallest one that fits.
    • Sizes are rounded up to an eighth of their power of two, so similar publications share buffers.
    • Taking a kept buffer measured 0.005–0.065 ms, against 55 ms for a new 925 MiB one.
  • Skip publications that change nothing. A mip without holes holds only the GPU's bytes, so after writing it the new baseline is the digest of those bytes, instead of a second read of title memory.
    • When that digest equals the last baseline and title memory still holds those bytes, nothing is written.
    • One behaviour change: a CPU write that lands just after a publication is now seen as a change and uploaded. Before, it was folded into the baseline.
  • Accounting under TUXBOX_LOG. About every 5 s it logs:
    • the readback volume;
    • published mips that changed or didn't;
    • buffers created and reused;
    • the eight textures with the most bytes read back, with address, size, format, layout, mips, subresources and queues, and why each counted as written (render target, clear, copy or UAV clear, or a writable view in an indexable heap).

The GPU copies, and when publication lands in title memory, are unchanged.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both

New tests:

  • a GPU test on a real device in which three readbacks share one buffer; it fails with reuse disabled;
  • a test that an unchanged publication doesn't write; it fails without the skip, because its pages are read-only;
  • unit tests of the reuse pool and of the log report.

The existing texture-readback, texture-publication, cross-queue and copy-memory Lanes self-tests, and the d3d12-placement suites, pass on both cards.

GPU, driver and backend:

  • RTX 5090 (10de:2b85), NVIDIA 620.70.10
  • AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8
  • both on GE-Proton11-14

Commands run and their results:

python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64
  both cards: all 11 steps passed, including Lanes and fixtures on the GPU,
  D3D12 regression controls and Shader translator on the GPU
d3d12 unit tests under GE-Proton (5090): 234 passed, 0 failed

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5538759827 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/392). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T09:32:11Z. --- ## Summary A batch that writes placed textures records a copy of each into a new readback buffer. Creating that buffer, with its allocator and list, is most of the "placement readback" time on the submitting thread. - **Measured:** on an RTX 5090 (GE-Proton 11-14), a 925 MiB buffer took 52–67 ms to create. - **In ProjectScarlett:** the world's largest publications are 925 MiB, and a profile of `ExecuteCommandLists` showed up to 72 ms for this step in a single batch. **Changes:** - **Reuse readback buffers.** Each queue's publication worker keeps finished buffers, allocators and lists for 2 s, up to 1 GiB. The next readback on that queue takes the smallest one that fits. - Sizes are rounded up to an eighth of their power of two, so similar publications share buffers. - Taking a kept buffer measured 0.005–0.065 ms, against 55 ms for a new 925 MiB one. - **Skip publications that change nothing.** A mip without holes holds only the GPU's bytes, so after writing it the new baseline is the digest of those bytes, instead of a second read of title memory. - When that digest equals the last baseline and title memory still holds those bytes, nothing is written. - **One behaviour change:** a CPU write that lands just after a publication is now seen as a change and uploaded. Before, it was folded into the baseline. - **Accounting under `TUXBOX_LOG`.** About every 5 s it logs: - the readback volume; - published mips that changed or didn't; - buffers created and reused; - the eight textures with the most bytes read back, with address, size, format, layout, mips, subresources and queues, and why each counted as written (render target, clear, copy or UAV clear, or a writable view in an indexable heap). The GPU copies, and when publication lands in title memory, are unchanged. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [x] Where the table calls for AMD and NVIDIA, they passed on both New tests: - a GPU test on a real device in which three readbacks share one buffer; it fails with reuse disabled; - a test that an unchanged publication doesn't write; it fails without the skip, because its pages are read-only; - unit tests of the reuse pool and of the log report. The existing texture-readback, texture-publication, cross-queue and copy-memory Lanes self-tests, and the `d3d12-placement` suites, pass on both cards. GPU, driver and backend: - RTX 5090 (10de:2b85), NVIDIA 620.70.10 - AMD Raphael iGPU (1002:13c0), Mesa RADV 26.0.8 - both on GE-Proton11-14 Commands run and their results: ```text python tuxbox.py check --adapter 10de:2b85 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 python tuxbox.py check --adapter 1002:13c0 --proton GE-Proton11-14 --prefix PREFIX --windows-dxc DXC/bin/x64 both cards: all 11 steps passed, including Lanes and fixtures on the GPU, D3D12 regression controls and Shader translator on the GPU d3d12 unit tests under GE-Proton (5090): 234 passed, 0 failed ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!392
No description provided.