Skip to content

Commit d4646f6

Browse files
committed
fix build and runtime errors (new material system is operational)
1 parent 6f97ff5 commit d4646f6

10 files changed

Lines changed: 56 additions & 960 deletions

File tree

jme3-examples/src/main/java/jme3test/vulkan/VulkanHelperTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ public void simpleInitApp() {
119119
flyCam.setMoveSpeed(5f);
120120
flyCam.setDragToRotate(true);
121121

122-
frames = new UpdateFrameManager(2, n -> new Frame());
123-
124122
long window = ((LwjglVulkanContext)context).getWindowHandle();
125123

126124
instance = new VulkanInstance(VK_API_VERSION_1_3);
@@ -171,14 +169,6 @@ public void simpleInitApp() {
171169
new PoolSize(Descriptor.StorageBuffer, 4),
172170
new PoolSize(Descriptor.CombinedImageSampler, 2));
173171

174-
material = new TestMaterial(descriptorPool);
175-
material.getMatrices().setValue(frames.wrap(n -> new PersistentBuffer(device,
176-
MemorySize.floats(16),
177-
BufferUsage.Uniform,
178-
Flag.of(MemoryFlag.HostVisible, MemoryFlag.HostCoherent),
179-
false)));
180-
material.getBaseColorMap().setValue(texture); // fixme
181-
182172
CommandPool transferPool = device.getShortTermPool(physDevice.getGraphics());
183173

184174
// depth texture
@@ -245,11 +235,18 @@ public void simpleInitApp() {
245235
indexBuffer.copy(stack, indexData);
246236
}
247237

238+
frames = new UpdateFrameManager(2, n -> new Frame());
239+
248240
// material color texture
249241
GpuImage image = assetManager.loadAsset(VulkanImageLoader.key(transferPool, "Common/Textures/MissingTexture.png"));
250242
texture = new Texture(device, image.createView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1),
251243
VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_REPEAT, VK_SAMPLER_MIPMAP_MODE_LINEAR);
252244

245+
material = new TestMaterial(descriptorPool);
246+
material.getMatrices().setValue(frames.wrap(n -> new PersistentBuffer(
247+
device, MemorySize.floats(16), BufferUsage.Uniform, false)));
248+
material.getBaseColorMap().setValue(frames.wrap(texture));
249+
253250
}
254251

255252
@Override

jme3-examples/src/main/java/jme3test/vulkan/VulkanTest.java

Lines changed: 0 additions & 901 deletions
This file was deleted.

jme3-lwjgl3/src/main/java/com/jme3/vulkan/buffers/PersistentBuffer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public class PersistentBuffer extends VulkanBuffer {
1111

1212
private final long address;
1313

14-
public PersistentBuffer(LogicalDevice device, MemorySize size, Flag<BufferUsage> usage, Flag<MemoryFlag> mem, boolean concurrent) {
14+
public PersistentBuffer(LogicalDevice<?> device, MemorySize size, Flag<BufferUsage> usage, boolean concurrent) {
15+
this(device, size, usage, Flag.of(MemoryFlag.HostVisible, MemoryFlag.HostCoherent), concurrent);
16+
}
17+
18+
public PersistentBuffer(LogicalDevice<?> device, MemorySize size, Flag<BufferUsage> usage, Flag<MemoryFlag> mem, boolean concurrent) {
1519
super(device, size, usage, mem, concurrent);
1620
try (MemoryStack stack = MemoryStack.stackPush()) {
1721
address = memory.map(stack, 0, size.getBytes(), 0).get(0);

jme3-lwjgl3/src/main/java/com/jme3/vulkan/descriptors/BufferDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public BufferDescriptor(GpuBuffer buffer, long offset, long range) {
1919
}
2020

2121
public void fillDescriptorInfo(VkDescriptorBufferInfo info) {
22-
info.buffer(buffer.getNativeObject()).offset(offset).range(range);
22+
info.buffer(buffer.getId()).offset(offset).range(range);
2323
}
2424

2525
public GpuBuffer getBuffer() {

jme3-lwjgl3/src/main/java/com/jme3/vulkan/material/Material.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void bind(CommandBuffer cmd, Pipeline pipeline, int offset) {
3535
try (MemoryStack stack = MemoryStack.stackPush()) {
3636
LongBuffer setBuf = stack.mallocLong(uniformSets.size());
3737
for (UniformSet set : uniformSets) {
38-
setBuf.put(set.acquireSet(pipeline.getDevice(), pool, availableLayouts).getNativeObject());
38+
setBuf.put(set.update(pipeline.getDevice(), pool, availableLayouts).getNativeObject());
3939
}
4040
setBuf.flip();
4141
vkCmdBindDescriptorSets(cmd.getBuffer(), pipeline.getBindPoint().getVkEnum(),

jme3-lwjgl3/src/main/java/com/jme3/vulkan/material/UniformSet.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class UniformSet implements Iterable<Uniform> {
1313
private final Map<FrameIndex, FrameData> frames = new HashMap<>();
1414

1515
public UniformSet(Uniform... uniforms) {
16-
this.uniforms = uniforms;
17-
this.currentFrame = new FrameIndex(this.uniforms);
16+
this.uniforms = Objects.requireNonNull(uniforms);
17+
this.currentFrame = new FrameIndex(this.uniforms, false);
1818
// ensure duplicate binding indices are not present
1919
BitSet bindings = new BitSet();
2020
for (Uniform u : uniforms) {
@@ -26,9 +26,12 @@ public UniformSet(Uniform... uniforms) {
2626
}
2727
}
2828

29-
public DescriptorSet acquireSet(LogicalDevice<?> device, DescriptorPool pool, List<DescriptorSetLayout> availableLayouts) {
29+
public DescriptorSet update(LogicalDevice<?> device, DescriptorPool pool, List<DescriptorSetLayout> availableLayouts) {
3030
for (Uniform<?> u : uniforms) {
3131
u.update(device);
32+
if (u.getValue() == null) {
33+
throw new NullPointerException("Uniform \"" + u.getName() + "\" contains no value.");
34+
}
3235
}
3336
currentFrame.update(uniforms);
3437
FrameData data = frames.get(currentFrame);
@@ -84,12 +87,12 @@ public SupportedSet get(DescriptorPool pool, List<DescriptorSetLayout> available
8487
private boolean isLayoutCompatible(DescriptorSetLayout layout) {
8588
for (Uniform u : uniforms) {
8689
for (SetLayoutBinding b : layout.getBindings()) {
87-
if (!u.isBindingCompatible(b)) {
88-
return false;
90+
if (u.isBindingCompatible(b)) {
91+
return true;
8992
}
9093
}
9194
}
92-
return true;
95+
return false;
9396
}
9497

9598
}
@@ -101,9 +104,11 @@ private static class FrameIndex {
101104

102105
private final int[] versions;
103106

104-
private FrameIndex(Uniform[] uniforms) {
107+
private FrameIndex(Uniform[] uniforms, boolean update) {
105108
versions = new int[uniforms.length];
106-
update(uniforms);
109+
if (update) {
110+
update(uniforms);
111+
}
107112
}
108113

109114
private FrameIndex(FrameIndex index) {

jme3-lwjgl3/src/main/java/com/jme3/vulkan/material/uniforms/BufferUniform.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class BufferUniform extends AbstractUniform<GpuBuffer> {
1616
private static final String BUFFER_NULL_ERROR = "Uniform buffer is null.";
1717

1818
private VersionedResource<GpuBuffer> resource;
19-
private boolean updateFlag = true;
19+
private long variant = 0L;
2020

2121
public BufferUniform(String name, Descriptor type, int bindingIndex, Flag<ShaderStage> stages) {
2222
super(name, type, bindingIndex, stages);
@@ -34,16 +34,10 @@ public void populateWrite(MemoryStack stack, VkWriteDescriptorSet write) {
3434
.dstArrayElement(0)
3535
.dstBinding(bindingIndex)
3636
.descriptorType(type.getVkEnum());
37-
updateFlag = false;
3837
}
3938

4039
@Override
41-
public boolean update(LogicalDevice<?> device) {
42-
if (resource == null) {
43-
throw new NullPointerException(BUFFER_NULL_ERROR);
44-
}
45-
return updateFlag;
46-
}
40+
public void update(LogicalDevice<?> device) {}
4741

4842
@Override
4943
public boolean isBindingCompatible(SetLayoutBinding binding) {
@@ -55,7 +49,7 @@ public boolean isBindingCompatible(SetLayoutBinding binding) {
5549
public void setValue(VersionedResource<GpuBuffer> value) {
5650
if (this.resource != value) {
5751
this.resource = value;
58-
updateFlag = true;
52+
variant++;
5953
}
6054
}
6155

@@ -64,4 +58,9 @@ public VersionedResource<GpuBuffer> getValue() {
6458
return resource;
6559
}
6660

61+
@Override
62+
public long getVariant() {
63+
return variant;
64+
}
65+
6766
}

jme3-lwjgl3/src/main/java/com/jme3/vulkan/material/uniforms/TextureUniform.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.jme3.vulkan.descriptors.Descriptor;
44
import com.jme3.vulkan.descriptors.SetLayoutBinding;
55
import com.jme3.vulkan.devices.LogicalDevice;
6+
import com.jme3.vulkan.frames.VersionedResource;
67
import com.jme3.vulkan.images.Image;
78
import com.jme3.vulkan.images.Texture;
89
import com.jme3.vulkan.shader.ShaderStage;
@@ -14,8 +15,8 @@
1415
public class TextureUniform extends AbstractUniform<Texture> {
1516

1617
private final Image.Layout layout;
17-
private Texture texture;
18-
private boolean updateFlag = true;
18+
private VersionedResource<Texture> texture;
19+
private long variant = 0L;
1920

2021
public TextureUniform(String name, Image.Layout layout, int bindingIndex, Flag<ShaderStage> stages) {
2122
super(name, Descriptor.CombinedImageSampler, bindingIndex, stages);
@@ -24,9 +25,10 @@ public TextureUniform(String name, Image.Layout layout, int bindingIndex, Flag<S
2425

2526
@Override
2627
public void populateWrite(MemoryStack stack, VkWriteDescriptorSet write) {
28+
Texture tex = texture.getVersion();
2729
VkDescriptorImageInfo.Buffer info = VkDescriptorImageInfo.calloc(1, stack)
28-
.imageView(texture.getImage().getNativeObject())
29-
.sampler(texture.getNativeObject())
30+
.imageView(tex.getImage().getNativeObject())
31+
.sampler(tex.getNativeObject())
3032
.imageLayout(layout.getVkEnum());
3133
write.pImageInfo(info)
3234
.descriptorType(type.getVkEnum())
@@ -36,26 +38,26 @@ public void populateWrite(MemoryStack stack, VkWriteDescriptorSet write) {
3638
}
3739

3840
@Override
39-
public boolean update(LogicalDevice<?> device) {
40-
if (texture == null) {
41-
throw new NullPointerException("Uniform texture is null.");
42-
}
43-
return updateFlag;
44-
}
41+
public void update(LogicalDevice<?> device) {}
4542

4643
@Override
47-
public void setValue(Texture value) {
44+
public void setValue(VersionedResource<Texture> value) {
4845
if (this.texture != value) {
4946
this.texture = value;
50-
updateFlag = true;
47+
variant++;
5148
}
5249
}
5350

5451
@Override
55-
public Texture getValue() {
52+
public VersionedResource<Texture> getValue() {
5653
return texture;
5754
}
5855

56+
@Override
57+
public long getVariant() {
58+
return variant;
59+
}
60+
5961
@Override
6062
public boolean isBindingCompatible(SetLayoutBinding binding) {
6163
return type == binding.getType()

jme3-lwjgl3/src/main/java/com/jme3/vulkan/mesh/Mesh.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,7 @@ public Mesh() {
2020
}
2121

2222
public void bindVertexBuffers(CommandBuffer cmd) {
23-
try (MemoryStack stack = MemoryStack.stackPush()) {
24-
LongBuffer vertBufs = stack.mallocLong(vertexBuffers.size());
25-
LongBuffer offsets = stack.mallocLong(vertexBuffers.size());
26-
for (GpuBuffer v : vertexBuffers) {
27-
vertBufs.put(v.getNativeObject());
28-
offsets.put(0);
29-
}
30-
vertBufs.flip();
31-
offsets.flip();
32-
vkCmdBindVertexBuffers(cmd.getBuffer(), 0, vertBufs, offsets);
33-
vkCmdBindIndexBuffer(cmd.getBuffer(), indexBuffer.getNativeObject(), 0, VK_INDEX_TYPE_UINT32);
34-
}
23+
3524
}
3625

3726
public void draw(CommandBuffer cmd) {

jme3-lwjgl3/src/main/java/com/jme3/vulkan/sync/SyncGroup.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import java.nio.IntBuffer;
77
import java.nio.LongBuffer;
8+
import java.util.Objects;
89

910
public class SyncGroup {
1011

11-
public static final SyncGroup ASYNC = new SyncGroup();
1212
private static final Semaphore[] EMPTY = new Semaphore[0];
13+
public static final SyncGroup ASYNC = new SyncGroup();
1314

1415
private static Semaphore[] toArray(Semaphore s) {
1516
return s != null ? new Semaphore[] {s} : EMPTY;
@@ -56,8 +57,8 @@ public SyncGroup(Semaphore[] waits, Semaphore signal, Fence fence) {
5657
}
5758

5859
public SyncGroup(Semaphore[] waits, Semaphore[] signals, Fence fence) {
59-
this.waits = waits;
60-
this.signals = signals;
60+
this.waits = Objects.requireNonNull(waits);
61+
this.signals = Objects.requireNonNull(signals);
6162
this.fence = fence;
6263
}
6364

@@ -96,7 +97,7 @@ public LongBuffer toWaitBuffer(MemoryStack stack) {
9697

9798
public IntBuffer toDstStageBuffer(MemoryStack stack) {
9899
IntBuffer buf = stack.mallocInt(waits.length);
99-
for (Semaphore s : signals) {
100+
for (Semaphore s : waits) {
100101
buf.put(s.getDstStageMask().bits());
101102
}
102103
buf.flip();

0 commit comments

Comments
 (0)