summaryrefslogtreecommitdiff
path: root/include/resources
diff options
context:
space:
mode:
authorChuyan Zhang <chuyan@ucsb.edu>2024-10-10 18:51:05 -0700
committerChuyan Zhang <chuyan@ucsb.edu>2024-10-10 18:51:05 -0700
commit6271f5ce797bf12be64c710b66b1b9e93a239829 (patch)
tree44cc6a5ab5a20f7e55829f18b68a9f1191dac81d /include/resources
parentba27f3c22e79b91a2573b7efd00c5a3bbdb96dbc (diff)
downloadiris-main.tar.gz
iris-main.zip
move to new resource abstractionHEADmain
Diffstat (limited to 'include/resources')
-rw-r--r--include/resources/buffer.h37
-rw-r--r--include/resources/image.h71
2 files changed, 108 insertions, 0 deletions
diff --git a/include/resources/buffer.h b/include/resources/buffer.h
new file mode 100644
index 0000000..7c6fe0e
--- /dev/null
+++ b/include/resources/buffer.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <vk_mem_alloc.h>
+#include <vulkan/vulkan_core.h>
+namespace iris {
+
+struct BufferDesc {
+ uint64_t size;
+ std::optional<uint64_t> alignment;
+ VkBufferUsageFlags buffer_usage;
+ VmaMemoryUsage memory_usage;
+};
+
+struct Buffer_tt {
+ VkBuffer handle;
+ BufferDesc desc;
+
+ // Used during release
+ VkDevice device;
+ VmaAllocator allocator;
+ VmaAllocation allocation;
+ void release();
+
+ // Used during map/unmap
+ std::optional<void *> mapped_data;
+ void *map();
+ void unmap();
+
+ ~Buffer_tt() { release(); }
+};
+
+typedef std::shared_ptr<Buffer_tt> Buffer_s;
+
+} // namespace iris \ No newline at end of file
diff --git a/include/resources/image.h b/include/resources/image.h
new file mode 100644
index 0000000..391c023
--- /dev/null
+++ b/include/resources/image.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include <unordered_map>
+#include <vk_mem_alloc.h>
+#include <vulkan/vulkan_core.h>
+namespace iris {
+
+enum struct ImageType {
+ Texture1D,
+ Texture1DArray,
+ Texture2D,
+ Texture2DArray,
+ Texture3D,
+ TextureCube,
+ TextureCubeArray,
+};
+
+struct ImageDesc {
+ ImageType image_type;
+ VkImageUsageFlags image_usage;
+ VkImageCreateFlags create_flags;
+ VmaAllocationCreateFlags alloc_flags;
+
+ VkFormat format;
+ VkExtent3D extent;
+ uint32_t mip_levels;
+ uint32_t array_layers;
+};
+
+struct ImageViewDesc {
+ VkImageViewType view_type;
+ VkFormat format;
+ VkImageAspectFlags aspect_mask;
+ uint32_t base_mip_level;
+ uint32_t mip_levels;
+ uint32_t base_array_layer;
+ uint32_t array_layers;
+
+ bool operator==(const ImageViewDesc& other) const = default;
+};
+
+struct ImageViewDescHash {
+ std::size_t operator()(const ImageViewDesc& desc) const noexcept {
+ auto h = std::hash<int>{}(desc.view_type);
+ h ^= std::hash<int>{}(desc.format) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ h ^= std::hash<int>{}(desc.aspect_mask) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ h ^= std::hash<int>{}(desc.base_mip_level) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ h ^= std::hash<int>{}(desc.mip_levels) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ h ^= std::hash<int>{}(desc.base_array_layer) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ h ^= std::hash<int>{}(desc.array_layers) + 0x9e3779b9 + (h << 6) + (h >> 2);
+ return h;
+ }
+};
+
+struct Image_tt {
+ VkImage handle;
+ ImageDesc desc;
+
+ // Used during release
+ VkDevice device;
+ VmaAllocator allocator;
+ VmaAllocation allocation;
+
+ // store all the image views
+ std::unordered_map<ImageViewDesc, VkImageView, ImageViewDescHash> image_views;
+ VkImageView get_image_view(const ImageViewDesc &desc);
+
+ void release();
+};
+
+} // namespace iris \ No newline at end of file