d3d12: release the scratch pages past a stored texture snapshot #324
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/324"
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?
Imported from brcly/TuxBox. Originally posted by proof-by-vibes on 2026-11-27T18:58:32Z.
Summary
Upload compares every placed texture's mips through one scratch buffer,
Transfer::scratch.snapshot_mipreserves the mip's size, which never shrinks the buffer, and writes the mip into it. After a large mip, the buffer keeps that capacity with its pages touched. When a mip has changed, the buffer moves intoContents::previousas its snapshot, and the snapshot it replaces becomes the next scratch. Snapshots live as long as their texture, so small mips end up holding the resident pages of the largest mip their buffer ever compared.Snapshots are now stored through
Contents::store. When at least 64 KiB of whole pages lie past the snapshot's bytes, it resets them withVirtualAlloc(MEM_RESET). Nothing is copied: theVecstill owns the memory and can grow back into it, and only the contents past its length, which it never reads, are discarded.shrink_to_fitdoesn't help here. Wine shrinks a large heap block in place, and its pages stay resident. A standalone probe under GE-Proton11-14 filled 64 scratch buffers of 16 MiB each and kept 4 KiB of each, reading the process'sRssAnonfrom Linux:RssAnongrowthtruncate+shrink_to_fitMEM_RESETon the pages past the lengthMeasured in ProjectScarlett
ProjectScarlett 1.0.2.1 on an RX 7900 XTX. The runs were made before #258 was merged, with #258 at its earlier head
d50a51con an oldermain. #258 backs guest memory withMEM_PRIVATE, which is what makes the effect show inRssAnon. In the upload burst as the world streams in, theRssAnonthe burst left behind was:The burst still peaks briefly, at about the same height as before, because comparing still fills the scratch buffers. The pages are released when the snapshots are stored, within one 5 s sample. A local trace of snapshot capacity, not included here, had measured 11.6 GiB held with 6.8 GiB of it past the snapshots' lengths in a run without this change.
Not yet repeated: the game runs on the current
main, which now includes #258.Tested
Run the checks relevant to this change.
No Lanes scenario: the snapshots are the provider's own host memory, which a title can't observe. Unit tests in
src/tests/device/placement/contents.rscover the change instead.a_stored_snapshot_releases_the_scratch_pages_past_its_byteschecks withQueryWorkingSetExthat a page past the snapshot is no longer resident, and it fails without the change.a_released_snapshot_can_grow_backchecks that a reused buffer keeps its bytes and refills the released pages.store_returns_the_replaced_snapshot_for_reusechecks the scratch handover.GPU, driver and backend: AMD Radeon RX 7900 XTX (
1002:744c, RADV NAVI31), Mesa 26.1.8, Linux 6.18.57, GE-Proton11-14 (protonbackend)Commands run and their results. The full check ran on
07db0df, beforemain(with #258) was merged into this branch. The unit tests ran again on the merged headba78020.Checks
CI runs the Python unit tests, the shader compiler, DXBC, and XG layout tests, and a Windows typecheck of
tuxbox-d3d12.No evidence JSON changes.