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