From b78bc4cb66d29019119349ef31cb4cbadf870cfe Mon Sep 17 00:00:00 2001 From: RSDuck Date: Tue, 26 Jan 2021 16:42:27 +0100 Subject: [PATCH] fixes to the threadedness of the sw rasteriser also fix #639 and fix #880 --- src/GPU.cpp | 5 +++++ src/GPU.h | 1 + src/GPU2D_Soft.cpp | 28 ++++++++++++++-------------- src/GPU3D.cpp | 5 +++++ src/GPU3D.h | 2 ++ src/GPU3D_Soft.cpp | 4 ++++ src/GPU_OpenGL.cpp | 6 ++++++ src/NDS.cpp | 5 +++-- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/GPU.cpp b/src/GPU.cpp index e2ece10d..40334de7 100644 --- a/src/GPU.cpp +++ b/src/GPU.cpp @@ -289,6 +289,11 @@ void Stop() memset(Framebuffer[0][1], 0, fbsize*4); memset(Framebuffer[1][0], 0, fbsize*4); memset(Framebuffer[1][1], 0, fbsize*4); + +#ifdef OGLRENDERER_ENABLED + if (Accelerated) + GLCompositor::Stop(); +#endif } void DoSavestate(Savestate* file) diff --git a/src/GPU.h b/src/GPU.h index cf2fe7d9..3a254dfb 100644 --- a/src/GPU.h +++ b/src/GPU.h @@ -561,6 +561,7 @@ void Reset(); void SetRenderSettings(RenderSettings& settings); +void Stop(); void RenderFrame(); void BindOutputTexture(); diff --git a/src/GPU2D_Soft.cpp b/src/GPU2D_Soft.cpp index f9c27685..53e7b733 100644 --- a/src/GPU2D_Soft.cpp +++ b/src/GPU2D_Soft.cpp @@ -187,6 +187,20 @@ void GPU2D_Soft::DrawScanline(u32 line) // oddly that's not the case for GPU A if (Num && !Enabled) forceblank = true; + if (line == 0 && CaptureCnt & (1 << 31) && !forceblank) + CaptureLatch = true; + + if (Num == 0) + { + if (!Accelerated) + _3DLine = GPU3D::GetLine(n3dline); + else if (CaptureLatch && (((CaptureCnt >> 29) & 0x3) != 1)) + { + _3DLine = GPU3D::GetLine(n3dline); + //GPU3D::GLRenderer::PrepareCaptureFrame(); + } + } + if (forceblank) { for (int i = 0; i < 256; i++) @@ -202,20 +216,6 @@ void GPU2D_Soft::DrawScanline(u32 line) u32 dispmode = DispCnt >> 16; dispmode &= (Num ? 0x1 : 0x3); - if (Num == 0) - { - if (!Accelerated) - _3DLine = GPU3D::GetLine(n3dline); - else if ((CaptureCnt & (1<<31)) && (((CaptureCnt >> 29) & 0x3) != 1)) - { - _3DLine = GPU3D::GetLine(n3dline); - //GPU3D::GLRenderer::PrepareCaptureFrame(); - } - } - - if (line == 0 && CaptureCnt & (1 << 31)) - CaptureLatch = true; - // always render regular graphics DrawScanline_BGOBJ(line); UpdateMosaicCounters(line); diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index e199d9a6..9b418300 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -2500,6 +2500,11 @@ void VCount144() if (GPU::Renderer == 0) SoftRenderer::VCount144(); } +void RestartFrame() +{ + if (GPU::Renderer == 0) SoftRenderer::SetupRenderThread(); +} + bool YSort(Polygon* a, Polygon* b) { diff --git a/src/GPU3D.h b/src/GPU3D.h index 62fe92c9..e4629b04 100644 --- a/src/GPU3D.h +++ b/src/GPU3D.h @@ -117,6 +117,8 @@ void VCount144(); void VBlank(); void VCount215(); +void RestartFrame(); + void SetRenderXPos(u16 xpos); u32* GetLine(int line); diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index 7fcafb18..3d6ace6c 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -94,9 +94,13 @@ void SetupRenderThread() RenderThread = Platform::Thread_Create(RenderThreadFunc); } + // otherwise more than one frame can be queued up at once + Platform::Semaphore_Reset(Sema_RenderStart); + if (RenderThreadRendering) Platform::Semaphore_Wait(Sema_RenderDone); + Platform::Semaphore_Reset(Sema_RenderDone); Platform::Semaphore_Reset(Sema_RenderStart); Platform::Semaphore_Reset(Sema_ScanlineCount); diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index fb04ca01..dd28bcdc 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -182,6 +182,10 @@ void SetRenderSettings(RenderSettings& settings) glBindFramebuffer(GL_FRAMEBUFFER, 0); } +void Stop() +{ + RenderFrame(); +} void RenderFrame() { @@ -195,6 +199,8 @@ void RenderFrame() glViewport(0, 0, ScreenW, ScreenH); + glClear(GL_COLOR_BUFFER_BIT); + // TODO: select more shaders (filtering, etc) OpenGL::UseShaderProgram(CompShader[0]); glUniform1ui(CompScaleLoc[0], Scale); diff --git a/src/NDS.cpp b/src/NDS.cpp index d0346a52..7c0ecea1 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -1018,8 +1018,8 @@ u32 RunFrame() if (CPUStop & 0x40000000) { // checkme: when is sleep mode effective? - //CancelEvent(Event_LCD); - //GPU::TotalScanlines = 263; + CancelEvent(Event_LCD); + GPU::TotalScanlines = 263; break; } } @@ -1163,6 +1163,7 @@ void SetLidClosed(bool closed) KeyInput &= ~(1<<23); SetIRQ(1, IRQ_LidOpen); CPUStop &= ~0x40000000; + GPU3D::RestartFrame(); } }