Mercurial > games > semicongine
annotate tests/test_rendering.nim @ 1363:ce92db0b8f50
add: allow configuration of triple buffering
author | sam <sam@basx.dev> |
---|---|
date | Tue, 05 Nov 2024 23:02:32 +0700 |
parents | d5a6f69dc855 |
children |
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 |
1334 | 669 proc test_08_texture_array(time: float32) = |
670 var renderdata = initRenderData() | |
671 | |
672 type | |
673 Uniforms = object | |
674 textures: ImageArray[BGRA] | |
675 | |
676 Shader = object | |
677 position {.VertexAttribute.}: Vec3f | |
678 uv {.VertexAttribute.}: Vec2f | |
679 fragmentUv {.Pass.}: Vec2f | |
680 outColor {.ShaderOutput.}: Vec4f | |
681 descriptorSets {.DescriptorSet: 0.}: Uniforms | |
682 # code | |
683 vertexCode: string = | |
684 """ | |
685 void main() { | |
686 fragmentUv = uv; | |
687 gl_Position = vec4(position, 1); | |
688 }""" | |
689 fragmentCode: string = | |
690 """ | |
691 void main() { | |
692 vec4 col1 = texture(textures, vec3(fragmentUv, 0)); | |
693 vec4 col2 = texture(textures, vec3(fragmentUv, 1)); | |
694 float w = length(fragmentUv * 2 - 1) / 1.41421; | |
695 outColor = (1 - w) * col1 + w * col2; | |
696 }""" | |
697 | |
698 Quad = object | |
699 position: GPUArray[Vec3f, VertexBuffer] | |
700 uv: GPUArray[Vec2f, VertexBuffer] | |
701 | |
702 var mesh = Quad( | |
703 position: asGPUArray( | |
704 [ | |
705 vec3(-0.8, -0.5), | |
706 vec3(-0.8, 0.5), | |
707 vec3(0.8, 0.5), | |
708 vec3(0.8, 0.5), | |
709 vec3(0.8, -0.5), | |
710 vec3(-0.8, -0.5), | |
711 ], | |
712 VertexBuffer, | |
713 ), | |
714 uv: asGPUArray( | |
715 [vec2(0, 1), vec2(0, 0), vec2(1, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1)], | |
716 VertexBuffer, | |
717 ), | |
718 ) | |
719 assignBuffers(renderdata, mesh) | |
720 renderdata.flushAllMemory() | |
721 | |
722 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) | |
723 var uniforms1 = asDescriptorSetData( | |
724 Uniforms(textures: loadImageArray[BGRA](["art.png", "art1.png"])) | |
725 ) | |
726 uploadImages(renderdata, uniforms1) | |
727 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | |
728 | |
729 var start = getMonoTime() | |
730 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
731 withNextFrame(framebuffer, commandbuffer): | |
732 withRenderPass( | |
733 vulkan.swapchain.renderPass, | |
734 framebuffer, | |
735 commandbuffer, | |
736 vulkan.swapchain.width, | |
737 vulkan.swapchain.height, | |
738 vec4(0, 0, 0, 0), | |
739 ): | |
740 withPipeline(commandbuffer, pipeline): | |
741 bindDescriptorSet(commandbuffer, uniforms1, 0, pipeline) | |
742 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | |
743 | |
744 # cleanup | |
745 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
746 destroyPipeline(pipeline) | |
747 destroyRenderData(renderdata) | |
748 | |
1242 | 749 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
|
750 var renderdata = initRenderData() |
1242 | 751 |
752 type | |
753 Uniforms = object | |
1252 | 754 texture1: Image[BGRA] |
1332 | 755 |
1242 | 756 Shader = object |
757 position {.VertexAttribute.}: Vec3f | |
758 uv {.VertexAttribute.}: Vec2f | |
759 fragmentUv {.Pass.}: Vec2f | |
760 outColor {.ShaderOutput.}: Vec4f | |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
761 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1242 | 762 # code |
1332 | 763 vertexCode: string = |
764 """ | |
1242 | 765 void main() { |
766 fragmentUv = uv; | |
767 gl_Position = vec4(position, 1); | |
768 }""" | |
1332 | 769 fragmentCode: string = |
770 """ | |
1242 | 771 void main() { |
772 outColor = texture(texture1, fragmentUv); | |
773 }""" | |
1332 | 774 |
1242 | 775 Quad = object |
776 position: GPUArray[Vec3f, VertexBuffer] | |
777 uv: GPUArray[Vec2f, VertexBuffer] | |
1332 | 778 |
1242 | 779 var mesh = Quad( |
1332 | 780 position: asGPUArray( |
781 [ | |
782 vec3(-0.8, -0.5), | |
783 vec3(-0.8, 0.5), | |
784 vec3(0.8, 0.5), | |
785 vec3(0.8, 0.5), | |
786 vec3(0.8, -0.5), | |
787 vec3(-0.8, -0.5), | |
788 ], | |
789 VertexBuffer, | |
790 ), | |
791 uv: asGPUArray( | |
792 [vec2(0, 1), vec2(0, 0), vec2(1, 0), vec2(1, 0), vec2(1, 1), vec2(0, 1)], | |
793 VertexBuffer, | |
794 ), | |
1242 | 795 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
796 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
797 renderdata.flushAllMemory() |
1242 | 798 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
799 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1332 | 800 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
|
801 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
802 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
1242 | 803 |
804 var start = getMonoTime() | |
805 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
|
806 withNextFrame(framebuffer, commandbuffer): |
1332 | 807 withRenderPass( |
808 vulkan.swapchain.renderPass, | |
809 framebuffer, | |
810 commandbuffer, | |
811 vulkan.swapchain.width, | |
812 vulkan.swapchain.height, | |
813 vec4(0, 0, 0, 0), | |
814 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
815 withPipeline(commandbuffer, pipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
816 bindDescriptorSet(commandbuffer, uniforms1, 0, pipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
817 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
1242 | 818 |
819 # cleanup | |
820 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
|
821 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
822 destroyRenderData(renderdata) |
1242 | 823 |
1334 | 824 proc test_09_triangle_2pass( |
1332 | 825 time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits |
826 ) = | |
827 var (offscreenRP, presentRP) = | |
828 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
|
829 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
830 setupSwapchain(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 var renderdata = initRenderData() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
833 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
834 type |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
835 Uniforms = object |
1252 | 836 frameTexture: Image[BGRA] |
1332 | 837 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
838 TriangleShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
839 position {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
840 color {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
841 fragmentColor {.Pass.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
842 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
843 # code |
1332 | 844 vertexCode: string = |
845 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
846 fragmentColor = color; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
847 gl_Position = vec4(position, 1);}""" |
1332 | 848 fragmentCode: string = |
849 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
850 outColor = vec4(fragmentColor, 1);}""" |
1332 | 851 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
852 PresentShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
853 position {.VertexAttribute.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
854 uv {.Pass.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
855 outColor {.ShaderOutput.}: Vec4f |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
856 descriptorSets {.DescriptorSet: 0.}: Uniforms |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
857 # code |
1332 | 858 vertexCode: string = |
859 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
860 uv = ((position + 1) * 0.5) * vec2(1, -1); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
861 gl_Position = vec4(position, 0, 1);}""" |
1332 | 862 fragmentCode: string = |
863 """void main() { | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
864 vec2 uv1 = uv + vec2(0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
865 vec2 uv2 = uv + vec2(0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
866 vec2 uv3 = uv + vec2(-0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
867 vec2 uv4 = uv + vec2(-0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
868 outColor = ( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
869 texture(frameTexture, uv1) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
870 texture(frameTexture, uv2) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
871 texture(frameTexture, uv3) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
872 texture(frameTexture, uv4) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
873 ) / 4; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
874 }""" |
1332 | 875 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
876 TriangleMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
877 position: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
878 color: GPUArray[Vec3f, VertexBuffer] |
1332 | 879 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
880 QuadMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
881 position: GPUArray[Vec2f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
882 indices: GPUArray[uint16, IndexBuffer] |
1332 | 883 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
884 var mesh = TriangleMesh( |
1332 | 885 position: |
886 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
|
887 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
|
888 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
889 var quad = QuadMesh( |
1332 | 890 position: |
891 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
|
892 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
|
893 ) |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
894 var uniforms1 = asDescriptorSetData( |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
895 Uniforms( |
1332 | 896 frameTexture: Image[BGRA]( |
897 width: vulkan.swapchain.width, | |
898 height: vulkan.swapchain.height, | |
899 isRenderTarget: true, | |
900 ) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
901 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
902 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
903 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
904 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
905 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
906 renderdata.flushAllMemory() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
907 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
908 var |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
909 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
|
910 presentPipeline = createPipeline[PresentShader](renderPass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
911 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
912 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
|
913 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
914 # 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
|
915 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
916 depthImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
917 depthImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
918 depthMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
919 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
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
927 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
|
928 depthMemory = svkAllocateMemory( |
1332 | 929 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
|
930 ) |
1332 | 931 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
|
932 depthImageView = svkCreate2DImageView( |
1332 | 933 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
|
934 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
935 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
936 # 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
|
937 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
938 msaaImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
939 msaaImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
940 msaaMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
941 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
|
942 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
|
943 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
|
944 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
|
945 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
|
946 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
|
947 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
|
948 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
949 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
|
950 msaaMemory = svkAllocateMemory( |
1332 | 951 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
|
952 ) |
1332 | 953 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
|
954 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
|
955 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 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
|
960 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
961 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
|
962 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
963 if offscreenRP.depthBuffer: |
1332 | 964 attachments = |
965 @[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
|
966 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
967 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
|
968 var offscreenFB = svkCreateFramebuffer( |
1332 | 969 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
|
970 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
971 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
972 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
973 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
|
974 withNextFrame(framebuffer, commandbuffer): |
1332 | 975 withRenderPass( |
976 offscreenRP, | |
977 offscreenFB, | |
978 commandbuffer, | |
979 vulkan.swapchain.width, | |
980 vulkan.swapchain.height, | |
981 vec4(0, 0, 0, 0), | |
982 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
983 withPipeline(commandbuffer, drawPipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
984 render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
985 |
1332 | 986 withRenderPass( |
987 presentRP, | |
988 framebuffer, | |
989 commandbuffer, | |
990 vulkan.swapchain.width, | |
991 vulkan.swapchain.height, | |
992 vec4(0, 0, 0, 0), | |
993 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
994 withPipeline(commandbuffer, presentPipeline): |
1322
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
995 bindDescriptorSet(commandbuffer, uniforms1, 0, presentPipeline) |
4a1c2b1128bc
did: improve handling of descriptor sets
sam <sam@basx.dev>
parents:
1299
diff
changeset
|
996 render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
997 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
998 # cleanup |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
999 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
|
1000 destroyPipeline(presentPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
1001 destroyPipeline(drawPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 vkFreeMemory(vulkan.device, msaaMemory, nil) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
1011 destroyRenderPass(offscreenRP) |
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
1012 destroyRenderPass(presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
1013 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
|
1014 clearSwapchain() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
1015 |
1204 | 1016 when isMainModule: |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
1017 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
|
1018 initVulkan() |
1204 | 1019 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
1020 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
|
1021 var renderPasses = [ |
1332 | 1022 (depthBuffer: false, samples: VK_SAMPLE_COUNT_1_BIT), |
1023 (depthBuffer: false, samples: VK_SAMPLE_COUNT_4_BIT), | |
1024 (depthBuffer: true, samples: VK_SAMPLE_COUNT_1_BIT), | |
1025 (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
|
1026 ] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
1027 |
1204 | 1028 # test normal |
1230 | 1029 for i, (depthBuffer, samples) in renderPasses: |
1332 | 1030 var renderpass = |
1031 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
|
1032 setupSwapchain(renderpass = renderpass) |
1204 | 1033 |
1230 | 1034 # tests a simple triangle with minimalistic shader and vertex format |
1334 | 1035 # test_01_triangle(time) |
1230 | 1036 |
1037 # tests instanced triangles and quads, mixing meshes and instances | |
1334 | 1038 # test_02_triangle_quad_instanced(time) |
1210 | 1039 |
1230 | 1040 # teste descriptor sets |
1334 | 1041 # test_03_simple_descriptorset(time) |
1204 | 1042 |
1230 | 1043 # tests multiple descriptor sets and arrays |
1334 | 1044 # test_04_multiple_descriptorsets(time) |
1231 | 1045 |
1046 # rotating cube | |
1334 | 1047 # test_05_cube(time) |
1204 | 1048 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
1049 # different draw modes (lines, points, and topologies) |
1334 | 1050 # test_06_different_draw_modes(time) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
1051 |
1334 | 1052 # test_07_png_texture(time) |
1053 | |
1054 test_08_texture_array(time) | |
1242 | 1055 |
1230 | 1056 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
1057 destroyRenderPass(renderpass) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
1058 clearSwapchain() |
1204 | 1059 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
1060 # test multiple render passes |
1334 | 1061 # for i, (depthBuffer, samples) in renderPasses: |
1062 # test_09_triangle_2pass(time, depthBuffer, samples) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
1063 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
1064 destroyVulkan() |