Blender V4.3
GHOST_ContextVK.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#ifndef WITH_VULKAN_BACKEND
12# error "ContextVK requires WITH_VULKAN_BACKEND"
13#endif
14
15#include "GHOST_Context.hh"
16
17#ifdef _WIN32
18# include "GHOST_SystemWin32.hh"
19#elif defined(__APPLE__)
20# include "GHOST_SystemCocoa.hh"
21#else
22# ifdef WITH_GHOST_X11
23# include "GHOST_SystemX11.hh"
24# else
25# define Display void
26# define Window void *
27# endif
28# ifdef WITH_GHOST_WAYLAND
29# include "GHOST_SystemWayland.hh"
30# else
31# define wl_surface void
32# define wl_display void
33# endif
34#endif
35
36#include <vector>
37
38#ifndef GHOST_OPENGL_VK_CONTEXT_FLAGS
39/* leave as convenience define for the future */
40# define GHOST_OPENGL_VK_CONTEXT_FLAGS 0
41#endif
42
43#ifndef GHOST_OPENGL_VK_RESET_NOTIFICATION_STRATEGY
44# define GHOST_OPENGL_VK_RESET_NOTIFICATION_STRATEGY 0
45#endif
46
47typedef enum {
48#ifdef WITH_GHOST_X11
49 GHOST_kVulkanPlatformX11 = 0,
50#endif
51#ifdef WITH_GHOST_WAYLAND
52 GHOST_kVulkanPlatformWayland = 1,
53#endif
55
57 int size[2];
58};
59
61 public:
65 GHOST_ContextVK(bool stereoVisual,
66#ifdef _WIN32
67 HWND hwnd,
68#elif defined(__APPLE__)
69 /* FIXME CAMetalLayer but have issue with linking. */
70 void *metal_layer,
71#else
73 /* X11 */
74 Window window,
75 Display *display,
76 /* Wayland */
77 wl_surface *wayland_surface,
78 wl_display *wayland_display,
79 const GHOST_ContextVK_WindowInfo *wayland_window_info,
80#endif
81 int contextMajorVersion,
82 int contextMinorVersion,
83 int debug,
84 const GHOST_GPUDevice &preferred_device);
85
90
95 GHOST_TSuccess swapBuffers() override;
96
102
108
114
121
126 GHOST_TSuccess getVulkanHandles(void *r_instance,
127 void *r_physical_device,
128 void *r_device,
129 uint32_t *r_graphic_queue_family,
130 void *r_queue,
131 void **r_queue_mutex) override;
132
133 GHOST_TSuccess getVulkanSwapChainFormat(GHOST_VulkanSwapChainData *r_swap_chain_data) override;
134
136 std::function<void(const GHOST_VulkanSwapChainData *)> swap_buffers_pre_callback,
137 std::function<void(void)> swap_buffers_post_callback) override;
138
144 GHOST_TSuccess setSwapInterval(int /*interval*/) override
145 {
146 return GHOST_kFailure;
147 }
148
154 GHOST_TSuccess getSwapInterval(int & /*intervalOut*/) override
155 {
156 return GHOST_kFailure;
157 };
158
159 private:
160#ifdef _WIN32
161 HWND m_hwnd;
162#elif defined(__APPLE__)
163 CAMetalLayer *m_metal_layer;
164#else /* Linux */
165 GHOST_TVulkanPlatformType m_platform;
166 /* X11 */
167 Display *m_display;
168 Window m_window;
169 /* Wayland */
170 wl_surface *m_wayland_surface;
171 wl_display *m_wayland_display;
172 const GHOST_ContextVK_WindowInfo *m_wayland_window_info;
173#endif
174
175 const int m_context_major_version;
176 const int m_context_minor_version;
177 const int m_debug;
178 const GHOST_GPUDevice m_preferred_device;
179
180 VkCommandPool m_command_pool;
181 VkCommandBuffer m_command_buffer;
182
183 VkQueue m_graphic_queue;
184 VkQueue m_present_queue;
185
186 /* For display only. */
187 VkSurfaceKHR m_surface;
188 VkSwapchainKHR m_swapchain;
189 std::vector<VkImage> m_swapchain_images;
190
191 VkExtent2D m_render_extent;
192 VkExtent2D m_render_extent_min;
193 VkSurfaceFormatKHR m_surface_format;
194 VkFence m_fence;
195
206 static uint32_t s_currentImage;
207
208 std::function<void(const GHOST_VulkanSwapChainData *)> swap_buffers_pre_callback_;
209 std::function<void(void)> swap_buffers_post_callback_;
210
211 const char *getPlatformSpecificSurfaceExtension() const;
212 GHOST_TSuccess createSwapchain();
213 GHOST_TSuccess destroySwapchain();
214 GHOST_TSuccess createCommandPools();
215 GHOST_TSuccess createGraphicsCommandBuffers();
216 GHOST_TSuccess createGraphicsCommandBuffer();
217 GHOST_TSuccess recordCommandBuffers();
218};
GHOST_TVulkanPlatformType
#define wl_display
#define wl_surface
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
GHOST_TSuccess activateDrawingContext() override
GHOST_TSuccess swapBuffers() override
GHOST_TSuccess getVulkanSwapChainFormat(GHOST_VulkanSwapChainData *r_swap_chain_data) override
GHOST_TSuccess getVulkanHandles(void *r_instance, void *r_physical_device, void *r_device, uint32_t *r_graphic_queue_family, void *r_queue, void **r_queue_mutex) override
GHOST_TSuccess getSwapInterval(int &) override
GHOST_TSuccess setSwapInterval(int) override
GHOST_TSuccess initializeDrawingContext() override
GHOST_TSuccess releaseDrawingContext() override
GHOST_TSuccess releaseNativeHandles() override
GHOST_TSuccess setVulkanSwapBuffersCallbacks(std::function< void(const GHOST_VulkanSwapChainData *)> swap_buffers_pre_callback, std::function< void(void)> swap_buffers_post_callback) override
GHOST_ContextVK(bool stereoVisual, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, int debug, const GHOST_GPUDevice &preferred_device)
unsigned int uint32_t
Definition stdint.h:80