From 3093b9c7bf49e5ea9d53c184f8a7cf7948be4b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 20 Sep 2020 21:33:06 +0200 Subject: [PATCH] Share GPUS stats formatting code between the backends (easier to add new stats) --- GPU/Common/TextureCacheCommon.cpp | 3 ++- GPU/D3D11/GPU_D3D11.cpp | 39 ++++++---------------------- GPU/Directx9/GPU_DX9.cpp | 37 +++++---------------------- GPU/GLES/GPU_GLES.cpp | 42 +++++++------------------------ GPU/GPU.h | 5 ++++ GPU/GPUCommon.cpp | 35 ++++++++++++++++++++++++++ GPU/GPUCommon.h | 2 ++ GPU/Vulkan/GPU_Vulkan.cpp | 38 +++++----------------------- 8 files changed, 72 insertions(+), 129 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 64c687bf1e..6cfa2d3f66 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1759,8 +1759,9 @@ void TextureCacheCommon::Invalidate(u32 addr, int size, GPUInvalidationType type // This is an active signal from the game that something in the texture cache may have changed. gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); } else { - // Do a quick check to see if the current texture is in range. + // Do a quick check to see if the current texture could potentially be in range. const u32 currentAddr = gstate.getTextureAddress(0); + // TODO: This can be made tighter. if (addr_end >= currentAddr && addr < currentAddr + LARGEST_TEXTURE_SIZE) { gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); } diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index f4e8f20db8..c5a8753d06 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -304,38 +304,13 @@ void GPU_D3D11::ExecuteOp(u32 op, u32 diff) { } void GPU_D3D11::GetStats(char *buffer, size_t bufsize) { - float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f; - snprintf(buffer, bufsize - 1, - "DL processing time: %0.2f ms\n" - "Draw calls: %i, flushes %i, clears %i (cached: %d)\n" - "Num Tracked Vertex Arrays: %i\n" - "GPU cycles executed: %d (%f per vertex)\n" - "Commands per call level: %i %i %i %i\n" - "Vertices submitted: %i\n" - "Cached, Uncached Vertices Drawn: %i, %i\n" - "FBOs active: %i (evaluations: %d)\n" - "Textures active: %i, decoded: %i invalidated: %i\n" - "Readbacks: %d, uploads: %d\n" - "Vertex, Fragment shaders loaded: %i, %i\n", - gpuStats.msProcessingDisplayLists * 1000.0f, - gpuStats.numDrawCalls, - gpuStats.numFlushes, - gpuStats.numClears, - gpuStats.numCachedDrawCalls, - gpuStats.numTrackedVertexArrays, - gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, - vertexAverageCycles, - gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3], - gpuStats.numVertsSubmitted, - gpuStats.numCachedVertsDrawn, - gpuStats.numUncachedVertsDrawn, - (int)framebufferManagerD3D11_->NumVFBs(), - gpuStats.numFramebufferEvaluations, - (int)textureCacheD3D11_->NumLoadedTextures(), - gpuStats.numTexturesDecoded, - gpuStats.numTextureInvalidations, - gpuStats.numReadbacks, - gpuStats.numUploads, + size_t offset = FormatGPUStatsCommon(buffer, bufsize); + buffer += offset; + bufsize -= offset; + if ((int)bufsize < 0) + return; + snprintf(buffer, bufsize, + "Vertex, Fragment shaders loaded: %d, %d\n", shaderManagerD3D11_->GetNumVertexShaders(), shaderManagerD3D11_->GetNumFragmentShaders() ); diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 936dcee7a8..ad858ea665 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -344,38 +344,13 @@ void GPU_DX9::ExecuteOp(u32 op, u32 diff) { } void GPU_DX9::GetStats(char *buffer, size_t bufsize) { - float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f; - snprintf(buffer, bufsize - 1, - "DL processing time: %0.2f ms\n" - "Draw calls: %i, flushes %i, clears %i (cached: %d)\n" - "Num Tracked Vertex Arrays: %i\n" - "GPU cycles executed: %d (%f per vertex)\n" - "Commands per call level: %i %i %i %i\n" - "Vertices submitted: %i\n" - "Cached, Uncached Vertices Drawn: %i, %i\n" - "FBOs active: %i (evaluations: %d)\n" - "Textures active: %i, decoded: %i invalidated: %i\n" - "Readbacks: %d, uploads: %d\n" + size_t offset = FormatGPUStatsCommon(buffer, bufsize); + buffer += offset; + bufsize -= offset; + if ((int)bufsize < 0) + return; + snprintf(buffer, bufsize, "Vertex, Fragment shaders loaded: %i, %i\n", - gpuStats.msProcessingDisplayLists * 1000.0f, - gpuStats.numDrawCalls, - gpuStats.numFlushes, - gpuStats.numClears, - gpuStats.numCachedDrawCalls, - gpuStats.numTrackedVertexArrays, - gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, - vertexAverageCycles, - gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3], - gpuStats.numVertsSubmitted, - gpuStats.numCachedVertsDrawn, - gpuStats.numUncachedVertsDrawn, - (int)framebufferManagerDX9_->NumVFBs(), - gpuStats.numFramebufferEvaluations, - (int)textureCacheDX9_->NumLoadedTextures(), - gpuStats.numTexturesDecoded, - gpuStats.numTextureInvalidations, - gpuStats.numReadbacks, - gpuStats.numUploads, shaderManagerDX9_->GetNumVertexShaders(), shaderManagerDX9_->GetNumFragmentShaders() ); diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 2ba4922a2c..062705f8a3 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -445,41 +445,17 @@ void GPU_GLES::ExecuteOp(u32 op, u32 diff) { } void GPU_GLES::GetStats(char *buffer, size_t bufsize) { - float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f; - snprintf(buffer, bufsize - 1, - "DL processing time: %0.2f ms\n" - "Draw calls: %i, flushes %i, clears %i (cached: %d)\n" - "Num Tracked Vertex Arrays: %i\n" - "GPU cycles executed: %d (%f per vertex)\n" - "Commands per call level: %i %i %i %i\n" - "Vertices submitted: %i\n" - "Cached, Uncached Vertices Drawn: %i, %i\n" - "FBOs active: %i (evaluations: %d)\n" - "Textures active: %i, decoded: %i invalidated: %i\n" - "Readbacks: %d, uploads: %d\n" - "Vertex, Fragment, Programs loaded: %i, %i, %i\n", - gpuStats.msProcessingDisplayLists * 1000.0f, - gpuStats.numDrawCalls, - gpuStats.numFlushes, - gpuStats.numClears, - gpuStats.numCachedDrawCalls, - gpuStats.numTrackedVertexArrays, - gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, - vertexAverageCycles, - gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3], - gpuStats.numVertsSubmitted, - gpuStats.numCachedVertsDrawn, - gpuStats.numUncachedVertsDrawn, - (int)framebufferManagerGL_->NumVFBs(), - gpuStats.numFramebufferEvaluations, - (int)textureCacheGL_->NumLoadedTextures(), - gpuStats.numTexturesDecoded, - gpuStats.numTextureInvalidations, - gpuStats.numReadbacks, - gpuStats.numUploads, + size_t offset = FormatGPUStatsCommon(buffer, bufsize); + buffer += offset; + bufsize -= offset; + if ((int)bufsize < 0) + return; + snprintf(buffer, bufsize, + "Vertex, Fragment, Programs loaded: %d, %d, %d\n", shaderManagerGL_->GetNumVertexShaders(), shaderManagerGL_->GetNumFragmentShaders(), - shaderManagerGL_->GetNumPrograms()); + shaderManagerGL_->GetNumPrograms() + ); } void GPU_GLES::ClearCacheNextFrame() { diff --git a/GPU/GPU.h b/GPU/GPU.h index 92785b8de4..0a4fb4f66d 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -55,6 +55,7 @@ struct GPUStatistics { // Never add a vtable :) memset(this, 0, sizeof(*this)); } + void ResetFrame() { numDrawCalls = 0; numCachedDrawCalls = 0; @@ -64,7 +65,9 @@ struct GPUStatistics { numTrackedVertexArrays = 0; numTextureInvalidations = 0; numTextureInvalidationsByFramebuffer = 0; + numTexturesHashed = 0; numTextureSwitches = 0; + numTextureDataBytesHashed = 0; numShaderSwitches = 0; numFlushes = 0; numTexturesDecoded = 0; @@ -88,6 +91,8 @@ struct GPUStatistics { int numTrackedVertexArrays; int numTextureInvalidations; int numTextureInvalidationsByFramebuffer; + int numTexturesHashed; + int numTextureDataBytesHashed; int numTextureSwitches; int numShaderSwitches; int numTexturesDecoded; diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 32bcb5ec66..620c1b85fc 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2876,3 +2876,38 @@ bool GPUCommon::FramebufferReallyDirty() { } return true; } + +size_t GPUCommon::FormatGPUStatsCommon(char *buffer, size_t size) { + float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f; + return snprintf(buffer, size, + "DL processing time: %0.2f ms\n" + "Draw calls: %i, flushes %i, clears %i (cached: %d)\n" + "Num Tracked Vertex Arrays: %i\n" + "GPU cycles executed: %d (%f per vertex)\n" + "Commands per call level: %i %i %i %i\n" + "Vertices submitted: %i\n" + "Cached, Uncached Vertices Drawn: %i, %i\n" + "FBOs active: %i (evaluations: %d)\n" + "Textures active: %i, decoded: %i invalidated: %i\n" + "Readbacks: %d, uploads: %d\n", + gpuStats.msProcessingDisplayLists * 1000.0f, + gpuStats.numDrawCalls, + gpuStats.numFlushes, + gpuStats.numClears, + gpuStats.numCachedDrawCalls, + gpuStats.numTrackedVertexArrays, + gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, + vertexAverageCycles, + gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3], + gpuStats.numVertsSubmitted, + gpuStats.numCachedVertsDrawn, + gpuStats.numUncachedVertsDrawn, + (int)framebufferManager_->NumVFBs(), + gpuStats.numFramebufferEvaluations, + (int)textureCache_->NumLoadedTextures(), + gpuStats.numTexturesDecoded, + gpuStats.numTextureInvalidations, + gpuStats.numReadbacks, + gpuStats.numUploads + ); +} diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 2dd4d7da1b..ede1b44720 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -303,6 +303,8 @@ protected: } } + size_t FormatGPUStatsCommon(char *buf, size_t size); + FramebufferManagerCommon *framebufferManager_ = nullptr; TextureCacheCommon *textureCache_ = nullptr; DrawEngineCommon *drawEngineCommon_ = nullptr; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 9c7f36afe7..2b9724f127 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -552,44 +552,18 @@ void GPU_Vulkan::DeviceRestore() { } void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) { + size_t offset = FormatGPUStatsCommon(buffer, bufsize); + buffer += offset; + bufsize -= offset; + if ((int)bufsize < 0) + return; const DrawEngineVulkanStats &drawStats = drawEngine_.GetStats(); char texStats[256]; textureCacheVulkan_->GetStats(texStats, sizeof(texStats)); - float vertexAverageCycles = gpuStats.numVertsSubmitted > 0 ? (float)gpuStats.vertexGPUCycles / (float)gpuStats.numVertsSubmitted : 0.0f; - snprintf(buffer, bufsize - 1, - "DL processing time: %0.2f ms\n" - "Draw calls: %i, flushes %i, clears %i (cached: %d)\n" - "Num Tracked Vertex Arrays: %i\n" - "GPU cycles executed: %d (%f per vertex)\n" - "Commands per call level: %i %i %i %i\n" - "Vertices submitted: %i\n" - "Cached, Uncached Vertices Drawn: %i, %i\n" - "FBOs active: %i (evaluations: %d)\n" - "Textures active: %i, decoded: %i invalidated: %d (%d by fb)\n" - "Readbacks: %d, uploads: %d\n" + snprintf(buffer, bufsize, "Vertex, Fragment, Pipelines loaded: %i, %i, %i\n" "Pushbuffer space used: UBO %d, Vtx %d, Idx %d\n" "%s\n", - gpuStats.msProcessingDisplayLists * 1000.0f, - gpuStats.numDrawCalls, - gpuStats.numFlushes, - gpuStats.numClears, - gpuStats.numCachedDrawCalls, - gpuStats.numTrackedVertexArrays, - gpuStats.vertexGPUCycles + gpuStats.otherGPUCycles, - vertexAverageCycles, - gpuStats.gpuCommandsAtCallLevel[0], gpuStats.gpuCommandsAtCallLevel[1], gpuStats.gpuCommandsAtCallLevel[2], gpuStats.gpuCommandsAtCallLevel[3], - gpuStats.numVertsSubmitted, - gpuStats.numCachedVertsDrawn, - gpuStats.numUncachedVertsDrawn, - (int)framebufferManager_->NumVFBs(), - gpuStats.numFramebufferEvaluations, - (int)textureCacheVulkan_->NumLoadedTextures(), - gpuStats.numTexturesDecoded, - gpuStats.numTextureInvalidations, - gpuStats.numTextureInvalidationsByFramebuffer, - gpuStats.numReadbacks, - gpuStats.numUploads, shaderManagerVulkan_->GetNumVertexShaders(), shaderManagerVulkan_->GetNumFragmentShaders(), pipelineManager_->GetNumPipelines(),