MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
VulkanBackend.hpp
Go to the documentation of this file.
1#pragma once
2
4
6struct BufferService;
7struct ComputeService;
8struct DisplayService;
9}
10
11namespace MayaFlux::Buffers {
12class VKBuffer;
13}
14
15namespace MayaFlux::Core {
16
17class VKContext;
18class VKCommandManager;
19
20class BackendResourceManager;
21class BackendPipelineManager;
22class BackendWindowHandler;
23
24/**
25 * @class VulkanBackend
26 * @brief Vulkan implementation of the IGraphicsBackend interface
27 *
28 * This class provides a Vulkan-based graphics backend for rendering to windows.
29 * It manages Vulkan context, swapchains, command buffers, and synchronization
30 * objects for each registered window.
31 * It supports window registration, rendering, and handling window resize events.
32 */
33class MAYAFLUX_API VulkanBackend : public IGraphicsBackend {
34public:
36
37 ~VulkanBackend() override;
38
39 /**
40 * @brief Initialize the graphics backend with global configuration
41 * @param config Global graphics configuration
42 * @return True if initialization was successful, false otherwise
43 */
44 bool initialize(const GlobalGraphicsConfig& config) override;
45
46 /**
47 * @brief Cleanup the graphics backend and release all resources
48 */
49 void cleanup() override;
50
51 /**
52 * @brief Get the type of the graphics backend
53 * @return GraphicsBackendType enum value representing the backend type
54 */
55 inline GlobalGraphicsConfig::GraphicsApi get_backend_type() override { return GlobalGraphicsConfig::GraphicsApi::VULKAN; }
56
57 /**
58 * @brief Register a window with the graphics backend for rendering
59 * @param window Shared pointer to the window to register
60 * @return True if registration was successful, false otherwise
61 */
62 bool register_window(std::shared_ptr<Window> window) override;
63
64 /**
65 * @brief Unregister a window from the graphics backend
66 * @param window Shared pointer to the window to unregister
67 */
68 void unregister_window(std::shared_ptr<Window> window) override;
69
70 /**
71 * @brief Check if a window is registered with the graphics backend
72 * @param window Shared pointer to the window to check
73 * @return True if the window is registered, false otherwise
74 */
75 [[nodiscard]] bool is_window_registered(std::shared_ptr<Window> window) override;
76
77 /**
78 * @brief Begin rendering frame for the specified window
79 * @param window Shared pointer to the window to begin frame for
80 *
81 * Default: no-op (handled in render_window)
82 * Vulkan handles frame begin internally when acquiring swapchain image
83 */
84 void begin_frame(std::shared_ptr<Window> /* window */) override { }
85
86 /**
87 * @brief Render the contents of the specified window
88 * @param window Shared pointer to the window to render
89 */
90 void render_window(std::shared_ptr<Window> window) override;
91
92 /**
93 * @brief Render all registered windows (batch optimization)
94 * Default: calls render_window() for each registered window
95 */
96 void render_all_windows() override;
97
98 /**
99 * @brief End rendering frame for the specified window
100 * @param window Shared pointer to the window to end frame for
101 *
102 * Default: no-op (handled in render_window)
103 * Vulkan handles frame end internally after rendering
104 */
105 void end_frame(std::shared_ptr<Window> /* window */) override { }
106
107 /**
108 * @brief Wait until the graphics backend is idle
109 */
110 void wait_idle() override;
111
112 /**
113 * @brief Handle window resize event for the specified window
114 */
115 void handle_window_resize() override;
116
117 /**
118 * @brief Get context pointer specific to the graphics backend (e.g., OpenGL context, Vulkan instance, etc.)
119 */
120 [[nodiscard]] void* get_native_context() override;
121 [[nodiscard]] const void* get_native_context() const override;
122
123 /**
124 * @brief Get reference to the backend resource manager
125 *
126 * Responsible for managing Vulkan resources like buffers, images, samplers, command and memory management.
127 * @return Reference to BackendResourceManager
128 */
129 BackendResourceManager& get_resource_manager() { return *m_resource_manager; }
130
131 /**
132 * @brief Get reference to the backend pipeline manager
133 *
134 * Responsible for managing Vulkan pipelines, descriptor sets, and shader modules.
135 * @return Reference to BackendPipelineManager
136 */
137 BackendPipelineManager& get_pipeline_manager() { return *m_pipeline_manager; }
138
139 /**
140 * @brief Get reference to the backend window handler
141 *
142 * Responsible for managing windows, swapchains, framebuffers, and rendering loops.
143 * @return Reference to BackendWindowHandler
144 */
145 VKContext& get_context() { return *m_context; }
146
147 /**
148 * @brief Get reference to the backend command manager
149 *
150 * Responsible for managing Vulkan command pools and command buffers.
151 * @return Reference to VKCommandManager
152 */
153 VKCommandManager& get_command_manager() { return *m_command_manager; }
154
155private:
156 std::unique_ptr<VKContext> m_context;
157 std::unique_ptr<VKCommandManager> m_command_manager;
158
159 std::unique_ptr<BackendResourceManager> m_resource_manager;
160 std::unique_ptr<BackendPipelineManager> m_pipeline_manager;
161 std::unique_ptr<BackendWindowHandler> m_window_handler;
162
163 bool m_is_initialized {};
164
165 void register_backend_services();
166
168
169 std::shared_ptr<Registry::Service::BufferService> m_buffer_service;
170 std::shared_ptr<Registry::Service::ComputeService> m_compute_service;
171 std::shared_ptr<Registry::Service::DisplayService> m_display_service;
172};
173
174}
Manages Vulkan pipelines (compute, graphics) and related resources.
Manages Vulkan resources (buffers, images, samplers) for the graphics backend.
Manages Vulkan command pools and command buffers.
High-level wrapper for Vulkan instance and device.
Definition VKContext.hpp:16
void begin_frame(std::shared_ptr< Window >) override
Begin rendering frame for the specified window.
std::shared_ptr< Registry::Service::ComputeService > m_compute_service
VKCommandManager & get_command_manager()
Get reference to the backend command manager.
VKContext & get_context()
Get reference to the backend window handler.
std::shared_ptr< Registry::Service::BufferService > m_buffer_service
std::unique_ptr< BackendWindowHandler > m_window_handler
std::unique_ptr< VKContext > m_context
void end_frame(std::shared_ptr< Window >) override
End rendering frame for the specified window.
std::shared_ptr< Registry::Service::DisplayService > m_display_service
std::unique_ptr< BackendPipelineManager > m_pipeline_manager
std::unique_ptr< VKCommandManager > m_command_manager
GlobalGraphicsConfig::GraphicsApi get_backend_type() override
Get the type of the graphics backend.
BackendPipelineManager & get_pipeline_manager()
Get reference to the backend pipeline manager.
BackendResourceManager & get_resource_manager()
Get reference to the backend resource manager.
std::unique_ptr< BackendResourceManager > m_resource_manager
Vulkan implementation of the IGraphicsBackend interface.
void initialize()
Definition main.cpp:11