From f7a39d1b120a27789f5d7433945f5b93113ca188 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Aug 2013 15:15:50 -0700 Subject: [PATCH 1/3] Move ReapplyGfxState() to GPUCommon. This way it can be overridden, and simplifies some other things. --- GPU/GLES/DisplayListInterpreter.cpp | 2 +- GPU/GPUCommon.cpp | 40 +++++++++++++++++++++++++++++ GPU/GPUCommon.h | 1 + GPU/GPUInterface.h | 1 + GPU/GPUState.cpp | 37 +------------------------- 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/GPU/GLES/DisplayListInterpreter.cpp b/GPU/GLES/DisplayListInterpreter.cpp index 28c07f673..931eb9004 100644 --- a/GPU/GLES/DisplayListInterpreter.cpp +++ b/GPU/GLES/DisplayListInterpreter.cpp @@ -235,7 +235,7 @@ void GLES_GPU::BuildReportingInfo() { void GLES_GPU::DeviceLost() { // Simply drop all caches and textures. - // FBO:s appear to survive? Or no? + // FBOs appear to survive? Or no? shaderManager_->ClearCache(false); textureCache_.Clear(false); framebufferManager_.DeviceLost(); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 0d587227d..4bda47f10 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -470,6 +470,46 @@ inline void GPUCommon::UpdatePC(u32 currentPC, u32 newPC) downcount = 0; } +void GPUCommon::ReapplyGfxState() +{ + // ShaderManager_DirtyShader(); + // The commands are embedded in the command memory so we can just reexecute the words. Convenient. + // To be safe we pass 0xFFFFFFF as the diff. + /* + ExecuteOp(gstate.cmdmem[GE_CMD_ALPHABLENDENABLE], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_ALPHATESTENABLE], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_BLENDMODE], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_ZTEST], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_ZTESTENABLE], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_CULL], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_CULLFACEENABLE], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_SCISSOR1], 0xFFFFFFFF); + ExecuteOp(gstate.cmdmem[GE_CMD_SCISSOR2], 0xFFFFFFFF); + */ + + for (int i = GE_CMD_VERTEXTYPE; i < GE_CMD_BONEMATRIXNUMBER; i++) + { + if (i != GE_CMD_ORIGIN) + ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); + } + + // Can't write to bonematrixnumber here + + for (int i = GE_CMD_MORPHWEIGHT0; i < GE_CMD_PATCHFACING; i++) + { + ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); + } + + // There are a few here in the middle that we shouldn't execute... + + for (int i = GE_CMD_VIEWPORTX1; i < GE_CMD_TRANSFERSTART; i++) + { + ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); + } + + // TODO: there's more... +} + inline void GPUCommon::UpdateState(GPUState state) { gpuState = state; diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 5d0801fd3..5fe462222 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -28,6 +28,7 @@ public: virtual bool FramebufferDirty() { return true; } virtual u32 Continue(); virtual u32 Break(int mode); + virtual void ReapplyGfxState(); protected: // To avoid virtual calls to PreExecuteOp(). diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 15d7d9180..7dadd1a36 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -192,6 +192,7 @@ public: virtual void DeviceLost() = 0; virtual void Flush() = 0; + virtual void ReapplyGfxState() = 0; virtual void DoState(PointerWrap &p) = 0; // Called by the window system if the window size changed. This will be reflected in PSPCoreParam.pixel*. diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index 35a5be2b7..159423d56 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -82,40 +82,5 @@ void ReapplyGfxState() { if (!gpu) return; - // ShaderManager_DirtyShader(); - // The commands are embedded in the command memory so we can just reexecute the words. Convenient. - // To be safe we pass 0xFFFFFFF as the diff. - /* - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_ALPHABLENDENABLE], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_ALPHATESTENABLE], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_BLENDMODE], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_ZTEST], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_ZTESTENABLE], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_CULL], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_CULLFACEENABLE], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_SCISSOR1], 0xFFFFFFFF); - gpu->ExecuteOp(gstate.cmdmem[GE_CMD_SCISSOR2], 0xFFFFFFFF); - */ - - for (int i = GE_CMD_VERTEXTYPE; i < GE_CMD_BONEMATRIXNUMBER; i++) - { - if(i != GE_CMD_ORIGIN) - gpu->ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); - } - - // Can't write to bonematrixnumber here - - for (int i = GE_CMD_MORPHWEIGHT0; i < GE_CMD_PATCHFACING; i++) - { - gpu->ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); - } - - // There are a few here in the middle that we shouldn't execute... - - for (int i = GE_CMD_VIEWPORTX1; i < GE_CMD_TRANSFERSTART; i++) - { - gpu->ExecuteOp(gstate.cmdmem[i], 0xFFFFFFFF); - } - - // TODO: there's more... + gpu->ReapplyGfxState(); } From b17b23f1f24b12be7f007bc492084db0dd30f694 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Aug 2013 15:22:30 -0700 Subject: [PATCH 2/3] Add a function to run the CPU core. --- Core/CoreParameter.h | 3 --- Core/System.cpp | 8 ++++++++ Core/System.h | 4 ++-- UI/EmuScreen.cpp | 4 +--- android/jni/TestRunner.cpp | 3 +-- headless/Headless.cpp | 7 ++----- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Core/CoreParameter.h b/Core/CoreParameter.h index 06278ffbd..f06ffd383 100644 --- a/Core/CoreParameter.h +++ b/Core/CoreParameter.h @@ -34,9 +34,6 @@ enum GPUCore { struct CoreParameter { CoreParameter() : collectEmuLog(0), unthrottle(false), fpsLimit(0), updateRecent(true) {} - // 0 = Interpreter - // 1 = Jit - // 2 = JitIL CPUCore cpuCore; GPUCore gpuCore; bool enableSound; // there aren't multiple sound cores. diff --git a/Core/System.cpp b/Core/System.cpp index d13eb6424..ad90ca04e 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -150,6 +150,14 @@ void PSP_Shutdown() currentCPU = 0; } +void PSP_RunLoopUntil(u64 globalticks) { + mipsr4k.RunLoopUntil(globalticks); +} + +void PSP_RunLoopFor(int cycles) { + PSP_RunLoopUntil(CoreTiming::GetTicks() + cycles); +} + CoreParameter &PSP_CoreParameter() { return coreParameter; diff --git a/Core/System.h b/Core/System.h index e9220b4e1..1781364be 100644 --- a/Core/System.h +++ b/Core/System.h @@ -41,8 +41,8 @@ extern GlobalUIState globalUIState; bool PSP_Init(const CoreParameter &coreParam, std::string *error_string); bool PSP_IsInited(); void PSP_Shutdown(); -void PSP_HWAdvance(int cycles); -void PSP_SWI(); +void PSP_RunLoopUntil(u64 globalticks); +void PSP_RunLoopFor(int cycles); void GetSysDirectories(std::string &memstickpath, std::string &flash0path); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index a66471212..eba24156f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -34,7 +34,6 @@ #include "Core/Core.h" #include "Core/Host.h" #include "Core/System.h" -#include "Core/MIPS/MIPS.h" #include "GPU/GPUState.h" #include "GPU/GPUInterface.h" #include "Core/HLE/sceCtrl.h" @@ -477,8 +476,7 @@ void EmuScreen::render() { // Run until CORE_NEXTFRAME while (coreState == CORE_RUNNING) { - u64 nowTicks = CoreTiming::GetTicks(); - mipsr4k.RunLoopUntil(nowTicks + blockTicks); + PSP_RunLoopFor(blockTicks); } // Hopefully coreState is now CORE_NEXTFRAME if (coreState == CORE_NEXTFRAME) { diff --git a/android/jni/TestRunner.cpp b/android/jni/TestRunner.cpp index c72ddb82c..548070c3d 100644 --- a/android/jni/TestRunner.cpp +++ b/android/jni/TestRunner.cpp @@ -99,8 +99,7 @@ void RunTests() while (true) { int blockTicks = usToCycles(1000000 / 10); while (coreState == CORE_RUNNING) { - u64 nowTicks = CoreTiming::GetTicks(); - mipsr4k.RunLoopUntil(nowTicks + blockTicks); + PSP_RunLoopFor(blockTicks); } // Hopefully coreState is now CORE_NEXTFRAME if (coreState == CORE_NEXTFRAME) { diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 63ff94420..68c7cd736 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -9,7 +9,6 @@ #include "Core/CoreTiming.h" #include "Core/System.h" #include "Core/HLE/sceUtility.h" -#include "Core/MIPS/MIPS.h" #include "Core/Host.h" #include "Log.h" #include "LogManager.h" @@ -229,10 +228,8 @@ int main(int argc, const char* argv[]) coreState = CORE_RUNNING; while (coreState == CORE_RUNNING) { - // Run for a frame at a time, just because. - u64 nowTicks = CoreTiming::GetTicks(); - u64 frameTicks = usToCycles(1000000/60); - mipsr4k.RunLoopUntil(nowTicks + frameTicks); + int blockTicks = usToCycles(1000000 / 10); + PSP_RunLoopFor(blockTicks); // If we were rendering, this might be a nice time to do something about it. if (coreState == CORE_NEXTFRAME) { From 3aa2db9a8e27c58d647631acff04fc9073f8c401 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Aug 2013 16:31:11 -0700 Subject: [PATCH 3/3] Simplify ProcessDLQueue() slightly. --- GPU/GPUCommon.cpp | 37 +++++++++++++++++++------------------ GPU/GPUCommon.h | 1 + 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 4bda47f10..9bb123a59 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -517,34 +517,35 @@ inline void GPUCommon::UpdateState(GPUState state) downcount = 0; } -bool GPUCommon::ProcessDLQueue() -{ +int GPUCommon::GetNextListIndex() { + auto iter = dlQueue.begin(); + if (iter != dlQueue.end()) { + return *iter; + } else { + return -1; + } +} + +bool GPUCommon::ProcessDLQueue() { startingTicks = CoreTiming::GetTicks(); cyclesExecuted = 0; - if (startingTicks < busyTicks) - { + if (startingTicks < busyTicks) { DEBUG_LOG(HLE, "Can't execute a list yet, still busy for %lld ticks", busyTicks - startingTicks); return false; } - DisplayListQueue::iterator iter = dlQueue.begin(); - while (iter != dlQueue.end()) - { - DisplayList &l = dls[*iter]; - DEBUG_LOG(G3D,"Okay, starting DL execution at %08x - stall = %08x", l.pc, l.stall); - if (!InterpretList(l)) - { + for (int listIndex = GetNextListIndex(); listIndex != -1; listIndex = GetNextListIndex()) { + DisplayList &l = dls[listIndex]; + DEBUG_LOG(G3D, "Okay, starting DL execution at %08x - stall = %08x", l.pc, l.stall); + if (!InterpretList(l)) { return false; - } - else - { - //At the end, we can remove it from the queue and continue - dlQueue.erase(iter); - //this invalidated the iterator, let's fix it - iter = dlQueue.begin(); + } else { + // At the end, we can remove it from the queue and continue. + dlQueue.erase(std::remove(dlQueue.begin(), dlQueue.end(), listIndex), dlQueue.end()); } } + currentList = NULL; drawCompleteTicks = startingTicks + cyclesExecuted; diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 5fe462222..89f0e689a 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -38,6 +38,7 @@ protected: void UpdateState(GPUState state); void PopDLQueue(); void CheckDrawSync(); + int GetNextListIndex(); typedef std::list DisplayListQueue;