summaryrefslogtreecommitdiff
path: root/src/vulkan_helper.h
diff options
context:
space:
mode:
authorChuyan Zhang <me@zcy.moe>2024-09-09 00:30:29 -0700
committerChuyan Zhang <me@zcy.moe>2024-09-09 00:30:29 -0700
commit7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3 (patch)
treed9ad5dbb2871e3999480e55ffa24bea6e50f8dd4 /src/vulkan_helper.h
parent2ead02037dc89e987fbc0a021fe470e29d226cfd (diff)
downloadiris-7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3.tar.gz
iris-7f14138e1baa2c40fb30d90ebcd45ad17b12e0a3.zip
Fixing swapchain
Diffstat (limited to 'src/vulkan_helper.h')
-rw-r--r--src/vulkan_helper.h76
1 files changed, 65 insertions, 11 deletions
diff --git a/src/vulkan_helper.h b/src/vulkan_helper.h
index b6f270a..ebdd691 100644
--- a/src/vulkan_helper.h
+++ b/src/vulkan_helper.h
@@ -1,19 +1,20 @@
#include <memory>
#include <vulkan/vulkan_core.h>
+#include <vulkan/vk_enum_string_helper.h>
#include <vk_mem_alloc.h>
#include <cstdint>
#include <vector>
#include <string>
-#define CHECK_VULKAN(result) \
- do { \
- VkResult res = result; \
- if (res != VK_SUCCESS) { \
- /* TODO: throw error instead of returning */ \
- std::cerr << "Vulkan error: " << res << std::endl; \
- abort(); \
- } \
+#define CHECK_VULKAN(result) \
+ do { \
+ VkResult res = result; \
+ if (res != VK_SUCCESS) { \
+ /* TODO: throw error instead of returning */ \
+ std::cerr << "Vulkan error: " << string_VkResult(res) << std::endl; \
+ abort(); \
+ } \
} while (0)
namespace iris {
@@ -25,8 +26,11 @@ struct Buffer_t {
VkBufferUsageFlags flags;
VkDeviceSize size;
+ void *mapped_data = nullptr;
~Buffer_t();
+ void* map();
+ void unmap();
};
typedef std::shared_ptr<Buffer_t> Buffer;
@@ -36,6 +40,7 @@ struct Texture2D_t {
VmaAllocator allocator;
VmaAllocation allocation;
VkImageView image_view;
+ VkImageLayout layout;
VkImageUsageFlags flags;
VkExtent2D extent;
@@ -45,6 +50,22 @@ struct Texture2D_t {
typedef std::shared_ptr<Texture2D_t> Texture2D;
+// This is a really brute-force implementation,
+// every command pool contains only 1 command buffer
+struct CommandBuffer {
+ VkDevice device;
+ VkCommandPool pool;
+ VkCommandBuffer buffer;
+ VkFence fence;
+ VkQueue queue;
+
+ CommandBuffer(VkDevice device, uint32_t queue_family_index, VkQueue queue);
+ ~CommandBuffer();
+
+ void begin(VkCommandBufferUsageFlags flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
+ void submit_sync();
+};
+
struct Device {
VkInstance instance;
VkPhysicalDevice physical_device;
@@ -52,22 +73,55 @@ struct Device {
uint32_t main_queue_family_index;
VkQueue graphics_queue;
VmaAllocator allocator;
+#ifdef USE_VULKAN_VALIDATION_LAYERS
+ VkDebugReportCallbackEXT debugReportCallback;
+#endif
+ Device() = delete;
Device(
std::vector<std::string> layers,
std::vector<std::string> instance_extensions);
- ~Device();
+ 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,
- VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_AUTO);
+ VmaAllocationCreateInfo create_info = {
+ .usage = VMA_MEMORY_USAGE_AUTO,
+ });
Texture2D create_texture(
VkExtent2D extent,
VkFormat format,
VkImageUsageFlags usage,
- VmaMemoryUsage memory_usage = VMA_MEMORY_USAGE_AUTO);
+ VmaAllocationCreateInfo create_info = {
+ .usage = VMA_MEMORY_USAGE_AUTO,
+ });
+
+ Texture2D create_texture_from_image(
+ const char* filename,
+ VkFormat format,
+ VkImageUsageFlags usage,
+ VmaAllocationCreateInfo create_info = {
+ .usage = VMA_MEMORY_USAGE_AUTO,
+ });
+
+ CommandBuffer create_command_buffer();
};
} // namespace iris \ No newline at end of file