1 | /**************************************************************************/ |
2 | /* openxr_vulkan_extension.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef OPENXR_VULKAN_EXTENSION_H |
32 | #define OPENXR_VULKAN_EXTENSION_H |
33 | |
34 | #include "../openxr_api.h" |
35 | #include "../util.h" |
36 | #include "openxr_extension_wrapper.h" |
37 | |
38 | #include "core/templates/vector.h" |
39 | #include "drivers/vulkan/vulkan_context.h" |
40 | |
41 | // Need to include Vulkan so we know of type definitions. |
42 | #define XR_USE_GRAPHICS_API_VULKAN |
43 | |
44 | #ifdef WINDOWS_ENABLED |
45 | // Including windows.h here is absolutely evil, we shouldn't be doing this outside of platform |
46 | // however due to the way the openxr headers are put together, we have no choice. |
47 | #include <windows.h> |
48 | #endif |
49 | |
50 | #ifdef ANDROID_ENABLED |
51 | // The jobject type from jni.h is used by openxr_platform.h on Android. |
52 | #include <jni.h> |
53 | #endif |
54 | |
55 | // Include platform dependent structs. |
56 | #include <openxr/openxr_platform.h> |
57 | |
58 | class OpenXRVulkanExtension : public OpenXRGraphicsExtensionWrapper, VulkanHooks { |
59 | public: |
60 | OpenXRVulkanExtension(); |
61 | virtual ~OpenXRVulkanExtension() override; |
62 | |
63 | virtual HashMap<String, bool *> get_requested_extensions() override; |
64 | |
65 | virtual void on_instance_created(const XrInstance p_instance) override; |
66 | virtual void *set_session_create_and_get_next_pointer(void *p_next_pointer) override; |
67 | |
68 | virtual bool create_vulkan_instance(const VkInstanceCreateInfo *p_vulkan_create_info, VkInstance *r_instance) override; |
69 | virtual bool get_physical_device(VkPhysicalDevice *r_device) override; |
70 | virtual bool create_vulkan_device(const VkDeviceCreateInfo *p_device_create_info, VkDevice *r_device) override; |
71 | |
72 | virtual void get_usable_swapchain_formats(Vector<int64_t> &p_usable_swap_chains) override; |
73 | virtual void get_usable_depth_formats(Vector<int64_t> &p_usable_swap_chains) override; |
74 | virtual String get_swapchain_format_name(int64_t p_swapchain_format) const override; |
75 | virtual bool get_swapchain_image_data(XrSwapchain p_swapchain, int64_t p_swapchain_format, uint32_t p_width, uint32_t p_height, uint32_t p_sample_count, uint32_t p_array_size, void **r_swapchain_graphics_data) override; |
76 | virtual void cleanup_swapchain_graphics_data(void **p_swapchain_graphics_data) override; |
77 | virtual bool create_projection_fov(const XrFovf p_fov, double p_z_near, double p_z_far, Projection &r_camera_matrix) override; |
78 | virtual RID get_texture(void *p_swapchain_graphics_data, int p_image_index) override; |
79 | |
80 | private: |
81 | static OpenXRVulkanExtension *singleton; |
82 | static XrGraphicsBindingVulkanKHR graphics_binding_vulkan; // declaring this as static so we don't need to know its size and we only need it once when creating our session |
83 | |
84 | struct SwapchainGraphicsData { |
85 | bool is_multiview; |
86 | Vector<RID> texture_rids; |
87 | }; |
88 | |
89 | bool check_graphics_api_support(XrVersion p_desired_version); |
90 | |
91 | VkInstance vulkan_instance = nullptr; |
92 | VkPhysicalDevice vulkan_physical_device = nullptr; |
93 | VkDevice vulkan_device = nullptr; |
94 | uint32_t vulkan_queue_family_index = 0; |
95 | uint32_t vulkan_queue_index = 0; |
96 | |
97 | EXT_PROTO_XRRESULT_FUNC3(xrGetVulkanGraphicsRequirements2KHR, (XrInstance), p_instance, (XrSystemId), p_system_id, (XrGraphicsRequirementsVulkanKHR *), p_graphics_requirements) |
98 | EXT_PROTO_XRRESULT_FUNC4(xrCreateVulkanInstanceKHR, (XrInstance), p_instance, (const XrVulkanInstanceCreateInfoKHR *), p_create_info, (VkInstance *), r_vulkan_instance, (VkResult *), r_vulkan_result) |
99 | EXT_PROTO_XRRESULT_FUNC3(xrGetVulkanGraphicsDevice2KHR, (XrInstance), p_instance, (const XrVulkanGraphicsDeviceGetInfoKHR *), p_get_info, (VkPhysicalDevice *), r_vulkan_physical_device) |
100 | EXT_PROTO_XRRESULT_FUNC4(xrCreateVulkanDeviceKHR, (XrInstance), p_instance, (const XrVulkanDeviceCreateInfoKHR *), p_create_info, (VkDevice *), r_device, (VkResult *), r_result) |
101 | EXT_PROTO_XRRESULT_FUNC4(, (XrSwapchain), p_swapchain, (uint32_t), p_image_capacity_input, (uint32_t *), p_image_count_output, (XrSwapchainImageBaseHeader *), p_images) |
102 | }; |
103 | |
104 | #endif // OPENXR_VULKAN_EXTENSION_H |
105 | |