d3d12: reuse live page imports outside registered page pools #148

Manually merged
github merged 2 commits from gh-pr/148/head into gh-pr/148/base 2026-11-26 06:34:31 +00:00
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 06:00 UTC · original
JeffreyBytes:fix/page-import-reuse → main · +117 −24 · 2 files · 2 commits · merged 2026-11-25 07:30 UTC

Summary

Fixes #147.

A placed resource imports the guest pages it covers as a host heap. Live imports were only shared for single pages inside a registered Xbox GPU page pool. ProjectScarlett places nearly all of its resources outside the pool, so the same pages were imported over and over. Each import is another driver buffer. On RADV every live buffer goes with each submission, which kept the vkd3d_queue thread pinned in the submit ioctl while the GPU sat idle.

Two commits, both in the weak import cache next to the pool caches in PagePools:

  1. Single pages outside every pool. 20,083 imports across 790 distinct pages in the first minute, one page 9,352 times.
  2. Imports that span several pages. Buffer views over five fixed ranges of 448 KiB to 1.2 MiB are imported about five times a frame each, and the recording allocators keep each import until they are reset 216 frames later: about 4,500 live buffers. The key is the page-aligned base with the page count in its low 16 bits, so an import is reused only for exactly the same pages. Ranges of 4 GiB and above, or not made of whole pages, open a fresh import as before.

Both use the same exact-range reuse and ImportedHeap::is_live check as heap_page_cache.rs. The cache never owns a heap, and a range is reopened once its import is released or its pages are remapped. TUXBOX_TRACE_BUFFER_BACKING reports the new paths as page_open / page_hit and span_open / span_hit.

A/B on an RX 6700 XT (RADV, Mesa 26.3.1), same warm cache and settings, only d3d12_xs.dll differing. Each run was sampled when the game process was 300 s old:

At 300 s main + commit 1 + commit 2
Title's GPU buffers 12,998 8,628 4,094
64 KiB buffers 4,671 277 279
1.0–1.2 MiB buffers 4,106 3,768 none in the ten most common sizes
Presents per 10 s ~72 ~110 ~640

This doesn't fix the black screen, but the submit thread is no longer the limit. An earlier version of this description attributed the remaining buffers to the title's 450 always-live command allocators. Counting live imports by size showed most of them were the multi-page case above. The allocators account for about 2,100 of the 4,094 that remain; pooling them removed those buffers in a prototype without improving the frame rate, so that is not part of this PR.

The change doesn't depend on #146. It was measured with #146 underneath only because this machine's Intel CPU needs it to get past startup.

Checks

All of the CONTRIBUTING.md checks pass on this branch: the Python unit tests, the shader compiler, DXBC and XG layout tests, and the Windows typecheck of tuxbox-d3d12 with no warnings. The tuxbox-d3d12 unit tests also pass under Proton's Wine (80/80), including three new heap_page_cache tests for the multi-page key. No evidence JSON changed.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 06:00 UTC · [original](https://github.com/brcly/TuxBox/pull/148) `JeffreyBytes:fix/page-import-reuse` → `main` · +117 −24 · 2 files · 2 commits · merged 2026-11-25 07:30 UTC ## Summary Fixes #147. A placed resource imports the guest pages it covers as a host heap. Live imports were only shared for single pages inside a registered Xbox GPU page pool. ProjectScarlett places nearly all of its resources outside the pool, so the same pages were imported over and over. Each import is another driver buffer. On RADV every live buffer goes with each submission, which kept the `vkd3d_queue` thread pinned in the submit ioctl while the GPU sat idle. Two commits, both in the weak import cache next to the pool caches in `PagePools`: 1. **Single pages outside every pool.** 20,083 imports across 790 distinct pages in the first minute, one page 9,352 times. 2. **Imports that span several pages.** Buffer views over five fixed ranges of 448 KiB to 1.2 MiB are imported about five times a frame each, and the recording allocators keep each import until they are reset 216 frames later: about 4,500 live buffers. The key is the page-aligned base with the page count in its low 16 bits, so an import is reused only for exactly the same pages. Ranges of 4 GiB and above, or not made of whole pages, open a fresh import as before. Both use the same exact-range reuse and `ImportedHeap::is_live` check as `heap_page_cache.rs`. The cache never owns a heap, and a range is reopened once its import is released or its pages are remapped. `TUXBOX_TRACE_BUFFER_BACKING` reports the new paths as `page_open` / `page_hit` and `span_open` / `span_hit`. A/B on an RX 6700 XT (RADV, Mesa 26.3.1), same warm cache and settings, only `d3d12_xs.dll` differing. Each run was sampled when the game process was 300 s old: | At 300 s | `main` | + commit 1 | + commit 2 | | --- | --- | --- | --- | | Title's GPU buffers | 12,998 | 8,628 | 4,094 | | 64 KiB buffers | 4,671 | 277 | 279 | | 1.0–1.2 MiB buffers | 4,106 | 3,768 | none in the ten most common sizes | | Presents per 10 s | ~72 | ~110 | ~640 | This doesn't fix the black screen, but the submit thread is no longer the limit. An earlier version of this description attributed the remaining buffers to the title's 450 always-live command allocators. Counting live imports by size showed most of them were the multi-page case above. The allocators account for about 2,100 of the 4,094 that remain; pooling them removed those buffers in a prototype without improving the frame rate, so that is not part of this PR. The change doesn't depend on #146. It was measured with #146 underneath only because this machine's Intel CPU needs it to get past startup. ## Checks All of the CONTRIBUTING.md checks pass on this branch: the Python unit tests, the shader compiler, DXBC and XG layout tests, and the Windows typecheck of `tuxbox-d3d12` with no warnings. The `tuxbox-d3d12` unit tests also pass under Proton's Wine (80/80), including three new `heap_page_cache` tests for the multi-page key. No evidence JSON changed.
A placed resource that fits in one 64 KiB page imports exactly that page
as a host heap. Live imports were only shared for pages inside a
registered Xbox GPU page pool. ProjectScarlett 1.0.2.1 places nearly all
of its small resources outside the pool: in its first minute it made
20,083 imports covering 790 distinct pages, one page imported 9,352
times. Each import is a separate driver buffer, and RADV passes every
live buffer with each submission, so the kernel's per-submit validation
grew with the import count.

Keep a weak cache of live single-page imports outside the pools as
well, using the same exact-page reuse and ImportedHeap::is_live check as
the pool cache. The cache never owns a heap; a page is reopened once its
import is released or its pages are remapped.

On an RX 6700 XT (RADV, Mesa 26.3.1), measured 300 s into each run with
only this change differing: the title's GPU buffers fell from 12,998 to
8,604 (64 KiB buffers 4,671 to 277), and presents rose from about 72 to
about 117 per 10 s.
Only single-page imports were shared. A resource that needs more than
one 64 KiB page still opened a fresh host heap every time, even for a
range that was already imported. ProjectScarlett 1.0.2.1 creates buffer
views over five fixed ranges of 448 KiB to 1.2 MiB about five times a
frame each, and its recording allocators keep each import until they
are reset 216 frames later: about 4,500 live driver buffers, more than
half of the title's total.

Share those through the same weak cache as loose single pages. The key
is the page-aligned base with the page count in its low 16 bits, so an
import is reused only for exactly the same pages, under the same
ImportedHeap::is_live check. Ranges of 4 GiB and above, and ranges that
are not whole pages, are opened as before.

On an RX 6700 XT (RADV, Mesa 26.3.1), measured 300 s into each run with
only this change differing: the title's GPU buffers fell from 8,628 to
4,094, with none of the 1.0 to 1.2 MiB buffers left among the ten most
common sizes, and presents rose from about 110 to about 640 per 10 s.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:34:29 +00:00
github manually merged commit fd561df146 into gh-pr/148/base 2026-11-26 06:34:31 +00:00
Author
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 07:25 UTC · original · edited 2026-11-25 07:28 UTC

The follow-up is pushed: this PR now has a second commit that shares multi-page imports too, and the description above is updated with the corrected diagnosis and the 300 s A/B numbers (it previously attributed the remaining buffers to command allocators). If you would rather take the second commit as a separate PR, say so and I will split it out.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 07:25 UTC · [original](https://github.com/brcly/TuxBox/pull/148#issuecomment-7155839704) · edited 2026-11-25 07:28 UTC The follow-up is pushed: this PR now has a second commit that shares multi-page imports too, and the description above is updated with the corrected diagnosis and the 300 s A/B numbers (it previously attributed the remaining buffers to command allocators). If you would rather take the second commit as a separate PR, say so and I will split it out.
This discussion has been locked. Commenting is limited to contributors.
No description provided.