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