Mercurial > games > semicongine
annotate semiconginev2/old/vulkan/swapchain.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/swapchain.nim@397c681f9c0c |
children |
rev | line source |
---|---|
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/options |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
2 import std/strformat |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
3 import std/logging |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 import ../core |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 import ./device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
7 import ./physicaldevice |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
8 import ./image |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
9 import ./framebuffer |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 import ./syncing |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 type |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 Swapchain* = object |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 device*: Device |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
15 vk*: VkSwapchainKHR |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
16 dimension*: TVec2[uint32] |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
17 nFramebuffers*: uint32 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
18 currentInFlight*: int |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
19 currentFramebufferIndex: uint32 |
1167 | 20 samples: VkSampleCountFlagBits |
21 colorImage: VulkanImage | |
22 colorImageView: ImageView | |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
23 framebufferViews*: seq[ImageView] |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
24 framebuffers*: seq[Framebuffer] |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
25 queueFinishedFence*: seq[Fence] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 imageAvailableSemaphore*: seq[Semaphore] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
27 renderFinishedSemaphore*: seq[Semaphore] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 # required for recreation: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 renderPass: VkRenderPass |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 surfaceFormat: VkSurfaceFormatKHR |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
31 inFlightFrames*: int |
946
5ef3e789b672
fix: possibly undeterministic queue selection in swapchain
sam <sam@basx.dev>
parents:
943
diff
changeset
|
32 presentQueue: Queue |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
948
diff
changeset
|
33 vSync: bool |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
34 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 |
1138 | 36 proc CreateSwapchain*( |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
37 device: Device, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
38 renderPass: VkRenderPass, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 surfaceFormat: VkSurfaceFormatKHR, |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
948
diff
changeset
|
40 inFlightFrames: int, |
1167 | 41 samples: VkSampleCountFlagBits, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
42 desiredFramebufferCount = 3'u32, |
913
b19faed54b14
did: correct usage of vSync/triple buffering
Sam <sam@basx.dev>
parents:
908
diff
changeset
|
43 oldSwapchain = VkSwapchainKHR(0), |
1167 | 44 vSync = false, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
45 ): Option[Swapchain] = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
46 assert device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
47 assert device.physicalDevice.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
48 assert renderPass.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
49 assert inFlightFrames > 0 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
50 |
1138 | 51 var capabilities = device.physicalDevice.GetSurfaceCapabilities() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
52 if capabilities.currentExtent.width == 0 or capabilities.currentExtent.height == 0: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
53 return none(Swapchain) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
54 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
55 var minFramebufferCount = desiredFramebufferCount |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
56 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
57 # following is according to vulkan specs |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
58 minFramebufferCount = max(minFramebufferCount, capabilities.minImageCount) |
908
75a544b946ea
did: always use FIFO swapchain mode, as recommended in a talk on the Vulkan youtube channel (except you know what you are doing, which is cleary not the case here)
Sam <sam@basx.dev>
parents:
902
diff
changeset
|
59 if capabilities.maxImageCount != 0: |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
60 minFramebufferCount = min(minFramebufferCount, capabilities.maxImageCount) |
1138 | 61 let hasTripleBuffering = VK_PRESENT_MODE_MAILBOX_KHR in device.physicalDevice.GetSurfacePresentModes() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
62 var createInfo = VkSwapchainCreateInfoKHR( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
63 sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
64 surface: device.physicalDevice.surface, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
65 minImageCount: minFramebufferCount, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
66 imageFormat: surfaceFormat.format, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
67 imageColorSpace: surfaceFormat.colorSpace, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
68 imageExtent: capabilities.currentExtent, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
69 imageArrayLayers: 1, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
70 imageUsage: toBits [VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
71 # VK_SHARING_MODE_CONCURRENT no supported currently |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
72 imageSharingMode: VK_SHARING_MODE_EXCLUSIVE, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 preTransform: capabilities.currentTransform, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 compositeAlpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, # only used for blending with other windows, can be opaque |
913
b19faed54b14
did: correct usage of vSync/triple buffering
Sam <sam@basx.dev>
parents:
908
diff
changeset
|
75 presentMode: if (vSync or not hasTripleBuffering): VK_PRESENT_MODE_FIFO_KHR else: VK_PRESENT_MODE_MAILBOX_KHR, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 clipped: true, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 oldSwapchain: oldSwapchain, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
78 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
79 var |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
80 swapchain = Swapchain( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
81 device: device, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 surfaceFormat: surfaceFormat, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 dimension: TVec2[uint32]([capabilities.currentExtent.width, capabilities.currentExtent.height]), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 inFlightFrames: inFlightFrames, |
949
0cf68e7336e8
add: a few more exposed parameters to the render API
sam <sam@basx.dev>
parents:
948
diff
changeset
|
85 renderPass: renderPass, |
1167 | 86 vSync: vSync, |
87 samples: samples, | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
88 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
89 |
1167 | 90 if samples != VK_SAMPLE_COUNT_1_BIT: |
91 swapchain.colorImage = device.CreateImage( | |
92 width = capabilities.currentExtent.width, | |
93 height = capabilities.currentExtent.height, | |
94 depth = 4, | |
95 samples = samples, | |
96 format = surfaceFormat.format, | |
97 usage = [VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], | |
98 ) | |
99 swapchain.colorImageView = swapchain.colorImage.CreateImageView() | |
100 | |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
101 if device.vk.vkCreateSwapchainKHR(addr createInfo, nil, addr swapchain.vk) == VK_SUCCESS: |
1194 | 102 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
103 checkVkResult device.vk.vkGetSwapchainImagesKHR(swapchain.vk, addr swapchain.nFramebuffers, nil) |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
104 var framebuffers = newSeq[VkImage](swapchain.nFramebuffers) |
1137 | 105 checkVkResult device.vk.vkGetSwapchainImagesKHR(swapchain.vk, addr swapchain.nFramebuffers, framebuffers.ToCPointer) |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
106 for framebuffer in framebuffers: |
1138 | 107 let framebufferView = VulkanImage(vk: framebuffer, format: surfaceFormat.format, device: device).CreateImageView() |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
108 swapchain.framebufferViews.add framebufferView |
1167 | 109 if samples == VK_SAMPLE_COUNT_1_BIT: |
110 swapchain.framebuffers.add device.CreateFramebuffer(renderPass, [framebufferView], swapchain.dimension) | |
111 else: | |
112 swapchain.framebuffers.add device.CreateFramebuffer(renderPass, [swapchain.colorImageView, framebufferView], swapchain.dimension) | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
113 for i in 0 ..< swapchain.inFlightFrames: |
1138 | 114 swapchain.queueFinishedFence.add device.CreateFence() |
115 swapchain.imageAvailableSemaphore.add device.CreateSemaphore() | |
116 swapchain.renderFinishedSemaphore.add device.CreateSemaphore() | |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
117 debug &"Created swapchain with: {swapchain.nFramebuffers} framebuffers, {inFlightFrames} in-flight frames, {swapchain.dimension.x}x{swapchain.dimension.y}" |
1138 | 118 assert device.FirstPresentationQueue().isSome, "No present queue found" |
119 swapchain.presentQueue = device.FirstPresentationQueue().get | |
1167 | 120 |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
121 result = some(swapchain) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
122 else: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
123 result = none(Swapchain) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
124 |
1138 | 125 proc CurrentFramebuffer*(swapchain: Swapchain): Framebuffer = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
126 assert swapchain.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
127 assert swapchain.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
128 swapchain.framebuffers[swapchain.currentFramebufferIndex] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
129 |
1138 | 130 proc AcquireNextFrame*(swapchain: var Swapchain): bool = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
131 assert swapchain.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
132 assert swapchain.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
133 |
1138 | 134 swapchain.queueFinishedFence[swapchain.currentInFlight].Await() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
135 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
136 let nextImageResult = swapchain.device.vk.vkAcquireNextImageKHR( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
137 swapchain.vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
138 high(uint64), |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
139 swapchain.imageAvailableSemaphore[swapchain.currentInFlight].vk, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
140 VkFence(0), |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
141 addr swapchain.currentFramebufferIndex, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
142 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
143 |
1158
f32359ffd882
fix: now something wrong with swapchain on linux XD
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
144 swapchain.queueFinishedFence[swapchain.currentInFlight].Reset() |
f32359ffd882
fix: now something wrong with swapchain on linux XD
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
145 |
f32359ffd882
fix: now something wrong with swapchain on linux XD
sam <sam@basx.dev>
parents:
1139
diff
changeset
|
146 return nextImageResult == VK_SUCCESS |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
147 |
1138 | 148 proc Swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
149 assert swapchain.device.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
150 assert swapchain.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
151 assert queue.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
152 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
153 var |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
154 waitSemaphores = [swapchain.imageAvailableSemaphore[swapchain.currentInFlight].vk] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
155 waitStages = [VkPipelineStageFlags(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)] |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
156 submitInfo = VkSubmitInfo( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
157 sType: VK_STRUCTURE_TYPE_SUBMIT_INFO, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
158 waitSemaphoreCount: 1, |
1137 | 159 pWaitSemaphores: waitSemaphores.ToCPointer, |
160 pWaitDstStageMask: waitStages.ToCPointer, | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
161 commandBufferCount: 1, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
162 pCommandBuffers: addr commandBuffer, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
163 signalSemaphoreCount: 1, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
164 pSignalSemaphores: addr swapchain.renderFinishedSemaphore[swapchain.currentInFlight].vk, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
165 ) |
946
5ef3e789b672
fix: possibly undeterministic queue selection in swapchain
sam <sam@basx.dev>
parents:
943
diff
changeset
|
166 checkVkResult queue.vk.vkQueueSubmit( |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
167 submitCount = 1, |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
168 pSubmits = addr submitInfo, |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
169 fence = swapchain.queueFinishedFence[swapchain.currentInFlight].vk |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
170 ) |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
171 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
172 var presentInfo = VkPresentInfoKHR( |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
173 sType: VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
174 waitSemaphoreCount: 1, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
175 pWaitSemaphores: addr swapchain.renderFinishedSemaphore[swapchain.currentInFlight].vk, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
176 swapchainCount: 1, |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
177 pSwapchains: addr swapchain.vk, |
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
178 pImageIndices: addr swapchain.currentFramebufferIndex, |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
179 pResults: nil, |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
180 ) |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
181 let presentResult = vkQueuePresentKHR(swapchain.presentQueue.vk, addr presentInfo) |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
182 if presentResult != VK_SUCCESS: |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
183 return false |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
184 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
185 return true |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
186 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
187 |
1138 | 188 proc Destroy*(swapchain: var Swapchain) = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
189 assert swapchain.vk.Valid |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
190 |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
191 for imageview in swapchain.framebufferViews.mitems: |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
192 assert imageview.vk.Valid |
1138 | 193 imageview.Destroy() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
194 for framebuffer in swapchain.framebuffers.mitems: |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
195 assert framebuffer.vk.Valid |
1138 | 196 framebuffer.Destroy() |
1167 | 197 if swapchain.colorImage.vk.Valid: |
198 swapchain.colorImage.Destroy() | |
199 if swapchain.colorImageView.vk.Valid: | |
200 swapchain.colorImageView.Destroy() | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
201 for i in 0 ..< swapchain.inFlightFrames: |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
202 assert swapchain.queueFinishedFence[i].vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
203 assert swapchain.imageAvailableSemaphore[i].vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
204 assert swapchain.renderFinishedSemaphore[i].vk.Valid |
1138 | 205 swapchain.queueFinishedFence[i].Destroy() |
206 swapchain.imageAvailableSemaphore[i].Destroy() | |
207 swapchain.renderFinishedSemaphore[i].Destroy() | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
208 |
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
209 swapchain.device.vk.vkDestroySwapchainKHR(swapchain.vk, nil) |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
210 swapchain.vk.Reset() |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
211 |
1138 | 212 proc Recreate*(swapchain: var Swapchain): Option[Swapchain] = |
1139
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
213 assert swapchain.vk.Valid |
114f395b9144
did: finish refactoring and updated all tests accordingly
sam <sam@basx.dev>
parents:
1138
diff
changeset
|
214 assert swapchain.device.vk.Valid |
1138 | 215 result = CreateSwapchain( |
902 | 216 device = swapchain.device, |
217 renderPass = swapchain.renderPass, | |
218 surfaceFormat = swapchain.surfaceFormat, | |
950
fe48b091e83f
did: tons of small improvments, on the way to make GPU sync (more) correct I guess
sam <sam@basx.dev>
parents:
949
diff
changeset
|
219 desiredFramebufferCount = swapchain.nFramebuffers, |
902 | 220 inFlightFrames = swapchain.inFlightFrames, |
221 oldSwapchain = swapchain.vk, | |
1167 | 222 vSync = swapchain.vSync, |
223 samples = swapchain.samples, | |
840
44ec744fbedc
did: package restructuring according to nimble recommendation for libraries
Sam <sam@basx.dev>
parents:
diff
changeset
|
224 ) |