Mercurial > games > semicongine
annotate src/vulkan_helpers.nim @ 13:a571db114152
add: vector/matrix modules, tests, nim config script
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 28 Dec 2022 11:42:21 +0700 |
parents | 9e5fe647ff91 |
children | b40466fa446a |
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 ./glslang/glslang | |
8 import ./vulkan | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
9 import ./window |
1 | 10 |
10 | 11 |
12 const ENABLEVULKANVALIDATIONLAYERS* = not defined(release) | |
0 | 13 |
14 | |
15 template checkVkResult*(call: untyped) = | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
16 when defined(release): |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
17 discard call |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
18 else: |
10 | 19 debug "CALLING vulkan: ", astToStr(call) |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
20 let value = call |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
21 if value != VK_SUCCESS: |
10 | 22 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
|
23 raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) |
0 | 24 |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
25 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
|
26 if obj.len > 0: addr(obj[0]) else: nil |
0 | 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 | |
1 | 31 |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
32 proc filterForSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): seq[VkSurfaceFormatKHR] = |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
33 for format in formats: |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
34 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
|
35 result.add(format) |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
36 |
4
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
37 proc getSuitableSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): VkSurfaceFormatKHR = |
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
38 let usableSurfaceFormats = filterForSurfaceFormat(formats) |
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
39 if len(usableSurfaceFormats) == 0: |
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
40 raise newException(Exception, "No suitable surface formats found") |
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
41 return usableSurfaceFormats[0] |
af9183acb173
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
2
diff
changeset
|
42 |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
43 |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
44 proc cleanString*(str: openArray[char]): string = |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
45 for i in 0 ..< len(str): |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
46 if str[i] == char(0): |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
47 result = join(str[0 ..< i]) |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
48 break |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
49 |
0 | 50 proc getInstanceExtensions*(): seq[string] = |
51 var extensionCount: uint32 | |
52 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), nil) | |
53 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
|
54 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), addrOrNil(extensions)) |
0 | 55 |
56 for extension in extensions: | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
57 result.add(cleanString(extension.extensionName)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
64 checkVkResult vkEnumerateDeviceExtensionProperties(device, nil, addr(extensionCount), addrOrNil(extensions)) |
0 | 65 |
66 for extension in extensions: | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
67 result.add(cleanString(extension.extensionName)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
74 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), addrOrNil(layers)) |
0 | 75 |
76 for layer in layers: | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
77 result.add(cleanString(layer.layerName)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
84 checkVkResult vkEnumeratePhysicalDevices(instance, addr(n_devices), addrOrNil(result)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
91 vkGetPhysicalDeviceQueueFamilyProperties(device, addr(n_queuefamilies), addrOrNil(result)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
98 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), addrOrNil(result)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
105 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), addrOrNil(result)) |
0 | 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) | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
112 checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), addrOrNil(result)); |
0 | 113 |
114 | |
115 proc getPresentMode*(modes: seq[VkPresentModeKHR]): VkPresentModeKHR = | |
116 let preferredModes = [ | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 VK_PRESENT_MODE_IMMEDIATE_KHR, # single buffering |
0 | 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 = | |
10 | 131 |
12 | 132 var requiredExtensions = @["VK_KHR_surface".cstring] |
10 | 133 when defined(linux): |
12 | 134 requiredExtensions.add("VK_KHR_xlib_surface".cstring) |
10 | 135 when defined(windows): |
12 | 136 requiredExtensions.add("VK_KHR_win32_surface".cstring) |
137 when ENABLEVULKANVALIDATIONLAYERS: | |
138 requiredExtensions.add("VK_EXT_debug_utils".cstring) | |
10 | 139 |
0 | 140 let availableExtensions = getInstanceExtensions() |
141 for extension in requiredExtensions: | |
10 | 142 assert $extension in availableExtensions, $extension |
0 | 143 |
144 let availableLayers = getValidationLayers() | |
145 var usableLayers = newSeq[cstring]() | |
146 | |
147 when ENABLEVULKANVALIDATIONLAYERS: | |
12 | 148 const desiredLayers = ["VK_LAYER_KHRONOS_validation".cstring, "VK_LAYER_MESA_overlay".cstring] |
0 | 149 for layer in desiredLayers: |
150 if $layer in availableLayers: | |
151 usableLayers.add(layer) | |
152 | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
153 echo "Available validation layers: ", availableLayers |
0 | 154 echo "Using validation layers: ", usableLayers |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
155 echo "Available extensions: ", availableExtensions |
0 | 156 echo "Using extensions: ", requiredExtensions |
157 | |
158 var appinfo = VkApplicationInfo( | |
159 sType: VK_STRUCTURE_TYPE_APPLICATION_INFO, | |
160 pApplicationName: "Hello Triangle", | |
161 pEngineName: "Custom engine", | |
162 apiVersion: vulkanVersion, | |
163 ) | |
164 var createinfo = VkInstanceCreateInfo( | |
165 sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, | |
166 pApplicationInfo: addr(appinfo), | |
167 enabledLayerCount: usableLayers.len.uint32, | |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
168 ppEnabledLayerNames: cast[ptr UncheckedArray[cstring]](addrOrNil(usableLayers)), |
0 | 169 enabledExtensionCount: requiredExtensions.len.uint32, |
12 | 170 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions[0])) |
0 | 171 ) |
172 checkVkResult vkCreateInstance(addr(createinfo), nil, addr(result)) | |
173 | |
174 loadVK_KHR_surface() | |
10 | 175 when defined(linux): |
176 loadVK_KHR_xlib_surface() | |
177 when defined(windows): | |
178 loadVK_KHR_win32_surface() | |
0 | 179 loadVK_KHR_swapchain() |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
180 when ENABLEVULKANVALIDATIONLAYERS: |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
181 loadVK_EXT_debug_utils(result) |
0 | 182 |
183 | |
184 proc getVulcanDevice*( | |
185 physicalDevice: var VkPhysicalDevice, | |
186 features: var VkPhysicalDeviceFeatures, | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
187 graphicsQueueFamily: uint32, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
188 presentationQueueFamily: uint32, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
189 ): (VkDevice, VkQueue, VkQueue) = |
0 | 190 # setup queue and device |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
191 # TODO: need check this, possibly wrong logic, see Vulkan tutorial |
0 | 192 var priority = 1.0'f32 |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
193 var queueCreateInfo = [ |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
194 VkDeviceQueueCreateInfo( |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
195 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
|
196 queueFamilyIndex: graphicsQueueFamily, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
197 queueCount: 1, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
198 pQueuePriorities: addr(priority), |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
199 ), |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
200 ] |
0 | 201 |
202 var requiredExtensions = ["VK_KHR_swapchain".cstring] | |
203 var deviceCreateInfo = VkDeviceCreateInfo( | |
204 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
|
205 queueCreateInfoCount: uint32(queueCreateInfo.len), |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
206 pQueueCreateInfos: addrOrNil(queueCreateInfo), |
0 | 207 pEnabledFeatures: addr(features), |
208 enabledExtensionCount: requiredExtensions.len.uint32, | |
209 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions)) | |
210 ) | |
211 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
|
212 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
|
213 vkGetDeviceQueue(result[0], presentationQueueFamily, 0'u32, addr(result[2])); |
1 | 214 |
215 proc createShaderStage*(device: VkDevice, stage: VkShaderStageFlagBits, shader: string): VkPipelineShaderStageCreateInfo = | |
216 const VK_GLSL_MAP = { | |
217 VK_SHADER_STAGE_VERTEX_BIT: GLSLANG_STAGE_VERTEX, | |
218 VK_SHADER_STAGE_FRAGMENT_BIT: GLSLANG_STAGE_FRAGMENT, | |
219 }.toTable() | |
220 var code = compileGLSLToSPIRV(VK_GLSL_MAP[stage], shader, "<memory-shader>") | |
221 var createInfo = VkShaderModuleCreateInfo( | |
222 sType: VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
223 codeSize: uint(code.len * sizeof(uint32)), |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
224 pCode: addrOrNil(code), |
1 | 225 ) |
226 var shaderModule: VkShaderModule | |
227 checkVkResult vkCreateShaderModule(device, addr(createInfo), nil, addr(shaderModule)) | |
228 | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
229 return VkPipelineShaderStageCreateInfo( |
1 | 230 sType: VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
231 stage: stage, | |
232 module: shaderModule, | |
233 pName: "main", # entry point for shader | |
234 ) | |
2
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
235 |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
236 proc debugCallback*( |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
237 messageSeverity: VkDebugUtilsMessageSeverityFlagBitsEXT, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
238 messageTypes: VkDebugUtilsMessageTypeFlagsEXT, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
239 pCallbackData: VkDebugUtilsMessengerCallbackDataEXT, |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
240 userData: pointer |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
241 ): VkBool32 {.cdecl.} = |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
242 echo &"{messageSeverity}: {VkDebugUtilsMessageTypeFlagBitsEXT(messageTypes)}: {pCallbackData.pMessage}" |
213fdf8d31dd
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
1
diff
changeset
|
243 return VK_FALSE |
5
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
244 |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
245 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
|
246 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
|
247 |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
248 when defined(linux): |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
249 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
|
250 var surfaceCreateInfo = VkXlibSurfaceCreateInfoKHR( |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
251 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
|
252 dpy: window.display, |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
253 window: window.window, |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
254 ) |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
255 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
|
256 when defined(windows): |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
257 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
|
258 var surfaceCreateInfo = VkWin32SurfaceCreateInfoKHR( |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
259 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
|
260 hinstance: window.hinstance, |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
261 hwnd: window.hwnd, |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
262 ) |
4ed9cb098315
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
4
diff
changeset
|
263 checkVkResult vkCreateWin32SurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) |