Mercurial > games > semicongine
annotate tests/test_rendering.nim @ 1332:df3c075e5dea
did: formatting
author | sam <sam@basx.dev> |
---|---|
date | Thu, 22 Aug 2024 18:31:59 +0700 |
parents | 4a1c2b1128bc |
children | d5a6f69dc855 |
rev | line source |
---|---|
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
1 import std/os |
1231 | 2 import std/sequtils |
1299
6d0162bfe48a
did: finish mentioned refactoring, no API changes still
sam <sam@basx.dev>
parents:
1285
diff
changeset
|
3 import std/math |
1232 | 4 import std/monotimes |
5 import std/times | |
1203 | 6 import std/options |
1204 | 7 import std/random |
8 | |
1267 | 9 import ../semicongine |
1203 | 10 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
11 proc test_01_triangle(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
12 var renderdata = initRenderData() |
1203 | 13 |
14 type | |
1252 | 15 PushConstant = object |
16 scale: float32 | |
1332 | 17 |
1242 | 18 Shader = object |
1203 | 19 position {.VertexAttribute.}: Vec3f |
20 color {.VertexAttribute.}: Vec3f | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
21 pushConstant {.PushConstant.}: PushConstant |
1203 | 22 fragmentColor {.Pass.}: Vec3f |
23 outColor {.ShaderOutput.}: Vec4f | |
24 # code | |
1332 | 25 vertexCode: string = |
26 """void main() { | |
1203 | 27 fragmentColor = color; |
1252 | 28 gl_Position = vec4(position * pushConstant.scale, 1);}""" |
1332 | 29 fragmentCode: string = |
30 """void main() { | |
1203 | 31 outColor = vec4(fragmentColor, 1);}""" |
1332 | 32 |
1203 | 33 TriangleMesh = object |
34 position: GPUArray[Vec3f, VertexBuffer] | |
35 color: GPUArray[Vec3f, VertexBuffer] | |
1332 | 36 |
1203 | 37 var mesh = TriangleMesh( |
1332 | 38 position: asGPUArray( |
39 [vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer | |
40 ), | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
41 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1203 | 42 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
43 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
44 renderdata.flushAllMemory() |
1203 | 45 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
46 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1203 | 47 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
48 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
49 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
50 withNextFrame(framebuffer, commandbuffer): |
1332 | 51 withRenderPass( |
52 vulkan.swapchain.renderPass, | |
53 framebuffer, | |
54 commandbuffer, | |
55 vulkan.swapchain.width, | |
56 vulkan.swapchain.height, | |
57 vec4(0, 0, 0, 0), | |
58 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
59 withPipeline(commandbuffer, pipeline): |
1332 | 60 renderWithPushConstant( |
61 commandbuffer = commandbuffer, | |
62 pipeline = pipeline, | |
63 mesh = mesh, | |
64 pushConstant = PushConstant( | |
65 scale: 0.3 + ((getMonoTime() - start).inMilliseconds().int / 1000) | |
66 ), | |
67 ) | |
1203 | 68 |
69 # cleanup | |
1204 | 70 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
71 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
72 destroyRenderData(renderdata) |
1203 | 73 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
74 proc test_02_triangle_quad_instanced(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
75 var renderdata = initRenderData() |
1204 | 76 |
77 type | |
78 SomeShader = object | |
79 position {.VertexAttribute.}: Vec3f | |
80 color {.VertexAttribute.}: Vec3f | |
81 pos {.InstanceAttribute.}: Vec3f | |
82 scale {.InstanceAttribute.}: float32 | |
83 fragmentColor {.Pass.}: Vec3f | |
84 outColor {.ShaderOutput.}: Vec4f | |
85 # code | |
1332 | 86 vertexCode: string = |
87 """void main() { | |
1204 | 88 fragmentColor = color; |
89 gl_Position = vec4((position * scale) + pos, 1);}""" | |
1332 | 90 fragmentCode: string = |
91 """void main() { | |
1204 | 92 outColor = vec4(fragmentColor, 1);}""" |
1332 | 93 |
1204 | 94 TriangleMesh = object |
95 position: GPUArray[Vec3f, VertexBuffer] | |
96 color: GPUArray[Vec3f, VertexBuffer] | |
1332 | 97 |
1204 | 98 QuadMesh = object |
99 position: GPUArray[Vec3f, VertexBuffer] | |
100 color: GPUArray[Vec3f, VertexBuffer] | |
101 indices: GPUArray[uint16, IndexBuffer] | |
1332 | 102 |
1204 | 103 Instances = object |
104 pos: GPUArray[Vec3f, VertexBuffer] | |
105 scale: GPUArray[float32, VertexBuffer] | |
1332 | 106 |
1204 | 107 var tri = TriangleMesh( |
1332 | 108 position: asGPUArray( |
109 [vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer | |
110 ), | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
111 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1204 | 112 ) |
113 var quad = QuadMesh( | |
1332 | 114 position: asGPUArray( |
115 [vec3(-0.3, -0.3, 0), vec3(-0.3, 0.3, 0), vec3(0.3, 0.3, 0), vec3(0.3, -0.3, 0)], | |
116 VertexBuffer, | |
117 ), | |
1204 | 118 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1332 | 119 color: asGPUArray( |
120 [vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1)], VertexBuffer | |
121 ), | |
1204 | 122 ) |
123 | |
124 var instancesA: Instances | |
1332 | 125 for n in 1 .. 100: |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
126 instancesA.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32), 0) |
1204 | 127 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32) |
128 var instancesB: Instances | |
1332 | 129 for n in 1 .. 100: |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
130 instancesB.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32), 0) |
1204 | 131 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32) |
132 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
133 assignBuffers(renderdata, tri) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
134 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
135 assignBuffers(renderdata, instancesA) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
136 assignBuffers(renderdata, instancesB) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
137 renderdata.flushAllMemory() |
1204 | 138 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
139 var pipeline = createPipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 140 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
141 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
142 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
143 withNextFrame(framebuffer, commandbuffer): |
1332 | 144 withRenderPass( |
145 vulkan.swapchain.renderPass, | |
146 framebuffer, | |
147 commandbuffer, | |
148 vulkan.swapchain.width, | |
149 vulkan.swapchain.height, | |
150 vec4(0, 0, 0, 0), | |
151 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
152 withPipeline(commandbuffer, pipeline): |
1332 | 153 render( |
154 commandbuffer = commandbuffer, | |
155 pipeline = pipeline, | |
156 mesh = quad, | |
157 instances = instancesA, | |
158 ) | |
159 render( | |
160 commandbuffer = commandbuffer, | |
161 pipeline = pipeline, | |
162 mesh = quad, | |
163 instances = instancesB, | |
164 ) | |
165 render( | |
166 commandbuffer = commandbuffer, | |
167 pipeline = pipeline, | |
168 mesh = tri, | |
169 instances = instancesA, | |
170 ) | |
171 render( | |
172 commandbuffer = commandbuffer, | |
173 pipeline = pipeline, | |
174 mesh = tri, | |
175 instances = instancesB, | |
176 ) | |
1204 | 177 |
178 # cleanup | |
179 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
180 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
181 destroyRenderData(renderdata) |
1204 | 182 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
183 proc test_03_simple_descriptorset(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
184 var renderdata = initRenderData() |
1210 | 185 |
186 type | |
187 Material = object | |
188 baseColor: Vec3f | |
189 | |
190 Uniforms = object | |
191 material: GPUValue[Material, UniformBuffer] | |
1252 | 192 texture1: Image[BGRA] |
1210 | 193 |
194 QuadShader = object | |
195 position {.VertexAttribute.}: Vec3f | |
196 fragmentColor {.Pass.}: Vec3f | |
197 uv {.Pass.}: Vec2f | |
198 outColor {.ShaderOutput.}: Vec4f | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
199 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1210 | 200 # code |
1332 | 201 vertexCode: string = |
202 """void main() { | |
1210 | 203 fragmentColor = material.baseColor; |
204 gl_Position = vec4(position, 1); | |
205 gl_Position.x += ((material.baseColor.b - 0.5) * 2) - 0.5; | |
206 uv = position.xy + 0.5; | |
207 }""" | |
1332 | 208 fragmentCode: string = |
209 """void main() { | |
1210 | 210 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" |
1332 | 211 |
1210 | 212 QuadMesh = object |
213 position: GPUArray[Vec3f, VertexBuffer] | |
214 indices: GPUArray[uint16, IndexBuffer] | |
215 | |
1252 | 216 let R = BGRA([255'u8, 0'u8, 0'u8, 255'u8]) |
217 let G = BGRA([0'u8, 255'u8, 0'u8, 255'u8]) | |
218 let B = BGRA([0'u8, 0'u8, 255'u8, 255'u8]) | |
219 let W = BGRA([255'u8, 255'u8, 255'u8, 255'u8]) | |
1210 | 220 var |
221 quad = QuadMesh( | |
1332 | 222 position: asGPUArray( |
223 [vec3(-0.5, -0.5, 0), vec3(-0.5, 0.5, 0), vec3(0.5, 0.5, 0), vec3(0.5, -0.5, 0)], | |
224 VertexBuffer, | |
225 ), | |
1210 | 226 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
227 ) | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
228 uniforms1 = asDescriptorSetData( |
1210 | 229 Uniforms( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
230 material: asGPUValue(Material(baseColor: vec3(1, 1, 1)), UniformBuffer), |
1332 | 231 texture1: Image[BGRA]( |
232 width: 3, | |
233 height: 3, | |
234 data: @[R, G, B, G, B, R, B, R, G], | |
235 minInterpolation: VK_FILTER_NEAREST, | |
236 magInterpolation: VK_FILTER_NEAREST, | |
237 ), | |
1210 | 238 ) |
239 ) | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
240 uniforms2 = asDescriptorSetData( |
1210 | 241 Uniforms( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
242 material: asGPUValue(Material(baseColor: vec3(0.5, 0.5, 0.5)), UniformBuffer), |
1252 | 243 texture1: Image[BGRA](width: 2, height: 2, data: @[R, G, B, W]), |
1332 | 244 ) |
1210 | 245 ) |
246 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
247 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
248 assignBuffers(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
249 assignBuffers(renderdata, uniforms2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
250 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
251 uploadImages(renderdata, uniforms2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
252 renderdata.flushAllMemory() |
1210 | 253 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
254 var pipeline = createPipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1210 | 255 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
256 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
257 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) |
1210 | 258 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
259 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
260 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
261 withNextFrame(framebuffer, commandbuffer): |
1332 | 262 withRenderPass( |
263 vulkan.swapchain.renderPass, | |
264 framebuffer, | |
265 commandbuffer, | |
266 vulkan.swapchain.width, | |
267 vulkan.swapchain.height, | |
268 vec4(0, 0, 0, 0), | |
269 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
270 withPipeline(commandbuffer, pipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
271 bindDescriptorSet(commandbuffer, uniforms1, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
272 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 273 |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
274 bindDescriptorSet(commandbuffer, uniforms2, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
275 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1210 | 276 |
277 # cleanup | |
278 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
279 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
280 destroyRenderData(renderdata) |
1210 | 281 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
282 proc test_04_multiple_descriptorsets(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
283 var renderdata = initRenderData() |
1203 | 284 |
1204 | 285 type |
286 RenderSettings = object | |
1209 | 287 brigthness: float32 |
1332 | 288 |
1210 | 289 Material = object |
290 baseColor: Vec3f | |
1332 | 291 |
1209 | 292 ObjectSettings = object |
1210 | 293 scale: float32 |
294 materialIndex: uint32 | |
1332 | 295 |
1210 | 296 Constants = object |
297 offset: Vec2f | |
298 | |
299 ConstSet = object | |
300 constants: GPUValue[Constants, UniformBuffer] | |
1332 | 301 |
1209 | 302 MainSet = object |
303 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] | |
1210 | 304 material: array[2, GPUValue[Material, UniformBuffer]] |
1242 | 305 texture1: array[2, Image[Gray]] |
1332 | 306 |
1209 | 307 OtherSet = object |
1210 | 308 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] |
1209 | 309 |
1204 | 310 QuadShader = object |
311 position {.VertexAttribute.}: Vec3f | |
312 fragmentColor {.Pass.}: Vec3f | |
1210 | 313 uv {.Pass.}: Vec2f |
1204 | 314 outColor {.ShaderOutput.}: Vec4f |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
315 descriptorSets0 {.DescriptorSet: 0.}: ConstSet |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
316 descriptorSets1 {.DescriptorSet: 1.}: MainSet |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
317 descriptorSets2 {.DescriptorSet: 2.}: OtherSet |
1204 | 318 # code |
1332 | 319 vertexCode: string = |
320 """void main() { | |
1210 | 321 fragmentColor = material[objectSettings.materialIndex].baseColor * renderSettings.brigthness; |
322 gl_Position = vec4(position * objectSettings.scale, 1); | |
323 gl_Position.xy += constants.offset.xy; | |
324 gl_Position.x += material[objectSettings.materialIndex].baseColor.b - 0.5; | |
325 uv = position.xy + 0.5; | |
326 }""" | |
1332 | 327 fragmentCode: string = |
328 """void main() { | |
1210 | 329 outColor = vec4(fragmentColor * texture(texture1[objectSettings.materialIndex], uv).rrr, 1); |
330 }""" | |
1332 | 331 |
1204 | 332 QuadMesh = object |
333 position: GPUArray[Vec3f, VertexBuffer] | |
334 indices: GPUArray[uint16, IndexBuffer] | |
1203 | 335 |
1204 | 336 var quad = QuadMesh( |
1332 | 337 position: asGPUArray( |
338 [vec3(-0.5, -0.5), vec3(-0.5, 0.5), vec3(0.5, 0.5), vec3(0.5, -0.5)], VertexBuffer | |
339 ), | |
1204 | 340 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1209 | 341 ) |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
342 var constset = asDescriptorSetData( |
1332 | 343 ConstSet(constants: asGPUValue(Constants(offset: vec2(-0.3, 0.2)), UniformBuffer)) |
1210 | 344 ) |
1242 | 345 let G = Gray([50'u8]) |
346 let W = Gray([255'u8]) | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
347 var mainset = asDescriptorSetData( |
1209 | 348 MainSet( |
349 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), | |
1210 | 350 material: [ |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
351 asGPUValue(Material(baseColor: vec3(1, 1, 0)), UniformBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
352 asGPUValue(Material(baseColor: vec3(1, 0, 1)), UniformBuffer), |
1332 | 353 ], |
354 texture1: [ | |
355 Image[Gray]( | |
356 width: 2, | |
357 height: 2, | |
358 data: @[W, G, G, W], | |
359 minInterpolation: VK_FILTER_NEAREST, | |
360 magInterpolation: VK_FILTER_NEAREST, | |
361 ), | |
362 Image[Gray]( | |
363 width: 3, | |
364 height: 3, | |
365 data: @[W, G, W, G, W, G, W, G, W], | |
366 minInterpolation: VK_FILTER_NEAREST, | |
367 magInterpolation: VK_FILTER_NEAREST, | |
368 ), | |
369 ], | |
370 ) | |
1210 | 371 ) |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
372 var otherset1 = asDescriptorSetData( |
1210 | 373 OtherSet( |
1332 | 374 objectSettings: |
375 asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 0), UniformBufferMapped) | |
1209 | 376 ) |
1204 | 377 ) |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
378 var otherset2 = asDescriptorSetData( |
1209 | 379 OtherSet( |
1332 | 380 objectSettings: |
381 asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 1), UniformBufferMapped) | |
1209 | 382 ) |
1204 | 383 ) |
1209 | 384 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
385 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
386 assignBuffers(renderdata, constset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
387 assignBuffers(renderdata, mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
388 assignBuffers(renderdata, otherset1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
389 assignBuffers(renderdata, otherset2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
390 uploadImages(renderdata, mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
391 renderdata.flushAllMemory() |
1204 | 392 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
393 var pipeline = createPipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 394 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
395 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
396 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
397 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
398 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset2) |
1205
f7530247a21f
did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
399 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
400 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
401 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
402 withNextFrame(framebuffer, commandbuffer): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
403 bindDescriptorSet(commandbuffer, constset, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
404 bindDescriptorSet(commandbuffer, mainset, 1, pipeline) |
1242 | 405 |
1332 | 406 withRenderPass( |
407 vulkan.swapchain.renderPass, | |
408 framebuffer, | |
409 commandbuffer, | |
410 vulkan.swapchain.width, | |
411 vulkan.swapchain.height, | |
412 vec4(0, 0, 0, 0), | |
413 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
414 withPipeline(commandbuffer, pipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
415 bindDescriptorSet(commandbuffer, otherset1, 2, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
416 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 417 |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
418 bindDescriptorSet(commandbuffer, otherset2, 2, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
419 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 420 |
1332 | 421 mainset.data.renderSettings.data.brigthness = |
422 ((getMonoTime() - start).inMilliseconds().int / 1000) / time | |
423 otherset1.data.objectSettings.data.scale = | |
424 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
425 updateGPUBuffer(mainset.data.renderSettings) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
426 updateGPUBuffer(otherset1.data.objectSettings) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
427 renderdata.flushAllMemory() |
1204 | 428 |
429 # cleanup | |
1203 | 430 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
431 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
432 destroyRenderData(renderdata) |
1204 | 433 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
434 proc test_05_cube(time: float32) = |
1231 | 435 type |
436 UniformData = object | |
1232 | 437 mvp: Mat4 |
1332 | 438 |
1231 | 439 Uniforms = object |
440 data: GPUValue[UniformData, UniformBufferMapped] | |
1332 | 441 |
1231 | 442 CubeShader = object |
443 position {.VertexAttribute.}: Vec3f | |
444 color {.VertexAttribute.}: Vec4f | |
445 fragmentColor {.Pass.}: Vec4f | |
446 outColor {.ShaderOutput.}: Vec4f | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
447 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1231 | 448 # code |
1332 | 449 vertexCode = |
450 """void main() { | |
1231 | 451 fragmentColor = color; |
1232 | 452 gl_Position = vec4(position, 1) * data.mvp; |
1231 | 453 }""" |
1332 | 454 fragmentCode = |
455 """void main() { | |
1231 | 456 outColor = fragmentColor; |
457 }""" | |
1332 | 458 |
1231 | 459 Mesh = object |
460 position: GPUArray[Vec3f, VertexBuffer] | |
461 normals: GPUArray[Vec3f, VertexBuffer] | |
462 color: GPUArray[Vec4f, VertexBuffer] | |
463 | |
1332 | 464 let quad = |
465 @[ | |
466 vec3(-0.5, -0.5), | |
467 vec3(-0.5, +0.5), | |
468 vec3(+0.5, +0.5), | |
469 vec3(+0.5, +0.5), | |
470 vec3(+0.5, -0.5), | |
471 vec3(-0.5, -0.5), | |
472 ] | |
1232 | 473 proc transf(data: seq[Vec3f], mat: Mat4): seq[Vec3f] = |
1231 | 474 for v in data: |
1232 | 475 result.add mat * v |
1231 | 476 |
477 var | |
478 vertices: seq[Vec3f] | |
479 colors: seq[Vec4f] | |
480 normals: seq[Vec3f] | |
481 | |
482 # front, red | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
483 vertices.add quad.transf(translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
484 colors.add newSeqWith(6, vec4(1, 0, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
485 normals.add newSeqWith(6, vec3(0, 0, -1)) |
1231 | 486 |
487 # back, cyan | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
488 vertices.add quad.transf(rotate(PI, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
489 colors.add newSeqWith(6, vec4(0, 1, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
490 normals.add newSeqWith(6, vec3(0, 0, 1)) |
1231 | 491 |
492 # right, green | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
493 vertices.add quad.transf(rotate(PI / 2, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
494 colors.add newSeqWith(6, vec4(0, 1, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
495 normals.add newSeqWith(6, vec3(-1, 0, 0)) |
1231 | 496 |
497 # left, magenta | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
498 vertices.add quad.transf(rotate(-PI / 2, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
499 colors.add newSeqWith(6, vec4(1, 0, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
500 normals.add newSeqWith(6, vec3(1, 0, 0)) |
1231 | 501 |
502 # bottom, blue | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
503 vertices.add quad.transf(rotate(PI / 2, X) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
504 colors.add newSeqWith(6, vec4(0, 0, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
505 normals.add newSeqWith(6, vec3(0, -1, 0)) |
1231 | 506 |
507 # top, yellow | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
508 vertices.add quad.transf(rotate(-PI / 2, X) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
509 colors.add newSeqWith(6, vec4(1, 1, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
510 normals.add newSeqWith(6, vec3(0, 1, 0)) |
1231 | 511 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
512 var renderdata = initRenderData() |
1231 | 513 |
514 var mesh = Mesh( | |
515 position: asGPUArray(vertices, VertexBuffer), | |
516 color: asGPUArray(colors, VertexBuffer), | |
517 normals: asGPUArray(normals, VertexBuffer), | |
518 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
519 assignBuffers(renderdata, mesh) |
1231 | 520 |
521 var floor = Mesh( | |
1332 | 522 position: asGPUArray( |
523 quad.transf(scale(10, 10, 10) * rotate(-PI / 2, X) * translate(0, 0, 0.05)), | |
524 VertexBuffer, | |
525 ), | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
526 color: asGPUArray(newSeqWith(6, vec4(0.1, 0.1, 0.1, 1)), VertexBuffer), |
1231 | 527 normals: asGPUArray(newSeqWith(6, Y), VertexBuffer), |
528 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
529 assignBuffers(renderdata, floor) |
1231 | 530 |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
531 var uniforms1 = asDescriptorSetData( |
1332 | 532 Uniforms(data: asGPUValue(UniformData(mvp: Unit4), UniformBufferMapped)) |
1231 | 533 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
534 assignBuffers(renderdata, uniforms1) |
1231 | 535 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
536 renderdata.flushAllMemory() |
1231 | 537 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
538 var pipeline = createPipeline[CubeShader](renderPass = vulkan.swapchain.renderPass) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
539 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
1231 | 540 |
1232 | 541 var tStart = getMonoTime() |
542 var t = tStart | |
1231 | 543 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
544 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
545 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
546 let tStartLoop = getMonoTime() - tStart |
1232 | 547 |
548 uniforms1.data.data.data.mvp = ( | |
1332 | 549 projection(-PI / 2, getAspectRatio(), 0.01, 100) * translate(0, 0, 2) * |
550 rotate(PI / 4, X) * rotate( | |
551 PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y | |
552 ) | |
1232 | 553 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
554 updateGPUBuffer(uniforms1.data.data, flush = true) |
1242 | 555 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
556 withNextFrame(framebuffer, commandbuffer): |
1332 | 557 withRenderPass( |
558 vulkan.swapchain.renderPass, | |
559 framebuffer, | |
560 commandbuffer, | |
561 vulkan.swapchain.width, | |
562 vulkan.swapchain.height, | |
563 vec4(0, 0, 0, 0), | |
564 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
565 withPipeline(commandbuffer, pipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
566 bindDescriptorSet(commandbuffer, uniforms1, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
567 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
568 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) |
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
569 |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
570 let tEndLoop = getMonoTime() - tStart |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
571 let looptime = tEndLoop - tStartLoop |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
572 let waitTime = 16_666 - looptime.inMicroseconds |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
573 if waitTime > 0: |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
574 sleep((waitTime / 1000).int) |
1231 | 575 |
576 # cleanup | |
577 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
578 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
579 destroyRenderData(renderdata) |
1231 | 580 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
581 proc test_06_different_draw_modes(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
582 var renderdata = initRenderData() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
583 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
584 type |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
585 Shader = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
586 position {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
587 color {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
588 fragmentColor {.Pass.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
589 outColor {.ShaderOutput.}: Vec4f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
590 # code |
1332 | 591 vertexCode: string = |
592 """void main() { | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
593 gl_PointSize = 100; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
594 fragmentColor = color; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
595 gl_Position = vec4(position, 1);}""" |
1332 | 596 fragmentCode: string = |
597 """void main() { | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
598 outColor = vec4(fragmentColor, 1);}""" |
1332 | 599 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
600 TriangleMesh = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
601 position: GPUArray[Vec3f, VertexBuffer] |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
602 color: GPUArray[Vec3f, VertexBuffer] |
1332 | 603 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
604 var triangle = TriangleMesh( |
1332 | 605 position: asGPUArray( |
606 [vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer | |
607 ), | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
608 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
609 ) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
610 var lines = TriangleMesh( |
1332 | 611 position: asGPUArray( |
612 [vec3(-0.9, 0, 0), vec3(-0.05, -0.9, 0), vec3(0.05, -0.9, 0), vec3(0.9, 0, 0)], | |
613 VertexBuffer, | |
614 ), | |
615 color: asGPUArray( | |
616 [vec3(1, 1, 0), vec3(1, 1, 0), vec3(0, 1, 0), vec3(0, 1, 0)], VertexBuffer | |
617 ), | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
618 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
619 assignBuffers(renderdata, triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
620 assignBuffers(renderdata, lines) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
621 renderdata.flushAllMemory() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
622 |
1332 | 623 var pipeline1 = createPipeline[Shader]( |
624 renderPass = vulkan.swapchain.renderPass, | |
625 polygonMode = VK_POLYGON_MODE_LINE, | |
626 lineWidth = 20'f32, | |
627 ) | |
628 var pipeline2 = createPipeline[Shader]( | |
629 renderPass = vulkan.swapchain.renderPass, polygonMode = VK_POLYGON_MODE_POINT | |
630 ) | |
631 var pipeline3 = createPipeline[Shader]( | |
632 renderPass = vulkan.swapchain.renderPass, | |
633 topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST, | |
634 lineWidth = 5, | |
635 ) | |
636 var pipeline4 = createPipeline[Shader]( | |
637 renderPass = vulkan.swapchain.renderPass, | |
638 topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST, | |
639 ) | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
640 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
641 var start = getMonoTime() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
642 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
643 withNextFrame(framebuffer, commandbuffer): |
1332 | 644 withRenderPass( |
645 vulkan.swapchain.renderPass, | |
646 framebuffer, | |
647 commandbuffer, | |
648 vulkan.swapchain.width, | |
649 vulkan.swapchain.height, | |
650 vec4(0, 0, 0, 0), | |
651 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
652 withPipeline(commandbuffer, pipeline1): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
653 render(commandbuffer = commandbuffer, pipeline = pipeline1, mesh = triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
654 withPipeline(commandbuffer, pipeline2): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
655 render(commandbuffer = commandbuffer, pipeline = pipeline2, mesh = triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
656 withPipeline(commandbuffer, pipeline3): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
657 render(commandbuffer = commandbuffer, pipeline = pipeline3, mesh = lines) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
658 withPipeline(commandbuffer, pipeline4): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
659 render(commandbuffer = commandbuffer, pipeline = pipeline4, mesh = lines) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
660 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
661 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
662 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
663 destroyPipeline(pipeline1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
664 destroyPipeline(pipeline2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
665 destroyPipeline(pipeline3) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
666 destroyPipeline(pipeline4) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
667 destroyRenderData(renderdata) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
668 |
1242 | 669 proc test_07_png_texture(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
670 var renderdata = initRenderData() |
1242 | 671 |
672 type | |
673 Uniforms = object | |
1252 | 674 texture1: Image[BGRA] |
1332 | 675 |
1242 | 676 Shader = object |
677 position {.VertexAttribute.}: Vec3f | |
678 uv {.VertexAttribute.}: Vec2f | |
679 fragmentUv {.Pass.}: Vec2f | |
680 outColor {.ShaderOutput.}: Vec4f | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
681 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1242 | 682 # code |
1332 | 683 vertexCode: string = |
684 """ | |
1242 | 685 void main() { |
686 fragmentUv = uv; | |
687 gl_Position = vec4(position, 1); | |
688 }""" | |
1332 | 689 fragmentCode: string = |
690 """ | |
1242 | 691 void main() { |
692 outColor = texture(texture1, fragmentUv); | |
693 }""" | |
1332 | 694 |
1242 | 695 Quad = object |
696 position: GPUArray[Vec3f, VertexBuffer] | |
697 uv: GPUArray[Vec2f, VertexBuffer] | |
1332 | 698 |
1242 | 699 var mesh = Quad( |
1332 | 700 position: asGPUArray( |
701 [ | |
702 vec3(-0.8, -0.5), | |
703 vec3(-0.8, 0.5), | |
704 vec3(0.8, 0.5), | |
705 vec3(0.8, 0.5), | |
706 vec3(0.8, -0.5), | |
707 vec3(-0.8, -0.5), | |
708 ], | |
709 VertexBuffer, | |
710 ), | |
711 uv: asGPUArray( | |
712 [vec2(0, 1), vec2(0, 0), vec2(1, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1)], | |
713 VertexBuffer, | |
714 ), | |
1242 | 715 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
716 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
717 renderdata.flushAllMemory() |
1242 | 718 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
719 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1332 | 720 var uniforms1 = asDescriptorSetData(Uniforms(texture1: loadImage[BGRA]("art.png"))) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
721 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
722 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
1242 | 723 |
724 var start = getMonoTime() | |
725 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
726 withNextFrame(framebuffer, commandbuffer): |
1332 | 727 withRenderPass( |
728 vulkan.swapchain.renderPass, | |
729 framebuffer, | |
730 commandbuffer, | |
731 vulkan.swapchain.width, | |
732 vulkan.swapchain.height, | |
733 vec4(0, 0, 0, 0), | |
734 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
735 withPipeline(commandbuffer, pipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
736 bindDescriptorSet(commandbuffer, uniforms1, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
737 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
1242 | 738 |
739 # cleanup | |
740 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
741 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
742 destroyRenderData(renderdata) |
1242 | 743 |
1332 | 744 proc test_08_triangle_2pass( |
745 time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits | |
746 ) = | |
747 var (offscreenRP, presentRP) = | |
748 createIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
749 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
750 setupSwapchain(renderpass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
751 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
752 var renderdata = initRenderData() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
753 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
754 type |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
755 Uniforms = object |
1252 | 756 frameTexture: Image[BGRA] |
1332 | 757 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
758 TriangleShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
759 position {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
760 color {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
761 fragmentColor {.Pass.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
762 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
763 # code |
1332 | 764 vertexCode: string = |
765 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
766 fragmentColor = color; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
767 gl_Position = vec4(position, 1);}""" |
1332 | 768 fragmentCode: string = |
769 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
770 outColor = vec4(fragmentColor, 1);}""" |
1332 | 771 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
772 PresentShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
773 position {.VertexAttribute.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
774 uv {.Pass.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
775 outColor {.ShaderOutput.}: Vec4f |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
776 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
777 # code |
1332 | 778 vertexCode: string = |
779 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
780 uv = ((position + 1) * 0.5) * vec2(1, -1); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
781 gl_Position = vec4(position, 0, 1);}""" |
1332 | 782 fragmentCode: string = |
783 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
784 vec2 uv1 = uv + vec2(0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
785 vec2 uv2 = uv + vec2(0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
786 vec2 uv3 = uv + vec2(-0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
787 vec2 uv4 = uv + vec2(-0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
788 outColor = ( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
789 texture(frameTexture, uv1) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
790 texture(frameTexture, uv2) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
791 texture(frameTexture, uv3) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
792 texture(frameTexture, uv4) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
793 ) / 4; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
794 }""" |
1332 | 795 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
796 TriangleMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
797 position: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
798 color: GPUArray[Vec3f, VertexBuffer] |
1332 | 799 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
800 QuadMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
801 position: GPUArray[Vec2f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
802 indices: GPUArray[uint16, IndexBuffer] |
1332 | 803 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
804 var mesh = TriangleMesh( |
1332 | 805 position: |
806 asGPUArray([vec3(-0.5, -0.5), vec3(0, 0.5), vec3(0.5, -0.5)], VertexBuffer), | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
807 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
808 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
809 var quad = QuadMesh( |
1332 | 810 position: |
811 asGPUArray([vec2(-1, -1), vec2(-1, 1), vec2(1, 1), vec2(1, -1)], VertexBuffer), | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
812 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
813 ) |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
814 var uniforms1 = asDescriptorSetData( |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
815 Uniforms( |
1332 | 816 frameTexture: Image[BGRA]( |
817 width: vulkan.swapchain.width, | |
818 height: vulkan.swapchain.height, | |
819 isRenderTarget: true, | |
820 ) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
821 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
822 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
823 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
824 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
825 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
826 renderdata.flushAllMemory() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
827 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
828 var |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
829 drawPipeline = createPipeline[TriangleShader](renderPass = offscreenRP) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
830 presentPipeline = createPipeline[PresentShader](renderPass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
831 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
832 initDescriptorSet(renderdata, presentPipeline.descriptorSetLayouts[0], uniforms1) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
833 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
834 # create depth buffer images (will not use the one in the swapchain |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
835 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
836 depthImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
837 depthImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
838 depthMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
839 if offscreenRP.depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
840 depthImage = svkCreate2DImage( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
841 width = vulkan.swapchain.width, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
842 height = vulkan.swapchain.height, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
843 format = DEPTH_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
844 usage = [VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
845 samples = offscreenRP.samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
846 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
847 let requirements = svkGetImageMemoryRequirements(depthImage) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
848 depthMemory = svkAllocateMemory( |
1332 | 849 requirements.size, bestMemory(mappable = false, filter = requirements.memoryTypes) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
850 ) |
1332 | 851 checkVkResult vkBindImageMemory(vulkan.device, depthImage, depthMemory, 0) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
852 depthImageView = svkCreate2DImageView( |
1332 | 853 image = depthImage, format = DEPTH_FORMAT, aspect = VK_IMAGE_ASPECT_DEPTH_BIT |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
854 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
855 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
856 # create msaa images (will not use the one in the swapchain |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
857 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
858 msaaImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
859 msaaImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
860 msaaMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
861 if offscreenRP.samples != VK_SAMPLE_COUNT_1_BIT: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
862 msaaImage = svkCreate2DImage( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
863 width = vulkan.swapchain.width, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
864 height = vulkan.swapchain.height, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
865 format = SURFACE_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
866 usage = [VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
867 samples = offscreenRP.samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
868 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
869 let requirements = svkGetImageMemoryRequirements(msaaImage) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
870 msaaMemory = svkAllocateMemory( |
1332 | 871 requirements.size, bestMemory(mappable = false, filter = requirements.memoryTypes) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
872 ) |
1332 | 873 checkVkResult vkBindImageMemory(vulkan.device, msaaImage, msaaMemory, 0) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
874 msaaImageView = svkCreate2DImageView(image = msaaImage, format = SURFACE_FORMAT) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
875 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
876 var attachments: seq[VkImageView] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
877 if offscreenRP.samples == VK_SAMPLE_COUNT_1_BIT: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
878 if offscreenRP.depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
879 attachments = @[uniforms1.data.frameTexture.imageview, depthImageView] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
880 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
881 attachments = @[uniforms1.data.frameTexture.imageview] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
882 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
883 if offscreenRP.depthBuffer: |
1332 | 884 attachments = |
885 @[msaaImageView, depthImageView, uniforms1.data.frameTexture.imageview] | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
886 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
887 attachments = @[msaaImageView, uniforms1.data.frameTexture.imageview] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
888 var offscreenFB = svkCreateFramebuffer( |
1332 | 889 offscreenRP.vk, vulkan.swapchain.width, vulkan.swapchain.height, attachments |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
890 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
891 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
892 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
893 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
894 withNextFrame(framebuffer, commandbuffer): |
1332 | 895 withRenderPass( |
896 offscreenRP, | |
897 offscreenFB, | |
898 commandbuffer, | |
899 vulkan.swapchain.width, | |
900 vulkan.swapchain.height, | |
901 vec4(0, 0, 0, 0), | |
902 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
903 withPipeline(commandbuffer, drawPipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
904 render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
905 |
1332 | 906 withRenderPass( |
907 presentRP, | |
908 framebuffer, | |
909 commandbuffer, | |
910 vulkan.swapchain.width, | |
911 vulkan.swapchain.height, | |
912 vec4(0, 0, 0, 0), | |
913 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
914 withPipeline(commandbuffer, presentPipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
915 bindDescriptorSet(commandbuffer, uniforms1, 0, presentPipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
916 render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
917 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
918 # cleanup |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
919 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
920 destroyPipeline(presentPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
921 destroyPipeline(drawPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
922 destroyRenderData(renderdata) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
923 if depthImage.Valid: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
924 vkDestroyImageView(vulkan.device, depthImageView, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
925 vkDestroyImage(vulkan.device, depthImage, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
926 vkFreeMemory(vulkan.device, depthMemory, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
927 if msaaImage.Valid: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
928 vkDestroyImageView(vulkan.device, msaaImageView, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
929 vkDestroyImage(vulkan.device, msaaImage, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
930 vkFreeMemory(vulkan.device, msaaMemory, nil) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
931 destroyRenderPass(offscreenRP) |
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
932 destroyRenderPass(presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
933 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
934 clearSwapchain() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
935 |
1204 | 936 when isMainModule: |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
937 var time = 1'f32 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
938 initVulkan() |
1204 | 939 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
940 var mainRenderpass: RenderPass |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
941 var renderPasses = [ |
1332 | 942 (depthBuffer: false, samples: VK_SAMPLE_COUNT_1_BIT), |
943 (depthBuffer: false, samples: VK_SAMPLE_COUNT_4_BIT), | |
944 (depthBuffer: true, samples: VK_SAMPLE_COUNT_1_BIT), | |
945 (depthBuffer: true, samples: VK_SAMPLE_COUNT_4_BIT), | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
946 ] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
947 |
1204 | 948 # test normal |
1230 | 949 for i, (depthBuffer, samples) in renderPasses: |
1332 | 950 var renderpass = |
951 createDirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
952 setupSwapchain(renderpass = renderpass) |
1204 | 953 |
1230 | 954 # tests a simple triangle with minimalistic shader and vertex format |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
955 test_01_triangle(time) |
1230 | 956 |
957 # tests instanced triangles and quads, mixing meshes and instances | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
958 test_02_triangle_quad_instanced(time) |
1210 | 959 |
1230 | 960 # teste descriptor sets |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
961 test_03_simple_descriptorset(time) |
1204 | 962 |
1230 | 963 # tests multiple descriptor sets and arrays |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
964 test_04_multiple_descriptorsets(time) |
1231 | 965 |
966 # rotating cube | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
967 test_05_cube(time) |
1204 | 968 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
969 # different draw modes (lines, points, and topologies) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
970 test_06_different_draw_modes(time) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
971 |
1242 | 972 # load PNG texture |
973 test_07_png_texture(time) | |
974 | |
1230 | 975 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
976 destroyRenderPass(renderpass) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
977 clearSwapchain() |
1204 | 978 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
979 # test multiple render passes |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
980 for i, (depthBuffer, samples) in renderPasses: |
1242 | 981 test_08_triangle_2pass(time, depthBuffer, samples) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
982 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
983 destroyVulkan() |