From 74a223d1a9d23369c6c20457424b34cf17da95ab Mon Sep 17 00:00:00 2001 From: ladevieq Date: Tue, 7 Feb 2023 23:53:55 +0100 Subject: Remove presentation stuff from device class Device instance is no more a pointer Remove desc member in device structs --- include/api-test/vk-device.hpp | 123 +++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 61 deletions(-) (limited to 'include/api-test/vk-device.hpp') diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp index 5b71529..fd69d60 100644 --- a/include/api-test/vk-device.hpp +++ b/include/api-test/vk-device.hpp @@ -15,11 +15,6 @@ using VmaAllocator = struct VmaAllocator_T*; class window; -struct vksemaphore { - VkSemaphore vk_semaphore = nullptr; - uint64_t value = 0U; -}; - class vkdevice { struct queue { VkQueue vk_queue; @@ -29,49 +24,63 @@ class vkdevice { }; public: - static vkdevice* init_device(const window& window); + void init(); - static void free_device(); - - static inline vkdevice* get_render_device() { + static inline vkdevice& get_render_device() { return render_device; } - handle create_texture(const texture_desc& desc); + handle create_texture(const texture_desc& desc); + + handle create_buffer(const buffer_desc& desc); - handle create_buffer(const buffer_desc& desc); + handle create_pipeline(const pipeline_desc& desc); - handle create_pipeline(const pipeline_desc& desc); + handle create_surface(const surface_desc& desc); - vksemaphore create_semaphore(); + handle create_semaphore(const semaphore_desc& desc); - void destroy_texture(const device_texture& texture); - void destroy_texture(handle handle); + void destroy_texture(const device_texture& texture); + void destroy_texture(handle handle); - void destroy_buffer(const device_buffer& buffer); - void destroy_buffer(handle handle); + void destroy_buffer(const device_buffer& buffer); + void destroy_buffer(handle handle); - void destroy_pipeline(const device_pipeline& pipeline); - void destroy_pipeline(handle handle); + void destroy_pipeline(const device_pipeline& pipeline); + void destroy_pipeline(handle handle); + + void destroy_semaphore(const device_semaphore& semaphore); + void destroy_semaphore(handle handle); + + void destroy_surface(const device_surface& surface); + void destroy_surface(handle handle); template void allocate_command_buffers(cmd_buf_type* buffers, size_t count, QueueType queue_type) { allocate_command_buffers(static_cast(buffers), count, queue_type); } - inline device_texture& get_texture(handle handle) { + [[nodiscard]] inline device_texture& get_texture(handle handle) { return textures[handle.id]; } - inline const device_buffer& get_buffer(handle handle) { + [[nodiscard]] inline const device_buffer& get_buffer(handle handle) const { return buffers[handle.id]; } - inline const device_pipeline& get_pipeline(handle handle) { + [[nodiscard]] inline const device_pipeline& get_pipeline(handle handle) const { return pipelines[handle.id]; } - inline const bindless_model& get_bindingmodel() { + [[nodiscard]] inline const device_surface& get_surface(handle handle) const { + return surfaces[handle.id]; + } + + [[nodiscard]] inline device_semaphore& get_semaphore(handle handle) { + return semaphores[handle.id]; + } + + [[nodiscard]] inline const bindless_model& get_bindingmodel() const { return bindless; } @@ -79,70 +88,62 @@ class vkdevice { return device; } - void wait(vksemaphore& semaphore); + void wait(handle semaphore_handle); - void submit(std::span buffers, vksemaphore* wait, vksemaphore* signal); + void submit(std::span buffers, handle wait_handle, handle signal_handle); - void present(device_surface& surface, const vksemaphore& semaphore); + void present(handle surface_handle, handle semaphore_handle); private: - vkdevice(const window& window); + vkdevice() = default; ~vkdevice(); void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type); - void create_views(device_texture& texture); + VkShaderModule create_shader_module(const std::span& shader_code); - // Presentation stuff - void create_surface(const window& window); + void create_views(const texture_desc& desc, device_texture& texture); - void create_swapchain(); - - void create_virtual_frames(); - - VkSurfaceKHR surface = nullptr; - VkSwapchainKHR swapchain = nullptr; + void create_swapchain(const surface_desc& desc, device_surface& surface); // TODO: Wrap in a struct called adapter ? - void create_instance(); - - void create_device(); + 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(); - static bool device_support_features(VkPhysicalDevice physical_dev); + void pick_physical_device(); - void create_debug_layer_callback(); + static bool device_support_features(VkPhysicalDevice physical_dev); - // Virtual frames resources - static constexpr uint32_t virtual_frames_count = 3U; - VkSemaphore semaphores[virtual_frames_count]; + void create_debug_layer_callback(); - queue queues[static_cast(QueueType::MAX)]; + queue queues[static_cast(QueueType::MAX)]; - VkInstance instance; - VkPhysicalDevice physical_device; - VkDevice device; + VkInstance instance; + VkPhysicalDevice physical_device; + VkDevice device; - VmaAllocator gpu_allocator; + VmaAllocator gpu_allocator; - bindless_model bindless; + bindless_model bindless; - 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 storage_indices; - freelist sampled_indices; + freelist storage_indices; + freelist sampled_indices; - freelist textures; - freelist buffers; - freelist pipelines; + freelist textures; + freelist buffers; + freelist pipelines; + freelist surfaces; + freelist semaphores; - static vkdevice* render_device; + static vkdevice render_device; #ifdef _DEBUG VkDebugUtilsMessengerEXT debug_messenger; -- cgit v1.3