Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile all demos to native executable #37

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
add glsl and metal shader files to native image
to make it work in Linux.

Also, remove the ThreadLocalUtil's substitution by GraalVM,
as the resulting native image seems to work fine without it.
chirontt committed Mar 21, 2021
commit 04aa74d01d8e5dd53f11357f3e16c8181eeebc66
15 changes: 15 additions & 0 deletions res/META-INF/native-image/resource-config.json
Original file line number Diff line number Diff line change
@@ -19,9 +19,24 @@
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/fs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/fs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/fs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/vs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/vs_bump_instanced.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/vs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/dx11/vs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/fs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/fs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/fs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/vs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/vs_bump_instanced.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/vs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/glsl/vs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/fs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/fs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/fs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/vs_bump.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/vs_bump_instanced.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/vs_cubes.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/shaders/metal/vs_raymarching.bin\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/textures/fieldstone-n.dds\\E"},
{"pattern":"\\Qorg/lwjgl/demo/bgfx/textures/fieldstone-rgba.dds\\E"},
{"pattern":"\\Qorg/lwjgl/system/APIUtil.class\\E"},
52 changes: 0 additions & 52 deletions src/org/lwjgl/graalvm/LwjglSubstitutions.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.lwjgl.graalvm;

import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.Pointer.*;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.lwjgl.Version;
@@ -38,52 +32,6 @@ public static String getVersion() {
}
}

@TargetClass(org.lwjgl.system.ThreadLocalUtil.class)
final class Target_org_lwjgl_system_ThreadLocalUtil {

@Alias
@RecomputeFieldValue(kind = Kind.FromAlias, isFinal = true)
private static long JNI_NATIVE_INTERFACE;

@Alias
@RecomputeFieldValue(kind = Kind.FromAlias, isFinal = true)
private static long FUNCTION_MISSING_ABORT;

@Substitute
public static void setFunctionMissingAddresses(Class<?> capabilitiesClass, int index) {
if (capabilitiesClass == null) {
long missingCaps = memGetAddress(JNI_NATIVE_INTERFACE + Integer.toUnsignedLong(index) * POINTER_SIZE);
if (missingCaps != NULL) {
getAllocator().free(missingCaps);
memPutAddress(JNI_NATIVE_INTERFACE + Integer.toUnsignedLong(index) * POINTER_SIZE, NULL);
}
} else {
int functionCount = getFieldsFromCapabilities(capabilitiesClass).size();

long missingCaps = getAllocator().malloc(Integer.toUnsignedLong(functionCount) * POINTER_SIZE);
for (int i = 0; i < functionCount; i++) {
memPutAddress(missingCaps + Integer.toUnsignedLong(i) * POINTER_SIZE, FUNCTION_MISSING_ABORT);
}

//the whole purpose of substituting this method is just to remove the following line
//(which causes the resulting native image to crash!)
//memPutAddress(JNI_NATIVE_INTERFACE + Integer.toUnsignedLong(index) * POINTER_SIZE, missingCaps);
}
}

//copied verbatim from the original class
@Substitute
private static List<Field> getFieldsFromCapabilities(Class<?> capabilitiesClass) {
List<Field> fields = new ArrayList<>();
for (Field field : capabilitiesClass.getFields()) {
if (field.getType() == long.class) {
fields.add(field);
}
}
return fields;
}
}

/** Dummy class with the file's name. */
public class LwjglSubstitutions {
}