Mercurial > games > semicongine
comparison src/vulkan_api/vulkan_api_generator.nim @ 81:fa1b6107deae
did: final cleanup for now
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 22 Feb 2023 18:36:01 +0700 |
parents | 637da715b604 |
children | 5e19aead2b61 |
comparison
equal
deleted
inserted
replaced
80:637da715b604 | 81:fa1b6107deae |
---|---|
7 import std/streams | 7 import std/streams |
8 import std/tables | 8 import std/tables |
9 import httpClient | 9 import httpClient |
10 import std/xmlparser | 10 import std/xmlparser |
11 import std/xmltree | 11 import std/xmltree |
12 | |
13 type | |
14 FileContent = seq[string] | |
15 | 12 |
16 const | 13 const |
17 TYPEMAP = { | 14 TYPEMAP = { |
18 "void": "void", | 15 "void": "void", |
19 "char": "char", | 16 "char": "char", |
309 a[k] = @[] | 306 a[k] = @[] |
310 a[k].add v | 307 a[k].add v |
311 | 308 |
312 | 309 |
313 proc main() = | 310 proc main() = |
314 if not os.fileExists("vk.xml"): | 311 let file = getTempDir() / "vk.xml" |
312 if not os.fileExists(file): | |
315 let client = newHttpClient() | 313 let client = newHttpClient() |
316 let glUrl = "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/vk.xml" | 314 let glUrl = "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/main/xml/vk.xml" |
317 client.downloadFile(glUrl, "vk.xml") | 315 client.downloadFile(glUrl, file) |
318 | 316 |
319 let api = loadXml("vk.xml") | 317 let api = loadXml(file) |
320 | 318 |
321 const outdir = "src/vulkan_api/output" | 319 const outdir = "src/vulkan_api/output" |
322 removeDir outdir | 320 removeDir outdir |
323 createDir outdir | 321 createDir outdir |
324 createDir outdir / "platform" | 322 createDir outdir / "platform" |
350 "if vulkanLib == nil:", | 348 "if vulkanLib == nil:", |
351 " raise newException(Exception, \"Unable to load vulkan library\")", | 349 " raise newException(Exception, \"Unable to load vulkan library\")", |
352 "func VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} =", | 350 "func VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} =", |
353 " (variant shl 29) or (major shl 22) or (minor shl 12) or patch", | 351 " (variant shl 29) or (major shl 22) or (minor shl 12) or patch", |
354 "", | 352 "", |
353 """template checkVkResult*(call: untyped) = | |
354 when defined(release): | |
355 discard call | |
356 else: | |
357 # yes, a bit cheap, but this is only for nice debug output | |
358 var callstr = astToStr(call).replace("\n", "") | |
359 while callstr.find(" ") >= 0: | |
360 callstr = callstr.replace(" ", " ") | |
361 debug "CALLING vulkan: ", callstr | |
362 let value = call | |
363 if value != VK_SUCCESS: | |
364 error "Vulkan error: ", astToStr(call), " returned ", $value | |
365 raise newException(Exception, "Vulkan error: " & astToStr(call) & | |
366 " returned " & $value)""", | |
355 "type", | 367 "type", |
356 ], | 368 ], |
357 "structs": @["type"], | 369 "structs": @["type"], |
358 "enums": @["type"], | 370 "enums": @["type"], |
359 "commands": @[], | 371 "commands": @[], |
503 for section in ["basetypes", "enums", "structs", "commands"]: | 515 for section in ["basetypes", "enums", "structs", "commands"]: |
504 mainout.add outputFiles[section] | 516 mainout.add outputFiles[section] |
505 for platform in api.findAll("platform"): | 517 for platform in api.findAll("platform"): |
506 mainout.add &"when defined({platform.attr(\"protect\")}):" | 518 mainout.add &"when defined({platform.attr(\"protect\")}):" |
507 mainout.add &" include platform/{platform.attr(\"name\")}" | 519 mainout.add &" include platform/{platform.attr(\"name\")}" |
508 writeFile outdir / &"types.nim", mainout.join("\n") | 520 writeFile outdir / &"api.nim", mainout.join("\n") |
509 | 521 |
510 for filename, filecontent in outputFiles.pairs: | 522 for filename, filecontent in outputFiles.pairs: |
511 if filename.startsWith("platform/"): | 523 if filename.startsWith("platform/"): |
512 writeFile outdir / &"{filename}.nim", (@[ | 524 writeFile outdir / &"{filename}.nim", (@[ |
513 "type" | 525 "type" |