annotate tests/test_vulkan_wrapper.nim @ 557:e2d8c02f1548

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