Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 104:9eeb9a44d158
did: some refactoring
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 20 Mar 2023 23:48:46 +0700 |
parents | 1e2027dfc642 |
children | 4059aa0d689b |
comparison
equal
deleted
inserted
replaced
103:1e2027dfc642 | 104:9eeb9a44d158 |
---|---|
12 Uniforms = object | 12 Uniforms = object |
13 time: float32 | 13 time: float32 |
14 Pixel = object | 14 Pixel = object |
15 color: Vec4 | 15 color: Vec4 |
16 | 16 |
17 | 17 proc diagnostics(instance: Instance) = |
18 when isMainModule: | |
19 # print basic driver infos | |
20 echo "Layers" | |
21 for layer in getLayers(): | |
22 echo " " & layer | |
23 echo "Instance extensions" | |
24 for extension in getInstanceExtensions(): | |
25 echo " " & extension | |
26 | |
27 # create instance | |
28 var thewindow = createWindow("Test") | |
29 var instance = thewindow.createInstance( | |
30 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0), | |
31 instanceExtensions= @["VK_EXT_debug_utils"], | |
32 layers= @["VK_LAYER_KHRONOS_validation"] | |
33 ) | |
34 var debugger = instance.createDebugMessenger() | |
35 | |
36 # diagnostic output | 18 # diagnostic output |
37 echo "Devices" | 19 echo "Devices" |
38 for device in instance.getPhysicalDevices(): | 20 for device in instance.getPhysicalDevices(): |
39 echo " " & $device | 21 echo " " & $device |
40 echo " Rating: " & $device.rateGraphics() | 22 echo " Rating: " & $device.rateGraphics() |
52 for mode in device.getSurfacePresentModes(): | 34 for mode in device.getSurfacePresentModes(): |
53 echo " " & $mode | 35 echo " " & $mode |
54 echo " Surface formats" | 36 echo " Surface formats" |
55 for format in device.getSurfaceFormats(): | 37 for format in device.getSurfaceFormats(): |
56 echo " " & $format | 38 echo " " & $format |
39 | |
40 when isMainModule: | |
41 # print basic driver infos | |
42 echo "Layers" | |
43 for layer in getLayers(): | |
44 echo " " & layer | |
45 echo "Instance extensions" | |
46 for extension in getInstanceExtensions(): | |
47 echo " " & extension | |
48 | |
49 # create instance | |
50 var thewindow = createWindow("Test") | |
51 var instance = thewindow.createInstance( | |
52 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0), | |
53 instanceExtensions= @["VK_EXT_debug_utils"], | |
54 layers= @["VK_LAYER_KHRONOS_validation"] | |
55 ) | |
56 var debugger = instance.createDebugMessenger() | |
57 | 57 |
58 # create devices | 58 # create devices |
59 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics() | 59 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics() |
60 var device = instance.createDevice( | 60 var device = instance.createDevice( |
61 selectedPhysicalDevice, | 61 selectedPhysicalDevice, |
78 commandPool = device.createCommandPool(family=device.firstGraphicsQueue().get().family, nBuffers=1) | 78 commandPool = device.createCommandPool(family=device.firstGraphicsQueue().get().family, nBuffers=1) |
79 imageAvailable = device.createSemaphore() | 79 imageAvailable = device.createSemaphore() |
80 renderFinished = device.createSemaphore() | 80 renderFinished = device.createSemaphore() |
81 inflight = device.createFence() | 81 inflight = device.createFence() |
82 | 82 |
83 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](shadertype=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") | 83 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") |
84 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](shadertype=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") | 84 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") |
85 var vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, "main", vertexBinary) | 85 var vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) |
86 var fragmentshader = createShader[FragmentInput, void, Pixel](device, "main", fragmentBinary) | 86 var fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) |
87 | 87 |
88 var pipeline = renderpass.createPipeline(vertexshader, fragmentshader) | 88 var pipeline = renderpass.createPipeline(vertexshader, fragmentshader) |
89 | 89 |
90 echo "All successfull" | 90 echo "All successfull" |
91 echo "Start cleanup" | 91 echo "Start cleanup" |
92 | 92 |
93 # cleanup | 93 # cleanup |
94 #pipeline.destroy() | |
95 #vertexshader.destroy() | |
96 #fragmentshader.destroy() | |
97 vertexshader.destroy() | 94 vertexshader.destroy() |
98 fragmentshader.destroy() | 95 fragmentshader.destroy() |
96 pipeline.destroy() | |
99 inflight.destroy() | 97 inflight.destroy() |
100 imageAvailable.destroy() | 98 imageAvailable.destroy() |
101 renderFinished.destroy() | 99 renderFinished.destroy() |
102 commandPool.destroy() | 100 commandPool.destroy() |
103 for fb in framebuffers.mitems: | 101 for fb in framebuffers.mitems: |