From a7b3a1eb96d3a39870e193c17fd5cb0e2c5f0f70 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 24 Dec 2017 10:31:25 -0800 Subject: [PATCH] Vulkan: Decimate the texture allocator. Thin3D wasn't calling Begin/End, which lead to leaks eventually and OOM. Was causing softgpu to crash. --- Common/Vulkan/VulkanMemory.cpp | 4 ++-- Common/Vulkan/VulkanMemory.h | 6 +++--- ext/native/thin3d/thin3d_vulkan.cpp | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Common/Vulkan/VulkanMemory.cpp b/Common/Vulkan/VulkanMemory.cpp index a77fa7e878a3..d19467847e73 100644 --- a/Common/Vulkan/VulkanMemory.cpp +++ b/Common/Vulkan/VulkanMemory.cpp @@ -157,7 +157,7 @@ void VulkanPushBuffer::Unmap() { } VulkanDeviceAllocator::VulkanDeviceAllocator(VulkanContext *vulkan, size_t minSlabSize, size_t maxSlabSize) - : vulkan_(vulkan), lastSlab_(0), minSlabSize_(minSlabSize), maxSlabSize_(maxSlabSize), memoryTypeIndex_(UNDEFINED_MEMORY_TYPE), destroyed_(false) { + : vulkan_(vulkan), minSlabSize_(minSlabSize), maxSlabSize_(maxSlabSize) { assert((minSlabSize_ & (SLAB_GRAIN_SIZE - 1)) == 0); } @@ -290,7 +290,7 @@ int VulkanDeviceAllocator::ComputeUsagePercent() const { blocksUsed += slabs_[i].usage[j] != 0 ? 1 : 0; } } - return 100 * blocksUsed / blockSum; + return blockSum == 0 ? 0 : 100 * blocksUsed / blockSum; } void VulkanDeviceAllocator::Free(VkDeviceMemory deviceMemory, size_t offset) { diff --git a/Common/Vulkan/VulkanMemory.h b/Common/Vulkan/VulkanMemory.h index 94cd1e837dfe..5541f0d628ed 100644 --- a/Common/Vulkan/VulkanMemory.h +++ b/Common/Vulkan/VulkanMemory.h @@ -190,9 +190,9 @@ class VulkanDeviceAllocator { VulkanContext *const vulkan_; std::vector slabs_; - size_t lastSlab_; + size_t lastSlab_ = 0; size_t minSlabSize_; const size_t maxSlabSize_; - uint32_t memoryTypeIndex_; - bool destroyed_; + uint32_t memoryTypeIndex_ = UNDEFINED_MEMORY_TYPE; + bool destroyed_ = false; }; diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index d4437d7ab8d6..f8906188a7c1 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -779,6 +779,7 @@ void VKContext::BeginFrame() { // OK, we now know that nothing is reading from this frame's data pushbuffer, push_->Reset(); push_->Begin(vulkan_); + allocator_->Begin(); frame.descSets_.clear(); VkResult result = vkResetDescriptorPool(device_, frame.descriptorPool, 0); @@ -792,6 +793,7 @@ void VKContext::WaitRenderCompletion(Framebuffer *fbo) { void VKContext::EndFrame() { // Stop collecting data in the frame's data pushbuffer. push_->End(); + allocator_->End(); renderManager_.Finish();