comparison tests/test_rendering.nim @ 1280:a89a70ea3da2

did: undo part of stupid API renaming a few weeks back ;(
author sam <sam@basx.dev>
date Mon, 29 Jul 2024 15:49:37 +0700
parents 01138e6257dd
children 0369fa1ffbd9
comparison
equal deleted inserted replaced
1277:01138e6257dd 1280:a89a70ea3da2
27 outColor = vec4(fragmentColor, 1);}""" 27 outColor = vec4(fragmentColor, 1);}"""
28 TriangleMesh = object 28 TriangleMesh = object
29 position: GPUArray[Vec3f, VertexBuffer] 29 position: GPUArray[Vec3f, VertexBuffer]
30 color: GPUArray[Vec3f, VertexBuffer] 30 color: GPUArray[Vec3f, VertexBuffer]
31 var mesh = TriangleMesh( 31 var mesh = TriangleMesh(
32 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 32 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer),
33 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), 33 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer),
34 ) 34 )
35 AssignBuffers(renderdata, mesh) 35 AssignBuffers(renderdata, mesh)
36 renderdata.FlushAllMemory() 36 renderdata.FlushAllMemory()
37 37
38 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) 38 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass)
40 var start = getMonoTime() 40 var start = getMonoTime()
41 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 41 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
42 42
43 WithNextFrame(framebuffer, commandbuffer): 43 WithNextFrame(framebuffer, commandbuffer):
44 44
45 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 45 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
46 46
47 WithPipeline(commandbuffer, pipeline): 47 WithPipeline(commandbuffer, pipeline):
48 48
49 RenderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3 + ((getMonoTime() - start).inMilliseconds().int / 1000))) 49 RenderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3 + ((getMonoTime() - start).inMilliseconds().int / 1000)))
50 50
80 indices: GPUArray[uint16, IndexBuffer] 80 indices: GPUArray[uint16, IndexBuffer]
81 Instances = object 81 Instances = object
82 pos: GPUArray[Vec3f, VertexBuffer] 82 pos: GPUArray[Vec3f, VertexBuffer]
83 scale: GPUArray[float32, VertexBuffer] 83 scale: GPUArray[float32, VertexBuffer]
84 var tri = TriangleMesh( 84 var tri = TriangleMesh(
85 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 85 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer),
86 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), 86 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer),
87 ) 87 )
88 var quad = QuadMesh( 88 var quad = QuadMesh(
89 position: asGPUArray([NewVec3f(-0.3, -0.3), NewVec3f(-0.3, 0.3), NewVec3f(0.3, 0.3), NewVec3f(0.3, -0.3)], VertexBuffer), 89 position: asGPUArray([vec3(-0.3, -0.3, 0), vec3(-0.3, 0.3, 0), vec3(0.3, 0.3, 0), vec3(0.3, -0.3, 0)], VertexBuffer),
90 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 90 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
91 color: asGPUArray([NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1)], VertexBuffer), 91 color: asGPUArray([vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1)], VertexBuffer),
92 ) 92 )
93 93
94 var instancesA: Instances 94 var instancesA: Instances
95 for n in 1..100: 95 for n in 1..100:
96 instancesA.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32)) 96 instancesA.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32), 0)
97 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32) 97 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32)
98 var instancesB: Instances 98 var instancesB: Instances
99 for n in 1..100: 99 for n in 1..100:
100 instancesB.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32)) 100 instancesB.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32), 0)
101 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32) 101 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32)
102 102
103 AssignBuffers(renderdata, tri) 103 AssignBuffers(renderdata, tri)
104 AssignBuffers(renderdata, quad) 104 AssignBuffers(renderdata, quad)
105 AssignBuffers(renderdata, instancesA) 105 AssignBuffers(renderdata, instancesA)
111 var start = getMonoTime() 111 var start = getMonoTime()
112 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 112 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
113 113
114 WithNextFrame(framebuffer, commandbuffer): 114 WithNextFrame(framebuffer, commandbuffer):
115 115
116 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 116 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
117 117
118 WithPipeline(commandbuffer, pipeline): 118 WithPipeline(commandbuffer, pipeline):
119 119
120 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) 120 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA)
121 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) 121 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB)
161 let G = BGRA([0'u8, 255'u8, 0'u8, 255'u8]) 161 let G = BGRA([0'u8, 255'u8, 0'u8, 255'u8])
162 let B = BGRA([0'u8, 0'u8, 255'u8, 255'u8]) 162 let B = BGRA([0'u8, 0'u8, 255'u8, 255'u8])
163 let W = BGRA([255'u8, 255'u8, 255'u8, 255'u8]) 163 let W = BGRA([255'u8, 255'u8, 255'u8, 255'u8])
164 var 164 var
165 quad = QuadMesh( 165 quad = QuadMesh(
166 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 166 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(-0.5, 0.5, 0), vec3(0.5, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer),
167 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 167 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
168 ) 168 )
169 uniforms1 = asDescriptorSet( 169 uniforms1 = asDescriptorSet(
170 Uniforms( 170 Uniforms(
171 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), 171 material: asGPUValue(Material(baseColor: vec3(1, 1, 1)), UniformBuffer),
172 texture1: Image[BGRA](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), 172 texture1: Image[BGRA](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST),
173 ) 173 )
174 ) 174 )
175 uniforms2 = asDescriptorSet( 175 uniforms2 = asDescriptorSet(
176 Uniforms( 176 Uniforms(
177 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), 177 material: asGPUValue(Material(baseColor: vec3(0.5, 0.5, 0.5)), UniformBuffer),
178 texture1: Image[BGRA](width: 2, height: 2, data: @[R, G, B, W]), 178 texture1: Image[BGRA](width: 2, height: 2, data: @[R, G, B, W]),
179 ) 179 )
180 ) 180 )
181 181
182 AssignBuffers(renderdata, quad) 182 AssignBuffers(renderdata, quad)
194 var start = getMonoTime() 194 var start = getMonoTime()
195 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 195 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
196 196
197 WithNextFrame(framebuffer, commandbuffer): 197 WithNextFrame(framebuffer, commandbuffer):
198 198
199 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 199 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
200 200
201 WithPipeline(commandbuffer, pipeline): 201 WithPipeline(commandbuffer, pipeline):
202 202
203 WithBind(commandbuffer, (uniforms1, ), pipeline): 203 WithBind(commandbuffer, (uniforms1, ), pipeline):
204 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) 204 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad)
254 QuadMesh = object 254 QuadMesh = object
255 position: GPUArray[Vec3f, VertexBuffer] 255 position: GPUArray[Vec3f, VertexBuffer]
256 indices: GPUArray[uint16, IndexBuffer] 256 indices: GPUArray[uint16, IndexBuffer]
257 257
258 var quad = QuadMesh( 258 var quad = QuadMesh(
259 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 259 position: asGPUArray([vec3(-0.5, -0.5), vec3(-0.5, 0.5), vec3(0.5, 0.5), vec3(0.5, -0.5)], VertexBuffer),
260 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 260 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
261 ) 261 )
262 var constset = asDescriptorSet( 262 var constset = asDescriptorSet(
263 ConstSet( 263 ConstSet(
264 constants: asGPUValue(Constants(offset: NewVec2f(-0.3, 0.2)), UniformBuffer), 264 constants: asGPUValue(Constants(offset: vec2(-0.3, 0.2)), UniformBuffer),
265 ) 265 )
266 ) 266 )
267 let G = Gray([50'u8]) 267 let G = Gray([50'u8])
268 let W = Gray([255'u8]) 268 let W = Gray([255'u8])
269 var mainset = asDescriptorSet( 269 var mainset = asDescriptorSet(
270 MainSet( 270 MainSet(
271 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), 271 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped),
272 material: [ 272 material: [
273 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), 273 asGPUValue(Material(baseColor: vec3(1, 1, 0)), UniformBuffer),
274 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), 274 asGPUValue(Material(baseColor: vec3(1, 0, 1)), UniformBuffer),
275 ], 275 ],
276 texture1: [ 276 texture1: [
277 Image[Gray](width: 2, height: 2, data: @[W, G, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), 277 Image[Gray](width: 2, height: 2, data: @[W, G, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST),
278 Image[Gray](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), 278 Image[Gray](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST),
279 ], 279 ],
308 var start = getMonoTime() 308 var start = getMonoTime()
309 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 309 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
310 310
311 WithNextFrame(framebuffer, commandbuffer): 311 WithNextFrame(framebuffer, commandbuffer):
312 312
313 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 313 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
314 314
315 WithPipeline(commandbuffer, pipeline): 315 WithPipeline(commandbuffer, pipeline):
316 316
317 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline): 317 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline):
318 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) 318 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad)
356 position: GPUArray[Vec3f, VertexBuffer] 356 position: GPUArray[Vec3f, VertexBuffer]
357 normals: GPUArray[Vec3f, VertexBuffer] 357 normals: GPUArray[Vec3f, VertexBuffer]
358 color: GPUArray[Vec4f, VertexBuffer] 358 color: GPUArray[Vec4f, VertexBuffer]
359 359
360 let quad = @[ 360 let quad = @[
361 NewVec3f(-0.5, -0.5), NewVec3f(-0.5, +0.5), NewVec3f(+0.5, +0.5), 361 vec3(-0.5, -0.5), vec3(-0.5, +0.5), vec3(+0.5, +0.5),
362 NewVec3f(+0.5, +0.5), NewVec3f(+0.5, -0.5), NewVec3f(-0.5, -0.5), 362 vec3(+0.5, +0.5), vec3(+0.5, -0.5), vec3(-0.5, -0.5),
363 ] 363 ]
364 proc transf(data: seq[Vec3f], mat: Mat4): seq[Vec3f] = 364 proc transf(data: seq[Vec3f], mat: Mat4): seq[Vec3f] =
365 for v in data: 365 for v in data:
366 result.add mat * v 366 result.add mat * v
367 367
369 vertices: seq[Vec3f] 369 vertices: seq[Vec3f]
370 colors: seq[Vec4f] 370 colors: seq[Vec4f]
371 normals: seq[Vec3f] 371 normals: seq[Vec3f]
372 372
373 # front, red 373 # front, red
374 vertices.add quad.transf(Translate(0, 0, -0.5)) 374 vertices.add quad.transf(translate(0, 0, -0.5))
375 colors.add newSeqWith(6, NewVec4f(1, 0, 0, 1)) 375 colors.add newSeqWith(6, vec4(1, 0, 0, 1))
376 normals.add newSeqWith(6, NewVec3f(0, 0, -1)) 376 normals.add newSeqWith(6, vec3(0, 0, -1))
377 377
378 # back, cyan 378 # back, cyan
379 vertices.add quad.transf(Rotate(PI, Y) * Translate(0, 0, -0.5)) 379 vertices.add quad.transf(rotate(PI, Y) * translate(0, 0, -0.5))
380 colors.add newSeqWith(6, NewVec4f(0, 1, 1, 1)) 380 colors.add newSeqWith(6, vec4(0, 1, 1, 1))
381 normals.add newSeqWith(6, NewVec3f(0, 0, 1)) 381 normals.add newSeqWith(6, vec3(0, 0, 1))
382 382
383 # right, green 383 # right, green
384 vertices.add quad.transf(Rotate(PI / 2, Y) * Translate(0, 0, -0.5)) 384 vertices.add quad.transf(rotate(PI / 2, Y) * translate(0, 0, -0.5))
385 colors.add newSeqWith(6, NewVec4f(0, 1, 0, 1)) 385 colors.add newSeqWith(6, vec4(0, 1, 0, 1))
386 normals.add newSeqWith(6, NewVec3f(-1, 0, 0)) 386 normals.add newSeqWith(6, vec3(-1, 0, 0))
387 387
388 # left, magenta 388 # left, magenta
389 vertices.add quad.transf(Rotate(-PI / 2, Y) * Translate(0, 0, -0.5)) 389 vertices.add quad.transf(rotate(-PI / 2, Y) * translate(0, 0, -0.5))
390 colors.add newSeqWith(6, NewVec4f(1, 0, 1, 1)) 390 colors.add newSeqWith(6, vec4(1, 0, 1, 1))
391 normals.add newSeqWith(6, NewVec3f(1, 0, 0)) 391 normals.add newSeqWith(6, vec3(1, 0, 0))
392 392
393 # bottom, blue 393 # bottom, blue
394 vertices.add quad.transf(Rotate(PI / 2, X) * Translate(0, 0, -0.5)) 394 vertices.add quad.transf(rotate(PI / 2, X) * translate(0, 0, -0.5))
395 colors.add newSeqWith(6, NewVec4f(0, 0, 1, 1)) 395 colors.add newSeqWith(6, vec4(0, 0, 1, 1))
396 normals.add newSeqWith(6, NewVec3f(0, -1, 0)) 396 normals.add newSeqWith(6, vec3(0, -1, 0))
397 397
398 # top, yellow 398 # top, yellow
399 vertices.add quad.transf(Rotate(-PI / 2, X) * Translate(0, 0, -0.5)) 399 vertices.add quad.transf(rotate(-PI / 2, X) * translate(0, 0, -0.5))
400 colors.add newSeqWith(6, NewVec4f(1, 1, 0, 1)) 400 colors.add newSeqWith(6, vec4(1, 1, 0, 1))
401 normals.add newSeqWith(6, NewVec3f(0, 1, 0)) 401 normals.add newSeqWith(6, vec3(0, 1, 0))
402 402
403 var renderdata = InitRenderData() 403 var renderdata = InitRenderData()
404 404
405 var mesh = Mesh( 405 var mesh = Mesh(
406 position: asGPUArray(vertices, VertexBuffer), 406 position: asGPUArray(vertices, VertexBuffer),
408 normals: asGPUArray(normals, VertexBuffer), 408 normals: asGPUArray(normals, VertexBuffer),
409 ) 409 )
410 AssignBuffers(renderdata, mesh) 410 AssignBuffers(renderdata, mesh)
411 411
412 var floor = Mesh( 412 var floor = Mesh(
413 position: asGPUArray(quad.transf(Scale(10, 10, 10) * Rotate(-PI / 2, X) * Translate(0, 0, 0.05)), VertexBuffer), 413 position: asGPUArray(quad.transf(scale(10, 10, 10) * rotate(-PI / 2, X) * translate(0, 0, 0.05)), VertexBuffer),
414 color: asGPUArray(newSeqWith(6, NewVec4f(0.1, 0.1, 0.1, 1)), VertexBuffer), 414 color: asGPUArray(newSeqWith(6, vec4(0.1, 0.1, 0.1, 1)), VertexBuffer),
415 normals: asGPUArray(newSeqWith(6, Y), VertexBuffer), 415 normals: asGPUArray(newSeqWith(6, Y), VertexBuffer),
416 ) 416 )
417 AssignBuffers(renderdata, floor) 417 AssignBuffers(renderdata, floor)
418 418
419 var uniforms1 = asDescriptorSet( 419 var uniforms1 = asDescriptorSet(
434 var start = getMonoTime() 434 var start = getMonoTime()
435 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 435 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
436 let tStartLoop = getMonoTime() - tStart 436 let tStartLoop = getMonoTime() - tStart
437 437
438 uniforms1.data.data.data.mvp = ( 438 uniforms1.data.data.data.mvp = (
439 Projection(-PI / 2, GetAspectRatio(), 0.01, 100) * 439 projection(-PI / 2, GetAspectRatio(), 0.01, 100) *
440 Translate(0, 0, 2) * 440 translate(0, 0, 2) *
441 Rotate(PI / 4, X) * 441 rotate(PI / 4, X) *
442 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) 442 rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y)
443 ) 443 )
444 UpdateGPUBuffer(uniforms1.data.data, flush = true) 444 UpdateGPUBuffer(uniforms1.data.data, flush = true)
445 445
446 WithNextFrame(framebuffer, commandbuffer): 446 WithNextFrame(framebuffer, commandbuffer):
447 447
448 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 448 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
449 WithPipeline(commandbuffer, pipeline): 449 WithPipeline(commandbuffer, pipeline):
450 450
451 WithBind(commandbuffer, (uniforms1, ), pipeline): 451 WithBind(commandbuffer, (uniforms1, ), pipeline):
452 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) 452 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh)
453 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) 453 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor)
481 outColor = vec4(fragmentColor, 1);}""" 481 outColor = vec4(fragmentColor, 1);}"""
482 TriangleMesh = object 482 TriangleMesh = object
483 position: GPUArray[Vec3f, VertexBuffer] 483 position: GPUArray[Vec3f, VertexBuffer]
484 color: GPUArray[Vec3f, VertexBuffer] 484 color: GPUArray[Vec3f, VertexBuffer]
485 var triangle = TriangleMesh( 485 var triangle = TriangleMesh(
486 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 486 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer),
487 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), 487 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer),
488 ) 488 )
489 var lines = TriangleMesh( 489 var lines = TriangleMesh(
490 position: asGPUArray([NewVec3f(-0.9, 0), NewVec3f(-0.05, -0.9), NewVec3f(0.05, -0.9), NewVec3f(0.9, 0)], VertexBuffer), 490 position: asGPUArray([vec3(-0.9, 0, 0), vec3(-0.05, -0.9, 0), vec3(0.05, -0.9, 0), vec3(0.9, 0, 0)], VertexBuffer),
491 color: asGPUArray([NewVec3f(1, 1, 0), NewVec3f(1, 1, 0), NewVec3f(0, 1, 0), NewVec3f(0, 1, 0)], VertexBuffer), 491 color: asGPUArray([vec3(1, 1, 0), vec3(1, 1, 0), vec3(0, 1, 0), vec3(0, 1, 0)], VertexBuffer),
492 ) 492 )
493 AssignBuffers(renderdata, triangle) 493 AssignBuffers(renderdata, triangle)
494 AssignBuffers(renderdata, lines) 494 AssignBuffers(renderdata, lines)
495 renderdata.FlushAllMemory() 495 renderdata.FlushAllMemory()
496 496
500 var pipeline4 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST) 500 var pipeline4 = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST)
501 501
502 var start = getMonoTime() 502 var start = getMonoTime()
503 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 503 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
504 WithNextFrame(framebuffer, commandbuffer): 504 WithNextFrame(framebuffer, commandbuffer):
505 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 505 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
506 WithPipeline(commandbuffer, pipeline1): 506 WithPipeline(commandbuffer, pipeline1):
507 Render(commandbuffer = commandbuffer, pipeline = pipeline1, mesh = triangle) 507 Render(commandbuffer = commandbuffer, pipeline = pipeline1, mesh = triangle)
508 WithPipeline(commandbuffer, pipeline2): 508 WithPipeline(commandbuffer, pipeline2):
509 Render(commandbuffer = commandbuffer, pipeline = pipeline2, mesh = triangle) 509 Render(commandbuffer = commandbuffer, pipeline = pipeline2, mesh = triangle)
510 WithPipeline(commandbuffer, pipeline3): 510 WithPipeline(commandbuffer, pipeline3):
545 Quad = object 545 Quad = object
546 position: GPUArray[Vec3f, VertexBuffer] 546 position: GPUArray[Vec3f, VertexBuffer]
547 uv: GPUArray[Vec2f, VertexBuffer] 547 uv: GPUArray[Vec2f, VertexBuffer]
548 var mesh = Quad( 548 var mesh = Quad(
549 position: asGPUArray([ 549 position: asGPUArray([
550 NewVec3f(-0.8, -0.5), NewVec3f(-0.8, 0.5), NewVec3f(0.8, 0.5), 550 vec3(-0.8, -0.5), vec3(-0.8, 0.5), vec3(0.8, 0.5),
551 NewVec3f(0.8, 0.5), NewVec3f(0.8, -0.5), NewVec3f(-0.8, -0.5), 551 vec3(0.8, 0.5), vec3(0.8, -0.5), vec3(-0.8, -0.5),
552 ], VertexBuffer), 552 ], VertexBuffer),
553 uv: asGPUArray([ 553 uv: asGPUArray([
554 NewVec2f(0, 1), NewVec2f(0, 0), NewVec2f(1, 0), 554 vec2(0, 1), vec2(0, 0), vec2(1, 0),
555 NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1), 555 vec2(1, 0), vec2(1, 1), vec2(0, 1),
556 ], VertexBuffer), 556 ], VertexBuffer),
557 ) 557 )
558 AssignBuffers(renderdata, mesh) 558 AssignBuffers(renderdata, mesh)
559 renderdata.FlushAllMemory() 559 renderdata.FlushAllMemory()
560 560
570 var start = getMonoTime() 570 var start = getMonoTime()
571 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 571 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
572 572
573 WithNextFrame(framebuffer, commandbuffer): 573 WithNextFrame(framebuffer, commandbuffer):
574 574
575 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 575 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
576 576
577 WithPipeline(commandbuffer, pipeline): 577 WithPipeline(commandbuffer, pipeline):
578 578
579 WithBind(commandbuffer, (uniforms1, ), pipeline): 579 WithBind(commandbuffer, (uniforms1, ), pipeline):
580 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) 580 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh)
631 color: GPUArray[Vec3f, VertexBuffer] 631 color: GPUArray[Vec3f, VertexBuffer]
632 QuadMesh = object 632 QuadMesh = object
633 position: GPUArray[Vec2f, VertexBuffer] 633 position: GPUArray[Vec2f, VertexBuffer]
634 indices: GPUArray[uint16, IndexBuffer] 634 indices: GPUArray[uint16, IndexBuffer]
635 var mesh = TriangleMesh( 635 var mesh = TriangleMesh(
636 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), 636 position: asGPUArray([vec3(-0.5, -0.5), vec3(0, 0.5), vec3(0.5, -0.5)], VertexBuffer),
637 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), 637 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer),
638 ) 638 )
639 var quad = QuadMesh( 639 var quad = QuadMesh(
640 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), 640 position: asGPUArray([vec2(-1, -1), vec2(-1, 1), vec2(1, 1), vec2(1, -1)], VertexBuffer),
641 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), 641 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer),
642 ) 642 )
643 var uniforms1 = asDescriptorSet( 643 var uniforms1 = asDescriptorSet(
644 Uniforms( 644 Uniforms(
645 frameTexture: Image[BGRA](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), 645 frameTexture: Image[BGRA](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true),
733 var start = getMonoTime() 733 var start = getMonoTime()
734 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 734 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
735 735
736 WithNextFrame(framebuffer, commandbuffer): 736 WithNextFrame(framebuffer, commandbuffer):
737 737
738 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 738 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
739 WithPipeline(commandbuffer, drawPipeline): 739 WithPipeline(commandbuffer, drawPipeline):
740 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) 740 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh)
741 741
742 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 742 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
743 743
744 WithPipeline(commandbuffer, presentPipeline): 744 WithPipeline(commandbuffer, presentPipeline):
745 745
746 WithBind(commandbuffer, (uniforms1, ), presentPipeline): 746 WithBind(commandbuffer, (uniforms1, ), presentPipeline):
747 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) 747 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad)