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
36 uint32_t current_frame = 0;
37 uint32_t current_image_index = 0;
40 void recreate_swapchain(LayerList& layers);
41 [[nodiscard]] const Window& get_window() const;
42
43
44 // TODO: a lot of htese we prolly dont need
45 FrameSync& get_frame_sync();
46 SwapchainSync& get_swapchain_sync(uint32_t image_index);
47
48 vk::UniqueSwapchainKHR& get_swapchain();
49 vk::SwapchainCreateInfoKHR& get_swapchain_create_info();
50 [[nodiscard]] const std::vector<vk::Image>& get_swapchain_images() const;
51 vk::SurfaceFormatKHR& get_surface_format();
52 vk::Extent2D& get_swapchain_extent();
53 [[nodiscard]] const std::vector<vk::UniqueImageView>& get_swapchain_image_views() const;
54
55 std::expected<uint32_t, vk::Result> get_vulkan_images(vk::UniqueSemaphore& image_acquired);
56 vk::Result present_image(uint32_t image_index);
57
58 void rebuild_per_image_sync();
59
60 [[nodiscard]] vk::CommandPool get_command_pool() const;
61
62 void resize(int witdh, int height);
63
64 bool is_minimized() const { return m_is_minimized; }
65 bool is_framebuffer_resized() const { return m_is_framebuffer_resized; }
66 void reset_framebuffer_resized() { m_is_framebuffer_resized = false; }
67
68 vk::CommandBuffer get_current_command_buffer() const { return *m_command_buffers[current_frame]; }
69 VulkanContext& get_vulkan_context() { return m_vulkan_ctx; }
70
71
72 void create_swapchain();
73 void create_command_pool();
74 void create_swapchain_dependent_resources();
75
77 vk::Device& m_device;
78
79
81
82 vk::UniqueSurfaceKHR m_surface;
83
84 vk::UniqueSwapchainKHR m_swapchain;
85 vk::SwapchainCreateInfoKHR m_swapchain_create_info;
86
87 std::vector<vk::Image> m_swapchain_images;
88 std::vector<vk::UniqueImageView> m_swapchain_image_views;
89 vk::Extent2D m_swapchain_extent;
90 vk::SurfaceFormatKHR m_surface_format;
91 vk::SurfaceCapabilitiesKHR m_surface_capabilities;
92
93 vk::UniqueCommandPool m_command_pool;
94 std::vector<vk::UniqueCommandBuffer> m_command_buffers;
95
96 std::vector<FrameSync> m_frame_syncs;
97 std::vector<SwapchainSync> m_swapchain_syncs;
98
99 bool m_is_minimized{};
100 bool m_is_framebuffer_resized{};
101};
102} // namespace sd
Definition Application.hpp:22
Definition VulkanWindow.hpp:19
vk::UniqueSemaphore image_acquired
Definition VulkanWindow.hpp:20
vk::UniqueFence in_flight
Definition VulkanWindow.hpp:21
Definition LayerList.hpp:15
Definition VulkanWindow.hpp:24
vk::UniqueSemaphore render_complete
Definition VulkanWindow.hpp:25
Definition VulkanContext.hpp:22
Definition VulkanWindow.hpp:35
bool is_framebuffer_resized() const
Definition VulkanWindow.hpp:65
vk::SwapchainCreateInfoKHR m_swapchain_create_info
Definition VulkanWindow.hpp:85
VulkanContext & m_vulkan_ctx
Definition VulkanWindow.hpp:76
std::vector< vk::UniqueCommandBuffer > m_command_buffers
Definition VulkanWindow.hpp:94
VulkanContext & get_vulkan_context()
Definition VulkanWindow.hpp:69
std::vector< vk::Image > m_swapchain_images
Definition VulkanWindow.hpp:87
vk::UniqueCommandPool m_command_pool
Definition VulkanWindow.hpp:93
vk::UniqueSwapchainKHR m_swapchain
Definition VulkanWindow.hpp:84
vk::CommandBuffer get_current_command_buffer() const
Definition VulkanWindow.hpp:68
vk::UniqueSurfaceKHR m_surface
Definition VulkanWindow.hpp:82
std::vector< SwapchainSync > m_swapchain_syncs
Definition VulkanWindow.hpp:97
vk::SurfaceFormatKHR m_surface_format
Definition VulkanWindow.hpp:90
vk::SurfaceCapabilitiesKHR m_surface_capabilities
Definition VulkanWindow.hpp:91
vk::Extent2D m_swapchain_extent
Definition VulkanWindow.hpp:89
vk::Device & m_device
Definition VulkanWindow.hpp:77
std::vector< vk::UniqueImageView > m_swapchain_image_views
Definition VulkanWindow.hpp:88
Window & m_window
Definition VulkanWindow.hpp:80
std::vector< FrameSync > m_frame_syncs
Definition VulkanWindow.hpp:96
void reset_framebuffer_resized()
Definition VulkanWindow.hpp:66
bool is_minimized() const
Definition VulkanWindow.hpp:64
Definition Window.hpp:49
consteval U64 type_id_of()
Definition type_id.hpp:6