Mercurial > games > semicongine
annotate tests/test_rendering.nim @ 1246:356089365076
add: gltf model for tests
author | sam <sam@basx.dev> |
---|---|
date | Wed, 24 Jul 2024 20:12:19 +0700 |
parents | e8b3dc80e48e |
children | 01e9f41d35b1 |
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 |
1232 | 3 import std/monotimes |
4 import std/times | |
1203 | 5 import std/options |
1204 | 6 import std/random |
7 | |
1223
55896320c8bf
fix: references to new package not updated
sam <sam@basx.dev>
parents:
1214
diff
changeset
|
8 import ../semiconginev2 |
1203 | 9 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
10 proc test_01_triangle(time: float32) = |
1203 | 11 var renderdata = InitRenderData() |
12 | |
13 type | |
1242 | 14 Shader = object |
1203 | 15 position {.VertexAttribute.}: Vec3f |
16 color {.VertexAttribute.}: Vec3f | |
17 fragmentColor {.Pass.}: Vec3f | |
18 outColor {.ShaderOutput.}: Vec4f | |
19 # code | |
20 vertexCode: string = """void main() { | |
21 fragmentColor = color; | |
22 gl_Position = vec4(position, 1);}""" | |
23 fragmentCode: string = """void main() { | |
24 outColor = vec4(fragmentColor, 1);}""" | |
25 TriangleMesh = object | |
26 position: GPUArray[Vec3f, VertexBuffer] | |
27 color: GPUArray[Vec3f, VertexBuffer] | |
28 var mesh = TriangleMesh( | |
1204 | 29 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
1203 | 30 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
31 ) | |
1204 | 32 AssignBuffers(renderdata, mesh) |
33 renderdata.FlushAllMemory() | |
1203 | 34 |
1242 | 35 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1203 | 36 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
37 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
38 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 39 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
40 WithNextFrame(framebuffer, commandbuffer): |
1242 | 41 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
42 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1242 | 43 |
1203 | 44 WithPipeline(commandbuffer, pipeline): |
1242 | 45 |
1204 | 46 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
1203 | 47 |
48 # cleanup | |
1204 | 49 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1203 | 50 DestroyPipeline(pipeline) |
51 DestroyRenderData(renderdata) | |
52 | |
53 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
54 proc test_02_triangle_quad_instanced(time: float32) = |
1204 | 55 var renderdata = InitRenderData() |
56 | |
57 type | |
58 SomeShader = object | |
59 position {.VertexAttribute.}: Vec3f | |
60 color {.VertexAttribute.}: Vec3f | |
61 pos {.InstanceAttribute.}: Vec3f | |
62 scale {.InstanceAttribute.}: float32 | |
63 fragmentColor {.Pass.}: Vec3f | |
64 outColor {.ShaderOutput.}: Vec4f | |
65 # code | |
66 vertexCode: string = """void main() { | |
67 fragmentColor = color; | |
68 gl_Position = vec4((position * scale) + pos, 1);}""" | |
69 fragmentCode: string = """void main() { | |
70 outColor = vec4(fragmentColor, 1);}""" | |
71 TriangleMesh = object | |
72 position: GPUArray[Vec3f, VertexBuffer] | |
73 color: GPUArray[Vec3f, VertexBuffer] | |
74 QuadMesh = object | |
75 position: GPUArray[Vec3f, VertexBuffer] | |
76 color: GPUArray[Vec3f, VertexBuffer] | |
77 indices: GPUArray[uint16, IndexBuffer] | |
78 Instances = object | |
79 pos: GPUArray[Vec3f, VertexBuffer] | |
80 scale: GPUArray[float32, VertexBuffer] | |
81 var tri = TriangleMesh( | |
82 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
83 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | |
84 ) | |
85 var quad = QuadMesh( | |
86 position: asGPUArray([NewVec3f(-0.3, -0.3), NewVec3f(-0.3, 0.3), NewVec3f(0.3, 0.3), NewVec3f(0.3, -0.3)], VertexBuffer), | |
87 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | |
88 color: asGPUArray([NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1)], VertexBuffer), | |
89 ) | |
90 | |
91 var instancesA: Instances | |
92 for n in 1..100: | |
93 instancesA.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32)) | |
94 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32) | |
95 var instancesB: Instances | |
96 for n in 1..100: | |
97 instancesB.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32)) | |
98 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32) | |
99 | |
100 AssignBuffers(renderdata, tri) | |
101 AssignBuffers(renderdata, quad) | |
102 AssignBuffers(renderdata, instancesA) | |
103 AssignBuffers(renderdata, instancesB) | |
104 renderdata.FlushAllMemory() | |
105 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
106 var pipeline = CreatePipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 107 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
108 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
109 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 110 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
111 WithNextFrame(framebuffer, commandbuffer): |
1242 | 112 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
113 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1242 | 114 |
1204 | 115 WithPipeline(commandbuffer, pipeline): |
1242 | 116 |
1204 | 117 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) |
118 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) | |
119 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) | |
120 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) | |
121 | |
122 # cleanup | |
123 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
124 DestroyPipeline(pipeline) | |
125 DestroyRenderData(renderdata) | |
126 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
127 proc test_03_simple_descriptorset(time: float32) = |
1210 | 128 var renderdata = InitRenderData() |
129 | |
130 type | |
131 Material = object | |
132 baseColor: Vec3f | |
133 | |
134 Uniforms = object | |
135 material: GPUValue[Material, UniformBuffer] | |
1242 | 136 texture1: Image[RGBA] |
1210 | 137 |
138 QuadShader = object | |
139 position {.VertexAttribute.}: Vec3f | |
140 fragmentColor {.Pass.}: Vec3f | |
141 uv {.Pass.}: Vec2f | |
142 outColor {.ShaderOutput.}: Vec4f | |
143 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
144 # code | |
145 vertexCode: string = """void main() { | |
146 fragmentColor = material.baseColor; | |
147 gl_Position = vec4(position, 1); | |
148 gl_Position.x += ((material.baseColor.b - 0.5) * 2) - 0.5; | |
149 uv = position.xy + 0.5; | |
150 }""" | |
151 fragmentCode: string = """void main() { | |
152 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" | |
153 QuadMesh = object | |
154 position: GPUArray[Vec3f, VertexBuffer] | |
155 indices: GPUArray[uint16, IndexBuffer] | |
156 | |
1242 | 157 let R = RGBA([255'u8, 0'u8, 0'u8, 255'u8]) |
158 let G = RGBA([0'u8, 255'u8, 0'u8, 255'u8]) | |
159 let B = RGBA([0'u8, 0'u8, 255'u8, 255'u8]) | |
160 let W = RGBA([255'u8, 255'u8, 255'u8, 255'u8]) | |
1210 | 161 var |
162 quad = QuadMesh( | |
163 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
164 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | |
165 ) | |
166 uniforms1 = asDescriptorSet( | |
167 Uniforms( | |
168 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), | |
1242 | 169 texture1: Image[RGBA](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST), |
1210 | 170 ) |
171 ) | |
172 uniforms2 = asDescriptorSet( | |
173 Uniforms( | |
174 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), | |
1242 | 175 texture1: Image[RGBA](width: 2, height: 2, data: @[R, G, B, W]), |
1212
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
176 ) |
1210 | 177 ) |
178 | |
179 AssignBuffers(renderdata, quad) | |
180 AssignBuffers(renderdata, uniforms1) | |
181 AssignBuffers(renderdata, uniforms2) | |
1228 | 182 UploadImages(renderdata, uniforms1) |
183 UploadImages(renderdata, uniforms2) | |
1210 | 184 renderdata.FlushAllMemory() |
185 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
186 var pipeline = CreatePipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1210 | 187 |
188 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | |
189 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) | |
190 | |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
191 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
192 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 193 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
194 WithNextFrame(framebuffer, commandbuffer): |
1242 | 195 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
196 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1242 | 197 |
1210 | 198 WithPipeline(commandbuffer, pipeline): |
1242 | 199 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
200 WithBind(commandbuffer, (uniforms1, ), pipeline): |
1210 | 201 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 202 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
203 WithBind(commandbuffer, (uniforms2, ), pipeline): |
1210 | 204 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
205 | |
206 # cleanup | |
207 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
208 DestroyPipeline(pipeline) | |
209 DestroyRenderData(renderdata) | |
210 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
211 proc test_04_multiple_descriptorsets(time: float32) = |
1204 | 212 var renderdata = InitRenderData() |
1203 | 213 |
1204 | 214 type |
215 RenderSettings = object | |
1209 | 216 brigthness: float32 |
1210 | 217 Material = object |
218 baseColor: Vec3f | |
1209 | 219 ObjectSettings = object |
1210 | 220 scale: float32 |
221 materialIndex: uint32 | |
222 Constants = object | |
223 offset: Vec2f | |
224 | |
225 ConstSet = object | |
226 constants: GPUValue[Constants, UniformBuffer] | |
1209 | 227 MainSet = object |
228 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] | |
1210 | 229 material: array[2, GPUValue[Material, UniformBuffer]] |
1242 | 230 texture1: array[2, Image[Gray]] |
1209 | 231 OtherSet = object |
1210 | 232 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] |
1209 | 233 |
1204 | 234 QuadShader = object |
235 position {.VertexAttribute.}: Vec3f | |
236 fragmentColor {.Pass.}: Vec3f | |
1210 | 237 uv {.Pass.}: Vec2f |
1204 | 238 outColor {.ShaderOutput.}: Vec4f |
1210 | 239 descriptorSets {.DescriptorSets.}: (ConstSet, MainSet, OtherSet) |
1204 | 240 # code |
241 vertexCode: string = """void main() { | |
1210 | 242 fragmentColor = material[objectSettings.materialIndex].baseColor * renderSettings.brigthness; |
243 gl_Position = vec4(position * objectSettings.scale, 1); | |
244 gl_Position.xy += constants.offset.xy; | |
245 gl_Position.x += material[objectSettings.materialIndex].baseColor.b - 0.5; | |
246 uv = position.xy + 0.5; | |
247 }""" | |
1204 | 248 fragmentCode: string = """void main() { |
1210 | 249 outColor = vec4(fragmentColor * texture(texture1[objectSettings.materialIndex], uv).rrr, 1); |
250 }""" | |
1204 | 251 QuadMesh = object |
252 position: GPUArray[Vec3f, VertexBuffer] | |
253 indices: GPUArray[uint16, IndexBuffer] | |
1203 | 254 |
1204 | 255 var quad = QuadMesh( |
1209 | 256 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
1204 | 257 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1209 | 258 ) |
1210 | 259 var constset = asDescriptorSet( |
260 ConstSet( | |
261 constants: asGPUValue(Constants(offset: NewVec2f(-0.3, 0.2)), UniformBuffer), | |
262 ) | |
263 ) | |
1242 | 264 let G = Gray([50'u8]) |
265 let W = Gray([255'u8]) | |
1210 | 266 var mainset = asDescriptorSet( |
1209 | 267 MainSet( |
268 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), | |
1210 | 269 material: [ |
270 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), | |
271 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), | |
272 ], | |
273 texture1: [ | |
1242 | 274 Image[Gray](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST), |
275 Image[Gray](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST), | |
1210 | 276 ], |
277 ), | |
278 ) | |
279 var otherset1 = asDescriptorSet( | |
280 OtherSet( | |
281 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 0), UniformBufferMapped), | |
1209 | 282 ) |
1204 | 283 ) |
1210 | 284 var otherset2 = asDescriptorSet( |
1209 | 285 OtherSet( |
1210 | 286 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 1), UniformBufferMapped), |
1209 | 287 ) |
1204 | 288 ) |
1209 | 289 |
1204 | 290 AssignBuffers(renderdata, quad) |
1210 | 291 AssignBuffers(renderdata, constset) |
292 AssignBuffers(renderdata, mainset) | |
293 AssignBuffers(renderdata, otherset1) | |
294 AssignBuffers(renderdata, otherset2) | |
1228 | 295 UploadImages(renderdata, mainset) |
1204 | 296 renderdata.FlushAllMemory() |
297 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
298 var pipeline = CreatePipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 299 |
1210 | 300 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) |
301 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) | |
302 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) | |
303 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
|
304 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
305 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
306 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 307 |
308 WithNextFrame(framebuffer, commandbuffer): | |
309 | |
310 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
311 | |
312 WithPipeline(commandbuffer, pipeline): | |
313 | |
314 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline): | |
315 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
316 | |
317 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline): | |
318 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
319 | |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
320 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
321 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
1210 | 322 UpdateGPUBuffer(mainset.data.renderSettings) |
323 UpdateGPUBuffer(otherset1.data.objectSettings) | |
1205
f7530247a21f
did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
324 renderdata.FlushAllMemory() |
1204 | 325 |
326 # cleanup | |
1203 | 327 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1204 | 328 DestroyPipeline(pipeline) |
329 DestroyRenderData(renderdata) | |
330 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
331 proc test_05_cube(time: float32) = |
1231 | 332 type |
333 | |
334 UniformData = object | |
1232 | 335 mvp: Mat4 |
1231 | 336 Uniforms = object |
337 data: GPUValue[UniformData, UniformBufferMapped] | |
338 CubeShader = object | |
339 position {.VertexAttribute.}: Vec3f | |
340 color {.VertexAttribute.}: Vec4f | |
341 fragmentColor {.Pass.}: Vec4f | |
342 outColor {.ShaderOutput.}: Vec4f | |
343 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
344 # code | |
345 vertexCode = """void main() { | |
346 fragmentColor = color; | |
1232 | 347 gl_Position = vec4(position, 1) * data.mvp; |
1231 | 348 }""" |
349 fragmentCode = """void main() { | |
350 outColor = fragmentColor; | |
351 }""" | |
352 Mesh = object | |
353 position: GPUArray[Vec3f, VertexBuffer] | |
354 normals: GPUArray[Vec3f, VertexBuffer] | |
355 color: GPUArray[Vec4f, VertexBuffer] | |
356 | |
357 let quad = @[ | |
358 NewVec3f(-0.5, -0.5), NewVec3f(-0.5, +0.5), NewVec3f(+0.5, +0.5), | |
359 NewVec3f(+0.5, +0.5), NewVec3f(+0.5, -0.5), NewVec3f(-0.5, -0.5), | |
360 ] | |
1232 | 361 proc transf(data: seq[Vec3f], mat: Mat4): seq[Vec3f] = |
1231 | 362 for v in data: |
1232 | 363 result.add mat * v |
1231 | 364 |
365 var | |
366 vertices: seq[Vec3f] | |
367 colors: seq[Vec4f] | |
368 normals: seq[Vec3f] | |
369 | |
370 # front, red | |
371 vertices.add quad.transf(Translate(0, 0, -0.5)) | |
372 colors.add newSeqWith(6, NewVec4f(1, 0, 0, 1)) | |
373 normals.add newSeqWith(6, NewVec3f(0, 0, -1)) | |
374 | |
375 # back, cyan | |
376 vertices.add quad.transf(Rotate(PI, Y) * Translate(0, 0, -0.5)) | |
377 colors.add newSeqWith(6, NewVec4f(0, 1, 1, 1)) | |
378 normals.add newSeqWith(6, NewVec3f(0, 0, 1)) | |
379 | |
380 # right, green | |
381 vertices.add quad.transf(Rotate(PI / 2, Y) * Translate(0, 0, -0.5)) | |
382 colors.add newSeqWith(6, NewVec4f(0, 1, 0, 1)) | |
383 normals.add newSeqWith(6, NewVec3f(-1, 0, 0)) | |
384 | |
385 # left, magenta | |
386 vertices.add quad.transf(Rotate(-PI / 2, Y) * Translate(0, 0, -0.5)) | |
387 colors.add newSeqWith(6, NewVec4f(1, 0, 1, 1)) | |
388 normals.add newSeqWith(6, NewVec3f(1, 0, 0)) | |
389 | |
390 # bottom, blue | |
391 vertices.add quad.transf(Rotate(PI / 2, X) * Translate(0, 0, -0.5)) | |
392 colors.add newSeqWith(6, NewVec4f(0, 0, 1, 1)) | |
393 normals.add newSeqWith(6, NewVec3f(0, -1, 0)) | |
394 | |
395 # top, yellow | |
396 vertices.add quad.transf(Rotate(-PI / 2, X) * Translate(0, 0, -0.5)) | |
397 colors.add newSeqWith(6, NewVec4f(1, 1, 0, 1)) | |
398 normals.add newSeqWith(6, NewVec3f(0, 1, 0)) | |
399 | |
400 var renderdata = InitRenderData() | |
401 | |
402 var mesh = Mesh( | |
403 position: asGPUArray(vertices, VertexBuffer), | |
404 color: asGPUArray(colors, VertexBuffer), | |
405 normals: asGPUArray(normals, VertexBuffer), | |
406 ) | |
407 AssignBuffers(renderdata, mesh) | |
408 | |
409 var floor = Mesh( | |
410 position: asGPUArray(quad.transf(Scale(10, 10, 10) * Rotate(-PI / 2, X) * Translate(0, 0, 0.05)), VertexBuffer), | |
411 color: asGPUArray(newSeqWith(6, NewVec4f(0.1, 0.1, 0.1, 1)), VertexBuffer), | |
412 normals: asGPUArray(newSeqWith(6, Y), VertexBuffer), | |
413 ) | |
414 AssignBuffers(renderdata, floor) | |
415 | |
416 var uniforms1 = asDescriptorSet( | |
417 Uniforms( | |
1232 | 418 data: asGPUValue(UniformData(mvp: Unit4), UniformBufferMapped) |
1231 | 419 ) |
420 ) | |
421 AssignBuffers(renderdata, uniforms1) | |
422 | |
423 renderdata.FlushAllMemory() | |
424 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
425 var pipeline = CreatePipeline[CubeShader](renderPass = vulkan.swapchain.renderPass) |
1231 | 426 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
427 | |
1232 | 428 var tStart = getMonoTime() |
429 var t = tStart | |
1231 | 430 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
431 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
432 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
|
433 let tStartLoop = getMonoTime() - tStart |
1232 | 434 |
435 uniforms1.data.data.data.mvp = ( | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
436 Perspective(-PI / 2, GetAspectRatio(), 0.01, 100) * |
1232 | 437 Translate(0, 0, 2) * |
438 Rotate(PI / 4, X) * | |
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
439 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) |
1232 | 440 ) |
1231 | 441 UpdateGPUBuffer(uniforms1.data.data, flush = true) |
1242 | 442 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
443 WithNextFrame(framebuffer, commandbuffer): |
1242 | 444 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
445 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1231 | 446 WithPipeline(commandbuffer, pipeline): |
1242 | 447 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
448 WithBind(commandbuffer, (uniforms1, ), pipeline): |
1231 | 449 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
450 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
|
451 |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
452 let tEndLoop = getMonoTime() - tStart |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
453 let looptime = tEndLoop - tStartLoop |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
454 let waitTime = 16_666 - looptime.inMicroseconds |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
455 if waitTime > 0: |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
456 sleep((waitTime / 1000).int) |
1231 | 457 |
458 # cleanup | |
459 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
460 DestroyPipeline(pipeline) | |
461 DestroyRenderData(renderdata) | |
462 | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
463 proc test_06_different_draw_modes(time: float32) = |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
464 var renderdata = InitRenderData() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
465 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
466 type |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
467 Shader = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
468 position {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
469 color {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
470 fragmentColor {.Pass.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
471 outColor {.ShaderOutput.}: Vec4f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
472 # code |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
473 vertexCode: string = """void main() { |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
474 gl_PointSize = 100; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
475 fragmentColor = color; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
476 gl_Position = vec4(position, 1);}""" |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
477 fragmentCode: string = """void main() { |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
478 outColor = vec4(fragmentColor, 1);}""" |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
479 TriangleMesh = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
480 position: GPUArray[Vec3f, VertexBuffer] |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
481 color: GPUArray[Vec3f, VertexBuffer] |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
482 var triangle = TriangleMesh( |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
483 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
484 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
485 ) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
486 var lines = TriangleMesh( |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
487 position: asGPUArray([NewVec3f(-0.9, 0), NewVec3f(-0.05, -0.9), NewVec3f(0.05, -0.9), NewVec3f(0.9, 0)], VertexBuffer), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
488 color: asGPUArray([NewVec3f(1, 1, 0), NewVec3f(1, 1, 0), NewVec3f(0, 1, 0), NewVec3f(0, 1, 0)], VertexBuffer), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
489 ) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
490 AssignBuffers(renderdata, triangle) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
491 AssignBuffers(renderdata, lines) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
492 renderdata.FlushAllMemory() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
493 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
494 var pipeline1 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, polygonMode = VK_POLYGON_MODE_LINE, lineWidth = 20'f32) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
495 var pipeline2 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, polygonMode = VK_POLYGON_MODE_POINT) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
496 var pipeline3 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST, lineWidth = 5) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
497 var pipeline4 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
498 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
499 var start = getMonoTime() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
500 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
501 WithNextFrame(framebuffer, commandbuffer): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
502 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
503 WithPipeline(commandbuffer, pipeline1): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
504 Render(commandbuffer = commandbuffer, pipeline = pipeline1, mesh = triangle) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
505 WithPipeline(commandbuffer, pipeline2): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
506 Render(commandbuffer = commandbuffer, pipeline = pipeline2, mesh = triangle) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
507 WithPipeline(commandbuffer, pipeline3): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
508 Render(commandbuffer = commandbuffer, pipeline = pipeline3, mesh = lines) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
509 WithPipeline(commandbuffer, pipeline4): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
510 Render(commandbuffer = commandbuffer, pipeline = pipeline4, mesh = lines) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
511 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
512 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
513 checkVkResult vkDeviceWaitIdle(vulkan.device) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
514 DestroyPipeline(pipeline1) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
515 DestroyPipeline(pipeline2) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
516 DestroyPipeline(pipeline3) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
517 DestroyPipeline(pipeline4) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
518 DestroyRenderData(renderdata) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
519 |
1242 | 520 proc test_07_png_texture(time: float32) = |
521 var renderdata = InitRenderData() | |
522 | |
523 type | |
524 Uniforms = object | |
525 texture1: Image[RGBA] | |
526 Shader = object | |
527 position {.VertexAttribute.}: Vec3f | |
528 uv {.VertexAttribute.}: Vec2f | |
529 fragmentUv {.Pass.}: Vec2f | |
530 outColor {.ShaderOutput.}: Vec4f | |
531 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
532 # code | |
533 vertexCode: string = """ | |
534 void main() { | |
535 fragmentUv = uv; | |
536 gl_Position = vec4(position, 1); | |
537 }""" | |
538 fragmentCode: string = """ | |
539 void main() { | |
540 outColor = texture(texture1, fragmentUv); | |
541 }""" | |
542 Quad = object | |
543 position: GPUArray[Vec3f, VertexBuffer] | |
544 uv: GPUArray[Vec2f, VertexBuffer] | |
545 var mesh = Quad( | |
546 position: asGPUArray([ | |
547 NewVec3f(-0.8, -0.5), NewVec3f(-0.8, 0.5), NewVec3f(0.8, 0.5), | |
548 NewVec3f(0.8, 0.5), NewVec3f(0.8, -0.5), NewVec3f(-0.8, -0.5), | |
549 ], VertexBuffer), | |
550 uv: asGPUArray([ | |
551 NewVec2f(0, 1), NewVec2f(0, 0), NewVec2f(1, 0), | |
552 NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1), | |
553 ], VertexBuffer), | |
554 ) | |
555 AssignBuffers(renderdata, mesh) | |
556 renderdata.FlushAllMemory() | |
557 | |
558 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) | |
559 var uniforms1 = asDescriptorSet( | |
560 Uniforms( | |
561 texture1: LoadImage[RGBA]("art.png"), | |
562 ) | |
563 ) | |
564 UploadImages(renderdata, uniforms1) | |
565 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | |
566 | |
567 var start = getMonoTime() | |
568 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
569 | |
570 WithNextFrame(framebuffer, commandbuffer): | |
571 | |
572 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
573 | |
574 WithPipeline(commandbuffer, pipeline): | |
575 | |
576 WithBind(commandbuffer, (uniforms1, ), pipeline): | |
577 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | |
578 | |
579 # cleanup | |
580 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
581 DestroyPipeline(pipeline) | |
582 DestroyRenderData(renderdata) | |
583 | |
584 proc test_08_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
585 var (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
586 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
587 SetupSwapchain(renderpass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
588 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
589 var renderdata = InitRenderData() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
590 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
591 type |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
592 Uniforms = object |
1242 | 593 frameTexture: Image[RGBA] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
594 TriangleShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
595 position {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
596 color {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
597 fragmentColor {.Pass.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
598 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
599 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
600 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
601 fragmentColor = color; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
602 gl_Position = vec4(position, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
603 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
604 outColor = vec4(fragmentColor, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
605 PresentShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
606 position {.VertexAttribute.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
607 uv {.Pass.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
608 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
609 descriptorSets {.DescriptorSets.}: (Uniforms, ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
610 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
611 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
612 uv = ((position + 1) * 0.5) * vec2(1, -1); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
613 gl_Position = vec4(position, 0, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
614 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
615 vec2 uv1 = uv + vec2(0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
616 vec2 uv2 = uv + vec2(0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
617 vec2 uv3 = uv + vec2(-0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
618 vec2 uv4 = uv + vec2(-0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
619 outColor = ( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
620 texture(frameTexture, uv1) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
621 texture(frameTexture, uv2) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
622 texture(frameTexture, uv3) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
623 texture(frameTexture, uv4) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
624 ) / 4; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
625 }""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
626 TriangleMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
627 position: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
628 color: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
629 QuadMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
630 position: GPUArray[Vec2f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
631 indices: GPUArray[uint16, IndexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
632 var mesh = TriangleMesh( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
633 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
634 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
635 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
636 var quad = QuadMesh( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
637 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
638 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
|
639 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
640 var uniforms1 = asDescriptorSet( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
641 Uniforms( |
1242 | 642 frameTexture: Image[RGBA](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
643 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
644 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
645 AssignBuffers(renderdata, mesh) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
646 AssignBuffers(renderdata, quad) |
1228 | 647 UploadImages(renderdata, uniforms1) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
648 renderdata.FlushAllMemory() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
649 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
650 var |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
651 drawPipeline = CreatePipeline[TriangleShader](renderPass = offscreenRP) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
652 presentPipeline = CreatePipeline[PresentShader](renderPass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
653 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
654 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
|
655 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
656 # 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
|
657 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
658 depthImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
659 depthImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
660 depthMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
669 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
|
670 depthMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
671 requirements.size, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
672 BestMemory(mappable = false, filter = requirements.memoryTypes) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
673 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
674 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
675 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
676 depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
677 depthMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
678 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
679 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
680 depthImageView = svkCreate2DImageView( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
681 image = depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
682 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
|
683 aspect = VK_IMAGE_ASPECT_DEPTH_BIT |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
684 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
685 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
686 # 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
|
687 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
688 msaaImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
689 msaaImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
690 msaaMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
699 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
|
700 msaaMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
701 requirements.size, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
702 BestMemory(mappable = false, filter = requirements.memoryTypes) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
703 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
704 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
705 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
706 msaaImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
707 msaaMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
708 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
709 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
710 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
|
711 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
712 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
|
713 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
|
714 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
|
715 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
|
716 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
717 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
|
718 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
719 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
|
720 attachments = @[msaaImageView, depthImageView, 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
|
721 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
722 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
|
723 var offscreenFB = svkCreateFramebuffer( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
724 offscreenRP.vk, |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
725 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
|
726 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
|
727 attachments |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
728 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
729 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
730 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
731 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
732 |
1242 | 733 WithNextFrame(framebuffer, commandbuffer): |
734 | |
735 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
736 WithPipeline(commandbuffer, drawPipeline): | |
737 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
738 |
1242 | 739 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
740 |
1242 | 741 WithPipeline(commandbuffer, presentPipeline): |
742 | |
743 WithBind(commandbuffer, (uniforms1, ), presentPipeline): | |
744 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
745 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
746 # cleanup |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
747 checkVkResult vkDeviceWaitIdle(vulkan.device) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
748 DestroyPipeline(presentPipeline) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
749 DestroyPipeline(drawPipeline) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 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
|
757 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
|
758 vkFreeMemory(vulkan.device, msaaMemory, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
759 vkDestroyRenderPass(vulkan.device, offscreenRP.vk, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
760 vkDestroyRenderPass(vulkan.device, presentRP.vk, nil) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
761 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
762 ClearSwapchain() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
763 |
1204 | 764 when isMainModule: |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
765 var time = 1'f32 |
1204 | 766 InitVulkan() |
767 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
768 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
|
769 var renderPasses = [ |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
770 (depthBuffer: false, samples: VK_SAMPLE_COUNT_1_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
771 (depthBuffer: false, samples: VK_SAMPLE_COUNT_4_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
772 (depthBuffer: true, samples: VK_SAMPLE_COUNT_1_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
773 (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
|
774 ] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
775 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
776 |
1204 | 777 # test normal |
1230 | 778 for i, (depthBuffer, samples) in renderPasses: |
779 var renderpass = CreateDirectPresentationRenderPass(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
|
780 SetupSwapchain(renderpass = renderpass) |
1204 | 781 |
1230 | 782 # 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
|
783 test_01_triangle(time) |
1230 | 784 |
785 # 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
|
786 test_02_triangle_quad_instanced(time) |
1210 | 787 |
1230 | 788 # 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
|
789 test_03_simple_descriptorset(time) |
1204 | 790 |
1230 | 791 # 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
|
792 test_04_multiple_descriptorsets(time) |
1231 | 793 |
794 # 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
|
795 test_05_cube(time) |
1204 | 796 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
797 # different draw modes (lines, points, and topologies) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
798 test_06_different_draw_modes(time) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
799 |
1242 | 800 # load PNG texture |
801 test_07_png_texture(time) | |
802 | |
1230 | 803 checkVkResult vkDeviceWaitIdle(vulkan.device) |
804 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
805 ClearSwapchain() |
1204 | 806 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
807 # test multiple render passes |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
808 for i, (depthBuffer, samples) in renderPasses: |
1242 | 809 test_08_triangle_2pass(time, depthBuffer, samples) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
810 |
1203 | 811 DestroyVulkan() |