Mercurial > games > semicongine
comparison tests/test_rendering.nim @ 1205:f7530247a21f compiletime-tests
did: improve descriptor-set handling, add simple descriptor set test
author | sam <sam@basx.dev> |
---|---|
date | Tue, 16 Jul 2024 11:53:43 +0700 |
parents | e2901100a596 |
children | 8cf9a05b03eb |
comparison
equal
deleted
inserted
replaced
1204:e2901100a596 | 1205:f7530247a21f |
---|---|
124 | 124 |
125 type | 125 type |
126 RenderSettings = object | 126 RenderSettings = object |
127 gamma: float32 | 127 gamma: float32 |
128 FirstDS = object | 128 FirstDS = object |
129 settings: GPUValue[RenderSettings, UniformBuffer] | 129 settings: GPUValue[RenderSettings, UniformBufferMapped] |
130 QuadShader = object | 130 QuadShader = object |
131 position {.VertexAttribute.}: Vec3f | 131 position {.VertexAttribute.}: Vec3f |
132 color {.VertexAttribute.}: Vec3f | 132 color {.VertexAttribute.}: Vec3f |
133 fragmentColor {.Pass.}: Vec3f | 133 fragmentColor {.Pass.}: Vec3f |
134 outColor {.ShaderOutput.}: Vec4f | 134 outColor {.ShaderOutput.}: Vec4f |
135 firstDS: DescriptorSet[FirstDS, First] | 135 descriptorSets {.DescriptorSets.}: (FirstDS, ) |
136 # code | 136 # code |
137 vertexCode: string = """void main() { | 137 vertexCode: string = """void main() { |
138 fragmentColor = vec3(pow(color.r, settings.gamma), pow(color.g, settings.gamma), pow(color.b, settings.gamma)); | 138 fragmentColor = vec3(pow(color.r, settings.gamma), pow(color.g, settings.gamma), pow(color.b, settings.gamma)); |
139 gl_Position = vec4(position, 1);}""" | 139 gl_Position = vec4(position, 1);}""" |
140 fragmentCode: string = """void main() { | 140 fragmentCode: string = """void main() { |
143 position: GPUArray[Vec3f, VertexBuffer] | 143 position: GPUArray[Vec3f, VertexBuffer] |
144 color: GPUArray[Vec3f, VertexBuffer] | 144 color: GPUArray[Vec3f, VertexBuffer] |
145 indices: GPUArray[uint16, IndexBuffer] | 145 indices: GPUArray[uint16, IndexBuffer] |
146 | 146 |
147 var quad = QuadMesh( | 147 var quad = QuadMesh( |
148 position: asGPUArray([NewVec3f(-0.3, -0.3), NewVec3f(-0.3, 0.3), NewVec3f(0.3, 0.3), NewVec3f(0.3, -0.3)], VertexBuffer), | 148 position: asGPUArray([NewVec3f(-0.9, -0.5), NewVec3f(-0.9, 0.5), NewVec3f(0.9, 0.5), NewVec3f(0.9, -0.5)], VertexBuffer), |
149 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | 149 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
150 color: asGPUArray([NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1)], VertexBuffer), | 150 color: asGPUArray([NewVec3f(0, 0, 0), NewVec3f(0, 0, 0), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1)], VertexBuffer), |
151 ) | 151 ) |
152 var firstDs = DescriptorSet[FirstDS, First]( | 152 var settings = DescriptorSet[FirstDS]( |
153 data: FirstDS( | 153 data: FirstDS( |
154 settings: asGPUValue(RenderSettings( | 154 settings: asGPUValue(RenderSettings( |
155 gamma: 1.0'f32 | 155 gamma: 0.01'f32 |
156 ), UniformBuffer) | 156 ), UniformBufferMapped) |
157 ) | 157 ) |
158 ) | 158 ) |
159 AssignBuffers(renderdata, quad) | 159 AssignBuffers(renderdata, quad) |
160 AssignBuffers(renderdata, firstDs) | 160 AssignBuffers(renderdata, settings) |
161 renderdata.FlushAllMemory() | 161 renderdata.FlushAllMemory() |
162 | 162 |
163 var pipeline = CreatePipeline[QuadShader](renderPass = mainRenderpass, samples = swapchain.samples) | 163 var pipeline = CreatePipeline[QuadShader](renderPass = mainRenderpass, samples = swapchain.samples) |
164 | |
165 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], settings) | |
164 | 166 |
165 var c = 0 | 167 var c = 0 |
166 while UpdateInputs() and c < nFrames: | 168 while UpdateInputs() and c < nFrames: |
167 WithNextFrame(swapchain, framebuffer, commandbuffer): | 169 WithNextFrame(swapchain, framebuffer, commandbuffer): |
168 WithBind(commandbuffer, firstDs, pipeline, swapchain.currentFiF): | 170 WithBind(commandbuffer, (settings, ), pipeline, swapchain.currentFiF): |
169 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 171 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
170 WithPipeline(commandbuffer, pipeline): | 172 WithPipeline(commandbuffer, pipeline): |
171 Render(commandbuffer = commandbuffer, pipeline = pipeline, firstSet = firstDs, mesh = quad) | 173 Render(commandbuffer = commandbuffer, pipeline = pipeline, firstSet = settings, mesh = quad) |
174 settings.data.settings.data.gamma = 0.01'f32 + (c.float32 / nFrames.float32) * 5'f32 | |
175 UpdateGPUBuffer(settings.data.settings) | |
176 renderdata.FlushAllMemory() | |
172 inc c | 177 inc c |
173 | 178 |
174 # cleanup | 179 # cleanup |
175 checkVkResult vkDeviceWaitIdle(vulkan.device) | 180 checkVkResult vkDeviceWaitIdle(vulkan.device) |
176 DestroyPipeline(pipeline) | 181 DestroyPipeline(pipeline) |
177 DestroyRenderData(renderdata) | 182 DestroyRenderData(renderdata) |
178 | 183 |
179 when isMainModule: | 184 when isMainModule: |
180 var nFrames = 100 | 185 var nFrames = 5000 |
181 InitVulkan() | 186 InitVulkan() |
182 | 187 |
183 # test normal | 188 # test normal |
184 block: | 189 block: |
185 mainRenderpass = CreatePresentationRenderPass() | 190 mainRenderpass = CreatePresentationRenderPass() |
186 swapchain = InitSwapchain(renderpass = mainRenderpass).get() | 191 swapchain = InitSwapchain(renderpass = mainRenderpass).get() |
187 | 192 |
188 # tests a simple triangle with minimalistic shader and vertex format | 193 # tests a simple triangle with minimalistic shader and vertex format |
189 test_01_triangle(nFrames) | 194 # test_01_triangle(nFrames) |
190 | 195 |
191 # tests instanced triangles and quads, mixing meshes and instances | 196 # tests instanced triangles and quads, mixing meshes and instances |
192 test_02_triangle_quad_instanced(nFrames) | 197 # test_02_triangle_quad_instanced(nFrames) |
193 | 198 |
194 # tests | 199 # tests |
195 test_03_global_descriptorset(nFrames) | 200 test_03_global_descriptorset(nFrames) |
196 | 201 |
197 checkVkResult vkDeviceWaitIdle(vulkan.device) | 202 checkVkResult vkDeviceWaitIdle(vulkan.device) |
201 # test MSAA | 206 # test MSAA |
202 block: | 207 block: |
203 mainRenderpass = CreatePresentationRenderPass(samples = VK_SAMPLE_COUNT_4_BIT) | 208 mainRenderpass = CreatePresentationRenderPass(samples = VK_SAMPLE_COUNT_4_BIT) |
204 swapchain = InitSwapchain(renderpass = mainRenderpass, samples = VK_SAMPLE_COUNT_4_BIT).get() | 209 swapchain = InitSwapchain(renderpass = mainRenderpass, samples = VK_SAMPLE_COUNT_4_BIT).get() |
205 | 210 |
206 test_01_triangle(nFrames) | 211 # test_01_triangle(nFrames) |
207 | 212 |
208 checkVkResult vkDeviceWaitIdle(vulkan.device) | 213 checkVkResult vkDeviceWaitIdle(vulkan.device) |
209 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil) | 214 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil) |
210 DestroySwapchain(swapchain) | 215 DestroySwapchain(swapchain) |
211 | 216 |