diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index f8a9c3e011..878303a2f0 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -292,7 +292,7 @@ void __DisplayDoState(PointerWrap &p) { } gpu->DoState(p); - ReapplyGfxState(); + gpu->ReapplyGfxState(); if (p.mode == p.MODE_READ) { if (hasSetMode) { diff --git a/Core/HLE/sceGe.cpp b/Core/HLE/sceGe.cpp index e3451286c3..1ac6ea307d 100644 --- a/Core/HLE/sceGe.cpp +++ b/Core/HLE/sceGe.cpp @@ -533,7 +533,7 @@ u32 sceGeRestoreContext(u32 ctxAddr) { gstate.Restore((u32_le *)Memory::GetPointer(ctxAddr)); } - ReapplyGfxState(); + gpu->ReapplyGfxState(); return 0; } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 7cb7ff2ec9..c8685af938 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -55,6 +55,8 @@ #include "Core/HLE/KernelWaitHelpers.h" #include "Core/ELF/ParamSFO.h" +#include "GPU/GPU.h" +#include "GPU/GPUInterface.h" #include "GPU/GPUState.h" #ifdef BLACKBERRY @@ -1518,7 +1520,7 @@ bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_str HLEShutdown(); Replacement_Init(); HLEInit(); - GPU_Reinitialize(); + gpu->Reinitialize(); } __KernelModuleInit(); diff --git a/Core/System.cpp b/Core/System.cpp index 06246507d6..b4d7c5bd00 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -484,6 +484,14 @@ void PSP_Shutdown() { g_Config.unloadGameConfig(); } +void PSP_BeginHostFrame() { + // Reapply the graphics state of the PSP + gpu->ReapplyGfxState(); +} + +void PSP_EndHostFrame() { +} + void PSP_RunLoopUntil(u64 globalticks) { SaveState::Process(); if (coreState == CORE_POWERDOWN || coreState == CORE_ERROR) { diff --git a/Core/System.h b/Core/System.h index 9a11b5241f..1815db3e23 100644 --- a/Core/System.h +++ b/Core/System.h @@ -62,6 +62,9 @@ bool PSP_InitUpdate(std::string *error_string); bool PSP_IsIniting(); bool PSP_IsInited(); void PSP_Shutdown(); + +void PSP_BeginHostFrame(); +void PSP_EndHostFrame(); void PSP_RunLoopUntil(u64 globalticks); void PSP_RunLoopFor(int cycles); diff --git a/GPU/GPU.cpp b/GPU/GPU.cpp index f9a3d0ea6f..a7d6638a02 100644 --- a/GPU/GPU.cpp +++ b/GPU/GPU.cpp @@ -64,35 +64,3 @@ void GPU_Shutdown() { gpu = 0; gpuDebug = 0; } - -void GPU_Reinitialize() { - if (gpu) { - gpu->Reinitialize(); - } -} - -void InitGfxState() { - memset(&gstate, 0, sizeof(gstate)); - memset(&gstate_c, 0, sizeof(gstate_c)); - for (int i = 0; i < 256; i++) { - gstate.cmdmem[i] = i << 24; - } - - // Lighting is not enabled by default, matrices are zero initialized. - memset(gstate.worldMatrix, 0, sizeof(gstate.worldMatrix)); - memset(gstate.viewMatrix, 0, sizeof(gstate.viewMatrix)); - memset(gstate.projMatrix, 0, sizeof(gstate.projMatrix)); - memset(gstate.tgenMatrix, 0, sizeof(gstate.tgenMatrix)); - memset(gstate.boneMatrix, 0, sizeof(gstate.boneMatrix)); -} - -void ShutdownGfxState() { -} - -// When you have changed state outside the psp gfx core, -// or saved the context and has reloaded it, call this function. -void ReapplyGfxState() { - if (!gpu) - return; - gpu->ReapplyGfxState(); -} diff --git a/GPU/GPU.h b/GPU/GPU.h index 0849ab8cbc..d036d3ebea 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -106,4 +106,3 @@ extern GPUDebugInterface *gpuDebug; bool GPU_Init(GraphicsContext *ctx); void GPU_Shutdown(); -void GPU_Reinitialize(); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 051cd378a3..0cf5fc6bc1 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -33,11 +33,11 @@ GPUCommon::GPUCommon() : Reinitialize(); SetupColorConv(); SetThreadEnabled(g_Config.bSeparateCPUThread); - InitGfxState(); + gstate.Reset(); + gstate_c.Reset(); } GPUCommon::~GPUCommon() { - ShutdownGfxState(); } void GPUCommon::Reinitialize() { diff --git a/GPU/GPUState.cpp b/GPU/GPUState.cpp index 3e2ab5b6f4..0b55acd18e 100644 --- a/GPU/GPUState.cpp +++ b/GPU/GPUState.cpp @@ -74,6 +74,20 @@ static const CmdRange contextCmdRanges[] = { // Skip: {0xFA, 0xFF}, }; +void GPUgstate::Reset() { + memset(gstate.cmdmem, 0, sizeof(gstate.cmdmem)); + for (int i = 0; i < 256; i++) { + gstate.cmdmem[i] = i << 24; + } + + // Lighting is not enabled by default, matrices are zero initialized. + memset(gstate.worldMatrix, 0, sizeof(gstate.worldMatrix)); + memset(gstate.viewMatrix, 0, sizeof(gstate.viewMatrix)); + memset(gstate.projMatrix, 0, sizeof(gstate.projMatrix)); + memset(gstate.tgenMatrix, 0, sizeof(gstate.tgenMatrix)); + memset(gstate.boneMatrix, 0, sizeof(gstate.boneMatrix)); +} + void GPUgstate::Save(u32_le *ptr) { // Not sure what the first 10 values are, exactly, but these seem right. ptr[5] = gstate_c.vertexAddr; @@ -189,6 +203,10 @@ struct GPUStateCache_v0 bool flipTexture; }; +void GPUStateCache::Reset() { + memset(&gstate_c, 0, sizeof(gstate_c)); +} + void GPUStateCache::DoState(PointerWrap &p) { auto s = p.Section("GPUStateCache", 0, 4); if (!s) { diff --git a/GPU/GPUState.h b/GPU/GPUState.h index e9fa08cbe0..0445ec5b7d 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -415,6 +415,7 @@ struct GPUgstate { // Real data in the context ends here + void Reset(); void Save(u32_le *ptr); void Restore(u32_le *ptr); }; @@ -528,13 +529,10 @@ struct GPUStateCache { u32 curRTOffsetX; u32 getRelativeAddress(u32 data) const; + void Reset(); void DoState(PointerWrap &p); }; -void InitGfxState(); -void ShutdownGfxState(); -void ReapplyGfxState(); - class GPUInterface; class GPUDebugInterface; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 3b785c2d7b..c7d57dcd74 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -879,9 +879,7 @@ void EmuScreen::render() { thin3d->SetTargetSize(pixel_xres, pixel_yres); } - - // Reapply the graphics state of the PSP - ReapplyGfxState(); + PSP_BeginHostFrame(); // We just run the CPU until we get to vblank. This will quickly sync up pretty nicely. // The actual number of cycles doesn't matter so much here as we will break due to CORE_NEXTFRAME, most of the time hopefully... @@ -898,6 +896,8 @@ void EmuScreen::render() { } checkPowerDown(); + PSP_EndHostFrame(); + if (invalid_) return;