Metal: Always run endEncoding on command encoders

Fixes a macOS Metal crash when stopping immediately after boot starts.

m_upload_encoder and m_texture_upload_encoder could be dealloc'd during shutdown before endEncoding could be called, which causes a Metal assertion failure.

Co-authored-by: OatmealDome <julian@oatmealdome.me>
This commit is contained in:
Simonx22 2026-03-03 09:38:13 -05:00
parent f898d75bf3
commit 03bcd564c5

View File

@ -383,11 +383,14 @@ void Metal::StateTracker::EndRenderPass()
void Metal::StateTracker::FlushEncoders()
{
if (!m_current_render_cmdbuf)
return;
EndRenderPass();
for (int i = 0; i <= static_cast<int>(UploadBuffer::Last); ++i)
Sync(m_upload_buffers[i]);
const bool needs_submit = m_current_render_cmdbuf;
if (needs_submit)
{
EndRenderPass();
for (int i = 0; i <= static_cast<int>(UploadBuffer::Last); ++i)
Sync(m_upload_buffers[i]);
}
if (!m_manual_buffer_upload)
{
ASSERT(!m_upload_cmdbuf && "Should never be used!");
@ -407,6 +410,10 @@ void Metal::StateTracker::FlushEncoders()
m_texture_upload_encoder = nullptr;
m_texture_upload_cmdbuf = nullptr;
}
if (!needs_submit)
return;
[m_current_render_cmdbuf
addCompletedHandler:[backref = m_backref, draw = m_current_draw,
q = std::move(m_current_perf_query)](id<MTLCommandBuffer> buf) {