mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
Merge branch 'openvr-v2'
This commit is contained in:
commit
2c9c7e1a36
4323
include/openvr/openvr.hpp
Normal file
4323
include/openvr/openvr.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -171,6 +171,8 @@ namespace dxvk {
|
||||
|
||||
// Generate list of extensions that we're actually going to use
|
||||
vk::NameSet enabledExtensionSet = extensions->getEnabledExtensionNames();
|
||||
enabledExtensionSet.merge(m_instance->queryExtraDeviceExtensions(this));
|
||||
|
||||
vk::NameList enabledExtensionList = enabledExtensionSet.getNameList();
|
||||
|
||||
Logger::info("Enabled device extensions:");
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "dxvk_instance.h"
|
||||
#include "dxvk_openvr.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -39,6 +40,11 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
vk::NameSet DxvkInstance::queryExtraDeviceExtensions(const DxvkAdapter* adapter) const {
|
||||
return m_vr.queryDeviceExtensions(adapter->handle());
|
||||
}
|
||||
|
||||
|
||||
VkInstance DxvkInstance::createInstance() {
|
||||
// Query available extensions and enable the ones that are needed
|
||||
vk::NameSet availableExtensions = vk::NameSet::enumerateInstanceExtensions(*m_vkl);
|
||||
@ -51,6 +57,8 @@ namespace dxvk {
|
||||
|
||||
// Generate list of extensions that we're actually going to use
|
||||
vk::NameSet enabledExtensionSet = extensionsToEnable.getEnabledExtensionNames();
|
||||
enabledExtensionSet.merge(m_vr.queryInstanceExtensions());
|
||||
|
||||
vk::NameList enabledExtensionList = enabledExtensionSet.getNameList();
|
||||
|
||||
Logger::info("Enabled instance extensions:");
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "dxvk_adapter.h"
|
||||
#include "dxvk_device.h"
|
||||
#include "dxvk_openvr.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
@ -41,8 +42,19 @@ namespace dxvk {
|
||||
*/
|
||||
std::vector<Rc<DxvkAdapter>> enumAdapters();
|
||||
|
||||
/**
|
||||
* \brief Queries extra device extensions
|
||||
*
|
||||
* \param [in] adapter The device to query
|
||||
* \returns Extra device extensions
|
||||
*/
|
||||
vk::NameSet queryExtraDeviceExtensions(
|
||||
const DxvkAdapter* adapter) const;
|
||||
|
||||
private:
|
||||
|
||||
VrInstance m_vr;
|
||||
|
||||
Rc<vk::LibraryFn> m_vkl;
|
||||
Rc<vk::InstanceFn> m_vki;
|
||||
|
||||
|
87
src/dxvk/dxvk_openvr.cpp
Normal file
87
src/dxvk/dxvk_openvr.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "dxvk_openvr.h"
|
||||
|
||||
#include <openvr/openvr.hpp>
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
VrInstance::VrInstance()
|
||||
: m_compositor(getCompositor()) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
VrInstance::~VrInstance() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
vk::NameSet VrInstance::queryInstanceExtensions() const {
|
||||
if (m_compositor != nullptr) {
|
||||
uint32_t len = m_compositor->GetVulkanInstanceExtensionsRequired(nullptr, 0);
|
||||
std::vector<char> extensionList(len);
|
||||
len = m_compositor->GetVulkanInstanceExtensionsRequired(extensionList.data(), len);
|
||||
return parseExtensionList(std::string(extensionList.data(), len));
|
||||
} return vk::NameSet();
|
||||
}
|
||||
|
||||
|
||||
vk::NameSet VrInstance::queryDeviceExtensions(VkPhysicalDevice adapter) const {
|
||||
if (m_compositor != nullptr) {
|
||||
uint32_t len = m_compositor->GetVulkanDeviceExtensionsRequired(adapter, nullptr, 0);
|
||||
std::vector<char> extensionList(len);
|
||||
len = m_compositor->GetVulkanDeviceExtensionsRequired(adapter, extensionList.data(), len);
|
||||
return parseExtensionList(std::string(extensionList.data(), len));
|
||||
} return vk::NameSet();
|
||||
}
|
||||
|
||||
|
||||
vk::NameSet VrInstance::parseExtensionList(const std::string& str) {
|
||||
vk::NameSet result;
|
||||
|
||||
std::stringstream strstream(str);
|
||||
std::string section;
|
||||
|
||||
while (std::getline(strstream, section, ' '))
|
||||
result.add(section);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
vr::IVRCompositor* VrInstance::getCompositor() {
|
||||
using GetGenericInterfaceProc =
|
||||
void* VR_CALLTYPE (*)(const char*, vr::EVRInitError*);
|
||||
|
||||
// Locate the OpenVR DLL if loaded by the process
|
||||
HMODULE ovrApi = ::GetModuleHandle("openvr_api.dll");
|
||||
|
||||
if (ovrApi == nullptr) {
|
||||
Logger::warn("OpenVR: Failed to locate module");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Load method used to retrieve the IVRCompositor interface
|
||||
auto vrGetGenericInterface = reinterpret_cast<GetGenericInterfaceProc>(
|
||||
::GetProcAddress(ovrApi, "VR_GetGenericInterface"));
|
||||
|
||||
if (vrGetGenericInterface == nullptr) {
|
||||
Logger::warn("OpenVR: VR_GetGenericInterface not found");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Retrieve the compositor interface
|
||||
vr::EVRInitError error = vr::VRInitError_None;
|
||||
|
||||
auto compositor = reinterpret_cast<vr::IVRCompositor*>(
|
||||
vrGetGenericInterface(vr::IVRCompositor_Version, &error));
|
||||
|
||||
if (error != vr::VRInitError_None) {
|
||||
Logger::warn(str::format("OpenVR: Failed to retrieve ", vr::IVRCompositor_Version));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Logger::warn("OpenVR: Compositor interface found");
|
||||
return compositor;
|
||||
}
|
||||
|
||||
}
|
48
src/dxvk/dxvk_openvr.h
Normal file
48
src/dxvk/dxvk_openvr.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "dxvk_include.h"
|
||||
|
||||
namespace vr {
|
||||
class IVRCompositor;
|
||||
}
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
/**
|
||||
* \brief OpenVR instance
|
||||
*
|
||||
* Loads Initializes OpenVR to provide
|
||||
* access to Vulkan extension queries.
|
||||
*/
|
||||
class VrInstance {
|
||||
|
||||
public:
|
||||
|
||||
VrInstance();
|
||||
~VrInstance();
|
||||
|
||||
/**
|
||||
* \brief Queries required instance extensions
|
||||
* \returns Set of required instance extensions
|
||||
*/
|
||||
vk::NameSet queryInstanceExtensions() const;
|
||||
|
||||
/**
|
||||
* \brief Queries required device extensions
|
||||
*
|
||||
* \param [in] adapter The Vulkan device to query
|
||||
* \returns Set of required device extensions
|
||||
*/
|
||||
vk::NameSet queryDeviceExtensions(VkPhysicalDevice adapter) const;
|
||||
|
||||
private:
|
||||
|
||||
vr::IVRCompositor* m_compositor = nullptr;
|
||||
|
||||
static vk::NameSet parseExtensionList(const std::string& str);
|
||||
|
||||
static vr::IVRCompositor* getCompositor();
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -49,6 +49,7 @@ dxvk_src = files([
|
||||
'dxvk_meta_clear.cpp',
|
||||
'dxvk_meta_mipgen.cpp',
|
||||
'dxvk_meta_resolve.cpp',
|
||||
'dxvk_openvr.cpp',
|
||||
'dxvk_pipecache.cpp',
|
||||
'dxvk_pipecompiler.cpp',
|
||||
'dxvk_pipelayout.cpp',
|
||||
|
Loading…
x
Reference in New Issue
Block a user