Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/openxr/src/loader/runtime_interface.hpp
9917 views
1
// Copyright (c) 2017-2025 The Khronos Group Inc.
2
// Copyright (c) 2017-2019 Valve Corporation
3
// Copyright (c) 2017-2019 LunarG, Inc.
4
//
5
// SPDX-License-Identifier: Apache-2.0 OR MIT
6
//
7
// Initial Author: Mark Young <[email protected]>
8
//
9
10
#pragma once
11
12
#include "loader_platform.hpp"
13
14
#include <openxr/openxr.h>
15
16
#include <string>
17
#include <vector>
18
#include <unordered_map>
19
#include <mutex>
20
#include <memory>
21
22
namespace Json {
23
class Value;
24
}
25
26
class RuntimeManifestFile;
27
struct XrGeneratedDispatchTableCore;
28
29
class RuntimeInterface {
30
public:
31
virtual ~RuntimeInterface();
32
33
// Helper functions for loading and unloading the runtime (but only when necessary)
34
static XrResult LoadRuntime(const std::string& openxr_command);
35
static void UnloadRuntime(const std::string& openxr_command);
36
static RuntimeInterface& GetRuntime() { return *(GetInstance().get()); }
37
static XrResult GetInstanceProcAddr(XrInstance instance, const char* name, PFN_xrVoidFunction* function);
38
39
// Get the direct dispatch table to this runtime, without API layers or loader terminators.
40
static const XrGeneratedDispatchTableCore* GetDispatchTable(XrInstance instance);
41
static const XrGeneratedDispatchTableCore* GetDebugUtilsMessengerDispatchTable(XrDebugUtilsMessengerEXT messenger);
42
43
void GetInstanceExtensionProperties(std::vector<XrExtensionProperties>& extension_properties);
44
bool SupportsExtension(const std::string& extension_name);
45
XrResult CreateInstance(const XrInstanceCreateInfo* info, XrInstance* instance);
46
XrResult DestroyInstance(XrInstance instance);
47
bool TrackDebugMessenger(XrInstance instance, XrDebugUtilsMessengerEXT messenger);
48
void ForgetDebugMessenger(XrDebugUtilsMessengerEXT messenger);
49
50
// No default construction
51
RuntimeInterface() = delete;
52
53
// Non-copyable
54
RuntimeInterface(const RuntimeInterface&) = delete;
55
RuntimeInterface& operator=(const RuntimeInterface&) = delete;
56
57
private:
58
RuntimeInterface(LoaderPlatformLibraryHandle runtime_library, PFN_xrGetInstanceProcAddr get_instance_proc_addr);
59
void SetSupportedExtensions(std::vector<std::string>& supported_extensions);
60
static XrResult TryLoadingSingleRuntime(const std::string& openxr_command, std::unique_ptr<RuntimeManifestFile>& manifest_file);
61
62
static std::unique_ptr<RuntimeInterface>& GetInstance() {
63
static std::unique_ptr<RuntimeInterface> instance;
64
return instance;
65
}
66
67
LoaderPlatformLibraryHandle _runtime_library;
68
PFN_xrGetInstanceProcAddr _get_instance_proc_addr;
69
std::unordered_map<XrInstance, std::unique_ptr<XrGeneratedDispatchTableCore>> _dispatch_table_map;
70
std::mutex _dispatch_table_mutex;
71
std::unordered_map<XrDebugUtilsMessengerEXT, XrInstance> _messenger_to_instance_map;
72
std::mutex _messenger_to_instance_mutex;
73
std::vector<std::string> _supported_extensions;
74
};
75
76