Skip to content
Draft

Vulkan #2545

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 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
6f97ff5
alter material system to support versions of resources per frame-in-f…
codex128 Aug 24, 2025
d4646f6
fix build and runtime errors (new material system is operational)
codex128 Aug 24, 2025
42a845a
fix warning on DescriptorSet destruction for DescriptorPools not crea…
codex128 Aug 24, 2025
ba4ea7f
use Flag for CommandPool creation instead of booleans
codex128 Aug 24, 2025
56a0a42
prototype meshes; improve usability; abstract images and buffers in p…
codex128 Aug 30, 2025
e29d2a9
fix image loader key type
codex128 Aug 30, 2025
85b3d95
mess around with meshes more
codex128 Sep 1, 2025
669ce8f
have uniforms use Resources/DataPipelines instead of VersionedResources
codex128 Sep 1, 2025
0fc9137
have uniforms use Resources/DataPipelines instead of VersionedResources
codex128 Sep 1, 2025
ab434fd
have uniforms use Resources/DataPipelines instead of VersionedResources
codex128 Sep 2, 2025
97750fd
simplified handling of DataPipe results by uniforms
codex128 Sep 2, 2025
bb7ab46
completed AdaptiveMesh; added CommandBatch system to properly update …
codex128 Sep 9, 2025
3099a26
fix vertex shader producing an unused varying
codex128 Sep 9, 2025
4756c04
rename updateStaticBuffers to updateSharedBuffers
codex128 Sep 9, 2025
519301e
add enum to represent common attribute names
codex128 Sep 9, 2025
20a2120
improve pipeline and sampler usability
codex128 Sep 9, 2025
2f3f8c5
improve pipeline and sampler usability
codex128 Sep 9, 2025
42d7525
preparing to alter Spatial
codex128 Sep 11, 2025
cb5c47a
move vulkan to core
codex128 Sep 12, 2025
29c1818
temporarily renamed Mesh to GLMesh to not conflict with the new Mesh …
codex128 Sep 12, 2025
1718bbf
Revert "temporarily renamed Mesh to GLMesh to not conflict with the n…
codex128 Sep 12, 2025
7fee9d2
temporarily renamed Mesh to GLMesh to not conflict with the new Mesh …
codex128 Sep 12, 2025
301b6bc
Revert "temporarily renamed Mesh to GLMesh to not conflict with the n…
codex128 Sep 12, 2025
e28d4df
Revert "Revert "temporarily renamed Mesh to GLMesh to not conflict wi…
codex128 Sep 12, 2025
d463d9c
Revert "temporarily renamed Mesh to GLMesh to not conflict with the n…
codex128 Sep 12, 2025
e3ee8be
Revert "Revert "temporarily renamed Mesh to GLMesh to not conflict wi…
codex128 Sep 12, 2025
65c076e
renamed new Mesh interface to NewMesh to not conflict with existing M…
codex128 Sep 12, 2025
115a985
renamed GLMesh back to Mesh
codex128 Sep 12, 2025
268988b
add BackedStaticBuffer
codex128 Sep 12, 2025
f23c5c8
make BIHTree compatible with NewMesh
codex128 Sep 12, 2025
c388da8
made BoundingVolume accept VertexReaders for computeFromPoints
codex128 Sep 13, 2025
e871c05
Geometry accepts NewMesh without errors
codex128 Sep 13, 2025
bc4ce97
Geometry accepts NewMesh without errors
codex128 Sep 13, 2025
d2e37e5
renamed vulkan material to NewMaterial
codex128 Sep 13, 2025
ef41a34
delete VertexModifier interface
codex128 Sep 13, 2025
1c45ac6
made Spatial iterable
codex128 Sep 13, 2025
49cc7f2
made Spatial iterable
codex128 Sep 13, 2025
1e2926d
setup vulkan test for rendering from the scene graph
codex128 Sep 13, 2025
a7c2f09
moved Mesh code to OldMesh; replaced NewMesh with Mesh, which has bee…
codex128 Sep 13, 2025
bd21a20
moved previous Mesh extensions to extend OldMesh
codex128 Sep 13, 2025
050e1df
moved Material to OldMaterial
codex128 Sep 13, 2025
93067db
renamed Texture to GlTexture and Image to GlImage, both implementing …
codex128 Sep 14, 2025
fe84d1e
added methods to Material interface for compatibility with old GlMate…
codex128 Sep 16, 2025
7e1f760
fix several incompatibilities
codex128 Sep 17, 2025
d3860c6
added GeometryBatch to cleanly and optimally handling renders; a lot …
codex128 Oct 10, 2025
ab514b7
added GeometryBatch to cleanly and optimally handling renders; a lot …
codex128 Oct 10, 2025
ebf9528
split Vulkan and OpenGL APIs on GeometryBatch
codex128 Oct 11, 2025
154d3ab
fixed build errors in GlVertexBuffer
codex128 Oct 11, 2025
d8dd146
changed command paradigm again; improved material set selection proce…
codex128 Oct 15, 2025
381b05d
start using Jackson to parse yaml matdefs
codex128 Oct 17, 2025
98163af
drafted a PipelineState system that I actually like and that will act…
codex128 Oct 18, 2025
eb7a6f1
drafted a PipelineState system that I actually like and that will act…
codex128 Oct 28, 2025
38b2ef2
deleted old deprecated animation system
codex128 Oct 28, 2025
c8db583
fixed build problems caused by new API
codex128 Oct 29, 2025
a574018
fix build problems, especially relating to FrameBuffers
codex128 Nov 1, 2025
b35e045
working on yet another rewrite of the mesh system
codex128 Nov 21, 2025
7235be7
working on yet another rewrite of the mesh system
codex128 Nov 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
243 changes: 243 additions & 0 deletions VulkanDesign.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@

Stuck, again. I need a good way to access vertex data. The current system has some flaws:

1. Processes must assume the format and number of components of an attribute.
This is especially concerning.
2. Data cannot be accessed as struct buffers. This not a huge issue.
3. Attributes are accessed by a string identifier.

I want to have a more concrete way to work with attributes. Something along these lines:

public interface PositionAttribute {
void setPosition(int vertex, Vector3f position);
Vector3f getPosition(int vertex);
void setPositionAccess(DataAccess access);
}

The problem is that a single attribute can get fairly bloated if you also add nice things like bulk setters and getters. Multiply that by every attribute you want, and it can get quite unwieldy. It also has that odd access setter on each attribute, which for whatever reason really annoys me.

What would actually be ideal is if everything could be represented by a simple "Vertex" struct.

struct Vertex {
Vector3f position;
Vector2f texCoord;
Vector3f normal;
}

(of course, in Java struct declaration is more complicated). The advantage is that all the vertex buffers can be very simply mapped as buffers of Vertex. It would also translate fairly well to instances.

struct Instance {
Matrix4f worldViewProjection;
Vector4f color;
}

The problem is what to do with vertex data split across multiple buffers, which could very well be done if multiple shaders want to access the vertex positions, but not everything wants the texCoord and normal data. In which case it'd be represented as so:

struct VertexPart1 {
Vector3f position;
}
struct VertexPart2 {
Vector2f texCoord;
Vector3f normal;
}

User-side, this wouldn't be much of a problem. He should know what type of vertex he's working with. But the engine utilities don't necessarily know that. The vertex struct would have to implement an interface (possibly for each attribute, as discussed above), and the utility would have to cast each individual vertex to the desired type.

for (Vertex v : mesh.getVertices()) {
((Position)v).setPosition(Vector3f.ZERO);
}

It's messy and a pain to work with. It also doesn't properly address the dual vertex buffer situation. A possible solution to this is custom iterators which will automatically verify that an entire batch of vertices already meets the requirements. It would work something like this:

for (Position p : mesh.getVertices(Position.class)) {
p.setPosition(Vector3f.ZERO);
}
for (TexCoord t : mesh.getVertices(TexCoord.class)) {
t.setTexCoord(Vector2f.ZERO);
}
mesh.unmap(); // unmap all used buffers

getVertices() implementation may look something like this:

public class Mesh {
private final Collection<VertexBuffer<?>> buffers = new ArrayList<>();
private final Map<Class<? extends VertexAttribute>, VertexBuffer<?>> bufferLookup = new HashMap<>();
public <T extends VertexAttribute> Iterable<T> getVertices(Class<T> type) {
VertexBuffer<?> buf = bufferLookup.get(type);
if (buf != null) {
return buf.getVertices(type);
}
for (VertexBuffer<?> buffer : buffers) {
if (type.isAssignableFrom(buffer.getVertexType())) {
bufferLookup.put(type, buffer);
return buffer.getVertices(type);
}
}
throw new IllegalArgumentException("Mesh does not contain " + type);
}
}
public class VertexBuffer <V extends Vertex> {
private final Class<V> vertexType;
private final GpuBuffer buffer;
public <T extends VertexAttribute> Iterable<T> getVertices(Class<T> type) {
if (!type.isAssignableFrom(vertexType)) {
throw new ClassCastException("Vertex data is not " + type);
}
return (Iterable<T>)map();
}
public Iterable<V> map() {
return buffer.map((Long address, Integer size) -> V.Buffer.create(address, size));
}
public Class<V> getVertexType() {
return vertexType;
}
}

Unfortunately, this doesn't make accessing two different attributes at once very do-able. You'd have to do an awkward multi-iterator loop, which is just a pain to do. It would be better to have to do this:

List<Position> pos = mesh.getVertices(Position.class);
List<TexCoord> tex = mesh.getVertices(TexCoord.class);
pos.get(12).setPosition(tex.get(11).toVector3f());

How about this:

Position pos = mesh.getAttribute(Position.class);
TexCoord tex = mesh.getAttribute(TexCoord.class);
pos.set(12, 0f, 0f, 0f);
Vector3f v = pos.get(11);
for (Vector3f v : pos) {

}
for (int i : Attributes.iterate(pos, tex)) {

}

public interface Attribute <T> extends Iterable<T> {

Attribute<T> map();

void set(int element, T value);

T get(int element);

int size();

// optional
default T get(int element, T store) {
return get(element);
}

@Override
default Iterator<T> iterator() {
return new IteratorImpl<>(null);
}

default IteratorImpl<T> iterator(T store) {
return new IteratorImpl<>(store);
}

class IteratorImpl <T> implements Iterator<T>, Iterable<T> {

private final Attribute<T> attr;
private final T store;
private int index = 0;

public IteratorImpl(Attribute<T> attr, T store) {
this.attr = attr;
this.store = store;
}

public boolean hasNext() {
return index < attr.size();
}

public T next() {
return attr.get(index++, store);
}

public Iterator<T> iterator() {
this.index = 0;
return this;
}

}

}
public abstract class AbstractAttribute <T> implements Attribute<T> {

protected final VertexBuffer vertexBuffer;
protected final int stride, offset, size;
protected ByteBuffer buffer;

public AbstractAttribute(VertexBuffer vertexBuffer, int stride, int offset, int size) {
this.vertexBuffer = vertexBuffer;
}

}
public class Position implements Attribute<Vector3f> {

private VertexBuffer buffer;
private int stride, offset;

@Override
public void set(int element, Vector3f value) {
set(element, value.x, value.y, value.z);
}

@Override
public Vector3f get(int element) {
Vector3f store = new Vector3f();
ByteBuffer buf = buffer.map().position(element * stride + offset);
store.x = buf.getFloat();
store.y = buf.getFloat();
store.z = buf.getFloat();
return store;
}

public void set(int element, float x, float y, float z) {
buffer.map()
.position(element * stride + offset)
.putFloat(x).putFloat(y).putFloat(z);
}

}

If mappings are frequent -> streaming buffer
If mappings are less frequent -> dynamic buffer
If only one mapping occurs OR a mapping hasn't occured in a very long time -> static buffer

Static AND dynamic
Build
1. Create GPU buffer (device local)
2. Create CPU buffer (nio)
CPU -> GPU
1. Acquire staging buffer (host visible and coherent)
2. Map staging buffer
3. Copy CPU buffer -> staging buffer
4. Record copy staging buffer -> GPU buffer
5. Unmap staging buffer
--- wait for copy to complete
6. Release staging buffer
GPU -> CPU
1. Acquire staging buffer (host visible and coherent)
2. Copy GPU buffer -> staging buffer
--- wait for copy to complete
3. Map staging buffer
4. Copy staging buffer -> CPU buffer
OR read directly from staging buffer
(depends on the nature of the read op)
5. Unmap staging buffer
6. Release staging buffer
Streaming
Build
1. Create GPU buffers per frame (host visible and coherent)
2. Create CPU buffer (nio)
CPU -> GPU
1. Map frame GPU buffer (if not already mapped)
2. Copy CPU buffer -> frame GPU buffer
3. Unmap frame GPU buffer (if necessary)
GPU -> CPU
1. Map a GPU buffer (if not already mapped)
2. Copy GPU buffer -> CPU buffer
3. Unmap GPU buffer (if necessary)

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
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.system.JmeSystem;
import com.jme3.system.Timer;
import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image;
import com.jme3.texture.GlFrameBuffer;
import com.jme3.texture.GlImage;
import com.jme3.util.AndroidScreenshots;
import com.jme3.util.BufferUtils;
import java.io.File;
Expand Down Expand Up @@ -233,15 +233,15 @@ private class VideoProcessor implements SceneProcessor {
private MjpegFileWriter writer;
private boolean fastMode = true;

public void addImage(Renderer renderer, FrameBuffer out) {
public void addImage(Renderer renderer, GlFrameBuffer out) {
if (freeItems == null) {
return;
}
try {
final WorkItem item = freeItems.take();
usedItems.add(item);
item.buffer.clear();
renderer.readFrameBufferWithFormat(out, item.buffer, Image.Format.BGRA8);
renderer.readFrameBufferWithFormat(out, item.buffer, GlImage.Format.BGRA8);
executor.submit(new Callable<Void>() {

@Override
Expand Down Expand Up @@ -307,7 +307,7 @@ public void postQueue(RenderQueue rq) {
}

@Override
public void postFrame(FrameBuffer out) {
public void postFrame(GlFrameBuffer out) {
numFrames++;
addImage(renderManager.getRenderer(), out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader;
import com.jme3.asset.TextureKey;
import com.jme3.texture.Image;
import com.jme3.texture.GlImage;
import com.jme3.texture.image.ColorSpace;
import com.jme3.util.BufferUtils;
import java.io.IOException;
Expand Down Expand Up @@ -72,7 +72,7 @@ private static void convertARGBtoABGR(int[] src, int srcOff, int[] dst, int dstO
@Override
public Object load(AssetInfo assetInfo) throws IOException {
Bitmap bitmap;
Image.Format format;
GlImage.Format format;
int bpp;

BitmapFactory.Options options = new BitmapFactory.Options();
Expand Down Expand Up @@ -102,15 +102,15 @@ public Object load(AssetInfo assetInfo) throws IOException {

switch (bitmap.getConfig()) {
case ALPHA_8:
format = Image.Format.Alpha8;
format = GlImage.Format.Alpha8;
bpp = 1;
break;
case ARGB_8888:
format = Image.Format.RGBA8;
format = GlImage.Format.RGBA8;
bpp = 4;
break;
case RGB_565:
format = Image.Format.RGB565;
format = GlImage.Format.RGB565;
bpp = 2;
break;
default:
Expand All @@ -124,7 +124,7 @@ public Object load(AssetInfo assetInfo) throws IOException {

ByteBuffer data = BufferUtils.createByteBuffer(bitmap.getWidth() * bitmap.getHeight() * bpp);

if (format == Image.Format.RGBA8) {
if (format == GlImage.Format.RGBA8) {
int[] pixelData = new int[width * height];
bitmap.getPixels(pixelData, 0, width, 0, 0, width, height);

Expand Down Expand Up @@ -163,7 +163,7 @@ public Object load(AssetInfo assetInfo) throws IOException {

bitmap.recycle();

Image image = new Image(format, width, height, data, ColorSpace.sRGB);
GlImage image = new GlImage(format, width, height, data, ColorSpace.sRGB);

return image;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader;
import com.jme3.asset.TextureKey;
import com.jme3.texture.Image;
import com.jme3.texture.GlImage;
import java.io.IOException;
import java.io.InputStream;

Expand All @@ -52,10 +52,10 @@ public class AndroidNativeImageLoader implements AssetLoader {
System.loadLibrary("decodejme");
}

private static native Image load(InputStream in, boolean flipY, byte[] tmpArray) throws IOException;
private static native GlImage load(InputStream in, boolean flipY, byte[] tmpArray) throws IOException;

@Override
public Image load(AssetInfo info) throws IOException {
public GlImage load(AssetInfo info) throws IOException {
boolean flip = ((TextureKey) info.getKey()).isFlipY();
try (final InputStream in = info.openStream()) {
return load(in, flip, tmpArray);
Expand Down
Loading
Loading