557
|
1 import std/options
|
|
2
|
554
|
3 import semicongine/vulkan
|
555
|
4 import semicongine/platform/window
|
559
|
5 import semicongine/math
|
554
|
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
|
557
|
18 var thewindow = createWindow("Test")
|
|
19 var instance = thewindow.createInstance(
|
554
|
20 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
|
555
|
21 instanceExtensions= @["VK_EXT_debug_utils"],
|
|
22 layers= @["VK_LAYER_KHRONOS_validation"]
|
554
|
23 )
|
|
24 var debugger = instance.createDebugMessenger()
|
555
|
25
|
|
26 # diagnostic output
|
554
|
27 echo "Devices"
|
|
28 for device in instance.getPhysicalDevices():
|
|
29 echo " " & $device
|
557
|
30 echo " Rating: " & $device.rateGraphics()
|
554
|
31 echo " Extensions"
|
|
32 for extension in device.getExtensions():
|
|
33 echo " " & $extension
|
557
|
34 echo " Properties"
|
|
35 echo " " & $device.getProperties()
|
|
36 echo " Features"
|
|
37 echo " " & $device.getFeatures()
|
554
|
38 echo " Queue families"
|
|
39 for queueFamily in device.getQueueFamilies():
|
|
40 echo " " & $queueFamily
|
555
|
41 echo " Surface present modes"
|
557
|
42 for mode in device.getSurfacePresentModes():
|
555
|
43 echo " " & $mode
|
|
44 echo " Surface formats"
|
557
|
45 for format in device.getSurfaceFormats():
|
555
|
46 echo " " & $format
|
554
|
47
|
|
48 # create devices
|
557
|
49 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics()
|
|
50 var device = instance.createDevice(
|
|
51 selectedPhysicalDevice,
|
|
52 @[],
|
|
53 @[],
|
|
54 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
|
|
55 )
|
|
56
|
559
|
57 # setup render pipeline
|
557
|
58 var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat())
|
|
59 if res != VK_SUCCESS:
|
|
60 raise newException(Exception, "Unable to create swapchain")
|
559
|
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)
|
557
|
68
|
|
69 echo "All successfull"
|
|
70 echo "Start cleanup"
|
554
|
71
|
559
|
72 commandPool.destroy()
|
554
|
73 # cleanup
|
559
|
74 for fb in framebuffers.mitems:
|
|
75 fb.destroy()
|
|
76 renderpass.destroy()
|
557
|
77 swapchain.destroy()
|
|
78 device.destroy()
|
554
|
79
|
|
80 debugger.destroy()
|
|
81 instance.destroy()
|