OpenXR - Remove multiview

This commit is contained in:
Lubos 2024-06-24 17:00:56 +02:00
parent 226956b49f
commit ffca688f99
9 changed files with 38 additions and 114 deletions

View File

@ -274,25 +274,7 @@ void GLQueueRunner::RunInitSteps(const FastVec<GLRInitStep> &steps, bool skipGLC
auto &query = program->queries_[j];
_dbg_assert_(query.name);
int location = -1;
if (IsVREnabled() && IsMultiviewSupported()) {
int index = GetStereoBufferIndex(query.name);
if (index >= 0) {
std::string layout = GetStereoBufferLayout(query.name);
glUniformBlockBinding(program->program, glGetUniformBlockIndex(program->program, layout.c_str()), index);
GLuint buffer = 0;
glGenBuffers(1, &buffer);
glBindBuffer(GL_UNIFORM_BUFFER, buffer);
glBufferData(GL_UNIFORM_BUFFER,2 * 16 * sizeof(float),NULL, GL_STATIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
location = buffer;
} else {
location = glGetUniformLocation(program->program, query.name);
}
} else {
location = glGetUniformLocation(program->program, query.name);
}
int location = glGetUniformLocation(program->program, query.name);
if (location < 0 && query.required) {
WARN_LOG(G3D, "Required uniform query for '%s' failed", query.name);
@ -1119,36 +1101,22 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step, bool first, bool last
case GLRRenderCommand::UNIFORMSTEREOMATRIX:
{
_dbg_assert_(curProgram);
if (IsMultiviewSupported()) {
int layout = GetStereoBufferIndex(c.uniformStereoMatrix4.name);
if (layout >= 0) {
int size = 2 * 16 * sizeof(float);
glBindBufferBase(GL_UNIFORM_BUFFER, layout, *c.uniformStereoMatrix4.loc);
glBindBuffer(GL_UNIFORM_BUFFER, *c.uniformStereoMatrix4.loc);
void *matrices = glMapBufferRange(GL_UNIFORM_BUFFER, 0, size, GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);
memcpy(matrices, c.uniformStereoMatrix4.mData, size);
glUnmapBuffer(GL_UNIFORM_BUFFER);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
delete[] c.uniformStereoMatrix4.mData; // We only playback once.
} else {
int loc = c.uniformStereoMatrix4.loc ? *c.uniformStereoMatrix4.loc : -1;
if (c.uniformStereoMatrix4.name) {
loc = curProgram->GetUniformLoc(c.uniformStereoMatrix4.name);
}
if (loc >= 0) {
if (GetVRFBOIndex() == 0) {
glUniformMatrix4fv(loc, 1, false, c.uniformStereoMatrix4.mData);
} else {
glUniformMatrix4fv(loc, 1, false, c.uniformStereoMatrix4.mData + 16);
}
}
if (GetVRFBOIndex() == 1 || GetVRPassesCount() == 1) {
// Only delete the data if we're rendering the only or the second eye.
// If we delete during the first eye, we get a use-after-free or double delete.
delete[] c.uniformStereoMatrix4.mData;
int loc = c.uniformStereoMatrix4.loc ? *c.uniformStereoMatrix4.loc : -1;
if (c.uniformStereoMatrix4.name) {
loc = curProgram->GetUniformLoc(c.uniformStereoMatrix4.name);
}
if (loc >= 0) {
if (GetVRFBOIndex() == 0) {
glUniformMatrix4fv(loc, 1, false, c.uniformStereoMatrix4.mData);
} else {
glUniformMatrix4fv(loc, 1, false, c.uniformStereoMatrix4.mData + 16);
}
}
if (GetVRFBOIndex() == 1 || GetVRPassesCount() == 1) {
// Only delete the data if we're rendering the only or the second eye.
// If we delete during the first eye, we get a use-after-free or double delete.
delete[] c.uniformStereoMatrix4.mData;
}
CHECK_GL_ERROR_IF_DEBUG();
break;
}

View File

@ -624,7 +624,7 @@ void* BindVRFramebuffer() {
bool StartVRRender() {
if (!VR_GetConfig(VR_CONFIG_VIEWPORT_VALID)) {
VR_InitRenderer(VR_GetEngine(), IsMultiviewSupported());
VR_InitRenderer(VR_GetEngine());
VR_SetConfig(VR_CONFIG_VIEWPORT_VALID, true);
}
@ -709,15 +709,7 @@ int GetVRFBOIndex() {
int GetVRPassesCount() {
bool vrStereo = !PSP_CoreParameter().compat.vrCompat().ForceMono && g_Config.bEnableStereo;
if (!IsMultiviewSupported() && vrStereo) {
return 2;
} else {
return 1;
}
}
bool IsMultiviewSupported() {
return false;
return vrStereo ? 2 : 1;
}
bool IsPassthroughSupported() {

View File

@ -52,7 +52,6 @@ void PreVRFrameRender(int fboIndex);
void PostVRFrameRender();
int GetVRFBOIndex();
int GetVRPassesCount();
bool IsMultiviewSupported();
bool IsPassthroughSupported();
bool IsFlatVRGame();
bool IsFlatVRScene();

View File

@ -78,7 +78,6 @@ typedef struct {
} ovrFramebuffer;
typedef struct {
bool Multiview;
ovrFramebuffer FrameBuffer[ovrMaxNumEyes];
} ovrRenderer;

View File

@ -81,23 +81,12 @@ void GLCheckErrors(const char* file, int line) {
#endif
#if XR_USE_GRAPHICS_API_OPENGL_ES
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, bool multiview) {
static bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuffer, int width, int height) {
frameBuffer->Width = width;
frameBuffer->Height = height;
if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_OVR_multiview2") == nullptr)
{
ALOGE("OpenGL implementation does not support GL_OVR_multiview2 extension.\n");
}
typedef void (*PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)(GLenum, GLenum, GLuint, GLint, GLint, GLsizei);
PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR glFramebufferTextureMultiviewOVR = nullptr;
glFramebufferTextureMultiviewOVR = (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVR)eglGetProcAddress ("glFramebufferTextureMultiviewOVR");
if (!glFramebufferTextureMultiviewOVR) {
ALOGE("Can not get proc address for glFramebufferTextureMultiviewOVR.\n");
}
XrSwapchainCreateInfo swapChainCreateInfo;
memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo));
swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
@ -106,7 +95,7 @@ static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBu
swapChainCreateInfo.height = height;
swapChainCreateInfo.faceCount = 1;
swapChainCreateInfo.mipCount = 1;
swapChainCreateInfo.arraySize = multiview ? 2 : 1;
swapChainCreateInfo.arraySize = 1;
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
@ -152,15 +141,9 @@ static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBu
// Create the frame buffer.
GL(glGenFramebuffers(1, &frameBuffer->GLFrameBuffers[i]));
GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->GLFrameBuffers[i]));
if (multiview) {
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, depthTexture, 0, 0, 2));
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0, 0, 2));
GL(glFramebufferTextureMultiviewOVR(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorTexture, 0, 0, 2));
} else {
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(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));
if (renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE) {
@ -177,7 +160,7 @@ static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBu
#if XR_USE_GRAPHICS_API_VULKAN
static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int width, int height,
bool multiview, void* context) {
void* context) {
frameBuffer->Width = width;
frameBuffer->Height = height;
@ -191,7 +174,7 @@ static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuff
swapChainCreateInfo.height = height;
swapChainCreateInfo.faceCount = 1;
swapChainCreateInfo.mipCount = 1;
swapChainCreateInfo.arraySize = multiview ? 2 : 1;
swapChainCreateInfo.arraySize = 1;
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
@ -378,25 +361,20 @@ void ovrRenderer_Clear(ovrRenderer* renderer) {
}
}
void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, bool multiview, void* vulkanContext) {
renderer->Multiview = multiview;
int instances = renderer->Multiview ? 1 : ovrMaxNumEyes;
for (int i = 0; i < instances; i++) {
void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, void* vulkanContext) {
for (int i = 0; i < ovrMaxNumEyes; i++) {
if (vulkanContext) {
ovrFramebuffer_CreateVK(session, &renderer->FrameBuffer[i], width, height, multiview, vulkanContext);
ovrFramebuffer_CreateVK(session, &renderer->FrameBuffer[i], width, height, vulkanContext);
} else {
#if XR_USE_GRAPHICS_API_OPENGL_ES
ovrFramebuffer_CreateGLES(session, &renderer->FrameBuffer[i], width, height, multiview);
#elif XR_USE_GRAPHICS_API_OPENGL
// TODO
#if XR_USE_GRAPHICS_API_OPENGL_ES || XR_USE_GRAPHICS_API_OPENGL
ovrFramebuffer_CreateGL(session, &renderer->FrameBuffer[i], width, height);
#endif
}
}
}
void ovrRenderer_Destroy(ovrRenderer* renderer) {
int instances = renderer->Multiview ? 1 : ovrMaxNumEyes;
for (int i = 0; i < instances; i++) {
for (int i = 0; i < ovrMaxNumEyes; i++) {
ovrFramebuffer_Destroy(&renderer->FrameBuffer[i]);
}
}

View File

@ -10,6 +10,6 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer);
void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer);
void* ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer);
void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, bool multiview, void* vulkanContext);
void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, void* vulkanContext);
void ovrRenderer_Destroy(ovrRenderer* renderer);
void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int sx, int sy);

View File

@ -186,7 +186,7 @@ void VR_Recenter(engine_t* engine) {
VR_SetConfigFloat(VR_CONFIG_MENU_YAW, 0.0f);
}
void VR_InitRenderer( engine_t* engine, bool multiview ) {
void VR_InitRenderer( engine_t* engine ) {
if (initialized) {
VR_DestroyRenderer(engine);
}
@ -242,7 +242,7 @@ void VR_InitRenderer( engine_t* engine, bool multiview ) {
ovrRenderer_Create(engine->appState.Session, &engine->appState.Renderer,
engine->appState.ViewConfigurationView[0].recommendedImageRectWidth,
engine->appState.ViewConfigurationView[0].recommendedImageRectHeight,
multiview, vulkanContext);
vulkanContext);
if (VR_GetPlatformFlag(VRPlatformFlag::VR_PLATFORM_EXTENSION_PASSTHROUGH)) {
XrPassthroughCreateInfoFB ptci = {XR_TYPE_PASSTHROUGH_CREATE_INFO_FB};
@ -387,14 +387,11 @@ void VR_FinishFrame( engine_t* engine ) {
if ((vrMode == VR_MODE_MONO_6DOF) || (vrMode == VR_MODE_STEREO_6DOF)) {
VR_SetConfigFloat(VR_CONFIG_MENU_YAW, hmdorientation.y);
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {
int imageLayer = engine->appState.Renderer.Multiview ? eye : 0;
for (int eye = 0; eye < ovrMaxNumEyes; eye++) {;
ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer[0];
XrPosef pose = invViewTransform[0];
if (vrMode != VR_MODE_MONO_6DOF) {
if (!engine->appState.Renderer.Multiview) {
frameBuffer = &engine->appState.Renderer.FrameBuffer[eye];
}
frameBuffer = &engine->appState.Renderer.FrameBuffer[eye];
pose = invViewTransform[eye];
}
@ -409,7 +406,7 @@ void VR_FinishFrame( engine_t* engine ) {
projection_layer_elements[eye].subImage.imageRect.offset.y = 0;
projection_layer_elements[eye].subImage.imageRect.extent.width = frameBuffer->ColorSwapChain.Width;
projection_layer_elements[eye].subImage.imageRect.extent.height = frameBuffer->ColorSwapChain.Height;
projection_layer_elements[eye].subImage.imageArrayIndex = imageLayer;
projection_layer_elements[eye].subImage.imageArrayIndex = 0;
}
XrCompositionLayerProjection projection_layer = {};
@ -458,12 +455,6 @@ void VR_FinishFrame( engine_t* engine ) {
if (vrMode == VR_MODE_MONO_SCREEN) {
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
} else if (engine->appState.Renderer.Multiview) {
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_LEFT;
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_RIGHT;
cylinder_layer.subImage.imageArrayIndex = 1;
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;
} else {
cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_LEFT;
engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer;

View File

@ -33,7 +33,7 @@ enum VRMode {
};
void VR_GetResolution( engine_t* engine, int *pWidth, int *pHeight );
void VR_InitRenderer( engine_t* engine, bool multiview );
void VR_InitRenderer( engine_t* engine );
void VR_DestroyRenderer( engine_t* engine );
bool VR_InitFrame( engine_t* engine );

View File

@ -172,9 +172,6 @@ u32 GPU_GLES::CheckGPUFeatures() const {
if (IsVREnabled()) {
features |= GPU_USE_VIRTUAL_REALITY;
}
if (IsMultiviewSupported()) {
features |= GPU_USE_SINGLE_PASS_STEREO;
}
if (!gl_extensions.GLES3) {
// Heuristic.