fix: present issues

This commit is contained in:
Samuliak 2024-08-03 16:15:22 +02:00
parent fa53af54db
commit d2edc41680
2 changed files with 34 additions and 20 deletions

View File

@ -102,7 +102,8 @@ void MetalRenderer::Initialize()
void MetalRenderer::Shutdown() void MetalRenderer::Shutdown()
{ {
debug_printf("MetalRenderer::Shutdown not implemented\n"); Renderer::Shutdown();
CommitCommandBuffer();
} }
bool MetalRenderer::IsPadWindowActive() bool MetalRenderer::IsPadWindowActive()
@ -129,7 +130,9 @@ void MetalRenderer::ClearColorbuffer(bool padView)
void MetalRenderer::DrawEmptyFrame(bool mainWindow) void MetalRenderer::DrawEmptyFrame(bool mainWindow)
{ {
debug_printf("MetalRenderer::DrawEmptyFrame not implemented\n"); if (!BeginFrame(mainWindow))
return;
SwapBuffers(mainWindow, !mainWindow);
} }
void MetalRenderer::SwapBuffers(bool swapTV, bool swapDRC) void MetalRenderer::SwapBuffers(bool swapTV, bool swapDRC)
@ -145,7 +148,6 @@ void MetalRenderer::SwapBuffers(bool swapTV, bool swapDRC)
debug_printf("skipped present!\n"); debug_printf("skipped present!\n");
} }
m_drawable = nullptr; m_drawable = nullptr;
m_drawableAcquired = false;
CommitCommandBuffer(); CommitCommandBuffer();
@ -157,19 +159,8 @@ void MetalRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutput
sint32 imageX, sint32 imageY, sint32 imageWidth, sint32 imageHeight, sint32 imageX, sint32 imageY, sint32 imageWidth, sint32 imageHeight,
bool padView, bool clearBackground) bool padView, bool clearBackground)
{ {
if (!m_drawableAcquired) if (!AcquireNextDrawable())
{ return;
debug_printf("drawable already acquired this frame\n");
m_drawableAcquired = true;
// Acquire drawable
m_drawable = m_metalLayer->nextDrawable();
if (!m_drawable)
{
return;
}
}
MTL::Texture* presentTexture = static_cast<LatteTextureViewMtl*>(texView)->GetTexture(); MTL::Texture* presentTexture = static_cast<LatteTextureViewMtl*>(texView)->GetTexture();
@ -193,13 +184,17 @@ void MetalRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutput
bool MetalRenderer::BeginFrame(bool mainWindow) bool MetalRenderer::BeginFrame(bool mainWindow)
{ {
// TODO return AcquireNextDrawable();
return false;
} }
void MetalRenderer::Flush(bool waitIdle) void MetalRenderer::Flush(bool waitIdle)
{ {
debug_printf("MetalRenderer::Flush not implemented\n"); // TODO: should we?
CommitCommandBuffer();
if (waitIdle)
{
// TODO
}
} }
void MetalRenderer::NotifyLatteCommandProcessorIdle() void MetalRenderer::NotifyLatteCommandProcessorIdle()
@ -832,6 +827,24 @@ void MetalRenderer::CommitCommandBuffer()
} }
} }
bool MetalRenderer::AcquireNextDrawable()
{
if (m_drawable)
{
// TODO: should this be true?
return true;
}
m_drawable = m_metalLayer->nextDrawable();
if (!m_drawable)
{
printf("failed to acquire next drawable\n");
return false;
}
return true;
}
void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader) void MetalRenderer::BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader)
{ {
sint32 textureCount = shader->resourceMapping.getTextureCount(); sint32 textureCount = shader->resourceMapping.getTextureCount();

View File

@ -213,7 +213,6 @@ private:
MetalEncoderType m_encoderType = MetalEncoderType::None; MetalEncoderType m_encoderType = MetalEncoderType::None;
MTL::CommandEncoder* m_commandEncoder = nullptr; MTL::CommandEncoder* m_commandEncoder = nullptr;
CA::MetalDrawable* m_drawable = nullptr; CA::MetalDrawable* m_drawable = nullptr;
bool m_drawableAcquired = false;
// State // State
MetalState m_state; MetalState m_state;
@ -226,6 +225,8 @@ private:
void EndEncoding(); void EndEncoding();
void CommitCommandBuffer(); void CommitCommandBuffer();
bool AcquireNextDrawable();
void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader); void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader);
void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder); void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder);
}; };