OpenXR - Foveation implemented (Quest only)

This commit is contained in:
Lubos 2023-03-09 20:42:49 +01:00
parent 61b0513046
commit 4fcc69242e
6 changed files with 78 additions and 0 deletions

View file

@ -153,6 +153,7 @@ void InitVROnAndroid(void* vm, void* activity, const char* system, int version,
VR_SetPlatformFLag(VR_PLATFORM_EXTENSION_INSTANCE, true);
} else if ((strcmp(vendor, "META") == 0) || (strcmp(vendor, "OCULUS") == 0)) {
VR_SetPlatformFLag(VR_PLATFORM_CONTROLLER_QUEST, true);
VR_SetPlatformFLag(VR_PLATFORM_EXTENSION_FOVEATION, true);
VR_SetPlatformFLag(VR_PLATFORM_EXTENSION_PERFORMANCE, true);
}
VR_SetPlatformFLag(VR_PLATFORM_RENDERER_VULKAN, (GPUBackend)g_Config.iGPUBackend == GPUBackend::VULKAN);

View file

@ -49,6 +49,15 @@ void VR_Init( void* system, const char* name, int version ) {
}
extensions.push_back(XR_KHR_COMPOSITION_LAYER_CYLINDER_EXTENSION_NAME);
#ifdef ANDROID
if (VR_GetPlatformFlag(VR_PLATFORM_EXTENSION_FOVEATION)) {
extensions.push_back(XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME);
extensions.push_back(XR_FB_SWAPCHAIN_UPDATE_STATE_OPENGL_ES_EXTENSION_NAME);
extensions.push_back(XR_FB_FOVEATION_EXTENSION_NAME);
extensions.push_back(XR_FB_FOVEATION_CONFIGURATION_EXTENSION_NAME);
if (VR_GetPlatformFlag(VR_PLATFORM_RENDERER_VULKAN)) {
extensions.push_back(XR_FB_SWAPCHAIN_UPDATE_STATE_VULKAN_EXTENSION_NAME);
}
}
if (VR_GetPlatformFlag(VR_PLATFORM_EXTENSION_INSTANCE)) {
extensions.push_back(XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME);
}

View file

@ -120,6 +120,7 @@ typedef struct {
enum VRPlatformFlag {
VR_PLATFORM_CONTROLLER_PICO,
VR_PLATFORM_CONTROLLER_QUEST,
VR_PLATFORM_EXTENSION_FOVEATION,
VR_PLATFORM_EXTENSION_INSTANCE,
VR_PLATFORM_EXTENSION_PERFORMANCE,
VR_PLATFORM_RENDERER_VULKAN,

View file

@ -105,6 +105,15 @@ static bool ovrFramebuffer_CreateGLES(XrSession session, ovrFramebuffer* frameBu
swapChainCreateInfo.mipCount = 1;
swapChainCreateInfo.arraySize = multiview ? 2 : 1;
#ifdef ANDROID
if (VR_GetPlatformFlag(VR_PLATFORM_EXTENSION_FOVEATION)) {
XrSwapchainCreateInfoFoveationFB swapChainFoveationCreateInfo;
memset(&swapChainFoveationCreateInfo, 0, sizeof(swapChainFoveationCreateInfo));
swapChainFoveationCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO_FOVEATION_FB;
swapChainCreateInfo.next = &swapChainFoveationCreateInfo;
}
#endif
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
@ -198,6 +207,15 @@ static bool ovrFramebuffer_CreateVK(XrSession session, ovrFramebuffer* frameBuff
swapChainCreateInfo.mipCount = 1;
swapChainCreateInfo.arraySize = multiview ? 2 : 1;
#ifdef ANDROID
if (VR_GetPlatformFlag(VR_PLATFORM_EXTENSION_FOVEATION)) {
XrSwapchainCreateInfoFoveationFB swapChainFoveationCreateInfo;
memset(&swapChainFoveationCreateInfo, 0, sizeof(swapChainFoveationCreateInfo));
swapChainFoveationCreateInfo.type = XR_TYPE_SWAPCHAIN_CREATE_INFO_FOVEATION_FB;
swapChainCreateInfo.next = &swapChainFoveationCreateInfo;
}
#endif
frameBuffer->ColorSwapChain.Width = swapChainCreateInfo.width;
frameBuffer->ColorSwapChain.Height = swapChainCreateInfo.height;
@ -407,6 +425,47 @@ void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int sx, int sy
}
}
#ifdef ANDROID
void ovrRenderer_SetFoveation(XrInstance* instance, XrSession* session, ovrRenderer* renderer, XrFoveationLevelFB level, float verticalOffset, XrFoveationDynamicFB dynamic) {
PFN_xrCreateFoveationProfileFB pfnCreateFoveationProfileFB;
OXR(xrGetInstanceProcAddr(*instance, "xrCreateFoveationProfileFB", (PFN_xrVoidFunction*)(&pfnCreateFoveationProfileFB)));
PFN_xrDestroyFoveationProfileFB pfnDestroyFoveationProfileFB;
OXR(xrGetInstanceProcAddr(*instance, "xrDestroyFoveationProfileFB", (PFN_xrVoidFunction*)(&pfnDestroyFoveationProfileFB)));
PFN_xrUpdateSwapchainFB pfnUpdateSwapchainFB;
OXR(xrGetInstanceProcAddr(*instance, "xrUpdateSwapchainFB", (PFN_xrVoidFunction*)(&pfnUpdateSwapchainFB)));
int instances = renderer->Multiview ? 1 : ovrMaxNumEyes;
for (int eye = 0; eye < instances; eye++) {
XrFoveationLevelProfileCreateInfoFB levelProfileCreateInfo;
memset(&levelProfileCreateInfo, 0, sizeof(levelProfileCreateInfo));
levelProfileCreateInfo.type = XR_TYPE_FOVEATION_LEVEL_PROFILE_CREATE_INFO_FB;
levelProfileCreateInfo.level = level;
levelProfileCreateInfo.verticalOffset = verticalOffset;
levelProfileCreateInfo.dynamic = dynamic;
XrFoveationProfileCreateInfoFB profileCreateInfo;
memset(&profileCreateInfo, 0, sizeof(profileCreateInfo));
profileCreateInfo.type = XR_TYPE_FOVEATION_PROFILE_CREATE_INFO_FB;
profileCreateInfo.next = &levelProfileCreateInfo;
XrFoveationProfileFB foveationProfile;
pfnCreateFoveationProfileFB(*session, &profileCreateInfo, &foveationProfile);
XrSwapchainStateFoveationFB foveationUpdateState;
memset(&foveationUpdateState, 0, sizeof(foveationUpdateState));
foveationUpdateState.type = XR_TYPE_SWAPCHAIN_STATE_FOVEATION_FB;
foveationUpdateState.profile = foveationProfile;
pfnUpdateSwapchainFB(renderer->FrameBuffer[eye].ColorSwapChain.Handle, (XrSwapchainStateBaseHeaderFB*)(&foveationUpdateState));
pfnDestroyFoveationProfileFB(foveationProfile);
}
}
#endif
/*
================================================================================

View file

@ -13,3 +13,6 @@ void* ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer);
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 sx, int sy);
#ifdef ANDROID
void ovrRenderer_SetFoveation(XrInstance* instance, XrSession* session, ovrRenderer* renderer, XrFoveationLevelFB level, float verticalOffset, XrFoveationDynamicFB dynamic);
#endif

View file

@ -216,6 +216,11 @@ void VR_InitRenderer( engine_t* engine, bool multiview ) {
engine->appState.ViewConfigurationView[0].recommendedImageRectWidth,
engine->appState.ViewConfigurationView[0].recommendedImageRectHeight,
multiview, vulkanContext);
#ifdef ANDROID
if (VR_GetPlatformFlag(VR_PLATFORM_EXTENSION_FOVEATION)) {
ovrRenderer_SetFoveation(&engine->appState.Instance, &engine->appState.Session, &engine->appState.Renderer, XR_FOVEATION_LEVEL_HIGH_FB, 0, XR_FOVEATION_DYNAMIC_LEVEL_ENABLED_FB);
}
#endif
initialized = true;
}