Skip to content

d3d12: hold less memory on an integrated GPU - #653

Draft
revonateB0T wants to merge 2 commits into
brcly:mainfrom
revonateB0T:main
Draft

revonateB0T wants to merge 2 commits into
brcly:mainfrom
revonateB0T:main

Conversation

@revonateB0T

@revonateB0T revonateB0T commented Dec 2, 2026 •

Copy link
Copy Markdown

An integrated GPU has one pool of system memory, so every copy the provider makes of game memory its driver cannot import is paid for twice: once as the copy the GPU reads, and once as the baseline that tells the CPU's changes from the GPU's. The baseline is now a digest of each 64-byte chunk, and the buffers the provider keeps for reuse share one budget instead of one per reader and one per queue.

This branch holds those two changes only. The UMA detection, the ledger and the cache limits that were in it before are in separate work: on this host the driver reports a non-zero dedicated video memory for the adapter, so the "one memory pool" path does not trigger, and forcing it with TUXBOX_HOST_PROFILE=memory=unified only moves the same 3749 MiB from the driver's video memory to the host's. A module that read the host's memory to compute the two limits was dropped as well: it computed min(256 MiB, host_total / 32), which is the 256 MiB constant that was there before, so the limits are the constants again.

Summary

On an integrated GPU the provider was paying twice for every byte of game memory its driver cannot import: the copy the GPU reads, and a byte-for-byte baseline that says which bytes the CPU changed. The baseline is now a digest of each 64-byte chunk, so the copy costs 1.125 times the range instead of twice.

The buffers the provider keeps for reuse — one pool per reader (twelve of them) and a readback pool per queue — share one budget now, so the memory they hold follows the work rather than the number of queues and workers.

Measured in ProjectScarlett on an AMD Radeon 780M under GE-Proton11-16, with the same prefix and title state, one build against the other:

Shadows Provider heap Driver system memory
Before 1481 MiB (129 shadows) 1762 MiB 1575 MiB
After 834 MiB (129 shadows) 1080 MiB 927 MiB

The same 129 shadows cost 647 MiB less, and the provider's own heap 682 MiB less: about 1.3 GiB on a 13.6 GiB host. Before the change the title died in system initialisation with its 6236 MB tile heap; with it the title reaches its title screen.

It still cannot enter the scene on this path. At the title screen the provider and the driver hold about 5.7 GiB beside the tile heap, of which the render target copies are 3127 MiB: this driver cannot import a section-backed page, so the provider gives the GPU a copy of every render target the title places in its own memory. The title places 572 of them and holds every one alive — 314 of them are depth pyramids and shadow maps under 1 MiB each, and the colour targets are the rest, 8 to 58 MiB each. Letting the scene fit on a host this size needs that copy to go away or to shrink, which is a larger change than this one.

The private path does not have that copy. With #660 merged the title reaches the scene there — its streaming requests reach zero — at about 120 frames a second instead of 5, and it does not go green, because the green screen is the page-table refusal of #656, which the private path does not meet. What is still missing there is #456: a second mapping of a page cannot be promoted while a host import holds it, and that first access kills the title. It shows up as an occasional crash in the first seconds.

Tested

Run the checks relevant to this change.

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

GPU, driver and backend:

  • AMD Radeon 780M (RADV PHOENIX, 1002:15bf), Mesa 26.3.1, kernel 7.3.7, GE-Proton11-16, 13.6 GiB host.
    NVIDIA has not run them. This machine has no NVIDIA card, and the change is shared code: it adds
    a reading of the adapter's own description to the host profile, and no path is chosen by vendor.
    The suites below must pass on an NVIDIA card before this merges.

On this head the Windows typecheck, Clippy and Formatting pass. The gate below ran on the same change
before the rebase onto main; the rebase dropped the host-memory module and kept upstream's own fix
for a deprecated atomic call, so no provider code of this change moved.

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 a6f3e0989718, no uncommitted changes, no GPU checks: 12 passed, 1 failed, 0 not run

The one failure is the Python step, and it is not from this change: the DXC helper cannot be compiled
on this host (/usr/include/c++/16/cstdlib: fatal error: stdlib.h: No such file or directory), so the
three test_dxc_worker tests error out instead of skipping. The same three fail with this branch's
changes reverted.

Commands run and their results:

$ python tuxbox.py check --no-gpu
  passed  Build the shader compiler / Synthetic shaders through the runtime's DXC flags /
           Shader compiler tests / DXBC tests / XG layout tests / XG entry point tests /
           BVH layout tests / Storage codec tests / ACP HAL tests /
           Windows typecheck / Clippy / Formatting
  FAILED  Python tests (3 test_dxc_worker errors: the DXC helper does not compile on this host)

$ python tuxbox.py verify --output build/verify-uma.json --proton GE-Proton11-16 \
      --prefix proton-ge-custom --windows-dxc ~/.winemonogame/drive_c/windows/system32 \
      --adapter 1002:15bf \
      --only cpu --only xmem --only xapu --only xgameruntime --only xcrdapi \
      --only graphics --only graphics-abi --only guest-frame --only present --only lanes \
      --only lanes-selftest --only lanes-shader-cache --only lanes-raster-tables \
      --only lanes-compute-root --only lanes-compute-root-recovery --only lanes-compute-root-srv \
      --only lanes-compute-root-constants --only lanes-large-dispatch --only lanes-late-pipeline \
      --only lanes-bindless-compute --only lanes-compute-heap-stride --only lanes-descriptor-tail \
      --only lanes-benchmark --only d3d12-exports --only d3d12-features --only d3d12-indirect \
      --only d3d12-queries --only d3d12-queues --only d3d12-tables --only d3d12-heaps \
      --only d3d12-placement --only d3d12-copy-resource --only d3d12-draw --only d3d12-stream \
      --only d3d12-frame-events --only d3d12-guids --only d3d12-signatures --only d3d12-mesh \
      --only xg-provider --only xg --only acphal
  140 suites passed, 13 failed

$ # the same 13, one build against the other:
$ git checkout origin/main -- runtime/d3d12 runtime/xmem && python build.py d3d12 xmem && <same verify>
  the same 13 failures, identical list

The 13 failures are the same on main as on this branch, and they are the host's: this machine's
Proton build cannot import a section-backed page, so the queue page mappings of #656 fail, and the
scene in the title never draws.

A control for the digest path is added: d3d12-buffer-import --shadow reads 1 MiB of XMem physical
pages through the provider's copy, rewrites them on the CPU and reads them again, and the receipt
carries words=262144/262144 passes=2.

AI use

The code change and the measurements were prepared with an AI coding agent (DeepSeek Harness, running
MiniMax-M3.1-Flash, following AGENTS.md). All runs were executed on my local machine.

@revonateB0T
revonateB0T marked this pull request as draft December 2, 2026 12:41
@revonateB0T

Copy link
Copy Markdown
Author

Will mark ready when I successfully run into real play scene.

The provider keeps staging and readback buffers for reuse, and it kept
them per queue and per worker: twelve check pools of their own, and a
readback pool for every queue. On an integrated adapter those buffers
sit beside the title's pages, and the same work is done by all of them
at once.

They share one pool now, and the amount they keep follows one budget
rather than the number of queues and workers.
@revonateB0T

Copy link
Copy Markdown
Author

Above comment is somewhat outdated and needs update.

The baseline of a shadow heap was a full copy of the guest's bytes, so
that the CPU's changes could be told from the GPU's. On a host that
cannot import the title's pages, that made the copy twice the size of
the range the GPU reads.

The shadow keeps a digest of each 64-byte block instead of its bytes:
one 64-bit value per block, which tells a changed block from an
unchanged one. The copy is gone and the shadow is 1.125 times the
range rather than 2.

This is the one change of the set that the private path does not use:
with private pages the provider imports the title's memory and keeps
no shadow at all.
@revonateB0T

revonateB0T commented Dec 2, 2026 •

Copy link
Copy Markdown
Author

A note on where this branch stands, because it is not the end of the work.

What is in this branch now. Two commits: the buffers the provider keeps for reuse share one budget instead of one per reader (twelve of them) and one per queue, and the shadow keeps a digest of each 64-byte chunk instead of a second copy of the guest's bytes. The UMA detection, the ledger and the cache limits that were in this branch before are separate work now, and nothing in this branch depends on them. They only pay off where the provider can tell that the adapter shares the host's memory; on this host the driver reports a non-zero dedicated video memory for the adapter, so that answer never comes out, and forcing it only moves the same 3749 MiB from the driver's video memory to the host's — bookkeeping, not a saving.

A third change that belongs to the same problem. A batch the provider cannot order is refused, and the refusal marks the queue: every later batch submitted to it is dropped (its later batches are dropped). The 3D world needs ordered batches and stays black while the 2D layers, which do not, are drawn — the symptom reported in #663. That fix is one commit, and it will go out as its own pull request:

d3d12: drop a batch that cannot be ordered instead of refusing it

The private path. With #660 merged the title's private pages are imported by the driver, the page-table path is not refused there, and on a Radeon 780M the title reaches the scene — its streaming requests reach zero — at about 120 frames a second instead of 5, and it does not go green, because the green screen is the page-table refusal of #656. What is still missing there is #456: a second mapping of a page cannot be promoted while a host import holds it, and that first access kills the title. It shows up as an occasional crash in the first seconds.

What keeps the scene out on this path. The render target copies: 3127 MiB in 572 heaps, of which 314 are depth pyramids and shadow maps under 1 MiB each, and the title holds every one of them alive. With --graphics-profile series-s they fall to 166 MiB, which is what lets the scene fit on a small card at all. Shrinking them further is a larger change than this one.

The plan. After testing, the two commits here go out as individual pull requests, because this one is not the end of the work: the private path, the render target copies and #456 all belong to the same problem and will be tracked on top of it.

AI use

The measurements and the code changes behind this were prepared with an AI coding agent (DeepSeek Harness, running MiniMax-M3.1-Flash, following AGENTS.md). All runs were executed on my local machine.

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.

1 participant