diff options
author | Leon Kang <2090093273@qq.com> | 2024-10-03 21:04:37 -0700 |
---|---|---|
committer | Leon Kang <2090093273@qq.com> | 2024-10-03 21:04:37 -0700 |
commit | 1f47c662a07ec83d4033b1a5f4b48dd8dfa58b7b (patch) | |
tree | cfb8941b80d1bc672bf25dba3ca716a1e0bc0823 /src/vulkan_helper.h | |
parent | c1ceb18d1c6d8af1266fc9cb9233e2328dd4d723 (diff) | |
parent | e59529d3f55b9128f798a7f02a7288f96bdaf9a4 (diff) | |
download | iris-1f47c662a07ec83d4033b1a5f4b48dd8dfa58b7b.tar.gz iris-1f47c662a07ec83d4033b1a5f4b48dd8dfa58b7b.zip |
Merge branch 'main' into windows-build
Diffstat (limited to 'src/vulkan_helper.h')
-rw-r--r-- | src/vulkan_helper.h | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/vulkan_helper.h b/src/vulkan_helper.h index c2b1c8c..04fcead 100644 --- a/src/vulkan_helper.h +++ b/src/vulkan_helper.h @@ -1,7 +1,10 @@ +#pragma once + #include <memory> #include <vulkan/vulkan_core.h> #include <vulkan/vk_enum_string_helper.h> #include <vk_mem_alloc.h> +#include <spdlog/spdlog.h> #include <cstdint> #include <vector> @@ -11,8 +14,7 @@ do { \ VkResult res = result; \ if (res != VK_SUCCESS) { \ - /* TODO: throw error instead of returning */ \ - std::cerr << "Vulkan error: " << string_VkResult(res) << std::endl; \ + spdlog::error("Vulkan error: {}", string_VkResult(res)); \ abort(); \ } \ } while (0) @@ -21,6 +23,7 @@ namespace iris { struct Buffer_t { VkBuffer buffer; + VkDevice device; VmaAllocator allocator; VmaAllocation allocation; VkBufferUsageFlags flags; @@ -30,12 +33,14 @@ struct Buffer_t { void* map(); void unmap(); void release(); + ~Buffer_t() { release(); } }; typedef std::shared_ptr<Buffer_t> Buffer; struct Texture2D_t { VkImage image; + VkDevice device; VmaAllocator allocator; VmaAllocation allocation; VkImageView image_view; @@ -45,6 +50,7 @@ struct Texture2D_t { VkExtent2D extent; void release(); + ~Texture2D_t() { release(); } }; typedef std::shared_ptr<Texture2D_t> Texture2D; @@ -59,19 +65,10 @@ struct CommandBuffer { VkQueue queue; CommandBuffer(VkDevice device, uint32_t queue_family_index, VkQueue queue); - void destroy(); + void release(); void begin(VkCommandBufferUsageFlags flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); void submit_sync(); -}; - -struct AsyncCommandBuffer { - VkDevice device; - VkCommandPool pool; - VkCommandBuffer buffer; - VkQueue queue; - - AsyncCommandBuffer(VkDevice device, uint32_t queue_family_index, VkQueue queue); - void destroy(); + ~CommandBuffer() { release(); } }; struct Device { @@ -92,21 +89,6 @@ struct Device { std::vector<std::string> instance_extensions); void destroy(); - Buffer_t create_buffer_raw( - VkDeviceSize size, - VkBufferUsageFlags usage, - VmaAllocationCreateInfo create_info = { - .usage = VMA_MEMORY_USAGE_AUTO, - }); - - Texture2D_t create_texture_raw( - VkExtent2D extent, - VkFormat format, - VkImageUsageFlags usage, - VmaAllocationCreateInfo create_info = { - .usage = VMA_MEMORY_USAGE_AUTO, - }); - Buffer create_buffer( VkDeviceSize size, VkBufferUsageFlags usage, @@ -131,7 +113,6 @@ struct Device { }); CommandBuffer create_command_buffer(); - AsyncCommandBuffer create_async_command_buffer(); }; } // namespace iris
\ No newline at end of file |