From b54835a6e1ec91cab429b89e51d6e1ad49434256 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 09:15:04 +0200 Subject: [PATCH 1/9] OpenXR - Remove depth buffer --- app/src/main/cpp/xr/framebuffer.c | 14 +------------- app/src/main/cpp/xr/framebuffer.h | 1 - 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/app/src/main/cpp/xr/framebuffer.c b/app/src/main/cpp/xr/framebuffer.c index e79b54fa..a50c1906 100644 --- a/app/src/main/cpp/xr/framebuffer.c +++ b/app/src/main/cpp/xr/framebuffer.c @@ -21,9 +21,7 @@ bool XrFramebufferCreate(struct XrFramebuffer *framebuffer, XrSession session, i void XrFramebufferDestroy(struct XrFramebuffer *framebuffer) { #if XR_USE_GRAPHICS_API_OPENGL_ES - GL(glDeleteRenderbuffers(framebuffer->SwapchainLength, framebuffer->GLDepthBuffers)); GL(glDeleteFramebuffers(framebuffer->SwapchainLength, framebuffer->GLFrameBuffers)); - free(framebuffer->GLDepthBuffers); free(framebuffer->GLFrameBuffers); #endif OXR(xrDestroySwapchain(framebuffer->Handle)); @@ -57,7 +55,7 @@ void XrFramebufferAcquire(struct XrFramebuffer *framebuffer) GL(glViewport(0, 0, framebuffer->Width, framebuffer->Height)); GL(glClearColor(0.0f, 0.0f, 0.0f, 0.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 @@ -114,24 +112,14 @@ bool XrFramebufferCreateGL(struct XrFramebuffer *framebuffer, XrSession session, &framebuffer->SwapchainLength, (XrSwapchainImageBaseHeader*)framebuffer->SwapchainImage)); - framebuffer->GLDepthBuffers = (GLuint*)malloc(framebuffer->SwapchainLength * sizeof(GLuint)); framebuffer->GLFrameBuffers = (GLuint*)malloc(framebuffer->SwapchainLength * sizeof(GLuint)); for (uint32_t i = 0; i < framebuffer->SwapchainLength; i++) { - // Create color and depth buffers. GLuint color_texture = ((XrSwapchainImageOpenGLESKHR*)framebuffer->SwapchainImage)[i].image; - GL(glGenRenderbuffers(1, &framebuffer->GLDepthBuffers[i])); - GL(glBindRenderbuffer(GL_RENDERBUFFER, framebuffer->GLDepthBuffers[i])); - GL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height)); - GL(glBindRenderbuffer(GL_RENDERBUFFER, 0)); // Create the frame buffer. GL(glGenFramebuffers(1, &framebuffer->GLFrameBuffers[i])); GL(glBindFramebuffer(GL_FRAMEBUFFER, framebuffer->GLFrameBuffers[i])); - GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, - framebuffer->GLDepthBuffers[i])); - GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, - framebuffer->GLDepthBuffers[i])); GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture, 0)); GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER)); diff --git a/app/src/main/cpp/xr/framebuffer.h b/app/src/main/cpp/xr/framebuffer.h index 5983b165..c0c5312f 100644 --- a/app/src/main/cpp/xr/framebuffer.h +++ b/app/src/main/cpp/xr/framebuffer.h @@ -12,7 +12,6 @@ struct XrFramebuffer { uint32_t SwapchainLength; void* SwapchainImage; - unsigned int* GLDepthBuffers; unsigned int* GLFrameBuffers; }; From 2997f045701749db3551b54b3ae187b8502c4ecd Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 09:17:24 +0200 Subject: [PATCH 2/9] OpenXR - Fix stage errors --- app/src/main/cpp/xr/renderer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/xr/renderer.c b/app/src/main/cpp/xr/renderer.c index 017c4c6d..ff4dc856 100644 --- a/app/src/main/cpp/xr/renderer.c +++ b/app/src/main/cpp/xr/renderer.c @@ -471,6 +471,8 @@ void XrRendererRecenter(struct XrEngine* engine, struct XrRenderer* renderer) // Create a default stage space to use if SPACE_TYPE_STAGE is not // supported, or calls to xrGetReferenceSpaceBoundsRect fail. space_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_LOCAL; + memset(&space_info.poseInReferenceSpace, 0, sizeof(XrPosef)); + space_info.poseInReferenceSpace.orientation.w = 1.0; if (engine->PlatformFlag[PLATFORM_TRACKING_FLOOR]) { space_info.poseInReferenceSpace.position.y = -1.6750f; @@ -482,7 +484,8 @@ void XrRendererRecenter(struct XrEngine* engine, struct XrRenderer* renderer) if (renderer->StageSupported) { space_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_STAGE; - space_info.poseInReferenceSpace.position.y = 0.0; + memset(&space_info.poseInReferenceSpace, 0, sizeof(XrPosef)); + space_info.poseInReferenceSpace.orientation.w = 1.0; OXR(xrCreateReferenceSpace(engine->Session, &space_info, &engine->StageSpace)); ALOGV("Created stage space"); if (engine->PlatformFlag[PLATFORM_TRACKING_FLOOR]) From 2b2aba0d1d36506d1f92137425b0645f69a3112b Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 09:39:13 +0200 Subject: [PATCH 3/9] OpenXR - Debugging fixed --- app/src/main/cpp/xr/engine.h | 22 +++++++++++----------- app/src/main/cpp/xr/main.c | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/cpp/xr/engine.h b/app/src/main/cpp/xr/engine.h index d0c35ea2..dc1f7c92 100644 --- a/app/src/main/cpp/xr/engine.h +++ b/app/src/main/cpp/xr/engine.h @@ -8,17 +8,6 @@ #define ANDROID 1 #endif -#if defined(_DEBUG) -void GLCheckErrors(const char* file, int line); -void OXRCheckErrors(XrResult result, const char* file, int line); - -#define GL(func) func; GLCheckErrors(__FILE__ , __LINE__); -#define OXR(func) OXRCheckErrors(func, __FILE__ , __LINE__); -#else -#define GL(func) func; -#define OXR(func) func; -#endif - #ifdef ANDROID #include #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, "OpenXR", __VA_ARGS__); @@ -38,6 +27,17 @@ void OXRCheckErrors(XrResult result, const char* file, int line); #include #include +#if defined(_DEBUG) +void GLCheckErrors(const char* file, int line); +void OXRCheckErrors(XrResult result, const char* file, int line); + +#define GL(func) func; GLCheckErrors(__FILE__ , __LINE__); +#define OXR(func) OXRCheckErrors(func, __FILE__ , __LINE__); +#else +#define GL(func) func; +#define OXR(func) func; +#endif + enum { XrMaxLayerCount = 2 diff --git a/app/src/main/cpp/xr/main.c b/app/src/main/cpp/xr/main.c index 739cb5af..9a5876ab 100644 --- a/app/src/main/cpp/xr/main.c +++ b/app/src/main/cpp/xr/main.c @@ -25,7 +25,7 @@ void GLCheckErrors(const char* file, int line) { void OXRCheckErrors(XrResult result, const char* file, int line) { if (XR_FAILED(result)) { char errorBuffer[XR_MAX_RESULT_STRING_SIZE]; - xrResultToString(xr_module_engine->Instance, result, errorBuffer); + xrResultToString(xr_module_engine.Instance, result, errorBuffer); ALOGE("OpenXR error on line %s:%d %s", file, line, errorBuffer); } } From ac7ec4f82634ca866eb453bfe68a328a1bb603be Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 09:48:52 +0200 Subject: [PATCH 4/9] OpenXR - Initialization fixed --- app/src/main/cpp/xr/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/xr/main.c b/app/src/main/cpp/xr/main.c index 9a5876ab..1aa2bea7 100644 --- a/app/src/main/cpp/xr/main.c +++ b/app/src/main/cpp/xr/main.c @@ -90,7 +90,7 @@ JNIEXPORT jboolean JNICALL Java_com_winlator_XrActivity_beginFrame(JNIEnv *env, xr_module_renderer.ConfigInt[CONFIG_SBS] = sbs; // Recenter if mode switched - static bool last_immersive = false; + static int last_immersive = -1; if (last_immersive != immersive) { XrRendererRecenter(&xr_module_engine, &xr_module_renderer); last_immersive = immersive; From 6f9de8b92aec5b873360745ac2dbfd8cf34a78ec Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 09:53:40 +0200 Subject: [PATCH 5/9] OpenXR - Move FBO to GLESv3 --- app/src/main/cpp/xr/framebuffer.c | 8 +++++--- app/src/main/cpp/xr/main.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/xr/framebuffer.c b/app/src/main/cpp/xr/framebuffer.c index a50c1906..1c603201 100644 --- a/app/src/main/cpp/xr/framebuffer.c +++ b/app/src/main/cpp/xr/framebuffer.c @@ -1,8 +1,8 @@ #include "framebuffer.h" #if XR_USE_GRAPHICS_API_OPENGL_ES -#include -#include +#include +#include #endif #include @@ -65,6 +65,8 @@ void XrFramebufferRelease(struct XrFramebuffer *framebuffer) { if (framebuffer->Acquired) { + const GLenum depthAttachment[1] = {GL_DEPTH_ATTACHMENT}; + glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, depthAttachment); XrSwapchainImageReleaseInfo release_info = {XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO, NULL}; OXR(xrReleaseSwapchainImage(framebuffer->Handle, &release_info)); framebuffer->Acquired = false; @@ -95,7 +97,7 @@ bool XrFramebufferCreateGL(struct XrFramebuffer *framebuffer, XrSession session, framebuffer->Height = swapchain_info.height; // Create the color swapchain. - swapchain_info.format = GL_SRGB8_ALPHA8_EXT; + swapchain_info.format = GL_RGBA8; swapchain_info.usageFlags = XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT; OXR(xrCreateSwapchain(session, &swapchain_info, &framebuffer->Handle)); OXR(xrEnumerateSwapchainImages(framebuffer->Handle, 0, &framebuffer->SwapchainLength, NULL)); diff --git a/app/src/main/cpp/xr/main.c b/app/src/main/cpp/xr/main.c index 1aa2bea7..5aa80228 100644 --- a/app/src/main/cpp/xr/main.c +++ b/app/src/main/cpp/xr/main.c @@ -85,7 +85,7 @@ JNIEXPORT jboolean JNICALL Java_com_winlator_XrActivity_beginFrame(JNIEnv *env, // Set render canvas int mode = immersive ? RENDER_MODE_MONO_6DOF : RENDER_MODE_MONO_SCREEN; xr_module_renderer.ConfigFloat[CONFIG_CANVAS_DISTANCE] = 5.0f; - xr_module_renderer.ConfigInt[CONFIG_PASSTHROUGH] = true; + xr_module_renderer.ConfigInt[CONFIG_PASSTHROUGH] = !immersive; xr_module_renderer.ConfigInt[CONFIG_MODE] = mode; xr_module_renderer.ConfigInt[CONFIG_SBS] = sbs; From 30b272de14fccb6c7c40b2cc79c3f18002fcb579 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 10:12:30 +0200 Subject: [PATCH 6/9] Prevent losing mouse --- app/src/main/java/com/winlator/XrActivity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/winlator/XrActivity.java b/app/src/main/java/com/winlator/XrActivity.java index fa9e5559..c6bfa17a 100644 --- a/app/src/main/java/com/winlator/XrActivity.java +++ b/app/src/main/java/com/winlator/XrActivity.java @@ -230,6 +230,10 @@ public static void updateControllers() { float meter2px = instance.getXServer().screenInfo.width * 10.0f; float dx = (axes[mouseAxisX.ordinal()] - lastAxes[mouseAxisX.ordinal()]) * meter2px; float dy = (axes[mouseAxisY.ordinal()] - lastAxes[mouseAxisY.ordinal()]) * meter2px; + if ((Math.abs(dx) > 100) || (Math.abs(dy) > 100)) { + dx = 0; + dy = 0; + } // Mouse control with head Pointer mouse = instance.getXServer().pointer; From 50ef77c9ffd29a966dba38a13bc164cf7005597c Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 10:28:19 +0200 Subject: [PATCH 7/9] OpenXR - Adjust mouse threshold --- app/src/main/java/com/winlator/XrActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/winlator/XrActivity.java b/app/src/main/java/com/winlator/XrActivity.java index c6bfa17a..e1643a57 100644 --- a/app/src/main/java/com/winlator/XrActivity.java +++ b/app/src/main/java/com/winlator/XrActivity.java @@ -230,7 +230,7 @@ public static void updateControllers() { float meter2px = instance.getXServer().screenInfo.width * 10.0f; float dx = (axes[mouseAxisX.ordinal()] - lastAxes[mouseAxisX.ordinal()]) * meter2px; float dy = (axes[mouseAxisY.ordinal()] - lastAxes[mouseAxisY.ordinal()]) * meter2px; - if ((Math.abs(dx) > 100) || (Math.abs(dy) > 100)) { + if ((Math.abs(dx) > 300) || (Math.abs(dy) > 300)) { dx = 0; dy = 0; } From 15d14c6026fa8237ebcd5c9838d6c1eb302fc194 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 14:57:04 +0200 Subject: [PATCH 8/9] OpenXR - Fix rebinding framebuffer --- app/src/main/java/com/winlator/renderer/Texture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/winlator/renderer/Texture.java b/app/src/main/java/com/winlator/renderer/Texture.java index 22e79423..94664677 100644 --- a/app/src/main/java/com/winlator/renderer/Texture.java +++ b/app/src/main/java/com/winlator/renderer/Texture.java @@ -36,7 +36,6 @@ public void allocateTexture(short width, short height, ByteBuffer data) { GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, minFilter); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - if (XrActivity.isSupported()) XrActivity.getInstance().bindFramebuffer(); } public int getWrapS() { @@ -118,6 +117,7 @@ public void copyFromFramebuffer(int framebuffer, short width, short height) { GLES20.glCopyTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 0, 0, width, height, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); + if (XrActivity.isSupported()) XrActivity.getInstance().bindFramebuffer(); } public void destroy() { From 805d8b8475e8dea0a6d1771f630248addc18a919 Mon Sep 17 00:00:00 2001 From: Lubos Date: Tue, 27 Aug 2024 16:39:44 +0200 Subject: [PATCH 9/9] OpenXR - Different defaults for VR headsets --- app/src/main/java/com/winlator/container/Container.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/winlator/container/Container.java b/app/src/main/java/com/winlator/container/Container.java index 97090e7f..6a654f46 100644 --- a/app/src/main/java/com/winlator/container/Container.java +++ b/app/src/main/java/com/winlator/container/Container.java @@ -2,6 +2,7 @@ import android.os.Environment; +import com.winlator.XrActivity; import com.winlator.box86_64.Box86_64Preset; import com.winlator.core.EnvVars; import com.winlator.core.FileUtils; @@ -25,9 +26,9 @@ public enum XrControllerMapping { public static final String DEFAULT_ENV_VARS = "ZINK_DESCRIPTORS=lazy ZINK_DEBUG=compact MESA_SHADER_CACHE_DISABLE=false MESA_SHADER_CACHE_MAX_SIZE=512MB mesa_glthread=true WINEESYNC=1 MESA_VK_WSI_PRESENT_MODE=mailbox TU_DEBUG=noconform"; public static final String DEFAULT_SCREEN_SIZE = "1280x720"; - public static final String DEFAULT_GRAPHICS_DRIVER = "turnip"; - public static final String DEFAULT_AUDIO_DRIVER = "alsa"; - public static final String DEFAULT_DXWRAPPER = "dxvk"; + public static final String DEFAULT_GRAPHICS_DRIVER = XrActivity.isSupported() ? "virgl-23.1.9" : "turnip"; + public static final String DEFAULT_AUDIO_DRIVER = XrActivity.isSupported() ? "pulseaudio" : "alsa"; + public static final String DEFAULT_DXWRAPPER = XrActivity.isSupported() ? "wined3d" : "dxvk"; public static final String DEFAULT_WINCOMPONENTS = "direct3d=1,directsound=1,directmusic=0,directshow=0,directplay=0,vcrun2010=1,wmdecoder=1"; public static final String FALLBACK_WINCOMPONENTS = "direct3d=0,directsound=0,directmusic=0,directshow=0,directplay=0,vcrun2010=0,wmdecoder=0"; public static final String DEFAULT_DRIVES = "D:"+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"E:/data/data/com.winlator/storage";