annotate src/semicongine/vulkan/syncing.nim @ 566:cc7ba46fe3c4

add: descriptors, better swapchain implementation
author Sam <sam@basx.dev>
date Fri, 24 Mar 2023 00:11:42 +0700
parents 8de8a2102071
children 9c3e3dcb0328
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
1 import ./api
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
2 import ./device
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
3
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
4 type
566
cc7ba46fe3c4 add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 560
diff changeset
5 Semaphore* = object
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
6 vk*: VkSemaphore
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
7 device: Device
566
cc7ba46fe3c4 add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 560
diff changeset
8 Fence* = object
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
9 vk*: VkFence
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
10 device: Device
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
11
560
8de8a2102071 add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents: 559
diff changeset
12 proc createSemaphore*(device: Device): Semaphore =
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
13 assert device.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
14 var semaphoreInfo = VkSemaphoreCreateInfo(sType: VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO)
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
15 result.device = device
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
16 checkVkResult device.vk.vkCreateSemaphore(addr(semaphoreInfo), nil, addr(result.vk))
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
17
560
8de8a2102071 add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents: 559
diff changeset
18 proc createFence*(device: Device): Fence =
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
19 assert device.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
20 var fenceInfo = VkFenceCreateInfo(
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
21 sType: VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
22 flags: toBits [VK_FENCE_CREATE_SIGNALED_BIT]
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
23 )
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
24 result.device = device
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
25 checkVkResult device.vk.vkCreateFence(addr(fenceInfo), nil, addr(result.vk))
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
26
560
8de8a2102071 add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents: 559
diff changeset
27 proc destroy*(semaphore: var Semaphore) =
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
28 assert semaphore.device.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
29 assert semaphore.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
30 semaphore.device.vk.vkDestroySemaphore(semaphore.vk, nil)
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
31 semaphore.vk.reset
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
32
560
8de8a2102071 add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents: 559
diff changeset
33 proc destroy*(fence: var Fence) =
559
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
34 assert fence.device.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
35 assert fence.vk.valid
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
36 fence.device.vk.vkDestroyFence(fence.vk, nil)
baaa620887b4 add: more vulkan objects
Sam <sam@basx.dev>
parents:
diff changeset
37 fence.vk.reset