Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
ApplicationContext.h
Go to the documentation of this file.
1#pragma once
2#include <filesystem>
3#include <vulkan/vulkan_core.h>
4#include <vk_mem_alloc.h>
5#include <openxr/openxr.h>
6#include <openxr/openxr_platform.h>
7#include <optional>
8#include <string>
9#include <utility>
10#include <vector>
11
12namespace EngineCore
13{
18 class EnvironmentException : public std::exception
19 {
20 public:
21 explicit EnvironmentException( std::string message ) : message_( std::move( message ) ) {}
22
23 [[nodiscard]] const char * what() const noexcept override
24 {
25 return message_.c_str();
26 }
27
28 private:
29 std::string message_;
30 };
31
36 {
37 public:
38 ApplicationContext() = default;
40
46 void createDevice( VkSurfaceKHR mirrorSurface );
47
53 [[nodiscard]] XrInstance getXrInstance() const;
54
60 [[nodiscard]] XrSystemId getXrSystemId() const;
61
67 [[nodiscard]] VkInstance getVkInstance() const;
68
77 [[nodiscard]] const VkDevice getVkDevice() const;
78
87 [[nodiscard]] const VkQueue & getPresentQueue() const;
88
97 [[nodiscard]] const VkQueue & getGraphicsQueue() const;
98
107 [[nodiscard]] const VkQueue & getTransferQueue() const;
108
117 [[nodiscard]] VkSampleCountFlagBits getMultisampleCount() const;
118
127 [[nodiscard]] const VkPhysicalDevice & getVkPhysicalDevice() const;
128
137 [[nodiscard]] uint32_t getVkGraphicsQueueFamilyIndex() const;
138
147 [[nodiscard]] uint32_t getVkTransferQueueFamilyIndex() const;
148
157 [[nodiscard]] VkDeviceSize getUniformBufferOffsetAlignment() const;
158
167 [[nodiscard]] uint32_t getMaxPushConstantsSize() const;
168
177 [[nodiscard]] const XrViewConfigurationType getXrViewType() const;
178
182 void createResources();
183
187 void cleanup();
188
197 [[nodiscard]] bool usesDedicatedTransferQueue() const;
198
207 [[nodiscard]] VmaAllocator getVmaAllocator() const;
208
209 private:
223 VkPhysicalDevice physicalDevice,
224 VkSurfaceKHR surface,
225 uint32_t & outGraphicsIndex,
226 uint32_t & outPresentIndex,
227 uint32_t & outTransferIndex
228 );
229
242 std::optional<std::filesystem::path> customOpenXrRuntimePath =
243 std::optional<std::filesystem::path>()
244 );
245
250 PFN_xrGetVulkanInstanceExtensionsKHR xrGetVulkanInstanceExtensionsKHR = nullptr;
251 PFN_xrGetVulkanGraphicsDevice2KHR xrGetVulkanGraphicsDevice2KHR = nullptr;
252 PFN_xrGetVulkanGraphicsRequirements2KHR xrGetVulkanGraphicsRequirements2KHR = nullptr;
253
254 PFN_xrCreateVulkanInstanceKHR xrCreateVulkanInstanceKHR = nullptr;
255 PFN_xrCreateVulkanDeviceKHR xrCreateVulkanDeviceKHR = nullptr;
256
257#ifdef IS_IN_DEBUG
258 PFN_xrCreateDebugUtilsMessengerEXT xrCreateDebugUtilsMessengerEXT = nullptr;
259 PFN_xrDestroyDebugUtilsMessengerEXT xrDestroyDebugUtilsMessengerEXT = nullptr;
260
261 void createOpenXrDebugMessenger();
262#endif
263
270 void retrieveXrSystemId();
271
279
287
295
303
307 std::vector<XrExtensionProperties> supportedOpenXRInstanceExtensions;
308
312 std::vector<XrApiLayerProperties> supportedOpenXRApiLayers;
313
317 XrInstance xrInstance = XR_NULL_HANDLE;
318
319#ifdef IS_IN_DEBUG
323 XrDebugUtilsMessengerEXT xrDebugMessenger = XR_NULL_HANDLE;
324#endif
325
329 XrSystemId xrSystemId = XR_NULL_SYSTEM_ID;
330
334 std::vector<VkExtensionProperties> supportedVulkanInstanceExtensions;
335
339 std::vector<const char *> vulkanInstanceExtensions;
340
344 VkInstance vkInstance = VK_NULL_HANDLE;
345
349 VkPhysicalDevice vkPhysicalDevice = VK_NULL_HANDLE;
350
354 std::vector<VkExtensionProperties> supportedVulkanDeviceExtensions;
358 std::vector<const char *> vulkanDeviceExtensions;
366 VkSampleCountFlagBits multisampleCount = VK_SAMPLE_COUNT_1_BIT;
370 uint32_t maxPushConstantsSize = 128u;
371
373 {
374 struct Family
375 {
376 uint32_t index = 0u;
377 VkQueue queue = VK_NULL_HANDLE;
378 };
379
384
385 VkDevice vkDevice = VK_NULL_HANDLE;
386
390 VmaAllocator vmaAllocator_ = VK_NULL_HANDLE;
391 };
392} // namespace EngineCore
const VkQueue & getPresentQueue() const
Gets the present queue.
void logVulkanRequirements()
Logs vulkan requirements.
uint32_t getVkTransferQueueFamilyIndex() const
gets the transfer queue family index
uint32_t getMaxPushConstantsSize() const
Gets max push constants size in bytes.
void createOpenXrInstance(std::optional< std::filesystem::path > customOpenXrRuntimePath=std::optional< std::filesystem::path >())
Queries supported openxr instance extensions, openxr api layers and creates the XrInstance.
PFN_xrCreateVulkanInstanceKHR xrCreateVulkanInstanceKHR
VmaAllocator vmaAllocator_
VMA allocator for efficient GPU memory management.
XrSystemId xrSystemId
Identifier for the xr device. So the identifier for the headset.
uint32_t getVkGraphicsQueueFamilyIndex() const
Gets the zero-based index of the vulkan draw queue family.
struct EngineCore::ApplicationContext::QueueFamily queueFamily
bool usesDedicatedTransferQueue() const
Check if the transfer queue index is its own, dedicated queue.
std::vector< XrExtensionProperties > supportedOpenXRInstanceExtensions
The supported open xr instance extensions.
uint32_t maxPushConstantsSize
Maximum push constants size in bytes.
PFN_xrGetVulkanGraphicsRequirements2KHR xrGetVulkanGraphicsRequirements2KHR
VkPhysicalDevice vkPhysicalDevice
The vulkan physical device.
XrInstance xrInstance
The xr instance.
std::vector< const char * > vulkanDeviceExtensions
(Immutable) the vulkan device extensions
const VkQueue & getTransferQueue() const
Gets the transfer queue.
void checkRequiredEnvironmentBlendModeAvailability()
Gets the environment blend mode.
void retrieveXrSystemId()
Gets the XrSystemId.
VkSampleCountFlagBits multisampleCount
Number of multisamples.
VkInstance vkInstance
The vulkan instance.
std::vector< VkExtensionProperties > supportedVulkanInstanceExtensions
The supported vulkan instance extensions.
std::vector< VkExtensionProperties > supportedVulkanDeviceExtensions
The supported vulkan device extensions.
XrSystemId getXrSystemId() const
Gets xr system identifier.
VkDeviceSize uniformBufferOffsetAlignment
The uniform buffer offset alignment.
const VkDevice getVkDevice() const
Gets the vulkan device.
void pickQueueFamilies(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface, uint32_t &outGraphicsIndex, uint32_t &outPresentIndex, uint32_t &outTransferIndex)
gets the device queues needed
const VkPhysicalDevice & getVkPhysicalDevice() const
Gets vulkan physical device.
void getVulkanInstanceExtensions()
Gets vulkan instance extensions.
PFN_xrCreateVulkanDeviceKHR xrCreateVulkanDeviceKHR
VkInstance getVkInstance() const
Gets vulkan instance.
void cleanup()
performs the cleanup by removing all vulkan and openxr pointers
PFN_xrGetVulkanGraphicsDevice2KHR xrGetVulkanGraphicsDevice2KHR
void createVulkanInstance()
Creates a vulkan instance.
const XrViewConfigurationType getXrViewType() const
Gets xr view type which should be stereo for any typical VR application.
void createDevice(VkSurfaceKHR mirrorSurface)
Creates the vulkan device and all necessary components for it.
std::vector< const char * > vulkanInstanceExtensions
(Immutable) the vulkan instance extensions which should get enabled
PFN_xrGetVulkanInstanceExtensionsKHR xrGetVulkanInstanceExtensionsKHR
VmaAllocator getVmaAllocator() const
Gets the VMA allocator for memory management.
std::vector< XrApiLayerProperties > supportedOpenXRApiLayers
The supported open xr API layers.
VkSampleCountFlagBits getMultisampleCount() const
Gets multisample count.
const VkQueue & getGraphicsQueue() const
Gets draw queue.
void createResources()
creates all openxr and vulkan resources
VkDeviceSize getUniformBufferOffsetAlignment() const
Gets uniform buffer offset alignment.
void LoadOpenXrExtensionFunctions()
Loads all dynamically loaded xr functions.
XrInstance getXrInstance() const
Gets xr instance.
EnvironmentException(std::string message)
const char * what() const noexcept override
Log category system implementation.
STL namespace.