From 763828837b3f8a4605b90ef2a384376e2c369d31 Mon Sep 17 00:00:00 2001 From: kd-11 <15904127+kd-11@users.noreply.github.com> Date: Fri, 28 May 2021 01:03:46 +0300 Subject: [PATCH] vk: Forcefully unmap DMA blocks before destroying them (#10359) - While the vulkan spec explicitly allows destroying mapped blocks, GPUOpen vma_alloc does not. - Strangely, this issue does not afflict linux users, only windows. --- rpcs3/Emu/RSX/VK/VKDMA.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKDMA.cpp b/rpcs3/Emu/RSX/VK/VKDMA.cpp index 4295fbebe7..bb480100e0 100644 --- a/rpcs3/Emu/RSX/VK/VKDMA.cpp +++ b/rpcs3/Emu/RSX/VK/VKDMA.cpp @@ -76,11 +76,22 @@ namespace vk { if (allocated_memory) { + // Do some accounting before the allocation info is no more s_allocated_dma_pool_size -= allocated_memory->size(); + // If you have both a memory allocation AND a parent block at the same time, you're in trouble + ensure(head() == this); + + if (memory_mapping) + { + // vma allocator does not allow us to destroy mapped memory on windows + unmap(); + ensure(!memory_mapping); + } + + // Move allocation to gc auto gc = vk::get_resource_manager(); gc->dispose(allocated_memory); - memory_mapping = nullptr; } } @@ -174,15 +185,15 @@ namespace vk return; } - inheritance_info.parent = parent; - inheritance_info.block_offset = (base_address - parent->base_address); - if (allocated_memory) { // Acquired blocks are always to be assumed dirty. It is not possible to synchronize host access and inline // buffer copies without causing weird issues. Overlapped incomplete data ends up overwriting host-uploaded data. free(); } + + inheritance_info.parent = parent; + inheritance_info.block_offset = (base_address - parent->base_address); } void dma_block::extend(const render_device& dev, usz new_size)