Skip to content

Commit

Permalink
[*] Use debug utils naming system
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed Aug 2, 2023
1 parent 53be5bd commit 4039951
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/inexor/vulkan-renderer/wrapper/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class CommandBuffer {
CommandBuffer(const CommandBuffer &) = delete;
CommandBuffer(CommandBuffer &&) noexcept;

/// @note Command buffers are allocated from a command pool, meaning the memory required for this will be
/// freed if the corresponding command pool is destroyed. Command buffers are not freed in the Destructor.
~CommandBuffer() = default;

CommandBuffer &operator=(const CommandBuffer &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion include/inexor/vulkan-renderer/wrapper/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Device {
/// @param obj_type The Vulkan object type
/// @param obj_handle The Vulkan object handle
/// @param name the internal debug name of the Vulkan object
void set_debug_utils_object_name(VkObjectType obj_type, std::uint64_t obj_handle, const std::string &name);
void set_debug_utils_object_name(VkObjectType obj_type, std::uint64_t obj_handle, const std::string &name) const;

/// Check if a surface supports a certain image usage
/// @param surface The window surface
Expand Down
4 changes: 4 additions & 0 deletions src/vulkan-renderer/wrapper/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ Buffer::Buffer(const Device &device, const VkDeviceSize buffer_size, const VkBuf
throw VulkanException("Error: vmaCreateBuffer failed for buffer " + m_name + " !", result);
}

// Set the buffer's internal debug name in Vulkan Memory Allocator (VMA)
vmaSetAllocationName(m_device.allocator(), m_allocation, m_name.c_str());

// Set the buffer's internal denug name through Vulkan debug utils
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_BUFFER, reinterpret_cast<std::uint64_t>(m_buffer), m_name);
}

Buffer::Buffer(const Device &device, const VkDeviceSize buffer_size, const void *buffer_data,
Expand Down
6 changes: 6 additions & 0 deletions src/vulkan-renderer/wrapper/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ CommandBuffer::CommandBuffer(const Device &device, const VkCommandPool cmd_pool,
.commandBufferCount = 1,
});

// Note that command buffers are allocated from a command pool, meaning the memory required for this will be
// freed if the corresponding command pool is destroyed. Command buffers are not freed in the destructor.
if (const auto result = vkAllocateCommandBuffers(m_device.device(), &cmd_buf_ai, &m_command_buffer);
result != VK_SUCCESS) {
throw VulkanException("Error: vkAllocateCommandBuffers failed!", result);
}

// Assign an internal debug name to this command buffer using debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_COMMAND_BUFFER,
reinterpret_cast<std::uint64_t>(m_command_buffer), m_name);

m_wait_fence = std::make_unique<Fence>(m_device, m_name, false);
}

Expand Down
5 changes: 5 additions & 0 deletions src/vulkan-renderer/wrapper/command_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ CommandPool::CommandPool(const Device &device, std::string name) : m_device(devi
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateCommandPool failed for command pool " + m_name + "!", result);
}
// Assign an internal debug name to this command pool using debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_COMMAND_POOL, reinterpret_cast<std::uint64_t>(m_cmd_pool),
m_name);
}

CommandPool::CommandPool(CommandPool &&other) noexcept : m_device(other.m_device) {
m_cmd_pool = std::exchange(other.m_cmd_pool, nullptr);
m_name = std::move(other.m_name);
m_cmd_bufs = std::move(other.m_cmd_bufs);
}

CommandPool::~CommandPool() {
Expand Down
7 changes: 5 additions & 2 deletions src/vulkan-renderer/wrapper/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ Device::Device(const Instance &inst, const VkSurfaceKHR surface, const bool pref
// Store the properties of this physical device
vkGetPhysicalDeviceProperties(m_physical_device, &m_properties);

// Set an internal debug name to this device using Vulkan debug utils (VK_EXT_debug_utils)
set_debug_utils_object_name(VK_OBJECT_TYPE_DEVICE, reinterpret_cast<std::uint64_t>(m_device), "Device");

// Now that we created the device, we can finally name the instance
set_debug_utils_object_name(VK_OBJECT_TYPE_INSTANCE, reinterpret_cast<std::uint64_t>(inst.instance()), "Johannes1");
set_debug_utils_object_name(VK_OBJECT_TYPE_INSTANCE, reinterpret_cast<std::uint64_t>(inst.instance()), "Instance");
}

Device::~Device() {
Expand Down Expand Up @@ -443,7 +446,7 @@ const CommandBuffer &Device::request_command_buffer(const std::string &name) {
}

void Device::set_debug_utils_object_name(const VkObjectType obj_type, const std::uint64_t obj_handle,
const std::string &name) {
const std::string &name) const {
const auto dbg_obj_name = wrapper::make_info<VkDebugUtilsObjectNameInfoEXT>({
.objectType = obj_type,
.objectHandle = obj_handle,
Expand Down
2 changes: 2 additions & 0 deletions src/vulkan-renderer/wrapper/fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Fence::Fence(const Device &device, const std::string &name, const bool in_signal
if (const auto result = vkCreateFence(m_device.device(), &fence_ci, nullptr, &m_fence); result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateFence failed for fence " + name + "!", result);
}
// Set an internal debug name to this fence using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_FENCE, reinterpret_cast<std::uint64_t>(m_fence), m_name);
}

Fence::Fence(Fence &&other) noexcept : m_device(other.m_device) {
Expand Down
4 changes: 4 additions & 0 deletions src/vulkan-renderer/wrapper/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Framebuffer::Framebuffer(const Device &device, VkRenderPass render_pass, const s
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateFramebuffer failed for framebuffer " + name + "!", result);
}

// Set an internal debug name to this framebuffer using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_FRAMEBUFFER, reinterpret_cast<std::uint64_t>(m_framebuffer),
m_name);
}

Framebuffer::Framebuffer(Framebuffer &&other) noexcept : m_device(other.m_device) {
Expand Down
6 changes: 6 additions & 0 deletions src/vulkan-renderer/wrapper/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ Image::Image(const Device &device, const VkImageCreateInfo &img_ci, const VkImag
result != VK_SUCCESS) {
throw VulkanException("Error: vmaCreateImage failed for image " + m_name + "!", result);
}
// Assign an internal debug name to this image in Vulkan Memory Allocator (VMA)
vmaSetAllocationName(m_device.allocator(), m_alloc, m_name.c_str());
// Set an internal debug name to this image using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_IMAGE, reinterpret_cast<std::uint64_t>(m_img), m_name);

// Fill in the image that was created and the format of the image
auto filled_img_view_ci = img_view_ci;
Expand All @@ -31,6 +34,9 @@ Image::Image(const Device &device, const VkImageCreateInfo &img_ci, const VkImag
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateImageView failed for image view " + m_name + "!", result);
}
// Set an internal debug name to this image using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast<std::uint64_t>(m_img_view),
m_name);
}

// Constructor 2 (calls constructor 1 internally)
Expand Down
1 change: 1 addition & 0 deletions src/vulkan-renderer/wrapper/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ Instance::Instance(const std::string &application_name, const std::string &engin
.ppEnabledExtensionNames = enabled_instance_extensions.data(),
});

// Note that an internal debug name will be assigned to the instance inside of the device wrapper
if (const auto result = vkCreateInstance(&instance_ci, nullptr, &m_instance); result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateInstance failed!", result);
}
Expand Down
3 changes: 3 additions & 0 deletions src/vulkan-renderer/wrapper/render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ RenderPass::RenderPass(const Device &device, const VkRenderPassCreateInfo &rende
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateRenderPass failed for renderpass " + m_name + " !", result);
}
// Set an internal debug name to this renderpass using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_RENDER_PASS, reinterpret_cast<std::uint64_t>(m_render_pass),
m_name);
}

RenderPass::RenderPass(const Device &device, const std::vector<VkAttachmentDescription> &attachments,
Expand Down
2 changes: 2 additions & 0 deletions src/vulkan-renderer/wrapper/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Sampler::Sampler(const Device &device, const VkSamplerCreateInfo &sampler_ci, st
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateSampler failed for sampler " + m_name + " !", result);
}
// Set an internal debug name to this sampler using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_SAMPLER, reinterpret_cast<std::uint64_t>(m_sampler), m_name);
}

Sampler::Sampler(const Device &device, std::string name)
Expand Down
3 changes: 3 additions & 0 deletions src/vulkan-renderer/wrapper/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Semaphore::Semaphore(const Device &device, const std::string &name) : m_device(d
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateSemaphore failed for " + m_name + " !", result);
}
// Set an internal debug name to this semaphore using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_SEMAPHORE, reinterpret_cast<std::uint64_t>(m_semaphore),
m_name);
}

Semaphore::Semaphore(Semaphore &&other) noexcept : m_device(other.m_device) {
Expand Down
3 changes: 3 additions & 0 deletions src/vulkan-renderer/wrapper/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Shader::Shader(const Device &device, const VkShaderStageFlagBits type, const std
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateShaderModule failed for shader module " + name + "!", result);
}
// Set an internal debug name to this shader module using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast<std::uint64_t>(m_shader_module),
m_name);
}

Shader::Shader(Shader &&other) noexcept : m_device(other.m_device) {
Expand Down
4 changes: 4 additions & 0 deletions src/vulkan-renderer/wrapper/swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ void Swapchain::setup_swapchain(const std::uint32_t width, const std::uint32_t h
throw VulkanException("Error: vkCreateSwapchainKHR failed!", result);
}

// Set an internal debug name to this swapchain using Vulkan debug utils (VK_EXT_debug_utils)
m_device.set_debug_utils_object_name(VK_OBJECT_TYPE_SWAPCHAIN_KHR, reinterpret_cast<std::uint64_t>(m_swapchain),
"Swapchain");

// We need to destroy the old swapchain if specified
if (old_swapchain != VK_NULL_HANDLE) {
for (auto *const img_view : m_img_views) {
Expand Down

0 comments on commit 4039951

Please sign in to comment.