SpaceWarp framebuffer fixed

This commit is contained in:
Lubos 2022-05-18 19:16:54 +02:00
parent 2d17e7d9b2
commit 3c2b85a148
4 changed files with 35 additions and 23 deletions

View file

@ -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 ) )
{

View file

@ -13,7 +13,7 @@
#include <stdlib.h>
#include <string.h>
#define ENABLE_GL_DEBUG 0
#define ENABLE_GL_DEBUG 1
#define ENABLE_GL_DEBUG_VERBOSE 0
#if ENABLE_GL_DEBUG
#include <GLES3/gl32.h>
@ -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;

View file

@ -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};

View file

@ -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();