annotate semiconginev2/rendering/swapchain.nim @ 1258:5442d0e9d8ff

did: improve testing lighting, try new glb model (need to add jpeg support first)
author sam <sam@basx.dev>
date Sun, 28 Jul 2024 20:42:51 +0700
parents 69489a678141
children
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
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
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,
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
7 ): 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:
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
17 return nil
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:
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
52 return nil
1196
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
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
153 return 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) =
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
156 if swapchain.oldSwapchain != nil:
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
157 DestroySwapchain(swapchain.oldSwapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
158
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
159 if swapchain.msaaImage.Valid:
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
160 vkDestroyImageView(vulkan.device, swapchain.msaaImageView, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
161 vkDestroyImage(vulkan.device, swapchain.msaaImage, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
162 vkFreeMemory(vulkan.device, swapchain.msaaMemory, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1201
diff changeset
163
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
164 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
165 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
166 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
167 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
168
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
169 for fence in swapchain.queueFinishedFence:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
170 vkDestroyFence(vulkan.device, fence, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
171
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
172 for semaphore in swapchain.imageAvailableSemaphore:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
173 vkDestroySemaphore(vulkan.device, semaphore, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
174
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
175 for semaphore in swapchain.renderFinishedSemaphore:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
176 vkDestroySemaphore(vulkan.device, semaphore, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
177
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
178 for imageView in swapchain.framebufferViews:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
179 vkDestroyImageView(vulkan.device, imageView, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
180
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
181 for framebuffer in swapchain.framebuffers:
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
182 vkDestroyFramebuffer(vulkan.device, framebuffer, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
183
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
184 vkDestroyCommandPool(vulkan.device, swapchain.commandBufferPool, nil)
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
185
1201
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
186 vkDestroySwapchainKHR(vulkan.device, swapchain.vk, nil)
d4a206b5e5b0 add: rest of the cleanup stuff
sam <sam@basx.dev>
parents: 1200
diff changeset
187
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
188 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
189 if not swapchain.queueFinishedFence[swapchain.currentFiF].Await(100_000_000):
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents: 1198
diff changeset
190 return none(VkFramebuffer)
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
191
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
192 let nextImageResult = vkAcquireNextImageKHR(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
193 vulkan.device,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
194 swapchain.vk,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
195 high(uint64),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
196 swapchain.imageAvailableSemaphore[swapchain.currentFiF],
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
197 VkFence(0),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
198 addr(swapchain.currentFramebufferIndex),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
199 )
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
200
1199
ba1af13233ee add: working main-renderloop
sam <sam@basx.dev>
parents: 1198
diff changeset
201 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
202
1196
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
203 if nextImageResult != VK_SUCCESS:
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
204 return none(VkFramebuffer)
82feceae80b1 sync from bedroom to office
sam <sam@basx.dev>
parents: 1195
diff changeset
205 return some(swapchain.framebuffers[swapchain.currentFramebufferIndex])
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
206
1229
5dcb503ef0c0 did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents: 1218
diff changeset
207 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
208 var
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
209 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
210 submitInfo = VkSubmitInfo(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
211 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
212 waitSemaphoreCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
213 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
214 pWaitDstStageMask: addr(waitStage),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
215 commandBufferCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
216 pCommandBuffers: addr(commandBuffer),
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
217 signalSemaphoreCount: 1,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
218 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
219 )
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
220 checkVkResult vkQueueSubmit(
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
221 queue = vulkan.graphicsQueue,
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
222 submitCount = 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
223 pSubmits = addr(submitInfo),
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
224 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
225 )
1194
397c681f9c0c swapchain and stuff
sam <sam@basx.dev>
parents:
diff changeset
226
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
227 var presentInfo = VkPresentInfoKHR(
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
228 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
229 waitSemaphoreCount: 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
230 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
231 swapchainCount: 1,
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
232 pSwapchains: addr(swapchain.vk),
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
233 pImageIndices: addr(swapchain.currentFramebufferIndex),
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
234 pResults: nil,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
235 )
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
236 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
237
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
238 if swapchain.oldSwapchain != nil:
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
239 dec swapchain.oldSwapchainCounter
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
240 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
241 DestroySwapchain(swapchain.oldSwapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
242 swapchain.oldSwapchain = nil
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
243
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
244 if presentResult != VK_SUCCESS:
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
245 return false
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
246
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
247 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
248 return true
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
249
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
250 proc Recreate(swapchain: Swapchain): Swapchain =
1197
f6a0dc7ad052 sync from bedroom to office
sam <sam@basx.dev>
parents: 1196
diff changeset
251 InitSwapchain(
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
252 renderPass = swapchain.renderPass,
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
253 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
254 oldSwapchain = swapchain,
1195
cfba2b7e00d0 did: most of swapchain, swap still needs to be done
sam <sam@basx.dev>
parents: 1194
diff changeset
255 )
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
256
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
257 template WithNextFrame*(framebufferName, commandBufferName, body: untyped): untyped =
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
258 assert vulkan.swapchain != nil, "Swapchain has not been initialized yet"
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
259 var maybeFramebuffer = TryAcquireNextImage(vulkan.swapchain)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
260 if maybeFramebuffer.isSome:
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
261 block:
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
262 let `framebufferName` {.inject.} = maybeFramebuffer.get
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
263 let `commandBufferName` {.inject.} = vulkan.swapchain.commandBuffers[vulkan.swapchain.currentFiF]
1198
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
264 let beginInfo = VkCommandBufferBeginInfo(
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
265 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
266 flags: VkCommandBufferUsageFlags(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT),
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 checkVkResult vkResetCommandBuffer(`commandBufferName`, VkCommandBufferResetFlags(0))
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
269 checkVkResult vkBeginCommandBuffer(`commandBufferName`, addr(beginInfo))
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
270
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
271 body
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
272
96a094cd0c78 sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1197
diff changeset
273 checkVkResult vkEndCommandBuffer(`commandBufferName`)
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
274 discard Swap(swapchain = vulkan.swapchain, commandBuffer = `commandBufferName`)
1200
5c6491f28dcd did: simplify some swapchain stuff, add many destructor calls
sam <sam@basx.dev>
parents: 1199
diff changeset
275 else:
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
276 let newSwapchain = Recreate(vulkan.swapchain)
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
277 if newSwapchain != nil:
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1229
diff changeset
278 vulkan.swapchain = newSwapchain