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

Merged
JeffreyBytes merged 2 commits from upstream-pr/148 into main 2026-11-25 07:30:32 +00:00
JeffreyBytes commented 2026-11-25 06:00:15 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-25T06:00:15Z.


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.

<!-- greyfinch-sync:brcly/TuxBox:issue:6598276395 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/148). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-25T06:00:15Z. --- ## 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 commented 2026-11-25 07:25:14 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-25T07:25:14Z.


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.

<!-- greyfinch-sync:brcly/TuxBox:comment:7155839704 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/148#issuecomment-7155839704). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-25T07:25:14Z. --- 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.
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!148
No description provided.