annotate tests/test_rendering.nim @ 1204:e2901100a596 compiletime-tests

add: tests, some fixes, some helpers
author sam <sam@basx.dev>
date Mon, 15 Jul 2024 23:51:17 +0700
parents 6360c8d17ce0
children f7530247a21f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
1 import std/options
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
2 import std/random
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
3
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
4 import ../semicongine
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
5
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
6 var
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
7 mainRenderpass: VkRenderPass
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
8 swapchain: Swapchain
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
9
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
10 proc test_01_triangle(nFrames: int) =
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
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
36 pipeline = CreatePipeline[TrianglShader](renderPass = mainRenderpass, samples = swapchain.samples)
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
37
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
38 var c = 0
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
39 while UpdateInputs() and c < nFrames:
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
40 WithNextFrame(swapchain, framebuffer, commandbuffer):
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
41 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
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)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
44 inc c
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
45
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
46 # cleanup
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
47 checkVkResult vkDeviceWaitIdle(vulkan.device)
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
48 DestroyPipeline(pipeline)
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
49 DestroyRenderData(renderdata)
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
50
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
51
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
52 proc test_02_triangle_quad_instanced(nFrames: int) =
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
53 var renderdata = InitRenderData()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
54
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
55 type
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
56 SomeShader = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
57 position {.VertexAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
58 color {.VertexAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
59 pos {.InstanceAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
60 scale {.InstanceAttribute.}: float32
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
61 fragmentColor {.Pass.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
62 outColor {.ShaderOutput.}: Vec4f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
63 # code
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
64 vertexCode: string = """void main() {
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
65 fragmentColor = color;
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
66 gl_Position = vec4((position * scale) + pos, 1);}"""
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
67 fragmentCode: string = """void main() {
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
68 outColor = vec4(fragmentColor, 1);}"""
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
69 TriangleMesh = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
70 position: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
71 color: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
72 QuadMesh = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
73 position: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
74 color: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
75 indices: GPUArray[uint16, IndexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
76 Instances = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
77 pos: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
78 scale: GPUArray[float32, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
79 var tri = TriangleMesh(
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
80 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
81 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
82 )
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
83 var quad = QuadMesh(
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
84 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
85 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
86 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
87 )
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
88
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
89 var instancesA: Instances
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
90 for n in 1..100:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
91 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
92 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
93 var instancesB: Instances
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
94 for n in 1..100:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
95 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
96 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
97
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
98 AssignBuffers(renderdata, tri)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
99 AssignBuffers(renderdata, quad)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
100 AssignBuffers(renderdata, instancesA)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
101 AssignBuffers(renderdata, instancesB)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
102 renderdata.FlushAllMemory()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
103
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
104 var pipeline = CreatePipeline[SomeShader](renderPass = mainRenderpass, samples = swapchain.samples)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
105
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
106 var c = 0
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
107 while UpdateInputs() and c < nFrames:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
108 WithNextFrame(swapchain, framebuffer, commandbuffer):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
109 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
110 WithPipeline(commandbuffer, pipeline):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
111 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
112 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
113 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
114 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
115 inc c
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
116
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
117 # cleanup
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
118 checkVkResult vkDeviceWaitIdle(vulkan.device)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
119 DestroyPipeline(pipeline)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
120 DestroyRenderData(renderdata)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
121
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
122 proc test_03_global_descriptorset(nFrames: int) =
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
123 var renderdata = InitRenderData()
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
124
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
125 type
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
126 RenderSettings = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
127 gamma: float32
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
128 FirstDS = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
129 settings: GPUValue[RenderSettings, UniformBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
130 QuadShader = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
131 position {.VertexAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
132 color {.VertexAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
133 fragmentColor {.Pass.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
134 outColor {.ShaderOutput.}: Vec4f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
135 firstDS: DescriptorSet[FirstDS, First]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
136 # code
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
137 vertexCode: string = """void main() {
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
138 fragmentColor = vec3(pow(color.r, settings.gamma), pow(color.g, settings.gamma), pow(color.b, settings.gamma));
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
139 gl_Position = vec4(position, 1);}"""
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
140 fragmentCode: string = """void main() {
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
141 outColor = vec4(fragmentColor, 1);}"""
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
142 QuadMesh = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
143 position: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
144 color: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
145 indices: GPUArray[uint16, IndexBuffer]
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
146
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
147 var quad = QuadMesh(
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
148 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
149 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
150 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
151 )
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
152 var firstDs = DescriptorSet[FirstDS, First](
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
153 data: FirstDS(
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
154 settings: asGPUValue(RenderSettings(
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
155 gamma: 1.0'f32
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
156 ), UniformBuffer)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
157 )
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
158 )
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
159 AssignBuffers(renderdata, quad)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
160 AssignBuffers(renderdata, firstDs)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
161 renderdata.FlushAllMemory()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
162
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
163 var pipeline = CreatePipeline[QuadShader](renderPass = mainRenderpass, samples = swapchain.samples)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
164
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
165 var c = 0
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
166 while UpdateInputs() and c < nFrames:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
167 WithNextFrame(swapchain, framebuffer, commandbuffer):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
168 WithBind(commandbuffer, firstDs, pipeline, swapchain.currentFiF):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
169 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
170 WithPipeline(commandbuffer, pipeline):
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
171 Render(commandbuffer = commandbuffer, pipeline = pipeline, firstSet = firstDs, mesh = quad)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
172 inc c
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
173
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
174 # cleanup
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
175 checkVkResult vkDeviceWaitIdle(vulkan.device)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
176 DestroyPipeline(pipeline)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
177 DestroyRenderData(renderdata)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
178
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
179 when isMainModule:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
180 var nFrames = 100
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
181 InitVulkan()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
182
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
183 # test normal
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
184 block:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
185 mainRenderpass = CreatePresentationRenderPass()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
186 swapchain = InitSwapchain(renderpass = mainRenderpass).get()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
187
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
188 # tests a simple triangle with minimalistic shader and vertex format
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
189 test_01_triangle(nFrames)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
190
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
191 # tests instanced triangles and quads, mixing meshes and instances
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
192 test_02_triangle_quad_instanced(nFrames)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
193
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
194 # tests
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
195 test_03_global_descriptorset(nFrames)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
196
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
197 checkVkResult vkDeviceWaitIdle(vulkan.device)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
198 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
199 DestroySwapchain(swapchain)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
200
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
201 # test MSAA
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
202 block:
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
203 mainRenderpass = CreatePresentationRenderPass(samples = VK_SAMPLE_COUNT_4_BIT)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
204 swapchain = InitSwapchain(renderpass = mainRenderpass, samples = VK_SAMPLE_COUNT_4_BIT).get()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
205
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
206 test_01_triangle(nFrames)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
207
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
208 checkVkResult vkDeviceWaitIdle(vulkan.device)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
209 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
210 DestroySwapchain(swapchain)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
211
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
212 DestroyVulkan()