diff --git a/Core/System.cpp b/Core/System.cpp index 1ec7ae54aa..1030d914ee 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -364,9 +364,9 @@ void Core_UpdateState(CoreState newState) { Core_UpdateSingleStep(); } -static void Core_UpdateDebugStats(bool flag) { - if (coreCollectDebugStats != flag) { - coreCollectDebugStats = flag; +void Core_UpdateDebugStats(bool collectStats) { + if (coreCollectDebugStats != collectStats) { + coreCollectDebugStats = collectStats; mipsr4k.ClearJitCache(); } @@ -518,8 +518,6 @@ void PSP_EndHostFrame() { } void PSP_RunLoopUntil(u64 globalticks) { - Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops); - SaveState::Process(); if (coreState == CORE_POWERDOWN || coreState == CORE_ERROR) { return; diff --git a/Core/System.h b/Core/System.h index 338d679fe1..26d1d6e19b 100644 --- a/Core/System.h +++ b/Core/System.h @@ -73,6 +73,9 @@ void PSP_EndHostFrame(); void PSP_RunLoopUntil(u64 globalticks); void PSP_RunLoopFor(int cycles); +// Call before PSP_BeginHostFrame() in order to not miss any GPU stats. +void Core_UpdateDebugStats(bool collectStats); + void Audio_Init(); bool IsOnSeparateCPUThread(); diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index 0254e2d006..82ab623172 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -1929,6 +1929,7 @@ bool FramebufferManagerCommon::GetFramebuffer(u32 fb_address, int fb_stride, GEB bool flipY = (g_Config.iGPUBackend == GPU_BACKEND_OPENGL && !useBufferedRendering_) ? true : false; buffer.Allocate(w, h, GE_FORMAT_8888, flipY, true); bool retval = draw_->CopyFramebufferToMemorySync(bound, Draw::FB_COLOR_BIT, 0, 0, w, h, Draw::DataFormat::R8G8B8A8_UNORM, buffer.GetData(), w); + gpuStats.numReadbacks++; // Vulkan requires us to re-apply all dynamic state for each command buffer, and the above will cause us to start a new cmdbuf. // So let's dirty the things that are involved in Vulkan dynamic state. Readbacks are not frequent so this won't hurt other backends. gstate_c.Dirty(DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE); @@ -2031,6 +2032,7 @@ void FramebufferManagerCommon::PackFramebufferSync_(VirtualFramebuffer *vfb, int DEBUG_LOG(G3D, "Reading framebuffer to mem, fb_address = %08x", fb_address); draw_->CopyFramebufferToMemorySync(vfb->fbo, Draw::FB_COLOR_BIT, x, y, w, h, destFormat, destPtr, vfb->fb_stride); + gpuStats.numReadbacks++; } void FramebufferManagerCommon::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) { diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 847fbf09c1..057716bf00 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -713,6 +713,7 @@ void GPU_D3D11::GetStats(char *buffer, size_t bufsize) { "Cached, Uncached Vertices Drawn: %i, %i\n" "FBOs active: %i\n" "Textures active: %i, decoded: %i invalidated: %i\n" + "Readbacks: %d\n" "Vertex, Fragment shaders loaded: %i, %i\n", gpuStats.msProcessingDisplayLists * 1000.0f, gpuStats.numDrawCalls, @@ -729,6 +730,7 @@ void GPU_D3D11::GetStats(char *buffer, size_t bufsize) { (int)textureCacheD3D11_->NumLoadedTextures(), gpuStats.numTexturesDecoded, gpuStats.numTextureInvalidations, + gpuStats.numReadbacks, shaderManagerD3D11_->GetNumVertexShaders(), shaderManagerD3D11_->GetNumFragmentShaders() ); diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index df33d8e41b..7459d45df6 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -645,6 +645,7 @@ void GPU_DX9::GetStats(char *buffer, size_t bufsize) { "Cached, Uncached Vertices Drawn: %i, %i\n" "FBOs active: %i\n" "Textures active: %i, decoded: %i invalidated: %i\n" + "Readbacks: %d\n" "Vertex, Fragment shaders loaded: %i, %i\n", gpuStats.msProcessingDisplayLists * 1000.0f, gpuStats.numDrawCalls, @@ -661,6 +662,7 @@ void GPU_DX9::GetStats(char *buffer, size_t bufsize) { (int)textureCacheDX9_->NumLoadedTextures(), gpuStats.numTexturesDecoded, gpuStats.numTextureInvalidations, + gpuStats.numReadbacks, shaderManagerDX9_->GetNumVertexShaders(), shaderManagerDX9_->GetNumFragmentShaders() ); diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index f12245778c..b8e7adbd06 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -884,6 +884,7 @@ void GPU_GLES::GetStats(char *buffer, size_t bufsize) { "Cached, Uncached Vertices Drawn: %i, %i\n" "FBOs active: %i\n" "Textures active: %i, decoded: %i invalidated: %i\n" + "Readbacks: %d\n" "Vertex, Fragment, Programs loaded: %i, %i, %i\n", gpuStats.msProcessingDisplayLists * 1000.0f, gpuStats.numDrawCalls, @@ -900,6 +901,7 @@ void GPU_GLES::GetStats(char *buffer, size_t bufsize) { (int)textureCacheGL_->NumLoadedTextures(), gpuStats.numTexturesDecoded, gpuStats.numTextureInvalidations, + gpuStats.numReadbacks, shaderManagerGL_->GetNumVertexShaders(), shaderManagerGL_->GetNumFragmentShaders(), shaderManagerGL_->GetNumPrograms()); diff --git a/GPU/GPU.h b/GPU/GPU.h index 2d9435da46..2042fab015 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -67,6 +67,7 @@ struct GPUStatistics { numShaderSwitches = 0; numFlushes = 0; numTexturesDecoded = 0; + numReadbacks = 0; msProcessingDisplayLists = 0; vertexGPUCycles = 0; otherGPUCycles = 0; @@ -85,6 +86,7 @@ struct GPUStatistics { int numTextureSwitches; int numShaderSwitches; int numTexturesDecoded; + int numReadbacks; double msProcessingDisplayLists; int vertexGPUCycles; int otherGPUCycles; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 2e276056aa..d84893d006 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -833,6 +833,7 @@ void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) { "Cached, Uncached Vertices Drawn: %i, %i\n" "FBOs active: %i\n" "Textures active: %i, decoded: %i invalidated: %i\n" + "Readbacks: %d\n" "Vertex, Fragment, Pipelines loaded: %i, %i, %i\n" "Pushbuffer space used: UBO %d, Vtx %d, Idx %d\n", gpuStats.msProcessingDisplayLists * 1000.0f, @@ -850,6 +851,7 @@ void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) { (int)textureCacheVulkan_->NumLoadedTextures(), gpuStats.numTexturesDecoded, gpuStats.numTextureInvalidations, + gpuStats.numReadbacks, shaderManagerVulkan_->GetNumVertexShaders(), shaderManagerVulkan_->GetNumFragmentShaders(), pipelineManager_->GetNumPipelines(), diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index a7339637c8..bbeb5c9b6d 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1012,6 +1012,8 @@ void EmuScreen::render() { } } + Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops); + PSP_BeginHostFrame(); // We just run the CPU until we get to vblank. This will quickly sync up pretty nicely. diff --git a/headless/Headless.cpp b/headless/Headless.cpp index ef3ead4188..a20e540a8f 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -158,6 +158,8 @@ bool RunAutoTest(HeadlessHost *headlessHost, CoreParameter &coreParameter, bool static double deadline; deadline = time_now() + timeout; + Core_UpdateDebugStats(g_Config.bShowDebugStats || g_Config.bLogFrameDrops); + PSP_BeginHostFrame(); coreState = CORE_RUNNING;