Skip to content

d3d12: cache GPU tile spans apart from single pages (#666) - #667

Draft
JeffreyBytes wants to merge 1 commit into
brcly:mainfrom
JeffreyBytes:fix/cluster-window-cache
Draft

JeffreyBytes wants to merge 1 commit into
brcly:mainfrom
JeffreyBytes:fix/cluster-window-cache

Conversation

@JeffreyBytes

@JeffreyBytes JeffreyBytes commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Needs a run on Nvidia hardware prior to merge.

Summary

Fixes #666.

Since 106120c, RADV backs queue page mappings with private memory, and gpu_tile imports a lot of pages one at a time. Those single-page pieces stay live while a GpuTile holds them, and they shared the pieces PageCache with the cluster windows from shared_window. Once 4,096 were live the cache stopped indexing new keys, so every page in a new window imported the whole window again. On my RX 6700 XT, ProjectScarlett hit 18 GiB of GTT a minute after the setup screens and then lost the device (Not enough memory for command submission).

This keeps single pages and spans in separate caches (PieceCaches), each with the existing bound. It also releases the cache lock before opening a piece that has no cache key, as the old code did.

DrArroway found this first, on an RX 6900 XT, and their local fix10 stack adds a separate cluster_pieces cache for the same reason (#533 comment). This PR is the same split, so credit to them. Their stack also limits shared_window() to MEM_MAPPED pages and holds whole private cluster windows. Neither is in this PR, which only splits the cache.

The single-page cache can still fill, but in practice that hardly matters. With a trace on top of this branch, the title opened 14,499 single-page pieces for 14,241 distinct pages, so at most 258 were opened again, and that count includes pages reopened after their last holder let go. About 13,000 single-page heaps (plus about 1,000 cluster heaps) are live at once, each a buffer on every submit. I measured the queue thread's kernel time and found no cost from them: it was already 40-45% of a core before any single-page pieces existed, and it didn't rise as they grew from 1,000 to 11,000.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

GPU, driver and backend: RX 6700 XT (1002:73df), RADV / Mesa 26.3.1, GE-Proton11-15, section-import=substituted

The Evidence: line tuxbox.py check prints last, one per card (it names the commit it tested; run it on this pull request's head):

Evidence: TuxBox check of 2898c907d7e4, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run

Commands run and their results:

python tuxbox.py check --proton <GE-Proton11-15> --prefix <scratch prefix> --windows-dxc <dir>: 17 passed
cargo +nightly miri test --target x86_64-pc-windows-msvc --lib -p tuxbox-d3d12 heap_page_cache
  10 passed. live_single_pages_do_not_keep_a_span_out_of_the_cache fails when both kinds go to one cache.
cargo clippy --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --all-targets -- -D warnings: clean

ProjectScarlett, same card:
  106120ca: exit 3 at 170-194 s, device lost, adapter system memory 18-27 GiB (3 runs)
  this PR:  no device loss, adapter system memory peaks at 4.4 GiB, exit 5 at 444 s on the
            title's main-thread watchdog (exe+0x23CF683, #215), as on older builds

The new test is a unit test on the cache, not a Lanes scenario: reproducing it in Lanes would need more than 4,096 live single-page queue mappings.

Since 106120c a host that substitutes section imports backs queue page
mappings with private memory, and gpu_tile imports many pages one at a
time. Those single-page pieces stay live while a GpuTile holds them, and
they shared one PageCache with the cluster windows of shared_window. Once
4,096 pieces were live the cache stopped indexing new keys, so a new
window was imported again for every page in it. On an RX 6700 XT (RADV)
ProjectScarlett reached 18 GiB of GTT within a minute of the setup
screens, and the next submission failed with "Not enough memory for
command submission" and VK_ERROR_DEVICE_LOST.

Single pages and spans now have separate caches with their own bounds.
Opening an uncached piece no longer holds the cache lock.

ProjectScarlett on the same card: before, 655 windows took 4,599 imports
and the device was lost at 170-194 s. After, adapter system memory
peaks at 4.4 GiB and the title runs 444 s with no device loss, until the
known main-thread watchdog (brcly#215).
@turboheadcrab

Copy link
Copy Markdown

Tested 2898c90 on an RX 9070 XT (RADV from Mesa 26.3.1, kernel 7.3.5, GE-Proton), packaged profile. I started a new game from the intro, under the same conditions as a run on 106120c just before it.

106120c #667
GTT at the intro (drm-total-gtt) 1.4 GiB 1.4 GiB
Peak GTT 19.2 GiB 4.3 GiB
End Not enough memory for command submission, device lost, exit 3 at 750 s no device loss; title watchdog exe+0x23CF683, exit 5 at 938 s

The runaway is gone on this card, so this looks like it fixes #666 here.

The watchdog afterwards seems to be a separate problem, filed as #669. Every userptr import is walked by amdgpu on each CS, at about 8.4 ms per GiB. With #667, GTT still grew from 1.4 to 4.3 GiB after the new game started. The median CS time went from 13 to 56 ms, and the frame rate fell to 1–1.7 fps, after which the title's 30 s watchdog fired. That matches the exit 5 you saw after your local fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

d3d12: since 106120ca, a full piece cache re-imports the same GPU page cluster windows until RADV loses the device (RX 6700 XT)

2 participants