mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-31 05:52:11 +01:00
Merge branch 'vr-init'
This commit is contained in:
commit
3bb94f1afb
@ -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() { }
|
||||||
@ -34,15 +45,13 @@ namespace dxvk {
|
|||||||
void VrInstance::initInstanceExtensions() {
|
void VrInstance::initInstanceExtensions() {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
if (m_initializedInsExt)
|
if (m_compositor == nullptr)
|
||||||
return;
|
m_compositor = this->getCompositor();
|
||||||
|
|
||||||
vr::IVRCompositor* compositor = this->getCompositor();
|
|
||||||
|
|
||||||
if (compositor == nullptr)
|
if (m_compositor == nullptr || m_initializedInsExt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_insExtensions = this->queryInstanceExtensions(compositor);
|
m_insExtensions = this->queryInstanceExtensions();
|
||||||
m_initializedInsExt = true;
|
m_initializedInsExt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,40 +59,38 @@ namespace dxvk {
|
|||||||
void VrInstance::initDeviceExtensions(const DxvkInstance* instance) {
|
void VrInstance::initDeviceExtensions(const DxvkInstance* instance) {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
if (m_initializedDevExt)
|
if (m_compositor == nullptr || m_initializedDevExt)
|
||||||
return;
|
|
||||||
|
|
||||||
vr::IVRCompositor* compositor = this->getCompositor();
|
|
||||||
|
|
||||||
if (compositor == nullptr)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (uint32_t i = 0; instance->enumAdapters(i) != nullptr; i++) {
|
for (uint32_t i = 0; instance->enumAdapters(i) != nullptr; i++) {
|
||||||
m_devExtensions.push_back(this->queryDeviceExtensions(
|
m_devExtensions.push_back(this->queryDeviceExtensions(
|
||||||
compositor, instance->enumAdapters(i)->handle()));
|
instance->enumAdapters(i)->handle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_initializedOpenVr)
|
||||||
|
g_vrFunctions.shutdownInternal();
|
||||||
|
|
||||||
m_initializedDevExt = true;
|
m_initializedDevExt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vk::NameSet VrInstance::queryInstanceExtensions(vr::IVRCompositor* compositor) const {
|
vk::NameSet VrInstance::queryInstanceExtensions() const {
|
||||||
uint32_t len = compositor->GetVulkanInstanceExtensionsRequired(nullptr, 0);
|
uint32_t len = m_compositor->GetVulkanInstanceExtensionsRequired(nullptr, 0);
|
||||||
std::vector<char> extensionList(len);
|
std::vector<char> extensionList(len);
|
||||||
len = compositor->GetVulkanInstanceExtensionsRequired(extensionList.data(), len);
|
len = m_compositor->GetVulkanInstanceExtensionsRequired(extensionList.data(), len);
|
||||||
return parseExtensionList(std::string(extensionList.data(), len));
|
return parseExtensionList(std::string(extensionList.data(), len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vk::NameSet VrInstance::queryDeviceExtensions(vr::IVRCompositor* compositor, VkPhysicalDevice adapter) const {
|
vk::NameSet VrInstance::queryDeviceExtensions(VkPhysicalDevice adapter) const {
|
||||||
uint32_t len = compositor->GetVulkanDeviceExtensionsRequired(adapter, nullptr, 0);
|
uint32_t len = m_compositor->GetVulkanDeviceExtensionsRequired(adapter, nullptr, 0);
|
||||||
std::vector<char> extensionList(len);
|
std::vector<char> extensionList(len);
|
||||||
len = compositor->GetVulkanDeviceExtensionsRequired(adapter, extensionList.data(), len);
|
len = m_compositor->GetVulkanDeviceExtensionsRequired(adapter, extensionList.data(), len);
|
||||||
return parseExtensionList(std::string(extensionList.data(), len));
|
return parseExtensionList(std::string(extensionList.data(), len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
@ -97,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");
|
||||||
|
|
||||||
@ -109,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;
|
||||||
}
|
}
|
||||||
@ -120,15 +125,38 @@ 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::warn("OpenVR: Compositor interface found");
|
Logger::info("OpenVR: Compositor interface found");
|
||||||
return compositor;
|
return compositor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,12 +7,13 @@
|
|||||||
|
|
||||||
namespace vr {
|
namespace vr {
|
||||||
class IVRCompositor;
|
class IVRCompositor;
|
||||||
|
class IVRSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
class DxvkInstance;
|
class DxvkInstance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief OpenVR instance
|
* \brief OpenVR instance
|
||||||
*
|
*
|
||||||
@ -63,24 +64,25 @@ namespace dxvk {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
|
vr::IVRCompositor* m_compositor = nullptr;
|
||||||
|
|
||||||
|
bool m_initializedOpenVr = false;
|
||||||
bool m_initializedInsExt = false;
|
bool m_initializedInsExt = false;
|
||||||
bool m_initializedDevExt = false;
|
bool m_initializedDevExt = false;
|
||||||
|
|
||||||
vk::NameSet m_insExtensions;
|
vk::NameSet m_insExtensions;
|
||||||
std::vector<vk::NameSet> m_devExtensions;
|
std::vector<vk::NameSet> m_devExtensions;
|
||||||
|
|
||||||
vk::NameSet queryInstanceExtensions(
|
vk::NameSet queryInstanceExtensions() const;
|
||||||
vr::IVRCompositor* compositor) const;
|
|
||||||
|
|
||||||
vk::NameSet queryDeviceExtensions(
|
vk::NameSet queryDeviceExtensions(
|
||||||
vr::IVRCompositor* compositor,
|
|
||||||
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