From 3f787d10bdb82a9ade26db28c347b4aa7f9f00e6 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 1 Jan 2025 16:34:01 +0000 Subject: [PATCH] Fix main buffer leak --- core/rend/metal/metal_renderer.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/rend/metal/metal_renderer.h b/core/rend/metal/metal_renderer.h index 121f64f75..c41e744ae 100644 --- a/core/rend/metal/metal_renderer.h +++ b/core/rend/metal/metal_renderer.h @@ -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 @@ -129,7 +132,7 @@ class MetalRenderer final : public Renderer MTL::Texture* depthBuffer = nullptr; MTL::Buffer *curMainBuffer = nullptr; - std::vector> mainBuffers; + MetalBufferData* mainBuffer; MetalPipelineManager pipelineManager = MetalPipelineManager(this); MetalShaders shaders; MetalTextureCache textureCache;