Mercurial > games > semicongine
comparison tests/test_rendering.nim @ 1239:69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
author | sam <sam@basx.dev> |
---|---|
date | Mon, 22 Jul 2024 00:46:10 +0700 |
parents | c70fee6568f6 |
children | 42eeb59f3a43 |
comparison
equal
deleted
inserted
replaced
1238:03634915bbdb | 1239:69489a678141 |
---|---|
5 import std/options | 5 import std/options |
6 import std/random | 6 import std/random |
7 | 7 |
8 import ../semiconginev2 | 8 import ../semiconginev2 |
9 | 9 |
10 proc test_01_triangle(time: float32, swapchain: var Swapchain) = | 10 proc test_01_triangle(time: float32) = |
11 var renderdata = InitRenderData() | 11 var renderdata = InitRenderData() |
12 | 12 |
13 type | 13 type |
14 TrianglShader = object | 14 TrianglShader = object |
15 position {.VertexAttribute.}: Vec3f | 15 position {.VertexAttribute.}: Vec3f |
31 ) | 31 ) |
32 AssignBuffers(renderdata, mesh) | 32 AssignBuffers(renderdata, mesh) |
33 renderdata.FlushAllMemory() | 33 renderdata.FlushAllMemory() |
34 | 34 |
35 var | 35 var |
36 pipeline = CreatePipeline[TrianglShader](renderPass = swapchain.renderPass) | 36 pipeline = CreatePipeline[TrianglShader](renderPass = vulkan.swapchain.renderPass) |
37 | 37 |
38 var start = getMonoTime() | 38 var start = getMonoTime() |
39 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 39 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
40 WithNextFrame(swapchain, framebuffer, commandbuffer): | 40 WithNextFrame(framebuffer, commandbuffer): |
41 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 41 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
42 WithPipeline(commandbuffer, pipeline): | 42 WithPipeline(commandbuffer, pipeline): |
43 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | 43 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
44 | 44 |
45 # cleanup | 45 # cleanup |
46 checkVkResult vkDeviceWaitIdle(vulkan.device) | 46 checkVkResult vkDeviceWaitIdle(vulkan.device) |
47 DestroyPipeline(pipeline) | 47 DestroyPipeline(pipeline) |
48 DestroyRenderData(renderdata) | 48 DestroyRenderData(renderdata) |
49 | 49 |
50 | 50 |
51 proc test_02_triangle_quad_instanced(time: float32, swapchain: var Swapchain) = | 51 proc test_02_triangle_quad_instanced(time: float32) = |
52 var renderdata = InitRenderData() | 52 var renderdata = InitRenderData() |
53 | 53 |
54 type | 54 type |
55 SomeShader = object | 55 SomeShader = object |
56 position {.VertexAttribute.}: Vec3f | 56 position {.VertexAttribute.}: Vec3f |
98 AssignBuffers(renderdata, quad) | 98 AssignBuffers(renderdata, quad) |
99 AssignBuffers(renderdata, instancesA) | 99 AssignBuffers(renderdata, instancesA) |
100 AssignBuffers(renderdata, instancesB) | 100 AssignBuffers(renderdata, instancesB) |
101 renderdata.FlushAllMemory() | 101 renderdata.FlushAllMemory() |
102 | 102 |
103 var pipeline = CreatePipeline[SomeShader](renderPass = swapchain.renderPass) | 103 var pipeline = CreatePipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) |
104 | 104 |
105 var start = getMonoTime() | 105 var start = getMonoTime() |
106 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 106 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
107 WithNextFrame(swapchain, framebuffer, commandbuffer): | 107 WithNextFrame(framebuffer, commandbuffer): |
108 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 108 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
109 WithPipeline(commandbuffer, pipeline): | 109 WithPipeline(commandbuffer, pipeline): |
110 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) | 110 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) |
111 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) | 111 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) |
112 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) | 112 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) |
113 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) | 113 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) |
115 # cleanup | 115 # cleanup |
116 checkVkResult vkDeviceWaitIdle(vulkan.device) | 116 checkVkResult vkDeviceWaitIdle(vulkan.device) |
117 DestroyPipeline(pipeline) | 117 DestroyPipeline(pipeline) |
118 DestroyRenderData(renderdata) | 118 DestroyRenderData(renderdata) |
119 | 119 |
120 proc test_03_simple_descriptorset(time: float32, swapchain: var Swapchain) = | 120 proc test_03_simple_descriptorset(time: float32) = |
121 var renderdata = InitRenderData() | 121 var renderdata = InitRenderData() |
122 | 122 |
123 type | 123 type |
124 Material = object | 124 Material = object |
125 baseColor: Vec3f | 125 baseColor: Vec3f |
174 AssignBuffers(renderdata, uniforms2) | 174 AssignBuffers(renderdata, uniforms2) |
175 UploadImages(renderdata, uniforms1) | 175 UploadImages(renderdata, uniforms1) |
176 UploadImages(renderdata, uniforms2) | 176 UploadImages(renderdata, uniforms2) |
177 renderdata.FlushAllMemory() | 177 renderdata.FlushAllMemory() |
178 | 178 |
179 var pipeline = CreatePipeline[QuadShader](renderPass = swapchain.renderPass) | 179 var pipeline = CreatePipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
180 | 180 |
181 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | 181 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
182 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) | 182 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) |
183 | 183 |
184 var start = getMonoTime() | 184 var start = getMonoTime() |
185 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 185 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
186 WithNextFrame(swapchain, framebuffer, commandbuffer): | 186 WithNextFrame(framebuffer, commandbuffer): |
187 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
188 WithPipeline(commandbuffer, pipeline): | 188 WithPipeline(commandbuffer, pipeline): |
189 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF): | 189 WithBind(commandbuffer, (uniforms1, ), pipeline): |
190 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 190 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
191 WithBind(commandbuffer, (uniforms2, ), pipeline, swapchain.currentFiF): | 191 WithBind(commandbuffer, (uniforms2, ), pipeline): |
192 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 192 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
193 | 193 |
194 # cleanup | 194 # cleanup |
195 checkVkResult vkDeviceWaitIdle(vulkan.device) | 195 checkVkResult vkDeviceWaitIdle(vulkan.device) |
196 DestroyPipeline(pipeline) | 196 DestroyPipeline(pipeline) |
197 DestroyRenderData(renderdata) | 197 DestroyRenderData(renderdata) |
198 | 198 |
199 proc test_04_multiple_descriptorsets(time: float32, swapchain: var Swapchain) = | 199 proc test_04_multiple_descriptorsets(time: float32) = |
200 var renderdata = InitRenderData() | 200 var renderdata = InitRenderData() |
201 | 201 |
202 type | 202 type |
203 RenderSettings = object | 203 RenderSettings = object |
204 brigthness: float32 | 204 brigthness: float32 |
281 AssignBuffers(renderdata, otherset1) | 281 AssignBuffers(renderdata, otherset1) |
282 AssignBuffers(renderdata, otherset2) | 282 AssignBuffers(renderdata, otherset2) |
283 UploadImages(renderdata, mainset) | 283 UploadImages(renderdata, mainset) |
284 renderdata.FlushAllMemory() | 284 renderdata.FlushAllMemory() |
285 | 285 |
286 var pipeline = CreatePipeline[QuadShader](renderPass = swapchain.renderPass) | 286 var pipeline = CreatePipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
287 | 287 |
288 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) | 288 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) |
289 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) | 289 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) |
290 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) | 290 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) |
291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset2) | 291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset2) |
292 | 292 |
293 var start = getMonoTime() | 293 var start = getMonoTime() |
294 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 294 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
295 TimeAndLog: | 295 TimeAndLog: |
296 WithNextFrame(swapchain, framebuffer, commandbuffer): | 296 WithNextFrame(framebuffer, commandbuffer): |
297 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 297 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
298 WithPipeline(commandbuffer, pipeline): | 298 WithPipeline(commandbuffer, pipeline): |
299 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline, swapchain.currentFiF): | 299 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline): |
300 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 300 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
301 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline, swapchain.currentFiF): | 301 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline): |
302 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 302 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
303 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time | 303 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
304 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time | 304 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
305 UpdateGPUBuffer(mainset.data.renderSettings) | 305 UpdateGPUBuffer(mainset.data.renderSettings) |
306 UpdateGPUBuffer(otherset1.data.objectSettings) | 306 UpdateGPUBuffer(otherset1.data.objectSettings) |
309 # cleanup | 309 # cleanup |
310 checkVkResult vkDeviceWaitIdle(vulkan.device) | 310 checkVkResult vkDeviceWaitIdle(vulkan.device) |
311 DestroyPipeline(pipeline) | 311 DestroyPipeline(pipeline) |
312 DestroyRenderData(renderdata) | 312 DestroyRenderData(renderdata) |
313 | 313 |
314 proc test_05_cube(time: float32, swapchain: var Swapchain) = | 314 proc test_05_cube(time: float32) = |
315 type | 315 type |
316 | 316 |
317 UniformData = object | 317 UniformData = object |
318 mvp: Mat4 | 318 mvp: Mat4 |
319 Uniforms = object | 319 Uniforms = object |
403 ) | 403 ) |
404 AssignBuffers(renderdata, uniforms1) | 404 AssignBuffers(renderdata, uniforms1) |
405 | 405 |
406 renderdata.FlushAllMemory() | 406 renderdata.FlushAllMemory() |
407 | 407 |
408 var pipeline = CreatePipeline[CubeShader](renderPass = swapchain.renderPass) | 408 var pipeline = CreatePipeline[CubeShader](renderPass = vulkan.swapchain.renderPass) |
409 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | 409 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
410 | 410 |
411 var tStart = getMonoTime() | 411 var tStart = getMonoTime() |
412 var t = tStart | 412 var t = tStart |
413 | 413 |
414 var start = getMonoTime() | 414 var start = getMonoTime() |
415 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 415 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
416 let tStartLoop = getMonoTime() - tStart | 416 let tStartLoop = getMonoTime() - tStart |
417 | 417 |
418 uniforms1.data.data.data.mvp = ( | 418 uniforms1.data.data.data.mvp = ( |
419 Perspective(-PI / 2, GetAspectRatio(swapchain), 0.01, 100) * | 419 Perspective(-PI / 2, GetAspectRatio(), 0.01, 100) * |
420 Translate(0, 0, 2) * | 420 Translate(0, 0, 2) * |
421 Rotate(PI / 4, X) * | 421 Rotate(PI / 4, X) * |
422 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) | 422 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) |
423 ) | 423 ) |
424 UpdateGPUBuffer(uniforms1.data.data, flush = true) | 424 UpdateGPUBuffer(uniforms1.data.data, flush = true) |
425 WithNextFrame(swapchain, framebuffer, commandbuffer): | 425 WithNextFrame(framebuffer, commandbuffer): |
426 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 426 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
427 WithPipeline(commandbuffer, pipeline): | 427 WithPipeline(commandbuffer, pipeline): |
428 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF): | 428 WithBind(commandbuffer, (uniforms1, ), pipeline): |
429 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | 429 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
430 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) | 430 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) |
431 | 431 |
432 let tEndLoop = getMonoTime() - tStart | 432 let tEndLoop = getMonoTime() - tStart |
433 let looptime = tEndLoop - tStartLoop | 433 let looptime = tEndLoop - tStartLoop |
440 checkVkResult vkDeviceWaitIdle(vulkan.device) | 440 checkVkResult vkDeviceWaitIdle(vulkan.device) |
441 DestroyPipeline(pipeline) | 441 DestroyPipeline(pipeline) |
442 DestroyRenderData(renderdata) | 442 DestroyRenderData(renderdata) |
443 | 443 |
444 proc test_06_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = | 444 proc test_06_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = |
445 var | 445 var (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
446 (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | 446 |
447 swapchain = InitSwapchain(renderpass = presentRP).get() | 447 SetupSwapchain(renderpass = presentRP) |
448 | 448 |
449 var renderdata = InitRenderData() | 449 var renderdata = InitRenderData() |
450 | 450 |
451 type | 451 type |
452 Uniforms = object | 452 Uniforms = object |
497 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), | 497 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), |
498 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | 498 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
499 ) | 499 ) |
500 var uniforms1 = asDescriptorSet( | 500 var uniforms1 = asDescriptorSet( |
501 Uniforms( | 501 Uniforms( |
502 frameTexture: Image[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true), | 502 frameTexture: Image[TVec4[uint8]](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), |
503 ) | 503 ) |
504 ) | 504 ) |
505 AssignBuffers(renderdata, mesh) | 505 AssignBuffers(renderdata, mesh) |
506 AssignBuffers(renderdata, quad) | 506 AssignBuffers(renderdata, quad) |
507 UploadImages(renderdata, uniforms1) | 507 UploadImages(renderdata, uniforms1) |
518 depthImage: VkImage | 518 depthImage: VkImage |
519 depthImageView: VkImageView | 519 depthImageView: VkImageView |
520 depthMemory: VkDeviceMemory | 520 depthMemory: VkDeviceMemory |
521 if offscreenRP.depthBuffer: | 521 if offscreenRP.depthBuffer: |
522 depthImage = svkCreate2DImage( | 522 depthImage = svkCreate2DImage( |
523 width = swapchain.width, | 523 width = vulkan.swapchain.width, |
524 height = swapchain.height, | 524 height = vulkan.swapchain.height, |
525 format = DEPTH_FORMAT, | 525 format = DEPTH_FORMAT, |
526 usage = [VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT], | 526 usage = [VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT], |
527 samples = offscreenRP.samples, | 527 samples = offscreenRP.samples, |
528 ) | 528 ) |
529 let requirements = svkGetImageMemoryRequirements(depthImage) | 529 let requirements = svkGetImageMemoryRequirements(depthImage) |
548 msaaImage: VkImage | 548 msaaImage: VkImage |
549 msaaImageView: VkImageView | 549 msaaImageView: VkImageView |
550 msaaMemory: VkDeviceMemory | 550 msaaMemory: VkDeviceMemory |
551 if offscreenRP.samples != VK_SAMPLE_COUNT_1_BIT: | 551 if offscreenRP.samples != VK_SAMPLE_COUNT_1_BIT: |
552 msaaImage = svkCreate2DImage( | 552 msaaImage = svkCreate2DImage( |
553 width = swapchain.width, | 553 width = vulkan.swapchain.width, |
554 height = swapchain.height, | 554 height = vulkan.swapchain.height, |
555 format = SURFACE_FORMAT, | 555 format = SURFACE_FORMAT, |
556 usage = [VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], | 556 usage = [VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], |
557 samples = offscreenRP.samples, | 557 samples = offscreenRP.samples, |
558 ) | 558 ) |
559 let requirements = svkGetImageMemoryRequirements(msaaImage) | 559 let requirements = svkGetImageMemoryRequirements(msaaImage) |
581 else: | 581 else: |
582 attachments = @[msaaImageView, uniforms1.data.frameTexture.imageview] | 582 attachments = @[msaaImageView, uniforms1.data.frameTexture.imageview] |
583 echo attachments | 583 echo attachments |
584 var offscreenFB = svkCreateFramebuffer( | 584 var offscreenFB = svkCreateFramebuffer( |
585 offscreenRP.vk, | 585 offscreenRP.vk, |
586 swapchain.width, | 586 vulkan.swapchain.width, |
587 swapchain.height, | 587 vulkan.swapchain.height, |
588 attachments | 588 attachments |
589 ) | 589 ) |
590 | 590 |
591 var start = getMonoTime() | 591 var start = getMonoTime() |
592 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 592 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
593 | 593 |
594 TimeAndLog: | 594 TimeAndLog: |
595 WithNextFrame(swapchain, framebuffer, commandbuffer): | 595 WithNextFrame(framebuffer, commandbuffer): |
596 | 596 |
597 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 597 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
598 WithPipeline(commandbuffer, drawPipeline): | 598 WithPipeline(commandbuffer, drawPipeline): |
599 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) | 599 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
600 | 600 |
601 WithRenderPass(presentRP, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | 601 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
602 WithPipeline(commandbuffer, presentPipeline): | 602 WithPipeline(commandbuffer, presentPipeline): |
603 WithBind(commandbuffer, (uniforms1, ), presentPipeline, swapchain.currentFiF): | 603 WithBind(commandbuffer, (uniforms1, ), presentPipeline): |
604 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) | 604 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) |
605 | 605 |
606 # cleanup | 606 # cleanup |
607 checkVkResult vkDeviceWaitIdle(vulkan.device) | 607 checkVkResult vkDeviceWaitIdle(vulkan.device) |
608 DestroyPipeline(presentPipeline) | 608 DestroyPipeline(presentPipeline) |
617 vkDestroyImage(vulkan.device, msaaImage, nil) | 617 vkDestroyImage(vulkan.device, msaaImage, nil) |
618 vkFreeMemory(vulkan.device, msaaMemory, nil) | 618 vkFreeMemory(vulkan.device, msaaMemory, nil) |
619 vkDestroyRenderPass(vulkan.device, offscreenRP.vk, nil) | 619 vkDestroyRenderPass(vulkan.device, offscreenRP.vk, nil) |
620 vkDestroyRenderPass(vulkan.device, presentRP.vk, nil) | 620 vkDestroyRenderPass(vulkan.device, presentRP.vk, nil) |
621 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) | 621 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) |
622 DestroySwapchain(swapchain) | 622 ClearSwapchain() |
623 | 623 |
624 when isMainModule: | 624 when isMainModule: |
625 var time = 1'f32 | 625 var time = 1'f32 |
626 InitVulkan() | 626 InitVulkan() |
627 | 627 |
634 ] | 634 ] |
635 | 635 |
636 # test normal | 636 # test normal |
637 for i, (depthBuffer, samples) in renderPasses: | 637 for i, (depthBuffer, samples) in renderPasses: |
638 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | 638 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
639 var swapchain = InitSwapchain(renderpass = renderpass).get() | 639 SetupSwapchain(renderpass = renderpass) |
640 | 640 |
641 # tests a simple triangle with minimalistic shader and vertex format | 641 # tests a simple triangle with minimalistic shader and vertex format |
642 test_01_triangle(time, swapchain) | 642 test_01_triangle(time) |
643 | 643 |
644 # tests instanced triangles and quads, mixing meshes and instances | 644 # tests instanced triangles and quads, mixing meshes and instances |
645 test_02_triangle_quad_instanced(time, swapchain) | 645 test_02_triangle_quad_instanced(time) |
646 | 646 |
647 # teste descriptor sets | 647 # teste descriptor sets |
648 test_03_simple_descriptorset(time, swapchain) | 648 test_03_simple_descriptorset(time) |
649 | 649 |
650 # tests multiple descriptor sets and arrays | 650 # tests multiple descriptor sets and arrays |
651 test_04_multiple_descriptorsets(time, swapchain) | 651 test_04_multiple_descriptorsets(time) |
652 | 652 |
653 # rotating cube | 653 # rotating cube |
654 test_05_cube(time, swapchain) | 654 test_05_cube(time) |
655 | 655 |
656 checkVkResult vkDeviceWaitIdle(vulkan.device) | 656 checkVkResult vkDeviceWaitIdle(vulkan.device) |
657 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | 657 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
658 DestroySwapchain(swapchain) | 658 ClearSwapchain() |
659 | 659 |
660 # test multiple render passes | 660 # test multiple render passes |
661 for i, (depthBuffer, samples) in renderPasses: | 661 for i, (depthBuffer, samples) in renderPasses: |
662 test_06_triangle_2pass(time, depthBuffer, samples) | 662 test_06_triangle_2pass(time, depthBuffer, samples) |
663 | 663 |