diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index 6c18c57624..f0ece9b12a 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -44,7 +44,12 @@ namespace cc { namespace gfx { CCMTLCommandBuffer::CCMTLCommandBuffer(Device *device) -: CommandBuffer(device), _mtlDevice((CCMTLDevice *)device), _mtlCommandQueue(id(((CCMTLDevice *)device)->getMTLCommandQueue())), _mtkView((MTKView *)(((CCMTLDevice *)device)->getMTKView())) { +: CommandBuffer(device) +, _mtlDevice((CCMTLDevice *)device) +, _mtlCommandQueue(id(((CCMTLDevice *)device)->getMTLCommandQueue())) +, _mtkView((MTKView *)(((CCMTLDevice *)device)->getMTKView())) +//, _frameBoundarySemaphore(dispatch_semaphore_create(MAX_INFLIGHT_BUFFER)) +{ const auto setCount = device->bindingMappingInfo().bufferOffsets.size(); _GPUDescriptorSets.resize(setCount); _dynamicOffsets.resize(setCount); @@ -58,11 +63,14 @@ bool CCMTLCommandBuffer::initialize(const CommandBufferInfo &info) { } void CCMTLCommandBuffer::destroy() { +// dispatch_semaphore_signal(_frameBoundarySemaphore); } void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer, int submitIndex) { if (_commandBufferBegan) return; +// dispatch_semaphore_wait(_frameBoundarySemaphore, DISPATCH_TIME_FOREVER); + _mtlCommandBuffer = [_mtlCommandQueue commandBuffer]; [_mtlCommandBuffer retain]; [_mtlCommandBuffer enqueue]; @@ -81,6 +89,14 @@ void CCMTLCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer void CCMTLCommandBuffer::end() { if (!_commandBufferBegan) return; + [_mtlCommandBuffer presentDrawable:_mtkView.currentDrawable]; + [_mtlCommandBuffer addCompletedHandler:^(id commandBuffer) { + // GPU work is complete + // Signal the semaphore to start the CPU work +// dispatch_semaphore_signal(_frameBoundarySemaphore); + [commandBuffer release]; + }]; + [_mtlCommandBuffer commit]; _commandBufferBegan = false; }