From 2dd66be025e619c9c80b0cc8bed09bde3e4a6c45 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sat, 13 Jan 2024 09:50:17 +0800 Subject: [PATCH 1/6] Update --- .../net/kdt/pojavlaunch/utils/JREUtils.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java index 11fec77f10..9010c841cd 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/JREUtils.java @@ -228,9 +228,6 @@ public static void setJavaEnvironment(Activity activity, String jreHome) throws if(LOCAL_RENDERER.equals("vulkan_zink_legacy")) { envMap.put("POJAVEXEC_OSMESA", "libOSMesa_znL.so"); } - if(LOCAL_RENDERER.equals("adrhw_freedreno") || LOCAL_RENDERER.equals("swrast") || LOCAL_RENDERER.equals("virgl")) { - envMap.put("POJAVEXEC_OSMESA", "libOSMesa.so"); - } } if(LauncherPreferences.PREF_BIG_CORE_AFFINITY) envMap.put("POJAV_BIG_CORE_AFFINITY", "1"); envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth)); @@ -455,19 +452,26 @@ public static String loadGraphicsLibrary(){ String renderLibrary; switch (LOCAL_RENDERER){ case "opengles2": - renderLibrary = "libgl4es_114.so"; break; + renderLibrary = "libgl4es_114.so"; + break; case "vgpu": - renderLibrary = "libvgpu.so"; break; + renderLibrary = "libvgpu.so"; + break; case "malihw_panfrost": - renderLibrary = "libOSMesa_pan.so"; break; + renderLibrary = "libOSMesa_pan.so"; + break; case "vulkan_zink_legacy": - renderLibrary = "libOSMesa_znL.so"; break; + renderLibrary = "libOSMesa_znL.so"; + break; case "malihw_panfrost-new": case "vulkan_zink": case "swrast": - case "virgl": case "adrhw_freedreno": - renderLibrary = "libOSMesa.so"; break; + renderLibrary = "libOSMesa.so"; + break; + case "virgl": + renderLibrary = "libOSMesa_81.so"; + break; case "opengles3_desktopgl_angle_vulkan" : renderLibrary = "libtinywrapper.so"; break; case "opengles3_desktopgl_angle_vulkan_new" : renderLibrary = "libtinywrapper_new_angle.so"; break; default: From a818071def93969864d9aff3b9f231f82fb29b9c Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:09:45 +0800 Subject: [PATCH 2/6] Update --- .../src/main/jni/ctxbridges/osmesa_loader.c | 24 +++++++++++-------- .../src/main/jni/ctxbridges/renderer_config.h | 12 ++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 app_pojavlauncher/src/main/jni/ctxbridges/renderer_config.h diff --git a/app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.c b/app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.c index 35bad442bc..499193b238 100644 --- a/app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.c +++ b/app_pojavlauncher/src/main/jni/ctxbridges/osmesa_loader.c @@ -1,10 +1,12 @@ // -// Created by maks on 21.09.2022. +// Modifile by Vera-Firefly on 13.01.2024. // #include #include #include +#include "environ/environ.h" #include "osmesa_loader.h" +#include "renderer_config.h" GLboolean (*OSMesaMakeCurrent_p) (OSMesaContext ctx, void *buffer, GLenum type, GLsizei width, GLsizei height); @@ -20,19 +22,21 @@ void (*glReadPixels_p) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum void dlsym_OSMesa() { char* main_osm_libname = getenv("POJAVEXEC_OSMESA"); - if(main_osm_libname == NULL) main_osm_libname = "libOSMesa.so"; char* main_path = NULL; - char* alt_path = NULL; - if(asprintf(&main_path, "%s/%s", getenv("POJAV_NATIVEDIR"), main_osm_libname) == -1 || - asprintf(&alt_path, "%s/libOSMesa.so.8", getenv("POJAV_NATIVEDIR")) == -1) { - abort(); + if(pojav_environ->config_renderer == RENDERER_VK_ZINK) { + if(main_osm_libname == NULL) main_osm_libname = "libOSMesa.so"; + if(asprintf(&main_path, "%s/%s", getenv("POJAV_NATIVEDIR"), main_osm_libname) == -1) { + abort(); + } + free(main_path); + } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { + if(asprintf(&main_path, "%s/libOSMesa_81.so", getenv("POJAV_NATIVEDIR")) == -1) { + abort(); + } } void* dl_handle = NULL; - dl_handle = dlopen(alt_path, RTLD_GLOBAL); - if(dl_handle == NULL) dl_handle = dlopen(main_path, RTLD_GLOBAL); + dl_handle = dlopen(main_path, RTLD_GLOBAL); if(dl_handle == NULL) abort(); - free(main_path); - free(alt_path); OSMesaMakeCurrent_p = dlsym(dl_handle, "OSMesaMakeCurrent"); OSMesaGetCurrentContext_p = dlsym(dl_handle,"OSMesaGetCurrentContext"); OSMesaCreateContext_p = dlsym(dl_handle, "OSMesaCreateContext"); diff --git a/app_pojavlauncher/src/main/jni/ctxbridges/renderer_config.h b/app_pojavlauncher/src/main/jni/ctxbridges/renderer_config.h new file mode 100644 index 0000000000..d7b7b2b8a8 --- /dev/null +++ b/app_pojavlauncher/src/main/jni/ctxbridges/renderer_config.h @@ -0,0 +1,12 @@ +// +// Created by Vera-Firefly on 2.12.2023. +// Definitions specific to the renderer +// + + +#define RENDERER_GL4ES 1 +#define RENDERER_VK_ZINK 2 +#define RENDERER_VIRGL 3 +#define RENDERER_VULKAN 4 +#define RENDERER_VK_WARLIP 5 +#define RENDERER_VK_ZINK_PREF 6 \ No newline at end of file From 979aa2a14767646a6d16cfd6e5fa11f3858a531b Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:10:21 +0800 Subject: [PATCH 3/6] Update --- app_pojavlauncher/src/main/jni/egl_bridge.c | 275 ++++++++++++++++++-- 1 file changed, 255 insertions(+), 20 deletions(-) diff --git a/app_pojavlauncher/src/main/jni/egl_bridge.c b/app_pojavlauncher/src/main/jni/egl_bridge.c index ac4b549438..02849a4b84 100644 --- a/app_pojavlauncher/src/main/jni/egl_bridge.c +++ b/app_pojavlauncher/src/main/jni/egl_bridge.c @@ -1,3 +1,6 @@ +// +// Modifile by Vera-Firefly on 13.01.2024. +// #include #include #include @@ -11,6 +14,7 @@ #include #include +#include "ctxbridges/egl_loader.h" #include "ctxbridges/osmesa_loader.h" #include "driver_helper/nsbypass.h" @@ -25,20 +29,23 @@ #include #include #include "utils.h" +#include "ctxbridges/gl_bridge.h" #include "ctxbridges/bridge_tbl.h" #include "ctxbridges/osm_bridge.h" +#include "ctxbridges/renderer_config.h" #define GLFW_CLIENT_API 0x22001 /* Consider GLFW_NO_API as Vulkan API */ #define GLFW_NO_API 0 #define GLFW_OPENGL_API 0x30001 +// region OSMESA internals // This means that the function is an external API and that it will be used #define EXTERNAL_API __attribute__((used)) // This means that you are forced to have this function/variable for ABI compatibility #define ABI_COMPAT __attribute__((unused)) - +// endregion OSMESA internals struct PotatoBridge { /* EGLContext */ void* eglContext; @@ -52,12 +59,11 @@ struct PotatoBridge { EGLConfig config; struct PotatoBridge potatoBridge; -#include "ctxbridges/egl_loader.h" -#include "ctxbridges/osmesa_loader.h" +int (*vtest_main_p) (int argc, char** argv); +void (*vtest_swap_buffers_p) (void); +void bigcore_set_affinity(); -#define RENDERER_GL4ES 1 -#define RENDERER_VK_ZINK 2 -#define RENDERER_VULKAN 4 +void* egl_make_current(void* window); EXTERNAL_API void pojavTerminate() { printf("EGLBridge: Terminating\n"); @@ -79,6 +85,9 @@ EXTERNAL_API void pojavTerminate() { case RENDERER_VK_ZINK: { // Nothing to do here } break; + case RENDERER_VK_ZINK_PREF: { + // Nothing to do here + } break; } } @@ -93,8 +102,26 @@ Java_net_kdt_pojavlaunch_utils_JREUtils_releaseBridgeWindow(ABI_COMPAT JNIEnv *e ANativeWindow_release(pojav_environ->pojavWindow); } +/*If you don't want your renderer for +the Mesa class to crash in your launcher +don't touch the code here +*/ EXTERNAL_API void* pojavGetCurrentContext() { - return br_get_current(); + if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + return br_get_current(); + } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + return (void *)OSMesaGetCurrentContext_p(); + } +} + +//Switches specifically provided for other renderers +void loadSymbols() { + switch (pojav_environ->config_renderer) { + case RENDERER_VIRGL: + dlsym_OSMesa(); + dlsym_EGL(); + break; + } } //#define ADRENO_POSSIBLE @@ -172,8 +199,8 @@ static void set_vulkan_ptr(void* ptr) { } void load_vulkan() { - if(getenv("POJAV_ZINK_PREFER_SYSTEM_DRIVER") == NULL && - android_get_device_api_level() >= 28) { // the loader does not support below that + if(getenv("POJAV_ZINK_PREFER_SYSTEM_DRIVER") == NULL && android_get_device_api_level() >= 28) { + // the loader does not support below that #ifdef ADRENO_POSSIBLE void* result = load_turnip_vulkan(); if(result != NULL) { @@ -189,6 +216,24 @@ void load_vulkan() { set_vulkan_ptr(vulkan_ptr); } +bool loadSymbolsVirGL() { + pojav_environ->config_renderer = RENDERER_VIRGL; + loadSymbols(); + + char* fileName = calloc(1, 1024); + + sprintf(fileName, "%s/libvirgl_test_server.so", getenv("POJAV_NATIVEDIR")); + void *handle = dlopen(fileName, RTLD_LAZY); + printf("VirGL: libvirgl_test_server = %p\n", handle); + if (!handle) { + printf("VirGL: %s\n", dlerror()); + } + vtest_main_p = dlsym(handle, "vtest_main"); + vtest_swap_buffers_p = dlsym(handle, "vtest_swap_buffers"); + + free(fileName); +} + int pojavInitOpenGL() { // Only affects GL4ES as of now const char *forceVsync = getenv("FORCE_VSYNC"); @@ -197,11 +242,14 @@ int pojavInitOpenGL() { // NOTE: Override for now. const char *renderer = getenv("POJAV_RENDERER"); - if (strcmp(renderer, "virgl") == 0) { - pojav_environ->config_renderer = RENDERER_VK_ZINK; - setenv("GALLIUM_DRIVER","virpipe", 1); - setenv("OSMESA_NO_FLUSH_FRONTBUFFER","1", false); // TODO: set to true? - set_osm_bridge_tbl(); + if (strncmp("opengles3_virgl", renderer, 15) == 0) { + pojav_environ->config_renderer = RENDERER_VIRGL; + setenv("GALLIUM_DRIVER","virpipe",1); + setenv("OSMESA_NO_FLUSH_FRONTBUFFER","1",false); + if(strcmp(getenv("OSMESA_NO_FLUSH_FRONTBUFFER"),"1") == 0) { + printf("VirGL: OSMesa buffer flush is DISABLED!\n"); + } + loadSymbolsVirGL(); } else if (strncmp("opengles", renderer, 8) == 0) { pojav_environ->config_renderer = RENDERER_GL4ES; set_gl_bridge_tbl(); @@ -227,9 +275,107 @@ int pojavInitOpenGL() { setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); set_osm_bridge_tbl(); } - if(br_init()) { - br_setup_window(); + if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + if(br_init()) { + br_setup_window(); + } + } + if (pojav_environ->config_renderer == RENDERER_VIRGL) { + if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) { + potatoBridge.eglDisplay = eglGetDisplay_p(EGL_DEFAULT_DISPLAY); + if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) { + printf("EGLBridge: Error eglGetDefaultDisplay() failed: %p\n", eglGetError_p()); + return 0; + } + } + + printf("EGLBridge: Initializing\n"); + // printf("EGLBridge: ANativeWindow pointer = %p\n", pojav_environ->pojavWindow); + //(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception"); + if (!eglInitialize_p(potatoBridge.eglDisplay, NULL, NULL)) { + printf("EGLBridge: Error eglInitialize() failed: %s\n", eglGetError_p()); + return 0; + } + + static const EGLint attribs[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + // Minecraft required on initial 24 + EGL_DEPTH_SIZE, 24, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + + EGLint num_configs; + EGLint vid; + + if (!eglChooseConfig_p(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) { + printf("EGLBridge: Error couldn't get an EGL visual config: %s\n", eglGetError_p()); + return 0; + } + + assert(config); + assert(num_configs > 0); + + if (!eglGetConfigAttrib_p(potatoBridge.eglDisplay, config, EGL_NATIVE_VISUAL_ID, &vid)) { + printf("EGLBridge: Error eglGetConfigAttrib() failed: %s\n", eglGetError_p()); + return 0; + } + + ANativeWindow_setBuffersGeometry(pojav_environ->pojavWindow, 0, 0, vid); + + eglBindAPI_p(EGL_OPENGL_ES_API); + + potatoBridge.eglSurface = eglCreateWindowSurface_p(potatoBridge.eglDisplay, config, pojav_environ->pojavWindow, NULL); + + if (!potatoBridge.eglSurface) { + printf("EGLBridge: Error eglCreateWindowSurface failed: %p\n", eglGetError_p()); + //(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception"); + return 0; + } + + // sanity checks + { + EGLint val; + assert(eglGetConfigAttrib_p(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val)); + assert(val & EGL_WINDOW_BIT); + } + + printf("EGLBridge: Initialized!\n"); + printf("EGLBridge: ThreadID=%d\n", gettid()); + printf("EGLBridge: EGLDisplay=%p, EGLSurface=%p\n", +/* window==0 ? EGL_NO_CONTEXT : */ + potatoBridge.eglDisplay, + potatoBridge.eglSurface + ); + if (pojav_environ->config_renderer != RENDERER_VIRGL) { + return 1; + } + } + + if (pojav_environ->config_renderer == RENDERER_VIRGL) { + // Init EGL context and vtest server + const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_NONE + }; + EGLContext* ctx = eglCreateContext_p(potatoBridge.eglDisplay, config, NULL, ctx_attribs); + printf("VirGL: created EGL context %p\n", ctx); + + pthread_t t; + pthread_create(&t, NULL, egl_make_current, (void *)ctx); + usleep(100*1000); // need enough time for the server to init } + + if (pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + if(OSMesaCreateContext_p == NULL) { + printf("OSMDroid: %s\n",dlerror()); + return 0; + } + } + return 0; } @@ -260,20 +406,102 @@ EXTERNAL_API void pojavSetWindowHint(int hint, int value) { } } +ANativeWindow_Buffer buf; +int32_t stride; +bool stopSwapBuffers; EXTERNAL_API void pojavSwapBuffers() { - br_swap_buffers(); + if (stopSwapBuffers) { + return; + } + if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + br_swap_buffers(); + } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { + glFinish_p(); + vtest_swap_buffers_p(); + } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { + OSMesaContext ctx = OSMesaGetCurrentContext_p(); + if(ctx == NULL) { + printf("Zink: attempted to swap buffers without context!"); + } + OSMesaMakeCurrent_p(ctx,buf.bits,GL_UNSIGNED_BYTE,pojav_environ->savedWidth,pojav_environ->savedHeight); + glFinish_p(); + ANativeWindow_unlockAndPost(pojav_environ->pojavWindow); + ANativeWindow_lock(pojav_environ->pojavWindow,&buf,NULL); + } } +void* egl_make_current(void* window) { + EGLBoolean success = eglMakeCurrent_p( + potatoBridge.eglDisplay, + window==0 ? (EGLSurface *) 0 : potatoBridge.eglSurface, + window==0 ? (EGLSurface *) 0 : potatoBridge.eglSurface, + /* window==0 ? EGL_NO_CONTEXT : */ (EGLContext *) window + ); + + if (success == EGL_FALSE) { + printf("EGLBridge: Error: eglMakeCurrent() failed: %p\n", eglGetError_p()); + } else { + printf("EGLBridge: eglMakeCurrent() succeed!\n"); + } + + if (pojav_environ->config_renderer == RENDERER_VIRGL) { + printf("VirGL: vtest_main = %p\n", vtest_main_p); + printf("VirGL: Calling VTest server's main function\n"); + vtest_main_p(3, (const char*[]){"vtest", "--no-loop-or-fork", "--use-gles", NULL, NULL}); + } +} EXTERNAL_API void pojavMakeCurrent(void* window) { - br_make_current((basic_render_window_t*)window); + if(getenv("POJAV_BIG_CORE_AFFINITY") != NULL) bigcore_set_affinity(); + if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + br_make_current((basic_render_window_t*)window); + } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { + printf("OSMDroid: making current\n"); + OSMesaMakeCurrent_p((OSMesaContext)window,setbuffer,GL_UNSIGNED_BYTE,pojav_environ->savedWidth,pojav_environ->savedHeight); + + + printf("OSMDroid: vendor: %s\n",glGetString_p(GL_VENDOR)); + printf("OSMDroid: renderer: %s\n",glGetString_p(GL_RENDERER)); + glClear_p(GL_COLOR_BUFFER_BIT); + glClearColor_p(0.4f, 0.4f, 0.4f, 1.0f); + + // Trigger a texture creation, which then set VIRGL_TEXTURE_ID + int pixelsArr[4]; + glReadPixels_p(0, 0, 1, 1, GL_RGB, GL_INT, &pixelsArr); + + pojavSwapBuffers(); + return; + } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { + printf("OSMDroid: making current %p\n", pojav_environ->pojavWindow); + ANativeWindow_lock(pojav_environ->pojavWindow,&buf,NULL); + OSMesaMakeCurrent_p((OSMesaContext)window,buf.bits,GL_UNSIGNED_BYTE,pojav_environ->savedWidth,pojav_environ->savedHeight); + OSMesaPixelStore_p(OSMESA_ROW_LENGTH,buf.stride); + OSMesaPixelStore_p(OSMESA_Y_UP,0); + + + printf("OSMDroid: vendor: %s\n",glGetString_p(GL_VENDOR)); + printf("OSMDroid: renderer: %s\n",glGetString_p(GL_RENDERER)); + glClearColor_p(0.4f, 0.4f, 0.4f, 1.0f); + glClear_p(GL_COLOR_BUFFER_BIT); + + pojavSwapBuffers(); + } } EXTERNAL_API void* pojavCreateContext(void* contextSrc) { if (pojav_environ->config_renderer == RENDERER_VULKAN) { return (void *) pojav_environ->pojavWindow; } - return br_init_context((basic_render_window_t*)contextSrc); + + if (pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + return br_init_context((basic_render_window_t*)contextSrc); + } else if (pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + pojavInitOpenGL(); + printf("OSMDroid: generating context\n"); + void* ctx = OSMesaCreateContext_p(OSMESA_RGBA,contextSrc); + printf("OSMDroid: context=%p\n",ctx); + return ctx; + } } EXTERNAL_API JNIEXPORT jlong JNICALL @@ -287,6 +515,13 @@ Java_org_lwjgl_vulkan_VK_getVulkanDriverHandle(ABI_COMPAT JNIEnv *env, ABI_COMPA } EXTERNAL_API void pojavSwapInterval(int interval) { - br_swap_interval(interval); + if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { + br_swap_interval(interval); + } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { + eglSwapInterval_p(potatoBridge.eglDisplay, interval); + } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { + printf("eglSwapInterval: NOT IMPLEMENTED YET!\n"); + // Nothing to do here + } } From 3d480bddad04897893027eac558d85726c915cfb Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:13:57 +0800 Subject: [PATCH 4/6] Remove unused code --- app_pojavlauncher/src/main/jni/egl_bridge.c | 35 ++------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/app_pojavlauncher/src/main/jni/egl_bridge.c b/app_pojavlauncher/src/main/jni/egl_bridge.c index 02849a4b84..53f4e90467 100644 --- a/app_pojavlauncher/src/main/jni/egl_bridge.c +++ b/app_pojavlauncher/src/main/jni/egl_bridge.c @@ -85,9 +85,6 @@ EXTERNAL_API void pojavTerminate() { case RENDERER_VK_ZINK: { // Nothing to do here } break; - case RENDERER_VK_ZINK_PREF: { - // Nothing to do here - } break; } } @@ -109,7 +106,7 @@ don't touch the code here EXTERNAL_API void* pojavGetCurrentContext() { if(pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { return br_get_current(); - } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { return (void *)OSMesaGetCurrentContext_p(); } } @@ -369,7 +366,7 @@ int pojavInitOpenGL() { usleep(100*1000); // need enough time for the server to init } - if (pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + if (pojav_environ->config_renderer == RENDERER_VIRGL) { if(OSMesaCreateContext_p == NULL) { printf("OSMDroid: %s\n",dlerror()); return 0; @@ -418,15 +415,6 @@ EXTERNAL_API void pojavSwapBuffers() { } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { glFinish_p(); vtest_swap_buffers_p(); - } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { - OSMesaContext ctx = OSMesaGetCurrentContext_p(); - if(ctx == NULL) { - printf("Zink: attempted to swap buffers without context!"); - } - OSMesaMakeCurrent_p(ctx,buf.bits,GL_UNSIGNED_BYTE,pojav_environ->savedWidth,pojav_environ->savedHeight); - glFinish_p(); - ANativeWindow_unlockAndPost(pojav_environ->pojavWindow); - ANativeWindow_lock(pojav_environ->pojavWindow,&buf,NULL); } } @@ -471,20 +459,6 @@ EXTERNAL_API void pojavMakeCurrent(void* window) { pojavSwapBuffers(); return; - } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { - printf("OSMDroid: making current %p\n", pojav_environ->pojavWindow); - ANativeWindow_lock(pojav_environ->pojavWindow,&buf,NULL); - OSMesaMakeCurrent_p((OSMesaContext)window,buf.bits,GL_UNSIGNED_BYTE,pojav_environ->savedWidth,pojav_environ->savedHeight); - OSMesaPixelStore_p(OSMESA_ROW_LENGTH,buf.stride); - OSMesaPixelStore_p(OSMESA_Y_UP,0); - - - printf("OSMDroid: vendor: %s\n",glGetString_p(GL_VENDOR)); - printf("OSMDroid: renderer: %s\n",glGetString_p(GL_RENDERER)); - glClearColor_p(0.4f, 0.4f, 0.4f, 1.0f); - glClear_p(GL_COLOR_BUFFER_BIT); - - pojavSwapBuffers(); } } @@ -495,7 +469,7 @@ EXTERNAL_API void* pojavCreateContext(void* contextSrc) { if (pojav_environ->config_renderer == RENDERER_VK_ZINK || pojav_environ->config_renderer == RENDERER_GL4ES) { return br_init_context((basic_render_window_t*)contextSrc); - } else if (pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF || pojav_environ->config_renderer == RENDERER_VIRGL) { + } else if (pojav_environ->config_renderer == RENDERER_VIRGL) { pojavInitOpenGL(); printf("OSMDroid: generating context\n"); void* ctx = OSMesaCreateContext_p(OSMESA_RGBA,contextSrc); @@ -519,9 +493,6 @@ EXTERNAL_API void pojavSwapInterval(int interval) { br_swap_interval(interval); } else if(pojav_environ->config_renderer == RENDERER_VIRGL) { eglSwapInterval_p(potatoBridge.eglDisplay, interval); - } else if(pojav_environ->config_renderer == RENDERER_VK_ZINK_PREF) { - printf("eglSwapInterval: NOT IMPLEMENTED YET!\n"); - // Nothing to do here } } From 84cf5cf96a7d2227b6090fa8c75728b12f5348a6 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sat, 13 Jan 2024 11:06:46 +0800 Subject: [PATCH 5/6] Fix[bridge]: Misrepresentation --- app_pojavlauncher/src/main/jni/egl_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_pojavlauncher/src/main/jni/egl_bridge.c b/app_pojavlauncher/src/main/jni/egl_bridge.c index 53f4e90467..144661ed6b 100644 --- a/app_pojavlauncher/src/main/jni/egl_bridge.c +++ b/app_pojavlauncher/src/main/jni/egl_bridge.c @@ -239,7 +239,7 @@ int pojavInitOpenGL() { // NOTE: Override for now. const char *renderer = getenv("POJAV_RENDERER"); - if (strncmp("opengles3_virgl", renderer, 15) == 0) { + if (strncmp("virgl", renderer, 15) == 0) { pojav_environ->config_renderer = RENDERER_VIRGL; setenv("GALLIUM_DRIVER","virpipe",1); setenv("OSMESA_NO_FLUSH_FRONTBUFFER","1",false); From b09840ae19f3d6fc5dffc5a91d68021e706540cd Mon Sep 17 00:00:00 2001 From: Vera-Firefly <87926662+Vera-Firefly@users.noreply.github.com> Date: Sun, 14 Jan 2024 07:43:13 +0800 Subject: [PATCH 6/6] Add virgl renderer again --- app_pojavlauncher/src/main/res/values/headings_array.xml | 8 +++++--- app_pojavlauncher/src/main/res/values/strings.xml | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app_pojavlauncher/src/main/res/values/headings_array.xml b/app_pojavlauncher/src/main/res/values/headings_array.xml index e08203c663..5dc2626b77 100644 --- a/app_pojavlauncher/src/main/res/values/headings_array.xml +++ b/app_pojavlauncher/src/main/res/values/headings_array.xml @@ -5,9 +5,10 @@ @string/mcl_setting_renderer_vulkan_zink @string/mcl_setting_renderer_angle @string/mcl_setting_renderer_angle_new - @string/mcl_setting_renderer_panfrost - @string/mcl_setting_renderer_freedreno - @string/mcl_setting_renderer_softpipe + @string/mcl_setting_renderer_virgl + @string/mcl_setting_renderer_panfrost + @string/mcl_setting_renderer_freedreno + @string/mcl_setting_renderer_softpipe @string/mcl_setting_renderer_vulkan_zink_legacy @@ -45,6 +46,7 @@ vulkan_zink opengles3_desktopgl_angle_vulkan opengles3_desktopgl_angle_vulkan_new + virgl malihw_panfrost adrhw_freedreno swrast diff --git a/app_pojavlauncher/src/main/res/values/strings.xml b/app_pojavlauncher/src/main/res/values/strings.xml index f2ab8727f5..a32875cd12 100644 --- a/app_pojavlauncher/src/main/res/values/strings.xml +++ b/app_pojavlauncher/src/main/res/values/strings.xml @@ -66,6 +66,7 @@ Renderer Holy GL4ES - (all versions, fast) Zink (Vulkan) - (all versions, mid) + virglrenderer - (release 1.7+, slow) ANGLE (Vulkan) - (1.17+ only, fast) Updated ANGLE (Vulkan) - (1.17+ only, mid) Panfrost (Mali Gx10 only) - (all versions, mid)