annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
1 import ../core
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
2 import ./device
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
3
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
4 type
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
5 Semaphore* = object
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
6 vk*: VkSemaphore
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
7 device: Device
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
8 Fence* = object
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
9 vk*: VkFence
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
10 device: Device
951
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
11 awaitAction: proc() = nil
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
12
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
13 proc CreateSemaphore*(device: Device): Semaphore =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
14 assert device.vk.Valid
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
15 var semaphoreInfo = VkSemaphoreCreateInfo(sType: VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO)
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
16 result.device = device
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
17 checkVkResult device.vk.vkCreateSemaphore(addr(semaphoreInfo), nil, addr(result.vk))
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
18
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
19 proc CreateFence*(device: Device, awaitAction: proc() = nil): Fence =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
20 assert device.vk.Valid
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
21 var fenceInfo = VkFenceCreateInfo(
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
22 sType: VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
23 flags: toBits [VK_FENCE_CREATE_SIGNALED_BIT]
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
24 )
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
25 result.device = device
951
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
26 result.awaitAction = awaitAction
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
27 checkVkResult device.vk.vkCreateFence(addr(fenceInfo), nil, addr(result.vk))
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
28
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
29 proc Await*(fence: var Fence) =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
30 assert fence.device.vk.Valid
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
31 assert fence.vk.Valid
951
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
32 checkVkResult vkWaitForFences(fence.device.vk, 1, addr fence.vk, false, high(uint64))
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
33 if fence.awaitAction != nil:
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
34 fence.awaitAction()
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
35
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
36 proc Reset*(fence: var Fence) =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
37 assert fence.device.vk.Valid
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
38 assert fence.vk.Valid
951
c6213a794ab0 fix: bad syncing mechanism, much better now (I think)
sam <sam@basx.dev>
parents: 920
diff changeset
39 checkVkResult fence.device.vk.vkResetFences(1, addr fence.vk)
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
40
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
41 proc Destroy*(semaphore: var Semaphore) =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
42 assert semaphore.device.vk.Valid
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
43 assert semaphore.vk.Valid
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
44 semaphore.device.vk.vkDestroySemaphore(semaphore.vk, nil)
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
45 semaphore.vk.Reset
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
46
1138
02e1d2658ff5 did: more renaming
sam <sam@basx.dev>
parents: 951
diff changeset
47 proc Destroy*(fence: var Fence) =
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
48 assert fence.device.vk.Valid
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
49 assert fence.vk.Valid
840
44ec744fbedc did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff changeset
50 fence.device.vk.vkDestroyFence(fence.vk, nil)
1139
114f395b9144 did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents: 1138
diff changeset
51 fence.vk.Reset