Metal: Fixed freeze when BGFX_FRAME_FLUSH is used. (#3714)

This commit is contained in:
Branimir Karadžić
2026-05-20 23:18:36 -07:00
committed by GitHub
parent f17b06fc00
commit 0158b15c23

View File

@@ -1712,31 +1712,43 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
void flip() override
{
if (NULL == m_commandBuffer)
{
return;
}
bool needPresent = false;
for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
{
FrameBufferMtl& frameBuffer = ii == 0 ? m_mainFrameBuffer : m_frameBuffers[m_windows[ii].idx];
if (NULL != frameBuffer.m_swapChain
&& frameBuffer.m_swapChain->m_drawableTexture)
{
needPresent = true;
break;
}
}
if (!needPresent)
{
return;
}
MTL::CommandBuffer* presentCommandBuffer = m_cmd.alloc();
for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii)
{
FrameBufferMtl& frameBuffer = ii == 0 ? m_mainFrameBuffer : m_frameBuffers[m_windows[ii].idx];
if (NULL != frameBuffer.m_swapChain
&& frameBuffer.m_swapChain->m_drawableTexture)
{
MTL_RELEASE_I(frameBuffer.m_swapChain->m_drawableTexture);
if (NULL != frameBuffer.m_swapChain->m_drawable)
{
if (NULL != frameBuffer.m_swapChain->m_drawable)
{
m_commandBuffer->presentDrawable( (MTL::Drawable*)frameBuffer.m_swapChain->m_drawable);
MTL_RELEASE_I(frameBuffer.m_swapChain->m_drawable);
}
presentCommandBuffer->presentDrawable( (MTL::Drawable*)frameBuffer.m_swapChain->m_drawable);
MTL_RELEASE_I(frameBuffer.m_swapChain->m_drawable);
}
}
}
m_cmd.kick(true, false);
m_commandBuffer = 0;
m_cmd.kick(false, false);
}
void updateResolution(const Resolution& _resolution)
@@ -5834,6 +5846,12 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
rce->endEncoding();
}
if (NULL != m_commandBuffer)
{
m_cmd.kick(true, false);
m_commandBuffer = NULL;
}
}
} /* namespace mtl */ } // namespace bgfx