Mercurial > games > semicongine
annotate src/vulkan_helpers.nim @ 469:ed49f1cdd8b7
add: a few missing changes
| author | Sam <sam@basx.dev> |
|---|---|
| date | Thu, 22 Dec 2022 19:35:54 +0700 |
| parents | 1dd9e2393a9e |
| children | 0660ba9d1930 |
| rev | line source |
|---|---|
| 462 | 1 import std/tables |
| 461 | 2 import std/strutils |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
3 import std/strformat |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
4 import std/logging |
| 462 | 5 |
| 6 import ./glslang/glslang | |
| 7 import ./vulkan | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
8 import ./window |
| 462 | 9 |
| 461 | 10 when defined(release): |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
11 const ENABLEVULKANVALIDATIONLAYERS* = false |
| 461 | 12 else: |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
13 const ENABLEVULKANVALIDATIONLAYERS* = true |
| 461 | 14 |
| 15 | |
| 16 template checkVkResult*(call: untyped) = | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
17 when defined(release): |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
18 discard call |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
19 else: |
|
465
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
20 debug(&"CALLING vulkan: {astToStr(call)}") |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
21 let value = call |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
22 if value != VK_SUCCESS: |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
23 raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) |
| 461 | 24 |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
25 func addrOrNil[T](obj: var openArray[T]): ptr T = |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
26 if obj.len > 0: addr(obj[0]) else: nil |
| 461 | 27 |
| 28 proc VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = | |
| 29 (variant shl 29) or (major shl 22) or (minor shl 12) or patch | |
| 30 | |
| 462 | 31 |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
32 proc filterForSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): seq[VkSurfaceFormatKHR] = |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
33 for format in formats: |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
34 if format.format == VK_FORMAT_B8G8R8A8_SRGB and format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
35 result.add(format) |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
36 |
|
465
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
37 proc getSuitableSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): VkSurfaceFormatKHR = |
|
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
38 let usableSurfaceFormats = filterForSurfaceFormat(formats) |
|
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
39 if len(usableSurfaceFormats) == 0: |
|
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
40 raise newException(Exception, "No suitable surface formats found") |
|
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
41 return usableSurfaceFormats[0] |
|
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
42 |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
43 |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
44 proc cleanString*(str: openArray[char]): string = |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
45 for i in 0 ..< len(str): |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
46 if str[i] == char(0): |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
47 result = join(str[0 ..< i]) |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
48 break |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
49 |
| 461 | 50 proc getInstanceExtensions*(): seq[string] = |
| 51 var extensionCount: uint32 | |
| 52 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), nil) | |
| 53 var extensions = newSeq[VkExtensionProperties](extensionCount) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
54 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), addrOrNil(extensions)) |
| 461 | 55 |
| 56 for extension in extensions: | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
57 result.add(cleanString(extension.extensionName)) |
| 461 | 58 |
| 59 | |
| 60 proc getDeviceExtensions*(device: VkPhysicalDevice): seq[string] = | |
| 61 var extensionCount: uint32 | |
| 62 checkVkResult vkEnumerateDeviceExtensionProperties(device, nil, addr(extensionCount), nil) | |
| 63 var extensions = newSeq[VkExtensionProperties](extensionCount) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
64 checkVkResult vkEnumerateDeviceExtensionProperties(device, nil, addr(extensionCount), addrOrNil(extensions)) |
| 461 | 65 |
| 66 for extension in extensions: | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
67 result.add(cleanString(extension.extensionName)) |
| 461 | 68 |
| 69 | |
| 70 proc getValidationLayers*(): seq[string] = | |
| 71 var n_layers: uint32 | |
| 72 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), nil) | |
| 73 var layers = newSeq[VkLayerProperties](n_layers) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
74 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), addrOrNil(layers)) |
| 461 | 75 |
| 76 for layer in layers: | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
77 result.add(cleanString(layer.layerName)) |
| 461 | 78 |
| 79 | |
| 80 proc getVulkanPhysicalDevices*(instance: VkInstance): seq[VkPhysicalDevice] = | |
| 81 var n_devices: uint32 | |
| 82 checkVkResult vkEnumeratePhysicalDevices(instance, addr(n_devices), nil) | |
| 83 result = newSeq[VkPhysicalDevice](n_devices) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
84 checkVkResult vkEnumeratePhysicalDevices(instance, addr(n_devices), addrOrNil(result)) |
| 461 | 85 |
| 86 | |
| 87 proc getQueueFamilies*(device: VkPhysicalDevice): seq[VkQueueFamilyProperties] = | |
| 88 var n_queuefamilies: uint32 | |
| 89 vkGetPhysicalDeviceQueueFamilyProperties(device, addr(n_queuefamilies), nil) | |
| 90 result = newSeq[VkQueueFamilyProperties](n_queuefamilies) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
91 vkGetPhysicalDeviceQueueFamilyProperties(device, addr(n_queuefamilies), addrOrNil(result)) |
| 461 | 92 |
| 93 | |
| 94 proc getDeviceSurfaceFormats*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkSurfaceFormatKHR] = | |
| 95 var n_formats: uint32 | |
| 96 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), nil); | |
| 97 result = newSeq[VkSurfaceFormatKHR](n_formats) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
98 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), addrOrNil(result)) |
| 461 | 99 |
| 100 | |
| 101 proc getDeviceSurfacePresentModes*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkPresentModeKHR] = | |
| 102 var n_modes: uint32 | |
| 103 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), nil); | |
| 104 result = newSeq[VkPresentModeKHR](n_modes) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
105 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), addrOrNil(result)) |
| 461 | 106 |
| 107 | |
| 108 proc getSwapChainImages*(device: VkDevice, swapChain: VkSwapchainKHR): seq[VkImage] = | |
| 109 var n_images: uint32 | |
| 110 checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), nil); | |
| 111 result = newSeq[VkImage](n_images) | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
112 checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), addrOrNil(result)); |
| 461 | 113 |
| 114 | |
| 115 proc getPresentMode*(modes: seq[VkPresentModeKHR]): VkPresentModeKHR = | |
| 116 let preferredModes = [ | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
117 VK_PRESENT_MODE_MAILBOX_KHR, # triple buffering |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
118 VK_PRESENT_MODE_FIFO_RELAXED_KHR, # double duffering |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
119 VK_PRESENT_MODE_FIFO_KHR, # double duffering |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
120 VK_PRESENT_MODE_IMMEDIATE_KHR, # single buffering |
| 461 | 121 ] |
| 122 for preferredMode in preferredModes: | |
| 123 for mode in modes: | |
| 124 if preferredMode == mode: | |
| 125 return mode | |
| 126 # should never be reached, but seems to be garuanteed by vulkan specs to always be available | |
| 127 return VK_PRESENT_MODE_FIFO_KHR | |
| 128 | |
| 129 | |
| 130 proc createVulkanInstance*(vulkanVersion: uint32): VkInstance = | |
| 131 var requiredExtensions = [ | |
| 132 "VK_EXT_acquire_xlib_display".cstring, | |
| 133 "VK_EXT_direct_mode_display".cstring, | |
| 134 "VK_KHR_display".cstring, | |
| 135 "VK_KHR_surface".cstring, | |
| 136 "VK_KHR_xlib_surface".cstring, | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
137 "VK_EXT_debug_utils".cstring, |
| 461 | 138 ] |
| 139 let availableExtensions = getInstanceExtensions() | |
| 140 for extension in requiredExtensions: | |
| 141 assert $extension in availableExtensions | |
| 142 | |
| 143 let desiredLayers = ["VK_LAYER_KHRONOS_validation".cstring, "VK_LAYER_MESA_overlay".cstring] | |
| 144 let availableLayers = getValidationLayers() | |
| 145 var usableLayers = newSeq[cstring]() | |
| 146 | |
| 147 when ENABLEVULKANVALIDATIONLAYERS: | |
| 148 for layer in desiredLayers: | |
| 149 if $layer in availableLayers: | |
| 150 usableLayers.add(layer) | |
| 151 | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
152 echo "Available validation layers: ", availableLayers |
| 461 | 153 echo "Using validation layers: ", usableLayers |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
154 echo "Available extensions: ", availableExtensions |
| 461 | 155 echo "Using extensions: ", requiredExtensions |
| 156 | |
| 157 var appinfo = VkApplicationInfo( | |
| 158 sType: VK_STRUCTURE_TYPE_APPLICATION_INFO, | |
| 159 pApplicationName: "Hello Triangle", | |
| 160 pEngineName: "Custom engine", | |
| 161 apiVersion: vulkanVersion, | |
| 162 ) | |
| 163 var createinfo = VkInstanceCreateInfo( | |
| 164 sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, | |
| 165 pApplicationInfo: addr(appinfo), | |
| 166 enabledLayerCount: usableLayers.len.uint32, | |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
167 ppEnabledLayerNames: cast[ptr UncheckedArray[cstring]](addrOrNil(usableLayers)), |
| 461 | 168 enabledExtensionCount: requiredExtensions.len.uint32, |
| 169 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions)) | |
| 170 ) | |
| 171 checkVkResult vkCreateInstance(addr(createinfo), nil, addr(result)) | |
| 172 | |
| 173 loadVK_KHR_surface() | |
| 174 loadVK_KHR_xlib_surface() | |
| 175 loadVK_KHR_swapchain() | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
176 when ENABLEVULKANVALIDATIONLAYERS: |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
177 loadVK_EXT_debug_utils(result) |
| 461 | 178 |
| 179 | |
| 180 proc getVulcanDevice*( | |
| 181 physicalDevice: var VkPhysicalDevice, | |
| 182 features: var VkPhysicalDeviceFeatures, | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
183 graphicsQueueFamily: uint32, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
184 presentationQueueFamily: uint32, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
185 ): (VkDevice, VkQueue, VkQueue) = |
| 461 | 186 # setup queue and device |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
187 # TODO: need check this, possibly wrong logic, see Vulkan tutorial |
| 461 | 188 var priority = 1.0'f32 |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
189 var queueCreateInfo = [ |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
190 VkDeviceQueueCreateInfo( |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
191 sType: VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
192 queueFamilyIndex: graphicsQueueFamily, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
193 queueCount: 1, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
194 pQueuePriorities: addr(priority), |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
195 ), |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
196 ] |
| 461 | 197 |
| 198 var requiredExtensions = ["VK_KHR_swapchain".cstring] | |
| 199 var deviceCreateInfo = VkDeviceCreateInfo( | |
| 200 sType: VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
201 queueCreateInfoCount: uint32(queueCreateInfo.len), |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
202 pQueueCreateInfos: addrOrNil(queueCreateInfo), |
| 461 | 203 pEnabledFeatures: addr(features), |
| 204 enabledExtensionCount: requiredExtensions.len.uint32, | |
| 205 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions)) | |
| 206 ) | |
| 207 checkVkResult vkCreateDevice(physicalDevice, addr(deviceCreateInfo), nil, addr(result[0])) | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
208 vkGetDeviceQueue(result[0], graphicsQueueFamily, 0'u32, addr(result[1])); |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
209 vkGetDeviceQueue(result[0], presentationQueueFamily, 0'u32, addr(result[2])); |
| 462 | 210 |
| 211 proc createShaderStage*(device: VkDevice, stage: VkShaderStageFlagBits, shader: string): VkPipelineShaderStageCreateInfo = | |
| 212 const VK_GLSL_MAP = { | |
| 213 VK_SHADER_STAGE_VERTEX_BIT: GLSLANG_STAGE_VERTEX, | |
| 214 VK_SHADER_STAGE_FRAGMENT_BIT: GLSLANG_STAGE_FRAGMENT, | |
| 215 }.toTable() | |
| 216 var code = compileGLSLToSPIRV(VK_GLSL_MAP[stage], shader, "<memory-shader>") | |
| 217 var createInfo = VkShaderModuleCreateInfo( | |
| 218 sType: VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
219 codeSize: uint(code.len * sizeof(uint32)), |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
220 pCode: addrOrNil(code), |
| 462 | 221 ) |
| 222 var shaderModule: VkShaderModule | |
| 223 checkVkResult vkCreateShaderModule(device, addr(createInfo), nil, addr(shaderModule)) | |
| 224 | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
225 return VkPipelineShaderStageCreateInfo( |
| 462 | 226 sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 227 stage: stage, | |
| 228 module: shaderModule, | |
| 229 pName: "main", # entry point for shader | |
| 230 ) | |
|
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
231 |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
232 proc debugCallback*( |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
233 messageSeverity: VkDebugUtilsMessageSeverityFlagBitsEXT, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
234 messageTypes: VkDebugUtilsMessageTypeFlagsEXT, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
235 pCallbackData: VkDebugUtilsMessengerCallbackDataEXT, |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
236 userData: pointer |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
237 ): VkBool32 {.cdecl.} = |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
238 echo &"{messageSeverity}: {VkDebugUtilsMessageTypeFlagBitsEXT(messageTypes)}: {pCallbackData.pMessage}" |
|
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
239 return VK_FALSE |
|
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
240 |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
241 proc getSurfaceCapabilities*(device: VkPhysicalDevice, surface: VkSurfaceKHR): VkSurfaceCapabilitiesKHR = |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
242 checkVkResult device.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(surface, addr(result)) |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
243 |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
244 when defined(linux): |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
245 proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
246 var surfaceCreateInfo = VkXlibSurfaceCreateInfoKHR( |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
247 sType: VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
248 dpy: window.display, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
249 window: window.window, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
250 ) |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
251 checkVkResult vkCreateXlibSurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
252 when defined(windows): |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
253 proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
254 var surfaceCreateInfo = VkWin32SurfaceCreateInfoKHR( |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
255 sType: VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
256 hinstance: window.hinstance, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
257 hwnd: window.hwnd, |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
258 ) |
|
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
259 checkVkResult vkCreateWin32SurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) |
