diff --git a/src/main/java/dev/thatredox/chunkynative/opencl/context/ClContext.java b/src/main/java/dev/thatredox/chunkynative/opencl/context/ClContext.java index 5b9c2f4..31453dd 100644 --- a/src/main/java/dev/thatredox/chunkynative/opencl/context/ClContext.java +++ b/src/main/java/dev/thatredox/chunkynative/opencl/context/ClContext.java @@ -60,10 +60,6 @@ public cl_program loadProgram(Function sourceReader, String kern // Search for include headers HashMap headerFiles = new HashMap<>(); - // Fake `opencl.h` header - headerFiles.put("../opencl.h", clCreateProgramWithSource(context, 1, new String[] { "" }, - null, null)); - // Load headers readHeaders(kernel, headerFiles); diff --git a/src/main/java/dev/thatredox/chunkynative/opencl/context/KernelLoader.java b/src/main/java/dev/thatredox/chunkynative/opencl/context/KernelLoader.java index 7822d7c..515dfdb 100644 --- a/src/main/java/dev/thatredox/chunkynative/opencl/context/KernelLoader.java +++ b/src/main/java/dev/thatredox/chunkynative/opencl/context/KernelLoader.java @@ -10,9 +10,13 @@ import java.nio.file.Paths; import java.util.Scanner; import java.util.function.BiFunction; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class KernelLoader { private static final KernelLoader instance = new KernelLoader(); + private static final Pattern openclIncludeMatcher = Pattern.compile( + "^\\h*#include\\h*\"\\.\\./opencl\\.h\"\\h*$", Pattern.MULTILINE); private final BiFunction rawSourceReader; private final boolean hotReload; @@ -54,7 +58,12 @@ private KernelLoader() { * @return OpenCL program. */ public static cl_program loadProgram(ClContext context, String base, String kernelName) { - return context.loadProgram(file -> instance.rawSourceReader.apply(base, file), kernelName); + return context.loadProgram(file -> { + String program = instance.rawSourceReader.apply(base, file); + Matcher matcher = openclIncludeMatcher.matcher(program); + program = matcher.replaceFirst("// #include \"../opencl.h\""); + return program; + }, kernelName); } public static boolean canHotReload() {