comparison tests/test_vulkan_wrapper.nim @ 568:1c0de073370b

add: working render loop
author Sam <sam@basx.dev>
date Mon, 27 Mar 2023 21:01:32 +0700
parents 05ac2455ff60
children 70f92081d2c1
comparison
equal deleted inserted replaced
567:05ac2455ff60 568:1c0de073370b
62 @[], 62 @[],
63 @[], 63 @[],
64 selectedPhysicalDevice.filterForGraphicsPresentationQueues() 64 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
65 ) 65 )
66 66
67 # setup render pipeline
68 var surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat() 67 var surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()
69 var renderpass = device.simpleForwardRenderPass(surfaceFormat.format) 68 var renderpass = device.simpleForwardRenderPass(surfaceFormat.format)
69 echo renderpass
70 var (swapchain, res) = device.createSwapchain(renderpass, surfaceFormat, device.firstGraphicsQueue().get().family) 70 var (swapchain, res) = device.createSwapchain(renderpass, surfaceFormat, device.firstGraphicsQueue().get().family)
71 if res != VK_SUCCESS: 71 if res != VK_SUCCESS:
72 raise newException(Exception, "Unable to create swapchain") 72 raise newException(Exception, "Unable to create swapchain")
73 73
74 # todo: could be create inside "device", but it would be nice to have nim v2 with support for circular dependencies first
75 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;") 74 const vertexBinary = shaderCode[Vertex, Uniforms, FragmentInput](stage=VK_SHADER_STAGE_VERTEX_BIT, version=450, entrypoint="main", "fragpos = pos;")
76 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);") 75 const fragmentBinary = shaderCode[FragmentInput, void, Pixel](stage=VK_SHADER_STAGE_FRAGMENT_BIT, version=450, entrypoint="main", "color = vec4(1, 1, 1, 0);")
77 var 76 var
78 vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary) 77 vertexshader = createShader[Vertex, Uniforms, FragmentInput](device, VK_SHADER_STAGE_VERTEX_BIT, "main", vertexBinary)
79 fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary) 78 fragmentshader = createShader[FragmentInput, void, Pixel](device, VK_SHADER_STAGE_FRAGMENT_BIT, "main", fragmentBinary)
80 pipeline = renderpass.createPipeline(vertexshader, fragmentshader) 79 pipeline = renderpass.createPipeline(vertexshader, fragmentshader)
81 descriptorPool = device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1'u32)]) 80 descriptorPool = device.createDescriptorSetPool(@[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1'u32)])
82 descriptorSet = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, 1) 81 descriptorSet = descriptorPool.allocateDescriptorSet(pipeline.descriptorSetLayout, 1)
83 82
84 echo "All successfull" 83 echo "All successfull"
85 echo swapchain.drawNextFrame(pipeline) 84 discard swapchain.drawNextFrame(pipeline)
86 echo "Start cleanup" 85 echo "Start cleanup"
87 86
88 # cleanup 87 # cleanup
89 checkVkResult device.vk.vkDeviceWaitIdle() 88 checkVkResult device.vk.vkDeviceWaitIdle()
90 descriptorPool.destroy() 89 descriptorPool.destroy()