diff --git a/src/ModSettings.cpp b/src/ModSettings.cpp index ab7eebe..240e793 100644 --- a/src/ModSettings.cpp +++ b/src/ModSettings.cpp @@ -1,17 +1,10 @@ #include "ModSettings.h" -#include "mods/VR.hpp" - namespace ModSettings { InternalSettings g_internalSettings; bool showFlatScreenDisplay() { - static auto vr = VR::get(); - //TODO fix for openvr - if (vr->is_hmd_active() && vr->get_runtime()->is_openvr()) { - return false; - } return g_internalSettings.forceFlatScreen || g_internalSettings.showQuadDisplay; } } diff --git a/src/mods/vr/D3D11Component.cpp b/src/mods/vr/D3D11Component.cpp index ed39485..400758d 100644 --- a/src/mods/vr/D3D11Component.cpp +++ b/src/mods/vr/D3D11Component.cpp @@ -229,6 +229,7 @@ vr::EVRCompositorError D3D11Component::on_frame(VR* vr) { auto runtime = vr->get_runtime(); bool is_left_eye_frame = vr->m_presenter_frame_count % 2 == vr->m_left_eye_interval; bool is_right_eye_frame = !is_left_eye_frame; + bool flat_openvr = runtime->is_openvr() && ModSettings::showFlatScreenDisplay(); // Duplicate frames can sometimes cause the UI to get stuck on the screen. // and can lock up the compositor. @@ -302,33 +303,66 @@ vr::EVRCompositorError D3D11Component::on_frame(VR* vr) { } if (runtime->is_openvr()) { - vr::VRTextureWithPose_t left_eye{}; - left_eye.handle = (void*)m_left_eye_tex.Get(); - left_eye.eType = vr::TextureType_DirectX; - left_eye.eColorSpace = vr::ColorSpace_Auto; - left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - - auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &vr->m_left_bounds, vr::Submit_TextureWithPose); - - if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); - vr->m_submitted = false; - return e; - } + if (flat_openvr) { + context->CopyResource(m_right_eye_tex.Get(), m_left_eye_tex.Get()); + + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)m_left_eye_tex.Get(); + left_eye.eType = vr::TextureType_DirectX; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - if (vr->is_using_async_aer()) { vr::VRTextureWithPose_t right_eye{}; right_eye.handle = (void*)m_right_eye_tex.Get(); right_eye.eType = vr::TextureType_DirectX; right_eye.eColorSpace = vr::ColorSpace_Auto; - right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &vr->m_left_bounds, vr::Submit_TextureWithPose); if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit right eye (resubmit): {}", (int)e); + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); + vr->m_submitted = false; + return e; } + + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); + vr->m_submitted = false; + return e; + } + vr->m_submitted = true; + } else { + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)m_left_eye_tex.Get(); + left_eye.eType = vr::TextureType_DirectX; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &vr->m_left_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); + vr->m_submitted = false; + return e; + } + + if (vr->is_using_async_aer()) { + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)m_right_eye_tex.Get(); + right_eye.eType = vr::TextureType_DirectX; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye (resubmit): {}", (int)e); + } + vr->m_submitted = true; + } } } } else { @@ -368,39 +402,75 @@ vr::EVRCompositorError D3D11Component::on_frame(VR* vr) { } if (runtime->is_openvr()) { - if (vr->is_using_async_aer()) { + if (flat_openvr) { + if (backbufferIs8Bit) { + context->CopyResource(m_right_eye_tex.Get(), backbuffer.Get()); + } + context->CopyResource(m_left_eye_tex.Get(), m_right_eye_tex.Get()); + vr::VRTextureWithPose_t left_eye{}; left_eye.handle = (void*)m_left_eye_tex.Get(); left_eye.eType = vr::TextureType_DirectX; left_eye.eColorSpace = vr::ColorSpace_Auto; - left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)m_right_eye_tex.Get(); + right_eye.eType = vr::TextureType_DirectX; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &vr->m_left_bounds, vr::Submit_TextureWithPose); if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit left eye (resubmit): {}", (int)e); + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); + vr->m_submitted = false; + return e; } - } - // Copy the back buffer to the right eye texture. - if (backbufferIs8Bit) { - context->CopyResource(m_right_eye_tex.Get(), backbuffer.Get()); - } - - vr::VRTextureWithPose_t right_eye{}; - right_eye.handle = (void*)m_right_eye_tex.Get(); - right_eye.eType = vr::TextureType_DirectX; - right_eye.eColorSpace = vr::ColorSpace_Auto; - right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - - auto e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); - - if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); - vr->m_submitted = false; - return e; - } - vr->m_submitted = true; + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); + vr->m_submitted = false; + return e; + } + + vr->m_submitted = true; + } else { + if (vr->is_using_async_aer()) { + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)m_left_eye_tex.Get(); + left_eye.eType = vr::TextureType_DirectX; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &vr->m_left_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit left eye (resubmit): {}", (int)e); + } + } + // Copy the back buffer to the right eye texture. + if (backbufferIs8Bit) { + context->CopyResource(m_right_eye_tex.Get(), backbuffer.Get()); + } + + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)m_right_eye_tex.Get(); + right_eye.eType = vr::TextureType_DirectX; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + auto e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &vr->m_right_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); + vr->m_submitted = false; + return e; + } + + vr->m_submitted = true; + } } } diff --git a/src/mods/vr/D3D12Component.cpp b/src/mods/vr/D3D12Component.cpp index 5ec7dea..4b5e630 100644 --- a/src/mods/vr/D3D12Component.cpp +++ b/src/mods/vr/D3D12Component.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -63,6 +64,7 @@ vr::EVRCompositorError D3D12Component::on_frame(VR* vr) { auto runtime = vr->get_runtime(); bool is_left_eye_frame = vr->m_presenter_frame_count % 2 == vr->m_left_eye_interval; bool is_right_eye_frame = !is_left_eye_frame; + bool flat_openvr = runtime->is_openvr() && ModSettings::showFlatScreenDisplay(); if (runtime->is_openxr() && runtime->ready() && vr->m_openxr->frame_began) { if (is_right_eye_frame) { @@ -95,50 +97,97 @@ vr::EVRCompositorError D3D12Component::on_frame(VR* vr) { // OpenVR texture // Copy the back buffer to the left eye texture (m_left_eye_tex0 holds the intermediate frame). if (runtime->is_openvr()) { - m_openvr.copy_left(eye_texture.Get()); - - vr::D3D12TextureData_t left_tex { - m_openvr.get_left().texture.Get(), - command_queue, - 0 - }; - - vr::VRTextureWithPose_t left_eye{}; - left_eye.handle = (void*)&left_tex; - left_eye.eType = vr::TextureType_DirectX12; - left_eye.eColorSpace = vr::ColorSpace_Auto; - left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - - const auto left_bounds = vr::VRTextureBounds_t{runtime->view_bounds[0][0], runtime->view_bounds[0][2], - runtime->view_bounds[0][1], runtime->view_bounds[0][3]}; - auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &left_bounds, vr::Submit_TextureWithPose); - - if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); - return e; - } + if (flat_openvr) { + m_openvr.copy_left(eye_texture.Get()); + m_openvr.copy_right(eye_texture.Get()); + + vr::D3D12TextureData_t left_tex { + m_openvr.get_left().texture.Get(), + command_queue, + 0 + }; - if (vr->is_using_async_aer()) { vr::D3D12TextureData_t right_tex { - m_openvr.get_right(true).texture.Get(), + m_openvr.get_right().texture.Get(), command_queue, 0 }; + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)&left_tex; + left_eye.eType = vr::TextureType_DirectX12; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + vr::VRTextureWithPose_t right_eye{}; right_eye.handle = (void*)&right_tex; right_eye.eType = vr::TextureType_DirectX12; right_eye.eColorSpace = vr::ColorSpace_Auto; - right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count-1); + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + const auto left_bounds = vr::VRTextureBounds_t{runtime->view_bounds[0][0], runtime->view_bounds[0][2], + runtime->view_bounds[0][1], runtime->view_bounds[0][3]}; const auto right_bounds = vr::VRTextureBounds_t{runtime->view_bounds[1][0], runtime->view_bounds[1][2], - runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; + runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &left_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); + return e; + } + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &right_bounds, vr::Submit_TextureWithPose); if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit right eye (resubmit): {}", (int)e); + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); return e; } vr->m_submitted = true; + } else { + m_openvr.copy_left(eye_texture.Get()); + + vr::D3D12TextureData_t left_tex { + m_openvr.get_left().texture.Get(), + command_queue, + 0 + }; + + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)&left_tex; + left_eye.eType = vr::TextureType_DirectX12; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + const auto left_bounds = vr::VRTextureBounds_t{runtime->view_bounds[0][0], runtime->view_bounds[0][2], + runtime->view_bounds[0][1], runtime->view_bounds[0][3]}; + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &left_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); + return e; + } + + if (vr->is_using_async_aer()) { + vr::D3D12TextureData_t right_tex { + m_openvr.get_right(true).texture.Get(), + command_queue, + 0 + }; + + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)&right_tex; + right_eye.eType = vr::TextureType_DirectX12; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count-1); + + const auto right_bounds = vr::VRTextureBounds_t{runtime->view_bounds[1][0], runtime->view_bounds[1][2], + runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &right_bounds, vr::Submit_TextureWithPose); + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye (resubmit): {}", (int)e); + return e; + } + vr->m_submitted = true; + } } } } else { @@ -161,53 +210,100 @@ vr::EVRCompositorError D3D12Component::on_frame(VR* vr) { // OpenVR texture // Copy the back buffer to the right eye texture. if (runtime->is_openvr()) { - if (vr->is_using_async_aer()) { + if (flat_openvr) { + m_openvr.copy_left(eye_texture.Get()); + m_openvr.copy_right(eye_texture.Get()); + vr::D3D12TextureData_t left_tex { m_openvr.get_left().texture.Get(), command_queue, 0 }; + vr::D3D12TextureData_t right_tex { + m_openvr.get_right().texture.Get(), + command_queue, + 0 + }; + vr::VRTextureWithPose_t left_eye{}; left_eye.handle = (void*)&left_tex; left_eye.eType = vr::TextureType_DirectX12; left_eye.eColorSpace = vr::ColorSpace_Auto; - left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)&right_tex; + right_eye.eType = vr::TextureType_DirectX12; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); const auto left_bounds = vr::VRTextureBounds_t{runtime->view_bounds[0][0], runtime->view_bounds[0][2], runtime->view_bounds[0][1], runtime->view_bounds[0][3]}; - auto e = vr::VRCompositor()->Submit(vr::Eye_Left, &left_eye, &left_bounds, vr::Submit_TextureWithPose); /*, vr::Submit_Default);*/ + const auto right_bounds = vr::VRTextureBounds_t{runtime->view_bounds[1][0], runtime->view_bounds[1][2], + runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, (vr::Texture_t*)&left_eye, &left_bounds, vr::Submit_TextureWithPose); if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit left eye (resubmit): {}", (int)e); + spdlog::error("[VR] VRCompositor failed to submit left eye: {}", (int)e); return e; } - } - m_openvr.copy_right(eye_texture.Get()); - - vr::D3D12TextureData_t right_tex { - m_openvr.get_right().texture.Get(), - command_queue, - 0 - }; - - vr::VRTextureWithPose_t right_eye{}; - right_eye.handle = (void*)&right_tex; - right_eye.eType = vr::TextureType_DirectX12; - right_eye.eColorSpace = vr::ColorSpace_Auto; - right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); - - const auto right_bounds = vr::VRTextureBounds_t{runtime->view_bounds[1][0], runtime->view_bounds[1][2], - runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; - auto e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &right_bounds, vr::Submit_TextureWithPose); - - if (e != vr::VRCompositorError_None) { - spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); - return e; - } - vr->m_submitted = true; - ++m_openvr.texture_counter; + e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &right_bounds, vr::Submit_TextureWithPose); + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); + return e; + } + vr->m_submitted = true; + } else { + if (vr->is_using_async_aer()) { + vr::D3D12TextureData_t left_tex { + m_openvr.get_left().texture.Get(), + command_queue, + 0 + }; + + vr::VRTextureWithPose_t left_eye{}; + left_eye.handle = (void*)&left_tex; + left_eye.eType = vr::TextureType_DirectX12; + left_eye.eColorSpace = vr::ColorSpace_Auto; + left_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count - 1); + + const auto left_bounds = vr::VRTextureBounds_t{runtime->view_bounds[0][0], runtime->view_bounds[0][2], + runtime->view_bounds[0][1], runtime->view_bounds[0][3]}; + auto e = vr::VRCompositor()->Submit(vr::Eye_Left, &left_eye, &left_bounds, vr::Submit_TextureWithPose); /*, vr::Submit_Default);*/ + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit left eye (resubmit): {}", (int)e); + return e; + } + } + m_openvr.copy_right(eye_texture.Get()); + + vr::D3D12TextureData_t right_tex { + m_openvr.get_right().texture.Get(), + command_queue, + 0 + }; + + vr::VRTextureWithPose_t right_eye{}; + right_eye.handle = (void*)&right_tex; + right_eye.eType = vr::TextureType_DirectX12; + right_eye.eColorSpace = vr::ColorSpace_Auto; + right_eye.mDeviceToAbsoluteTracking = GlobalPool::get_openvr_pose(vr->m_presenter_frame_count); + + const auto right_bounds = vr::VRTextureBounds_t{runtime->view_bounds[1][0], runtime->view_bounds[1][2], + runtime->view_bounds[1][1], runtime->view_bounds[1][3]}; + auto e = vr::VRCompositor()->Submit(vr::Eye_Right, (vr::Texture_t*)&right_eye, &right_bounds, vr::Submit_TextureWithPose); + + if (e != vr::VRCompositorError_None) { + spdlog::error("[VR] VRCompositor failed to submit right eye: {}", (int)e); + return e; + } + vr->m_submitted = true; + + ++m_openvr.texture_counter; + } } }