diff --git a/src/renderer_mtl.cpp b/src/renderer_mtl.cpp index 369519266..5e7f5b728 100644 --- a/src/renderer_mtl.cpp +++ b/src/renderer_mtl.cpp @@ -1087,7 +1087,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames } } - m_cmd.init(m_device); + m_cmd.init(m_device, _init.resolution.maxFrameLatency); BGFX_FATAL(NULL != m_cmd.m_commandQueue, Fatal::UnableToInitialize, "Unable to create Metal device."); for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_FRAME_LATENCY; ++ii) @@ -4242,10 +4242,14 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames m_pixelFormatHash = m_swapChain->resize(_width, _height, _format, _depthFormat); } - void CommandQueueMtl::init(MTL::Device* _device) + void CommandQueueMtl::init(MTL::Device* _device, uint32_t _maxFrameLatency) { m_commandQueue = _device->newCommandQueue(); - m_framesSemaphore.post(BGFX_CONFIG_MAX_FRAME_LATENCY); + m_maxFrameLatency = bx::min( + _maxFrameLatency != 0 ? _maxFrameLatency : BGFX_CONFIG_MAX_FRAME_LATENCY + , BGFX_CONFIG_MAX_FRAME_LATENCY + ); + m_framesSemaphore.post(m_maxFrameLatency); } void CommandQueueMtl::shutdown() @@ -4317,9 +4321,9 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames { if (_finishAll) { - uint32_t count = m_activeCommandBuffer != NULL - ? 2 - : 3 + const uint32_t count = m_activeCommandBuffer != NULL + ? m_maxFrameLatency - 1 + : m_maxFrameLatency ; for (uint32_t ii = 0; ii < count; ++ii) diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index 0465e06ae..3f87afc60 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -610,10 +610,11 @@ namespace bgfx { namespace mtl , m_activeCommandBuffer(NULL) , m_releaseWriteIndex(0) , m_releaseReadIndex(0) + , m_maxFrameLatency(BGFX_CONFIG_MAX_FRAME_LATENCY) { } - void init(MTL::Device* _device); + void init(MTL::Device* _device, uint32_t _maxFrameLatency); void shutdown(); MTL::CommandBuffer* alloc(); void kick(bool _endFrame, bool _waitForFinish); @@ -632,6 +633,7 @@ namespace bgfx { namespace mtl int m_releaseWriteIndex; int m_releaseReadIndex; + uint32_t m_maxFrameLatency; typedef stl::vector ResourceArray; ResourceArray m_release[BGFX_CONFIG_MAX_FRAME_LATENCY]; };