Skip to content

Commit

Permalink
worth a shot
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Sep 21, 2024
1 parent ce46c23 commit 0ea2d10
Show file tree
Hide file tree
Showing 29 changed files with 921 additions and 74 deletions.
762 changes: 762 additions & 0 deletions jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/GL.java

Large diffs are not rendered by default.

Binary file modified src/main/assets/lwjgl/lwjgl-glfw-classes.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/assets/lwjgl/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1725986487354
1726879946411
7 changes: 1 addition & 6 deletions src/main/java/pojlib/util/JREUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,8 @@ public static void setJavaEnvironment(Activity activity, MinecraftInstances.Inst
envMap.put("GALLIUM_DRIVER", "zink");
envMap.put("MESA_LOADER_DRIVER_OVERRIDE", "zink");
envMap.put("MESA_LOG_FILE", instance.gameDir + "/mesa.log");
envMap.put("LIBGL_DRIVERS_PATH", activity.getApplicationInfo().nativeLibraryDir);
envMap.put("EGL_PLATFORM", "surfaceless");
envMap.put("POJLIB_RENDERER", "zink");
envMap.put("ZINK_DEBUG", "compact,gpl");
envMap.put("ZINK_DESCRIPTORS", "lazy");
envMap.put("FD_DEV_FEATURES", "enable_tp_ubwc_flag_hint=1");
envMap.put("POJAV_RENDERER", "zink");

envMap.put("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
envMap.put("PATH", activity.getFilesDir() + "/runtimes/JRE-22/bin:" + Os.getenv("PATH"));
Expand Down Expand Up @@ -236,7 +232,6 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr
public static List<String> getJavaArgs(Context ctx, MinecraftInstances.Instance instance) {
return new ArrayList<>(Arrays.asList(
"-Djava.home=" + new File(ctx.getFilesDir(), "runtimes/JRE-22"),
"-Djava.io.tmpdir=" + ctx.getApplicationInfo().nativeLibraryDir + "/.cache",
"-Duser.home=" + instance.gameDir,
"-Duser.language=" + System.getProperty("user.language"),
"-Dos.name=Linux",
Expand Down
11 changes: 8 additions & 3 deletions src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
# Link GLESv2 for test
LOCAL_LDLIBS := -ldl -llog -landroid -lGLESv3 -lEGL
LOCAL_LDLIBS := -ldl -llog -landroid
LOCAL_CFLAGS := -DXR_USE_PLATFORM_ANDROID -DXR_USE_GRAPHICS_API_OPENGL_ES
# -lGLESv2
LOCAL_MODULE := pojavexec
# LOCAL_CFLAGS += -DDEBUG
LOCAL_SHARED_LIBRARIES := openvr_api
# -DGLES_TEST
LOCAL_SRC_FILES := \
egl_bridge.c \
Expand All @@ -46,7 +45,13 @@ LOCAL_SRC_FILES := \
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -landroid -lGLESv3 -lvulkan -lEGL
LOCAL_MODULE := tinywrapper
LOCAL_SRC_FILES := \
tinywrapper/main.c
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog -landroid -lGLESv3 -lvulkan
LOCAL_CFLAGS := -DXR_USE_PLATFORM_ANDROID -DXR_USE_GRAPHICS_API_OPENGL_ES
LOCAL_SHARED_LIBRARIES := openxr_loader pojavexec
LOCAL_WHOLE_STATIC_LIBRARIES := ocovr
Expand Down
Binary file modified src/main/jni/adrenotools/libadrenotools.so
Binary file not shown.
56 changes: 20 additions & 36 deletions src/main/jni/egl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,21 @@ eglSwapBuffers_t* eglSwapBuffers_p;
eglSwapInterval_t* eglSwapInterval_p;
eglGetProcAddress_t* eglGetProcAddress_p;

EGLContext xrEglContext;
EGLDisplay xrEglDisplay;
EGLSurface xrEglSurface;
EGLConfig xrConfig;
EGLContext gameEglContext;
EGLDisplay gameEglDisplay;
EGLSurface gameEglSurface;
EGLConfig gameConfig;

void* gbuffer;

void dlsym_egl() {
void* handle = dlopen("libEGL_mesa.so", RTLD_NOW);
eglGetDisplay_p = (eglGetDisplay_t*) dlsym(handle, "eglGetDisplay");
eglInitialize_p = (eglInitialize_t*) dlsym(handle, "eglInitialize");
eglChooseConfig_p = (eglChooseConfig_t*) dlsym(handle, "eglChooseConfig");
eglGetConfigAttrib_p = (eglGetConfigAttrib_t*) dlsym(handle, "eglGetConfigAttrib");
eglBindAPI_p = (eglBindAPI_t*) dlsym(handle, "eglBindAPI");
eglCreatePbufferSurface_p = (eglCreatePbufferSurface_t*) dlsym(handle, "eglCreatePbufferSurface");
eglCreateContext_p = (eglCreateContext_t*) dlsym(handle, "eglCreateContext");
eglMakeCurrent_p = (eglMakeCurrent_t*) dlsym(handle, "eglMakeCurrent");
eglCreateImage_p = (eglCreateImage_t*) dlsym(handle, "eglCreateImage");
eglGetError_p = (eglGetError_t*) dlsym(handle, "eglGetError");
eglSwapBuffers_p = (eglSwapBuffers_t*) dlsym(handle, "eglSwapBuffers");
eglSwapInterval_p = (eglSwapInterval_t*) dlsym(handle, "eglSwapInterval");
eglGetProcAddress_p = (eglGetProcAddress_t*) dlsym(handle, "eglGetProcAddress");
eglExportDMABUFImageMESA_p = (PFNEGLEXPORTDMABUFIMAGEMESAPROC) eglGetProcAddress_p("eglExportDMABUFImageMESA");
eglExportDMABUFImageQueryMESA_p = (PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) eglGetProcAddress_p("eglExportDMABUFImageQueryMESA");
}

void pojav_openGLOnLoad() {
}
void pojav_openGLOnUnload() {

}

void pojavTerminate() {
}
if(!handle) {
printf("Couldn't dlopen mesa! %s\n", dlerror());
}

void dlsym_egl() {
void* handle = dlopen("libtinywrapper.so", RTLD_NOW);
eglGetProcAddress_p = (eglGetProcAddress_t*) dlsym(handle, "eglGetProcAddress");

eglGetDisplay_p = (eglGetDisplay_t*) eglGetProcAddress_p("eglGetDisplay");
eglInitialize_p = (eglInitialize_t*) eglGetProcAddress_p("eglInitialize");
eglChooseConfig_p = (eglChooseConfig_t*) eglGetProcAddress_p("eglChooseConfig");
Expand All @@ -102,6 +79,15 @@ void dlsym_egl() {
eglSwapInterval_p = (eglSwapInterval_t*) eglGetProcAddress_p("eglSwapInterval");
}

void pojav_openGLOnLoad() {
}
void pojav_openGLOnUnload() {

}

void pojavTerminate() {
}

void* pojavGetCurrentContext() {
return gameEglContext;
}
Expand Down Expand Up @@ -180,7 +166,7 @@ int gameEglInit() {
};

gameEglSurface = eglCreatePbufferSurface_p(gameEglDisplay, gameConfig,
surface_attribs);
surface_attribs);
if (!gameEglSurface) {
printf("GameEGL: Error eglCreatePbufferSurface failed: %d\n", eglGetError_p());
}
Expand All @@ -201,10 +187,7 @@ void initDriver() {
char *nativeDir;
asprintf(&nativeDir, "%s/", getenv("POJLIB_NATIVEDIR"));
asprintf(&gpuStuff, "%s/gpustuff", getenv("HOME"));
void *libvulkan = adrenotools_open_libvulkan(RTLD_NOW, ADRENOTOOLS_DRIVER_CUSTOM, gpuStuff,
gpuStuff, nativeDir,
"libvulkan_freedreno.so", NULL, NULL);
dlopen("libvulkan.so", RTLD_NOW);
void *libvulkan = dlopen("libvulkan.so", RTLD_NOW);
printf("Driver Loader: libvulkan handle: %p\n", libvulkan);
char *vulkanPtrString;
asprintf(&vulkanPtrString, "%p", libvulkan);
Expand Down Expand Up @@ -267,6 +250,7 @@ void* pojavCreateContext(void* contextSrc) {
EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_CONTEXT_MINOR_VERSION, 2,
EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE, EGL_TRUE,
EGL_NONE
};
EGLContext* ctx = eglCreateContext_p(gameEglDisplay, gameConfig, contextSrc, ctx_attribs);
Expand Down
7 changes: 7 additions & 0 deletions src/main/jni/environ/environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdatomic.h>
#include <jni.h>
#include <OpenOVR/openxr_platform.h>
#include <vulkan/vulkan.h>

/* How many events can be handled at the same time */
#define EVENT_WINDOW_SIZE 8000
Expand Down Expand Up @@ -54,6 +55,12 @@ struct pojav_environ_s {
jobject activity;
XrInstanceCreateInfoAndroidKHR *OpenComposite_Android_Create_Info;
XrGraphicsBindingOpenGLESAndroidKHR *OpenComposite_Android_GLES_Binding_Info;
VkInstance instance;
void* pDev;
VkDevice device;
VkQueue queue;
int queueIndex;
VkImage image;
long showingWindow;
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse;
int savedWidth, savedHeight;
Expand Down
56 changes: 55 additions & 1 deletion src/main/jni/jre_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,37 @@
#include "log.h"
#include "utils.h"

// Uncomment to try redirect signal handling to JVM
#define TRY_SIG2JVM

#define FULL_VERSION "1.8.0-internal"
#define DOT_VERSION "1.8"

static const char* const_progname = "java";
static const char* const_launcher = "openjdk";
static const char** const_jargs = NULL;
static const char** const_appclasspath = NULL;
static const jboolean const_javaw = JNI_FALSE;
static const jboolean const_cpwildcard = JNI_TRUE;
static const jint const_ergo_class = 0; // DEFAULT_POLICY
static struct sigaction old_sa[NSIG];

void (*__old_sa)(int signal, siginfo_t *info, void *reserved);
int (*JVM_handle_linux_signal)(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized);

void android_sigaction(int signal, siginfo_t *info, void *reserved) {
if (JVM_handle_linux_signal == NULL) { // should not happen, but still
__old_sa = old_sa[signal].sa_sigaction;
__old_sa(signal,info,reserved);
exit(1);
} else {
// Based on https://github.com/PojavLauncherTeam/openjdk-multiarch-jdk8u/blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/linux/vm/os_linux.cpp#L4688-4693
int orig_errno = errno; // Preserve errno value over signal handler.
JVM_handle_linux_signal(signal, info, reserved, true);
errno = orig_errno;
}
}
typedef jint JNI_CreateJavaVM_func(JavaVM **pvm, void **penv, void *args);

typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */
int jargc, const char** jargv, /* java args */
Expand Down Expand Up @@ -96,6 +120,36 @@ static jint launchJVM(int margc, char** margv) {
* Signature: ([Ljava/lang/String;)I
*/
JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env, jclass clazz, jobjectArray argsArray) {
#ifdef TRY_SIG2JVM
void* libjvm = dlopen("libjvm.so", RTLD_LAZY | RTLD_GLOBAL);
if (NULL == libjvm) {
LOGE("JVM lib = NULL: %s", dlerror());
return -1;
}
JVM_handle_linux_signal = dlsym(libjvm, "JVM_handle_linux_signal");
#endif

jint res = 0;
// int i;
//Prepare the signal trapper
struct sigaction catcher;
memset(&catcher,0,sizeof(sigaction));
catcher.sa_sigaction = android_sigaction;
catcher.sa_flags = SA_SIGINFO|SA_RESTART;
// SA_RESETHAND;
#define CATCHSIG(X) sigaction(X, &catcher, &old_sa[X])
CATCHSIG(SIGILL);
CATCHSIG(SIGABRT);
CATCHSIG(SIGBUS);
CATCHSIG(SIGFPE);
#ifdef TRY_SIG2JVM
CATCHSIG(SIGSEGV);
#endif
CATCHSIG(SIGSTKFLT);
CATCHSIG(SIGPIPE);
CATCHSIG(SIGXFSZ);
//Signal trapper ready

// Save dalvik JNIEnv pointer for JVM launch thread
dalvikJNIEnvPtr_ANDROID = env;

Expand All @@ -110,7 +164,7 @@ JNIEXPORT jint JNICALL Java_com_oracle_dalvik_VMLauncher_launchJVM(JNIEnv *env,

LOGD("Done processing args");

int res = launchJVM(argc, argv);
res = launchJVM(argc, argv);

LOGD("Going to free args");
free_char_array(env, argsArray, argv);
Expand Down
14 changes: 14 additions & 0 deletions src/main/jni/tinywrapper/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "../GL/gl.h"
#include <EGL/egl.h>
#include <dlfcn.h>

typedef __eglMustCastToProperFunctionPointerType eglGetProcAddress_t (const char *procname);
eglGetProcAddress_t* eglGetProcAddress_p;

void* glXGetProcAddress(const GLubyte* name) {
if(eglGetProcAddress_p == NULL) {
void* handle = dlopen("libEGL_mesa.so", RTLD_NOW);
eglGetProcAddress_p = dlsym(handle, "eglGetProcAddress");
}
return eglGetProcAddress_p(name);
}
60 changes: 37 additions & 23 deletions src/main/jni/vloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,43 @@ Java_pojlib_util_VLoader_setAndroidInitInfo(JNIEnv *env, jclass clazz, jobject c
}

extern "C"
JNIEXPORT void JNICALL
Java_org_vivecraft_util_VLoader_setEGLGlobal(JNIEnv* env, jclass clazz) {
EGLConfig cfg;
EGLint num_configs;
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKImage1(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->image;
}

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_ES3_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};
extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKImage2(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->image;
}

eglChooseConfig(eglGetCurrentDisplay(), attribs, &cfg, 1, &num_configs);
pojav_environ->OpenComposite_Android_GLES_Binding_Info = new XrGraphicsBindingOpenGLESAndroidKHR {
XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR,
nullptr,
(void*)eglGetCurrentDisplay(),
(void*) cfg,
(void*)eglGetCurrentContext()
};
extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKInstance(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->instance;
}

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKPhysicalDevice(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->pDev;
}

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKDevice(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->device;
}

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getVKQueue(JNIEnv* env, jclass clazz) {
return (jlong) pojav_environ->queue;
}

extern "C"
JNIEXPORT jint JNICALL
Java_org_vivecraft_util_VLoader_getVKQueueIndex(JNIEnv* env, jclass clazz) {
return (jint) pojav_environ->queueIndex;
}
Binary file modified src/main/jniLibs/arm64-v8a/libEGL_mesa.so
Binary file not shown.
Git LFS file not shown
3 changes: 3 additions & 0 deletions src/main/jniLibs/arm64-v8a/libcutils.so
Git LFS file not shown
Binary file modified src/main/jniLibs/arm64-v8a/libdrm.so
Binary file not shown.
Binary file removed src/main/jniLibs/arm64-v8a/libdrm_freedreno.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/libgallium_dri.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/libglapi.so
Binary file not shown.
Binary file removed src/main/jniLibs/arm64-v8a/libgsl_alloc_hook.so
Binary file not shown.
Binary file modified src/main/jniLibs/arm64-v8a/libhardware.so
Binary file not shown.
Binary file removed src/main/jniLibs/arm64-v8a/libhook_impl.so
Binary file not shown.
Binary file removed src/main/jniLibs/arm64-v8a/liblinkernsbypass.so
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main/jniLibs/arm64-v8a/liblog.so
Git LFS file not shown
Binary file removed src/main/jniLibs/arm64-v8a/libmain_hook.so
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main/jniLibs/arm64-v8a/libnativewindow.so
Git LFS file not shown
3 changes: 3 additions & 0 deletions src/main/jniLibs/arm64-v8a/libsync.so
Git LFS file not shown
3 changes: 0 additions & 3 deletions src/main/jniLibs/arm64-v8a/libtinywrapper.so

This file was deleted.

Binary file removed src/main/jniLibs/arm64-v8a/libvulkan_freedreno.so
Binary file not shown.
2 changes: 1 addition & 1 deletion wrapper

0 comments on commit 0ea2d10

Please sign in to comment.