Mercurial > games > semicongine
comparison svk/generate.nim @ 1483:55911f736a5a
add: more shit
| author | sam <sam@basx.dev> |
|---|---|
| date | Tue, 29 Apr 2025 00:17:33 +0700 |
| parents | bca8f65ed4ed |
| children | a2af327f19df |
comparison
equal
deleted
inserted
replaced
| 1482:bca8f65ed4ed | 1483:55911f736a5a |
|---|---|
| 233 # | 233 # |
| 234 # android | 234 # android |
| 235 ANativeWindow = object | 235 ANativeWindow = object |
| 236 AHardwareBuffer = object | 236 AHardwareBuffer = object |
| 237 | 237 |
| 238 # apple | 238 # apple/metal |
| 239 CAMetalLayer = object | 239 CAMetalLayer = object |
| 240 MTLDevice = object | |
| 241 MTLCommandQueue = object | |
| 242 MTLBuffer = object | |
| 243 MTLTexture = object | |
| 244 MTLSharedEvent = object | |
| 245 MTLSharedEvent_id = object | 240 MTLSharedEvent_id = object |
| 241 MTLDevice_id = object | |
| 242 MTLCommandQueue_id = object | |
| 243 MTLBuffer_id = object | |
| 244 MTLTexture_id = object | |
| 245 IOSurfaceRef = object | |
| 246 | 246 |
| 247 # wayland | 247 # wayland |
| 248 wl_display = object | 248 wl_display = object |
| 249 wl_surface = object | 249 wl_surface = object |
| 250 | 250 |
| 275 NvSciSyncFence = object | 275 NvSciSyncFence = object |
| 276 NvSciBufAttrList = object | 276 NvSciBufAttrList = object |
| 277 NvSciBufObj = object | 277 NvSciBufObj = object |
| 278 | 278 |
| 279 # some base vulkan base types | 279 # some base vulkan base types |
| 280 VkSampleMask = distinct uint32 | 280 VkSampleMask* = distinct uint32 |
| 281 VkBool32 = distinct uint32 | 281 VkBool32* = distinct uint32 |
| 282 VkFlags = distinct uint32 | 282 VkFlags* = distinct uint32 |
| 283 VkFlags64 = distinct uint64 | 283 VkFlags64* = distinct uint64 |
| 284 VkDeviceSize = distinct uint64 | 284 VkDeviceSize* = distinct uint64 |
| 285 VkDeviceAddress = distinct uint64 | 285 VkDeviceAddress* = distinct uint64 |
| 286 VkRemoteAddressNV = pointer | 286 VkRemoteAddressNV* = pointer |
| 287 """ | 287 """ |
| 288 | 288 |
| 289 # generate consts =============================================================================== | 289 # generate consts =============================================================================== |
| 290 outFile.writeLine "const" | 290 outFile.writeLine "const" |
| 291 for c in consts: | 291 for c in consts: |
| 305 "VK_PIPELINE_CACHE_HEADER_VERSION_SAFETY_CRITICAL_ONE", | 305 "VK_PIPELINE_CACHE_HEADER_VERSION_SAFETY_CRITICAL_ONE", |
| 306 "VK_DEVICE_FAULT_VENDOR_BINARY_HEADER_VERSION_ONE_EXT", | 306 "VK_DEVICE_FAULT_VENDOR_BINARY_HEADER_VERSION_ONE_EXT", |
| 307 ] | 307 ] |
| 308 outFile.writeLine "type" | 308 outFile.writeLine "type" |
| 309 | 309 |
| 310 echo "#########################" | |
| 311 for edef in enums.values(): | 310 for edef in enums.values(): |
| 312 echo edef.values | |
| 313 if edef.values.len > 0: | 311 if edef.values.len > 0: |
| 314 outFile.writeLine &" {edef.name}* {{.size: 4.}} = enum" | 312 outFile.writeLine &" {edef.name}* {{.size: 4.}} = enum" |
| 315 for ee in edef.values: | 313 for ee in edef.values: |
| 316 # due to the nim identifier-system, there might be collisions between typenames and enum-member names | 314 # due to the nim identifier-system, there might be collisions between typenames and enum-member names |
| 317 if ee.name in nameCollisions: | 315 if ee.name in nameCollisions: |
| 322 outFile.writeLine "" | 320 outFile.writeLine "" |
| 323 | 321 |
| 324 # generate types =============================================================================== | 322 # generate types =============================================================================== |
| 325 for t in types: | 323 for t in types: |
| 326 let category = t.attr("category") | 324 let category = t.attr("category") |
| 325 let tName = t.attr("name") | |
| 326 if tName.startsWith("VkVideo"): # we are not doing the video API, sorry | |
| 327 continue | |
| 328 if tName.startsWith("VkPhysicalDeviceVideo"): # we are not doing the video API, sorry | |
| 329 continue | |
| 327 if t.attr("api") == "vulkansc": | 330 if t.attr("api") == "vulkansc": |
| 328 continue | 331 continue |
| 329 elif t.attr("deprecated") == "true": | 332 elif t.attr("deprecated") == "true": |
| 330 continue | 333 continue |
| 331 elif category == "include": | 334 elif category == "include": |
| 334 continue | 337 continue |
| 335 elif t.attr("requires").startsWith("vk_video"): | 338 elif t.attr("requires").startsWith("vk_video"): |
| 336 continue | 339 continue |
| 337 elif t.attr("alias") != "": | 340 elif t.attr("alias") != "": |
| 338 let a = t.attr("alias") | 341 let a = t.attr("alias") |
| 339 let n = t.attr("name") | 342 outFile.writeLine &" {tName}* = {a}" |
| 340 outFile.writeLine &" {n} = {a}" | |
| 341 elif category == "bitmask": | 343 elif category == "bitmask": |
| 342 if t.len > 0 and t[0].text.startsWith("typedef"): | 344 if t.len > 0 and t[0].text.startsWith("typedef"): |
| 343 outFile.writeLine &" {t[2][0].text} = distinct {t[1][0].text}" | 345 outFile.writeLine &" {t[2][0].text}* = distinct {t[1][0].text}" |
| 344 elif category == "union": | 346 elif category == "union": |
| 345 let n = t.attr("name") | 347 outFile.writeLine &" {tName}* {{.union.}} = object" |
| 346 outFile.writeLine &" {n}* {{.union.}} = object" | |
| 347 for member in t.findAll("member"): | 348 for member in t.findAll("member"): |
| 348 outFile.writeLine &" {member.memberDecl()}" | 349 outFile.writeLine &" {member.memberDecl()}" |
| 349 elif category == "handle": | 350 elif category == "handle": |
| 350 outFile.writeLine &" {t[2][0].text} = distinct pointer" | 351 outFile.writeLine &" {t[2][0].text}* = distinct pointer" |
| 351 elif category == "struct": | 352 elif category == "struct": |
| 352 let n = t.attr("name") | 353 outFile.writeLine &" {tName}* = object" |
| 353 outFile.writeLine &" {n}* = object" | |
| 354 for member in t.findAll("member"): | 354 for member in t.findAll("member"): |
| 355 if member.attr("api") == "vulkansc": | 355 if member.attr("api") == "vulkansc": |
| 356 continue | 356 continue |
| 357 outFile.writeLine &" {member.memberDecl()}" | 357 outFile.writeLine &" {member.memberDecl()}" |
| 358 elif category == "funcpointer": | 358 elif category == "funcpointer": |
| 361 <type>void</type>* pUserData, | 361 <type>void</type>* pUserData, |
| 362 <type>size_t</type> size, | 362 <type>size_t</type> size, |
| 363 <type>size_t</type> alignment, | 363 <type>size_t</type> alignment, |
| 364 <type>VkSystemAllocationScope</type> allocationScope); | 364 <type>VkSystemAllocationScope</type> allocationScope); |
| 365 </type> | 365 </type> |
| 366 PFN_vkAllocationFunction* = proc( | |
| 367 pUserData: pointer, | |
| 368 size: csize_t, | |
| 369 alignment: csize_t, | |
| 370 allocationScope: VkSystemAllocationScope, | |
| 371 ): pointer {.cdecl.} | |
| 372 ]# | 366 ]# |
| 373 assert t[0].text.startsWith("typedef ") | 367 assert t[0].text.startsWith("typedef ") |
| 374 outFile.writeLine &" {t[1][0].text}* = proc()" | 368 let retName = t[0].text[8 ..< ^13].strip() |
| 369 let funcName = t.findAll("name")[0][0].text | |
| 370 | |
| 371 outFile.write &" {funcname}* = proc(" | |
| 372 for i in 3 ..< t.len: | |
| 373 # TODO: params | |
| 374 | |
| 375 if retName == "void" | |
| 376 outFile.writeLine &") {{.cdecl.}}" | |
| 377 elif retName == "void*" | |
| 378 outFile.writeLine &"): pointer {{.cdecl.}}" | |
| 379 else: | |
| 380 outFile.writeLine &"): {doTypename(retName, false)} {{.cdecl.}}" | |
| 381 | |
| 375 else: | 382 else: |
| 376 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category | 383 doAssert category in ["", "basetype", "enum"], "unknown type category: " & category |
| 377 outFile.writeLine "" | 384 outFile.writeLine "" |
| 378 | 385 |
| 379 outFile.writeLine """ | 386 for command in commands: |
| 380 when defined(linux): | 387 #[ |
| 381 include ../semicongine/rendering/vulkan/platform/xlib | 388 <command successcodes="VK_SUCCESS" errorcodes="VK_ERROR_OUT_OF_HOST_MEMORY,VK_ERROR_OUT_OF_DEVICE_MEMORY,VK_ERROR_INITIALIZATION_FAILED,VK_ERROR_LAYER_NOT_PRESENT,VK_ERROR_EXTENSION_NOT_PRESENT,VK_ERROR_INCOMPATIBLE_DRIVER"> |
| 382 when defined(windows): | 389 <proto> |
| 383 include ../semicongine/rendering/vulkan/platform/win32 | 390 <type>VkResult</type> |
| 384 """ | 391 <name>vkCreateInstance</name> |
| 392 </proto> | |
| 393 <param>const <type>VkInstanceCreateInfo</type>* <name>pCreateInfo</name></param> | |
| 394 <param optional="true">const <type>VkAllocationCallbacks</type>* <name>pAllocator</name></param> | |
| 395 <param><type>VkInstance</type>* <name>pInstance</name></param> | |
| 396 </command> | |
| 397 ]# | |
| 398 if command.attr("api") == "vulkansc": | |
| 399 continue | |
| 400 if command.attr("alias") != "": | |
| 401 let funcName = command.attr("name") | |
| 402 let funcAlias = command.attr("alias") | |
| 403 outFile.write &"var {funcName}* = {funcAlias}\n" | |
| 404 continue | |
| 405 | |
| 406 let proto = command.findAll("proto")[0] | |
| 407 let retType = proto.findAll("type")[0][0].text.strip() | |
| 408 let funcName = proto.findAll("name")[0][0].text.strip() | |
| 409 | |
| 410 if "Video" in funcName: # Video API not supported at this time | |
| 411 continue | |
| 412 | |
| 413 outFile.write &"var {funcName}*: proc(" | |
| 414 for param in command: | |
| 415 if param.tag != "param": | |
| 416 continue | |
| 417 if param.attr("api") == "vulkansc": | |
| 418 continue | |
| 419 assert param.len in [2, 3, 4] | |
| 420 let paramType = param.findAll("type")[0][0].text | |
| 421 let paramName = param.findAll("name")[0][0].text | |
| 422 assert "*" notin paramType, $param | |
| 423 if paramType == "void": | |
| 424 outFile.write &"{doIdentifier(paramName)}: {doTypename(paramType, true)}, " | |
| 425 else: | |
| 426 outFile.write &"{doIdentifier(paramName)}: {doTypename(paramType, false)}, " | |
| 427 | |
| 428 outFile.write &")" | |
| 429 if retType != "void": | |
| 430 assert "*" notin retType | |
| 431 outFile.write &": {doTypename(retType, false)}" | |
| 432 outFile.write " {.stdcall.}\n" | |
| 385 | 433 |
| 386 outFile.close() | 434 outFile.close() |
| 387 | 435 |
| 388 assert execCmd("nim c " & outPath) == 0 | 436 assert execCmd("nim c " & outPath) == 0 |
