Skip to content

Commit 5a25563

Browse files
committed
up
1 parent d0cfd0c commit 5a25563

File tree

6 files changed

+75
-10
lines changed

6 files changed

+75
-10
lines changed

src/main/kotlin/vkk/_10/api/Device_vk10.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ interface Device_vk10 : Pointer {
7979
infix fun createCommandPool(createInfo: CommandPoolCreateInfo): VkCommandPool =
8080
stak { it createCommandPool createInfo }
8181

82-
// infix fun MemoryStack.createCommandPoolUnique(createInfo: CommandPoolCreateInfo): VkCommandPool =
83-
// createCommandPool(createInfo).also { vk.cleaner.register() }
84-
//
85-
// infix fun createCommandPoolUnique(createInfo: CommandPoolCreateInfo): VkCommandPool =
86-
// createCommandPool(createInfo)
82+
infix fun MemoryStack.createCommandPoolUnique(createInfo: CommandPoolCreateInfo): VkCommandPool {
83+
val commandPool = createCommandPool(createInfo)
84+
vk.cleaner.register(commandPool) {
85+
callPJPV(this@Device_vk10.adr, commandPool.L, NULL, capabilities.vkDestroyCommandPool)
86+
}
87+
return commandPool
88+
}
89+
90+
infix fun createCommandPoolUnique(createInfo: CommandPoolCreateInfo): VkCommandPool =
91+
stak { it createCommandPoolUnique createInfo }
8792

8893
// --- [ vkCreateComputePipelines ] ---
8994

src/main/kotlin/vkk/entities/objects.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ inline class VkBufferView(val L: Long = VK_NULL_HANDLE) {
3939
}
4040
}
4141

42+
//fun VkUniqueCommandPool(long: Long = VK_NULL_HANDLE): VkUniqueCommandPool = VkUniqueCommandPool(L)
43+
//
44+
//inline class VkUniqueCommandPool(val L: Long = VK_NULL_HANDLE)
45+
4246
inline class VkCommandPool(val L: Long = VK_NULL_HANDLE) {
4347
val isValid get() = L != VK_NULL_HANDLE
4448
val isInvalid get() = L == VK_NULL_HANDLE

src/main/kotlin/vkk/identifiers/CommandBuffer.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package vkk.identifiers
22

33
import kool.Ptr
4+
import kool.adr
5+
import org.lwjgl.system.JNI
46
import org.lwjgl.system.MemoryStack
57
import vkk.VkQueryControlFlags
68
import vkk.VkSubpassContents
@@ -10,8 +12,17 @@ import vkk._10.structs.RenderPassBeginInfo
1012
import vkk._11.api.CommandBuffer_vk11
1113
import vkk.entities.VkQueryPool
1214

15+
class UniqueCommandBuffer(handle: Ptr, device: Device) : CommandBuffer(handle, device) {
16+
// val address = adr
17+
// val function = capabilities.vkDestroy
18+
// vk.cleaner.register(this) {
19+
// JNI.callPJPV(address, commandPool.L, commandBufferCount, pCommandBuffers, capabilities.vkFreeCommandBuffers)
20+
// println("device gc'ed")
21+
// }
22+
}
23+
1324
/** Wraps a Vulkan command buffer handle. */
14-
class CommandBuffer
25+
open class CommandBuffer
1526
/**
1627
* Creates a `VkCommandBuffer` using the specified native handle and device.
1728
*
@@ -20,8 +31,7 @@ class CommandBuffer
2031
*/
2132
constructor(handle: Ptr,
2233
/** Returns the device on which this `VkCommandBuffer` was created. */
23-
val device: Device
24-
)
34+
val device: Device)
2535

2636
: DispatchableHandleDevice(handle, device.capabilities),
2737

src/main/kotlin/vkk/identifiers/Device.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ open class Device(handle: Ptr,
7373
infix fun allocateCommandBuffers(allocateInfo: CommandBufferAllocateInfo): Array<CommandBuffer> =
7474
stak { it allocateCommandBuffers allocateInfo }
7575

76+
// Unique
77+
78+
infix fun MemoryStack.allocateCommandBufferUnique(allocateInfo: CommandBufferAllocateInfo): UniqueCommandBuffer =
79+
framed { UniqueCommandBuffer(this.pointerAdr { nAllocateCommandBuffers(allocateInfo write this, it).check() }, this@Device) }
80+
81+
infix fun allocateCommandBufferUnique(allocateInfo: CommandBufferAllocateInfo): CommandBuffer =
82+
stak { it allocateCommandBufferUnique allocateInfo }
83+
84+
85+
infix fun MemoryStack.allocateCommandBuffersUnique(allocateInfo: CommandBufferAllocateInfo): Array<UniqueCommandBuffer> =
86+
framed {
87+
val pCommandBuffers = this.mPointer(allocateInfo.commandBufferCount)
88+
nAllocateCommandBuffers(allocateInfo write this, pCommandBuffers.adr)
89+
// val address = [email protected]
90+
val array = Array(allocateInfo.commandBufferCount) {
91+
UniqueCommandBuffer(memGetAddress(pCommandBuffers[it]), this@Device)
92+
}
93+
// vk.cleaner.register(array) {
94+
// callPJPV(address, allocateInfo.commandPool.L, array.size, pCommandBuffers, capabilities.vkFreeCommandBuffers)
95+
// }
96+
array
97+
}
98+
99+
infix fun allocateCommandBuffersUnique(allocateInfo: CommandBufferAllocateInfo): Array<UniqueCommandBuffer> =
100+
stak { it allocateCommandBuffersUnique allocateInfo }
101+
76102
// --- [ vkGetDeviceQueue ] ---
77103

78104
fun MemoryStack.getQueue(queueFamilyIndex: Int, queueIndex: Int = 0): Queue =

src/test/kotlin/tests/01 initInstance.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@ class `01 initInstance` : StringSpec() {
2626
// Note: No need to explicitly destroy the instance, as the corresponding destroy function is
2727
// called by the destructor of the UniqueInstance on leaving this scope.
2828
}
29+
// "a" {
30+
// for (i in 1..10000) {
31+
// val a = IntArray(10000)
32+
// try {
33+
// Thread.sleep(1)
34+
// } catch (e: InterruptedException) {
35+
// }
36+
// }
37+
// }
2938
}
3039
}

src/test/kotlin/tests/04 initCommandBuffer.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package tests
22

33
import io.kotlintest.specs.StringSpec
44
import main.isNotCI
5+
import vkk.VkCommandBufferLevel
6+
import vkk._10.structs.CommandBufferAllocateInfo
7+
import vkk._10.structs.CommandPoolCreateInfo
58
import vkk.vu
69

710
class `04 initCommandBuffer` : StringSpec() {
@@ -25,10 +28,18 @@ class `04 initCommandBuffer` : StringSpec() {
2528
/* VULKAN_HPP_KEY_START */
2629

2730
// create a UniqueCommandPool to allocate a CommandBuffer from
28-
// val commandPool = device.createCommandPoolUnique(CommandPoolCreateInfo(0, graphicsQueueFamilyIndex))
31+
val commandPool = device.createCommandPoolUnique(CommandPoolCreateInfo(0, graphicsQueueFamilyIndex))
2932

3033
// allocate a CommandBuffer from the CommandPool
31-
// vk::UniqueCommandBuffer commandBuffer = std::move(device->allocateCommandBuffersUnique(vk::CommandBufferAllocateInfo(commandPool.get(), vk::CommandBufferLevel::ePrimary, 1)).front())
34+
val commandBuffer = device.allocateCommandBuffersUnique(CommandBufferAllocateInfo(commandPool, VkCommandBufferLevel.PRIMARY, 1))[0]
35+
36+
// for (i in 1..10000) {
37+
// val a = IntArray(10000)
38+
// try {
39+
// Thread.sleep(1)
40+
// } catch (e: InterruptedException) {
41+
// }
42+
// }
3243
}
3344
}
3445
}

0 commit comments

Comments
 (0)