comparison tests/test_vulkan_wrapper.nim @ 105:4059aa0d689b

add: descriptors, better swapchain implementation
author Sam <sam@basx.dev>
date Fri, 24 Mar 2023 00:11:42 +0700
parents 9eeb9a44d158
children 9c3e3dcb0328
comparison
equal deleted inserted replaced
104:9eeb9a44d158 105:4059aa0d689b
63 @[], 63 @[],
64 selectedPhysicalDevice.filterForGraphicsPresentationQueues() 64 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
65 ) 65 )
66 66
67 # setup render pipeline 67 # setup render pipeline
68 var (swapchain, res) = device.createSwapchain(device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()) 68 var surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()
69 var renderpass = device.simpleForwardRenderPass(surfaceFormat.format)
70 var (swapchain, res) = device.createSwapchain(renderpass, surfaceFormat)
69 if res != VK_SUCCESS: 71 if res != VK_SUCCESS:
70 raise newException(Exception, "Unable to create swapchain") 72 raise newException(Exception, "Unable to create swapchain")
71 var renderpass = device.simpleForwardRenderPass(swapchain.format) 73 # var framebuffers: seq[Framebuffer]
72 var framebuffers: seq[Framebuffer] 74 # for imageview in swapchain.imageviews:
73 for imageview in swapchain.imageviews: 75 # framebuffers.add device.createFramebuffer(renderpass, [imageview], swapchain.dimension)
74 framebuffers.add device.createFramebuffer(renderpass, [imageview], swapchain.dimension)
75 76
76 # todo: could be create inside "device", but it would be nice to have nim v2 with support for circular dependencies first 77 # todo: could be create inside "device", but it would be nice to have nim v2 with support for circular dependencies first
77 var 78 var
78 commandPool = device.createCommandPool(family=device.firstGraphicsQueue().get().family, nBuffers=1) 79 commandPool = device.createCommandPool(family=device.firstGraphicsQueue().get().family, nBuffers=1)
79 imageAvailable = device.createSemaphore() 80 imageAvailable = device.createSemaphore()
84 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") 85 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, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) 86 var vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary)
86 var fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) 87 var fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary)
87 88
88 var pipeline = renderpass.createPipeline(vertexshader, fragmentshader) 89 var pipeline = renderpass.createPipeline(vertexshader, fragmentshader)
90 var descriptorPool = device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1'u32)])
91 var descriptorSet = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, 1)
89 92
90 echo "All successfull" 93 echo "All successfull"
91 echo "Start cleanup" 94 echo "Start cleanup"
92 95
93 # cleanup 96 # cleanup
97 checkVkResult device.vk.vkDeviceWaitIdle()
98 descriptorPool.destroy()
94 vertexshader.destroy() 99 vertexshader.destroy()
95 fragmentshader.destroy() 100 fragmentshader.destroy()
96 pipeline.destroy() 101 pipeline.destroy()
97 inflight.destroy() 102 inflight.destroy()
98 imageAvailable.destroy() 103 imageAvailable.destroy()
99 renderFinished.destroy() 104 renderFinished.destroy()
100 commandPool.destroy() 105 commandPool.destroy()
101 for fb in framebuffers.mitems:
102 fb.destroy()
103 renderpass.destroy() 106 renderpass.destroy()
104 swapchain.destroy() 107 swapchain.destroy()
105 device.destroy() 108 device.destroy()
106 109
107 debugger.destroy() 110 debugger.destroy()