comparison tests/test_vulkan_wrapper.nim @ 555:7c44f714bd03

add: device, surface and refactoring
author Sam <sam@basx.dev>
date Tue, 28 Feb 2023 23:51:07 +0700
parents f9a5ada2df1e
children b9fc90de1450
comparison
equal deleted inserted replaced
554:f9a5ada2df1e 555:7c44f714bd03
1 import semicongine/vulkan 1 import semicongine/vulkan
2 import semicongine/platform/window
2 3
3 4
4 when isMainModule: 5 when isMainModule:
5 # print basic driver infos 6 # print basic driver infos
6 echo "Layers" 7 echo "Layers"
11 echo " " & extension 12 echo " " & extension
12 13
13 # create instance 14 # create instance
14 var instance = createInstance( 15 var instance = createInstance(
15 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0), 16 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
16 instanceExtensions=["VK_EXT_debug_utils"], 17 instanceExtensions= @["VK_EXT_debug_utils"],
17 layers=["VK_LAYER_KHRONOS_validation"] 18 layers= @["VK_LAYER_KHRONOS_validation"]
18 ) 19 )
19 var debugger = instance.createDebugMessenger() 20 var debugger = instance.createDebugMessenger()
21
22 # create surface
23 var thewindow = createWindow("Test")
24 var surface = instance.createSurface(thewindow)
25
26 # diagnostic output
20 echo "Devices" 27 echo "Devices"
21 for device in instance.getPhysicalDevices(): 28 for device in instance.getPhysicalDevices():
22 echo " " & $device 29 echo " " & $device
23 echo " Extensions" 30 echo " Extensions"
24 for extension in device.getExtensions(): 31 for extension in device.getExtensions():
25 echo " " & $extension 32 echo " " & $extension
26 echo " Queue families" 33 echo " Queue families"
27 for queueFamily in device.getQueueFamilies(): 34 for queueFamily in device.getQueueFamilies():
28 echo " " & $queueFamily 35 echo " " & $queueFamily
36 echo " Surface present modes"
37 for mode in device.getSurfacePresentModes(surface):
38 echo " " & $mode
39 echo " Surface formats"
40 for format in device.getSurfaceFormats(surface):
41 echo " " & $format
29 42
30 # create devices 43 # create devices
31 var devices: seq[Device] 44 var devices: seq[Device]
32 for physicalDevice in instance.getPhysicalDevices(): 45 for physicalDevice in instance.getPhysicalDevices():
33 devices.add physicalDevice.createDevice([], [], []) 46 devices.add physicalDevice.createDevice([], [], physicalDevice.getQueueFamilies(surface).filterForGraphicsPresentationQueues())
34 47
35 # cleanup 48 # cleanup
49 surface.destroy()
36 for device in devices.mitems: 50 for device in devices.mitems:
37 device.destroy() 51 device.destroy()
38 52
39 debugger.destroy() 53 debugger.destroy()
40 instance.destroy() 54 instance.destroy()