Mercurial > games > semicongine
comparison semiconginev2/old/vulkan/syncing.nim @ 1218:56781cc0fc7c compiletime-tests
did: renamge main package
| author | sam <sam@basx.dev> |
|---|---|
| date | Wed, 17 Jul 2024 21:01:37 +0700 |
| parents | semicongine/old/vulkan/syncing.nim@a3eb305bcac2 |
| children |
comparison
equal
deleted
inserted
replaced
| 1217:f819a874058f | 1218:56781cc0fc7c |
|---|---|
| 1 import ../core | |
| 2 import ./device | |
| 3 | |
| 4 type | |
| 5 Semaphore* = object | |
| 6 vk*: VkSemaphore | |
| 7 device: Device | |
| 8 Fence* = object | |
| 9 vk*: VkFence | |
| 10 device: Device | |
| 11 awaitAction: proc() = nil | |
| 12 | |
| 13 proc CreateSemaphore*(device: Device): Semaphore = | |
| 14 assert device.vk.Valid | |
| 15 var semaphoreInfo = VkSemaphoreCreateInfo(sType: VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO) | |
| 16 result.device = device | |
| 17 checkVkResult device.vk.vkCreateSemaphore(addr(semaphoreInfo), nil, addr(result.vk)) | |
| 18 | |
| 19 proc CreateFence*(device: Device, awaitAction: proc() = nil): Fence = | |
| 20 assert device.vk.Valid | |
| 21 var fenceInfo = VkFenceCreateInfo( | |
| 22 sType: VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, | |
| 23 flags: toBits [VK_FENCE_CREATE_SIGNALED_BIT] | |
| 24 ) | |
| 25 result.device = device | |
| 26 result.awaitAction = awaitAction | |
| 27 checkVkResult device.vk.vkCreateFence(addr(fenceInfo), nil, addr(result.vk)) | |
| 28 | |
| 29 proc Await*(fence: var Fence) = | |
| 30 assert fence.device.vk.Valid | |
| 31 assert fence.vk.Valid | |
| 32 checkVkResult vkWaitForFences(fence.device.vk, 1, addr fence.vk, false, high(uint64)) | |
| 33 if fence.awaitAction != nil: | |
| 34 fence.awaitAction() | |
| 35 | |
| 36 proc Reset*(fence: var Fence) = | |
| 37 assert fence.device.vk.Valid | |
| 38 assert fence.vk.Valid | |
| 39 checkVkResult fence.device.vk.vkResetFences(1, addr fence.vk) | |
| 40 | |
| 41 proc Destroy*(semaphore: var Semaphore) = | |
| 42 assert semaphore.device.vk.Valid | |
| 43 assert semaphore.vk.Valid | |
| 44 semaphore.device.vk.vkDestroySemaphore(semaphore.vk, nil) | |
| 45 semaphore.vk.Reset | |
| 46 | |
| 47 proc Destroy*(fence: var Fence) = | |
| 48 assert fence.device.vk.Valid | |
| 49 assert fence.vk.Valid | |
| 50 fence.device.vk.vkDestroyFence(fence.vk, nil) | |
| 51 fence.vk.Reset |
