Skip to content

Commit

Permalink
Better debug vis for push pools
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 15, 2023
1 parent 9fcd6d6 commit c8b25e5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
27 changes: 14 additions & 13 deletions Common/GPU/Vulkan/VulkanMemory.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
27 changes: 12 additions & 15 deletions Common/GPU/Vulkan/VulkanMemory.h
Expand Up @@ -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
Expand All @@ -53,6 +52,11 @@ class VulkanPushBuffer : public VulkanMemoryManager {

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;
Expand Down Expand Up @@ -112,10 +116,6 @@ class VulkanPushBuffer : public VulkanMemoryManager {
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) {
Expand All @@ -141,8 +141,7 @@ class VulkanPushBuffer : public VulkanMemoryManager {
info->range = sizeof(T);
}

size_t GetTotalSize() const override; // Used size
size_t GetTotalCapacity() const override;
size_t GetTotalSize() const;

private:
bool AddBuffer();
Expand Down Expand Up @@ -171,8 +170,10 @@ class VulkanPushPool : public VulkanMemoryManager {
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) {
Expand Down Expand Up @@ -202,10 +203,6 @@ class VulkanPushPool : public VulkanMemoryManager {
return bindOffset;
}

const char *Name() const override {
return name_;
}

private:
void NextBlock(VkDeviceSize allocationSize);

Expand Down
6 changes: 3 additions & 3 deletions GPU/Vulkan/DebugVisVulkan.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit c8b25e5

Please sign in to comment.