Repository navigation
d3d12: hold less memory on an integrated GPU - #653
revonateB0T wants to merge 2 commits into
Conversation
|
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.
|
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.
|
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 ( 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 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 useThe measurements and the code changes behind this were prepared with an AI coding agent (DeepSeek Harness, running MiniMax-M3.1-Flash, following |
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=unifiedonly 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 computedmin(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:
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.
GPU, driver and backend:
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 fixfor a deprecated atomic call, so no provider code of this change moved.
The
Evidence:linetuxbox.py checkprints last, one per card (it names the commit it tested; run it on this pull request's head):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 thethree
test_dxc_workertests error out instead of skipping. The same three fail with this branch'schanges reverted.
Commands run and their results:
The 13 failures are the same on
mainas on this branch, and they are the host's: this machine'sProton 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 --shadowreads 1 MiB of XMem physicalpages 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.