adding debug vulkan resources names

This commit is contained in:
2024-09-21 12:18:42 +02:00
parent 2e08c37624
commit 904b6d31ac
27 changed files with 306 additions and 104 deletions

View File

@@ -8,7 +8,7 @@
Error("invalid window ptr (NULL)"); \
return; \
} \
else if(std::find_if(m_graphics.begin(), m_graphics.end(), [win](const std::unique_ptr<GraphicsSupport>& gs){ return *static_cast<int*>(win) == gs->GetID(); }) != m_graphics.end()) \
else if(std::find_if(m_graphics.begin(), m_graphics.end(), [win](const std::unique_ptr<GraphicsSupport>& gs){ return *static_cast<int*>(win) == gs->GetID(); }) == m_graphics.end()) \
{ \
Error("invalid window ptr"); \
return; \

View File

@@ -39,10 +39,10 @@ namespace mlx
{
Sprite& new_sprite = p_scene->CreateSprite(texture);
new_sprite.SetPosition(Vec3f{ static_cast<float>(x), static_cast<float>(y), static_cast<float>(m_current_depth) });
m_current_depth++;
}
else
sprite->SetPosition(Vec3f{ static_cast<float>(x), static_cast<float>(y), static_cast<float>(m_current_depth) });
m_current_depth++;
}
void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale)

View File

@@ -20,12 +20,12 @@ namespace mlx
{
CPUBuffer vb(vertices.size() * sizeof(Vertex));
std::memcpy(vb.GetData(), vertices.data(), vb.GetSize());
vbo.Init(vb.GetSize());
vbo.Init(vb.GetSize(), 0, "mlx_mesh");
vbo.SetData(std::move(vb));
CPUBuffer ib(indices.size() * sizeof(std::uint32_t));
std::memcpy(ib.GetData(), indices.data(), ib.GetSize());
ibo.Init(ib.GetSize());
ibo.Init(ib.GetSize(), 0, "mlx_mesh");
ibo.SetData(std::move(ib));
triangle_count = vertices.size() / 3;

View File

@@ -12,7 +12,7 @@ namespace mlx
public:
GPUBuffer() = default;
void Init(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, CPUBuffer data);
void Init(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, CPUBuffer data, std::string_view debug_name);
void Destroy() noexcept;
bool CopyFrom(const GPUBuffer& buffer) noexcept;
@@ -33,6 +33,9 @@ namespace mlx
void PushToGPU() noexcept;
protected:
#ifdef DEBUG
std::string m_debug_name;
#endif
VkBuffer m_buffer = VK_NULL_HANDLE;
VmaAllocation m_allocation;
VkDeviceSize m_offset = 0;
@@ -40,7 +43,7 @@ namespace mlx
void* p_map = nullptr;
private:
void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VmaAllocationCreateInfo alloc_info);
void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VmaAllocationCreateInfo alloc_info, std::string_view debug_name);
private:
VkBufferUsageFlags m_usage = 0;
@@ -49,7 +52,7 @@ namespace mlx
class VertexBuffer : public GPUBuffer
{
public:
inline void Init(std::uint32_t size, VkBufferUsageFlags additional_flags = 0) { GPUBuffer::Init(BufferType::LowDynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | additional_flags, {}); }
inline void Init(std::uint32_t size, VkBufferUsageFlags additional_flags, std::string_view debug_name) { GPUBuffer::Init(BufferType::LowDynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | additional_flags, {}, std::move(debug_name)); }
void SetData(CPUBuffer data);
inline void Bind(VkCommandBuffer cmd) const noexcept { VkDeviceSize offset = 0; RenderCore::Get().vkCmdBindVertexBuffers(cmd, 0, 1, &m_buffer, &offset); }
};
@@ -57,7 +60,7 @@ namespace mlx
class IndexBuffer : public GPUBuffer
{
public:
inline void Init(std::uint32_t size, VkBufferUsageFlags additional_flags = 0) { GPUBuffer::Init(BufferType::LowDynamic, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_flags, {}); }
inline void Init(std::uint32_t size, VkBufferUsageFlags additional_flags, std::string_view debug_name) { GPUBuffer::Init(BufferType::LowDynamic, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_flags, {}, std::move(debug_name)); }
void SetData(CPUBuffer data);
inline void Bind(VkCommandBuffer cmd) const noexcept { RenderCore::Get().vkCmdBindIndexBuffer(cmd, m_buffer, 0, VK_INDEX_TYPE_UINT32); }
};
@@ -65,7 +68,7 @@ namespace mlx
class UniformBuffer
{
public:
void Init(std::uint32_t size);
void Init(std::uint32_t size, std::string_view debug_name);
void SetData(CPUBuffer data, std::size_t frame_index);
void Destroy() noexcept;

View File

@@ -14,16 +14,19 @@ namespace mlx
public:
Image() = default;
inline void Init(VkImage image, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept
inline void Init(VkImage image, VkFormat format, std::uint32_t width, std::uint32_t height, VkImageLayout layout, std::string_view debug_name) noexcept
{
m_image = image;
m_format = format;
m_width = width;
m_height = height;
m_layout = layout;
#ifdef DEBUG
m_debug_name = std::move(debug_name);
#endif
}
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled = false);
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled, std::string_view debug_name);
void CreateImageView(VkImageViewType type, VkImageAspectFlags aspectFlags, int layer_count = 1) noexcept;
void CreateSampler() noexcept;
void TransitionLayout(VkImageLayout new_layout, VkCommandBuffer cmd = VK_NULL_HANDLE);
@@ -48,6 +51,9 @@ namespace mlx
virtual ~Image() = default;
protected:
#ifdef DEBUG
std::string m_debug_name;
#endif
VmaAllocation m_allocation;
VkImage m_image = VK_NULL_HANDLE;
VkImageView m_image_view = VK_NULL_HANDLE;
@@ -65,11 +71,12 @@ namespace mlx
{
public:
DepthImage() = default;
inline void Init(std::uint32_t width, std::uint32_t height, bool is_multisampled = false)
inline void Init(std::uint32_t width, std::uint32_t height, bool is_multisampled, std::string_view debug_name)
{
MLX_PROFILE_FUNCTION();
std::vector<VkFormat> candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT };
VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, is_multisampled);
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, is_multisampled, std::move(debug_name));
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT);
Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
}
@@ -80,33 +87,12 @@ namespace mlx
{
public:
Texture() = default;
Texture(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format = VK_FORMAT_R8G8B8A8_SRGB, bool is_multisampled = false)
Texture(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, std::string_view debug_name)
{
Init(std::move(pixels), width, height, format, is_multisampled);
Init(std::move(pixels), width, height, format, is_multisampled, std::move(debug_name));
}
inline void Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format = VK_FORMAT_R8G8B8A8_SRGB, bool is_multisampled = false)
{
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
Image::CreateSampler();
if(pixels)
{
GPUBuffer staging_buffer;
std::size_t size = width * height * kvfFormatSize(format);
staging_buffer.Init(BufferType::Staging, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
kvfCopyBufferToImage(cmd, Image::Get(), staging_buffer.Get(), staging_buffer.GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { width, height, 1 });
RenderCore::Get().vkEndCommandBuffer(cmd);
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
staging_buffer.Destroy();
}
TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
void Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, std::string_view debug_name);
void SetPixel(int x, int y, std::uint32_t color) noexcept;
int GetPixel(int x, int y) noexcept;

View File

@@ -12,10 +12,10 @@ namespace mlx
void Destroy() noexcept;
VmaAllocation CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
void DestroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
void DestroyBuffer(VmaAllocation allocation, VkBuffer buffer, const char* name) noexcept;
VmaAllocation CreateImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
void DestroyImage(VmaAllocation allocation, VkImage image) noexcept;
void DestroyImage(VmaAllocation allocation, VkImage image, const char* name) noexcept;
void MapMemory(VmaAllocation allocation, void** data) noexcept;
void UnmapMemory(VmaAllocation allocation) noexcept;

View File

@@ -31,6 +31,12 @@ namespace mlx
#undef MLX_VULKAN_INSTANCE_FUNCTION
#undef MLX_VULKAN_DEVICE_FUNCTION
#if defined(DEBUG) && defined(VK_EXT_debug_utils)
inline static constexpr bool HAS_DEBUG_UTILS_FUNCTIONS = true;
#else
inline static constexpr bool HAS_DEBUG_UTILS_FUNCTIONS = false;
#endif
~RenderCore();
private:

View File

@@ -20,6 +20,12 @@
MLX_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceMemoryProperties)
MLX_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceProperties)
MLX_VULKAN_INSTANCE_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties)
#ifdef DEBUG
#ifdef VK_EXT_debug_utils
MLX_VULKAN_INSTANCE_FUNCTION(vkSetDebugUtilsObjectNameEXT)
//MLX_VULKAN_INSTANCE_FUNCTION(vkSetDebugUtilsObjectTagEXT)
#endif
#endif
#endif
#ifdef MLX_VULKAN_DEVICE_FUNCTION