Skip to content

Commit

Permalink
Fix main buffer leak
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jan 1, 2025
1 parent 9b4ab19 commit 3f787d1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/rend/metal/metal_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,26 @@ class MetalRenderer final : public Renderer

MetalBufferData* GetMainBuffer(u32 size)
{
MetalBufferData* buffer = nullptr;

if (!mainBuffers.empty())
if (mainBuffer != nullptr)
{
buffer = mainBuffers.back().release();
mainBuffers.pop_back();
if (buffer->bufferSize < size)
{
if (mainBuffer->bufferSize < size) {
u32 newSize = (u32)mainBuffer->bufferSize;
while (newSize < size)
newSize *= 2;

INFO_LOG(RENDERER, "Increasing main buffer size %zd -> %d", mainBuffer->bufferSize, newSize);
mainBuffer->buffer->setPurgeableState(MTL::PurgeableStateEmpty);
mainBuffer->buffer->release();

mainBuffer = new MetalBufferData(newSize);
}
}
else
{
buffer = new MetalBufferData(std::max(512 * 1024u, size));
mainBuffer = new MetalBufferData(std::max(512 * 1024u, size));
}

return buffer;
return mainBuffer;
}

template<typename T>
Expand Down Expand Up @@ -129,7 +132,7 @@ class MetalRenderer final : public Renderer
MTL::Texture* depthBuffer = nullptr;

MTL::Buffer *curMainBuffer = nullptr;
std::vector<std::unique_ptr<MetalBufferData>> mainBuffers;
MetalBufferData* mainBuffer;
MetalPipelineManager pipelineManager = MetalPipelineManager(this);
MetalShaders shaders;
MetalTextureCache textureCache;
Expand Down

0 comments on commit 3f787d1

Please sign in to comment.