Renderer: Implement and use debug names

This commit is contained in:
SirLynix
2022-12-02 22:46:43 +01:00
parent 54aafe05a1
commit 77642cf431
74 changed files with 290 additions and 38 deletions

View File

@@ -33,6 +33,8 @@ namespace Nz
void* Map(UInt64 offset, UInt64 size) override;
bool Unmap() override;
void UpdateDebugName(std::string_view name) override;
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
VulkanBuffer& operator=(VulkanBuffer&&) = delete; ///TODO

View File

@@ -30,6 +30,8 @@ namespace Nz
inline std::size_t GetPoolIndex() const;
inline const VulkanCommandPool& GetOwner() const;
void UpdateDebugName(std::string_view name) override;
VulkanCommandBuffer& operator=(const VulkanCommandBuffer&) = delete;
VulkanCommandBuffer& operator=(VulkanCommandBuffer&&) = delete;

View File

@@ -30,6 +30,8 @@ namespace Nz
CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
void UpdateDebugName(std::string_view name) override;
VulkanCommandPool& operator=(const VulkanCommandPool&) = delete;
VulkanCommandPool& operator=(VulkanCommandPool&&) = delete;

View File

@@ -19,7 +19,10 @@ namespace Nz
public:
using Framebuffer::Framebuffer;
virtual Vk::Framebuffer& GetFramebuffer() = 0;
virtual const Vk::Framebuffer& GetFramebuffer() const = 0;
void UpdateDebugName(std::string_view name) override;
};
}

View File

@@ -27,6 +27,8 @@ namespace Nz
inline Vk::RenderPass& GetRenderPass();
inline const Vk::RenderPass& GetRenderPass() const;
void UpdateDebugName(std::string_view name) override;
VulkanRenderPass& operator=(const VulkanRenderPass&) = delete;
VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = default;

View File

@@ -15,6 +15,7 @@
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Pipeline.hpp>
#include <Nazara/Utils/MovablePtr.hpp>
#include <string>
#include <vector>
namespace Nz
@@ -35,6 +36,8 @@ namespace Nz
inline const RenderPipelineInfo& GetPipelineInfo() const override;
void UpdateDebugName(std::string_view name) override;
VulkanRenderPipeline& operator=(const VulkanRenderPipeline&) = delete;
VulkanRenderPipeline& operator=(VulkanRenderPipeline&&) = delete;
@@ -93,6 +96,7 @@ namespace Nz
Vk::Pipeline pipeline;
};
std::string m_debugName;
mutable std::unordered_map<std::pair<VkRenderPass, std::size_t>, PipelineData, PipelineHasher> m_pipelines;
MovablePtr<Vk::Device> m_device;
mutable CreateInfo m_pipelineCreateInfo;

View File

@@ -39,6 +39,8 @@ namespace Nz
inline const Vk::PipelineLayout& GetPipelineLayout() const;
void UpdateDebugName(std::string_view name) override;
private:
struct DescriptorPool;

View File

@@ -30,6 +30,8 @@ namespace Nz
void Update(const Binding* bindings, std::size_t bindingCount) override;
void UpdateDebugName(std::string_view name) override;
VulkanShaderBinding& operator=(const VulkanShaderBinding&) = delete;
VulkanShaderBinding& operator=(VulkanShaderBinding&&) = delete;

View File

@@ -28,6 +28,8 @@ namespace Nz
inline const Vk::ShaderModule& GetHandle() const;
inline const std::vector<Stage>& GetStages() const;
void UpdateDebugName(std::string_view name) override;
struct Stage
{
nzsl::ShaderStageType stage;

View File

@@ -35,6 +35,8 @@ namespace Nz
using Texture::Update;
bool Update(const void* ptr, const Boxui& box, unsigned int srcWidth, unsigned int srcHeight, UInt8 level) override;
void UpdateDebugName(std::string_view name) override;
VulkanTexture& operator=(const VulkanTexture&) = delete;
VulkanTexture& operator=(VulkanTexture&&) = delete;

View File

@@ -23,6 +23,7 @@ namespace Nz
VulkanTextureFramebuffer(VulkanTextureFramebuffer&&) = delete;
~VulkanTextureFramebuffer() = default;
inline Vk::Framebuffer& GetFramebuffer() override;
inline const Vk::Framebuffer& GetFramebuffer() const override;
VulkanTextureFramebuffer& operator=(const VulkanTextureFramebuffer&) = delete;

View File

@@ -7,6 +7,11 @@
namespace Nz
{
inline Vk::Framebuffer& VulkanTextureFramebuffer::GetFramebuffer()
{
return m_framebuffer;
}
inline const Vk::Framebuffer& VulkanTextureFramebuffer::GetFramebuffer() const
{
return m_framebuffer;

View File

@@ -25,6 +25,8 @@ namespace Nz
inline VkSampler GetSampler() const;
void UpdateDebugName(std::string_view name) override;
VulkanTextureSampler& operator=(const VulkanTextureSampler&) = delete;
VulkanTextureSampler& operator=(VulkanTextureSampler&&) = delete;

View File

@@ -20,6 +20,7 @@ namespace Nz
VulkanWindowFramebuffer(VulkanWindowFramebuffer&&) noexcept = default;
~VulkanWindowFramebuffer() = default;
inline Vk::Framebuffer& GetFramebuffer() override;
inline const Vk::Framebuffer& GetFramebuffer() const override;
VulkanWindowFramebuffer& operator=(const VulkanWindowFramebuffer&) = delete;

View File

@@ -13,7 +13,12 @@ namespace Nz
{
}
inline const Vk::Framebuffer& Nz::VulkanWindowFramebuffer::GetFramebuffer() const
inline Vk::Framebuffer& VulkanWindowFramebuffer::GetFramebuffer()
{
return m_framebuffer;
}
inline const Vk::Framebuffer& VulkanWindowFramebuffer::GetFramebuffer() const
{
return m_framebuffer;
}

View File

@@ -77,6 +77,7 @@ namespace Nz
inline void Free();
inline VkResult GetLastErrorCode() const;
inline CommandPool& GetPool();
inline void ImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout, VkImage image, VkImageAspectFlags aspectFlags);
@@ -104,8 +105,6 @@ namespace Nz
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout);
inline void SetImageLayout(VkImage image, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageLayout oldImageLayout, VkImageLayout newImageLayout, const VkImageSubresourceRange& subresourceRange);
inline VkResult GetLastErrorCode() const;
CommandBuffer& operator=(const CommandBuffer&) = delete;
CommandBuffer& operator=(CommandBuffer&& commandBuffer) noexcept;

View File

@@ -345,6 +345,11 @@ namespace Nz
}
}
inline VkResult CommandBuffer::GetLastErrorCode() const
{
return m_lastErrorCode;
}
inline CommandPool& CommandBuffer::GetPool()
{
return *m_pool;
@@ -586,11 +591,6 @@ namespace Nz
return m_pool->GetDevice()->vkCmdSetViewport(m_handle, firstViewport, viewportCount, viewports);
}
inline VkResult CommandBuffer::GetLastErrorCode() const
{
return m_lastErrorCode;
}
inline CommandBuffer& CommandBuffer::operator=(CommandBuffer&& commandBuffer) noexcept
{
m_lastErrorCode = commandBuffer.m_lastErrorCode;

View File

@@ -64,6 +64,10 @@ namespace Nz
inline bool IsExtensionLoaded(const std::string& extensionName);
inline bool IsLayerLoaded(const std::string& layerName);
inline void SetDebugName(VkObjectType objectType, UInt64 objectHandle, const char* name);
inline void SetDebugName(VkObjectType objectType, UInt64 objectHandle, std::string_view name);
inline void SetDebugName(VkObjectType objectType, UInt64 objectHandle, const std::string& name);
inline bool WaitForIdle();
Device& operator=(const Device&) = delete;

View File

@@ -5,6 +5,7 @@
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/VulkanRenderer/Wrapper/Instance.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
@@ -87,6 +88,40 @@ namespace Nz::Vk
return m_loadedLayers.count(layerName) > 0;
}
inline void Device::SetDebugName(VkObjectType objectType, UInt64 objectHandle, const char* name)
{
if (vkSetDebugUtilsObjectNameEXT)
{
VkDebugUtilsObjectNameInfoEXT debugName = {
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
nullptr,
objectType,
objectHandle,
name
};
vkSetDebugUtilsObjectNameEXT(m_device, &debugName);
}
}
inline void Device::SetDebugName(VkObjectType objectType, UInt64 objectHandle, std::string_view name)
{
if (vkSetDebugUtilsObjectNameEXT)
{
// Ensure \0 at the end of string
StackArray<char> nullTerminatedName = NazaraStackArrayNoInit(char, name.size() + 1);
std::memcpy(nullTerminatedName.data(), name.data(), name.size());
nullTerminatedName[name.size()] = '\0';
return SetDebugName(objectType, objectHandle, nullTerminatedName.data());
}
}
inline void Device::SetDebugName(VkObjectType objectType, UInt64 objectHandle, const std::string& name)
{
return SetDebugName(objectType, objectHandle, name.data());
}
inline bool Device::WaitForIdle()
{
m_lastErrorCode = vkDeviceWaitIdle(m_device);

View File

@@ -32,8 +32,7 @@ namespace Nz::Vk
Device* GetDevice() const;
VkResult GetLastErrorCode() const;
void SetDebugName(const char* name);
void SetDebugName(const std::string& name);
template<typename T> void SetDebugName(T&& name);
DeviceObject& operator=(const DeviceObject&) = delete;
DeviceObject& operator=(DeviceObject&& object) noexcept;

View File

@@ -83,31 +83,16 @@ namespace Nz::Vk
}
template<typename C, typename VkType, typename CreateInfo, VkObjectType ObjectType>
void DeviceObject<C, VkType, CreateInfo, ObjectType>::SetDebugName(const char* name)
template<typename T>
void DeviceObject<C, VkType, CreateInfo, ObjectType>::SetDebugName(T&& name)
{
if (m_device->vkSetDebugUtilsObjectNameEXT)
{
VkDebugUtilsObjectNameInfoEXT debugName = {
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
nullptr,
ObjectType,
0,
name
};
UInt64 objectHandle;
if constexpr (std::is_pointer_v<VkType>)
objectHandle = static_cast<UInt64>(reinterpret_cast<std::uintptr_t>(m_handle));
else
objectHandle = static_cast<UInt64>(m_handle);
if constexpr (std::is_pointer_v<VkType>)
debugName.objectHandle = static_cast<UInt64>(reinterpret_cast<std::uintptr_t>(m_handle));
else
debugName.objectHandle = static_cast<UInt64>(m_handle);
m_device->vkSetDebugUtilsObjectNameEXT(*m_device, &debugName);
}
}
template<typename C, typename VkType, typename CreateInfo, VkObjectType ObjectType>
void DeviceObject<C, VkType, CreateInfo, ObjectType>::SetDebugName(const std::string& name)
{
return SetDebugName(name.data());
return m_device->SetDebugName(ObjectType, objectHandle, std::forward<T>(name));
}
template<typename C, typename VkType, typename CreateInfo, VkObjectType ObjectType>

View File

@@ -9,6 +9,7 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
#include <string_view>
namespace Nz
{
@@ -29,6 +30,8 @@ namespace Nz
inline Device& GetDevice() const;
inline VkResult GetLastErrorCode() const;
inline void SetDebugName(std::string_view name);
Pipeline& operator=(const Pipeline&) = delete;
Pipeline& operator=(Pipeline&&) = delete;

View File

@@ -4,6 +4,7 @@
#include <Nazara/VulkanRenderer/Wrapper/Pipeline.hpp>
#include <Nazara/VulkanRenderer/Utils.hpp>
#include <Nazara/Utils/StackArray.hpp>
#include <Nazara/VulkanRenderer/Debug.hpp>
namespace Nz
@@ -58,6 +59,11 @@ namespace Nz
return m_lastErrorCode;
}
inline void Pipeline::SetDebugName(std::string_view name)
{
return m_device->SetDebugName(VK_OBJECT_TYPE_PIPELINE, static_cast<UInt64>(reinterpret_cast<std::uintptr_t>(m_handle)), name);
}
inline Pipeline::operator VkPipeline() const
{
return m_handle;