From d8fbc7ce56e426d7bdd65318d4a3f009e8c55974 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 14 Sep 2022 19:53:55 +0200 Subject: [PATCH] OpenXR - Vulkan support in progress --- Common/VR/PPSSPPVR.cpp | 22 ++++- Common/VR/PPSSPPVR.h | 4 +- Common/VR/VRBase.cpp | 22 +++-- Common/VR/VRBase.h | 23 ++++- Common/VR/VRFramebuffer.cpp | 181 ++++++++++++++++++++++++++++-------- Common/VR/VRFramebuffer.h | 4 +- Common/VR/VRRenderer.cpp | 12 ++- android/jni/app-android.cpp | 2 +- 8 files changed, 204 insertions(+), 66 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 23712db954..ef0d6f7c03 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -1,3 +1,4 @@ +#include "Common/GPU/Vulkan/VulkanContext.h" #include "Common/VR/PPSSPPVR.h" #include "Common/VR/VRBase.h" #include "Common/VR/VRInput.h" @@ -109,10 +110,25 @@ void InitVROnAndroid(void* vm, void* activity, int version, const char* name) { __DisplaySetFramerate(72); } -void EnterVR(bool firstStart) { +void EnterVR(bool firstStart, void* vulkanContext) { if (firstStart) { - VR_EnterVR(VR_GetEngine()); - IN_VRInit(VR_GetEngine()); + engine_t* engine = VR_GetEngine(); + bool useVulkan = (GPUBackend)g_Config.iGPUBackend == GPUBackend::VULKAN; + if (useVulkan) { + auto* context = (VulkanContext*)vulkanContext; + engine->graphicsBindingVulkan = {}; + engine->graphicsBindingVulkan.type = XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR; + engine->graphicsBindingVulkan.next = NULL; + engine->graphicsBindingVulkan.device = context->GetDevice(); + engine->graphicsBindingVulkan.instance = context->GetInstance(); + engine->graphicsBindingVulkan.physicalDevice = context->GetCurrentPhysicalDevice(); + engine->graphicsBindingVulkan.queueFamilyIndex = context->GetGraphicsQueueFamilyIndex(); + engine->graphicsBindingVulkan.queueIndex = 0; + VR_EnterVR(engine, &engine->graphicsBindingVulkan); + } else { + VR_EnterVR(engine, nullptr); + } + IN_VRInit(engine); } VR_SetConfig(VR_CONFIG_VIEWPORT_VALID, false); } diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index e7151130ea..7ff1338eea 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -8,7 +8,7 @@ // VR app flow integration bool IsVRBuild(); void InitVROnAndroid(void* vm, void* activity, int version, const char* name); -void EnterVR(bool firstStart); +void EnterVR(bool firstStart, void* vulkanContext); void GetVRResolutionPerEye(int* width, int* height); void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale); void UpdateVRScreenKey(const KeyInput &key); @@ -31,7 +31,7 @@ void UpdateVRView(float* leftEye, float* rightEye); // VR app flow integration inline bool IsVRBuild() { return false; } inline void InitVROnAndroid(void* vm, void* activity, int version, const char* name) {} -inline void EnterVR(bool firstTime) {} +inline void EnterVR(bool firstTime, void* vulkanContext) {} inline void GetVRResolutionPerEye(int* width, int* height) {} inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale) {} inline void UpdateVRScreenKey(const KeyInput &key) {} diff --git a/Common/VR/VRBase.cpp b/Common/VR/VRBase.cpp index bedc6b1e0c..e146967b42 100644 --- a/Common/VR/VRBase.cpp +++ b/Common/VR/VRBase.cpp @@ -118,6 +118,7 @@ void VR_Init( ovrJava java, bool useVulkan ) { vr_engine.appState.SystemId = systemId; vr_engine.java = java; + vr_engine.useVulkan = useVulkan; vr_initialized = 1; } @@ -128,7 +129,7 @@ void VR_Destroy( engine_t* engine ) { } } -void VR_EnterVR( engine_t* engine ) { +void VR_EnterVR( engine_t* engine, XrGraphicsBindingVulkanKHR* graphicsBindingVulkan ) { if (engine->appState.Session) { ALOGE("VR_EnterVR called with existing session"); @@ -136,17 +137,20 @@ void VR_EnterVR( engine_t* engine ) { } // Create the OpenXR Session. - XrGraphicsBindingOpenGLESAndroidKHR graphicsBindingAndroidGLES = {}; - graphicsBindingAndroidGLES.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR; - graphicsBindingAndroidGLES.next = NULL; - graphicsBindingAndroidGLES.display = eglGetCurrentDisplay(); - graphicsBindingAndroidGLES.config = eglGetCurrentSurface(EGL_DRAW); - graphicsBindingAndroidGLES.context = eglGetCurrentContext(); - XrSessionCreateInfo sessionCreateInfo = {}; + XrGraphicsBindingOpenGLESAndroidKHR graphicsBindingAndroidGLES = {}; memset(&sessionCreateInfo, 0, sizeof(sessionCreateInfo)); + if (engine->useVulkan) { + sessionCreateInfo.next = graphicsBindingVulkan; + } else { + graphicsBindingAndroidGLES.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR; + graphicsBindingAndroidGLES.next = NULL; + graphicsBindingAndroidGLES.display = eglGetCurrentDisplay(); + graphicsBindingAndroidGLES.config = eglGetCurrentSurface(EGL_DRAW); + graphicsBindingAndroidGLES.context = eglGetCurrentContext(); + sessionCreateInfo.next = &graphicsBindingAndroidGLES; + } sessionCreateInfo.type = XR_TYPE_SESSION_CREATE_INFO; - sessionCreateInfo.next = &graphicsBindingAndroidGLES; sessionCreateInfo.createFlags = 0; sessionCreateInfo.systemId = engine->appState.SystemId; diff --git a/Common/VR/VRBase.h b/Common/VR/VRBase.h index 4d5138e40f..89bec2b3dd 100644 --- a/Common/VR/VRBase.h +++ b/Common/VR/VRBase.h @@ -9,6 +9,14 @@ #define ALOGV(...) printf(__VA_ARGS__) #endif +//Vulkan +#ifdef VK_USE_NATIVE_LIB +#include +#else +#include "Common/GPU/Vulkan/VulkanLoader.h" +using namespace PPSSPP_VK; +#endif + //OpenXR #define XR_USE_PLATFORM_ANDROID 1 #define XR_USE_GRAPHICS_API_OPENGL_ES 1 @@ -17,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -98,10 +105,14 @@ typedef struct { uint32_t TextureSwapChainIndex; ovrSwapChain ColorSwapChain; ovrSwapChain DepthSwapChain; - XrSwapchainImageOpenGLESKHR* ColorSwapChainImage; - XrSwapchainImageOpenGLESKHR* DepthSwapChainImage; - unsigned int* FrameBuffers; + void* ColorSwapChainImage; + void* DepthSwapChainImage; + unsigned int* GLFrameBuffers; + VkFramebuffer* VKFrameBuffers; + bool Acquired; + bool UseVulkan; + XrGraphicsBindingVulkanKHR* VKContext; } ovrFramebuffer; typedef struct { @@ -146,11 +157,13 @@ typedef struct { ovrApp appState; ovrJava java; float predictedDisplayTime; + bool useVulkan; + XrGraphicsBindingVulkanKHR graphicsBindingVulkan; } engine_t; void VR_Init( ovrJava java, bool useVulkan ); void VR_Destroy( engine_t* engine ); -void VR_EnterVR( engine_t* engine ); +void VR_EnterVR( engine_t* engine, XrGraphicsBindingVulkanKHR* graphicsBindingVulkan ); void VR_LeaveVR( engine_t* engine ); engine_t* VR_GetEngine( void ); diff --git a/Common/VR/VRFramebuffer.cpp b/Common/VR/VRFramebuffer.cpp index 007a21cee8..4a71cb5cd8 100644 --- a/Common/VR/VRFramebuffer.cpp +++ b/Common/VR/VRFramebuffer.cpp @@ -37,14 +37,15 @@ void ovrFramebuffer_Clear(ovrFramebuffer* frameBuffer) { frameBuffer->DepthSwapChain.Height = 0; frameBuffer->DepthSwapChainImage = NULL; - frameBuffer->FrameBuffers = NULL; + frameBuffer->GLFrameBuffers = NULL; frameBuffer->Acquired = false; } -bool ovrFramebuffer_Create(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, bool multiview) { +bool ovrFramebuffer_CreateGL(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, bool multiview) { frameBuffer->Width = width; frameBuffer->Height = height; + frameBuffer->UseVulkan = false; if (strstr((const char*)glGetString(GL_EXTENSIONS), "GL_OVR_multiview2") == nullptr) { @@ -78,20 +79,20 @@ bool ovrFramebuffer_Create(XrSession session, ovrFramebuffer* frameBuffer, int w swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->ColorSwapChain.Handle)); OXR(xrEnumerateSwapchainImages(frameBuffer->ColorSwapChain.Handle, 0, &frameBuffer->TextureSwapChainLength, NULL)); - frameBuffer->ColorSwapChainImage = (XrSwapchainImageOpenGLESKHR*)malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR)); + frameBuffer->ColorSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR)); // 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 = (XrSwapchainImageOpenGLESKHR*)malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR)); + frameBuffer->DepthSwapChainImage = malloc(frameBuffer->TextureSwapChainLength * sizeof(XrSwapchainImageOpenGLESKHR)); // Populate the swapchain image array. for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { - frameBuffer->ColorSwapChainImage[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR; - frameBuffer->ColorSwapChainImage[i].next = NULL; - frameBuffer->DepthSwapChainImage[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR; - frameBuffer->DepthSwapChainImage[i].next = NULL; + ((XrSwapchainImageOpenGLESKHR*)frameBuffer->ColorSwapChainImage)[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR; + ((XrSwapchainImageOpenGLESKHR*)frameBuffer->ColorSwapChainImage)[i].next = NULL; + ((XrSwapchainImageOpenGLESKHR*)frameBuffer->DepthSwapChainImage)[i].type = XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_ES_KHR; + ((XrSwapchainImageOpenGLESKHR*)frameBuffer->DepthSwapChainImage)[i].next = NULL; } OXR(xrEnumerateSwapchainImages( frameBuffer->ColorSwapChain.Handle, @@ -104,14 +105,14 @@ bool ovrFramebuffer_Create(XrSession session, ovrFramebuffer* frameBuffer, int w &frameBuffer->TextureSwapChainLength, (XrSwapchainImageBaseHeader*)frameBuffer->DepthSwapChainImage)); - frameBuffer->FrameBuffers = (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint)); + frameBuffer->GLFrameBuffers = (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint)); for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { - const GLuint colorTexture = frameBuffer->ColorSwapChainImage[i].image; - const GLuint depthTexture = frameBuffer->DepthSwapChainImage[i].image; + const GLuint colorTexture = ((XrSwapchainImageOpenGLESKHR*)frameBuffer->ColorSwapChainImage)[i].image; + const GLuint depthTexture = ((XrSwapchainImageOpenGLESKHR*)frameBuffer->DepthSwapChainImage)[i].image; // Create the frame buffer. - GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i])); - GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i])); + 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)); @@ -132,29 +133,114 @@ bool ovrFramebuffer_Create(XrSession session, ovrFramebuffer* frameBuffer, int w return true; } +bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuffer, int width, int height, + bool multiview, void* context) { + + frameBuffer->Width = width; + frameBuffer->Height = height; + frameBuffer->UseVulkan = true; + frameBuffer->VKContext = (XrGraphicsBindingVulkanKHR*)context; + + XrSwapchainCreateInfo swapChainCreateInfo; + memset(&swapChainCreateInfo, 0, sizeof(swapChainCreateInfo)); + swapChainCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO; + swapChainCreateInfo.sampleCount = 1; + swapChainCreateInfo.width = width; + swapChainCreateInfo.height = height; + swapChainCreateInfo.faceCount = 1; + swapChainCreateInfo.mipCount = 1; + swapChainCreateInfo.arraySize = multiview ? 2 : 1; + + 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; + swapChainCreateInfo.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; + OXR(xrCreateSwapchain(session, &swapChainCreateInfo, &frameBuffer->ColorSwapChain.Handle)); + 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->VKFrameBuffers = (VkFramebuffer*)malloc(frameBuffer->TextureSwapChainLength * sizeof(VkFramebuffer)); + for (uint32_t i = 0; i < frameBuffer->TextureSwapChainLength; i++) { + VkImage colorTexture = ((XrSwapchainImageVulkanKHR*)frameBuffer->ColorSwapChainImage)[i].image; + VkImage depthTexture = ((XrSwapchainImageVulkanKHR*)frameBuffer->DepthSwapChainImage)[i].image; + + // Create the frame buffer. + //TODO:implement framebuffer creation + } + + return true; +} + void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) { - GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers)); + if (frameBuffer->UseVulkan) { + for (int i = 0; i < frameBuffer->TextureSwapChainLength; i++) { + vkDestroyFramebuffer(frameBuffer->VKContext->device, frameBuffer->VKFrameBuffers[i], nullptr); + } + free(frameBuffer->VKFrameBuffers); + } else { + GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->GLFrameBuffers)); + free(frameBuffer->GLFrameBuffers); + } OXR(xrDestroySwapchain(frameBuffer->ColorSwapChain.Handle)); OXR(xrDestroySwapchain(frameBuffer->DepthSwapChain.Handle)); free(frameBuffer->ColorSwapChainImage); free(frameBuffer->DepthSwapChainImage); - free(frameBuffer->FrameBuffers); ovrFramebuffer_Clear(frameBuffer); } void ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer) { - GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[frameBuffer->TextureSwapChainIndex])); + if (frameBuffer->UseVulkan) { + //TODO:bind framebuffer + } else { + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->GLFrameBuffers[frameBuffer->TextureSwapChainIndex])); + } } -void ovrFramebuffer_SetNone() { - GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); +void ovrFramebuffer_SetNone(ovrFramebuffer* frameBuffer) { + if (frameBuffer->UseVulkan) { + //TODO:unbind framebuffer + } else { + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); + } } void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer) { // 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); + if (frameBuffer->UseVulkan) { + //TODO:implement + } else { + const GLenum depthAttachment[1] = {GL_DEPTH_ATTACHMENT}; + glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, 1, depthAttachment); + } } void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) { @@ -178,13 +264,18 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) { frameBuffer->Acquired = res == XR_SUCCESS; ovrFramebuffer_SetCurrent(frameBuffer); - GL(glEnable( GL_SCISSOR_TEST )); - 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(glScissor( 0, 0, 0, 0 )); - GL(glDisable( GL_SCISSOR_TEST )); + + if (frameBuffer->UseVulkan) { + //TODO:implement + } else { + GL(glEnable( GL_SCISSOR_TEST )); + 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(glScissor( 0, 0, 0, 0 )); + GL(glDisable( GL_SCISSOR_TEST )); + } } void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer) { @@ -194,10 +285,14 @@ void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer) { frameBuffer->Acquired = false; // Clear the alpha channel, other way OpenXR would not transfer the framebuffer fully - GL(glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE)); - GL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); - GL(glClear(GL_COLOR_BUFFER_BIT)); - GL(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)); + if (frameBuffer->UseVulkan) { + //TODO:implement + } else { + GL(glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE)); + GL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); + GL(glClear(GL_COLOR_BUFFER_BIT)); + GL(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)); + } } } @@ -215,11 +310,15 @@ void ovrRenderer_Clear(ovrRenderer* renderer) { } } -void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, bool multiview) { +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++) { - ovrFramebuffer_Create(session, &renderer->FrameBuffer[i], width, height, multiview); + if (vulkanContext) { + ovrFramebuffer_CreateVK(session, &renderer->FrameBuffer[i], width, height, multiview, vulkanContext); + } else { + ovrFramebuffer_CreateGL(session, &renderer->FrameBuffer[i], width, height, multiview); + } } } @@ -231,12 +330,16 @@ void ovrRenderer_Destroy(ovrRenderer* renderer) { } void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int size) { - GL(glEnable(GL_SCISSOR_TEST)); - GL(glScissor(x, y, size, size)); - GL(glViewport(x, y, size, size)); - GL(glClearColor(1.0f, 1.0f, 1.0f, 1.0f)); - GL(glClear(GL_COLOR_BUFFER_BIT)); - GL(glDisable(GL_SCISSOR_TEST)); + if (renderer->FrameBuffer[0].UseVulkan) { + //TODO:implement + } else { + GL(glEnable(GL_SCISSOR_TEST)); + GL(glScissor(x, y, size, size)); + GL(glViewport(x, y, size, size)); + GL(glClearColor(1.0f, 1.0f, 1.0f, 1.0f)); + GL(glClear(GL_COLOR_BUFFER_BIT)); + GL(glDisable(GL_SCISSOR_TEST)); + } } /* diff --git a/Common/VR/VRFramebuffer.h b/Common/VR/VRFramebuffer.h index 20b9004190..12eb162980 100644 --- a/Common/VR/VRFramebuffer.h +++ b/Common/VR/VRFramebuffer.h @@ -10,8 +10,8 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer); void ovrFramebuffer_Resolve(ovrFramebuffer* frameBuffer); void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer); void ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer); -void ovrFramebuffer_SetNone(); +void ovrFramebuffer_SetNone(ovrFramebuffer* frameBuffer); -void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, bool multiview); +void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int height, bool multiview, void* vulkanContext); void ovrRenderer_Destroy(ovrRenderer* renderer); void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int size); diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index 1d421c2fa3..f9a8e5ce53 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -204,12 +204,14 @@ void VR_InitRenderer( engine_t* engine, bool multiview ) { projections = (XrView*)(malloc(ovrMaxNumEyes * sizeof(XrView))); - ovrRenderer_Create( - engine->appState.Session, - &engine->appState.Renderer, + void* vulkanContext = nullptr; + if (engine->useVulkan) { + vulkanContext = &engine->graphicsBindingVulkan; + } + ovrRenderer_Create(engine->appState.Session, &engine->appState.Renderer, engine->appState.ViewConfigurationView[0].recommendedImageRectWidth, engine->appState.ViewConfigurationView[0].recommendedImageRectHeight, - multiview); + multiview, vulkanContext); initialized = true; } @@ -311,7 +313,7 @@ void VR_EndFrame( engine_t* engine ) { ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer[fboIndex]; //ovrFramebuffer_Resolve(frameBuffer); ovrFramebuffer_Release(frameBuffer); - ovrFramebuffer_SetNone(); + ovrFramebuffer_SetNone(frameBuffer); } void VR_FinishFrame( engine_t* engine ) { diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 482b864ea5..d430322afc 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -940,7 +940,7 @@ extern "C" bool Java_org_ppsspp_ppsspp_NativeRenderer_displayInit(JNIEnv * env, NativeMessageReceived("recreateviews", ""); if (IsVRBuild()) { - EnterVR(firstStart); + EnterVR(firstStart, graphicsContext->GetAPIContext()); } return true;