Commit af3c1022 by Alexis Hetu Committed by Alexis Hétu

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/23188Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent 50dd2ce4
......@@ -58,6 +58,11 @@ Device::Device(const Device::CreateInfo* info, void* mem)
void Device::destroy(const VkAllocationCallbacks* pAllocator)
{
for(uint32_t i = 0; i < queueCount; i++)
{
queues[i].destroy();
}
vk::deallocate(queues, pAllocator);
}
......
......@@ -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 @@ void Queue::submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence f
{
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);
......
......@@ -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 @@ public:
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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment