2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  openxr_vulkan_extension.h                                            */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                       This file is part of:                           */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                           GODOT ENGINE                                */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                      https://godotengine.org                          */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* Permission is hereby granted, free of charge, to any person obtaining */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* a copy of this software and associated documentation files (the       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* "Software"), to deal in the Software without restriction, including   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* without limitation the rights to use, copy, modify, merge, publish,   */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* distribute, sublicense, and/or sell copies of the Software, and to    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* permit persons to whom the Software is furnished to do so, subject to */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* the following conditions:                                             */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* The above copyright notice and this permission notice shall be        */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* included in all copies or substantial portions of the Software.       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*                                                                       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*************************************************************************/  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifndef OPENXR_VULKAN_EXTENSION_H 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define OPENXR_VULKAN_EXTENSION_H 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "core/templates/vector.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "openxr_extension_wrapper.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "drivers/vulkan/vulkan_context.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "../openxr_api.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "../util.h" 
  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								// need to include Vulkan so we know of type definitions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# define XR_USE_GRAPHICS_API_VULKAN 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef WINDOWS_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Including windows.h here is absolutely evil, we shouldn't be doing this outside of platform
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// however due to the way the openxr headers are put together, we have no choice.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <windows.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# ifdef ANDROID_ENABLED 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// The jobject type from jni.h is used by openxr_platform.h on Android.
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <jni.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# endif 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// include platform dependent structs
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <openxr/openxr_platform.h> 
  
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  OpenXRVulkanExtension  :  public  OpenXRGraphicsExtensionWrapper ,  VulkanHooks  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									OpenXRVulkanExtension ( OpenXRAPI  * p_openxr_api ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  ~ OpenXRVulkanExtension ( )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  on_instance_created ( const  XrInstance  p_instance )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  * set_session_create_and_get_next_pointer ( void  * p_next_pointer )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-02-23 18:07:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  create_vulkan_instance ( const  VkInstanceCreateInfo  * p_vulkan_create_info ,  VkInstance  * r_instance )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  bool  get_physical_device ( VkPhysicalDevice  * r_device )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  bool  create_vulkan_device ( const  VkDeviceCreateInfo  * p_device_create_info ,  VkDevice  * r_device )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  get_usable_swapchain_formats ( Vector < int64_t >  & p_usable_swap_chains )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  void  get_usable_depth_formats ( Vector < int64_t >  & p_usable_swap_chains )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									virtual  String  get_swapchain_format_name ( int64_t  p_swapchain_format )  const  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									virtual  void  cleanup_swapchain_graphics_data ( void  * * p_swapchain_graphics_data )  override ; 
							 
						 
					
						
							
								
									
										
										
											
												Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
											 
										 
										
											2022-07-20 01:11:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  bool  create_projection_fov ( const  XrFovf  p_fov ,  double  p_z_near ,  double  p_z_far ,  Projection  & r_camera_matrix )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									virtual  RID  get_texture ( void  * p_swapchain_graphics_data ,  int  p_image_index )  override ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								private :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									static  OpenXRVulkanExtension  * singleton ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									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
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  SwapchainGraphicsData  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										bool  is_multiview ; 
							 
						 
					
						
							
								
									
										
										
										
											2022-09-01 18:10:53 +10:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										Vector < RID >  texture_rids ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									bool  check_graphics_api_support ( XrVersion  p_desired_version ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-05-02 16:28:25 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									VkInstance  vulkan_instance  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									VkPhysicalDevice  vulkan_physical_device  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									VkDevice  vulkan_device  =  nullptr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uint32_t  vulkan_queue_family_index  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									uint32_t  vulkan_queue_index  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-09-24 13:56:00 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									EXT_PROTO_XRRESULT_FUNC3 ( xrGetVulkanGraphicsRequirements2KHR ,  ( XrInstance ) ,  p_instance ,  ( XrSystemId ) ,  p_system_id ,  ( XrGraphicsRequirementsVulkanKHR  * ) ,  p_graphics_requirements ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EXT_PROTO_XRRESULT_FUNC4 ( xrCreateVulkanInstanceKHR ,  ( XrInstance ) ,  p_instance ,  ( const  XrVulkanInstanceCreateInfoKHR  * ) ,  p_create_info ,  ( VkInstance  * ) ,  r_vulkan_instance ,  ( VkResult  * ) ,  r_vulkan_result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EXT_PROTO_XRRESULT_FUNC3 ( xrGetVulkanGraphicsDevice2KHR ,  ( XrInstance ) ,  p_instance ,  ( const  XrVulkanGraphicsDeviceGetInfoKHR  * ) ,  p_get_info ,  ( VkPhysicalDevice  * ) ,  r_vulkan_physical_device ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EXT_PROTO_XRRESULT_FUNC4 ( xrCreateVulkanDeviceKHR ,  ( XrInstance ) ,  p_instance ,  ( const  XrVulkanDeviceCreateInfoKHR  * ) ,  p_create_info ,  ( VkDevice  * ) ,  r_device ,  ( VkResult  * ) ,  r_result ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									EXT_PROTO_XRRESULT_FUNC4 ( xrEnumerateSwapchainImages ,  ( XrSwapchain ) ,  p_swapchain ,  ( uint32_t ) ,  p_image_capacity_input ,  ( uint32_t  * ) ,  p_image_count_output ,  ( XrSwapchainImageBaseHeader  * ) ,  p_images ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 12:44:12 +11:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-07-23 23:41:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# endif  // OPENXR_VULKAN_EXTENSION_H