diff options
| author | Quentin LADEVIE <qladevie@wanadev.fr> | 2023-01-22 17:59:24 +0100 |
|---|---|---|
| committer | Quentin LADEVIE <qladevie@wanadev.fr> | 2023-01-22 17:59:24 +0100 |
| commit | 0a882c4b85423a170455f05a52d18f7fa7c9220b (patch) | |
| tree | 3bdc24d73ba7cc828fce2b93ce85f73831b12204 /include/api-test/vk-device.hpp | |
| parent | 5e3bb454d50091e581d5d1d03af34e38277694b3 (diff) | |
Api test bindless and command buffers
Diffstat (limited to 'include/api-test/vk-device.hpp')
| -rw-r--r-- | include/api-test/vk-device.hpp | 138 |
1 files changed, 80 insertions, 58 deletions
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp index f010cc5..b09ed9e 100644 --- a/include/api-test/vk-device.hpp +++ b/include/api-test/vk-device.hpp @@ -1,115 +1,137 @@ #pragma once #include <cstdint> +#include <span> #include <vulkan/vulkan_core.h> -#include "handle.hpp" -#include "freelist.hpp" -#include "texture.hpp" -#include "buffer.hpp" #include "command-buffer.hpp" +#include "freelist.hpp" +#include "handle.hpp" +#include "vk-bindless.hpp" +#include "vk-device-types.hpp" using VmaAllocator = struct VmaAllocator_T*; -using VmaAllocation = struct VmaAllocation_T*; - -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 { struct queue { - VkQueue handle; - uint32_t index; - VkQueueFlags usages; - VkCommandPool command_pool; + VkQueue vk_queue; + uint32_t index; + VkQueueFlags usages; + VkCommandPool command_pool; }; -public: + public: + static vkdevice* init_device(const window& window); - vkdevice(const window& window); + static void free_device(); + + static inline vkdevice* get_device() { + return render_device; + } + + handle<device_texture> create_texture(const texture_desc& desc); + + handle<device_buffer> create_buffer(const buffer_desc& desc); - handle<device_texture> create_texture(const texture_desc& desc); + handle<device_pipeline> create_pipeline(const pipeline_desc& desc); - handle<device_buffer> create_buffer(const buffer_desc& desc); + void destroy_texture(const device_texture& texture); + void destroy_texture(handle<device_texture> handle); + + void destroy_buffer(const device_buffer& buffer); + void destroy_buffer(handle<device_buffer> handle); + + void destroy_pipeline(const device_pipeline& pipeline); + void destroy_pipeline(handle<device_pipeline> handle); template<typename cmd_buf_type> void allocate_command_buffers(cmd_buf_type* buffers, size_t count, QueueType queue_type) { - allocate_command_buffers(buffers, count, queue_type); + allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type); } - const device_texture& get_texture(handle<device_texture> handle) { + inline device_texture& get_texture(handle<device_texture> handle) { return textures[handle.id]; } - const device_buffer& get_buffer(handle<device_buffer> handle) { + inline const device_buffer& get_buffer(handle<device_buffer> handle) { return buffers[handle.id]; } + inline const device_pipeline& get_pipeline(handle<device_pipeline> handle) { + return pipelines[handle.id]; + } + + inline const bindless_model& get_bindingmodel() { + return bindless; + } + void submit(command_buffer* buffers, size_t count); -private: + void present(); + + private: + vkdevice(const window& window); + ~vkdevice(); void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type); void create_views(device_texture& texture); - void create_surface(const window& window); + // Presentation stuff + void create_surface(const window& window); - void create_swapchain(); + void create_swapchain(); - VkSurfaceKHR surface; - VkSwapchainKHR swapchain; + void create_virtual_frames(); - // TODO: Wrap in a struct called adapter ? - void create_instance(); + VkSurfaceKHR surface = nullptr; + VkSwapchainKHR swapchain = nullptr; - void create_device(); + // TODO: Wrap in a struct called adapter ? + void create_instance(); - void create_memory_allocator(); + void create_device(); - void create_command_pools(); + void create_memory_allocator(); - void pick_physical_device(); + void create_command_pools(); - [[nodiscard]] uint32_t pick_queue(VkQueueFlags usages) const; + void pick_physical_device(); static bool device_support_features(VkPhysicalDevice physical_dev); - void create_debug_layer_callback(); + void create_debug_layer_callback(); + + // Virtual frames resources + static constexpr uint32_t virtual_frames_count = 3U; + VkSemaphore semaphores[virtual_frames_count]; + + queue queues[static_cast<uint32_t>(QueueType::MAX)]; + VkInstance instance; + VkPhysicalDevice physical_device; + VkDevice device; - queue queues[static_cast<uint32_t>(QueueType::MAX)]; + VmaAllocator gpu_allocator; - VkInstance instance; - VkPhysicalDevice physical_device; - VkDevice device; + bindless_model bindless; - VmaAllocator gpu_allocator; + static constexpr size_t max_allocable_command_buffers = 16; + static constexpr size_t max_submitable_command_buffers = 16; - static constexpr size_t max_allocable_command_buffers = 16; - static constexpr size_t max_submitable_command_buffers = 16; + freelist<device_texture*> storage_indices; + freelist<device_texture*> sampled_indices; + + freelist<device_texture> textures; + freelist<device_buffer> buffers; + freelist<device_pipeline> pipelines; + + static vkdevice* render_device; #ifdef _DEBUG - VkDebugUtilsMessengerEXT debug_messenger; + VkDebugUtilsMessengerEXT debug_messenger; #endif // _DEBUG - - freelist<device_texture> textures; - freelist<device_buffer> buffers; }; |
