-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestWebGPUCore.java
More file actions
55 lines (47 loc) · 1.95 KB
/
TestWebGPUCore.java
File metadata and controls
55 lines (47 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS com.github.xpenatan.jWebGPU:webgpu-core:0.1.12
//DEPS com.github.xpenatan.jWebGPU:webgpu-desktop:0.1.12:windows_64_wgpu
//REPOS https://oss.sonatype.org/content/repositories/releases/
import com.github.xpenatan.webgpu.WGPU;
import com.github.xpenatan.webgpu.WGPUInstance;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class TestWebGPUCore {
public static void main(String... args) {
System.out.println("Attempting to load WebGPU...");
try {
loadNativeLibrary();
WGPUInstance instance = WGPU.setupInstance();
if (instance.isValid()) {
System.out.println("WebGPU Instance is VALID!");
} else {
System.out.println("WebGPU Instance is INVALID (Native lib missing?)");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
private static void loadNativeLibrary() throws Exception {
String libName = "jWebGPU64.dll";
String resourcePath = "/native/wgpu/" + libName;
System.out.println("Looking for resource: " + resourcePath);
InputStream is = TestWebGPUCore.class.getResourceAsStream(resourcePath);
if (is == null) {
throw new RuntimeException("Could not find native library in classpath: " + resourcePath);
}
File tempLib = File.createTempFile("jWebGPU64", ".dll");
tempLib.deleteOnExit();
try (OutputStream os = new FileOutputStream(tempLib)) {
byte[] buffer = new byte[8192];
int read;
while ((read = is.read(buffer)) != -1) {
os.write(buffer, 0, read);
}
}
System.out.println("Extracted native library to: " + tempLib.getAbsolutePath());
System.load(tempLib.getAbsolutePath());
System.out.println("Native library loaded successfully.");
}
}