annotate tests/test_vulkan_wrapper.nim @ 97:110ed3ee5df8

add: swapchain, images, fix some destroctors
author Sam <sam@basx.dev>
date Thu, 02 Mar 2023 23:16:45 +0700
parents b9fc90de1450
children 335a65d3f892
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
1 import std/options
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
2
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
3 import semicongine/vulkan
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
4 import semicongine/platform/window
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
5
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
6
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
7 when isMainModule:
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
8 # print basic driver infos
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
9 echo "Layers"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
10 for layer in getLayers():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
11 echo " " & layer
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
12 echo "Instance extensions"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
13 for extension in getInstanceExtensions():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
14 echo " " & extension
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
15
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
16 # create instance
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
17 var thewindow = createWindow("Test")
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
18 var instance = thewindow.createInstance(
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
19 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
20 instanceExtensions= @["VK_EXT_debug_utils"],
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
21 layers= @["VK_LAYER_KHRONOS_validation"]
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
22 )
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
23 var debugger = instance.createDebugMessenger()
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
24
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
25 # diagnostic output
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
26 echo "Devices"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
27 for device in instance.getPhysicalDevices():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
28 echo " " & $device
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
29 echo " Rating: " & $device.rateGraphics()
93
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
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
33 echo " Properties"
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
34 echo " " & $device.getProperties()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
35 echo " Features"
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
36 echo " " & $device.getFeatures()
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
37 echo " Queue families"
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
38 for queueFamily in device.getQueueFamilies():
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
39 echo " " & $queueFamily
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
40 echo " Surface present modes"
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
41 for mode in device.getSurfacePresentModes():
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
42 echo " " & $mode
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
43 echo " Surface formats"
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
44 for format in device.getSurfaceFormats():
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 93
diff changeset
45 echo " " & $format
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
46
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
47 # create devices
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
48 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
49 var device = instance.createDevice(
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
50 selectedPhysicalDevice,
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
51 @[],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
52 @[],
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
53 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
54 )
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
55
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
56 echo "Created device ", device.physicalDevice.name
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
57 var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat())
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
58 if res != VK_SUCCESS:
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
59 raise newException(Exception, "Unable to create swapchain")
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
60
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
61 echo "All successfull"
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
62 echo "Start cleanup"
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
63
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
64 # cleanup
96
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
65 swapchain.destroy()
b9fc90de1450 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 94
diff changeset
66 device.destroy()
93
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
67
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
68 debugger.destroy()
cb773e81032f add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
69 instance.destroy()