From 26e52ca5e823d3930c4fb9e31c2c36fec3d7a840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 5 Nov 2017 20:10:05 +0100 Subject: [PATCH] Get rid of a bunch of sync stuff that's no longer needed. --- Core/HLE/sceGe.cpp | 5 +---- Core/System.cpp | 23 +++-------------------- GPU/D3D11/DrawEngineD3D11.h | 4 +++- GPU/D3D11/GPU_D3D11.cpp | 16 +--------------- GPU/Directx9/GPU_DX9.cpp | 16 +--------------- GPU/GLES/GPU_GLES.cpp | 10 ---------- GPU/GPUCommon.cpp | 19 +++++-------------- GPU/GPUCommon.h | 25 +++++++------------------ GPU/GPUInterface.h | 7 ------- GPU/Null/NullGpu.h | 1 + GPU/Software/SoftGpu.cpp | 1 + GPU/Software/SoftGpu.h | 3 ++- GPU/Vulkan/GPU_Vulkan.cpp | 10 ---------- 13 files changed, 25 insertions(+), 115 deletions(-) diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index 25aaa6848a..d72ebe4a26 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -193,13 +193,12 @@ static void __GeExecuteInterrupt(u64 userdata, int cyclesLate) { __TriggerInterrupt(PSP_INTR_IMMEDIATE, PSP_GE_INTR, PSP_INTR_SUB_NONE); } +// Should we still do this? static void __GeCheckCycles(u64 userdata, int cyclesLate) { u64 geTicks = gpu->GetTickEstimate(); if (geTicks != 0) { if (CoreTiming::GetTicks() > geTicks + usToCycles(geBehindThresholdUs)) { u64 diff = CoreTiming::GetTicks() - geTicks; - // Let the GPU thread catch up. - gpu->SyncThread(); CoreTiming::Advance(); } } @@ -504,7 +503,6 @@ static int sceGeUnsetCallback(u32 cbID) { // unless some insane game pokes it and relies on it... u32 sceGeSaveContext(u32 ctxAddr) { DEBUG_LOG(SCEGE, "sceGeSaveContext(%08x)", ctxAddr); - gpu->SyncThread(); if (gpu->BusyDrawing()) { WARN_LOG(SCEGE, "sceGeSaveContext(%08x): lists in process, aborting", ctxAddr); @@ -524,7 +522,6 @@ u32 sceGeSaveContext(u32 ctxAddr) { u32 sceGeRestoreContext(u32 ctxAddr) { DEBUG_LOG(SCEGE, "sceGeRestoreContext(%08x)", ctxAddr); - gpu->SyncThread(); if (gpu->BusyDrawing()) { WARN_LOG(SCEGE, "sceGeRestoreContext(%08x): lists in process, aborting", ctxAddr); diff --git a/Core/System.cpp b/Core/System.cpp index 6f7069f1f2..1ec7ae54aa 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -328,7 +328,6 @@ void CPU_RunLoop() { switch (cpuThreadState) { case CPU_THREAD_EXECUTE: mipsr4k.RunLoopUntil(cpuThreadUntil); - gpu->FinishEventLoop(); CPU_NextState(CPU_THREAD_EXECUTE, CPU_THREAD_RUNNING); break; @@ -354,12 +353,6 @@ void CPU_RunLoop() { coreState = CORE_POWERDOWN; } - // Let's make sure the gpu has already cleaned up before we start freeing memory. - if (gpu) { - gpu->FinishEventLoop(); - gpu->SyncThread(true); - } - CPU_Shutdown(); CPU_SetState(CPU_THREAD_NOT_RUNNING); } @@ -384,9 +377,6 @@ static void Core_UpdateDebugStats(bool flag) { void System_Wake() { // Ping the threads so they check coreState. CPU_NextStateNot(CPU_THREAD_NOT_RUNNING, CPU_THREAD_SHUTDOWN); - if (gpu) { - gpu->FinishEventLoop(); - } } // Ugly! @@ -545,9 +535,8 @@ void PSP_RunLoopUntil(u64 globalticks) { cpuThread = new std::thread(&CPU_RunLoop); cpuThreadID = cpuThread->get_id(); cpuThread->detach(); - if (gpu) { - gpu->SetThreadEnabled(true); - } + // Probably needs to tell the gpu that it will need to queue up its output + // on another thread. CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsReady); } else if (!useCPUThread && cpuThread != nullptr) { CPU_SetState(CPU_THREAD_QUIT); @@ -555,21 +544,15 @@ void PSP_RunLoopUntil(u64 globalticks) { delete cpuThread; cpuThread = nullptr; cpuThreadID = std::thread::id(); - if (gpu) { - gpu->SetThreadEnabled(false); - } } if (cpuThread != nullptr) { - // Tell the gpu a new frame is about to begin, before we start the CPU. - gpu->SyncBeginFrame(); - cpuThreadUntil = globalticks; if (CPU_NextState(CPU_THREAD_RUNNING, CPU_THREAD_EXECUTE)) { // The CPU doesn't actually respect cpuThreadUntil well, especially when skipping frames. // TODO: Something smarter? Or force CPU to bail periodically? while (!CPU_IsReady()) { - gpu->RunEventsUntil(CoreTiming::GetTicks() + msToCycles(1000)); + // Have the GPU do stuff here. if (coreState != CORE_RUNNING) { CPU_WaitStatus(cpuThreadReplyCond, &CPU_IsReady); } diff --git a/GPU/D3D11/DrawEngineD3D11.h b/GPU/D3D11/DrawEngineD3D11.h index 7175a78e61..48b52063bf 100644 --- a/GPU/D3D11/DrawEngineD3D11.h +++ b/GPU/D3D11/DrawEngineD3D11.h @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -190,7 +191,8 @@ private: PushBufferD3D11 *pushVerts_; PushBufferD3D11 *pushInds_; - // D3D11 state object caches + // D3D11 state object caches. + // TODO: Change them to DenseHashMaps. std::map blendCache_; std::map blendCache1_; std::map depthStencilCache_; diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index cc3f06f16e..aa281e3b67 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -338,13 +338,6 @@ void GPU_D3D11::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat f } bool GPU_D3D11::FramebufferDirty() { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - if (ThreadEnabled()) { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; @@ -353,15 +346,8 @@ bool GPU_D3D11::FramebufferDirty() { } return true; } -bool GPU_D3D11::FramebufferReallyDirty() { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - if (ThreadEnabled()) { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } +bool GPU_D3D11::FramebufferReallyDirty() { VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->reallyDirtyAfterDisplay; diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 0dd93e7137..e9af77b1d1 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -304,13 +304,6 @@ void GPU_DX9::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat for } bool GPU_DX9::FramebufferDirty() { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - if (ThreadEnabled()) { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; @@ -319,15 +312,8 @@ bool GPU_DX9::FramebufferDirty() { } return true; } -bool GPU_DX9::FramebufferReallyDirty() { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - if (ThreadEnabled()) { - // FIXME: Workaround for displaylists sometimes hanging unprocessed. Not yet sure of the cause. - ScheduleEvent(GPU_EVENT_PROCESS_QUEUE); - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } +bool GPU_DX9::FramebufferReallyDirty() { VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->reallyDirtyAfterDisplay; diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index b7d25debd3..d8b3829305 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -504,11 +504,6 @@ void GPU_GLES::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat fo } bool GPU_GLES::FramebufferDirty() { - if (ThreadEnabled()) { - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } - VirtualFramebuffer *vfb = framebufferManagerGL_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; @@ -519,11 +514,6 @@ bool GPU_GLES::FramebufferDirty() { } bool GPU_GLES::FramebufferReallyDirty() { - if (ThreadEnabled()) { - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } - VirtualFramebuffer *vfb = framebufferManagerGL_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->reallyDirtyAfterDisplay; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index dff49ed0bb..a7270edf2f 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -362,7 +362,6 @@ GPUCommon::GPUCommon(GraphicsContext *gfxCtx, Draw::DrawContext *draw) : Reinitialize(); SetupColorConv(); - SetThreadEnabled(false); gstate.Reset(); gstate_c.Reset(); gpuStats.Reset(); @@ -408,6 +407,11 @@ void GPUCommon::Reinitialize() { ScheduleEvent(GPU_EVENT_REINITIALIZE); } +void GPUCommon::ScheduleEvent(GPUEventType event) { + // Queue is gone, we now process events immediately. + ProcessEvent(event); +} + int GPUCommon::EstimatePerVertexCost() { // TODO: This is transform cost, also account for rasterization cost somehow... although it probably // runs in parallel with transform. @@ -470,11 +474,6 @@ void GPUCommon::DumpNextFrame() { } u32 GPUCommon::DrawSync(int mode) { - if (ThreadEnabled()) { - // Sync first, because the CPU is usually faster than the emulated GPU. - SyncThread(); - } - if (mode < 0 || mode > 1) return SCE_KERNEL_ERROR_INVALID_MODE; @@ -523,11 +522,6 @@ void GPUCommon::CheckDrawSync() { } int GPUCommon::ListSync(int listid, int mode) { - if (ThreadEnabled()) { - // Sync first, because the CPU is usually faster than the emulated GPU. - SyncThread(); - } - if (listid < 0 || listid >= DisplayListMaxCount) return SCE_KERNEL_ERROR_INVALID_ID; @@ -2319,9 +2313,6 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size) { ev.fb_memcpy.src = src; ev.fb_memcpy.size = size; ScheduleEvent(ev); - - // This is a memcpy, so we need to wait for it to complete. - SyncThread(); } else { PerformMemoryCopyInternal(dest, src, size); } diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 2123a3eea7..434fbeda3d 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -2,7 +2,6 @@ #include "Common/Common.h" #include "Common/MemoryUtil.h" -#include "Core/ThreadEventQueue.h" #include "GPU/GPUInterface.h" #include "GPU/GPUState.h" #include "GPU/Common/GPUDebugInterface.h" @@ -15,8 +14,6 @@ #include #endif -typedef ThreadEventQueue GPUThreadEventQueue; - class FramebufferManagerCommon; class TextureCacheCommon; class DrawEngineCommon; @@ -42,7 +39,7 @@ enum { FLAG_DIRTYONCHANGE = 64, // NOTE: Either this or FLAG_EXECUTE*, not both! }; -class GPUCommon : public GPUThreadEventQueue, public GPUDebugInterface { +class GPUCommon : public GPUInterface, public GPUDebugInterface { public: GPUCommon(GraphicsContext *gfxCtx, Draw::DrawContext *draw); virtual ~GPUCommon(); @@ -77,14 +74,6 @@ public: u32 DrawSync(int mode) override; int GetStack(int index, u32 stackPtr) override; void DoState(PointerWrap &p) override; - bool FramebufferDirty() override { - SyncThread(); - return true; - } - bool FramebufferReallyDirty() override { - SyncThread(); - return true; - } bool BusyDrawing() override; u32 Continue() override; u32 Break(int mode) override; @@ -261,12 +250,12 @@ protected: void ProcessDLQueueInternal(); virtual void ReapplyGfxStateInternal(); virtual void FastLoadBoneMatrix(u32 target); - void ProcessEvent(GPUEvent ev) override; - bool ShouldExitEventLoop() override { - return coreState != CORE_RUNNING; - } - virtual void FinishDeferred() { - } + + void ScheduleEvent(GPUEventType event); + void ProcessEvent(GPUEvent ev); + + // TODO: Unify this. + virtual void FinishDeferred() {} void DoBlockTransfer(u32 skipDrawReason); diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 5faf3540bb..3c21e45298 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -225,10 +225,6 @@ public: virtual void BeginHostFrame() = 0; virtual void EndHostFrame() = 0; - // Events - virtual void RunEventsUntil(u64 globalticks) = 0; - virtual void FinishEventLoop() = 0; - // Draw queue management virtual DisplayList* getList(int listid) = 0; // TODO: Much of this should probably be shared between the different GPU implementations. @@ -277,8 +273,6 @@ public: virtual void DeviceLost() = 0; virtual void DeviceRestore() = 0; virtual void ReapplyGfxState() = 0; - virtual void SyncThread(bool force = false) = 0; - virtual void SyncBeginFrame() = 0; virtual u64 GetTickEstimate() = 0; virtual void DoState(PointerWrap &p) = 0; @@ -289,7 +283,6 @@ public: virtual bool FramebufferDirty() = 0; virtual bool FramebufferReallyDirty() = 0; virtual bool BusyDrawing() = 0; - virtual void SetThreadEnabled(bool threadEnabled) = 0; // If any jit is being used inside the GPU. virtual bool DescribeCodePtr(const u8 *ptr, std::string &name) = 0; diff --git a/GPU/Null/NullGpu.h b/GPU/Null/NullGpu.h index ae31ce3024..59b920723c 100644 --- a/GPU/Null/NullGpu.h +++ b/GPU/Null/NullGpu.h @@ -40,6 +40,7 @@ public: bool PerformMemoryUpload(u32 dest, int size) override; bool PerformStencilUpload(u32 dest, int size) override; void ClearCacheNextFrame() override {} + bool FramebufferDirty() override { return true; } void DeviceLost() override {} void DeviceRestore() override {} diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 89b8383fb0..9d84af6385 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -28,6 +28,7 @@ #include "Core/HLE/sceGe.h" #include "Core/MIPS/MIPS.h" #include "Core/Reporting.h" +#include "Core/Core.h" #include "profiler/profiler.h" #include "thin3d/thin3d.h" diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 25c21da0ec..664e3d74f7 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -94,7 +94,8 @@ public: protected: void FastRunLoop(DisplayList &list) override; - void ProcessEvent(GPUEvent ev) override; + void ScheduleEvent(GPUEvent ev) { ProcessEvent(ev); } + void ProcessEvent(GPUEvent ev); void CopyToCurrentFboFromDisplayRam(int srcwidth, int srcheight); private: diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index cfaae884f3..3513f5d755 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -370,11 +370,6 @@ void GPU_Vulkan::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat } bool GPU_Vulkan::FramebufferDirty() { - if (ThreadEnabled()) { - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } - VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->dirtyAfterDisplay; @@ -385,11 +380,6 @@ bool GPU_Vulkan::FramebufferDirty() { } bool GPU_Vulkan::FramebufferReallyDirty() { - if (ThreadEnabled()) { - // Allow it to process fully before deciding if it's dirty. - SyncThread(); - } - VirtualFramebuffer *vfb = framebufferManager_->GetDisplayVFB(); if (vfb) { bool dirty = vfb->reallyDirtyAfterDisplay;