Path: blob/master/thirdparty/openxr/src/loader/runtime_interface.hpp
9917 views
// Copyright (c) 2017-2025 The Khronos Group Inc.1// Copyright (c) 2017-2019 Valve Corporation2// Copyright (c) 2017-2019 LunarG, Inc.3//4// SPDX-License-Identifier: Apache-2.0 OR MIT5//6// Initial Author: Mark Young <[email protected]>7//89#pragma once1011#include "loader_platform.hpp"1213#include <openxr/openxr.h>1415#include <string>16#include <vector>17#include <unordered_map>18#include <mutex>19#include <memory>2021namespace Json {22class Value;23}2425class RuntimeManifestFile;26struct XrGeneratedDispatchTableCore;2728class RuntimeInterface {29public:30virtual ~RuntimeInterface();3132// Helper functions for loading and unloading the runtime (but only when necessary)33static XrResult LoadRuntime(const std::string& openxr_command);34static void UnloadRuntime(const std::string& openxr_command);35static RuntimeInterface& GetRuntime() { return *(GetInstance().get()); }36static XrResult GetInstanceProcAddr(XrInstance instance, const char* name, PFN_xrVoidFunction* function);3738// Get the direct dispatch table to this runtime, without API layers or loader terminators.39static const XrGeneratedDispatchTableCore* GetDispatchTable(XrInstance instance);40static const XrGeneratedDispatchTableCore* GetDebugUtilsMessengerDispatchTable(XrDebugUtilsMessengerEXT messenger);4142void GetInstanceExtensionProperties(std::vector<XrExtensionProperties>& extension_properties);43bool SupportsExtension(const std::string& extension_name);44XrResult CreateInstance(const XrInstanceCreateInfo* info, XrInstance* instance);45XrResult DestroyInstance(XrInstance instance);46bool TrackDebugMessenger(XrInstance instance, XrDebugUtilsMessengerEXT messenger);47void ForgetDebugMessenger(XrDebugUtilsMessengerEXT messenger);4849// No default construction50RuntimeInterface() = delete;5152// Non-copyable53RuntimeInterface(const RuntimeInterface&) = delete;54RuntimeInterface& operator=(const RuntimeInterface&) = delete;5556private:57RuntimeInterface(LoaderPlatformLibraryHandle runtime_library, PFN_xrGetInstanceProcAddr get_instance_proc_addr);58void SetSupportedExtensions(std::vector<std::string>& supported_extensions);59static XrResult TryLoadingSingleRuntime(const std::string& openxr_command, std::unique_ptr<RuntimeManifestFile>& manifest_file);6061static std::unique_ptr<RuntimeInterface>& GetInstance() {62static std::unique_ptr<RuntimeInterface> instance;63return instance;64}6566LoaderPlatformLibraryHandle _runtime_library;67PFN_xrGetInstanceProcAddr _get_instance_proc_addr;68std::unordered_map<XrInstance, std::unique_ptr<XrGeneratedDispatchTableCore>> _dispatch_table_map;69std::mutex _dispatch_table_mutex;70std::unordered_map<XrDebugUtilsMessengerEXT, XrInstance> _messenger_to_instance_map;71std::mutex _messenger_to_instance_mutex;72std::vector<std::string> _supported_extensions;73};747576