Mercurial > games > semicongine
comparison semiconginev2/rendering/vulkan_wrappers.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 |
comparison
equal
deleted
inserted
replaced
1228:4e465583ea32 | 1229:5dcb503ef0c0 |
---|---|
46 device, | 46 device, |
47 queueFamilyIndex, | 47 queueFamilyIndex, |
48 0, | 48 0, |
49 addr(result), | 49 addr(result), |
50 ) | 50 ) |
51 | |
52 proc DefaultSurfaceFormat(): VkFormat = | |
53 # EVERY windows driver and almost every linux driver should support this | |
54 VK_FORMAT_B8G8R8A8_SRGB | |
55 | 51 |
56 func size(format: VkFormat): uint64 = | 52 func size(format: VkFormat): uint64 = |
57 const formatSize = [ | 53 const formatSize = [ |
58 VK_FORMAT_B8G8R8A8_SRGB.int: 4'u64, | 54 VK_FORMAT_B8G8R8A8_SRGB.int: 4'u64, |
59 ] | 55 ] |
138 sharingMode: VK_SHARING_MODE_EXCLUSIVE, | 134 sharingMode: VK_SHARING_MODE_EXCLUSIVE, |
139 samples: samples, | 135 samples: samples, |
140 ) | 136 ) |
141 checkVkResult vkCreateImage(vulkan.device, addr imageInfo, nil, addr(result)) | 137 checkVkResult vkCreateImage(vulkan.device, addr imageInfo, nil, addr(result)) |
142 | 138 |
143 proc svkCreate2DImageView(image: VkImage, format: VkFormat): VkImageView = | 139 proc svkCreate2DImageView*(image: VkImage, format: VkFormat, aspect = VK_IMAGE_ASPECT_COLOR_BIT): VkImageView = |
144 var createInfo = VkImageViewCreateInfo( | 140 var createInfo = VkImageViewCreateInfo( |
145 sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, | 141 sType: VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, |
146 image: image, | 142 image: image, |
147 viewType: VK_IMAGE_VIEW_TYPE_2D, | 143 viewType: VK_IMAGE_VIEW_TYPE_2D, |
148 format: format, | 144 format: format, |
151 g: VK_COMPONENT_SWIZZLE_IDENTITY, | 147 g: VK_COMPONENT_SWIZZLE_IDENTITY, |
152 b: VK_COMPONENT_SWIZZLE_IDENTITY, | 148 b: VK_COMPONENT_SWIZZLE_IDENTITY, |
153 a: VK_COMPONENT_SWIZZLE_IDENTITY, | 149 a: VK_COMPONENT_SWIZZLE_IDENTITY, |
154 ), | 150 ), |
155 subresourceRange: VkImageSubresourceRange( | 151 subresourceRange: VkImageSubresourceRange( |
156 aspectMask: VkImageAspectFlags(VK_IMAGE_ASPECT_COLOR_BIT), | 152 aspectMask: toBits [aspect], |
157 baseMipLevel: 0, | 153 baseMipLevel: 0, |
158 levelCount: 1, | 154 levelCount: 1, |
159 baseArrayLayer: 0, | 155 baseArrayLayer: 0, |
160 layerCount: 1, | 156 layerCount: 1, |
161 ), | 157 ), |
227 | 223 |
228 | 224 |
229 proc svkCreateRenderPass( | 225 proc svkCreateRenderPass( |
230 attachments: openArray[VkAttachmentDescription], | 226 attachments: openArray[VkAttachmentDescription], |
231 colorAttachments: openArray[VkAttachmentReference], | 227 colorAttachments: openArray[VkAttachmentReference], |
228 depthAttachments: openArray[VkAttachmentReference], | |
232 resolveAttachments: openArray[VkAttachmentReference], | 229 resolveAttachments: openArray[VkAttachmentReference], |
233 dependencies: openArray[VkSubpassDependency], | 230 dependencies: openArray[VkSubpassDependency], |
234 ): VkRenderPass = | 231 ): VkRenderPass = |
235 assert colorAttachments.len == resolveAttachments.len or resolveAttachments.len == 0 | 232 assert colorAttachments.len == resolveAttachments.len or resolveAttachments.len == 0 |
236 var subpass = VkSubpassDescription( | 233 var subpass = VkSubpassDescription( |
239 inputAttachmentCount: 0, | 236 inputAttachmentCount: 0, |
240 pInputAttachments: nil, | 237 pInputAttachments: nil, |
241 colorAttachmentCount: colorAttachments.len.uint32, | 238 colorAttachmentCount: colorAttachments.len.uint32, |
242 pColorAttachments: colorAttachments.ToCPointer, | 239 pColorAttachments: colorAttachments.ToCPointer, |
243 pResolveAttachments: resolveAttachments.ToCPointer, | 240 pResolveAttachments: resolveAttachments.ToCPointer, |
244 pDepthStencilAttachment: nil, | 241 pDepthStencilAttachment: depthAttachments.ToCPointer, |
245 preserveAttachmentCount: 0, | 242 preserveAttachmentCount: 0, |
246 pPreserveAttachments: nil, | 243 pPreserveAttachments: nil, |
247 ) | 244 ) |
248 var createInfo = VkRenderPassCreateInfo( | 245 var createInfo = VkRenderPassCreateInfo( |
249 sType: VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, | 246 sType: VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, |