1 | // Copyright (c) 2017-2023, The Khronos Group Inc. |
2 | // Copyright (c) 2017 Valve Corporation |
3 | // Copyright (c) 2017 LunarG, Inc. |
4 | // |
5 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
6 | // |
7 | // Initial Author: Mark Young <marky@lunarg.com> |
8 | // |
9 | |
10 | #pragma once |
11 | |
12 | #include <openxr/openxr.h> |
13 | |
14 | #ifdef __cplusplus |
15 | extern "C" { |
16 | #endif |
17 | |
18 | // Forward declare. |
19 | typedef struct XrApiLayerCreateInfo XrApiLayerCreateInfo; |
20 | |
21 | // Function pointer prototype for the xrCreateApiLayerInstance function used in place of xrCreateInstance. |
22 | // This function allows us to pass special API layer information to each layer during the process of creating an Instance. |
23 | typedef XrResult(XRAPI_PTR *PFN_xrCreateApiLayerInstance)(const XrInstanceCreateInfo *info, |
24 | const XrApiLayerCreateInfo *apiLayerInfo, XrInstance *instance); |
25 | |
26 | // Loader/API Layer Interface versions |
27 | // 1 - First version, introduces negotiation structure and functions |
28 | #define XR_CURRENT_LOADER_API_LAYER_VERSION 1 |
29 | |
30 | // Loader/Runtime Interface versions |
31 | // 1 - First version, introduces negotiation structure and functions |
32 | #define XR_CURRENT_LOADER_RUNTIME_VERSION 1 |
33 | |
34 | // Version negotiation values |
35 | typedef enum XrLoaderInterfaceStructs { |
36 | XR_LOADER_INTERFACE_STRUCT_UNINTIALIZED = 0, |
37 | XR_LOADER_INTERFACE_STRUCT_LOADER_INFO, |
38 | XR_LOADER_INTERFACE_STRUCT_API_LAYER_REQUEST, |
39 | XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST, |
40 | XR_LOADER_INTERFACE_STRUCT_API_LAYER_CREATE_INFO, |
41 | XR_LOADER_INTERFACE_STRUCT_API_LAYER_NEXT_INFO, |
42 | } XrLoaderInterfaceStructs; |
43 | |
44 | #define XR_LOADER_INFO_STRUCT_VERSION 1 |
45 | typedef struct XrNegotiateLoaderInfo { |
46 | XrLoaderInterfaceStructs structType; // XR_LOADER_INTERFACE_STRUCT_LOADER_INFO |
47 | uint32_t structVersion; // XR_LOADER_INFO_STRUCT_VERSION |
48 | size_t structSize; // sizeof(XrNegotiateLoaderInfo) |
49 | uint32_t minInterfaceVersion; |
50 | uint32_t maxInterfaceVersion; |
51 | XrVersion minApiVersion; |
52 | XrVersion maxApiVersion; |
53 | } XrNegotiateLoaderInfo; |
54 | |
55 | #define XR_API_LAYER_INFO_STRUCT_VERSION 1 |
56 | typedef struct XrNegotiateApiLayerRequest { |
57 | XrLoaderInterfaceStructs structType; // XR_LOADER_INTERFACE_STRUCT_API_LAYER_REQUEST |
58 | uint32_t structVersion; // XR_API_LAYER_INFO_STRUCT_VERSION |
59 | size_t structSize; // sizeof(XrNegotiateApiLayerRequest) |
60 | uint32_t layerInterfaceVersion; // CURRENT_LOADER_API_LAYER_VERSION |
61 | XrVersion layerApiVersion; |
62 | PFN_xrGetInstanceProcAddr getInstanceProcAddr; |
63 | PFN_xrCreateApiLayerInstance createApiLayerInstance; |
64 | } XrNegotiateApiLayerRequest; |
65 | |
66 | #define XR_RUNTIME_INFO_STRUCT_VERSION 1 |
67 | typedef struct XrNegotiateRuntimeRequest { |
68 | XrLoaderInterfaceStructs structType; // XR_LOADER_INTERFACE_STRUCT_RUNTIME_REQUEST |
69 | uint32_t structVersion; // XR_RUNTIME_INFO_STRUCT_VERSION |
70 | size_t structSize; // sizeof(XrNegotiateRuntimeRequest) |
71 | uint32_t runtimeInterfaceVersion; // CURRENT_LOADER_RUNTIME_VERSION |
72 | XrVersion runtimeApiVersion; |
73 | PFN_xrGetInstanceProcAddr getInstanceProcAddr; |
74 | } XrNegotiateRuntimeRequest; |
75 | |
76 | // Function used to negotiate an interface betewen the loader and an API layer. Each library exposing one or |
77 | // more API layers needs to expose at least this function. |
78 | typedef XrResult(XRAPI_PTR *PFN_xrNegotiateLoaderApiLayerInterface)(const XrNegotiateLoaderInfo *loaderInfo, |
79 | const char *apiLayerName, |
80 | XrNegotiateApiLayerRequest *apiLayerRequest); |
81 | |
82 | // Function used to negotiate an interface betewen the loader and a runtime. Each runtime should expose |
83 | // at least this function. |
84 | typedef XrResult(XRAPI_PTR *PFN_xrNegotiateLoaderRuntimeInterface)(const XrNegotiateLoaderInfo *loaderInfo, |
85 | XrNegotiateRuntimeRequest *runtimeRequest); |
86 | |
87 | // Forward declare. |
88 | typedef struct XrApiLayerNextInfo XrApiLayerNextInfo; |
89 | |
90 | #define XR_API_LAYER_NEXT_INFO_STRUCT_VERSION 1 |
91 | struct XrApiLayerNextInfo { |
92 | XrLoaderInterfaceStructs structType; // XR_LOADER_INTERFACE_STRUCT_API_LAYER_NEXT_INFO |
93 | uint32_t structVersion; // XR_API_LAYER_NEXT_INFO_STRUCT_VERSION |
94 | size_t structSize; // sizeof(XrApiLayerNextInfo) |
95 | char layerName[XR_MAX_API_LAYER_NAME_SIZE]; // Name of API layer which should receive this info |
96 | PFN_xrGetInstanceProcAddr nextGetInstanceProcAddr; // Pointer to next API layer's xrGetInstanceProcAddr |
97 | PFN_xrCreateApiLayerInstance nextCreateApiLayerInstance; // Pointer to next API layer's xrCreateApiLayerInstance |
98 | XrApiLayerNextInfo *next; // Pointer to the next API layer info in the sequence |
99 | }; |
100 | |
101 | #define XR_API_LAYER_MAX_SETTINGS_PATH_SIZE 512 |
102 | #define XR_API_LAYER_CREATE_INFO_STRUCT_VERSION 1 |
103 | typedef struct XrApiLayerCreateInfo { |
104 | XrLoaderInterfaceStructs structType; // XR_LOADER_INTERFACE_STRUCT_API_LAYER_CREATE_INFO |
105 | uint32_t structVersion; // XR_API_LAYER_CREATE_INFO_STRUCT_VERSION |
106 | size_t structSize; // sizeof(XrApiLayerCreateInfo) |
107 | void *loaderInstance; // Pointer to the LoaderInstance class |
108 | char settings_file_location[XR_API_LAYER_MAX_SETTINGS_PATH_SIZE]; // Location to the found settings file (or empty '\0') |
109 | XrApiLayerNextInfo *nextInfo; // Pointer to the next API layer's Info |
110 | } XrApiLayerCreateInfo; |
111 | |
112 | #ifdef __cplusplus |
113 | } // extern "C" |
114 | #endif |
115 | |