Skip to content

Commit 42a845a

Browse files
committed
fix warning on DescriptorSet destruction for DescriptorPools not created with a certain flag
1 parent d4646f6 commit 42a845a

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.jme3.util.natives.Native;
55
import com.jme3.util.natives.NativeReference;
66
import com.jme3.vulkan.devices.LogicalDevice;
7+
import com.jme3.vulkan.util.Flag;
78
import org.lwjgl.system.MemoryStack;
89
import org.lwjgl.vulkan.*;
910

@@ -14,17 +15,41 @@
1415

1516
public class DescriptorPool implements Native<Long> {
1617

18+
public enum Create implements Flag<Create> {
19+
20+
FreeDescriptorSets(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
21+
22+
private final int vkEnum;
23+
24+
Create(int vkEnum) {
25+
this.vkEnum = vkEnum;
26+
}
27+
28+
@Override
29+
public int bits() {
30+
return vkEnum;
31+
}
32+
33+
}
34+
1735
private final LogicalDevice<?> device;
1836
private final NativeReference ref;
37+
private final Flag<Create> flags;
1938
private final long id;
2039

2140
public DescriptorPool(LogicalDevice<?> device, int sets, PoolSize... sizes) {
41+
this(device, sets, Flag.none(), sizes);
42+
}
43+
44+
public DescriptorPool(LogicalDevice<?> device, int sets, Flag<Create> flags, PoolSize... sizes) {
2245
this.device = device;
46+
this.flags = flags;
2347
try (MemoryStack stack = MemoryStack.stackPush()) {
2448
VkDescriptorPoolCreateInfo create = VkDescriptorPoolCreateInfo.calloc(stack)
2549
.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO)
2650
.pPoolSizes(PoolSize.aggregate(stack, sizes))
27-
.maxSets(sets);
51+
.maxSets(sets)
52+
.flags(this.flags.bits());
2853
LongBuffer idBuf = stack.mallocLong(1);
2954
check(vkCreateDescriptorPool(device.getNativeObject(), create, null, idBuf),
3055
"Failed to create descriptor pool.");
@@ -52,6 +77,12 @@ public NativeReference getNativeReference() {
5277
return ref;
5378
}
5479

80+
/**
81+
* Allocates a {@link DescriptorSet} for each {@link DescriptorSetLayout} provided.
82+
*
83+
* @param layouts layouts to allocate DescriptorSets with
84+
* @return allocated DescriptorSets, in the same order as {@code layouts}
85+
*/
5586
public DescriptorSet[] allocateSets(DescriptorSetLayout... layouts) {
5687
assert layouts.length > 0 : "Must specify at least one set layout.";
5788
// layouts length = number of descriptor sets created
@@ -75,4 +106,8 @@ public void reset() {
75106
vkResetDescriptorPool(device.getNativeObject(), id, 0);
76107
}
77108

109+
public boolean isFreeSetsEnabled() {
110+
return flags.contains(Create.FreeDescriptorSets);
111+
}
112+
78113
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public DescriptorSet(LogicalDevice<?> device, DescriptorPool pool, DescriptorSet
2626
@Override
2727
public Runnable createNativeDestroyer() {
2828
return () -> {
29-
try (MemoryStack stack = MemoryStack.stackPush()) {
29+
if (pool.isFreeSetsEnabled()) try (MemoryStack stack = MemoryStack.stackPush()) {
3030
vkFreeDescriptorSets(device.getNativeObject(), pool.getNativeObject(), stack.longs(object));
3131
}
3232
};

jme3-lwjgl3/src/main/java/com/jme3/vulkan/util/Flag.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ static <T extends Flag> Flag<T> of(int bits) {
4141
return new FlagImpl<>(bits);
4242
}
4343

44+
static <T extends Flag> Flag<T> none() {
45+
return of(0);
46+
}
47+
4448
@SafeVarargs
4549
static <T extends Flag> Flag<T> of(Flag<T>... flags) {
4650
return new FlagImpl<>(flags);

0 commit comments

Comments
 (0)