From 705d16cd4e5f00c398623cb5e7060d439962ddc0 Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Sun, 21 Jan 2024 11:02:00 +0100 Subject: [PATCH] Allow named vulkan allocations --- client/vk/allocation.cpp | 11 ++++++----- client/vk/allocation.h | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/vk/allocation.cpp b/client/vk/allocation.cpp index 385b1b07..96d22ceb 100644 --- a/client/vk/allocation.cpp +++ b/client/vk/allocation.cpp @@ -20,7 +20,6 @@ #include "allocation.h" #include "application.h" -#include "spdlog/spdlog.h" #include "utils/check.h" #include "vulkan/vulkan_raii.hpp" @@ -29,14 +28,15 @@ std::pair basic_allocation_traits::create( const CreateInfo& buffer_info, - const VmaAllocationCreateInfo* alloc_info) + const VmaAllocationCreateInfo& alloc_info) { VmaAllocator allocator = application::get_allocator(); vk::raii::Device& device = application::get_device(); VmaAllocation allocation; VkBuffer tmp; - CHECK_VK(vmaCreateBuffer(allocator, &(NativeCreateInfo&)buffer_info, alloc_info, &tmp, &allocation, nullptr)); + + CHECK_VK(vmaCreateBuffer(allocator, &(NativeCreateInfo&)buffer_info, &alloc_info, &tmp, &allocation, nullptr)); return std::pair{vk::raii::Buffer{device, tmp}, allocation}; @@ -73,14 +73,15 @@ void basic_allocation_traits_base::unmap(VmaAllocation allocation) std::pair basic_allocation_traits::create( const CreateInfo& image_info, - const VmaAllocationCreateInfo* alloc_info) + const VmaAllocationCreateInfo& alloc_info) { VmaAllocator allocator = application::get_allocator(); vk::raii::Device& device = application::get_device(); VmaAllocation allocation; VkImage tmp; - CHECK_VK(vmaCreateImage(allocator, &(NativeCreateInfo&)image_info, alloc_info, &tmp, &allocation, nullptr)); + + CHECK_VK(vmaCreateImage(allocator, &(NativeCreateInfo&)image_info, &alloc_info, &tmp, &allocation, nullptr)); return std::pair{vk::raii::Image{device, tmp}, allocation}; } diff --git a/client/vk/allocation.h b/client/vk/allocation.h index 53ca6c66..5e0ecebc 100644 --- a/client/vk/allocation.h +++ b/client/vk/allocation.h @@ -21,6 +21,7 @@ #include "vk_mem_alloc.h" #include +#include "application.h" template struct basic_allocation_traits @@ -42,7 +43,7 @@ struct basic_allocation_traits : basic_allocation_traits_base static std::pair create( const CreateInfo& buffer_info, - const VmaAllocationCreateInfo* alloc_info); + const VmaAllocationCreateInfo& alloc_info); static void destroy( RaiiType& buffer, @@ -59,7 +60,7 @@ struct basic_allocation_traits : basic_allocation_traits_base static std::pair create( const CreateInfo& image_info, - const VmaAllocationCreateInfo* alloc_info); + const VmaAllocationCreateInfo& alloc_info); static void destroy( RaiiType& image, @@ -118,7 +119,15 @@ public: basic_allocation(const CreateInfo& create_info, const VmaAllocationCreateInfo& alloc_info) : create_info(create_info) { - std::tie(resource, allocation) = traits::create(create_info, &alloc_info); + std::tie(resource, allocation) = traits::create(create_info, alloc_info); + } + + basic_allocation(const CreateInfo& create_info, VmaAllocationCreateInfo alloc_info, const std::string& name) : + create_info(create_info) + { + std::tie(resource, allocation) = traits::create(create_info, alloc_info); + + vmaSetAllocationName(application::get_allocator(), allocation, name.c_str()); } basic_allocation(const basic_allocation&) = delete;