ProjectScarlett on RADV: thousands of duplicate single-page imports make every GPU submission expensive #147
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox#147
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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_queuethread 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::importonly 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_queuebusy:gpu_busy_percent)vkd3d_queuethreadeu-stack, 6 of 6 samples)vk_queue_submit→radv_queue_submit→radv_amdgpu_winsys_cs_submit→ioctl/proc/<tid>/syscall)-ENOMEMretry sleepamdgpu_fence_info, 5 s)amdgpu_gem_info)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=1andTUXBOX_WATCH_ADDRESSset 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 at0xdd4770000), sopool_open/pool_hitnever appeared.0x2482b370x4fa0000every time)0x4ed46aa0x72cc0000)0x2484b120x72cc0000)0x6dd8b0x4ecc821Fix (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 andImportedHeap::is_livecheck thatheap_page_cache.rsalready 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 pathspage_open/page_hitmirrorpool_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.dlldiffering. Each run was sampled when the game process was 300 s old:The trace shows at least 16,384
page_hits against a few dozenpage_opens. All 86tuxbox-d3d12tests 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
UNKNOWNinamdgpu_gem_info. With the fix, they're inGTT. 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:
VKD3D_SCRATCH_BUFFER_SIZE_DEFAULT = 1 << 20)20 * 1024 * 4)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 -Hon the game'svkd3d_queuethread 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
RockstarGamesInc.28872443D20A71.0.2.1,game_scarlett_master.exeSHA-256e95020b2fa4a721db3df59fdecf75621730ac559d8835252f6c3b658d5a0899397b8ad3+ #146 (e1262ac); fix on top as7216bb9unshare --user --map-current-user --net, as in the docs@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.