metal: Create temporary autorelease pools (#1783)
Some checks failed
Build check / build (push) Has been cancelled
Generate translation template / generate-pot (push) Has been cancelled

This commit is contained in:
SamoZ256 2026-01-16 04:23:12 +01:00 committed by GitHub
parent 3d26998975
commit d9cc8f81c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 10 deletions

View File

@ -50,12 +50,12 @@ inline size_t Align(size_t size, size_t alignment)
return (size + alignment - 1) & ~(alignment - 1); return (size + alignment - 1) & ~(alignment - 1);
} }
__attribute__((unused)) static inline void ETStackAutoRelease(void* object) __attribute__((unused)) static inline void StackAutoRelease(void* object)
{ {
(*(NS::Object**)object)->release(); (*(NS::Object**)object)->release();
} }
#define NS_STACK_SCOPED __attribute__((cleanup(ETStackAutoRelease))) __attribute__((unused)) #define NS_STACK_SCOPED __attribute__((cleanup(StackAutoRelease))) __attribute__((unused))
// Cast from const char* to NS::String* // Cast from const char* to NS::String*
inline NS::String* ToNSString(const char* str) inline NS::String* ToNSString(const char* str)

View File

@ -1690,7 +1690,9 @@ MTL::CommandBuffer* MetalRenderer::GetCommandBuffer()
// Debug // Debug
//m_commandQueue->insertDebugCaptureBoundary(); //m_commandQueue->insertDebugCaptureBoundary();
MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer(); auto pool = NS::AutoreleasePool::alloc()->init();
MTL::CommandBuffer* mtlCommandBuffer = m_commandQueue->commandBuffer()->retain();
pool->release();
m_currentCommandBuffer = {mtlCommandBuffer}; m_currentCommandBuffer = {mtlCommandBuffer};
// Wait for the previous command buffer // Wait for the previous command buffer
@ -1717,7 +1719,9 @@ MTL::RenderCommandEncoder* MetalRenderer::GetTemporaryRenderCommandEncoder(MTL::
auto commandBuffer = GetCommandBuffer(); auto commandBuffer = GetCommandBuffer();
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor); auto pool = NS::AutoreleasePool::alloc()->init();
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor)->retain();
pool->release();
#ifdef CEMU_DEBUG_ASSERT #ifdef CEMU_DEBUG_ASSERT
renderCommandEncoder->setLabel(GetLabel("Temporary render command encoder", renderCommandEncoder)); renderCommandEncoder->setLabel(GetLabel("Temporary render command encoder", renderCommandEncoder));
#endif #endif
@ -1780,7 +1784,9 @@ MTL::RenderCommandEncoder* MetalRenderer::GetRenderCommandEncoder(bool forceRecr
auto commandBuffer = GetCommandBuffer(); auto commandBuffer = GetCommandBuffer();
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(m_state.m_activeFBO.m_fbo->GetRenderPassDescriptor()); auto pool = NS::AutoreleasePool::alloc()->init();
auto renderCommandEncoder = commandBuffer->renderCommandEncoder(m_state.m_activeFBO.m_fbo->GetRenderPassDescriptor())->retain();
pool->release();
#ifdef CEMU_DEBUG_ASSERT #ifdef CEMU_DEBUG_ASSERT
renderCommandEncoder->setLabel(GetLabel("Render command encoder", renderCommandEncoder)); renderCommandEncoder->setLabel(GetLabel("Render command encoder", renderCommandEncoder));
#endif #endif
@ -1813,7 +1819,9 @@ MTL::ComputeCommandEncoder* MetalRenderer::GetComputeCommandEncoder()
auto commandBuffer = GetCommandBuffer(); auto commandBuffer = GetCommandBuffer();
auto computeCommandEncoder = commandBuffer->computeCommandEncoder(); auto pool = NS::AutoreleasePool::alloc()->init();
auto computeCommandEncoder = commandBuffer->computeCommandEncoder()->retain();
pool->release();
m_commandEncoder = computeCommandEncoder; m_commandEncoder = computeCommandEncoder;
m_encoderType = MetalEncoderType::Compute; m_encoderType = MetalEncoderType::Compute;
@ -1836,7 +1844,9 @@ MTL::BlitCommandEncoder* MetalRenderer::GetBlitCommandEncoder()
auto commandBuffer = GetCommandBuffer(); auto commandBuffer = GetCommandBuffer();
auto blitCommandEncoder = commandBuffer->blitCommandEncoder(); auto pool = NS::AutoreleasePool::alloc()->init();
auto blitCommandEncoder = commandBuffer->blitCommandEncoder()->retain();
pool->release();
m_commandEncoder = blitCommandEncoder; m_commandEncoder = blitCommandEncoder;
m_encoderType = MetalEncoderType::Blit; m_encoderType = MetalEncoderType::Blit;

View File

@ -534,9 +534,6 @@ private:
MTL::CommandBuffer* m_lastCommandBuffer = nullptr; MTL::CommandBuffer* m_lastCommandBuffer = nullptr;
} m_occlusionQuery; } m_occlusionQuery;
// Autorelease pool
NS::AutoreleasePool* m_autoreleasePool;
// Active objects // Active objects
MetalCommandBuffer m_currentCommandBuffer{}; MetalCommandBuffer m_currentCommandBuffer{};
std::vector<MTL::CommandBuffer*> m_executingCommandBuffers; std::vector<MTL::CommandBuffer*> m_executingCommandBuffers;