diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 10:43:18 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 10:43:18 -0500 |
| commit | b0767fd6574e5ec7af617e27c87a3401176154b8 (patch) | |
| tree | 3118b532fc54beab0216743f9d11c53931865943 /runtime/test/xmem_test.cpp | |
| parent | 246791612080cae89dc40cd20c5cdb8d92f90066 (diff) | |
d3d12, xmem: remove remap release and the console heap mirror
Both came in with #2350 as additions on top of stopgap mechanisms, broke world runs (remap release: a GPUVM page
fault and a lost device; the mirror: a GPU hang) and were made opt-in by #2356. They go completely; with both
variables unset, main behaves as before.
Remap release (LEONIDA_GEOMETRY_REMAP_RELEASE, from 36771ec53):
- xmem.cpp: RemapReleases, remap_releases_enabled() and the page recording in unmap_range_locked; the four call
sites (XMemMapPhysicalPages, the scatter call, both copy_page_mappings).
- xmem.h/xmem.cpp: the test seam rt::xmem::reload_remap_release_setting().
- xmem_test: test_remap_releases (and the title_geometry_watch.h include only it used).
- README row, the docs/d3d12_vulkan.md paragraph; comments that named it.
Console heap mirror (LEONIDA_HEAP_MIRROR, LEONIDA_HEAP_MIRROR_CHECK, from 746059011):
- src/console_heap_copy.h goes. ConsoleHeap::copy is a plain std::uint8_t* again, written with memcpy/memset as
before the mirror, including the zeroing site that #2350's merge of #2162 resolved as heap.copy.zero(); the
compute-input probe reads it directly again. Without the mirror, view() was the copy itself, so nothing changes.
- heap_mirror_enabled(), heap_mirror_check_enabled(), check_console_heap_mirror(), the per-heap check counters and
log line, and the test API console_heap_mirror_mismatches() (d3d12_com.h).
- Tests console_heap_copy, d3d12_console_heap_mirror, _off and _default with their CMake entries; README rows and
the docs/d3d12_vulkan.md sentences.
Kept, because other paths use them or main's behaviour with the variable unset depends on them:
- LEONIDA_GEOMETRY_HOST and its DeviceState memory-type assert (dc9ef1a0b).
- The final copy at retirement (GeometryViews::retire_range's final_copy, "copied at retirement" in the geometry
buffers line): XMemFree of a title heap block (free_title_block) reports a release while the block's memory stays
committed and readable, so that copy is still made without remap release. Comments now say that instead of
naming remaps; geometry_views_test case 15 stays.
- forget_pool_span and "retired with their copy" in the title memory line: any retirement (free, decommit, unmap)
feeds it.
- The release queue's joining of touching ranges (title_geometry_watch.h): unmaps report page runs too;
geometry_views_test case 16 stays.
- LEONIDA_CONSOLE_RELEASE_FILTER, which predates the mirror; its sweep reads the copy again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/xmem_test.cpp')
| -rw-r--r-- | runtime/test/xmem_test.cpp | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/runtime/test/xmem_test.cpp b/runtime/test/xmem_test.cpp index d5e866a76..79f655412 100644 --- a/runtime/test/xmem_test.cpp +++ b/runtime/test/xmem_test.cpp | |||
| @@ -31,7 +31,6 @@ | |||
| 31 | #include "startup_trace.h" | 31 | #include "startup_trace.h" |
| 32 | #include "xmem.h" | 32 | #include "xmem.h" |
| 33 | #include "../src/title_page_watch.h" | 33 | #include "../src/title_page_watch.h" |
| 34 | #include "../src/title_geometry_watch.h" | ||
| 35 | 34 | ||
| 36 | // The process heap as test_heap_lock_faults needs it (the same gate as d3d12_existing_heap_test's): an allocation that | 35 | // The process heap as test_heap_lock_faults needs it (the same gate as d3d12_existing_heap_test's): an allocation that |
| 37 | // waits while a thread holds the heap's lock. The NT heap's low-fragmentation front end serves most small sizes | 36 | // waits while a thread holds the heap's lock. The NT heap's low-fragmentation front end serves most small sizes |
| @@ -430,99 +429,6 @@ struct PhysicalApi { | |||
| 430 | XMemMapPhysicalPagesScatterFn scatter; | 429 | XMemMapPhysicalPagesScatterFn scatter; |
| 431 | }; | 430 | }; |
| 432 | 431 | ||
| 433 | // A remap that gives watched pages another frame reports them released (geometry_writes::note_released), so the | ||
| 434 | // geometry copies of what they held are retired; a page mapped again to the frame it had is no change. Through | ||
| 435 | // XMemMapPhysicalPages, the scatter call and CopyPageMappingsBatchX. | ||
| 436 | void test_remap_releases(const PhysicalApi& api) { | ||
| 437 | namespace watch = leonida::geometry_writes; | ||
| 438 | constexpr uint64_t kPages = 3; | ||
| 439 | auto* const window = static_cast<uint8_t*>(api.virtual_alloc( | ||
| 440 | nullptr, kPages * kPage64k, MEM_RESERVE | kXmem64kPages, 0x23, PAGE_READWRITE | PAGE_GRAPHICS_READWRITE)); | ||
| 441 | uint64_t pages[4]{}; | ||
| 442 | uint64_t count = 4; | ||
| 443 | if (!window || api.allocate(0x280, &count, pages) != TRUE || count != 4) { | ||
| 444 | check(false, "remap releases: a window and four physical pages"); | ||
| 445 | return; | ||
| 446 | } | ||
| 447 | const auto base = reinterpret_cast<uintptr_t>(window); | ||
| 448 | watch::ReleaseQueue queue; | ||
| 449 | watch::subscribe(queue); | ||
| 450 | for (uint64_t i = 0; i < kPages; ++i) watch::acquire(base + i * kPage64k); // as a geometry copy over the pages | ||
| 451 | std::vector<std::pair<uintptr_t, uintptr_t>> released; | ||
| 452 | const auto take = [&] { | ||
| 453 | watch::take_released(queue, released); | ||
| 454 | return released; | ||
| 455 | }; | ||
| 456 | const auto covers = [&](uintptr_t from, uintptr_t to) { | ||
| 457 | for (const auto& [lo, hi] : released) | ||
| 458 | if (lo <= from && hi >= to) return true; | ||
| 459 | return false; | ||
| 460 | }; | ||
| 461 | const auto any_overlap = [&](uintptr_t from, uintptr_t to) { | ||
| 462 | for (const auto& [lo, hi] : released) | ||
| 463 | if (lo < to && hi > from) return true; | ||
| 464 | return false; | ||
| 465 | }; | ||
| 466 | |||
| 467 | // Off by default: a remap keeps the address valid, and a root view recorded before it (or a placed buffer view) | ||
| 468 | // names the copy's address after it, so a copy freed then is read by the GPU (a page fault and a lost device). | ||
| 469 | char previous[8]{}; | ||
| 470 | const DWORD had = GetEnvironmentVariableA("LEONIDA_GEOMETRY_REMAP_RELEASE", previous, sizeof(previous)); | ||
| 471 | SetEnvironmentVariableA("LEONIDA_GEOMETRY_REMAP_RELEASE", nullptr); | ||
| 472 | rt::xmem::reload_remap_release_setting(); | ||
| 473 | const uint64_t first[kPages] = {pages[0], pages[1], pages[2]}; | ||
| 474 | const uint64_t other[kPages] = {pages[3], pages[2], pages[1]}; | ||
| 475 | check(api.map(window, kPages, first) == window && api.map(window, kPages, other) == window && take().empty(), | ||
| 476 | "remap releases: off by default, a remap releases nothing"); | ||
| 477 | SetEnvironmentVariableA("LEONIDA_GEOMETRY_REMAP_RELEASE", "0"); | ||
| 478 | rt::xmem::reload_remap_release_setting(); | ||
| 479 | check(api.map(window, kPages, first) == window && take().empty(), | ||
| 480 | "remap releases: LEONIDA_GEOMETRY_REMAP_RELEASE=0 releases nothing"); | ||
| 481 | check(api.map(window, kPages, nullptr) == window && !take().empty() && covers(base, base + 3 * kPage64k), | ||
| 482 | "remap releases: unmapping releases the range whatever the setting"); | ||
| 483 | SetEnvironmentVariableA("LEONIDA_GEOMETRY_REMAP_RELEASE", "1"); | ||
| 484 | rt::xmem::reload_remap_release_setting(); | ||
| 485 | |||
| 486 | check(api.map(window, kPages, first) == window && take().empty(), | ||
| 487 | "remap releases: a first mapping of unmapped pages releases nothing"); | ||
| 488 | check(api.map(window + kPage64k, 1, &pages[1]) == window + kPage64k && take().empty(), | ||
| 489 | "remap releases: a page mapped again to the frame it has is no change"); | ||
| 490 | check(api.map(window + kPage64k, 1, &pages[3]) == window + kPage64k && !take().empty() && | ||
| 491 | covers(base + kPage64k, base + 2 * kPage64k) && !any_overlap(base, base + kPage64k) && | ||
| 492 | !any_overlap(base + 2 * kPage64k, base + 3 * kPage64k), | ||
| 493 | "remap releases: a page given another frame is released, its neighbours are not"); | ||
| 494 | const uint64_t rotated[kPages] = {pages[2], pages[0], pages[1]}; | ||
| 495 | check(api.map(window, kPages, rotated) == window && !take().empty() && covers(base, base + 3 * kPage64k), | ||
| 496 | "remap releases: a run given other frames is released whole"); | ||
| 497 | const uint64_t partly[kPages] = {pages[2], pages[3], pages[1]}; | ||
| 498 | check(api.map(window, kPages, partly) == window && !take().empty() && | ||
| 499 | covers(base + kPage64k, base + 2 * kPage64k) && !any_overlap(base, base + kPage64k) && | ||
| 500 | !any_overlap(base + 2 * kPage64k, base + 3 * kPage64k), | ||
| 501 | "remap releases: of a remapped run, only the page whose frame changed is released"); | ||
| 502 | void* const last = window + 2 * kPage64k; | ||
| 503 | check(api.scatter(&last, 1, &pages[0]) == TRUE && !take().empty() && | ||
| 504 | covers(base + 2 * kPage64k, base + 3 * kPage64k) && !any_overlap(base, base + 2 * kPage64k), | ||
| 505 | "remap releases: the scatter call releases the page it gives another frame"); | ||
| 506 | check(api.scatter(&last, 1, &pages[0]) == TRUE && take().empty(), | ||
| 507 | "remap releases: the scatter call with the frame the page has releases nothing"); | ||
| 508 | // CopyPageMappingsBatchX: page 0 gets the frame at page 1 (kind 0 from a pool at the window itself). | ||
| 509 | const rt::xmem::PageRange range{0, 1, 1}; | ||
| 510 | const rt::xmem::PageBatch batch{base, 1, &range}; | ||
| 511 | check(rt::xmem::copy_page_mappings(1, &batch, base, kPages, 0) && !take().empty() && | ||
| 512 | covers(base, base + kPage64k) && !any_overlap(base + kPage64k, base + 3 * kPage64k), | ||
| 513 | "remap releases: CopyPageMappingsBatchX releases the page it gives another frame"); | ||
| 514 | |||
| 515 | check(api.map(window, kPages, nullptr) == window && !take().empty() && covers(base, base + 3 * kPage64k), | ||
| 516 | "remap releases: unmapping releases the range"); | ||
| 517 | SetEnvironmentVariableA("LEONIDA_GEOMETRY_REMAP_RELEASE", | ||
| 518 | had > 0 && had < sizeof(previous) ? previous : nullptr); | ||
| 519 | rt::xmem::reload_remap_release_setting(); | ||
| 520 | for (uint64_t i = 0; i < kPages; ++i) watch::release(base + i * kPage64k); | ||
| 521 | watch::unsubscribe(queue); | ||
| 522 | api.free_pages(4, pages); | ||
| 523 | VirtualFree(window, 0, MEM_RELEASE); | ||
| 524 | } | ||
| 525 | |||
| 526 | // Physical pages in a 64 KiB-page window, as the measured callers use them: reserve a window, allocate pages, map them, | 432 | // Physical pages in a 64 KiB-page window, as the measured callers use them: reserve a window, allocate pages, map them, |
| 527 | // remap them elsewhere and in another order, unmap, free. | 433 | // remap them elsewhere and in another order, unmap, free. |
| 528 | void test_physical_pages(const PhysicalApi& api) { | 434 | void test_physical_pages(const PhysicalApi& api) { |
| @@ -2793,7 +2699,6 @@ int main(int argc, char** argv) { | |||
| 2793 | // Keep the direct SEC_RESERVE control ahead of the first physical allocation, which installs xmem's VEH. | 2699 | // Keep the direct SEC_RESERVE control ahead of the first physical allocation, which installs xmem's VEH. |
| 2794 | g_section_write_control = measure_section_write_control(); | 2700 | g_section_write_control = measure_section_write_control(); |
| 2795 | test_physical_pages(physical); | 2701 | test_physical_pages(physical); |
| 2796 | test_remap_releases(physical); | ||
| 2797 | if (argc == 2 && std::strcmp(argv[1], "--file-pools") == 0) { | 2702 | if (argc == 2 && std::strcmp(argv[1], "--file-pools") == 0) { |
| 2798 | test_placeholders(physical); | 2703 | test_placeholders(physical); |
| 2799 | print_result(); | 2704 | print_result(); |