diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index e46b545817..8216bba19a 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -81,7 +81,6 @@ void CCMTLCommandBuffer::doDestroy() { _mtlCommandQueue = nil; _parallelEncoder = nil; - // mtlCommandbuffer released in present.completeHandler CC_SAFE_DELETE(_gpuCommandBufferObj); } @@ -102,7 +101,7 @@ void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer if (!_gpuCommandBufferObj->isSecondary) { auto *mtlQueue = static_cast(_queue)->gpuQueueObj()->mtlCommandQueue; // Only primary command buffer should request command buffer explicitly - _gpuCommandBufferObj->mtlCommandBuffer = [mtlQueue commandBuffer]; + _gpuCommandBufferObj->mtlCommandBuffer = [[mtlQueue commandBuffer] retain]; } _numTriangles = 0; diff --git a/native/cocos/renderer/gfx-metal/MTLQueue.mm b/native/cocos/renderer/gfx-metal/MTLQueue.mm index 58afd2980a..f2c0f4fbd9 100644 --- a/native/cocos/renderer/gfx-metal/MTLQueue.mm +++ b/native/cocos/renderer/gfx-metal/MTLQueue.mm @@ -73,6 +73,8 @@ void CCMTLQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { _gpuQueueObj->numTriangles += cmdBuffer->getNumTris(); id mtlCmdBuffer = cmdBuffer->gpuCommandBufferObj()->mtlCommandBuffer; [mtlCmdBuffer commit]; + [mtlCmdBuffer release]; + cmdBuffer->gpuCommandBufferObj()->mtlCommandBuffer = nil; cmdBuffer->reset(); } } diff --git a/native/cocos/renderer/gfx-metal/MTLSwapchain.mm b/native/cocos/renderer/gfx-metal/MTLSwapchain.mm index 0a259e12af..6cea11e57c 100644 --- a/native/cocos/renderer/gfx-metal/MTLSwapchain.mm +++ b/native/cocos/renderer/gfx-metal/MTLSwapchain.mm @@ -64,19 +64,22 @@ void CCMTLSwapchain::doInit(const SwapchainInfo &info) { layer.framebufferOnly = NO; //setDisplaySyncEnabled : physic device refresh rate. //setPresentsWithTransaction : Core Animation transactions update rate. + auto syncModeFunc = [&](BOOL sync, BOOL transaction) { +#if CC_PLATFORM == CC_PLATFORM_MAC_OSX + [layer setDisplaySyncEnabled:sync]; +#endif + [layer setPresentsWithTransaction:transaction]; + }; switch (_vsyncMode) { case VsyncMode::OFF: - [layer setDisplaySyncEnabled:NO]; - [layer setPresentsWithTransaction:NO]; + syncModeFunc(NO, NO); break; case VsyncMode::ON: - [layer setDisplaySyncEnabled:YES]; - [layer setPresentsWithTransaction:YES]; + syncModeFunc(YES, YES); case VsyncMode::RELAXED: case VsyncMode::MAILBOX: case VsyncMode::HALF: - [layer setDisplaySyncEnabled:YES]; - [layer setPresentsWithTransaction:NO]; + syncModeFunc(YES, NO); default: break; }