ProjectScarlett on RADV: thousands of duplicate single-page imports make every GPU submission expensive #147

Closed
opened 2026-11-26 06:34:27 +00:00 by github-bot · 1 comment
Owner

@⁠JeffreyBytes on GitHub · 2026-11-25 05:57 UTC · original

Summary

On an RX 6700 XT with RADV, ProjectScarlett shows a black window and presents only about 6–7 frames per second, with the GPU almost idle. One vkd3d_queue thread pins a full CPU core inside RADV's command-submission ioctl. The cause is the number of driver buffers the title holds: RADV passes every live buffer with each submission, and the kernel locks and validates all of them every time.

A large share of those buffers are imports of the same 64 KiB guest page, over and over. PagePools::import only reuses a live single-page import for pages inside a registered Xbox GPU page pool, and none of the title's small placed resources are in that pool. So every placement opens a new host heap, even when another live heap already covers that exact page.

What I measured

The game was still running, at a black screen, with only vkd3d_queue busy:

GPU busy (gpu_busy_percent) 1–4%
VRAM / GTT used 55% / 44% of 12 / 15.5 GiB (not exhausted)
vkd3d_queue thread 88–94% of one core
Stack (eu-stack, 6 of 6 samples) vk_queue_submit → radv_queue_submit → radv_amdgpu_winsys_cs_submit → ioctl
Thread state (/proc/<tid>/syscall) running in 284 of 300 samples, so not the 1 ms -ENOMEM retry sleep
Graphics submissions (amdgpu_fence_info, 5 s) ~235 a second, a normal rate
Buffers (amdgpu_gem_info) 17,172 system-wide

That works out to about 3.7 ms of kernel time per submission, which is the per-buffer locking and validation cost for that many buffers.

With TUXBOX_TRACE_BUFFER_BACKING=1 and TUXBOX_WATCH_ADDRESS set to cover the whole address space, the title made 20,083 imports in its first ~70 s covering only 790 distinct (page, size) pairs. None were inside the registered page pool (99,776 pages at 0xdd4770000), so pool_open / pool_hit never appeared.

Title call site (RVA) Imports Distinct pages
0x2482b37 9,352 1 (0x4fa0000 every time)
0x4ed46aa 4,691 1 (0x72cc0000)
0x2484b12 2,343 1 (0x72cc0000)
0x6dd8b 3,404 616 (256–4,352-byte buffers packed onto shared pages)
0x4ecc821 252 198

Fix (verified)

Keep a weak cache of live single-page imports for pages outside every registered pool, next to the pool caches in PagePools. It uses the same exact-page reuse and ImportedHeap::is_live check that heap_page_cache.rs already applies inside pools. The cache never owns a heap, and a page is reopened once its import is released or its pages are remapped. New trace paths page_open / page_hit mirror pool_open / pool_hit. It's one file, runtime/d3d12/src/device/heap.rs.

A/B on the same machine, warm shader cache and settings, with only d3d12_xs.dll differing. Each run was sampled when the game process was 300 s old:

At 300 s Without With Change
Title's GPU buffers 12,998 8,604 −34%
64 KiB buffers 4,671 277 −94%
All GPU buffers (system) 17,264 12,855 −26%
Presents per 10 s (last 20 samples) ~72 (61–75) ~117 (111–124) +63%

The trace shows at least 16,384 page_hits against a few dozen page_opens. All 86 tuxbox-d3d12 tests pass under Wine.

The speedup is larger than the buffer reduction alone would suggest. In the run without the fix, most of the vkd3d scratch and other mid-size buffers are listed as UNKNOWN in amdgpu_gem_info. With the fix, they're in GTT. My guess is that the extra pinned imports were pushing those buffers out of GTT, so the kernel was also moving memory around (sdma rings ran about 830 jobs a second). I haven't confirmed that.

What this doesn't fix

The window is still black, and the queue thread is still the bottleneck. Most of the remaining ~8,600 buffers match vkd3d-proton and RADV defaults exactly:

Buffers Size Source
~4,100 1 MiB + 0–3 pages vkd3d-proton per-allocator scratch (VKD3D_SCRATCH_BUFFER_SIZE_DEFAULT = 1 << 20)
~1,240 80 KiB RADV initial command-stream buffer (20 * 1024 * 4)
~1,140 16 KiB RADV minimum command-buffer upload buffer (16 * 1024)

These come from the title's command allocators. It creates 450 at startup and keeps all of them alive, which is cheap on the console. Under vkd3d-proton, each allocator keeps its own scratch pools and its command buffers' memory. Texture uploads and readbacks, and GPU memory-wait segments, are not a factor: I counted them, and they're freed within a frame or two. Pooling native allocators behind the guest's allocators would probably need some design discussion, so I'll raise it separately.

NVIDIA's driver doesn't validate a per-submission buffer list this way. That would explain why every ProjectScarlett run that got further so far is on NVIDIA. #39 (RX 9060 XT, RADV, black screen) may be the same bottleneck. A quick top -H on the game's vkd3d_queue thread would show it.

Related: Mesa #4330 was a different RADV submission slowdown, fixed in 2021. In it, the vkd3d-proton author notes they "attempt suballocation of all committed resources" to keep the buffer count down. Imports can't be suballocated, so TuxBox has to avoid creating duplicates itself.

Environment

  • Package RockstarGamesInc.28872443D20A7 1.0.2.1, game_scarlett_master.exe SHA-256 e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993
  • CPU: Intel Core i5-12600K (needs #146 to get past startup)
  • GPU: AMD Radeon RX 6700 XT, RADV, Mesa 26.3.1, resizable BAR
  • Proton: 1794497090 experimental-11.0-20261112-x86_64, umu-launcher 1.4.3
  • OS: CachyOS, kernel 7.3.5
  • TuxBox: 97b8ad3 + #146 (e1262ac); fix on top as 7216bb9
  • Launched offline with unshare --user --map-current-user --net, as in the docs
**@⁠JeffreyBytes** on GitHub · 2026-11-25 05:57 UTC · [original](https://github.com/brcly/TuxBox/issues/147) ## Summary On an RX 6700 XT with RADV, ProjectScarlett shows a black window and presents only about 6–7 frames per second, with the GPU almost idle. One `vkd3d_queue` thread pins a full CPU core inside RADV's command-submission ioctl. The cause is the number of driver buffers the title holds: RADV passes every live buffer with each submission, and the kernel locks and validates all of them every time. A large share of those buffers are imports of the **same 64 KiB guest page, over and over**. `PagePools::import` only reuses a live single-page import for pages inside a registered Xbox GPU page pool, and none of the title's small placed resources are in that pool. So every placement opens a new host heap, even when another live heap already covers that exact page. ## What I measured The game was still running, at a black screen, with only `vkd3d_queue` busy: | | | | --- | --- | | GPU busy (`gpu_busy_percent`) | 1–4% | | VRAM / GTT used | 55% / 44% of 12 / 15.5 GiB (not exhausted) | | `vkd3d_queue` thread | 88–94% of one core | | Stack (`eu-stack`, 6 of 6 samples) | `vk_queue_submit` → `radv_queue_submit` → `radv_amdgpu_winsys_cs_submit` → `ioctl` | | Thread state (`/proc/<tid>/syscall`) | running in 284 of 300 samples, so not the 1 ms `-ENOMEM` retry sleep | | Graphics submissions (`amdgpu_fence_info`, 5 s) | ~235 a second, a normal rate | | Buffers (`amdgpu_gem_info`) | 17,172 system-wide | That works out to about 3.7 ms of kernel time per submission, which is the per-buffer locking and validation cost for that many buffers. With `TUXBOX_TRACE_BUFFER_BACKING=1` and `TUXBOX_WATCH_ADDRESS` set to cover the whole address space, the title made **20,083 imports in its first ~70 s covering only 790 distinct (page, size) pairs**. **None** were inside the registered page pool (99,776 pages at `0xdd4770000`), so `pool_open` / `pool_hit` never appeared. | Title call site (RVA) | Imports | Distinct pages | | --- | --- | --- | | `0x2482b37` | 9,352 | 1 (`0x4fa0000` every time) | | `0x4ed46aa` | 4,691 | 1 (`0x72cc0000`) | | `0x2484b12` | 2,343 | 1 (`0x72cc0000`) | | `0x6dd8b` | 3,404 | 616 (256–4,352-byte buffers packed onto shared pages) | | `0x4ecc821` | 252 | 198 | ## Fix (verified) Keep a weak cache of live single-page imports for pages outside every registered pool, next to the pool caches in `PagePools`. It uses the same exact-page reuse and `ImportedHeap::is_live` check that `heap_page_cache.rs` already applies inside pools. The cache never owns a heap, and a page is reopened once its import is released or its pages are remapped. New trace paths `page_open` / `page_hit` mirror `pool_open` / `pool_hit`. It's one file, `runtime/d3d12/src/device/heap.rs`. A/B on the same machine, warm shader cache and settings, with only `d3d12_xs.dll` differing. Each run was sampled when the game process was 300 s old: | At 300 s | Without | With | Change | | --- | --- | --- | --- | | Title's GPU buffers | 12,998 | 8,604 | −34% | | 64 KiB buffers | 4,671 | 277 | −94% | | All GPU buffers (system) | 17,264 | 12,855 | −26% | | Presents per 10 s (last 20 samples) | ~72 (61–75) | ~117 (111–124) | +63% | The trace shows at least 16,384 `page_hit`s against a few dozen `page_open`s. All 86 `tuxbox-d3d12` tests pass under Wine. The speedup is larger than the buffer reduction alone would suggest. In the run without the fix, most of the vkd3d scratch and other mid-size buffers are listed as `UNKNOWN` in `amdgpu_gem_info`. With the fix, they're in `GTT`. My guess is that the extra pinned imports were pushing those buffers out of GTT, so the kernel was also moving memory around (sdma rings ran about 830 jobs a second). I haven't confirmed that. ## What this doesn't fix The window is still black, and the queue thread is still the bottleneck. Most of the remaining ~8,600 buffers match vkd3d-proton and RADV defaults exactly: | Buffers | Size | Source | | --- | --- | --- | | ~4,100 | 1 MiB + 0–3 pages | vkd3d-proton per-allocator scratch (`VKD3D_SCRATCH_BUFFER_SIZE_DEFAULT = 1 << 20`) | | ~1,240 | 80 KiB | RADV initial command-stream buffer (`20 * 1024 * 4`) | | ~1,140 | 16 KiB | RADV minimum command-buffer upload buffer (`16 * 1024`) | These come from the title's command allocators. It creates 450 at startup and keeps all of them alive, which is cheap on the console. Under vkd3d-proton, each allocator keeps its own scratch pools and its command buffers' memory. Texture uploads and readbacks, and GPU memory-wait segments, are not a factor: I counted them, and they're freed within a frame or two. Pooling native allocators behind the guest's allocators would probably need some design discussion, so I'll raise it separately. NVIDIA's driver doesn't validate a per-submission buffer list this way. That would explain why every ProjectScarlett run that got further so far is on NVIDIA. #39 (RX 9060 XT, RADV, black screen) may be the same bottleneck. A quick `top -H` on the game's `vkd3d_queue` thread would show it. Related: [Mesa #4330](https://gitlab.freedesktop.org/mesa/mesa/-/work_items/4330) was a different RADV submission slowdown, fixed in 2021. In it, the vkd3d-proton author notes they "attempt suballocation of all committed resources" to keep the buffer count down. Imports can't be suballocated, so TuxBox has to avoid creating duplicates itself. ## Environment - Package `RockstarGamesInc.28872443D20A7` 1.0.2.1, `game_scarlett_master.exe` SHA-256 `e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a08993` - CPU: Intel Core i5-12600K (needs #146 to get past startup) - GPU: AMD Radeon RX 6700 XT, RADV, Mesa 26.3.1, resizable BAR - Proton: 1794497090 experimental-11.0-20261112-x86_64, umu-launcher 1.4.3 - OS: CachyOS, kernel 7.3.5 - TuxBox: `97b8ad3` + #146 (`e1262ac`); fix on top as `7216bb9` - Launched offline with `unshare --user --map-current-user --net`, as in the docs
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:34:27 +00:00
Author
Owner

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

Update: the diagnosis in this issue was incomplete. I attributed the buffers left after the single-page fix to the title's 450 always-live command allocators. Counting live imports by size showed most of them were the multi-page case of the same bug: buffer views over five fixed ranges of 448 KiB to 1.2 MiB, imported about five times a frame each and kept alive for 216 frames, about 4,500 live buffers.

#148 now has a second commit that shares those imports too. At 300 s on the same machine the title's GPU buffers go from 8,628 to 4,094 and presents from about 110 to about 640 per 10 s. The screen is still black, but the submit thread is no longer what limits the frame rate.

For the record on the allocators: the title records into one allocator per frame from a ring of 216 and resets each only when its turn comes round again, so about 217 native allocators hold a frame's recording at any time. A prototype that backs them with a small native pool ran on 8 allocators and removed about 2,100 more buffers, but did not improve the frame rate, so I have not proposed it.

**@⁠JeffreyBytes** on GitHub · 2026-11-25 07:28 UTC · [original](https://github.com/brcly/TuxBox/issues/147#issuecomment-7155893138) Update: the diagnosis in this issue was incomplete. I attributed the buffers left after the single-page fix to the title's 450 always-live command allocators. Counting live imports by size showed most of them were the multi-page case of the same bug: buffer views over five fixed ranges of 448 KiB to 1.2 MiB, imported about five times a frame each and kept alive for 216 frames, about 4,500 live buffers. #148 now has a second commit that shares those imports too. At 300 s on the same machine the title's GPU buffers go from 8,628 to 4,094 and presents from about 110 to about 640 per 10 s. The screen is still black, but the submit thread is no longer what limits the frame rate. For the record on the allocators: the title records into one allocator per frame from a ring of 216 and resets each only when its turn comes round again, so about 217 native allocators hold a frame's recording at any time. A prototype that backs them with a small native pool ran on 8 allocators and removed about 2,100 more buffers, but did not improve the frame rate, so I have not proposed it.
This discussion has been locked. Commenting is limited to contributors.
No description provided.