mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-22 07:54:15 +01:00
[vr] Initialize and shut down OpenVR if necessary
This commit is contained in:
parent
cf6e3c1fbf
commit
092331232b
@ -7,9 +7,20 @@
|
|||||||
|
|
||||||
#include <openvr/openvr.hpp>
|
#include <openvr/openvr.hpp>
|
||||||
|
|
||||||
|
using VR_InitInternalProc = vr::IVRSystem* (VR_CALLTYPE *)(vr::EVRInitError*, vr::EVRApplicationType);
|
||||||
|
using VR_ShutdownInternalProc = void (VR_CALLTYPE *)();
|
||||||
|
using VR_GetGenericInterfaceProc = void* (VR_CALLTYPE *)(const char*, vr::EVRInitError*);
|
||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
VrInstance g_vrInstance;
|
struct VrFunctions {
|
||||||
|
VR_InitInternalProc initInternal = nullptr;
|
||||||
|
VR_ShutdownInternalProc shutdownInternal = nullptr;
|
||||||
|
VR_GetGenericInterfaceProc getGenericInterface = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
VrFunctions g_vrFunctions;
|
||||||
|
VrInstance g_vrInstance;
|
||||||
|
|
||||||
VrInstance:: VrInstance() { }
|
VrInstance:: VrInstance() { }
|
||||||
VrInstance::~VrInstance() { }
|
VrInstance::~VrInstance() { }
|
||||||
@ -57,7 +68,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_initializedOpenVr)
|
if (m_initializedOpenVr)
|
||||||
/* shutdown */;
|
g_vrFunctions.shutdownInternal();
|
||||||
|
|
||||||
m_initializedDevExt = true;
|
m_initializedDevExt = true;
|
||||||
}
|
}
|
||||||
@ -79,7 +90,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vk::NameSet VrInstance::parseExtensionList(const std::string& str) {
|
vk::NameSet VrInstance::parseExtensionList(const std::string& str) const {
|
||||||
vk::NameSet result;
|
vk::NameSet result;
|
||||||
|
|
||||||
std::stringstream strstream(str);
|
std::stringstream strstream(str);
|
||||||
@ -93,9 +104,6 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
vr::IVRCompositor* VrInstance::getCompositor() {
|
vr::IVRCompositor* VrInstance::getCompositor() {
|
||||||
using GetGenericInterfaceProc =
|
|
||||||
void* (VR_CALLTYPE *)(const char*, vr::EVRInitError*);
|
|
||||||
|
|
||||||
// Locate the OpenVR DLL if loaded by the process
|
// Locate the OpenVR DLL if loaded by the process
|
||||||
HMODULE ovrApi = ::GetModuleHandle("openvr_api.dll");
|
HMODULE ovrApi = ::GetModuleHandle("openvr_api.dll");
|
||||||
|
|
||||||
@ -105,10 +113,11 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load method used to retrieve the IVRCompositor interface
|
// Load method used to retrieve the IVRCompositor interface
|
||||||
auto vrGetGenericInterface = reinterpret_cast<GetGenericInterfaceProc>(
|
g_vrFunctions.initInternal = reinterpret_cast<VR_InitInternalProc> (::GetProcAddress(ovrApi, "VR_InitInternal"));
|
||||||
::GetProcAddress(ovrApi, "VR_GetGenericInterface"));
|
g_vrFunctions.shutdownInternal = reinterpret_cast<VR_ShutdownInternalProc> (::GetProcAddress(ovrApi, "VR_ShutdownInternal"));
|
||||||
|
g_vrFunctions.getGenericInterface = reinterpret_cast<VR_GetGenericInterfaceProc>(::GetProcAddress(ovrApi, "VR_GetGenericInterface"));
|
||||||
|
|
||||||
if (vrGetGenericInterface == nullptr) {
|
if (g_vrFunctions.getGenericInterface == nullptr) {
|
||||||
Logger::warn("OpenVR: VR_GetGenericInterface not found");
|
Logger::warn("OpenVR: VR_GetGenericInterface not found");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -116,12 +125,35 @@ namespace dxvk {
|
|||||||
// Retrieve the compositor interface
|
// Retrieve the compositor interface
|
||||||
vr::EVRInitError error = vr::VRInitError_None;
|
vr::EVRInitError error = vr::VRInitError_None;
|
||||||
|
|
||||||
auto compositor = reinterpret_cast<vr::IVRCompositor*>(
|
vr::IVRCompositor* compositor = reinterpret_cast<vr::IVRCompositor*>(
|
||||||
vrGetGenericInterface(vr::IVRCompositor_Version, &error));
|
g_vrFunctions.getGenericInterface(vr::IVRCompositor_Version, &error));
|
||||||
|
|
||||||
if (error != vr::VRInitError_None) {
|
if (error != vr::VRInitError_None || compositor == nullptr) {
|
||||||
Logger::warn(str::format("OpenVR: Failed to retrieve ", vr::IVRCompositor_Version));
|
if (g_vrFunctions.initInternal == nullptr
|
||||||
return nullptr;
|
|| g_vrFunctions.shutdownInternal == nullptr) {
|
||||||
|
Logger::warn("OpenVR: VR_InitInternal or VR_ShutdownInternal not found");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the app has not initialized OpenVR yet, we need
|
||||||
|
// to do it now in order to grab a compositor instance
|
||||||
|
g_vrFunctions.initInternal(&error, vr::VRApplication_Background);
|
||||||
|
m_initializedOpenVr = error == vr::VRInitError_None;
|
||||||
|
|
||||||
|
if (error != vr::VRInitError_None) {
|
||||||
|
Logger::warn("OpenVR: Failed to initialize OpenVR");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
compositor = reinterpret_cast<vr::IVRCompositor*>(
|
||||||
|
g_vrFunctions.getGenericInterface(vr::IVRCompositor_Version, &error));
|
||||||
|
|
||||||
|
if (error != vr::VRInitError_None || compositor == nullptr) {
|
||||||
|
Logger::warn("OpenVR: Failed to query compositor interface");
|
||||||
|
g_vrFunctions.shutdownInternal();
|
||||||
|
m_initializedOpenVr = false;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info("OpenVR: Compositor interface found");
|
Logger::info("OpenVR: Compositor interface found");
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
namespace vr {
|
namespace vr {
|
||||||
class IVRCompositor;
|
class IVRCompositor;
|
||||||
|
class IVRSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
@ -64,7 +65,7 @@ namespace dxvk {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
vr::IVRCompositor* m_compositor;
|
vr::IVRCompositor* m_compositor = nullptr;
|
||||||
|
|
||||||
bool m_initializedOpenVr = false;
|
bool m_initializedOpenVr = false;
|
||||||
bool m_initializedInsExt = false;
|
bool m_initializedInsExt = false;
|
||||||
@ -78,9 +79,10 @@ namespace dxvk {
|
|||||||
vk::NameSet queryDeviceExtensions(
|
vk::NameSet queryDeviceExtensions(
|
||||||
VkPhysicalDevice adapter) const;
|
VkPhysicalDevice adapter) const;
|
||||||
|
|
||||||
static vk::NameSet parseExtensionList(const std::string& str);
|
vk::NameSet parseExtensionList(
|
||||||
|
const std::string& str) const;
|
||||||
|
|
||||||
static vr::IVRCompositor* getCompositor();
|
vr::IVRCompositor* getCompositor();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user