annotate tests/test_vulkan_wrapper.nim @ 94:f036546f5ea2

add: device, surface and refactoring
author Sam <sam@basx.dev>
date Tue, 28 Feb 2023 23:51:07 +0700
parents cb773e81032f
children b9fc90de1450
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
1 import semicongine/vulkan
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
2 import semicongine/platform/window
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
3
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
4
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
5 when isMainModule:
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
6 # print basic driver infos
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
7 echo "Layers"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
8 for layer in getLayers():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
9 echo " " & layer
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
10 echo "Instance extensions"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
11 for extension in getInstanceExtensions():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
12 echo " " & extension
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
13
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
14 # create instance
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
15 var instance = createInstance(
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
16 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
17 instanceExtensions= @["VK_EXT_debug_utils"],
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
18 layers= @["VK_LAYER_KHRONOS_validation"]
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
19 )
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
20 var debugger = instance.createDebugMessenger()
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
21
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
22 # create surface
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
23 var thewindow = createWindow("Test")
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
24 var surface = instance.createSurface(thewindow)
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
25
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
26 # diagnostic output
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
27 echo "Devices"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
28 for device in instance.getPhysicalDevices():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
29 echo " " & $device
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
30 echo " Extensions"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
31 for extension in device.getExtensions():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
32 echo " " & $extension
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
33 echo " Queue families"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
34 for queueFamily in device.getQueueFamilies():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
35 echo " " & $queueFamily
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
36 echo " Surface present modes"
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
37 for mode in device.getSurfacePresentModes(surface):
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
38 echo " " & $mode
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
39 echo " Surface formats"
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
40 for format in device.getSurfaceFormats(surface):
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
41 echo " " & $format
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
42
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
43 # create devices
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
44 var devices: seq[Device]
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
45 for physicalDevice in instance.getPhysicalDevices():
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
46 devices.add physicalDevice.createDevice([], [], physicalDevice.getQueueFamilies(surface).filterForGraphicsPresentationQueues())
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
47
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
48 # cleanup
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
49 surface.destroy()
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
50 for device in devices.mitems:
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
51 device.destroy()
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
52
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
53 debugger.destroy()
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
54 instance.destroy()