diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-27 05:56:53 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-27 05:56:53 -0500 |
| commit | 0cdc80d2075a7e22f24c76f4a9cfe6c0ae72f08a (patch) | |
| tree | b1e161d6960d02cdf73723c51b5b583c5858600e /runtime/shims/xmem.cpp | |
| parent | f950eaae8f63f6ad90c8bf47d5d8cd874ed8969c (diff) | |
d3d12: slot-133 buffers, title windows and pool extents onto the page mirror; GPU writes into mirrored pages go back; hot/cold tracking; homes by budget (RT-PAGE-MIRROR)
Step C, with the previous WIP commit.
- Resource::create_mirror_buffer: a slot-133 buffer over title memory the mirror holds in one chunk is bound to that
chunk at heap_base + its title address: no import, no shadow, no per-submission walk or guard of its own. Its GPU VA
is the title address; V#s and root views naming it keep that address. Title windows and stream-pool extents are not
made for mirrored memory (resolve_title_memory answers the mirror first, since step B).
- Write-back (DeviceState::page_mirror_write_back, from write_back_titles after the reaching submission retired): the
256-byte pieces whose home differs from the title's page are written back through kernel_writes, on pages nothing
wrote since they were last armed (TitleMirrorTracking::unwritten); a page written on both sides keeps the title's
bytes, which are uploaded over the home before the next submission. Ranges are noted (note_title_write, with its
caps) where a V#, a writable geometry range, a title-memory resolution or a BVH range is answered by the mirror.
- The mirror's tracking is HotColdTracking (src/title_mirror_hot_cold.h); it now answers unwritten() for cold pages
from the version its guard was armed at (an additive change to that file and to the interface, default false).
- Homes go to device-local memory while VK_EXT_memory_budget keeps 1.5 GiB (or an eighth of the budget) for the
title's textures and render targets after a unit, to host memory otherwise, decided per 32 MiB unit and logged when
it switches; the mirror's line and the mem-probe item count units of each kind.
- The mirror's line adds hot and cold pages, write faults, hot and cold copies, and KiB uploaded a submission and a
frame.
Not moved: the XMemAlloc heap (HeapCreate places it). RtlCreateHeap over a reservation in the mirror's range faults
under Wine (it writes the reserved base), so it stays outside the mirror; slot-133 buffers there keep their shadows.
Tests: d3d12_page_mirror_test (Wine, iGPU): a slot-133 buffer over mirrored memory has the title's address as its GPU
VA and is no shadow; a GPU write into its home goes back to the title's page (one 256-byte piece), a page written on
both sides keeps the title's write. Linux ctest (llvmpipe) 122/122; xmem_test OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/xmem.cpp')
| -rw-r--r-- | runtime/shims/xmem.cpp | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/runtime/shims/xmem.cpp b/runtime/shims/xmem.cpp index 9b8e9c169..69a0b9b44 100644 --- a/runtime/shims/xmem.cpp +++ b/runtime/shims/xmem.cpp | |||
| @@ -94,27 +94,8 @@ HANDLE title_heap() { | |||
| 94 | // Set LEONIDA_TITLE_HEAP=0 to use the CRT heap. | 94 | // Set LEONIDA_TITLE_HEAP=0 to use the CRT heap. |
| 95 | const char* v = std::getenv("LEONIDA_TITLE_HEAP"); | 95 | const char* v = std::getenv("LEONIDA_TITLE_HEAP"); |
| 96 | if (v && std::strcmp(v, "0") == 0) return HANDLE(nullptr); | 96 | if (v && std::strcmp(v, "0") == 0) return HANDLE(nullptr); |
| 97 | // In the page mirror's range (src/title_mirror_space.h), so a V# or pointer the title writes into a block | 97 | const HANDLE h = HeapCreate(0, 0, 0); |
| 98 | // reaches the mirror: a heap over a reservation there (ntdll's RtlCreateHeap with a base), up to kTitleHeapBytes. | 98 | std::fprintf(stderr, "[rt] xmem: XMemAlloc blocks come from a heap of their own (%p)\n", h); |
| 99 | // The host's own heap where that is refused. | ||
| 100 | HANDLE h = nullptr; | ||
| 101 | using RtlCreateHeapFn = PVOID(NTAPI*)(ULONG, PVOID, SIZE_T, SIZE_T, PVOID, PVOID); | ||
| 102 | const auto create = reinterpret_cast<RtlCreateHeapFn>( | ||
| 103 | reinterpret_cast<void*>(GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlCreateHeap"))); | ||
| 104 | constexpr SIZE_T kTitleHeapBytes = SIZE_T(8) << 30; | ||
| 105 | if (create) | ||
| 106 | leonida::title_mirror_space::take(kTitleHeapBytes, 0x10000, true, [&](std::uint64_t at) { | ||
| 107 | void* const base = VirtualAlloc(reinterpret_cast<void*>(static_cast<uintptr_t>(at)), kTitleHeapBytes, | ||
| 108 | MEM_RESERVE, PAGE_READWRITE); | ||
| 109 | if (!base) return false; // something of the host's there: the next address | ||
| 110 | h = create(0x2 /* HEAP_GROWABLE */, base, kTitleHeapBytes, 0, nullptr, nullptr); | ||
| 111 | if (!h) VirtualFree(base, 0, MEM_RELEASE); // refused with a base: not tried again | ||
| 112 | return true; | ||
| 113 | }); | ||
| 114 | const bool placed = h != nullptr; | ||
| 115 | if (!h) h = HeapCreate(0, 0, 0); | ||
| 116 | std::fprintf(stderr, "[rt] xmem: XMemAlloc blocks come from a heap of their own (%p, %s)\n", h, | ||
| 117 | placed ? "in the page mirror's range" : "placed by the host"); | ||
| 118 | return h; | 99 | return h; |
| 119 | }(); | 100 | }(); |
| 120 | return heap; | 101 | return heap; |