Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 108:70f92081d2c1
did: reorganize code
author | Sam <sam@basx.dev> |
---|---|
date | Tue, 28 Mar 2023 00:20:49 +0700 |
parents | 2d0351a68a4e |
children | 8d24727c9795 |
comparison
equal
deleted
inserted
replaced
107:2d0351a68a4e | 108:70f92081d2c1 |
---|---|
62 @[], | 62 @[], |
63 @[], | 63 @[], |
64 selectedPhysicalDevice.filterForGraphicsPresentationQueues() | 64 selectedPhysicalDevice.filterForGraphicsPresentationQueues() |
65 ) | 65 ) |
66 | 66 |
67 var surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat() | |
68 var renderpass = device.simpleForwardRenderPass(surfaceFormat.format) | |
69 echo renderpass | |
70 var (swapchain, res) = device.createSwapchain(renderpass, surfaceFormat, device.firstGraphicsQueue().get().family) | |
71 if res != VK_SUCCESS: | |
72 raise newException(Exception, "Unable to create swapchain") | |
73 | |
74 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") | 67 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") |
75 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") | 68 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") |
76 var | 69 var |
77 vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) | 70 vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) |
78 fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) | 71 fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) |
79 pipeline = renderpass.createPipeline(vertexshader, fragmentshader) | 72 surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat() |
80 descriptorPool = device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1'u32)]) | 73 renderpass = device.simpleForwardRenderPass(surfaceFormat.format, vertexshader, fragmentshader, 2) |
81 descriptorSet = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, 1) | 74 var (swapchain, res) = device.createSwapchain(renderpass, surfaceFormat, device.firstGraphicsQueue().get().family, 2) |
75 if res != VK_SUCCESS: | |
76 raise newException(Exception, "Unable to create swapchain") | |
82 | 77 |
83 echo "All successfull" | 78 echo "All successfull" |
84 discard swapchain.drawNextFrame(pipeline) | 79 for i in 0 ..< 2: |
80 discard swapchain.drawNextFrame() | |
81 echo "Rendered ", swapchain.framesRendered, " frames" | |
85 echo "Start cleanup" | 82 echo "Start cleanup" |
83 | |
86 | 84 |
87 # cleanup | 85 # cleanup |
88 checkVkResult device.vk.vkDeviceWaitIdle() | 86 checkVkResult device.vk.vkDeviceWaitIdle() |
89 descriptorPool.destroy() | |
90 vertexshader.destroy() | 87 vertexshader.destroy() |
91 fragmentshader.destroy() | 88 fragmentshader.destroy() |
92 pipeline.destroy() | |
93 renderpass.destroy() | 89 renderpass.destroy() |
94 swapchain.destroy() | 90 swapchain.destroy() |
95 device.destroy() | 91 device.destroy() |
96 | 92 |
97 debugger.destroy() | 93 debugger.destroy() |