Skip to content

Commit af3c102

Browse files
committed
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>
1 parent 50dd2ce commit af3c102

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Vulkan/VkDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ Device::Device(const Device::CreateInfo* info, void* mem)
5858

5959
void Device::destroy(const VkAllocationCallbacks* pAllocator)
6060
{
61+
for(uint32_t i = 0; i < queueCount; i++)
62+
{
63+
queues[i].destroy();
64+
}
65+
6166
vk::deallocate(queues, pAllocator);
6267
}
6368

src/Vulkan/VkQueue.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
namespace vk
2222
{
2323

24-
Queue::Queue(uint32_t pFamilyIndex, float pPriority) : context(), renderer(&context, sw::OpenGL, true), familyIndex(pFamilyIndex), priority(pPriority)
24+
Queue::Queue(uint32_t pFamilyIndex, float pPriority) : familyIndex(pFamilyIndex), priority(pPriority)
2525
{
26+
context = new sw::Context();
27+
renderer = new sw::Renderer(context, sw::OpenGL, true);
28+
}
29+
30+
void Queue::destroy()
31+
{
32+
delete context;
33+
delete renderer;
2634
}
2735

2836
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
3745

3846
{
3947
CommandBuffer::ExecutionState executionState;
40-
executionState.renderer = &renderer;
48+
executionState.renderer = renderer;
4149
for(uint32_t j = 0; j < submitInfo.commandBufferCount; j++)
4250
{
4351
vk::Cast(submitInfo.pCommandBuffers[j])->submit(executionState);

src/Vulkan/VkQueue.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
1616
#define VK_QUEUE_HPP_
1717

1818
#include "VkObject.hpp"
19-
#include "Device/Renderer.hpp"
2019
#include <vulkan/vk_icd.h>
2120

21+
namespace sw
22+
{
23+
class Context;
24+
class Renderer;
25+
}
26+
2227
namespace vk
2328
{
2429

@@ -35,11 +40,12 @@ class Queue
3540
return reinterpret_cast<VkQueue>(this);
3641
}
3742

43+
void destroy();
3844
void submit(uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence);
3945

4046
private:
41-
sw::Context context;
42-
sw::Renderer renderer;
47+
sw::Context* context = nullptr;
48+
sw::Renderer* renderer = nullptr;
4349
uint32_t familyIndex = 0;
4450
float priority = 0.0f;
4551
};

0 commit comments

Comments
 (0)