44import com .jme3 .util .natives .Native ;
55import com .jme3 .util .natives .NativeReference ;
66import com .jme3 .vulkan .devices .LogicalDevice ;
7+ import com .jme3 .vulkan .util .Flag ;
78import org .lwjgl .system .MemoryStack ;
89import org .lwjgl .vulkan .*;
910
1415
1516public 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}
0 commit comments