summaryrefslogtreecommitdiff
path: root/src/vulkan_helper.h
diff options
context:
space:
mode:
authorChuyan Zhang <chuyan@ucsb.edu>2024-10-01 17:08:41 -0700
committerChuyan Zhang <chuyan@ucsb.edu>2024-10-01 17:08:41 -0700
commit6185c081c1a6ec13b54eab6a12ff72814cf3addb (patch)
tree49d5461e95a9894069bb04c492c2079789636d3f /src/vulkan_helper.h
parente5eed5bdfa01cf549436c6001eaf334d266acc40 (diff)
downloadiris-6185c081c1a6ec13b54eab6a12ff72814cf3addb.tar.gz
iris-6185c081c1a6ec13b54eab6a12ff72814cf3addb.zip
Fix vulkan validation error
Diffstat (limited to 'src/vulkan_helper.h')
-rw-r--r--src/vulkan_helper.h26
1 files changed, 9 insertions, 17 deletions
diff --git a/src/vulkan_helper.h b/src/vulkan_helper.h
index c2b1c8c..d8c9c32 100644
--- a/src/vulkan_helper.h
+++ b/src/vulkan_helper.h
@@ -2,6 +2,7 @@
#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 +12,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 +21,7 @@ namespace iris {
struct Buffer_t {
VkBuffer buffer;
+ VkDevice device;
VmaAllocator allocator;
VmaAllocation allocation;
VkBufferUsageFlags flags;
@@ -30,12 +31,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 +48,7 @@ struct Texture2D_t {
VkExtent2D extent;
void release();
+ ~Texture2D_t() { release(); }
};
typedef std::shared_ptr<Texture2D_t> Texture2D;
@@ -62,16 +66,19 @@ struct CommandBuffer {
void destroy();
void begin(VkCommandBufferUsageFlags flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
void submit_sync();
+ ~CommandBuffer() { destroy(); }
};
struct AsyncCommandBuffer {
VkDevice device;
VkCommandPool pool;
VkCommandBuffer buffer;
+ VkFence fence;
VkQueue queue;
AsyncCommandBuffer(VkDevice device, uint32_t queue_family_index, VkQueue queue);
void destroy();
+ ~AsyncCommandBuffer() { destroy(); }
};
struct Device {
@@ -92,21 +99,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,