diff --git a/Common/MemArenaDarwin.cpp b/Common/MemArenaDarwin.cpp index ee4683382e..3736780d8a 100644 --- a/Common/MemArenaDarwin.cpp +++ b/Common/MemArenaDarwin.cpp @@ -84,6 +84,17 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) { void MemArena::ReleaseView(s64 offset, void* view, size_t size) { vm_address_t addr = (vm_address_t)view; + if (reserved_size != 0 && addr >= reserved_mem && addr + size <= reserved_mem + reserved_size) { + // Put the reserved pages back instead of unmapping. A hole would let another thread's allocation + // (Metal maps its command buffer memory at any free address) land in it, and ReleaseViewSpace() + // would then unmap that too. + kern_return_t retval = vm_map(mach_task_self(), &addr, size, 0, VM_FLAGS_FIXED | VM_FLAGS_OVERWRITE, MACH_PORT_NULL, 0, false, + VM_PROT_NONE, VM_PROT_ALL, VM_INHERIT_DEFAULT); + if (retval == KERN_SUCCESS) { + return; + } + WARN_LOG(Log::MemMap, "Couldn't restore the reservation under a view at %p (%d)", view, (int)retval); + } vm_deallocate(mach_task_self(), addr, size); } diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index fc9ccc613d..7372fc989d 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -57,7 +57,9 @@ GPUCommon::GPUCommon(GraphicsContext *gfxCtx, Draw::DrawContext *draw) : Reinitialize(); gstate.Reset(); gstate_c.Reset(); - gpuStats.ResetFrame(); + // Including the flip count, which framebuffer ages are measured in. Otherwise a frame dump replayed after + // another in the same process (headless) renders differently from one replayed alone. + gpuStats.Reset(); PPGeSetDrawContext(draw); ResetMatrices();