Path: blob/master/thirdparty/openxr/src/loader/loader_instance.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 "extra_algorithms.h"1213#include <openxr/openxr.h>14#include <openxr/openxr_loader_negotiation.h>1516#include <array>17#include <cmath>18#include <memory>19#include <mutex>20#include <string>21#include <unordered_map>22#include <vector>2324class ApiLayerInterface;25struct XrGeneratedDispatchTableCore;26class LoaderInstance;2728// Manage the single loader instance that is available.29namespace ActiveLoaderInstance {30// Set the active loader instance. This will fail if there is already an active loader instance.31XrResult Set(std::unique_ptr<LoaderInstance> loader_instance, const char* log_function_name);3233// Returns true if there is an active loader instance.34bool IsAvailable();3536// Get the active LoaderInstance.37XrResult Get(LoaderInstance** loader_instance, const char* log_function_name);3839// Destroy the currently active LoaderInstance if there is one. This will make the loader able to create a new XrInstance if needed.40void Remove();41}; // namespace ActiveLoaderInstance4243// Manages information needed by the loader for an XrInstance, such as what extensions are available and the dispatch table.44class LoaderInstance {45public:46// Factory method47static XrResult CreateInstance(PFN_xrGetInstanceProcAddr get_instance_proc_addr_term, PFN_xrCreateInstance create_instance_term,48PFN_xrCreateApiLayerInstance create_api_layer_instance_term,49std::vector<std::unique_ptr<ApiLayerInterface>> layer_interfaces,50const XrInstanceCreateInfo* createInfo, std::unique_ptr<LoaderInstance>* loader_instance);51static const std::array<XrExtensionProperties, 1>& LoaderSpecificExtensions();5253virtual ~LoaderInstance();5455XrInstance GetInstanceHandle() { return _runtime_instance; }56const std::unique_ptr<XrGeneratedDispatchTableCore>& DispatchTable() { return _dispatch_table; }57std::vector<std::unique_ptr<ApiLayerInterface>>& LayerInterfaces() { return _api_layer_interfaces; }58bool ExtensionIsEnabled(const std::string& extension);59XrDebugUtilsMessengerEXT DefaultDebugUtilsMessenger() { return _messenger; }60void SetDefaultDebugUtilsMessenger(XrDebugUtilsMessengerEXT messenger) { _messenger = messenger; }61XrResult GetInstanceProcAddr(const char* name, PFN_xrVoidFunction* function);6263private:64LoaderInstance(XrInstance instance, const XrInstanceCreateInfo* createInfo, PFN_xrGetInstanceProcAddr topmost_gipa,65std::vector<std::unique_ptr<ApiLayerInterface>> api_layer_interfaces);6667private:68XrInstance _runtime_instance{XR_NULL_HANDLE};69PFN_xrGetInstanceProcAddr _topmost_gipa{nullptr};70std::vector<std::string> _enabled_extensions;71std::vector<std::unique_ptr<ApiLayerInterface>> _api_layer_interfaces;7273std::unique_ptr<XrGeneratedDispatchTableCore> _dispatch_table;74// Internal debug messenger created during xrCreateInstance75XrDebugUtilsMessengerEXT _messenger{XR_NULL_HANDLE};76};777879