Properly dispose of the sw::Renderer object This fixes a memory leak in the Queue object. The sw::Renderer object has a non trivial destructor, which means we need to call it before deallocating the Queue objects. Bug b/117974925 Change-Id: I1e13c6108e77d5cdcbea337d572f72fdd32530a1 Reviewed-on: https://swiftshader-review.googlesource.com/c/23188 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Vulkan/VkDevice.cpp b/src/Vulkan/VkDevice.cpp index 092b252..78a9e9c 100644 --- a/src/Vulkan/VkDevice.cpp +++ b/src/Vulkan/VkDevice.cpp
@@ -58,6 +58,11 @@ void Device::destroy(const VkAllocationCallbacks* pAllocator) { + for(uint32_t i = 0; i < queueCount; i++) + { + queues[i].destroy(); + } + vk::deallocate(queues, pAllocator); }
diff --git a/src/Vulkan/VkQueue.cpp b/src/Vulkan/VkQueue.cpp index 57f8605..cb704ae 100644 --- a/src/Vulkan/VkQueue.cpp +++ b/src/Vulkan/VkQueue.cpp
@@ -21,8 +21,16 @@ namespace vk { -Queue::Queue(uint32_t pFamilyIndex, float pPriority) : context(), renderer(&context, sw::OpenGL, true), familyIndex(pFamilyIndex), priority(pPriority) +Queue::Queue(uint32_t pFamilyIndex, float pPriority) : familyIndex(pFamilyIndex), priority(pPriority) { + context = new sw::Context(); + renderer = new sw::Renderer(context, sw::OpenGL, true); +} + +void Queue::destroy() +{ + delete context; + delete renderer; } void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) @@ -37,7 +45,7 @@ { CommandBuffer::ExecutionState executionState; - executionState.renderer = &renderer; + executionState.renderer = renderer; for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++) { vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);
diff --git a/src/Vulkan/VkQueue.hpp b/src/Vulkan/VkQueue.hpp index f57ebdf..93e65b8 100644 --- a/src/Vulkan/VkQueue.hpp +++ b/src/Vulkan/VkQueue.hpp
@@ -16,9 +16,14 @@ #define VK_QUEUE_HPP_ #include "VkObject.hpp" -#include "Device/Renderer.hpp" #include <vulkan/vk_icd.h> +namespace sw +{ + class Context; + class Renderer; +} + namespace vk { @@ -35,11 +40,12 @@ return reinterpret_cast<VkQueue>(this); } + void destroy(); void submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); private: - sw::Context context; - sw::Renderer renderer; + sw::Context* context = nullptr; + sw::Renderer* renderer = nullptr; uint32_t familyIndex = 0; float priority = 0.0f; };