d3d12: skip unchanged texture publications, store into XMem pages, share in-flight readback buffers #439

Merged
NickStallman merged 3 commits from upstream-pr/439 into main 2026-11-29 11:25:17 +00:00
NickStallman commented 2026-11-29 04:17:26 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T04:17:26Z.


Draft. Unrun in the game on main, and not measured there. The full check passes on an RTX 5090 and an RDNA 2 iGPU, and so do this PR's 12 device tests on both. Opening early because it touches what c92559b6 just changed, so it can be steered before more work goes in.

Summary

c92559b6 narrows what is read back, and caps idle readback buffers. Three things remain for the mips that are still read back. They behave independently, but their changes share writeback.rs and a test rig, so this is one PR to review commit by commit:

  • Leave a publication alone when neither side changed. A mip is skipped only if the rows read back, the baseline and the title's memory now all match the last publication. A title write, an upload, an overlapping texture's publication, or a failed one, publishes as before. The baseline of a mip with holes takes the GPU's elements from what was published, so a title store racing it isn't mistaken for the baseline. TUXBOX_PUBLICATION_COMPARE=0 turns it off.
  • Publish into XMem's plain pages with a guarded store rather than WriteProcessMemory, which is a Wine server request per run. Pages that aren't plain read-write keep the native write, including a page in a reservation of the title's own that carries the title's write watch (#290). TUXBOX_PUBLICATION_STORE=0 turns it off.
  • Share one readback buffer per size among a queue's publications in flight. The idle cap doesn't count buffers in use, so a lagging worker makes the queue create one per batch. Testers of #413 on an RX 6600 saw readback memory grow this way. It's bounded by the number of sizes, not literally one buffer, and adds no wait: submit already queues one on the worker's fence. TUXBOX_READBACK_SHARE=0 turns it off.

Overlap with c92559b6

Commits 1 and 2 act on mips still read back, so they don't duplicate it, but they plausibly gain less than before. Commit 3 overlaps only in the idle cap, whose constant it reuses. If you'd rather take only some of these, I can split or drop them.

What I don't know

  • What's left to save on main: not measured yet. A run with an earlier version of these commits, without c92559b6, still spent a good part of its frame time publishing, so they are not a full fix.

Tested

  • python tuxbox.py check on an RTX 5090 (10de:2b85, NVIDIA 620.70.10) and an AMD Raphael iGPU (1002:13c0, Mesa RADV 26.0.8), GE-Proton11-14: all steps passed (guest-present-4k-splash skipped on AMD). On 962a1cee.
  • 16 unit tests that need no GPU pass in Wine with Vulkan disabled; some are already on main. Removing the title-watch rule, the XMem store or the holed-baseline overlay each makes a test fail.
  • The 12 device tests (11 in publication_compare.rs and a_finished_readback_lends_its_buffer_and_list_to_the_next), by exact name, on both cards: all pass, and each prints the device it opened, so none returned early. The project's checks only typecheck the D3D12 crate, so run these by name.
  • Not run: the game, Windows.

Lanes: no new scenario. These commits must not change output, only work done and memory, and the two correctness edges (a title store racing a publication, a title-owned watched reservation) can't be made deterministic from a guest. The existing publication Lanes cases cover the output.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5547478711 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/439). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T04:17:26Z. --- **Draft. Unrun in the game on `main`, and not measured there.** The full check passes on an RTX 5090 and an RDNA 2 iGPU, and so do this PR's 12 device tests on both. Opening early because it touches what `c92559b6` just changed, so it can be steered before more work goes in. ## Summary `c92559b6` narrows what is read back, and caps idle readback buffers. Three things remain for the mips that are still read back. They behave independently, but their changes share `writeback.rs` and a test rig, so this is one PR to review commit by commit: - **Leave a publication alone when neither side changed.** A mip is skipped only if the rows read back, the baseline and the title's memory now all match the last publication. A title write, an upload, an overlapping texture's publication, or a failed one, publishes as before. The baseline of a mip with holes takes the GPU's elements from what was published, so a title store racing it isn't mistaken for the baseline. `TUXBOX_PUBLICATION_COMPARE=0` turns it off. - **Publish into XMem's plain pages with a guarded store** rather than `WriteProcessMemory`, which is a Wine server request per run. Pages that aren't plain read-write keep the native write, including a page in a reservation of the title's own that carries the title's write watch (#290). `TUXBOX_PUBLICATION_STORE=0` turns it off. - **Share one readback buffer per size** among a queue's publications in flight. The idle cap doesn't count buffers in use, so a lagging worker makes the queue create one per batch. Testers of #413 on an RX 6600 saw readback memory grow this way. It's bounded by the number of sizes, not literally one buffer, and adds no wait: `submit` already queues one on the worker's fence. `TUXBOX_READBACK_SHARE=0` turns it off. ## Overlap with `c92559b6` Commits 1 and 2 act on mips still read back, so they don't duplicate it, but they plausibly gain less than before. Commit 3 overlaps only in the idle cap, whose constant it reuses. If you'd rather take only some of these, I can split or drop them. ## What I don't know - What's left to save on `main`: not measured yet. A run with an earlier version of these commits, without `c92559b6`, still spent a good part of its frame time publishing, so they are not a full fix. ## Tested - `python tuxbox.py check` on an RTX 5090 (10de:2b85, NVIDIA 620.70.10) and an AMD Raphael iGPU (1002:13c0, Mesa RADV 26.0.8), GE-Proton11-14: all steps passed (guest-present-4k-splash skipped on AMD). On 962a1cee. - 16 unit tests that need no GPU pass in Wine with Vulkan disabled; some are already on `main`. Removing the title-watch rule, the XMem store or the holed-baseline overlay each makes a test fail. - The 12 device tests (11 in `publication_compare.rs` and `a_finished_readback_lends_its_buffer_and_list_to_the_next`), by exact name, on both cards: all pass, and each prints the device it opened, so none returned early. The project's checks only typecheck the D3D12 crate, so run these by name. - **Not run:** the game, Windows. **Lanes:** no new scenario. These commits must not change output, only work done and memory, and the two correctness edges (a title store racing a publication, a title-owned watched reservation) can't be made deterministic from a guest. The existing publication Lanes cases cover the output. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DrArroway commented 2026-11-29 08:38:42 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T08:38:42Z.


Tested same-binary A/B of #439 (962a1cee) in ProjectScarlett (1.0.2.1, 3840×2160, offline) on AMD Radeon RX 6900 XT (1002:73bf, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14) with TUXBOX_SUBMIT_PROFILE=1.

  • Setup: Built on main (2871726) + #455 (guest-memory BLAS lifetime) + #441 (root SRV/UAV reach) + #439 (962a1cee, clean merge).
  • Runs:
    • OFF: TUXBOX_PUBLICATION_COMPARE=0 TUXBOX_PUBLICATION_STORE=0 TUXBOX_READBACK_SHARE=0 (449.7s total, 11 3D world windows / 22 placement publication profile windows = 188.7s, 38 readback windows = 191.9s)
    • ON: default (623.6s total, 10 3D world windows / 21 placement publication profile windows = 117.6s, 24 readback windows = 121.0s)

3D World Steady-State Comparison

Metric #439 OFF #439 ON (default) Delta
3D frame cadence 21 frames / 174s (8.29 s/frame, 0.121 FPS; steady after first window: 18 / 155s = 8.61 s/frame) 27 frames / 107s (3.96 s/frame, 0.252 FPS, 3 frames / 11–13s) 2.1×–2.2× faster
placement publication 157.07s / 188.7s (83.2% wall, 229 calls, avg 685.9 ms, max 2,699.2 ms, 78,220.5 MiB, 2.008 ms/MiB) 49.34s / 117.6s (42.0% wall, 299 calls, avg 165.0 ms, max 1,592.4 ms, 104,147.2 MiB, 0.474 ms/MiB) 4.24× faster/MiB, 4.16× lower avg/batch
publish-compare (commit 1) off 17.72s (15.1% wall, 0.173 ms/MiB, 69,422 units / 102,218.7 MiB) Skipped 87.3% of units & 74.1% of MiB; unchanged ... written again fell from 17,378 / 48,681 (35.7%) to 3,034 / 63,423 (4.8%)
publish-retile 48.21s (25.5% wall, 52,415 units / 76,778.3 MiB, avg 210.5 ms, max 1,001.0 ms, 0.628 ms/MiB) 14.18s (12.1% wall, 8,792 units / 26,482.1 MiB, avg 55.0 ms, max 392.5 ms, 0.536 ms/MiB) 3.8× lower avg/batch
publish-store (commit 2) 107.47s (57.0% wall, avg 469.3 ms, max 1,811.9 ms, 1.400 ms/MiB) 16.01s (13.6% wall, avg 62.1 ms, max 709.4 ms, 0.605 ms/MiB) 2.31× faster/MiB, 7.56× lower avg/batch, 0 store faults
placement readback (queue side) 3.42s (232 calls, avg 14.7 ms, max 284.6 ms) 1.78s (307 calls, avg 5.8 ms, max 47.6 ms) 2.5× faster avg, 6.0× lower max
Readback buffers created / reused (commit 3) 189 created (88,695.4 MiB), 51 reused (21.2% across 240 batches) 32 created (1,540.4 MiB), 274 reused (89.5% across 306 batches; 0 created / 100% reused in the final steady windows) 98.3% less allocation churn
GPU faults / VK_ERROR_DEVICE_LOST 0 0 Clean (both runs ended on unrelated title-side CPU exceptions)

Summary

All three commits pay off clearly on main (2871726) on RADV:

  • Skipping unchanged mips removes 87.3% of unit retiles/stores (with publish-compare itself at 0.173 ms/MiB).
  • Direct guarded XMem stores cut publish-store cost per MiB by 2.31× with 0 store faults.
  • In-flight readback buffer sharing eliminates 98.3% of buffer creation churn (86.6 GiB → 1.50 GiB).
  • What's left on main: placement publication still takes 42.0% of wall time (15.1% compare + 12.1% retile + 13.6% store) because ~104 GiB of placed textures (largest=939.3MiB/504 textures per batch) are still read back.
<!-- greyfinch-sync:brcly/TuxBox:comment:7253238236 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/439#issuecomment-7253238236). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-29T08:38:42Z. --- Tested same-binary A/B of `#439` (`962a1cee`) in ProjectScarlett (1.0.2.1, 3840×2160, offline) on AMD Radeon RX 6900 XT (`1002:73bf`, RADV NAVI21, Mesa 26.3.1, Linux 7.3.6, `GE-Proton11-14`) with `TUXBOX_SUBMIT_PROFILE=1`. - **Setup:** Built on `main` (`2871726`) + `#455` (guest-memory BLAS lifetime) + `#441` (root SRV/UAV reach) + `#439` (`962a1cee`, clean merge). - **Runs:** - **OFF:** `TUXBOX_PUBLICATION_COMPARE=0 TUXBOX_PUBLICATION_STORE=0 TUXBOX_READBACK_SHARE=0` (`449.7s` total, `11` 3D world windows / `22` `placement publication` profile windows = `188.7s`, `38` readback windows = `191.9s`) - **ON:** default (`623.6s` total, `10` 3D world windows / `21` `placement publication` profile windows = `117.6s`, `24` readback windows = `121.0s`) ### 3D World Steady-State Comparison | Metric | `#439` OFF | `#439` ON (default) | Delta | |---|---:|---:|---| | **3D frame cadence** | `21` frames / `174s` (`8.29 s/frame`, `0.121 FPS`; steady after first window: `18` / `155s` = `8.61 s/frame`) | `27` frames / `107s` (`3.96 s/frame`, `0.252 FPS`, `3 frames / 11–13s`) | **`2.1×–2.2×` faster** | | **`placement publication`** | `157.07s / 188.7s` (`83.2%` wall, `229` calls, avg `685.9 ms`, max `2,699.2 ms`, `78,220.5 MiB`, `2.008 ms/MiB`) | `49.34s / 117.6s` (`42.0%` wall, `299` calls, avg `165.0 ms`, max `1,592.4 ms`, `104,147.2 MiB`, `0.474 ms/MiB`) | **`4.24×` faster/MiB**, **`4.16×` lower avg/batch** | | **`publish-compare`** (commit 1) | off | `17.72s` (`15.1%` wall, `0.173 ms/MiB`, `69,422` units / `102,218.7 MiB`) | Skipped **87.3%** of units & **74.1%** of MiB; `unchanged ... written again` fell from `17,378 / 48,681` (`35.7%`) to `3,034 / 63,423` (`4.8%`) | | **`publish-retile`** | `48.21s` (`25.5%` wall, `52,415` units / `76,778.3 MiB`, avg `210.5 ms`, max `1,001.0 ms`, `0.628 ms/MiB`) | `14.18s` (`12.1%` wall, `8,792` units / `26,482.1 MiB`, avg `55.0 ms`, max `392.5 ms`, `0.536 ms/MiB`) | **`3.8×` lower avg/batch** | | **`publish-store`** (commit 2) | `107.47s` (`57.0%` wall, avg `469.3 ms`, max `1,811.9 ms`, `1.400 ms/MiB`) | `16.01s` (`13.6%` wall, avg `62.1 ms`, max `709.4 ms`, `0.605 ms/MiB`) | **`2.31×` faster/MiB**, **`7.56×` lower avg/batch**, `0` store faults | | **`placement readback`** (queue side) | `3.42s` (`232` calls, avg `14.7 ms`, max `284.6 ms`) | `1.78s` (`307` calls, avg `5.8 ms`, max `47.6 ms`) | **`2.5×` faster avg**, **`6.0×` lower max** | | **Readback buffers created / reused** (commit 3) | `189` created (**`88,695.4 MiB`**), `51` reused (`21.2%` across `240` batches) | `32` created (**`1,540.4 MiB`**), `274` reused (`89.5%` across `306` batches; `0` created / `100%` reused in the final steady windows) | **`98.3%` less allocation churn** | | **GPU faults / `VK_ERROR_DEVICE_LOST`** | `0` | `0` | Clean (both runs ended on unrelated title-side CPU exceptions) | ### Summary All three commits pay off clearly on `main` (`2871726`) on RADV: - Skipping unchanged mips removes **87.3%** of unit retiles/stores (with `publish-compare` itself at `0.173 ms/MiB`). - Direct guarded XMem stores cut `publish-store` cost per MiB by **2.31×** with `0` store faults. - In-flight readback buffer sharing eliminates **98.3%** of buffer creation churn (`86.6 GiB` → `1.50 GiB`). - What's left on `main`: `placement publication` still takes `42.0%` of wall time (`15.1%` compare + `12.1%` retile + `13.6%` store) because `~104 GiB` of placed textures (`largest=939.3MiB/504 textures` per batch) are still read back.
brcly commented 2026-11-29 10:19:53 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T10:19:53Z.


Measured in ProjectScarlett's world load on main (75453953), RTX 4070 Ti SUPER, warm caches, one run each:

main with this
Pinned readback buffers 2.5–4.4 GiB (13–14 buffers) 0.3–1.4 GiB
New readback buffers per 5 s 7–20 1–9, the rest reused
Publishing ~0.8 GiB/s, worker ~90% busy ~2.3 GiB/s
Menu publications (0.5 MiB) 7–9 ms each ~0.15 ms

Combined with #460 and a heap write bitmap (#462, stacked on this and #460), pinned readback in the world load is 0.29 GiB. lanes-bindless-compute 22/22 on an RTX 4070 Ti SUPER and a Radeon 610M, lanes-selftest 27/27 and d3d12-placement on NVIDIA, publication_compare and the rest of the d3d12 --lib tests (376) under Wine.

#462 changes Worker::enqueue to take an optional readback beside the bitmap part, so one job still signals publication once per batch.

Could this come out of draft? #462 builds on it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7254362254 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/439#issuecomment-7254362254). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T10:19:53Z. --- Measured in ProjectScarlett's world load on `main` (75453953), RTX 4070 Ti SUPER, warm caches, one run each: | | `main` | with this | |---|---|---| | Pinned readback buffers | 2.5–4.4 GiB (13–14 buffers) | 0.3–1.4 GiB | | New readback buffers per 5 s | 7–20 | 1–9, the rest reused | | Publishing | ~0.8 GiB/s, worker ~90% busy | ~2.3 GiB/s | | Menu publications (0.5 MiB) | 7–9 ms each | ~0.15 ms | Combined with #460 and a heap write bitmap (#462, stacked on this and #460), pinned readback in the world load is 0.29 GiB. `lanes-bindless-compute` 22/22 on an RTX 4070 Ti SUPER and a Radeon 610M, `lanes-selftest` 27/27 and `d3d12-placement` on NVIDIA, `publication_compare` and the rest of the d3d12 `--lib` tests (376) under Wine. #462 changes `Worker::enqueue` to take an optional readback beside the bitmap part, so one job still signals publication once per batch. Could this come out of draft? #462 builds on it.
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!439
No description provided.