XR: Re-enable SteamVR OpenGL backend for AMD gpus

Addresses T76082.

Since the DirectX backend does not work for AMD gpus
(wglDXRegisterObjectNV() fails to register the shared OpenGL-DirectX
render buffer, displaying a pink screen to the user), the original
solution was to use SteamVR's OpenGL backend, which, as tested
recently, seems to work without any issues on AMD hardware.

However, the SteamVR OpenGL backend (on Windows) was disabled in
fe492d922d since it resulted in crashes with NVIDIA gpus (and still
crashes, as tested recently), so SteamVR would always use the
AMD-incompatible DirectX backend (on Windows).

This patch restores use of the SteamVR OpenGL backend for non-NVIDIA
(AMD, etc.) gpus while maintaining the DirectX workaround for NVIDIA
gpus. In this way, issues are still resolved on the NVIDIA side but
AMD users can once again use the SteamVR runtime, which may be their
only viable option of using Blender in VR.

Reviewed By: Julian Eisel

Differential Revision: https://developer.blender.org/D12409
This commit is contained in:
Peter Kim 2021-09-10 13:01:14 +09:00
parent ee3b4e8420
commit 82ab2c1678
4 changed files with 21 additions and 6 deletions

View File

@ -652,6 +652,11 @@ typedef struct {
enum {
GHOST_kXrContextDebug = (1 << 0),
GHOST_kXrContextDebugTime = (1 << 1),
# ifdef WIN32
/* Needed to avoid issues with the SteamVR OpenGL graphics binding (use DirectX fallback
instead). */
GHOST_kXrContextGpuNVIDIA = (1 << 2),
# endif
};
typedef struct {

View File

@ -99,7 +99,7 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
storeInstanceProperties();
/* Multiple bindings may be enabled. Now that we know the runtime in use, settle for one. */
m_gpu_binding_type = determineGraphicsBindingTypeToUse(graphics_binding_types);
m_gpu_binding_type = determineGraphicsBindingTypeToUse(graphics_binding_types, create_info);
printInstanceInfo();
if (isDebugMode()) {
@ -473,14 +473,16 @@ std::vector<GHOST_TXrGraphicsBinding> GHOST_XrContext::determineGraphicsBindingT
}
GHOST_TXrGraphicsBinding GHOST_XrContext::determineGraphicsBindingTypeToUse(
const std::vector<GHOST_TXrGraphicsBinding> &enabled_types)
const std::vector<GHOST_TXrGraphicsBinding> &enabled_types,
const GHOST_XrContextCreateInfo *create_info)
{
/* Return the first working type. */
for (GHOST_TXrGraphicsBinding type : enabled_types) {
#ifdef WIN32
/* The SteamVR OpenGL backend fails currently. Disable it and allow falling back to the DirectX
* one. */
if ((m_runtime_id == OPENXR_RUNTIME_STEAMVR) && (type == GHOST_kXrGraphicsOpenGL)) {
/* The SteamVR OpenGL backend currently fails for NVIDIA gpus. Disable it and allow falling
* back to the DirectX one. */
if ((m_runtime_id == OPENXR_RUNTIME_STEAMVR) && (type == GHOST_kXrGraphicsOpenGL) &&
((create_info->context_flag & GHOST_kXrContextGpuNVIDIA) != 0)) {
continue;
}
#endif

View File

@ -139,5 +139,6 @@ class GHOST_XrContext : public GHOST_IXrContext {
std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
const GHOST_XrContextCreateInfo *create_info);
GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToUse(
const std::vector<GHOST_TXrGraphicsBinding> &enabled_types);
const std::vector<GHOST_TXrGraphicsBinding> &enabled_types,
const GHOST_XrContextCreateInfo *create_info);
};

View File

@ -35,6 +35,8 @@
#include "GHOST_C-api.h"
#include "GPU_platform.h"
#include "WM_api.h"
#include "wm_surface.h"
@ -91,6 +93,11 @@ bool wm_xr_init(wmWindowManager *wm)
if (G.debug & G_DEBUG_XR_TIME) {
create_info.context_flag |= GHOST_kXrContextDebugTime;
}
#ifdef WIN32
if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_WIN, GPU_DRIVER_ANY)) {
create_info.context_flag |= GHOST_kXrContextGpuNVIDIA;
}
#endif
if (!(context = GHOST_XrContextCreate(&create_info))) {
return false;