Mercurial > games > semicongine
annotate svk/generate.nim @ 1485:6e062a84c157 default tip
add: more api-starting
author | sam <sam@basx.dev> |
---|---|
date | Sat, 03 May 2025 01:03:01 +0700 |
parents | a2af327f19df |
children |
rev | line source |
---|---|
1479 | 1 import std/strtabs |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
2 import std/syncio |
1479 | 3 import std/xmltree |
4 import std/tables | |
5 import std/options | |
6 import std/sequtils | |
7 import std/strutils | |
8 import std/strformat | |
9 import std/xmlparser | |
10 import std/os | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
11 import std/osproc |
1479 | 12 import std/paths |
13 | |
14 # helpers | |
15 func smartParseInt(value: string): int = | |
16 if value.startsWith("0x"): | |
17 parseHexInt(value) | |
18 else: | |
19 parseInt(value) | |
20 | |
21 const TYPEMAP = { | |
22 "void": "void", | |
23 "char": "char", | |
24 "float": "float32", | |
25 "double": "float64", | |
26 "int8_t": "int8", | |
27 "uint8_t": "uint8", | |
28 "int16_t": "int16", | |
29 "uint16_t": "uint16", | |
30 "int32_t": "int32", | |
31 "uint32_t": "uint32", | |
32 "uint64_t": "uint64", | |
33 "int64_t": "int64", | |
34 "size_t": "csize_t", | |
35 "int": "cint", | |
36 }.toTable | |
37 # load xml | |
38 let xml = (system.currentSourcePath.parentDir() / "vk.xml").loadXml() | |
39 let platforms = xml.findAll("platforms")[0] | |
40 let types = xml.findAll("types")[0] | |
41 let xmlenums = xml.findAll("enums") | |
42 let commands = xml.findAll("commands")[0] | |
43 let features = xml.findAll("feature") # features has extends="<ENUM>" | |
44 let extensions = xml.findAll("extensions")[0] # extensions has extends="<ENUM>" | |
45 let formats = xml.findAll("formats")[0] | |
46 | |
47 # gather all enums | |
48 | |
49 type | |
50 EnumEntry = object | |
51 name: string | |
52 value: string | |
53 | |
54 EnumDef = object | |
55 name: string | |
56 values: seq[EnumEntry] | |
57 isBitmask: bool | |
58 | |
59 ConstantDef = object | |
60 name: string | |
61 datatype: string | |
62 value: string | |
63 | |
64 var consts: seq[ConstantDef] | |
65 var enums: Table[string, EnumDef] | |
66 | |
67 func addValue(edef: var EnumDef, n: XmlNode) = | |
68 if n.attr("deprecated") != "aliased" and n.attr("alias") == "": | |
69 if n.attr("name") in edef.values.mapIt(it.name): | |
70 return | |
71 | |
72 var value = "" | |
73 if n.attr("value") != "": | |
74 value = n.attr("value") | |
75 elif n.attr("bitpos") != "": | |
76 value = $(1 shl parseInt(n.attr("bitpos"))) | |
77 elif n.attr("offset") != "": | |
78 var enumBase = 1000000000 | |
79 if n.attr("extnumber") != "": | |
80 enumBase += (smartParseInt(n.attr("extnumber")) - 1) * 1000 | |
81 var v = smartParseInt(n.attr("offset")) + enumBase | |
82 if n.attr("dir") == "-": | |
83 v = -v | |
84 value = $(v) | |
85 | |
1482 | 86 if value notin edef.values.mapIt(it.value): |
87 edef.values.add EnumEntry(name: n.attr("name"), value: value) | |
1479 | 88 |
1484 | 89 func doTypename(typename: string, pointerType: int): string = |
90 ## pointerType == 0: no pointer | |
91 ## pointerType == 1: normal pointer (e.g. char *) | |
92 ## pointerType == 2: double pointer (e.g. void **) | |
93 assert pointerType in [0, 1, 2] | |
1481 | 94 result = TYPEMAP.getOrDefault(typename.strip(), typename.strip()).strip(chars = {'_'}) |
95 | |
96 if typename == "void": | |
1484 | 97 assert pointerType > 0 |
1481 | 98 |
1484 | 99 if pointerType > 0: |
1481 | 100 if typename == "void": |
101 result = "pointer" | |
102 elif typename == "char": | |
1485 | 103 if pointerType == 1: |
104 result = "cstring" | |
105 elif pointerType == 2: | |
106 result = "cstringArray" | |
107 else: | |
108 assert false, "Unsupported char pointer type" | |
1481 | 109 else: |
110 result = "ptr " & result | |
1485 | 111 |
112 if pointerType == 2 and typename != "char": | |
1484 | 113 result = "ptr " & result |
1481 | 114 |
115 func doIdentifier(typename: string): string = | |
116 if typename in ["type", "object"]: | |
117 return &"`{typename}`" | |
118 return typename.strip() | |
119 | |
1484 | 120 func doMember(typename, theType: string, pointerType: int, value: string): string = |
1481 | 121 if value == "": |
1484 | 122 &"{doIdentifier(typename)}: {doTypename(theType, pointerType)}" |
1481 | 123 else: |
1484 | 124 &"{doIdentifier(typename)}: {doTypename(theType, pointerType)} = {value}" |
1481 | 125 |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
126 func memberDecl(n: XmlNode): string = |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
127 for i in 0 ..< n.len: |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
128 if n[i].kind == xnElement and n[i].tag == "comment": |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
129 n.delete(i) |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
130 break |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
131 assert n.tag == "member" |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
132 if n.len == 2: |
1484 | 133 return doMember(n[1][0].text, n[0][0].text, 0, n.attr("values")) |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
134 elif n.len == 3: |
1481 | 135 assert "*" notin n[0][0].text.strip() |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
136 if n[1].kind == xnElement and n[1].tag == "name": |
1481 | 137 # bitfield |
138 if n[2].text.strip().startsWith(":"): | |
139 return | |
1484 | 140 &"{doIdentifier(n[1][0].text)} {{.bitsize:{n[2].text.strip()[1 .. ^1]}.}}: {doTypename(n[0][0].text, 0)}" |
1481 | 141 # array definition |
142 elif n[2].text.strip().startsWith("["): | |
143 let arrayDim = n[2].text[1 ..< ^1] | |
144 if "][" in arrayDim: | |
145 let dims = arrayDim.split("][", 1) | |
146 let (dim1, dim2) = (dims[0], dims[1]) | |
147 return doMember( | |
148 n[1][0].text, | |
1484 | 149 &"array[{dim1}, array[{dim2}, {doTypename(n[0][0].text, 0)}]]", |
150 0, | |
1481 | 151 n.attr("values"), |
152 ) | |
153 else: | |
154 return doMember( | |
155 n[1][0].text, | |
1484 | 156 &"array[{arrayDim}, {doTypename(n[0][0].text, 0)}]", |
157 0, | |
1481 | 158 n.attr("values"), |
159 ) | |
160 else: | |
161 debugecho n.toSeq | |
162 doAssert false, "This should not happen" | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
163 else: |
1481 | 164 # pointer definition |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
165 assert n[1].text.strip() == "*" |
1484 | 166 return doMember(n[2][0].text, n[0][0].text, 1, n.attr("values")) |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
167 elif n.len == 4: |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
168 if n[0].text.strip() in ["struct", "const struct"]: |
1484 | 169 return doMember(n[3][0].text, n[1][0].text, 1, n.attr("values")) |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
170 else: |
1481 | 171 assert n[0].text.strip() == "const" # can be ignored |
172 assert n[1].tag == "type" | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
173 assert n[2].text.strip() in ["*", "* const *", "* const*"] |
1481 | 174 assert n[3].tag == "name" |
175 assert n[1].len == 1 | |
176 assert n[3].len == 1 | |
1485 | 177 return doMember( |
178 n[3][0].text, n[1][0].text, n[2].text.strip().count("*"), n.attr("values") | |
179 ) | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
180 elif n.len in [5, 6]: |
1481 | 181 # array definition, using const-value for array length |
182 # <type>uint8_t</type>,<name>pipelineCacheUUID</name>[<enum>VK_UUID_SIZE</enum>] | |
183 assert n[2].text.strip() == "[" | |
184 assert n[4].text.strip() == "]" | |
185 return doMember( | |
186 n[1][0].text, | |
1484 | 187 &"array[{n[3][0].text}, {doTypename(n[0][0].text, 0)}]", |
188 0, | |
1481 | 189 n.attr("values"), |
190 ) | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
191 assert false |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
192 |
1479 | 193 for e in xmlenums: |
194 if e.attr("type") == "constants": | |
195 for c in e.findAll("enum"): | |
196 var value = c.attr("value").strip(chars = {'(', ')'}) | |
197 consts.add ConstantDef( | |
198 name: c.attr("name"), datatype: TYPEMAP[c.attr("type")], value: value | |
199 ) | |
200 elif e.attr("type") == "enum": | |
201 var edef = EnumDef(name: e.attr("name"), isBitmask: false) | |
202 for ee in e.findAll("enum"): | |
203 edef.addValue(ee) | |
204 enums[edef.name] = edef | |
205 elif e.attr("type") == "bitmask": | |
206 var edef = EnumDef(name: e.attr("name"), isBitmask: true) | |
207 for ee in e.findAll("enum"): | |
208 edef.addValue(ee) | |
209 enums[edef.name] = edef | |
210 | |
211 for f in features: | |
212 for extendenum in f.findAll("enum"): | |
213 if extendenum.attr("extends") != "": | |
214 enums[extendenum.attr("extends")].addValue(extendenum) | |
215 | |
216 for extension in extensions.findAll("extension"): | |
217 let extNum = extension.attr("number") | |
218 for extendenum in extension.findAll("enum"): | |
219 if extendenum.attr("extends") != "": | |
220 if extendenum.attr("extnumber") == "": | |
221 extendenum.attrs["extnumber"] = extNum | |
222 enums[extendenum.attr("extends")].addValue(extendenum) | |
223 | |
1481 | 224 let outPath = (system.currentSourcePath.parentDir() / "vkapi.nim") |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
225 let outFile = open(outPath, fmWrite) |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
226 |
1479 | 227 # generate core types =============================================================================== |
228 # preamble, much easier to hardcode than to generate from xml | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
229 outFile.writeLine """ |
1481 | 230 |
1484 | 231 import std/dynlib |
232 | |
1481 | 233 import ../semicongine/thirdparty/winim/winim/inc/winbase |
234 import ../semicongine/thirdparty/winim/winim/inc/windef | |
235 import ../semicongine/thirdparty/x11/xlib | |
236 import ../semicongine/thirdparty/x11/x | |
237 import ../semicongine/thirdparty/x11/xrandr | |
238 | |
1479 | 239 func VK_MAKE_API_VERSION*( |
240 variant: uint32, major: uint32, minor: uint32, patch: uint32 | |
1485 | 241 ): uint32 = |
1479 | 242 (variant shl 29) or (major shl 22) or (minor shl 12) or patch |
243 """ | |
244 | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
245 outFile.writeLine "type" |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
246 outFile.writeLine """ |
1481 | 247 # some unused native types |
248 # | |
249 # android | |
250 ANativeWindow = object | |
251 AHardwareBuffer = object | |
252 | |
1483 | 253 # apple/metal |
1481 | 254 CAMetalLayer = object |
255 MTLSharedEvent_id = object | |
1483 | 256 MTLDevice_id = object |
257 MTLCommandQueue_id = object | |
258 MTLBuffer_id = object | |
259 MTLTexture_id = object | |
260 IOSurfaceRef = object | |
1481 | 261 |
262 # wayland | |
263 wl_display = object | |
264 wl_surface = object | |
265 | |
266 # XCB | |
267 xcb_connection_t = object | |
268 xcb_window_t = object | |
269 xcb_visualid_t = object | |
270 | |
271 # directfb | |
272 IDirectFB = object | |
273 IDirectFBSurface = object | |
274 | |
275 # Zircon | |
276 zx_handle_t = object | |
277 | |
278 # GGP C | |
279 GgpStreamDescriptor = object | |
280 GgpFrameToken = object | |
281 | |
282 # Screen (nintendo switch?) | |
283 screen_context = object | |
284 screen_window = object | |
285 screen_buffer = object | |
286 | |
287 # Nvidia | |
288 NvSciSyncAttrList = object | |
289 NvSciSyncObj = object | |
290 NvSciSyncFence = object | |
291 NvSciBufAttrList = object | |
292 NvSciBufObj = object | |
293 | |
294 # some base vulkan base types | |
1483 | 295 VkSampleMask* = distinct uint32 |
296 VkBool32* = distinct uint32 | |
297 VkFlags* = distinct uint32 | |
298 VkFlags64* = distinct uint64 | |
299 VkDeviceSize* = distinct uint64 | |
300 VkDeviceAddress* = distinct uint64 | |
301 VkRemoteAddressNV* = pointer | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
302 """ |
1479 | 303 |
304 # generate consts =============================================================================== | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
305 outFile.writeLine "const" |
1479 | 306 for c in consts: |
307 var value = c.value | |
308 if value.endsWith("U"): | |
309 value = value[0 ..^ 2] & "'u32" | |
310 elif value.endsWith("ULL"): | |
311 value = value[0 ..^ 4] & "'u64" | |
312 if value[0] == '~': | |
313 value = "not " & value[1 ..^ 1] | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
314 outFile.writeLine &" {c.name}*: {c.datatype} = {value}" |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
315 outFile.writeLine "" |
1479 | 316 |
317 # generate enums =============================================================================== | |
1481 | 318 const nameCollisions = [ |
319 "VK_PIPELINE_CACHE_HEADER_VERSION_ONE", | |
320 "VK_PIPELINE_CACHE_HEADER_VERSION_SAFETY_CRITICAL_ONE", | |
321 "VK_DEVICE_FAULT_VENDOR_BINARY_HEADER_VERSION_ONE_EXT", | |
322 ] | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
323 outFile.writeLine "type" |
1482 | 324 |
1479 | 325 for edef in enums.values(): |
326 if edef.values.len > 0: | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
327 outFile.writeLine &" {edef.name}* {{.size: 4.}} = enum" |
1479 | 328 for ee in edef.values: |
1481 | 329 # due to the nim identifier-system, there might be collisions between typenames and enum-member names |
330 if ee.name in nameCollisions: | |
331 outFile.writeLine &" {ee.name}_VALUE = {ee.value}" | |
332 else: | |
333 outFile.writeLine &" {ee.name} = {ee.value}" | |
334 | |
335 outFile.writeLine "" | |
336 | |
337 # generate types =============================================================================== | |
338 for t in types: | |
339 let category = t.attr("category") | |
1483 | 340 let tName = t.attr("name") |
341 if tName.startsWith("VkVideo"): # we are not doing the video API, sorry | |
342 continue | |
343 if tName.startsWith("VkPhysicalDeviceVideo"): # we are not doing the video API, sorry | |
344 continue | |
1481 | 345 if t.attr("api") == "vulkansc": |
346 continue | |
347 elif t.attr("deprecated") == "true": | |
348 continue | |
349 elif category == "include": | |
350 continue | |
351 elif category == "define": | |
352 continue | |
353 elif t.attr("requires").startsWith("vk_video"): | |
354 continue | |
355 elif t.attr("alias") != "": | |
356 let a = t.attr("alias") | |
1483 | 357 outFile.writeLine &" {tName}* = {a}" |
1481 | 358 elif category == "bitmask": |
359 if t.len > 0 and t[0].text.startsWith("typedef"): | |
1483 | 360 outFile.writeLine &" {t[2][0].text}* = distinct {t[1][0].text}" |
1481 | 361 elif category == "union": |
1483 | 362 outFile.writeLine &" {tName}* {{.union.}} = object" |
1481 | 363 for member in t.findAll("member"): |
364 outFile.writeLine &" {member.memberDecl()}" | |
365 elif category == "handle": | |
1484 | 366 outFile.writeLine &" {t[2][0].text} = distinct pointer" |
1481 | 367 elif category == "struct": |
1483 | 368 outFile.writeLine &" {tName}* = object" |
1481 | 369 for member in t.findAll("member"): |
370 if member.attr("api") == "vulkansc": | |
371 continue | |
372 outFile.writeLine &" {member.memberDecl()}" | |
373 elif category == "funcpointer": | |
374 assert t[0].text.startsWith("typedef ") | |
1483 | 375 let retName = t[0].text[8 ..< ^13].strip() |
376 let funcName = t.findAll("name")[0][0].text | |
377 | |
378 outFile.write &" {funcname}* = proc(" | |
1484 | 379 let nParams = (t.len - 3) div 2 |
380 for i in 0 ..< nParams: | |
381 assert t[i * 2 + 3].tag == "type" | |
382 let typename = t[i * 2 + 3][0].text.strip() | |
383 var identifier = t[i * 2 + 4].text.strip(chars = {' ', ')', ';', ',', '\n'}) | |
384 var pointerType = if identifier.startsWith("*"): 1 else: 0 | |
385 if pointerType > 0: | |
386 identifier = identifier[1 .. ^1].strip(chars = {' ', ')', ';', ',', '\n'}) | |
387 if identifier.endsWith("const"): | |
388 identifier = identifier[0 .. ^6].strip(chars = {' ', ')', ';', ',', '\n'}) | |
389 identifier = identifier.strip(chars = {','}) | |
390 outFile.write &"{doIdentifier(identifier)}: {doTypename(typename, pointerType)}, " | |
1483 | 391 |
1484 | 392 if retName == "void": |
1483 | 393 outFile.writeLine &") {{.cdecl.}}" |
1484 | 394 elif retName == "void*": |
1483 | 395 outFile.writeLine &"): pointer {{.cdecl.}}" |
396 else: | |
1484 | 397 outFile.writeLine &"): {doTypename(retName, 0)} {{.cdecl.}}" |
1481 | 398 else: |
399 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category | |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
400 outFile.writeLine "" |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
401 |
1483 | 402 for command in commands: |
403 if command.attr("api") == "vulkansc": | |
404 continue | |
405 if command.attr("alias") != "": | |
406 let funcName = command.attr("name") | |
407 let funcAlias = command.attr("alias") | |
1485 | 408 outFile.write &"var {funcName}* = {funcAlias}\n" |
1483 | 409 continue |
410 | |
411 let proto = command.findAll("proto")[0] | |
412 let retType = proto.findAll("type")[0][0].text.strip() | |
413 let funcName = proto.findAll("name")[0][0].text.strip() | |
414 | |
415 if "Video" in funcName: # Video API not supported at this time | |
416 continue | |
417 | |
1485 | 418 outFile.write &"var {funcName}*: proc(" |
1483 | 419 for param in command: |
420 if param.tag != "param": | |
421 continue | |
422 if param.attr("api") == "vulkansc": | |
423 continue | |
424 assert param.len in [2, 3, 4] | |
425 let paramType = param.findAll("type")[0][0].text | |
426 let paramName = param.findAll("name")[0][0].text | |
427 assert "*" notin paramType, $param | |
1484 | 428 |
429 if param.len == 4: | |
430 param.delete(0) | |
431 | |
432 var pointerType = 0 | |
433 | |
434 if param.len == 3: | |
435 if param[param.len - 1].kind == xnText: | |
436 assert param[param.len - 1].text[^1] == ']' | |
437 else: | |
438 assert param[0].tag == "type" | |
439 assert param[param.len - 1].tag == "name" | |
440 if param[1].text.strip() == "*": | |
441 pointerType = 1 | |
442 elif param[1].text.strip() == "**": | |
443 pointerType = 2 | |
444 # echo "3: ", param[1].text, " ", paramType, " ", paramName | |
445 outFile.write &"{doIdentifier(paramName)}: {doTypename(paramType, pointerType)}, " | |
1483 | 446 |
447 outFile.write &")" | |
448 if retType != "void": | |
449 assert "*" notin retType | |
1484 | 450 outFile.write &": {doTypename(retType, 0)}" |
1483 | 451 outFile.write " {.stdcall.}\n" |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
452 |
1484 | 453 outFile.write """ |
454 when defined(linux): | |
455 let vulkanLib = loadLib("libvulkan.so.1") | |
456 when defined(windows): | |
457 let vulkanLib = loadLib("vulkan-1.dll") | |
458 if vulkanLib == nil: | |
459 raise newException(Exception, "Unable to load vulkan library") | |
460 | |
461 vkGetInstanceProcAddr = cast[proc(instance: VkInstance, pName: cstring, ): PFN_vkVoidFunction {.stdcall.}](checkedSymAddr(vulkanLib, "vkGetInstanceProcAddr")) | |
1485 | 462 |
463 proc loadFunc[T](instance: VkInstance, f: var T, name: string) = | |
464 f = cast[T](vkGetInstanceProcAddr(instance, name)) | |
465 | |
466 """ | |
467 | |
468 for f in features: | |
469 let name = f.attr("name").replace(",", "_") | |
470 if f.attr("struct") != "": | |
471 continue | |
472 outFile.writeLine &"proc loadFeature_{name}(instance: VkInstance) =" | |
473 var hasEntries = false | |
474 for cmd in f.findAll("command"): | |
475 hasEntries = true | |
476 let cName = cmd.attr("name") | |
477 outFile.writeLine &" loadFunc(instance, {cName}, \"{cName}\")" | |
478 if not hasEntries: | |
479 outFile.writeLine " discard" | |
480 outFile.writeLine "" | |
1484 | 481 |
1480
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
482 outFile.close() |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
483 |
0b302531f5c5
did: continue on vulkan nim api generator
sam <sam@basx.dev>
parents:
1479
diff
changeset
|
484 assert execCmd("nim c " & outPath) == 0 |