Skip to content

Commit

Permalink
vulkan memory stats debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Feb 1, 2025
1 parent 0d21908 commit 0a28fe2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/event/sdl/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "joystick/sdl/Joystick.h"
#include "window/sdl/Window.h"
#include "graphics/vulkan/Graphics.h"

namespace love
{
Expand Down Expand Up @@ -219,6 +220,13 @@ Message *Event::convert(const SDL_Event &e)
break;
}

if (e.key.key == SDLK_F10)
{
auto vgfx = dynamic_cast<love::graphics::vulkan::Graphics *>(Module::getInstance<love::graphics::Graphics>(M_GRAPHICS));
if (vgfx != nullptr)
vgfx->dumpMemoryStats();
}

love::keyboard::sdl::Keyboard::getConstant(e.key.key, key);
if (!love::keyboard::Keyboard::getConstant(key, txt))
txt = "unknown";
Expand Down
18 changes: 18 additions & 0 deletions src/modules/graphics/vulkan/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "GraphicsReadback.h"
#include "Shader.h"
#include "Vulkan.h"
#include "filesystem/Filesystem.h"

#include <SDL3/SDL_vulkan.h>
#include <SDL3/SDL_hints.h>
Expand Down Expand Up @@ -3069,6 +3070,23 @@ VkPipeline Graphics::createGraphicsPipeline(Shader *shader, const GraphicsPipeli
return graphicsPipeline;
}

void Graphics::dumpMemoryStats()
{
auto fs = Module::getInstance<filesystem::Filesystem>(M_FILESYSTEM);
if (fs == nullptr)
return;

char *stats = nullptr;
vmaBuildStatsString(vmaAllocator, &stats, VK_TRUE);
if (stats != nullptr)
{
fs->write("vulkan_memory_stats.json", stats, strlen(stats));
vmaFreeStatsString(vmaAllocator, stats);
}

::printf("memory stats saved to vulkan_memory_stats.json\n");
}

VkSampleCountFlagBits Graphics::getMsaaCount(int requestedMsaa) const
{
VkPhysicalDeviceProperties physicalDeviceProperties;
Expand Down
2 changes: 2 additions & 0 deletions src/modules/graphics/vulkan/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ class Graphics final : public love::graphics::Graphics

VkPipeline createGraphicsPipeline(Shader *shader, const GraphicsPipelineConfigurationCore &configuration, const GraphicsPipelineConfigurationNoDynamicState *noDynamicStateConfiguration);

void dumpMemoryStats();

uint32 getDeviceApiVersion() const { return deviceApiVersion; }

uint64 getRealFrameIndex() const { return realFrameIndex; }
Expand Down
13 changes: 13 additions & 0 deletions src/modules/graphics/vulkan/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,23 @@ void SharedDescriptorPools::createDescriptorPool()
createInfo.poolSizeCount = static_cast<uint32_t>(descriptorPoolSizes.size());
createInfo.pPoolSizes = descriptorPoolSizes.data();

std::string descs;
for (const auto &size : descriptorPoolSizes)
{
descs += std::string("type ") + std::to_string(size.type) + std::string(" with count: ") + std::to_string(size.descriptorCount) + std::string(", ");
}

::printf("Creating descriptor pool: %s\n", descs.c_str());

VkDescriptorPool pool;
VkResult result = vkCreateDescriptorPool(device, &createInfo, nullptr, &pool);
if (result != VK_SUCCESS)
{
auto vgfx = (Graphics *)Module::getInstance<Graphics>(Module::M_GRAPHICS);
if (vgfx != nullptr)
vgfx->dumpMemoryStats();
throw love::Exception("Failed to create Vulkan descriptor pool: %s", Vulkan::getErrorString(result));
}

pools[currentFrame].push_back(pool);
}
Expand Down

0 comments on commit 0a28fe2

Please sign in to comment.