openxr_sys/
loader.rs

1use crate::generated::*;
2use crate::support::fmt_enum;
3use crate::Version;
4
5/// Function pointer prototype for the xrCreateApiLayerInstance function used in place of xrCreateInstance.
6/// This function allows us to pass special API layer information to each layer during the process of creating an Instance.
7pub type FnCreateApiLayerInstance = unsafe extern "system" fn(
8    info: *const InstanceCreateInfo,
9    api_layer_info: *const ApiLayerCreateInfo,
10    instance: *mut Instance,
11) -> Result;
12
13/// Loader/API Layer Interface versions
14///
15///  1 - First version, introduces negotiation structure and functions
16pub const CURRENT_LOADER_API_LAYER_VERSION: u32 = 1;
17
18/// Loader/Runtime Interface versions
19///
20///  1 - First version, introduces negotiation structure and functions
21pub const CURRENT_LOADER_RUNTIME_VERSION: u32 = 1;
22
23#[repr(transparent)]
24#[derive(Copy, Clone, Eq, PartialEq)]
25pub struct LoaderInterfaceStructureType(i32);
26impl LoaderInterfaceStructureType {
27    pub const UNINTIALIZED: Self = Self(0);
28    pub const LOADER_INFO: Self = Self(1);
29    pub const API_LAYER_REQUEST: Self = Self(2);
30    pub const RUNTIME_REQUEST: Self = Self(3);
31    pub const API_LAYER_CREATE_INFO: Self = Self(4);
32    pub const API_LAYER_NEXT_INFO: Self = Self(5);
33}
34
35impl core::fmt::Debug for LoaderInterfaceStructureType {
36    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        let name = match *self {
38            Self::UNINTIALIZED => Some("UNINTIALIZED"),
39            Self::LOADER_INFO => Some("LOADER_INFO"),
40            Self::API_LAYER_REQUEST => Some("API_LAYER_REQUEST"),
41            Self::RUNTIME_REQUEST => Some("RUNTIME_REQUEST"),
42            Self::API_LAYER_CREATE_INFO => Some("API_LAYER_CREATE_INFO"),
43            Self::API_LAYER_NEXT_INFO => Some("API_LAYER_NEXT_INFO"),
44            _ => None,
45        };
46        fmt_enum(fmt, self.0, name)
47    }
48}
49
50#[repr(C)]
51#[derive(Copy, Clone, Debug)]
52pub struct XrNegotiateLoaderInfo {
53    pub ty: LoaderInterfaceStructureType,
54    pub struct_version: u32,
55    pub struct_size: usize,
56    pub min_interface_version: u32,
57    pub max_interface_version: u32,
58    pub min_api_version: Version,
59    pub max_api_version: Version,
60}
61impl XrNegotiateLoaderInfo {
62    pub const TYPE: LoaderInterfaceStructureType = LoaderInterfaceStructureType::LOADER_INFO;
63    pub const VERSION: u32 = 1;
64}
65
66#[repr(C)]
67#[derive(Copy, Clone)]
68pub struct XrNegotiateApiLayerRequest {
69    pub ty: LoaderInterfaceStructureType,
70    pub struct_version: u32,
71    pub struct_size: usize,
72    pub layer_interface_version: u32,
73    pub layer_api_version: Version,
74    pub get_instance_proc_addr: Option<pfn::GetInstanceProcAddr>,
75    pub create_api_layer_instance: Option<FnCreateApiLayerInstance>,
76}
77impl XrNegotiateApiLayerRequest {
78    pub const TYPE: LoaderInterfaceStructureType = LoaderInterfaceStructureType::API_LAYER_REQUEST;
79    pub const VERSION: u32 = 1;
80}
81
82#[repr(C)]
83#[derive(Copy, Clone)]
84pub struct XrNegotiateRuntimeRequest {
85    pub ty: LoaderInterfaceStructureType,
86    pub struct_version: u32,
87    pub struct_size: usize,
88    pub runtime_interface_version: u32,
89    pub runtime_api_version: Version,
90    pub get_instance_proc_addr: Option<pfn::GetInstanceProcAddr>,
91}
92impl XrNegotiateRuntimeRequest {
93    pub const TYPE: LoaderInterfaceStructureType = LoaderInterfaceStructureType::RUNTIME_REQUEST;
94    pub const VERSION: u32 = 1;
95}
96
97/// Function used to negotiate an interface between the loader and an API layer.  Each library exposing one or
98/// more API layers needs to expose at least this function.
99pub type FnNegotiateLoaderApiLayerInterface = unsafe extern "system" fn(
100    loader_info: *const XrNegotiateLoaderInfo,
101    api_layer_name: *const i8,
102    api_layer_request: *mut XrNegotiateApiLayerRequest,
103) -> Result;
104
105/// Function used to negotiate an interface between the loader and a runtime.  Each runtime should expose
106/// at least this function.
107pub type FnNegotiateLoaderRuntimeInterface = unsafe extern "system" fn(
108    loader_info: *const XrNegotiateLoaderInfo,
109    runtime_request: *mut XrNegotiateRuntimeRequest,
110) -> Result;
111
112#[repr(C)]
113#[derive(Copy, Clone)]
114pub struct XrApiLayerNextInfo {
115    pub ty: LoaderInterfaceStructureType,
116    pub struct_version: u32,
117    pub struct_size: usize,
118    /// Name of API layer which should receive this info
119    pub layer_name: [i8; MAX_API_LAYER_NAME_SIZE],
120    /// Pointer to next API layer's xrGetInstanceProcAddr
121    pub next_get_instance_proc_addr: pfn::GetInstanceProcAddr,
122    /// Pointer to next API layer's xrCreateApiLayerInstance
123    pub next_create_api_layer_instance: FnCreateApiLayerInstance,
124    /// Pointer to the next API layer info in the sequence
125    pub next: *mut XrApiLayerNextInfo,
126}
127impl XrApiLayerNextInfo {
128    pub const TYPE: LoaderInterfaceStructureType =
129        LoaderInterfaceStructureType::API_LAYER_NEXT_INFO;
130    pub const VERSION: u32 = 1;
131}
132
133pub const API_LAYER_MAX_SETTINGS_PATH_SIZE: usize = 512;
134
135#[repr(C)]
136#[derive(Copy, Clone, Debug)]
137pub struct ApiLayerCreateInfo {
138    pub ty: LoaderInterfaceStructureType,
139    pub struct_version: u32,
140    pub struct_size: usize,
141    /// Pointer to the LoaderInstance class
142    pub loader_instance: *const (),
143    /// Location to the found settings file (or empty '\0')
144    pub settings_file_location: [i8; API_LAYER_MAX_SETTINGS_PATH_SIZE],
145    /// Pointer to the next API layer's Info
146    pub next_info: *mut XrApiLayerNextInfo,
147}
148impl ApiLayerCreateInfo {
149    pub const TYPE: LoaderInterfaceStructureType =
150        LoaderInterfaceStructureType::API_LAYER_CREATE_INFO;
151    pub const VERSION: u32 = 1;
152}