From c8b25e50b0b3e9bbc9ff21a02afce4a79fd1f2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 15 Mar 2023 00:54:50 +0100 Subject: [PATCH] Better debug vis for push pools --- Common/GPU/Vulkan/VulkanMemory.cpp | 27 ++++++++++++++------------- Common/GPU/Vulkan/VulkanMemory.h | 27 ++++++++++++--------------- GPU/Vulkan/DebugVisVulkan.cpp | 6 +++--- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanMemory.cpp b/Common/GPU/Vulkan/VulkanMemory.cpp index b4ee6297a5..8fea4abafa 100644 --- a/Common/GPU/Vulkan/VulkanMemory.cpp +++ b/Common/GPU/Vulkan/VulkanMemory.cpp @@ -27,6 +27,7 @@ #include "Common/TimeUtil.h" #include "Common/Math/math_util.h" #include "Common/GPU/Vulkan/VulkanMemory.h" +#include "Common/Data/Text/Parsers.h" using namespace PPSSPP_VK; @@ -150,8 +151,13 @@ size_t VulkanPushBuffer::GetTotalSize() const { return sum; } -size_t VulkanPushBuffer::GetTotalCapacity() const { - return size_ * buffers_.size(); +void VulkanPushBuffer::GetDebugString(char *buffer, size_t bufSize) const { + size_t sum = 0; + if (buffers_.size() > 1) + sum += size_ * (buffers_.size() - 1); + sum += offset_; + size_t capacity = size_ * buffers_.size(); + snprintf(buffer, bufSize, "Push %s: %s/%s", name_, NiceSizeFormat(capacity).c_str(), NiceSizeFormat(sum).c_str()); } void VulkanPushBuffer::Map() { @@ -367,18 +373,13 @@ void VulkanPushPool::NextBlock(VkDeviceSize allocationSize) { // curBlockIndex_ is already set correctly here. } -size_t VulkanPushPool::GetTotalSize() const { - size_t sz = 0; +void VulkanPushPool::GetDebugString(char *buffer, size_t bufSize) const { + size_t used = 0; + size_t capacity = 0; for (auto &block : blocks_) { - sz += block.used; + used += block.used; + capacity += block.size; } - return sz; -} -size_t VulkanPushPool::GetTotalCapacity() const { - size_t sz = 0; - for (auto &block : blocks_) { - sz += block.size; - } - return sz; + snprintf(buffer, bufSize, "Pool %s: %s / %s (%d extra blocks)", name_, NiceSizeFormat(used).c_str(), NiceSizeFormat(capacity).c_str(), (int)blocks_.size() - 3); } diff --git a/Common/GPU/Vulkan/VulkanMemory.h b/Common/GPU/Vulkan/VulkanMemory.h index a27cd9e3e7..e280e02c42 100644 --- a/Common/GPU/Vulkan/VulkanMemory.h +++ b/Common/GPU/Vulkan/VulkanMemory.h @@ -24,9 +24,8 @@ class VulkanMemoryManager { public: virtual ~VulkanMemoryManager() {} - virtual size_t GetTotalSize() const = 0; - virtual size_t GetTotalCapacity() const = 0; - virtual const char *Name() const = 0; + virtual void GetDebugString(char *buffer, size_t bufSize) const = 0; + virtual const char *Name() const = 0; // for sorting }; // VulkanPushBuffer @@ -53,6 +52,11 @@ public: void Reset() { offset_ = 0; } + void GetDebugString(char *buffer, size_t bufSize) const override; + const char *Name() const override { + return name_; + } + // Needs context in case of defragment. void Begin(VulkanContext *vulkan) { buf_ = 0; @@ -112,10 +116,6 @@ public: return offset_; } - const char *Name() const override { - return name_; - } - // "Zero-copy" variant - you can write the data directly as you compute it. // Recommended. void *Push(size_t size, uint32_t *bindOffset, VkBuffer *vkbuf) { @@ -141,8 +141,7 @@ public: info->range = sizeof(T); } - size_t GetTotalSize() const override; // Used size - size_t GetTotalCapacity() const override; + size_t GetTotalSize() const; private: bool AddBuffer(); @@ -171,8 +170,10 @@ public: void Destroy(); void BeginFrame(); - size_t GetTotalSize() const override; // Used size - size_t GetTotalCapacity() const override; + const char *Name() const override { + return name_; + } + void GetDebugString(char *buffer, size_t bufSize) const override; // When using the returned memory, make sure to bind the returned vkbuf. uint8_t *Allocate(VkDeviceSize numBytes, VkDeviceSize alignment, VkBuffer *vkbuf, uint32_t *bindOffset) { @@ -202,10 +203,6 @@ public: return bindOffset; } - const char *Name() const override { - return name_; - } - private: void NextBlock(VkDeviceSize allocationSize); diff --git a/GPU/Vulkan/DebugVisVulkan.cpp b/GPU/Vulkan/DebugVisVulkan.cpp index 74bf57100d..1c1cf1ff7a 100644 --- a/GPU/Vulkan/DebugVisVulkan.cpp +++ b/GPU/Vulkan/DebugVisVulkan.cpp @@ -78,10 +78,10 @@ void DrawAllocatorVis(UIContext *ui, GPUInterface *gpu) { auto managers = GetActiveVulkanMemoryManagers(); std::sort(managers.begin(), managers.end(), comparePushBufferNames); + char buffer[512]; for (auto manager : managers) { - str << " " << manager->Name() << " " - << NiceSizeFormat(manager->GetTotalCapacity()) << ", used: " - << NiceSizeFormat(manager->GetTotalSize()) << std::endl; + manager->GetDebugString(buffer, sizeof(buffer)); + str << " " << buffer << std::endl; } const int padding = 10 + System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT);