diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2022-10-27 23:22:55 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2022-10-27 23:22:55 +0200 |
| commit | b47e177898657e435cb5bc913a4a783fddbe1f3d (patch) | |
| tree | df0a042b5ed9e98d7653462466dd3c6147127bc3 /include/api-test | |
| parent | cee4f9c528a91691d94c52ec1849f3ad1245b081 (diff) | |
Api prototype
Diffstat (limited to 'include/api-test')
| -rw-r--r-- | include/api-test/buffer.hpp | 25 | ||||
| -rw-r--r-- | include/api-test/freelist.hpp | 32 | ||||
| -rw-r--r-- | include/api-test/handle.hpp | 8 | ||||
| -rw-r--r-- | include/api-test/resource-manager.hpp | 22 | ||||
| -rw-r--r-- | include/api-test/texture.hpp | 29 | ||||
| -rw-r--r-- | include/api-test/vk-command-buffer.hpp | 14 | ||||
| -rw-r--r-- | include/api-test/vk-device.hpp | 128 |
7 files changed, 258 insertions, 0 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; +}; |
