From 3c2b85a1489f06283d3048d8bf96ec2b3f13391d Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 18 May 2022 19:16:54 +0200 Subject: [PATCH] SpaceWarp framebuffer fixed --- .../main/cpp/code/renderergles3/tr_backend.c | 15 +++++++- .../app/src/main/cpp/code/vr/vr_renderer.c | 5 ++- android/app/src/main/cpp/code/vr/vr_types.c | 37 +++++++++---------- android/app/src/main/cpp/code/vr/vr_types.h | 1 + 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/android/app/src/main/cpp/code/renderergles3/tr_backend.c b/android/app/src/main/cpp/code/renderergles3/tr_backend.c index 863a6966..bb93ba06 100644 --- a/android/app/src/main/cpp/code/renderergles3/tr_backend.c +++ b/android/app/src/main/cpp/code/renderergles3/tr_backend.c @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "tr_local.h" #include "tr_fbo.h" #include "tr_dsa.h" +#include "../vr/vr_renderer.h" backEndData_t *backEndData; backEndState_t backEnd; @@ -360,7 +361,14 @@ void RB_BeginDrawingView (void) { // ensures that depth writes are enabled for the depth clear GL_State( GLS_DEFAULT ); // clear relevant buffers - clearBits = GL_DEPTH_BUFFER_BIT; + if( VR_RenderMotionVector() ) + { + clearBits = 0; + } + else + { + clearBits = GL_DEPTH_BUFFER_BIT; + } if ( r_measureOverdraw->integer || r_shadows->integer == 2 ) { @@ -377,7 +385,10 @@ void RB_BeginDrawingView (void) { clearBits |= GL_COLOR_BUFFER_BIT; } - qglClear( clearBits ); + if( clearBits ) + { + qglClear( clearBits ); + } if ( ( backEnd.refdef.rdflags & RDF_HYPERSPACE ) ) { diff --git a/android/app/src/main/cpp/code/vr/vr_renderer.c b/android/app/src/main/cpp/code/vr/vr_renderer.c index 16354e4d..97af4abb 100644 --- a/android/app/src/main/cpp/code/vr/vr_renderer.c +++ b/android/app/src/main/cpp/code/vr/vr_renderer.c @@ -13,7 +13,7 @@ #include #include -#define ENABLE_GL_DEBUG 0 +#define ENABLE_GL_DEBUG 1 #define ENABLE_GL_DEBUG_VERBOSE 0 #if ENABLE_GL_DEBUG #include @@ -394,6 +394,7 @@ void VR_RenderScene( engine_t* engine, XrFovf fov, qboolean motionVector ) { // Release framebuffer ovrFramebuffer_Release(frameBuffer, motionVector); + ovrFramebuffer_Resolve(frameBuffer, motionVector); ovrFramebuffer_SetNone(); } @@ -502,12 +503,12 @@ void VR_DrawFrame( engine_t* engine ) { fullscreenMode = qfalse; } + VR_RenderScene( engine, fov, qfalse ); if (vr_spacewarp->integer) { renderMotionVector = qtrue; VR_RenderScene( engine, fov, qtrue ); renderMotionVector = qfalse; } - VR_RenderScene( engine, fov, qfalse ); for (int eye = 0; eye < ovrMaxNumEyes; eye++) { ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer; diff --git a/android/app/src/main/cpp/code/vr/vr_types.c b/android/app/src/main/cpp/code/vr/vr_types.c index 70feaef8..a0808c0b 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.c +++ b/android/app/src/main/cpp/code/vr/vr_types.c @@ -152,14 +152,11 @@ bool ovrFramebuffer_Create( frameBuffer->MotionVectorWidth = motionVectorWidth; frameBuffer->MotionVectorHeight = motionVectorHeight; - GLenum mvFormat = GL_RGBA16F; - GLenum mvDepthFormat = GL_DEPTH_COMPONENT24; XrSwapchainCreateInfo swapChainCreateInfo; memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo)); swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO; - swapChainCreateInfo.usageFlags = - XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; - swapChainCreateInfo.format = mvFormat; + swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; + swapChainCreateInfo.format = GL_RGBA16F; swapChainCreateInfo.sampleCount = 1; swapChainCreateInfo.width = frameBuffer->MotionVectorWidth; swapChainCreateInfo.height = frameBuffer->MotionVectorHeight; @@ -196,9 +193,8 @@ bool ovrFramebuffer_Create( (XrSwapchainImageBaseHeader*)frameBuffer->MotionVectorSwapChainImage)); // Motion Vector depth construction - swapChainCreateInfo.usageFlags = - XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; - swapChainCreateInfo.format = mvDepthFormat; + swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + swapChainCreateInfo.format = GL_DEPTH_COMPONENT24; OXR(xrCreateSwapchain( session, &swapChainCreateInfo, &frameBuffer->MotionVectorDepthSwapChain.Handle)); @@ -239,8 +235,7 @@ bool ovrFramebuffer_Create( GL(glBindTexture(textureTarget, 0)); // depth buffer texture. - const GLuint motionVectorDepthTexture = - frameBuffer->MotionVectorDepthSwapChainImage[i].image; + const GLuint motionVectorDepthTexture = frameBuffer->MotionVectorDepthSwapChainImage[i].image; GL(glBindTexture(textureTarget, motionVectorDepthTexture)); GL(glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); GL(glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); @@ -251,15 +246,8 @@ bool ovrFramebuffer_Create( // Create the frame buffer. GL(glGenFramebuffers(1, &frameBuffer->MotionVectorFrameBuffers[i])); GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->MotionVectorFrameBuffers[i])); - GL(glFramebufferTextureMultiviewOVR( - GL_DRAW_FRAMEBUFFER, - GL_DEPTH_ATTACHMENT, - textureTarget, - motionVectorDepthTexture, - 0, 2)); - - GL(glFramebufferTextureMultiviewOVR( - GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, motionVectorTexture, 0, 2)); + GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, motionVectorDepthTexture, 0, 0, 2)); + GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, motionVectorTexture, 0, 0, 2)); GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); @@ -310,6 +298,17 @@ void ovrFramebuffer_SetNone() { GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); } +void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass) { + if (isMotionVectorPass) { + // AppSpaceWarp Both depth and color buffer will be resolved for motion vector pass + } else { + // Discard the depth buffer, so the tiler won't need to write it back out to memory. + const GLenum depthAttachment[1] = {GL_DEPTH_ATTACHMENT}; + glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, 1, depthAttachment); + // We now let the resolve happen implicitly. + } +} + void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass) { // Acquire the swapchain image XrSwapchainImageAcquireInfo acquireInfo = {XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, NULL}; diff --git a/android/app/src/main/cpp/code/vr/vr_types.h b/android/app/src/main/cpp/code/vr/vr_types.h index 67afa4dc..08e9c548 100644 --- a/android/app/src/main/cpp/code/vr/vr_types.h +++ b/android/app/src/main/cpp/code/vr/vr_types.h @@ -173,6 +173,7 @@ GLboolean ovrApp_HandleXrEvents(ovrApp* app); void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass); void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass); +void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass); void ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer, GLboolean isMotionVectorPass); void ovrFramebuffer_SetNone();