Skip to content

Commit

Permalink
Add buffer tags for debugging (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
shg8 authored Apr 10, 2024
1 parent dc69867 commit b34541f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions src/vulkan/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,18 +36,24 @@ 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<uint64_t>(static_cast<VkBuffer>(buffer)), debugName.c_str()});
}
}

Buffer::Buffer(const std::shared_ptr<VulkanContext>& _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),
shared(shared),
usage(usage),
vmaUsage(vmaUsage),
flags(flags),
allocation(nullptr) {
allocation(nullptr),
debugName(std::move(debugName)) {
alloc();
}

Expand Down Expand Up @@ -159,12 +165,12 @@ std::shared_ptr<Buffer> Buffer::staging(std::shared_ptr<VulkanContext> context,
}

std::shared_ptr<Buffer> Buffer::storage(std::shared_ptr<VulkanContext> context, uint64_t size, bool concurrentSharing,
vk::DeviceSize alignment) {
vk::DeviceSize alignment, std::string debugName) {
return std::make_shared<Buffer>(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) {
Expand Down
6 changes: 4 additions & 2 deletions src/vulkan/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DescriptorSet;
class Buffer : public std::enable_shared_from_this<Buffer> {
public:
Buffer(const std::shared_ptr<VulkanContext>& 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;

Expand All @@ -33,7 +33,8 @@ class Buffer : public std::enable_shared_from_this<Buffer> {

static std::shared_ptr<Buffer> staging(std::shared_ptr<VulkanContext> context, unsigned long size);

static std::shared_ptr<Buffer> storage(std::shared_ptr<VulkanContext> context, uint64_t size, bool concurrentSharing = false, vk::DeviceSize alignment = 0);
static std::shared_ptr<Buffer> storage(std::shared_ptr<VulkanContext> 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);

Expand Down Expand Up @@ -82,6 +83,7 @@ class Buffer : public std::enable_shared_from_this<Buffer> {
std::shared_ptr<VulkanContext> context;

std::vector<std::tuple<std::weak_ptr<DescriptorSet>, uint32_t, uint32_t, vk::DescriptorType>> boundDescriptorSets;
std::string debugName;
};


Expand Down

0 comments on commit b34541f

Please sign in to comment.