diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index e38d5c560c..a77bce6663 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -527,7 +527,7 @@ bool StartVRRender() { // VR flags bool vrIncompatibleGame = PSP_CoreParameter().compat.vrCompat().ForceFlatScreen; - bool vrMode = (g_Config.bEnableVR || g_Config.bEnableImmersiveVR) && !vrIncompatibleGame; + bool vrMode = (g_Config.bEnableVR || IsImmersiveVRMode()) && !vrIncompatibleGame; bool vrScene = !vrFlatForced && (g_Config.bManualForceVR || (vr3DGeometryCount > 15)); bool vrStereo = !PSP_CoreParameter().compat.vrCompat().ForceMono && g_Config.bEnableStereo; @@ -558,7 +558,7 @@ bool StartVRRender() { M[10] = -1; M[11] = -1; M[14] = -(nearZ + nearZ); - if (g_Config.bEnableImmersiveVR) { + if (IsImmersiveVRMode()) { M[0] /= 2.0f; } memcpy(vrMatrix[VR_PROJECTION_MATRIX], M, sizeof(float) * 16); @@ -567,7 +567,7 @@ bool StartVRRender() { VR_SetConfigFloat(VR_CONFIG_CANVAS_ASPECT, 480.0f / 272.0f); if (vrMode && vrScene && (appMode == VR_GAME_MODE)) { VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_6DOF : VR_MODE_MONO_6DOF); - VR_SetConfig(VR_CONFIG_REPROJECTION, g_Config.bEnableImmersiveVR ? 0 : 1); + VR_SetConfig(VR_CONFIG_REPROJECTION, IsImmersiveVRMode() ? 0 : 1); vrFlatGame = false; } else if (appMode == VR_GAME_MODE) { VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_SCREEN : VR_MODE_MONO_SCREEN); @@ -632,6 +632,10 @@ bool IsGameVRScene() { return (appMode == VR_GAME_MODE) || (appMode == VR_DIALOG_MODE); } +bool IsImmersiveVRMode() { + return g_Config.bEnableImmersiveVR && !PSP_CoreParameter().compat.vrCompat().IdentityViewHack; +} + bool Is2DVRObject(float* projMatrix, bool ortho) { // Quick analyze if the object is in 2D diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index 37c614bbc4..e77f5a0d07 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -56,6 +56,7 @@ bool IsPassthroughSupported(); bool IsFlatVRGame(); bool IsFlatVRScene(); bool IsGameVRScene(); +bool IsImmersiveVRMode(); bool Is2DVRObject(float* projMatrix, bool ortho); void UpdateVRParams(float* projMatrix); void UpdateVRProjection(float* projMatrix, float* output); diff --git a/Common/VR/VRBase.h b/Common/VR/VRBase.h index 9a82145dd7..0f6efb24da 100644 --- a/Common/VR/VRBase.h +++ b/Common/VR/VRBase.h @@ -65,13 +65,10 @@ typedef struct { uint32_t TextureSwapChainLength; uint32_t TextureSwapChainIndex; ovrSwapChain ColorSwapChain; - ovrSwapChain DepthSwapChain; void* ColorSwapChainImage; - void* DepthSwapChainImage; unsigned int* GLFrameBuffers; VkFramebuffer* VKFrameBuffers; VkImageView* VKColorImages; - VkImageView* VKDepthImages; bool Acquired; XrGraphicsBindingVulkanKHR* VKContext; diff --git a/Common/VR/VRFramebuffer.cpp b/Common/VR/VRFramebuffer.cpp index 800ad5a0d0..e3ad09253f 100644 --- a/Common/VR/VRFramebuffer.cpp +++ b/Common/VR/VRFramebuffer.cpp @@ -47,10 +47,6 @@ void ovrFramebuffer_Clear(ovrFramebuffer* frameBuffer) { frameBuffer->ColorSwapChain.Width = 0; frameBuffer->ColorSwapChain.Height = 0; frameBuffer->ColorSwapChainImage = NULL; - frameBuffer->DepthSwapChain.Handle = XR_NULL_HANDLE; - frameBuffer->DepthSwapChain.Width = 0; - frameBuffer->DepthSwapChain.Height = 0; - frameBuffer->DepthSwapChainImage = NULL; frameBuffer->GLFrameBuffers = NULL; frameBuffer->Acquired = false; @@ -107,8 +103,6 @@ static bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuff frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width; frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height; - frameBuffer->DepthSwapChain.Width = swapChainCreateInfo.width; - frameBuffer->DepthSwapChain.Height = swapChainCreateInfo.height; // Create the color swapchain. swapChainCreateInfo.format = GL_SRGB8_ALPHA8; @@ -117,40 +111,24 @@ static bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuff OXR(xrEnumerateSwapchainImages(frameBuffer->ColorSwapChain.Handle, 0, &frameBuffer->TextureSwapChainLength, NULL)); frameBuffer->ColorSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XR_GL_IMAGE)); - // Create the depth swapchain. - swapChainCreateInfo.format = GL_DEPTH24_STENCIL8; - swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->DepthSwapChain.Handle)); - frameBuffer->DepthSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XR_GL_IMAGE)); - // Populate the swapchain image array. for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { ((XR_GL_IMAGE*)frameBuffer->ColorSwapChainImage)[i].type = XR_GL_SWAPCHAIN; ((XR_GL_IMAGE*)frameBuffer->ColorSwapChainImage)[i].next = NULL; - ((XR_GL_IMAGE*)frameBuffer->DepthSwapChainImage)[i].type = XR_GL_SWAPCHAIN; - ((XR_GL_IMAGE*)frameBuffer->DepthSwapChainImage)[i].next = NULL; } OXR(xrEnumerateSwapchainImages( frameBuffer->ColorSwapChain.Handle, frameBuffer->TextureSwapChainLength, &frameBuffer->TextureSwapChainLength, (XrSwapchainImageBaseHeader*)frameBuffer->ColorSwapChainImage)); - OXR(xrEnumerateSwapchainImages( - frameBuffer->DepthSwapChain.Handle, - frameBuffer->TextureSwapChainLength, - &frameBuffer->TextureSwapChainLength, - (XrSwapchainImageBaseHeader*)frameBuffer->DepthSwapChainImage)); frameBuffer->GLFrameBuffers = (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint)); for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { const GLuint colorTexture = ((XR_GL_IMAGE*)frameBuffer->ColorSwapChainImage)[i].image; - const GLuint depthTexture = ((XR_GL_IMAGE*)frameBuffer->DepthSwapChainImage)[i].image; // Create the frame buffer. GL(glGenFramebuffers(1, &frameBuffer->GLFrameBuffers[i])); GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->GLFrameBuffers[i])); - GL(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0)); - GL(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0)); GL(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0)); GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); @@ -168,7 +146,7 @@ static bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuff #if XR_USE_GRAPHICS_API_VULKAN static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, - void* context) { + void* context) { frameBuffer->Width = width; frameBuffer->Height = height; @@ -186,8 +164,6 @@ static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuff frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width; frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height; - frameBuffer->DepthSwapChain.Width = swapChainCreateInfo.width; - frameBuffer->DepthSwapChain.Height = swapChainCreateInfo.height; // Create the color swapchain. swapChainCreateInfo.format = VK_FORMAT_R8G8B8A8_UNORM; @@ -196,32 +172,18 @@ static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuff OXR(xrEnumerateSwapchainImages(frameBuffer->ColorSwapChain.Handle, 0, &frameBuffer->TextureSwapChainLength, NULL)); frameBuffer->ColorSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageVulkanKHR)); - // Create the depth swapchain. - swapChainCreateInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; - swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->DepthSwapChain.Handle)); - frameBuffer->DepthSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageVulkanKHR)); - // Populate the swapchain image array. for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { ((XrSwapchainImageVulkanKHR*)frameBuffer->ColorSwapChainImage)[i].type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR; ((XrSwapchainImageVulkanKHR*)frameBuffer->ColorSwapChainImage)[i].next = NULL; - ((XrSwapchainImageVulkanKHR*)frameBuffer->DepthSwapChainImage)[i].type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR; - ((XrSwapchainImageVulkanKHR*)frameBuffer->DepthSwapChainImage)[i].next = NULL; } OXR(xrEnumerateSwapchainImages( frameBuffer->ColorSwapChain.Handle, frameBuffer->TextureSwapChainLength, &frameBuffer->TextureSwapChainLength, (XrSwapchainImageBaseHeader*)frameBuffer->ColorSwapChainImage)); - OXR(xrEnumerateSwapchainImages( - frameBuffer->DepthSwapChain.Handle, - frameBuffer->TextureSwapChainLength, - &frameBuffer->TextureSwapChainLength, - (XrSwapchainImageBaseHeader*)frameBuffer->DepthSwapChainImage)); frameBuffer->VKColorImages = new VkImageView[frameBuffer->TextureSwapChainLength]; - frameBuffer->VKDepthImages = new VkImageView[frameBuffer->TextureSwapChainLength]; frameBuffer->VKFrameBuffers = new VkFramebuffer[frameBuffer->TextureSwapChainLength]; for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { VkImageViewCreateInfo createInfo{}; @@ -243,16 +205,8 @@ static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuff return false; } - createInfo.image = ((XrSwapchainImageVulkanKHR*)frameBuffer->DepthSwapChainImage)[i].image; - createInfo.format = VK_FORMAT_D24_UNORM_S8_UINT; - createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - if (vkCreateImageView(frameBuffer->VKContext->device, &createInfo, nullptr, &frameBuffer->VKDepthImages[i]) != VK_SUCCESS) { - ALOGE("failed to create depth image view!"); - return false; - } - // Create the frame buffer. - VkImageView attachments[] = { frameBuffer->VKColorImages[i], frameBuffer->VKDepthImages[i] }; + VkImageView attachments[] = { frameBuffer->VKColorImages[i] }; VkFramebufferCreateInfo framebufferInfo{}; framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; framebufferInfo.renderPass = VK_NULL_HANDLE; //TODO:This is probably wrong @@ -276,11 +230,9 @@ void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) { if (VR_GetPlatformFlag(VR_PLATFORM_RENDERER_VULKAN)) { for (int i = 0; i < (int)frameBuffer->TextureSwapChainLength; i++) { vkDestroyImageView(frameBuffer->VKContext->device, frameBuffer->VKColorImages[i], nullptr); - vkDestroyImageView(frameBuffer->VKContext->device, frameBuffer->VKDepthImages[i], nullptr); vkDestroyFramebuffer(frameBuffer->VKContext->device, frameBuffer->VKFrameBuffers[i], nullptr); } delete[] frameBuffer->VKColorImages; - delete[] frameBuffer->VKDepthImages; delete[] frameBuffer->VKFrameBuffers; } else { #if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL @@ -289,9 +241,7 @@ void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) { #endif } OXR(xrDestroySwapchain(frameBuffer->ColorSwapChain.Handle)); - OXR(xrDestroySwapchain(frameBuffer->DepthSwapChain.Handle)); free(frameBuffer->ColorSwapChainImage); - free(frameBuffer->DepthSwapChainImage); ovrFramebuffer_Clear(frameBuffer); } @@ -328,7 +278,7 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) { GL(glViewport( 0, 0, frameBuffer->Width, frameBuffer->Height )); GL(glClearColor( 0.0f, 0.0f, 0.0f, 1.0f )); GL(glScissor( 0, 0, frameBuffer->Width, frameBuffer->Height )); - GL(glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )); + GL(glClear( GL_COLOR_BUFFER_BIT )); GL(glScissor( 0, 0, 0, 0 )); GL(glDisable( GL_SCISSOR_TEST )); #endif diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index a6d8b409f9..8e038dcfd5 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -38,14 +38,10 @@ void VR_UpdateStageBounds(ovrApp* pappState) { XrResult result; OXR(result = xrGetReferenceSpaceBoundsRect(pappState->Session, XR_REFERENCE_SPACE_TYPE_STAGE, &stageBounds)); if (result != XR_SUCCESS) { - ALOGV("Stage bounds query failed: using small defaults"); stageBounds.width = 1.0f; stageBounds.height = 1.0f; - pappState->CurrentSpace = pappState->FakeStageSpace; } - - ALOGV("Stage bounds: width = %f, depth %f", stageBounds.width, stageBounds.height); } void VR_GetResolution(engine_t* engine, int *pWidth, int *pHeight) { @@ -167,6 +163,8 @@ void VR_Recenter(engine_t* engine) { // Create a default stage space to use if SPACE_TYPE_STAGE is not // supported, or calls to xrGetReferenceSpaceBoundsRect fail. spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + spaceCreateInfo.poseInReferenceSpace = {}; + spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0; if (VR_GetPlatformFlag(VR_PLATFORM_TRACKING_FLOOR)) { spaceCreateInfo.poseInReferenceSpace.position.y = -1.6750f; } @@ -176,7 +174,8 @@ void VR_Recenter(engine_t* engine) { if (stageSupported) { spaceCreateInfo.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; - spaceCreateInfo.poseInReferenceSpace.position.y = 0.0; + spaceCreateInfo.poseInReferenceSpace = {}; + spaceCreateInfo.poseInReferenceSpace.orientation.w = 1.0; OXR(xrCreateReferenceSpace(engine->appState.Session, &spaceCreateInfo, &engine->appState.StageSpace)); ALOGV("Created stage space"); if (VR_GetPlatformFlag(VR_PLATFORM_TRACKING_FLOOR)) { diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index edc8a5bcfc..d6fbc3b16b 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -1664,13 +1664,13 @@ void FramebufferManagerCommon::CopyDisplayToOutput(bool reallyDirty) { //clip the VR framebuffer to keep the aspect ratio if (IsVREnabled() && !IsFlatVRGame() && !IsGameVRScene()) { - float aspect = 272.0f / 480.0f * (g_Config.bEnableImmersiveVR ? 2.0f : 1.0f); + float aspect = 272.0f / 480.0f * (IsImmersiveVRMode() ? 2.0f : 1.0f); float clipY = 272.0f * (1.0f - aspect) / 2.0f; v0 = (clipY + offsetY) / (float)vfb->bufferHeight; v1 = (272.0f - clipY + offsetY) / (float)vfb->bufferHeight; //zoom inside - float zoom = g_Config.bEnableImmersiveVR ? 0.4f : 0.1f; + float zoom = IsImmersiveVRMode() ? 0.4f : 0.1f; u0 += zoom / aspect; u1 -= zoom / aspect; v0 += zoom; diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index e4c7993fc1..b1fd36871a 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -412,7 +412,7 @@ void LinkedShader::UpdateUniforms(const ShaderID &vsid, bool useBufferedRenderin // Set HUD mode if (gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) { if (GuessVRDrawingHUD(is2D, flatScreen)) { - float aspect = 480.0f / 272.0f * (g_Config.bEnableImmersiveVR ? 0.5f : 1.0f); + float aspect = 480.0f / 272.0f * (IsImmersiveVRMode() ? 0.5f : 1.0f); render_->SetUniformF1(&u_scaleX, g_Config.fHeadUpDisplayScale * aspect); render_->SetUniformF1(&u_scaleY, g_Config.fHeadUpDisplayScale); } else {