annotate semiconginev2/rendering/swapchain.nim @ 1229:5dcb503ef0c0

did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
author sam <sam@basx.dev>
date Thu, 18 Jul 2024 21:32:41 +0700
parents 56781cc0fc7c
children 69489a678141
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
1 const N_FRAMEBUFFERS = 3'u32
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
2
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
3 proc InitSwapchain*(
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
4 renderPass: RenderPass,
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
5 vSync: bool = false,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
6 oldSwapchain: Swapchain = nil,
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
7 ): Option[Swapchain] =
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
8 assert vulkan.instance.Valid, "Vulkan not initialized"
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
9
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
10 var capabilities: VkSurfaceCapabilitiesKHR
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
11 checkVkResult vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vulkan.physicalDevice, vulkan.surface, addr(capabilities))
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
12 let
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
13 width = capabilities.currentExtent.width
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
14 height = capabilities.currentExtent.height
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
15
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
16 if width == 0 or height == 0:
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
17 return none(Swapchain)
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
18
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
19 # following "count" is established according to vulkan specs
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
20 var minFramebufferCount = N_FRAMEBUFFERS
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
21 minFramebufferCount = max(minFramebufferCount, capabilities.minImageCount)
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
22 if capabilities.maxImageCount != 0:
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
23 minFramebufferCount = min(minFramebufferCount, capabilities.maxImageCount)
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
24
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
25 # create swapchain
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
26 let hasTripleBuffering = VK_PRESENT_MODE_MAILBOX_KHR in svkGetPhysicalDeviceSurfacePresentModesKHR()
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
27 var swapchainCreateInfo = VkSwapchainCreateInfoKHR(
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
28 sType: VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
29 surface: vulkan.surface,
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
30 minImageCount: minFramebufferCount,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
31 imageFormat: SURFACE_FORMAT,
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
32 imageColorSpace: VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, # only one supported without special extensions
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
33 imageExtent: capabilities.currentExtent,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
34 imageArrayLayers: 1,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
35 imageUsage: toBits [VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT],
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
36 imageSharingMode: VK_SHARING_MODE_EXCLUSIVE,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
37 preTransform: capabilities.currentTransform,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
38 compositeAlpha: VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, # only used for blending with other windows, can be opaque
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
39 presentMode: if (vSync or not hasTripleBuffering): VK_PRESENT_MODE_FIFO_KHR else: VK_PRESENT_MODE_MAILBOX_KHR,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
40 clipped: true,
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
41 oldSwapchain: if oldSwapchain != nil: oldSwapchain.vk else: VkSwapchainKHR(0),
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
42 )
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
43 var swapchain = Swapchain(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
44 width: width,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
45 height: height,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
46 renderPass: renderPass,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
47 vSync: vSync,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
48 oldSwapchain: oldSwapchain,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
49 )
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
50
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
51 if vkCreateSwapchainKHR(vulkan.device, addr(swapchainCreateInfo), nil, addr(swapchain.vk)) != VK_SUCCESS:
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
52 return none(Swapchain)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
53
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
54 if swapchain.oldSwapchain != nil:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
55 swapchain.oldSwapchainCounter = INFLIGHTFRAMES.int * 2
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
56
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
57 # create depth buffer image+view if desired
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
58 if renderPass.depthBuffer:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
59 swapchain.depthImage = svkCreate2DImage(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
60 width = width,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
61 height = height,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
62 format = DEPTH_FORMAT,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
63 usage = [VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT],
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
64 samples = renderPass.samples,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
65 )
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
66 let requirements = svkGetImageMemoryRequirements(swapchain.depthImage)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
67 swapchain.depthMemory = svkAllocateMemory(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
68 requirements.size,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
69 BestMemory(mappable = false, filter = requirements.memoryTypes)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
70 )
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
71 checkVkResult vkBindImageMemory(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
72 vulkan.device,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
73 swapchain.depthImage,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
74 swapchain.depthMemory,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
75 0,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
76 )
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
77 swapchain.depthImageView = svkCreate2DImageView(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
78 image = swapchain.depthImage,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
79 format = DEPTH_FORMAT,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
80 aspect = VK_IMAGE_ASPECT_DEPTH_BIT
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
81 )
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
82
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
83 # create msaa image+view if desired
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
84 if renderPass.samples != VK_SAMPLE_COUNT_1_BIT:
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
85 swapchain.msaaImage = svkCreate2DImage(
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
86 width = width,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
87 height = height,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
88 format = SURFACE_FORMAT,
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
89 usage = [VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT],
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
90 samples = renderPass.samples,
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
91 )
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
92 let requirements = svkGetImageMemoryRequirements(swapchain.msaaImage)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
93 swapchain.msaaMemory = svkAllocateMemory(
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
94 requirements.size,
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
95 BestMemory(mappable = false, filter = requirements.memoryTypes)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
96 )
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
97 checkVkResult vkBindImageMemory(
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
98 vulkan.device,
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
99 swapchain.msaaImage,
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
100 swapchain.msaaMemory,
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
101 0,
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
102 )
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
103 swapchain.msaaImageView = svkCreate2DImageView(image = swapchain.msaaImage, format = SURFACE_FORMAT)
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
104
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
105 # create framebuffers
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
106 var actualNFramebuffers: uint32
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
107 checkVkResult vkGetSwapchainImagesKHR(vulkan.device, swapchain.vk, addr(actualNFramebuffers), nil)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
108 var framebuffers = newSeq[VkImage](actualNFramebuffers)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
109 checkVkResult vkGetSwapchainImagesKHR(vulkan.device, swapchain.vk, addr(actualNFramebuffers), framebuffers.ToCPointer)
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
110
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
111 for framebuffer in framebuffers:
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
112 swapchain.framebufferViews.add svkCreate2DImageView(framebuffer, SURFACE_FORMAT)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
113 var attachments: seq[VkImageView]
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
114 if renderPass.samples == VK_SAMPLE_COUNT_1_BIT:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
115 if renderPass.depthBuffer:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
116 attachments = @[swapchain.framebufferViews[^1], swapchain.depthImageView]
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
117 else:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
118 attachments = @[swapchain.framebufferViews[^1]]
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
119 else:
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
120 if renderPass.depthBuffer:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
121 attachments = @[swapchain.msaaImageView, swapchain.depthImageView, swapchain.framebufferViews[^1]]
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
122 else:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
123 attachments = @[swapchain.msaaImageView, swapchain.framebufferViews[^1]]
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
124
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
125 swapchain.framebuffers.add svkCreateFramebuffer(
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
126 renderpass = renderPass.vk,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
127 width = width,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
128 height = height,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
129 attachments = attachments,
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
130 )
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
131
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
132 # create sync primitives
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
133 for i in 0 ..< INFLIGHTFRAMES:
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
134 swapchain.queueFinishedFence[i] = svkCreateFence(signaled = true)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
135 swapchain.imageAvailableSemaphore[i] = svkCreateSemaphore()
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
136 swapchain.renderFinishedSemaphore[i] = svkCreateSemaphore()
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
137
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
138 # command buffers
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
139 var commandPoolCreateInfo = VkCommandPoolCreateInfo(
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
140 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
141 flags: toBits [VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT],
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
142 queueFamilyIndex: vulkan.graphicsQueueFamily,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
143 )
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
144 checkVkResult vkCreateCommandPool(vulkan.device, addr(commandPoolCreateInfo), nil, addr(swapchain.commandBufferPool))
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
145 var allocInfo = VkCommandBufferAllocateInfo(
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
146 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
147 commandPool: swapchain.commandBufferPool,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
148 level: VK_COMMAND_BUFFER_LEVEL_PRIMARY,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
149 commandBufferCount: INFLIGHTFRAMES,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
150 )
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
151 checkVkResult vkAllocateCommandBuffers(vulkan.device, addr(allocInfo), swapchain.commandBuffers.ToCPointer)
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
152
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
153 return some(swapchain)
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
154
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
155 proc DestroySwapchain*(swapchain: Swapchain) =
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
156
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
157 if swapchain.msaaImage.Valid:
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
158 vkDestroyImageView(vulkan.device, swapchain.msaaImageView, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
159 vkDestroyImage(vulkan.device, swapchain.msaaImage, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
160 vkFreeMemory(vulkan.device, swapchain.msaaMemory, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
161
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
162 if swapchain.depthImage.Valid:
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
163 vkDestroyImageView(vulkan.device, swapchain.depthImageView, nil)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
164 vkDestroyImage(vulkan.device, swapchain.depthImage, nil)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
165 vkFreeMemory(vulkan.device, swapchain.depthMemory, nil)
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
166
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
167 for fence in swapchain.queueFinishedFence:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
168 vkDestroyFence(vulkan.device, fence, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
169
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
170 for semaphore in swapchain.imageAvailableSemaphore:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
171 vkDestroySemaphore(vulkan.device, semaphore, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
172
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
173 for semaphore in swapchain.renderFinishedSemaphore:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
174 vkDestroySemaphore(vulkan.device, semaphore, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
175
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
176 for imageView in swapchain.framebufferViews:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
177 vkDestroyImageView(vulkan.device, imageView, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
178
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
179 for framebuffer in swapchain.framebuffers:
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
180 vkDestroyFramebuffer(vulkan.device, framebuffer, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
181
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
182 vkDestroyCommandPool(vulkan.device, swapchain.commandBufferPool, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
183
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
184 vkDestroySwapchainKHR(vulkan.device, swapchain.vk, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
185
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
186 proc TryAcquireNextImage(swapchain: Swapchain): Option[VkFramebuffer] =
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
187 if not swapchain.queueFinishedFence[swapchain.currentFiF].Await(100_000_000):
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents: 1198
diff changeset
188 return none(VkFramebuffer)
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
189
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
190 let nextImageResult = vkAcquireNextImageKHR(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
191 vulkan.device,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
192 swapchain.vk,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
193 high(uint64),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
194 swapchain.imageAvailableSemaphore[swapchain.currentFiF],
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
195 VkFence(0),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
196 addr(swapchain.currentFramebufferIndex),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
197 )
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
198
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents: 1198
diff changeset
199 swapchain.queueFinishedFence[swapchain.currentFiF].svkResetFences()
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
200
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
201 if nextImageResult != VK_SUCCESS:
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
202 return none(VkFramebuffer)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
203 return some(swapchain.framebuffers[swapchain.currentFramebufferIndex])
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
204
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
205 proc Swap(swapchain: Swapchain, commandBuffer: VkCommandBuffer): bool =
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
206 var
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
207 waitStage = VkPipelineStageFlags(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
208 submitInfo = VkSubmitInfo(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
209 sType: VK_STRUCTURE_TYPE_SUBMIT_INFO,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
210 waitSemaphoreCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
211 pWaitSemaphores: addr(swapchain.imageAvailableSemaphore[swapchain.currentFiF]),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
212 pWaitDstStageMask: addr(waitStage),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
213 commandBufferCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
214 pCommandBuffers: addr(commandBuffer),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
215 signalSemaphoreCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
216 pSignalSemaphores: addr(swapchain.renderFinishedSemaphore[swapchain.currentFiF]),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
217 )
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
218 checkVkResult vkQueueSubmit(
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
219 queue = vulkan.graphicsQueue,
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
220 submitCount = 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
221 pSubmits = addr(submitInfo),
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
222 fence = swapchain.queueFinishedFence[swapchain.currentFiF]
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
223 )
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
224
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
225 var presentInfo = VkPresentInfoKHR(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
226 sType: VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
227 waitSemaphoreCount: 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
228 pWaitSemaphores: addr(swapchain.renderFinishedSemaphore[swapchain.currentFiF]),
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
229 swapchainCount: 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
230 pSwapchains: addr(swapchain.vk),
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
231 pImageIndices: addr(swapchain.currentFramebufferIndex),
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
232 pResults: nil,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
233 )
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
234 let presentResult = vkQueuePresentKHR(vulkan.graphicsQueue, addr(presentInfo))
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
235
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
236 if swapchain.oldSwapchain != nil:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
237 dec swapchain.oldSwapchainCounter
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
238 if swapchain.oldSwapchainCounter <= 0:
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
239 DestroySwapchain(swapchain.oldSwapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
240 swapchain.oldSwapchain = nil
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
241
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
242 if presentResult != VK_SUCCESS:
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
243 return false
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
244
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
245 swapchain.currentFiF = (uint32(swapchain.currentFiF) + 1) mod INFLIGHTFRAMES
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
246 return true
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
247
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
248 proc Recreate(swapchain: Swapchain): Option[Swapchain] =
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
249 InitSwapchain(
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
250 renderPass = swapchain.renderPass,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
251 vSync = swapchain.vSync,
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
252 oldSwapchain = swapchain,
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
253 )
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
254
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
255 template WithNextFrame*(theSwapchain: var Swapchain, framebufferName, commandBufferName, body: untyped): untyped =
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
256 var maybeFramebuffer = TryAcquireNextImage(theSwapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
257 if maybeFramebuffer.isSome:
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
258 block:
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
259 let `framebufferName` {.inject.} = maybeFramebuffer.get
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
260 let `commandBufferName` {.inject.} = theSwapchain.commandBuffers[theSwapchain.currentFiF]
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
261 let beginInfo = VkCommandBufferBeginInfo(
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
262 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
263 flags: VkCommandBufferUsageFlags(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT),
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
264 )
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
265 checkVkResult vkResetCommandBuffer(`commandBufferName`, VkCommandBufferResetFlags(0))
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
266 checkVkResult vkBeginCommandBuffer(`commandBufferName`, addr(beginInfo))
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
267
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
268 body
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
269
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
270 checkVkResult vkEndCommandBuffer(`commandBufferName`)
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
271 discard Swap(swapchain = theSwapchain, commandBuffer = `commandBufferName`)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
272 else:
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
273 let maybeNewSwapchain = Recreate(theSwapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
274 if maybeNewSwapchain.isSome:
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
275 theSwapchain = maybeNewSwapchain.get
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
276