From 7f55c837a84a46b62b6b852458ddae5a1b402288 Mon Sep 17 00:00:00 2001 From: shg8 Date: Tue, 9 Apr 2024 20:56:30 -0500 Subject: [PATCH] Add buffer tags for debugging --- src/Renderer.cpp | 8 ++++---- src/vulkan/Buffer.cpp | 16 +++++++++++----- src/vulkan/Buffer.h | 6 ++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index cdfb64b..fe7e4e4 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -233,13 +233,13 @@ void Renderer::createPrefixSumPipeline() { void Renderer::createRadixSortPipeline() { spdlog::debug("Creating radix sort pipeline"); sortKBufferEven = Buffer::storage(context, scene->getNumVertices() * sizeof(uint64_t) * sortBufferSizeMultiplier, - false); + false, 0, "sortKBufferEven"); sortKBufferOdd = Buffer::storage(context, scene->getNumVertices() * sizeof(uint64_t) * sortBufferSizeMultiplier, - false); + false, 0, "sortKBufferOdd"); sortVBufferEven = Buffer::storage(context, scene->getNumVertices() * sizeof(uint32_t) * sortBufferSizeMultiplier, - false); + false, 0, "sortVBufferEven"); sortVBufferOdd = Buffer::storage(context, scene->getNumVertices() * sizeof(uint32_t) * sortBufferSizeMultiplier, - false); + false, 0, "sortVBufferOdd"); uint32_t globalInvocationSize = scene->getNumVertices() * sortBufferSizeMultiplier / numRadixSortBlocksPerWorkgroup; uint32_t remainder = scene->getNumVertices() * sortBufferSizeMultiplier % numRadixSortBlocksPerWorkgroup; diff --git a/src/vulkan/Buffer.cpp b/src/vulkan/Buffer.cpp index 137f418..5228aa1 100644 --- a/src/vulkan/Buffer.cpp +++ b/src/vulkan/Buffer.cpp @@ -23,7 +23,7 @@ void Buffer::alloc() { allocInfo.usage = vmaUsage; allocInfo.flags = flags; - VkBuffer vkBuffer; + VkBuffer vkBuffer = VK_NULL_HANDLE; VkResult res; if (alignment != 0) { @@ -36,10 +36,15 @@ void Buffer::alloc() { throw std::runtime_error("Failed to create buffer"); } buffer = vk::Buffer(vkBuffer); + + if (context->validationLayersEnabled) { + context->device->setDebugUtilsObjectNameEXT( + vk::DebugUtilsObjectNameInfoEXT {vk::ObjectType::eBuffer, reinterpret_cast(static_cast(buffer)), debugName.c_str()}); + } } Buffer::Buffer(const std::shared_ptr& _context, uint32_t size, vk::BufferUsageFlags usage, - VmaMemoryUsage vmaUsage, VmaAllocationCreateFlags flags, bool shared, vk::DeviceSize alignment) + VmaMemoryUsage vmaUsage, VmaAllocationCreateFlags flags, bool shared, vk::DeviceSize alignment, std::string debugName) : context(_context), size(size), alignment(alignment), @@ -47,7 +52,8 @@ Buffer::Buffer(const std::shared_ptr& _context, uint32_t size, vk usage(usage), vmaUsage(vmaUsage), flags(flags), - allocation(nullptr) { + allocation(nullptr), + debugName(std::move(debugName)) { alloc(); } @@ -159,12 +165,12 @@ std::shared_ptr Buffer::staging(std::shared_ptr context, } std::shared_ptr Buffer::storage(std::shared_ptr context, uint64_t size, bool concurrentSharing, - vk::DeviceSize alignment) { + vk::DeviceSize alignment, std::string debugName) { return std::make_shared(context, size, vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eTransferSrc, VMA_MEMORY_USAGE_GPU_ONLY, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT, - concurrentSharing, alignment); + concurrentSharing, alignment, debugName); } void Buffer::assertEquals(char* data, size_t length) { diff --git a/src/vulkan/Buffer.h b/src/vulkan/Buffer.h index b2602bc..aa62648 100644 --- a/src/vulkan/Buffer.h +++ b/src/vulkan/Buffer.h @@ -13,7 +13,7 @@ class DescriptorSet; class Buffer : public std::enable_shared_from_this { public: Buffer(const std::shared_ptr& context, uint32_t size, vk::BufferUsageFlags usage, VmaMemoryUsage vmaUsage, - VmaAllocationCreateFlags flags, bool concurrentSharing = false, VkDeviceSize alignment = 0); + VmaAllocationCreateFlags flags, bool concurrentSharing = false, VkDeviceSize alignment = 0, std::string debugName = "Unnamed"); Buffer(const Buffer &) = delete; @@ -33,7 +33,8 @@ class Buffer : public std::enable_shared_from_this { static std::shared_ptr staging(std::shared_ptr context, unsigned long size); - static std::shared_ptr storage(std::shared_ptr context, uint64_t size, bool concurrentSharing = false, vk::DeviceSize alignment = 0); + static std::shared_ptr storage(std::shared_ptr context, uint64_t size, bool concurrentSharing = false, vk::DeviceSize alignment = 0, std + ::string debugName = "Unnamed Storage Buffer"); void upload(const void *data, uint32_t size, uint32_t offset = 0); @@ -82,6 +83,7 @@ class Buffer : public std::enable_shared_from_this { std::shared_ptr context; std::vector, uint32_t, uint32_t, vk::DescriptorType>> boundDescriptorSets; + std::string debugName; };