96
|
1 import std/options
|
|
2
|
93
|
3 import semicongine/vulkan
|
94
|
4 import semicongine/platform/window
|
98
|
5 import semicongine/math
|
93
|
6
|
|
7
|
|
8 when isMainModule:
|
|
9 # print basic driver infos
|
|
10 echo "Layers"
|
|
11 for layer in getLayers():
|
|
12 echo " " & layer
|
|
13 echo "Instance extensions"
|
|
14 for extension in getInstanceExtensions():
|
|
15 echo " " & extension
|
|
16
|
|
17 # create instance
|
96
|
18 var thewindow = createWindow("Test")
|
|
19 var instance = thewindow.createInstance(
|
93
|
20 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
|
94
|
21 instanceExtensions= @["VK_EXT_debug_utils"],
|
|
22 layers= @["VK_LAYER_KHRONOS_validation"]
|
93
|
23 )
|
|
24 var debugger = instance.createDebugMessenger()
|
94
|
25
|
|
26 # diagnostic output
|
93
|
27 echo "Devices"
|
|
28 for device in instance.getPhysicalDevices():
|
|
29 echo " " & $device
|
96
|
30 echo " Rating: " & $device.rateGraphics()
|
93
|
31 echo " Extensions"
|
|
32 for extension in device.getExtensions():
|
|
33 echo " " & $extension
|
96
|
34 echo " Properties"
|
|
35 echo " " & $device.getProperties()
|
|
36 echo " Features"
|
|
37 echo " " & $device.getFeatures()
|
93
|
38 echo " Queue families"
|
|
39 for queueFamily in device.getQueueFamilies():
|
|
40 echo " " & $queueFamily
|
94
|
41 echo " Surface present modes"
|
96
|
42 for mode in device.getSurfacePresentModes():
|
94
|
43 echo " " & $mode
|
|
44 echo " Surface formats"
|
96
|
45 for format in device.getSurfaceFormats():
|
94
|
46 echo " " & $format
|
93
|
47
|
|
48 # create devices
|
96
|
49 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics()
|
|
50 var device = instance.createDevice(
|
|
51 selectedPhysicalDevice,
|
|
52 @[],
|
|
53 @[],
|
|
54 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
|
|
55 )
|
|
56
|
98
|
57 # setup render pipeline
|
96
|
58 var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat())
|
|
59 if res != VK_SUCCESS:
|
|
60 raise newException(Exception, "Unable to create swapchain")
|
98
|
61 var renderpass = device.simpleForwardRenderPass(swapchain.format)
|
|
62 var framebuffers: seq[Framebuffer]
|
|
63 for imageview in swapchain.imageviews:
|
|
64 framebuffers.add device.createFramebuffer(renderpass, [imageview], swapchain.dimension)
|
|
65
|
|
66 # todo: could be create inside "device", but it would be nice to have nim v2 with support for circular dependencies first
|
|
67 var commandPool = device.createCommandPool(family=device.firstGraphicsQueue().get().family, nBuffers=1)
|
96
|
68
|
|
69 echo "All successfull"
|
|
70 echo "Start cleanup"
|
93
|
71
|
98
|
72 commandPool.destroy()
|
93
|
73 # cleanup
|
98
|
74 for fb in framebuffers.mitems:
|
|
75 fb.destroy()
|
|
76 renderpass.destroy()
|
96
|
77 swapchain.destroy()
|
|
78 device.destroy()
|
93
|
79
|
|
80 debugger.destroy()
|
|
81 instance.destroy()
|