aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-10-27 23:22:55 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-10-27 23:22:55 +0200
commitb47e177898657e435cb5bc913a4a783fddbe1f3d (patch)
treedf0a042b5ed9e98d7653462466dd3c6147127bc3 /include
parentcee4f9c528a91691d94c52ec1849f3ad1245b081 (diff)
Api prototype
Diffstat (limited to 'include')
-rw-r--r--include/api-test/buffer.hpp25
-rw-r--r--include/api-test/freelist.hpp32
-rw-r--r--include/api-test/handle.hpp8
-rw-r--r--include/api-test/resource-manager.hpp22
-rw-r--r--include/api-test/texture.hpp29
-rw-r--r--include/api-test/vk-command-buffer.hpp14
-rw-r--r--include/api-test/vk-device.hpp128
-rw-r--r--include/resource-manager.hpp6
-rw-r--r--include/window.hpp2
9 files changed, 265 insertions, 1 deletions
diff --git a/include/api-test/buffer.hpp b/include/api-test/buffer.hpp
new file mode 100644
index 0000000..500e15b
--- /dev/null
+++ b/include/api-test/buffer.hpp
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <cstdint>
+
+#include <vulkan/vulkan_core.h>
+
+#include "handle.hpp"
+
+struct buffer_desc {
+ size_t size;
+ VkBufferUsageFlags usages;
+ VkMemoryPropertyFlags memory_properties;
+ uint32_t memory_usage;
+};
+
+struct device_buffer;
+
+class buffer {
+public:
+ buffer(handle<device_buffer> handle);
+
+private:
+ handle<device_buffer> handle;
+
+};
diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp
new file mode 100644
index 0000000..e5af6f5
--- /dev/null
+++ b/include/api-test/freelist.hpp
@@ -0,0 +1,32 @@
+#include <numeric>
+#include <vector>
+
+template<typename T, const size_t initial_size = 1024U>
+class freelist {
+ public:
+ freelist()
+ : holes(initial_size),
+ items(initial_size) {
+ std::iota(holes.begin(), holes.end(), 0);
+ }
+
+ uint32_t add(const T& item) {
+ const auto id = holes.back();
+ holes.pop_back();
+
+ items[id] = std::move(item);
+
+ return id;
+ }
+
+ void remove(uint32_t item_id) {
+ holes.push_back(item_id);
+ }
+
+ const T& operator[](uint32_t index) {
+ return items[index];
+ }
+
+ std::vector<T> items;
+ std::vector<uint32_t> holes;
+};
diff --git a/include/api-test/handle.hpp b/include/api-test/handle.hpp
new file mode 100644
index 0000000..90c1ade
--- /dev/null
+++ b/include/api-test/handle.hpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <cstdint>
+
+template<typename T>
+struct handle {
+ const uint32_t handle;
+};
diff --git a/include/api-test/resource-manager.hpp b/include/api-test/resource-manager.hpp
new file mode 100644
index 0000000..f414367
--- /dev/null
+++ b/include/api-test/resource-manager.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "handle.hpp"
+#include "freelist.hpp"
+#include "texture.hpp"
+#include "buffer.hpp"
+
+class resourcemanager {
+public:
+
+ handle<texture> create_texture(const texture_desc& desc);
+
+ handle<buffer> create_buffer(const buffer_desc& desc);
+
+ const texture& get_texture(handle<texture> handle);
+
+ const buffer& get_buffer(handle<buffer> handle);
+
+private:
+ freelist<texture> textures;
+ freelist<buffer> buffers;
+};
diff --git a/include/api-test/texture.hpp b/include/api-test/texture.hpp
new file mode 100644
index 0000000..9632c5e
--- /dev/null
+++ b/include/api-test/texture.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <cstdint>
+
+#include <vulkan/vulkan_core.h>
+
+#include "handle.hpp"
+
+struct texture_desc {
+ uint32_t width = 1U;
+ uint32_t height = 1U;
+ uint32_t depth = 1U;
+ uint32_t mips = 1U;
+ VkImageUsageFlags usages;
+ VkFormat format;
+ VkImageType type;
+
+ static constexpr auto max_mips = 16U;
+};
+
+struct device_texture;
+
+class texture {
+public:
+ texture(handle<device_texture> handle);
+
+private:
+ handle<device_texture> handle;
+};
diff --git a/include/api-test/vk-command-buffer.hpp b/include/api-test/vk-command-buffer.hpp
new file mode 100644
index 0000000..c1f1899
--- /dev/null
+++ b/include/api-test/vk-command-buffer.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <vulkan/vulkan_core.h>
+
+class command_buffer {
+ void start();
+ void stop();
+
+ VkCommandBuffer handle;
+};
+
+class graphics_command_buffer : command_buffer {
+
+};
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp
new file mode 100644
index 0000000..f931c70
--- /dev/null
+++ b/include/api-test/vk-device.hpp
@@ -0,0 +1,128 @@
+#pragma once
+
+#include <cstdint>
+
+#include <vulkan/vulkan_core.h>
+
+#include "handle.hpp"
+#include "freelist.hpp"
+#include "texture.hpp"
+#include "buffer.hpp"
+
+using VmaAllocator = struct VmaAllocator_T*;
+using VmaAllocation = struct VmaAllocation_T*;
+
+// typedef struct VkInstance_T* VkInstance;
+// typedef struct VkDevice_T* VkDevice;
+// typedef struct VkPhysicalDevice_T* VkPhysicalDevice;
+// typedef struct VkQueue_T* VkQueue;
+// typedef uint32_t VkFlags;
+// typedef VkFlags VkQueueUsageFlags;
+// typedef struct VkImage_T* VkImage;
+// typedef struct VkImageView_T* VkImageView;
+// typedef struct VkBuffer_T* VkBuffer;
+// typedef enum VkImageType VkImageType;
+// typedef enum VkFormat VkFormat;
+// typedef VkFlags VkImageUsageFlags;
+//
+// #ifdef _DEBUG
+// typedef struct VkDebugUtilsMessengerEXT_T* VkDebugUtilsMessengerEXT;
+// #endif // _DEBUG
+
+
+struct device_texture {
+ VkImage handle;
+ VkImageView whole_view;
+ VkImageView mips_views[texture_desc::max_mips] = { VK_NULL_HANDLE };
+ VmaAllocation alloc;
+
+ texture_desc desc;
+};
+
+struct device_buffer {
+ VkBuffer handle;
+ VmaAllocation alloc;
+ VkDeviceAddress device_address;
+ void* mapped_ptr;
+
+ buffer_desc desc;
+};
+
+class window;
+
+class vkdevice {
+public:
+
+ vkdevice(const window& window);
+
+ handle<device_texture> create_texture(const texture_desc& desc);
+
+ handle<device_buffer> create_buffer(const buffer_desc& desc);
+
+ const device_texture& get_texture(handle<device_texture> handle) {
+ return textures[handle.handle];
+ }
+
+ const device_buffer& get_buffer(handle<device_buffer> handle) {
+ return buffers[handle.handle];
+ }
+
+ void submit(/*std::span<command_buffer>*/);
+
+private:
+
+ void create_views(device_texture& texture);
+
+ void create_surface(const window& window);
+
+ void create_swapchain();
+
+ VkSurfaceKHR surface;
+ VkSwapchainKHR swapchain;
+
+ // TODO: Wrap in a struct called adapter ?
+ void create_instance();
+
+ void create_device();
+
+ void create_memory_allocator();
+
+ void create_command_pools();
+
+ void pick_physical_device();
+
+ [[nodiscard]] uint32_t pick_queue(VkQueueFlags usages) const;
+
+ static bool device_support_features(VkPhysicalDevice physical_dev);
+
+ void create_debug_layer_callback();
+
+
+ enum QueueTypes : uint32_t {
+ GRAPHICS,
+ // COPY,
+ MAX,
+ };
+
+ struct queue {
+ VkQueue handle;
+ uint32_t index;
+ VkQueueFlags usages;
+ VkCommandPool command_pool;
+ };
+
+ queue queues[QueueTypes::MAX];
+
+ VkInstance instance;
+ VkPhysicalDevice physical_device;
+ VkDevice device;
+
+ VmaAllocator gpu_allocator;
+
+#ifdef _DEBUG
+ VkDebugUtilsMessengerEXT debug_messenger;
+#endif // _DEBUG
+
+ freelist<device_texture> textures;
+ freelist<device_buffer> buffers;
+};
diff --git a/include/resource-manager.hpp b/include/resource-manager.hpp
new file mode 100644
index 0000000..2a8a787
--- /dev/null
+++ b/include/resource-manager.hpp
@@ -0,0 +1,6 @@
+#pragma once
+
+class resourcemanager {
+ public:
+ static const resourcemanager resource_manager;
+};
diff --git a/include/window.hpp b/include/window.hpp
index aeea39a..33fce4f 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -146,7 +146,7 @@ class window {
static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
- HWND window_handle {};
+ HWND handle {};
WNDCLASS window_class {};
LPVOID main_fiber;
LPVOID message_loop_fiber;