annotate tests/test_rendering.nim @ 1214:04e446a7eb2b compiletime-tests

add: multipass renderer, finish tets for now
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 20:11:55 +0700
parents f9919ea98e5b
children 55896320c8bf
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
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
10 proc test_01_triangle(nFrames: int, renderPass: VkRenderPass, samples = VK_SAMPLE_COUNT_1_BIT) =
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
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
36 pipeline = CreatePipeline[TrianglShader](renderPass = renderPass, samples = 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):
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
41 WithRenderPass(renderPass, framebuffer, commandbuffer, swapchain.width, 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)
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
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
52 proc test_02_triangle_quad_instanced(nFrames: int, renderPass: VkRenderPass, samples = VK_SAMPLE_COUNT_1_BIT) =
1204
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
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
104 var pipeline = CreatePipeline[SomeShader](renderPass = renderPass, samples = samples)
1204
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):
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
109 WithRenderPass(renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
1204
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
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
122 proc test_03_simple_descriptorset(nFrames: int, renderPass: VkRenderPass, samples = VK_SAMPLE_COUNT_1_BIT) =
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
123 var renderdata = InitRenderData()
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
124
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
125 type
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
126 Material = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
127 baseColor: Vec3f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
128
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
129 Uniforms = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
130 material: GPUValue[Material, UniformBuffer]
1212
518a952eccbf did: increase texture format compatability
sam <sam@basx.dev>
parents: 1211
diff changeset
131 texture1: Texture[TVec4[uint8]]
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
132
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
133 QuadShader = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
134 position {.VertexAttribute.}: Vec3f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
135 fragmentColor {.Pass.}: Vec3f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
136 uv {.Pass.}: Vec2f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
137 outColor {.ShaderOutput.}: Vec4f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
138 descriptorSets {.DescriptorSets.}: (Uniforms, )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
139 # code
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
140 vertexCode: string = """void main() {
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
141 fragmentColor = material.baseColor;
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
142 gl_Position = vec4(position, 1);
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
143 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
144 uv = position.xy + 0.5;
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
145 }"""
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
146 fragmentCode: string = """void main() {
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
147 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}"""
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
148 QuadMesh = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
149 position: GPUArray[Vec3f, VertexBuffer]
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
150 indices: GPUArray[uint16, IndexBuffer]
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
151
1212
518a952eccbf did: increase texture format compatability
sam <sam@basx.dev>
parents: 1211
diff changeset
152 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
153 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
154 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
155 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
156 var
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
157 quad = QuadMesh(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
158 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
159 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
160 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
161 uniforms1 = asDescriptorSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
162 Uniforms(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
163 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer),
1212
518a952eccbf did: increase texture format compatability
sam <sam@basx.dev>
parents: 1211
diff changeset
164 texture1: Texture[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
165 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
166 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
167 uniforms2 = asDescriptorSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
168 Uniforms(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
169 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer),
1212
518a952eccbf did: increase texture format compatability
sam <sam@basx.dev>
parents: 1211
diff changeset
170 texture1: Texture[TVec4[uint8]](width: 2, height: 2, data: @[R, G, B, W]),
518a952eccbf did: increase texture format compatability
sam <sam@basx.dev>
parents: 1211
diff changeset
171 )
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
172 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
173
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
174 AssignBuffers(renderdata, quad)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
175 AssignBuffers(renderdata, uniforms1)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
176 AssignBuffers(renderdata, uniforms2)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
177 UploadTextures(renderdata, uniforms1)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
178 UploadTextures(renderdata, uniforms2)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
179 renderdata.FlushAllMemory()
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
180
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
181 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples)
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
182
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
183 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
184 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
185
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
186 var c = 0
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
187 while UpdateInputs() and c < nFrames:
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
188 WithNextFrame(swapchain, framebuffer, commandbuffer):
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
189 WithRenderPass(renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
190 WithPipeline(commandbuffer, pipeline):
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
191 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF):
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 WithBind(commandbuffer, (uniforms2, ), pipeline, swapchain.currentFiF):
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
194 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
195 inc c
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
196
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
197 # cleanup
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
198 checkVkResult vkDeviceWaitIdle(vulkan.device)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
199 DestroyPipeline(pipeline)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
200 DestroyRenderData(renderdata)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
201
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
202 proc test_04_multiple_descriptorsets(nFrames: int, renderPass: VkRenderPass, samples = VK_SAMPLE_COUNT_1_BIT) =
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
203 var renderdata = InitRenderData()
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
204
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
205 type
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
206 RenderSettings = object
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
207 brigthness: float32
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
208 Material = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
209 baseColor: Vec3f
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
210 ObjectSettings = object
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
211 scale: float32
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
212 materialIndex: uint32
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
213 Constants = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
214 offset: Vec2f
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
215
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
216 ConstSet = object
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
217 constants: GPUValue[Constants, UniformBuffer]
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
218 MainSet = object
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
219 renderSettings: GPUValue[RenderSettings, UniformBufferMapped]
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
220 material: array[2, GPUValue[Material, UniformBuffer]]
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
221 texture1: array[2, Texture[TVec1[uint8]]]
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
222 OtherSet = object
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
223 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped]
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
224
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
225 QuadShader = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
226 position {.VertexAttribute.}: Vec3f
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
227 fragmentColor {.Pass.}: Vec3f
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
228 uv {.Pass.}: Vec2f
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
229 outColor {.ShaderOutput.}: Vec4f
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
230 descriptorSets {.DescriptorSets.}: (ConstSet, MainSet, OtherSet)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
231 # code
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
232 vertexCode: string = """void main() {
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
233 fragmentColor = material[objectSettings.materialIndex].baseColor * renderSettings.brigthness;
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
234 gl_Position = vec4(position * objectSettings.scale, 1);
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
235 gl_Position.xy += constants.offset.xy;
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
236 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
237 uv = position.xy + 0.5;
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 fragmentCode: string = """void main() {
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
240 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
241 }"""
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
242 QuadMesh = object
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
243 position: GPUArray[Vec3f, VertexBuffer]
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
244 indices: GPUArray[uint16, IndexBuffer]
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
245
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
246 var quad = QuadMesh(
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
247 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
248 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
249 )
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
250 var constset = asDescriptorSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
251 ConstSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
252 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
253 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
254 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
255 let G = TVec1[uint8]([50'u8])
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
256 let W = TVec1[uint8]([255'u8])
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
257 var mainset = asDescriptorSet(
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
258 MainSet(
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
259 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped),
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
260 material: [
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
261 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer),
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
262 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer),
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
263 ],
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
264 texture1: [
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
265 Texture[TVec1[uint8]](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST),
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
266 Texture[TVec1[uint8]](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST),
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
267 ],
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
268 ),
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
269 )
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
270 var otherset1 = asDescriptorSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
271 OtherSet(
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
272 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 0), UniformBufferMapped),
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
273 )
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
274 )
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
275 var otherset2 = asDescriptorSet(
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
276 OtherSet(
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
277 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 1), UniformBufferMapped),
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
278 )
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
279 )
1209
e177336cac3f sync to notebook in bedroom
sam <sam@basx.dev>
parents: 1208
diff changeset
280
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
281 AssignBuffers(renderdata, quad)
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
282 AssignBuffers(renderdata, constset)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
283 AssignBuffers(renderdata, mainset)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
284 AssignBuffers(renderdata, otherset1)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
285 AssignBuffers(renderdata, otherset2)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
286 UploadTextures(renderdata, mainset)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
287 renderdata.FlushAllMemory()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
288
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
289 var pipeline = CreatePipeline[QuadShader](renderPass = renderPass, samples = samples)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
290
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
292 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
293 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
294 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
295
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
296 var c = 0
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
297 while UpdateInputs() and c < nFrames:
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
298 TimeAndLog:
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
299 WithNextFrame(swapchain, framebuffer, commandbuffer):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
300 WithRenderPass(renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
301 WithPipeline(commandbuffer, pipeline):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
302 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline, swapchain.currentFiF):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
303 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
304 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline, swapchain.currentFiF):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
305 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad)
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
306 mainset.data.renderSettings.data.brigthness = (c.float32 / nFrames.float32)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
307 otherset1.data.objectSettings.data.scale = 0.5 + (c.float32 / nFrames.float32)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
308 UpdateGPUBuffer(mainset.data.renderSettings)
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
309 UpdateGPUBuffer(otherset1.data.objectSettings)
1205
f7530247a21f did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents: 1204
diff changeset
310 renderdata.FlushAllMemory()
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
311 inc c
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
312
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
313 # cleanup
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
314 checkVkResult vkDeviceWaitIdle(vulkan.device)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
315 DestroyPipeline(pipeline)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
316 DestroyRenderData(renderdata)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
317
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
318 proc test_05_triangle_2pass(nFrames: int, samples = VK_SAMPLE_COUNT_1_BIT) =
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
319 var
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
320 (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
321 swapchain = InitSwapchain(renderpass = presentRP).get()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
322
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
323 var renderdata = InitRenderData()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
324
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
325 type
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
326 Uniforms = object
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
327 frameTexture: Texture[TVec4[uint8]]
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
328 TriangleShader = object
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
329 position {.VertexAttribute.}: Vec3f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
330 color {.VertexAttribute.}: Vec3f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
331 fragmentColor {.Pass.}: Vec3f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
332 outColor {.ShaderOutput.}: Vec4f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
333 # code
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
334 vertexCode: string = """void main() {
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
335 fragmentColor = color;
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
336 gl_Position = vec4(position, 1);}"""
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
337 fragmentCode: string = """void main() {
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
338 outColor = vec4(fragmentColor, 1);}"""
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
339 PresentShader = object
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
340 position {.VertexAttribute.}: Vec2f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
341 uv {.Pass.}: Vec2f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
342 outColor {.ShaderOutput.}: Vec4f
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
343 descriptorSets {.DescriptorSets.}: (Uniforms, )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
344 # code
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
345 vertexCode: string = """void main() {
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
346 uv = ((position + 1) * 0.5) * vec2(1, -1);
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
347 gl_Position = vec4(position, 0, 1);}"""
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
348 fragmentCode: string = """void main() {
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
349 vec2 uv1 = uv + vec2(0.001, 0.001);
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
350 vec2 uv2 = uv + vec2(0.001, -0.001);
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
351 vec2 uv3 = uv + vec2(-0.001, 0.001);
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
352 vec2 uv4 = uv + vec2(-0.001, -0.001);
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
353 outColor = (
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
354 texture(frameTexture, uv1) +
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
355 texture(frameTexture, uv2) +
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
356 texture(frameTexture, uv3) +
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
357 texture(frameTexture, uv4)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
358 ) / 4;
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
359 }"""
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
360 TriangleMesh = object
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
361 position: GPUArray[Vec3f, VertexBuffer]
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
362 color: GPUArray[Vec3f, VertexBuffer]
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
363 QuadMesh = object
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
364 position: GPUArray[Vec2f, VertexBuffer]
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
365 indices: GPUArray[uint16, IndexBuffer]
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
366 var mesh = TriangleMesh(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
367 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
368 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
369 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
370 var quad = QuadMesh(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
371 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
372 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
373 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
374 var uniforms1 = asDescriptorSet(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
375 Uniforms(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
376 frameTexture: Texture[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true),
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
377 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
378 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
379 var uniforms2 = asDescriptorSet(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
380 Uniforms(
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
381 frameTexture: Texture[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true),
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
382 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
383 )
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
384 AssignBuffers(renderdata, mesh)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
385 AssignBuffers(renderdata, quad)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
386 UploadTextures(renderdata, uniforms1)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
387 UploadTextures(renderdata, uniforms2)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
388 renderdata.FlushAllMemory()
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
389
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
390 var
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
391 drawPipeline = CreatePipeline[TriangleShader](renderPass = offscreenRP, samples = samples)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
392 presentPipeline = CreatePipeline[PresentShader](renderPass = presentRP, samples = samples)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
393
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
394 InitDescriptorSet(renderdata, presentPipeline.descriptorSetLayouts[0], uniforms1)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
395 InitDescriptorSet(renderdata, presentPipeline.descriptorSetLayouts[0], uniforms2)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
396
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
397 var offscreenFB = svkCreateFramebuffer(offscreenRP, swapchain.width, swapchain.height, [uniforms1.data.frameTexture.imageview])
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
398
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
399 var c = 0
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
400 while UpdateInputs() and c < nFrames:
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
401
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
402 TimeAndLog:
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
403 WithNextFrame(swapchain, framebuffer, commandbuffer):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
404
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
405 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
406 WithPipeline(commandbuffer, drawPipeline):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
407 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
408
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
409 WithRenderPass(presentRP, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
410 WithPipeline(commandbuffer, presentPipeline):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
411 WithBind(commandbuffer, (uniforms1, ), presentPipeline, swapchain.currentFiF):
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
412 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
413 inc c
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
414
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
415 # cleanup
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
416 checkVkResult vkDeviceWaitIdle(vulkan.device)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
417 DestroyPipeline(presentPipeline)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
418 DestroyPipeline(drawPipeline)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
419 DestroyRenderData(renderdata)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
420 vkDestroyRenderPass(vulkan.device, offscreenRP, nil)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
421 vkDestroyRenderPass(vulkan.device, presentRP, nil)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
422 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
423 DestroySwapchain(swapchain)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
424
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
425 when isMainModule:
1211
d9799f74f5a7 did: cleanup and enable all tests
sam <sam@basx.dev>
parents: 1210
diff changeset
426 var nFrames = 2000
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
427 InitVulkan()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
428
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
429
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
430 # test normal
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
431 block:
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
432 mainRenderpass = CreateDirectPresentationRenderPass()
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
433 swapchain = InitSwapchain(renderpass = mainRenderpass).get()
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
434
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
435 # tests a simple triangle with minimalistic shader and vertex format
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
436 test_01_triangle(nFrames, renderPass = mainRenderpass)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
437
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
438 # tests instanced triangles and quads, mixing meshes and instances
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
439 test_02_triangle_quad_instanced(nFrames, renderPass = mainRenderpass)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
440
1211
d9799f74f5a7 did: cleanup and enable all tests
sam <sam@basx.dev>
parents: 1210
diff changeset
441 # teste descriptor sets
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
442 test_03_simple_descriptorset(nFrames, renderPass = mainRenderpass)
1210
570ac1620fb6 fix: make uniform-block-arrays working
sam <sam@basx.dev>
parents: 1209
diff changeset
443
1211
d9799f74f5a7 did: cleanup and enable all tests
sam <sam@basx.dev>
parents: 1210
diff changeset
444 # tests multiple descriptor sets and arrays
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
445 test_04_multiple_descriptorsets(nFrames, renderPass = mainRenderpass)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
446
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
447 checkVkResult vkDeviceWaitIdle(vulkan.device)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
448 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
449 DestroySwapchain(swapchain)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
450
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
451 # test MSAA
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
452 block:
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
453 mainRenderpass = CreateDirectPresentationRenderPass(samples = VK_SAMPLE_COUNT_4_BIT)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
454 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
455
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
456 test_01_triangle(nFrames, renderPass = mainRenderpass, VK_SAMPLE_COUNT_4_BIT)
1204
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
457
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
458 checkVkResult vkDeviceWaitIdle(vulkan.device)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
459 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
460 DestroySwapchain(swapchain)
e2901100a596 add: tests, some fixes, some helpers
sam <sam@basx.dev>
parents: 1203
diff changeset
461
1214
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
462 # test multiple render passes
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
463 block:
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
464 test_05_triangle_2pass(999999999)
04e446a7eb2b add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents: 1213
diff changeset
465
1203
6360c8d17ce0 did: preprations to add rendering tests
sam <sam@basx.dev>
parents:
diff changeset
466 DestroyVulkan()