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

Open
JeffreyBytes wants to merge 1 commit from upstream-pr/667 into main
JeffreyBytes commented 2026-12-03 01:30:46 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-12-03T01:30:46Z.


Caution

Needs a run on Nvidia hardware prior to merge.

Summary

Fixes #666.

Since 106120ca, 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 (https://github.com/brcly/TuxBox/issues/533#issuecomment-7358936475). 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. That does cost something, which this PR doesn't change: it comes from 106120ca's single-page imports, not from the cache split. An earlier version of this description said the queue thread's kernel time didn't rise with them; that was the wrong place to look. Timed around the shared init queue, each initialize_gpu_tiles submission took about 1.5 ms while fewer than 1,000 single-page imports were live and 10–41 ms at 8,000–13,000, and the title's threads spent about 114 s of a 250 s load waiting on it. Details in https://github.com/brcly/TuxBox/issues/669#issuecomment-7380503963).

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)

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.

The exit 5 that remains is not from this PR and not from older builds either: on this card 6d4f1cd7 (before the queue page mapping series) doesn't hit it. It's the per-submission cost tracked in #669 (bisect).

<!-- greyfinch-sync:brcly/TuxBox:issue:5617984377 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/667). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-12-03T01:30:46Z. --- > [!CAUTION] > Needs a run on Nvidia hardware prior to merge. ## Summary Fixes #666. Since 106120ca, 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 (https://github.com/brcly/TuxBox/issues/533#issuecomment-7358936475). 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. That does cost something, which this PR doesn't change: it comes from 106120ca's single-page imports, not from the cache split. An earlier version of this description said the queue thread's kernel time didn't rise with them; that was the wrong place to look. Timed around the shared init queue, each `initialize_gpu_tiles` submission took about 1.5 ms while fewer than 1,000 single-page imports were live and 10–41 ms at 8,000–13,000, and the title's threads spent about 114 s of a 250 s load waiting on it. Details in https://github.com/brcly/TuxBox/issues/669#issuecomment-7380503963). ## Tested - [x] The checks relevant to this change passed - [x] 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): ```text Evidence: TuxBox check of 2898c907d7e4, no uncommitted changes, GPU default adapter: 17 passed, 0 failed, 0 not run ``` Commands run and their results: ```text 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) ``` 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. The exit 5 that remains is not from this PR and not from older builds either: on this card 6d4f1cd7 (before the queue page mapping series) doesn't hit it. It's the per-submission cost tracked in #669 ([bisect](https://github.com/brcly/TuxBox/issues/669#issuecomment-7371210234)).
turboheadcrab commented 2026-12-03 06:55:40 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by turboheadcrab on 2026-12-03T06:55:40Z.


Tested 2898c907 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 106120ca just before it.

106120ca #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.

<!-- greyfinch-sync:brcly/TuxBox:comment:7370393257 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/667#issuecomment-7370393257). Originally posted by [turboheadcrab](https://github.com/turboheadcrab) on 2026-12-03T06:55:40Z. --- Tested 2898c907 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 106120ca just before it. | | 106120ca | #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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/667:upstream-pr/667'
git switch 'upstream-pr/667'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/667'
git switch 'upstream-pr/667'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/667'
git switch 'upstream-pr/667'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/667'
git switch 'main'
git merge --squash 'upstream-pr/667'
git switch 'main'
git merge --ff-only 'upstream-pr/667'
git switch 'main'
git merge 'upstream-pr/667'
git push origin 'main'
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!667
No description provided.