d3d12, xmem: check only the placed textures that may have been written #430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/430"
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 NickStallman on 2026-11-28T23:54:51Z.
Summary
Placed textures are checked against title memory on every submission. After this change, D3D12 checks only textures that may have been written, using the OS write watch on XMem's private pages, so an unchanged texture costs one atomic load instead of a read and digest.
What changes
MEM_WRITE_WATCH. One scan per refresh finds the pages written since the last one. A page's range is marked before its texture is read, so no write is missed between the check and the next scan.Unmap, and publication write-back.QueryInterfaceper unequal fence.TUXBOX_PLACEMENT_WATCH=0turns it off.TUXBOX_PLACEMENT_LAZY_FLUSH=1(off by default) scans only the firstD3DFlushEntireCpuCacheafter a submission; it is not exact, and the docs say why.TUXBOX_SUBMIT_PROFILE=1reports each step.What it doesn't do: reduce the readback of GPU-written textures. That is the larger cost in the game, and #413 builds on this branch.
Measured
xmem.dll: BC7 128² 0.140 ms/MiB without the watch, 0.0004 with it; BC1 1024² 0.046–0.057 against 0.00015; RGBA8 2048² 0.040 against 0.00014. A 1 GiB scan of 16 runs takes 0.15 ms.QueryInterfaceabout 12 times slower, and some ran with the desktop locked.Known limits
double free or corruption. It also happens without this change, on both cards, before any GPU test finishes. I haven't found the cause.Tested
Tests: XMem (writes at the first and last byte and page boundaries, ReadFile, WriteProcessMemory, a write between scan and re-arm, import holds, section promotion, remaps, merged runs), D3D12 (unchanged textures do no digest, held and section textures are always checked, a texture re-armed before it is read, the reader and write indexes against brute force, the lock split, the fence-compare count). A texture-publication, texture-readback, cross-queue and copy-memory Lanes pass on both cards.
GPU, driver and backend:
Commands run and their results:
🤖 Generated with Claude Code