diff options
Diffstat (limited to 'drivers/vulkan/vulkan_context.h')
-rw-r--r-- | drivers/vulkan/vulkan_context.h | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h index 7a62ef51e2..4176f85c0f 100644 --- a/drivers/vulkan/vulkan_context.h +++ b/drivers/vulkan/vulkan_context.h @@ -2,6 +2,7 @@ #define VULKAN_CONTEXT_H #include "core/error_list.h" +#include "core/map.h" #include "core/ustring.h" #include <vulkan/vulkan.h> @@ -24,6 +25,7 @@ class VulkanContext { VkDevice device; //present + bool queues_initialized; uint32_t graphics_queue_family_index; uint32_t present_queue_family_index; bool separate_present_queue; @@ -40,36 +42,46 @@ class VulkanContext { typedef struct { VkImage image; - VkCommandBuffer cmd; VkCommandBuffer graphics_to_present_cmd; VkImageView view; - VkBuffer uniform_buffer; - VkDeviceMemory uniform_memory; VkFramebuffer framebuffer; - VkDescriptorSet descriptor_set; + } SwapchainImageResources; - VkSwapchainKHR swapchain; - SwapchainImageResources *swapchain_image_resources; - VkPresentModeKHR presentMode; + struct Window { + + bool is_minimzed; + VkSurfaceKHR surface; + VkSwapchainKHR swapchain; + SwapchainImageResources *swapchain_image_resources; + VkPresentModeKHR presentMode; + uint32_t current_buffer; + int width; + int height; + VkCommandPool present_cmd_pool; //for separate present queue + + VkRenderPass render_pass; + + Window() { + width = 0; + height = 0; + render_pass = VK_NULL_HANDLE; + current_buffer = 0; + surface = VK_NULL_HANDLE; + swapchain_image_resources = VK_NULL_HANDLE; + swapchain = VK_NULL_HANDLE; + is_minimzed = false; + presentMode = VK_PRESENT_MODE_FIFO_KHR; + } + }; + + Map<int, Window> windows; + int last_window_id; uint32_t swapchainImageCount; - uint64_t refresh_duration; - bool syncd_with_actual_presents; - uint64_t refresh_duration_multiplier; - uint64_t target_IPD; // image present duration (inverse of frame rate) - uint64_t prev_desired_present_time; - uint32_t next_present_id; - uint32_t last_early_id; // 0 if no early images - uint32_t last_late_id; // 0 if no late images - bool is_minimized; - uint32_t current_buffer; //commands - VkRenderPass render_pass; - VkCommandPool present_cmd_pool; //for separate present queue bool prepared; - int width, height; //extensions bool VK_KHR_incremental_present_enabled; @@ -111,38 +123,46 @@ class VulkanContext { void *pUserData); Error _create_physical_device(); + + Error _initialize_queues(VkSurfaceKHR surface); + Error _create_device(); - Error _create_swap_chain(); - Error _create_semaphores(); - Error _prepare_buffers(); - Error _prepare_framebuffers(); - Error _create_buffers(); + Error _clean_up_swap_chain(Window *window); + + Error _update_swap_chain(Window *window); - int screen_width; - int screen_height; - bool minimized; + Error _create_swap_chain(); + Error _create_semaphores(); Vector<VkCommandBuffer> command_buffer_queue; int command_buffer_count; protected: virtual const char *_get_platform_surface_extension() const = 0; - virtual VkResult _create_surface(VkSurfaceKHR *surface, VkInstance p_instance) = 0; + // virtual VkResult _create_surface(VkSurfaceKHR *surface, VkInstance p_instance) = 0; + + virtual int _window_create(VkSurfaceKHR p_surface, int p_width, int p_height); + + VkInstance _get_instance() { + return inst; + } - VkSurfaceKHR &get_surface() { return surface; } + bool buffers_prepared; public: VkDevice get_device(); VkPhysicalDevice get_physical_device(); - int get_frame_count() const; + int get_swapchain_image_count() const; uint32_t get_graphics_queue() const; - int get_screen_width(int p_screen = 0); - int get_screen_height(int p_screen = 0); + void window_resize(int p_window_id, int p_width, int p_height); + int window_get_width(int p_window = 0); + int window_get_height(int p_window = 0); + void window_destroy(int p_window_id); + VkFramebuffer window_get_framebuffer(int p_window = 0); + VkRenderPass window_get_render_pass(int p_window = 0); - VkFramebuffer get_frame_framebuffer(int p_frame); - VkRenderPass get_render_pass(); VkFormat get_screen_format() const; VkPhysicalDeviceLimits get_device_limits() const; @@ -150,8 +170,9 @@ public: void append_command_buffer(const VkCommandBuffer &pCommandBuffer); void resize_notify(); void flush(bool p_flush_setup = false, bool p_flush_pending = false); + Error prepare_buffers(); Error swap_buffers(); - Error initialize(int p_width, int p_height, bool p_minimized); + Error initialize(); VulkanContext(); }; |