SDEngine
Game Engine
Loading...
Searching...
No Matches
VulkanWindow.hpp
Go to the documentation of this file.
1// TODO(docs): Add file-level Doxygen header
2// - @file VulkanWindow.hpp
3// - @brief Vulkan swapchain and per-window rendering resources
4// - Relationship to Window (GLFW) and VulkanContext
5// - Frame synchronization model
6#pragma once
8#include "SD/core/Window.hpp"
11#include "VulkanContext.hpp"
12
13namespace sd {
14// TODO(docs): Document FrameSync and SwapchainSync structs
15// - Purpose: Synchronization primitives for frame rendering
16// - imageAcquired: GPU signal when swapchain image is ready
17// - inFlight: CPU-GPU sync for command buffer reuse
18// - renderComplete: GPU signal when rendering done
19struct FrameSync {
20 vk::UniqueSemaphore image_acquired;
21 vk::UniqueFence in_flight;
22};
23
25 vk::UniqueSemaphore render_complete;
26};
27
28// TODO(docs): Document VulkanWindow class thoroughly
29// - Purpose: Manages Vulkan swapchain and per-window resources
30// - Swapchain creation and recreation
31// - Frame synchronization (MAX_FRAMES_IN_FLIGHT)
32// - Command buffer management
33// - Minimization handling
34// - Integration with LayerList for swapchain recreation
36public:
37 uint32_t current_frame = 0;
38 uint32_t current_image_index = 0;
41 void recreate_swapchain(LayerList& layers);
42 [[nodiscard]] const Window& get_window() const;
43
44
45 // TODO: a lot of htese we prolly dont need
46 FrameSync& get_frame_sync();
47 SwapchainSync& get_swapchain_sync(uint32_t image_index);
48
49 vk::UniqueSwapchainKHR& get_swapchain();
50 vk::SwapchainCreateInfoKHR& get_swapchain_create_info();
51 [[nodiscard]] const std::vector<vk::Image>& get_swapchain_images() const;
52 vk::SurfaceFormatKHR& get_surface_format();
53 vk::Extent2D& get_swapchain_extent();
54 [[nodiscard]] const std::vector<vk::UniqueImageView>& get_swapchain_image_views() const;
55
56 [[nodiscard]] const std::vector<vk::UniqueFramebuffer>& get_framebuffers() const;
57
58 [[nodiscard]] vk::RenderPass get_render_pass() const;
59
60 std::expected<uint32_t, vk::Result> get_vulkan_images(vk::UniqueSemaphore& image_acquired);
61 vk::Result present_image(uint32_t image_index);
62
63 void rebuild_per_image_sync();
64
65 [[nodiscard]] vk::CommandPool get_command_pool() const;
66
67 void resize(int witdh, int height);
68
69 bool is_minimized() const { return m_is_minimized; }
70 bool is_framebuffer_resized() const { return m_is_framebuffer_resized; }
71 void reset_framebuffer_resized() { m_is_framebuffer_resized = false; }
72
73 vk::CommandBuffer get_current_command_buffer() const { return *m_command_buffers[current_frame]; }
74 VulkanContext& get_vulkan_context() { return m_vulkan_ctx; }
75
76private:
77 void create_swapchain();
78 void create_render_pass(); // can be shared, but yeah...
79
80 void create_command_pool();
81
82 void create_swapchain_dependent_resources();
83 void create_framebuffers();
84
86 vk::Device& m_device;
87
88
90
91 vk::UniqueSurfaceKHR m_surface;
92
93 vk::UniqueSwapchainKHR m_swapchain;
94 vk::SwapchainCreateInfoKHR m_swapchain_create_info;
95
96 std::vector<vk::Image> m_swapchain_images;
97 std::vector<vk::UniqueImageView> m_swapchain_image_views;
98 vk::Extent2D m_swapchain_extent;
99 vk::SurfaceFormatKHR m_surface_format;
100 vk::SurfaceCapabilitiesKHR m_surface_capabilities;
101
102 vk::UniqueRenderPass m_render_pass;
103
104 vk::UniqueCommandPool m_command_pool;
105 std::vector<vk::UniqueCommandBuffer> m_command_buffers;
106
107 std::vector<vk::UniqueFramebuffer> m_framebuffers;
108
109 std::vector<FrameSync> m_frame_syncs;
110 std::vector<SwapchainSync> m_swapchain_syncs;
111
112 bool m_is_minimized{};
113 bool m_is_framebuffer_resized{};
114};
115} // namespace sd
Definition LayerList.hpp:21
Definition VulkanContext.hpp:22
Definition VulkanWindow.hpp:35
bool is_framebuffer_resized() const
Definition VulkanWindow.hpp:70
vk::SwapchainCreateInfoKHR m_swapchain_create_info
Definition VulkanWindow.hpp:94
VulkanContext & m_vulkan_ctx
Definition VulkanWindow.hpp:85
std::vector< vk::UniqueCommandBuffer > m_command_buffers
Definition VulkanWindow.hpp:105
VulkanContext & get_vulkan_context()
Definition VulkanWindow.hpp:74
std::vector< vk::Image > m_swapchain_images
Definition VulkanWindow.hpp:96
vk::UniqueCommandPool m_command_pool
Definition VulkanWindow.hpp:104
vk::UniqueSwapchainKHR m_swapchain
Definition VulkanWindow.hpp:93
vk::CommandBuffer get_current_command_buffer() const
Definition VulkanWindow.hpp:73
vk::UniqueSurfaceKHR m_surface
Definition VulkanWindow.hpp:91
std::vector< SwapchainSync > m_swapchain_syncs
Definition VulkanWindow.hpp:110
vk::SurfaceFormatKHR m_surface_format
Definition VulkanWindow.hpp:99
vk::UniqueRenderPass m_render_pass
Definition VulkanWindow.hpp:102
vk::SurfaceCapabilitiesKHR m_surface_capabilities
Definition VulkanWindow.hpp:100
vk::Extent2D m_swapchain_extent
Definition VulkanWindow.hpp:98
vk::Device & m_device
Definition VulkanWindow.hpp:86
std::vector< vk::UniqueImageView > m_swapchain_image_views
Definition VulkanWindow.hpp:97
Window & m_window
Definition VulkanWindow.hpp:89
std::vector< FrameSync > m_frame_syncs
Definition VulkanWindow.hpp:109
std::vector< vk::UniqueFramebuffer > m_framebuffers
Definition VulkanWindow.hpp:107
void reset_framebuffer_resized()
Definition VulkanWindow.hpp:71
bool is_minimized() const
Definition VulkanWindow.hpp:69
Definition Window.hpp:49
Definition Application.hpp:28
Definition VulkanWindow.hpp:19
vk::UniqueSemaphore image_acquired
Definition VulkanWindow.hpp:20
vk::UniqueFence in_flight
Definition VulkanWindow.hpp:21
Definition VulkanWindow.hpp:24
vk::UniqueSemaphore render_complete
Definition VulkanWindow.hpp:25
constexpr T g_type_max
Definition types.hpp:21