annotate tests/test_rendering.nim @ 1240:42eeb59f3a43

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