summaryrefslogtreecommitdiff
path: root/src/vulkan_helper.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vulkan_helper.h')
-rw-r--r--src/vulkan_helper.h39
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