Skip to content

Vulkan #2545

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

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft

Vulkan #2545

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d2315be
added AlertArmatureMask
codex128 Jul 24, 2023
2f1dae8
fixed docs and added another helper
codex128 Jul 24, 2023
a750f1c
made it easier to turn off priority checking
codex128 Jul 24, 2023
cd876d4
removed copy methods
codex128 Jul 25, 2023
9c9c2d8
updated license
codex128 Jan 19, 2024
83c95e5
updated javadoc
codex128 Jan 20, 2024
90e6cd8
renamed mask
codex128 Jan 21, 2024
0f410c0
Merge branch 'jMonkeyEngine:master' into master
codex128 Feb 29, 2024
9cf7dc4
Merge branch 'jMonkeyEngine:master' into master
codex128 Jun 7, 2024
7efa4c6
Merge remote-tracking branch 'origin/master'
codex128 Apr 26, 2025
0e25de2
Merge remote-tracking branch 'origin/master'
codex128 Jun 22, 2025
0c2d187
create vulkan context and prototyped vulkan instance creation in a te…
codex128 Jun 24, 2025
061a782
vulkan logical device
codex128 Jun 24, 2025
1b9f2e3
vulkan logical device
codex128 Jun 24, 2025
863e6a9
create interface over vulkan API
codex128 Jul 3, 2025
1b2ee3d
debug initial vulkan engine interface
codex128 Jul 27, 2025
e82ab06
debug initial vulkan engine interface
codex128 Jul 27, 2025
5aa391e
add shader attributes and gpu buffers
codex128 Jul 28, 2025
adb4e01
add uniforms; fix native crash and memory leaks
codex128 Aug 1, 2025
8e7ff36
added depth testing; added enums for image properties
codex128 Aug 1, 2025
beba5fe
added depth testing; added enums for image properties
codex128 Aug 1, 2025
4e31f0d
migrated instance, device, surface, and swapchain to new builder arc…
codex128 Aug 3, 2025
5f7d1ec
migrated instance, device, surface, and swapchain to new builder arc…
codex128 Aug 3, 2025
c4738ee
successfully abstracted all vulkan components
codex128 Aug 6, 2025
e0efc40
successfully abstracted all vulkan components
codex128 Aug 6, 2025
0c035ab
organized files
codex128 Aug 9, 2025
6a3171c
added MemorySize for clarity in allocating buffer sizes
codex128 Aug 9, 2025
bcb7014
managed to create acceptable prototype material system (still much to…
codex128 Aug 13, 2025
b168553
managed to create acceptable prototype material system (still much to…
codex128 Aug 13, 2025
6c0dbaf
altered material system slightly
codex128 Aug 13, 2025
f7d3679
basic material system is working
codex128 Aug 13, 2025
62882d4
basic material system is working
codex128 Aug 13, 2025
4a1970f
add device interfaces for different queue types
codex128 Aug 14, 2025
521c8a7
move pool management to logical device
codex128 Aug 14, 2025
a00411b
add stage mask to semaphores
codex128 Aug 15, 2025
d0340ab
figure out uniform details
codex128 Aug 16, 2025
ab0de0e
add Flag interface to handle bit flags
codex128 Aug 19, 2025
6657009
fix build error
codex128 Aug 19, 2025
72b0156
fix json error
codex128 Aug 19, 2025
ed6096e
extract GpuBuffer into an interface; create VersionedBuffer in prepar…
codex128 Aug 19, 2025
5587e17
fix build errors related to GpuBuffer interface extraction
codex128 Aug 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ lwjgl3-opencl = { module = "org.lwjgl:lwjgl-opencl", version.ref = "lwjgl3"
lwjgl3-opengl = { module = "org.lwjgl:lwjgl-opengl", version.ref = "lwjgl3" }
lwjgl3-openvr = { module = "org.lwjgl:lwjgl-openvr", version.ref = "lwjgl3" }
lwjgl3-ovr = { module = "org.lwjgl:lwjgl-ovr", version.ref = "lwjgl3" }
lwjgl3-vulkan = { module = "org.lwjgl:lwjgl-vulkan", version.ref = "lwjgl3" }
lwjgl3-shaderc = { module = "org.lwjgl:lwjgl-shaderc", version.ref = "lwjgl3" }

mokito-core = "org.mockito:mockito-core:3.12.4"

Expand Down
50 changes: 50 additions & 0 deletions jme3-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,56 @@ dependencies {
testRuntimeOnly project(':jme3-testdata')
testImplementation project(':jme3-desktop')
testRuntimeOnly project(':jme3-plugins')

// Use LWJGL3 directly in core. This destroys LWJGL2 and JOGL compatibility.
api (libs.lwjgl3.awt) {
exclude group: 'org.lwjgl', module: 'lwjgl'
}
api libs.lwjgl3.base
api libs.lwjgl3.glfw
api libs.lwjgl3.jawt
api libs.lwjgl3.jemalloc
api libs.lwjgl3.openal
api libs.lwjgl3.opencl
api libs.lwjgl3.opengl
api libs.lwjgl3.vulkan
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-windows') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-windows-x86') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-linux') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-linux-arm32') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-linux-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-macos') })
runtimeOnly(variantOf(libs.lwjgl3.base){ classifier('natives-macos-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-windows') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-windows-x86') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-linux') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-linux-arm32') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-linux-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-macos') })
runtimeOnly(variantOf(libs.lwjgl3.glfw){ classifier('natives-macos-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-windows') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-windows-x86') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-linux') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-linux-arm32') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-linux-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-macos') })
runtimeOnly(variantOf(libs.lwjgl3.jemalloc){ classifier('natives-macos-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-windows') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-windows-x86') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-linux') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-linux-arm32') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-linux-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-macos') })
runtimeOnly(variantOf(libs.lwjgl3.opengl){ classifier('natives-macos-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-windows') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-windows-x86') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-linux') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-linux-arm32') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-linux-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-macos') })
runtimeOnly(variantOf(libs.lwjgl3.openal){ classifier('natives-macos-arm64') })
runtimeOnly(variantOf(libs.lwjgl3.shaderc) { classifier('natives-linux') })

}

task updateVersionPropertiesFile {
Expand Down
12 changes: 12 additions & 0 deletions jme3-core/src/main/java/com/jme3/math/Matrix4f.java
Original file line number Diff line number Diff line change
Expand Up @@ -2560,4 +2560,16 @@ public Matrix4f clone() {
throw new AssertionError(); // can not happen
}
}

/**
* Flips the sign of the Y scalar component (m11) to make Vulkan renderings
* appear upright in clip space.
*
* @return this instance
*/
public Matrix4f flipYScalarForVulkan() {
m11 = -m11;
return this;
}

}
5 changes: 3 additions & 2 deletions jme3-core/src/main/java/com/jme3/renderer/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,6 @@ public void updateViewProjection() {
if (overrideProjection) {
viewProjectionMatrix.set(projectionMatrixOverride).multLocal(viewMatrix);
} else {
//viewProjectionMatrix.set(viewMatrix).multLocal(projectionMatrix);
viewProjectionMatrix.set(projectionMatrix).multLocal(viewMatrix);
}
}
Expand Down Expand Up @@ -1358,7 +1357,9 @@ public void onFrustumChange() {

projectionMatrix.fromFrustum(frustumNear, frustumFar, frustumLeft, frustumRight,
frustumTop, frustumBottom, parallelProjection);
// projectionMatrix.transposeLocal();

// for Vulkan rendering
projectionMatrix.flipYScalarForVulkan();

// The frame is affected by the frustum values
// update it as well
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jme3.renderer.vulkan;

import com.jme3.system.NullRenderer;

/**
* Temporary placeholder.
*/
public class VulkanRenderer extends NullRenderer {

}
179 changes: 179 additions & 0 deletions jme3-core/src/main/java/com/jme3/renderer/vulkan/VulkanUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package com.jme3.renderer.vulkan;

import com.jme3.util.natives.Native;
import org.lwjgl.PointerBuffer;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.Struct;
import org.lwjgl.system.StructBuffer;
import org.lwjgl.vulkan.VkInstance;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.LongBuffer;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.*;
import java.util.stream.Stream;

import static org.lwjgl.vulkan.VK10.*;

public class VulkanUtils {

public static final int UINT32_MAX = 0xFFFFFFFF;

public static int check(int vulkanCode, String message) {
if (vulkanCode != VK_SUCCESS) {
throw new RuntimeException(message);
}
return vulkanCode;
}

public static int check(int vulkanCode) {
return check(vulkanCode, "Operation unsuccessful: " + vulkanCode);
}

public static long nonNull(long id, String message) {
if (id == MemoryUtil.NULL) {
throw new NullPointerException(message);
}
return id;
}

public static long nonNull(long id) {
return nonNull(id, "Pointer ID is NULL.");
}

public static <T> T enumerateBuffer(MemoryStack stack, IntFunction<T> factory, BiConsumer<IntBuffer, T> fetch) {
IntBuffer count = stack.callocInt(1);
fetch.accept(count, null);
if (count.get(0) <= 0) {
return null;
}
T buffer = factory.apply(count.get(0));
fetch.accept(count, buffer);
return buffer;
}

public static <T> T enumerateBuffer(IntFunction<T> factory, BiConsumer<IntBuffer, T> fetch) {
IntBuffer count = MemoryUtil.memAllocInt(1);
fetch.accept(count, null);
if (count.get(0) <= 0) {
return null;
}
T buffer = factory.apply(count.get(0));
fetch.accept(count, buffer);
MemoryUtil.memFree(count);
return buffer;
}

public static <T> PointerBuffer toPointers(MemoryStack stack, Stream<T> stream, int count, Function<T, ByteBuffer> toBytes) {
PointerBuffer ptrs = stack.mallocPointer(count);
stream.map(toBytes).forEach(ptrs::put);
return ptrs.rewind();
}

public static <T> PointerBuffer toPointers(MemoryStack stack, Collection<T> collection, Function<T, ByteBuffer> toBytes) {
return toPointers(stack, collection.stream(), collection.size(), toBytes);
}

public static long getPointer(MemoryStack stack, Consumer<PointerBuffer> action) {
PointerBuffer ptr = stack.mallocPointer(1);
action.accept(ptr);
return ptr.get(0);
}

public static long getLong(MemoryStack stack, Consumer<LongBuffer> action) {
LongBuffer l = stack.mallocLong(1);
action.accept(l);
return l.get(0);
}

public static int getInt(MemoryStack stack, Consumer<IntBuffer> action) {
IntBuffer i = stack.mallocInt(1);
action.accept(i);
return i.get(0);
}

public static PointerBuffer gatherPointers(MemoryStack stack, Collection<PointerBuffer> pointers) {
int size = 0;
for (PointerBuffer p : pointers) {
size += p.limit();
}
PointerBuffer gather = stack.mallocPointer(size);
for (PointerBuffer p : pointers) {
gather.put(p);
}
return gather.rewind();
}

public static <T> void printListed(String label, Iterable<T> list, Function<T, String> toString) {
System.out.println(label);
for (T o : list) {
System.out.println(" " + toString.apply(o));
}
}

public static void verifyExtensionMethod(VkInstance instance, String name) {
if (vkGetInstanceProcAddr(instance, name) == MemoryUtil.NULL) {
throw new NullPointerException("Extension method " + name + " does not exist.");
}
}

public static <T> NativeIterator<T> iteratePointers(PointerBuffer buffer, LongFunction<T> func) {
return new NativeIterator<>(buffer, func);
}

public static boolean isBitSet(int n, int bit) {
return (n & bit) > 0;
}

public static int sharingMode(boolean concurrent) {
return concurrent ? VK_SHARING_MODE_CONCURRENT : VK_SHARING_MODE_EXCLUSIVE;
}

public static <T extends StructBuffer<E, T>, E extends Struct<E>> T accumulate(Collection<E> collection, IntFunction<T> allocate) {
T buffer = allocate.apply(collection.size());
for (E e : collection) {
buffer.put(e);
}
return buffer.rewind();
}

public static LongBuffer accumulate(MemoryStack stack, Native<Long>... natives) {
LongBuffer buf = stack.mallocLong(natives.length);
for (int i = 0; i < buf.limit(); i++) {
buf.put(i, natives[i].getNativeObject());
}
return buf;
}

public static class NativeIterator <T> implements Iterable<T>, Iterator<T> {

private final PointerBuffer pointers;
private final LongFunction<T> func;
private int index = 0;

public NativeIterator(PointerBuffer pointers, LongFunction<T> func) {
this.pointers = pointers;
this.func = func;
}

@Override
public Iterator<T> iterator() {
return this;
}

@Override
public boolean hasNext() {
return index < pointers.limit();
}

@Override
public T next() {
return func.apply(pointers.get(index++));
}

}

}
19 changes: 18 additions & 1 deletion jme3-core/src/main/java/com/jme3/system/JmeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface JmeContext {
/**
* The type of context.
*/
public enum Type {
enum Type {
/**
* A display can represent a windowed or a fullscreen-exclusive display.
* If windowed, the graphics are rendered to a new on-screen surface
Expand Down Expand Up @@ -79,6 +79,23 @@ public enum Type {
Headless,
}

/**
* Enum specifying the backend to use.
*/
enum Backend {

/**
* Specifies the OpenGL backend.
*/
OpenGL,

/**
* Specifies the Vulkan backend.
*/
Vulkan;

}

/**
* @return The type of the context.
*/
Expand Down
Loading
Loading