Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenXR - Hotfix for v69 #19416

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Common/VR/PPSSPPVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Common/VR/PPSSPPVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions Common/VR/VRBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 3 additions & 53 deletions Common/VR/VRFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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{};
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions Common/VR/VRRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/FramebufferManagerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManagerGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading