Add wb_probe = 1, which finds out who reads what the GPU wrote back into guest memory.

Per-pass GPU timestamps put the write-back of GPU-written storage buffers at 3.6 to 5.3 ms of GPU time a frame in play, against 1.8 to 2.5 ms for all of the game's own passes and dispatches: about 67 MiB a frame goes from the mirrors back into guest memory, from the same eleven pools all session, in case the CPU or a host path reads it. Nothing said whether anything does.

With wb_probe = 1 the 2 MiB regions that lie wholly inside a range just written back are made inaccessible. The first read or write of such a region faults; the handler gives the region back the protection it had (read-only when frozen, else read-write), notes the address, the instruction and the thread, and the access runs again. The bytes are in guest memory all along, so nothing changes for the game. A log block every perf window gives the regions armed, the probes a read or a write ended, and the first accesses by instruction. Every thaw ends the probe of its region first, which covers file reads into guest memory and mapping changes; a file write from guest memory thaws its buffer while the probe is on; a probed region is not frozen anew.

The platform layer gets a hook for every read or write access fault beside the write-fault hook; it is installed only with the setting. --probe-gfx-abi checks that nothing is armed without it and, run with NX2NAVI_WB_PROBE=1, that reads and writes end a probe and run again, that a frozen region thaws after it and that mem_thaw ends and holds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-09 21:01:47 -05:00
parent c32b9c40a8
commit 57cdfa1520
10 changed files with 183 additions and 7 deletions

View File

@@ -94,6 +94,29 @@ static void check_write_watch(void) {
CHECK(plat_mem_state(a, a + 0x10000, &end) == PLAT_PROT_RW && end == a + 0x4000, "the thawed pages are not read-write");
CHECK(plat_mem_state(a + 0x4000, a + 0x4001, &end) == PLAT_MEM_RESERVED, "a hole got committed");
printf("write-watch: region with reserved holes frozen and thawed by a write\n");
// NX2NAVI_WB_PROBE=1 (memory.c, "Probed regions"): a probed region is inaccessible until its first access, which is
// noted and runs again; a frozen one goes back to read-only first and then thaws on a write; mem_thaw ends a probe
// and holds the region. With the setting off mem_probe arms nothing.
if (mem_probing()) {
volatile uint8_t *q = (volatile uint8_t *)(uintptr_t)a;
CHECK(mem_probe(ra, 0x200000) == 1, "probe of a 2 MiB region");
CHECK(plat_mem_state(a, a + 1, &end) == PLAT_PROT_NONE, "a probed region is not inaccessible");
CHECK(q[0x2000] == 9, "a read of a probed region did not return its byte");
CHECK(plat_mem_state(a, a + 0x10000, &end) == PLAT_PROT_RW && end == a + 0x4000, "the read did not end the probe");
CHECK(mem_freeze(ra) == 1 && mem_probe(ra, 0x200000) == 1, "probe of a frozen region");
q[0x3000] = 5; // ends the probe (read-only again), faults once more and thaws
CHECK(!mem_frozen(ra) && q[0x3000] == 5, "a write into a probed frozen region did not land");
CHECK(plat_mem_state(a, a + 0x10000, &end) == PLAT_PROT_RW && end == a + 0x4000, "its pages are not read-write after it");
CHECK(mem_probe(ra, 0x200000) == 1, "probe again");
mem_thaw(a, 0x1000);
CHECK(plat_mem_state(a, a + 1, &end) == PLAT_PROT_RW && mem_probe(ra, 0x200000) == 0,
"mem_thaw did not end the probe and hold the region");
mem_probe_report(0);
printf("write-back probe: a read and a write end a probe and run again, a frozen region thaws after it, "
"mem_thaw ends and holds\n");
} else {
CHECK(mem_probe(ra, 0x200000) == 0, "mem_probe armed a region with the probe off");
}
CHECK(mem_unmap_physical(a, 0x4000) == 0, "UnmapPhysicalMemory");
CHECK(mem_written_pages(RT_KERNEL_BASE, 0x1000, pages, 8) == UINT64_MAX, "kernel region is not write-watched");
CHECK(mem_set_heap_size(0, &heap) == 0, "SetHeapSize 0");