Skip to content

Commit

Permalink
rend: last frame was sometimes presented after the game is stopped
Browse files Browse the repository at this point in the history
When the clearLastFrame flag is set, renderers should return false from
Present() and RenderLastFrame() until a new frame is rendered.
  • Loading branch information
flyinghead committed Dec 15, 2024
1 parent ecd0305 commit 3f8d645
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions core/rend/dx11/dx11_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ bool DX11Renderer::Render()
#endif
frameRendered = true;
frameRenderedOnce = true;
clearLastFrame = false;
}

return !is_rtt;
Expand Down Expand Up @@ -1040,6 +1041,7 @@ void DX11Renderer::RenderFramebuffer(const FramebufferInfo& info)
#endif
frameRendered = true;
frameRenderedOnce = true;
clearLastFrame = false;
}

void DX11Renderer::setBaseScissor()
Expand Down
3 changes: 1 addition & 2 deletions core/rend/dx11/dx11_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ struct DX11Renderer : public Renderer

bool Present() override
{
if (!frameRendered)
if (!frameRendered || clearLastFrame)
return false;
frameRendered = false;
clearLastFrame = false;
#ifndef LIBRETRO
imguiDriver->setFrameRendered();
#else
Expand Down
1 change: 1 addition & 0 deletions core/rend/dx11/oit/dx11_oitrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ struct DX11OITRenderer : public DX11Renderer
#endif
frameRendered = true;
frameRenderedOnce = true;
clearLastFrame = false;
}

return !is_rtt;
Expand Down
2 changes: 2 additions & 0 deletions core/rend/dx9/d3d_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void D3DRenderer::RenderFramebuffer(const FramebufferInfo& info)
drawOSD();
frameRendered = true;
frameRenderedOnce = true;
clearLastFrame = false;
theDXContext.setFrameRendered();
}

Expand Down Expand Up @@ -1181,6 +1182,7 @@ bool D3DRenderer::Render()
drawOSD();
frameRendered = true;
frameRenderedOnce = true;
clearLastFrame = false;
theDXContext.setFrameRendered();
}

Expand Down
3 changes: 1 addition & 2 deletions core/rend/dx9/d3d_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ struct D3DRenderer : public Renderer
bool RenderLastFrame() override;
bool Present() override
{
if (!frameRendered)
if (!frameRendered || clearLastFrame)
return false;
imguiDriver->setFrameRendered();
frameRendered = false;
clearLastFrame = false;
return true;
}
BaseTextureCacheData *GetTexture(TSP tsp, TCW tcw) override;
Expand Down
1 change: 1 addition & 0 deletions core/rend/gl4/gles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ struct OpenGL4Renderer : OpenGLRenderer
if (!config::EmulateFramebuffer)
{
frameRendered = true;
clearLastFrame = false;
drawOSD();
renderVideoRouting();
}
Expand Down
1 change: 1 addition & 0 deletions core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void OpenGLRenderer::RenderFramebuffer(const FramebufferInfo& info)

drawOSD();
frameRendered = true;
clearLastFrame = false;
renderVideoRouting();
restoreCurrentFramebuffer();
}
Expand Down
1 change: 1 addition & 0 deletions core/rend/gles/gles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,7 @@ bool OpenGLRenderer::Render()
if (!config::EmulateFramebuffer)
{
frameRendered = true;
clearLastFrame = false;
drawOSD();
renderVideoRouting();
}
Expand Down
3 changes: 1 addition & 2 deletions core/rend/gles/gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,11 @@ struct OpenGLRenderer : Renderer

bool Present() override
{
if (!frameRendered)
if (!frameRendered || clearLastFrame)
return false;
#ifndef LIBRETRO
imguiDriver->setFrameRendered();
#endif
clearLastFrame = false;
frameRendered = false;
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion core/rend/vulkan/oit/oit_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class OITVulkanRenderer final : public BaseVulkanRenderer

bool Present() override
{
clearLastFrame = false;
if (clearLastFrame)
return false;
if (config::EmulateFramebuffer || framebufferRendered)
return presentFramebuffer();
else
Expand Down
10 changes: 8 additions & 2 deletions core/rend/vulkan/vulkan_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ BaseTextureCacheData *BaseVulkanRenderer::GetTexture(TSP tsp, TCW tcw)

void BaseVulkanRenderer::Process(TA_context* ctx)
{
framebufferRendered = false;
if (!ctx->rend.isRTT) {
framebufferRendered = false;
if (!config::EmulateFramebuffer)
clearLastFrame = false;
}
if (resetTextureCache) {
textureCache.Clear();
resetTextureCache = false;
Expand Down Expand Up @@ -156,6 +160,7 @@ void BaseVulkanRenderer::RenderFramebuffer(const FramebufferInfo& info)
commandBuffer.end();
fbCommandPool.EndFrame();
framebufferRendered = true;
clearLastFrame = false;
}

void BaseVulkanRenderer::RenderVideoRouting()
Expand Down Expand Up @@ -300,7 +305,8 @@ class VulkanRenderer final : public BaseVulkanRenderer

bool Present() override
{
clearLastFrame = false;
if (clearLastFrame)
return false;
if (config::EmulateFramebuffer || framebufferRendered)
return presentFramebuffer();
else
Expand Down

0 comments on commit 3f8d645

Please sign in to comment.