Mercurial > games > semicongine
annotate tests/test_rendering.nim @ 1287:bc03dc1efe6e
fix: mat4 inverse
author | sam <sam@basx.dev> |
---|---|
date | Tue, 30 Jul 2024 16:13:31 +0700 |
parents | 6d16003406fb |
children | 6d0162bfe48a |
rev | line source |
---|---|
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
1 import std/os |
1231 | 2 import std/sequtils |
1232 | 3 import std/monotimes |
4 import std/times | |
1203 | 5 import std/options |
1204 | 6 import std/random |
7 | |
1267 | 8 import ../semicongine |
1203 | 9 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
10 proc test_01_triangle(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
11 var renderdata = initRenderData() |
1203 | 12 |
13 type | |
1252 | 14 PushConstant = object |
15 scale: float32 | |
1242 | 16 Shader = object |
1203 | 17 position {.VertexAttribute.}: Vec3f |
18 color {.VertexAttribute.}: Vec3f | |
1252 | 19 pushConstant {.PushConstantAttribute.}: PushConstant |
1203 | 20 fragmentColor {.Pass.}: Vec3f |
21 outColor {.ShaderOutput.}: Vec4f | |
22 # code | |
23 vertexCode: string = """void main() { | |
24 fragmentColor = color; | |
1252 | 25 gl_Position = vec4(position * pushConstant.scale, 1);}""" |
1203 | 26 fragmentCode: string = """void main() { |
27 outColor = vec4(fragmentColor, 1);}""" | |
28 TriangleMesh = object | |
29 position: GPUArray[Vec3f, VertexBuffer] | |
30 color: GPUArray[Vec3f, VertexBuffer] | |
31 var mesh = TriangleMesh( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
32 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
33 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1203 | 34 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
35 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
36 renderdata.flushAllMemory() |
1203 | 37 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
38 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1203 | 39 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
40 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
41 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 42 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
43 withNextFrame(framebuffer, commandbuffer): |
1242 | 44 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
45 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1242 | 46 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
47 withPipeline(commandbuffer, pipeline): |
1242 | 48 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
49 renderWithPushConstant(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh, pushConstant = PushConstant(scale: 0.3 + ((getMonoTime() - start).inMilliseconds().int / 1000))) |
1203 | 50 |
51 # cleanup | |
1204 | 52 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
53 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
54 destroyRenderData(renderdata) |
1203 | 55 |
56 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
57 proc test_02_triangle_quad_instanced(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
58 var renderdata = initRenderData() |
1204 | 59 |
60 type | |
61 SomeShader = object | |
62 position {.VertexAttribute.}: Vec3f | |
63 color {.VertexAttribute.}: Vec3f | |
64 pos {.InstanceAttribute.}: Vec3f | |
65 scale {.InstanceAttribute.}: float32 | |
66 fragmentColor {.Pass.}: Vec3f | |
67 outColor {.ShaderOutput.}: Vec4f | |
68 # code | |
69 vertexCode: string = """void main() { | |
70 fragmentColor = color; | |
71 gl_Position = vec4((position * scale) + pos, 1);}""" | |
72 fragmentCode: string = """void main() { | |
73 outColor = vec4(fragmentColor, 1);}""" | |
74 TriangleMesh = object | |
75 position: GPUArray[Vec3f, VertexBuffer] | |
76 color: GPUArray[Vec3f, VertexBuffer] | |
77 QuadMesh = object | |
78 position: GPUArray[Vec3f, VertexBuffer] | |
79 color: GPUArray[Vec3f, VertexBuffer] | |
80 indices: GPUArray[uint16, IndexBuffer] | |
81 Instances = object | |
82 pos: GPUArray[Vec3f, VertexBuffer] | |
83 scale: GPUArray[float32, VertexBuffer] | |
84 var tri = TriangleMesh( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
85 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
86 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1204 | 87 ) |
88 var quad = QuadMesh( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
89 position: asGPUArray([vec3(-0.3, -0.3, 0), vec3(-0.3, 0.3, 0), vec3(0.3, 0.3, 0), vec3(0.3, -0.3, 0)], VertexBuffer), |
1204 | 90 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
91 color: asGPUArray([vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1), vec3(1, 1, 1)], VertexBuffer), |
1204 | 92 ) |
93 | |
94 var instancesA: Instances | |
95 for n in 1..100: | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
96 instancesA.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32), 0) |
1204 | 97 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32) |
98 var instancesB: Instances | |
99 for n in 1..100: | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
100 instancesB.pos.data.add vec3(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32), 0) |
1204 | 101 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32) |
102 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
103 assignBuffers(renderdata, tri) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
104 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
105 assignBuffers(renderdata, instancesA) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
106 assignBuffers(renderdata, instancesB) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
107 renderdata.flushAllMemory() |
1204 | 108 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
109 var pipeline = createPipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 110 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
111 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
112 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 113 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
114 withNextFrame(framebuffer, commandbuffer): |
1242 | 115 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
116 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1242 | 117 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
118 withPipeline(commandbuffer, pipeline): |
1242 | 119 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
120 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
121 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
122 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
123 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) |
1204 | 124 |
125 # cleanup | |
126 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
127 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
128 destroyRenderData(renderdata) |
1204 | 129 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
130 proc test_03_simple_descriptorset(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
131 var renderdata = initRenderData() |
1210 | 132 |
133 type | |
134 Material = object | |
135 baseColor: Vec3f | |
136 | |
137 Uniforms = object | |
138 material: GPUValue[Material, UniformBuffer] | |
1252 | 139 texture1: Image[BGRA] |
1210 | 140 |
141 QuadShader = object | |
142 position {.VertexAttribute.}: Vec3f | |
143 fragmentColor {.Pass.}: Vec3f | |
144 uv {.Pass.}: Vec2f | |
145 outColor {.ShaderOutput.}: Vec4f | |
146 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
147 # code | |
148 vertexCode: string = """void main() { | |
149 fragmentColor = material.baseColor; | |
150 gl_Position = vec4(position, 1); | |
151 gl_Position.x += ((material.baseColor.b - 0.5) * 2) - 0.5; | |
152 uv = position.xy + 0.5; | |
153 }""" | |
154 fragmentCode: string = """void main() { | |
155 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" | |
156 QuadMesh = object | |
157 position: GPUArray[Vec3f, VertexBuffer] | |
158 indices: GPUArray[uint16, IndexBuffer] | |
159 | |
1252 | 160 let R = BGRA([255'u8, 0'u8, 0'u8, 255'u8]) |
161 let G = BGRA([0'u8, 255'u8, 0'u8, 255'u8]) | |
162 let B = BGRA([0'u8, 0'u8, 255'u8, 255'u8]) | |
163 let W = BGRA([255'u8, 255'u8, 255'u8, 255'u8]) | |
1210 | 164 var |
165 quad = QuadMesh( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
166 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(-0.5, 0.5, 0), vec3(0.5, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer), |
1210 | 167 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
168 ) | |
169 uniforms1 = asDescriptorSet( | |
170 Uniforms( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
171 material: asGPUValue(Material(baseColor: vec3(1, 1, 1)), UniformBuffer), |
1252 | 172 texture1: Image[BGRA](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), |
1210 | 173 ) |
174 ) | |
175 uniforms2 = asDescriptorSet( | |
176 Uniforms( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
177 material: asGPUValue(Material(baseColor: vec3(0.5, 0.5, 0.5)), UniformBuffer), |
1252 | 178 texture1: Image[BGRA](width: 2, height: 2, data: @[R, G, B, W]), |
1212
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
179 ) |
1210 | 180 ) |
181 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
182 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
183 assignBuffers(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
184 assignBuffers(renderdata, uniforms2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
185 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
186 uploadImages(renderdata, uniforms2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
187 renderdata.flushAllMemory() |
1210 | 188 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
189 var pipeline = createPipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1210 | 190 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
191 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
192 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) |
1210 | 193 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
194 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
195 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 196 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
197 withNextFrame(framebuffer, commandbuffer): |
1242 | 198 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
199 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1242 | 200 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
201 withPipeline(commandbuffer, pipeline): |
1242 | 202 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
203 withBind(commandbuffer, (uniforms1, ), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
204 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 205 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
206 withBind(commandbuffer, (uniforms2, ), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
207 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1210 | 208 |
209 # cleanup | |
210 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
211 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
212 destroyRenderData(renderdata) |
1210 | 213 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
214 proc test_04_multiple_descriptorsets(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
215 var renderdata = initRenderData() |
1203 | 216 |
1204 | 217 type |
218 RenderSettings = object | |
1209 | 219 brigthness: float32 |
1210 | 220 Material = object |
221 baseColor: Vec3f | |
1209 | 222 ObjectSettings = object |
1210 | 223 scale: float32 |
224 materialIndex: uint32 | |
225 Constants = object | |
226 offset: Vec2f | |
227 | |
228 ConstSet = object | |
229 constants: GPUValue[Constants, UniformBuffer] | |
1209 | 230 MainSet = object |
231 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] | |
1210 | 232 material: array[2, GPUValue[Material, UniformBuffer]] |
1242 | 233 texture1: array[2, Image[Gray]] |
1209 | 234 OtherSet = object |
1210 | 235 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] |
1209 | 236 |
1204 | 237 QuadShader = object |
238 position {.VertexAttribute.}: Vec3f | |
239 fragmentColor {.Pass.}: Vec3f | |
1210 | 240 uv {.Pass.}: Vec2f |
1204 | 241 outColor {.ShaderOutput.}: Vec4f |
1210 | 242 descriptorSets {.DescriptorSets.}: (ConstSet, MainSet, OtherSet) |
1204 | 243 # code |
244 vertexCode: string = """void main() { | |
1210 | 245 fragmentColor = material[objectSettings.materialIndex].baseColor * renderSettings.brigthness; |
246 gl_Position = vec4(position * objectSettings.scale, 1); | |
247 gl_Position.xy += constants.offset.xy; | |
248 gl_Position.x += material[objectSettings.materialIndex].baseColor.b - 0.5; | |
249 uv = position.xy + 0.5; | |
250 }""" | |
1204 | 251 fragmentCode: string = """void main() { |
1210 | 252 outColor = vec4(fragmentColor * texture(texture1[objectSettings.materialIndex], uv).rrr, 1); |
253 }""" | |
1204 | 254 QuadMesh = object |
255 position: GPUArray[Vec3f, VertexBuffer] | |
256 indices: GPUArray[uint16, IndexBuffer] | |
1203 | 257 |
1204 | 258 var quad = QuadMesh( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
259 position: asGPUArray([vec3(-0.5, -0.5), vec3(-0.5, 0.5), vec3(0.5, 0.5), vec3(0.5, -0.5)], VertexBuffer), |
1204 | 260 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1209 | 261 ) |
1210 | 262 var constset = asDescriptorSet( |
263 ConstSet( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
264 constants: asGPUValue(Constants(offset: vec2(-0.3, 0.2)), UniformBuffer), |
1210 | 265 ) |
266 ) | |
1242 | 267 let G = Gray([50'u8]) |
268 let W = Gray([255'u8]) | |
1210 | 269 var mainset = asDescriptorSet( |
1209 | 270 MainSet( |
271 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), | |
1210 | 272 material: [ |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
273 asGPUValue(Material(baseColor: vec3(1, 1, 0)), UniformBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
274 asGPUValue(Material(baseColor: vec3(1, 0, 1)), UniformBuffer), |
1210 | 275 ], |
276 texture1: [ | |
1252 | 277 Image[Gray](width: 2, height: 2, data: @[W, G, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), |
278 Image[Gray](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], minInterpolation: VK_FILTER_NEAREST, magInterpolation: VK_FILTER_NEAREST), | |
1210 | 279 ], |
280 ), | |
281 ) | |
282 var otherset1 = asDescriptorSet( | |
283 OtherSet( | |
284 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 0), UniformBufferMapped), | |
1209 | 285 ) |
1204 | 286 ) |
1210 | 287 var otherset2 = asDescriptorSet( |
1209 | 288 OtherSet( |
1210 | 289 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 1), UniformBufferMapped), |
1209 | 290 ) |
1204 | 291 ) |
1209 | 292 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
293 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
294 assignBuffers(renderdata, constset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
295 assignBuffers(renderdata, mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
296 assignBuffers(renderdata, otherset1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
297 assignBuffers(renderdata, otherset2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
298 uploadImages(renderdata, mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
299 renderdata.flushAllMemory() |
1204 | 300 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
301 var pipeline = createPipeline[QuadShader](renderPass = vulkan.swapchain.renderPass) |
1204 | 302 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
303 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
304 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
305 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
306 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
|
307 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
308 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
309 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1242 | 310 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
311 withNextFrame(framebuffer, commandbuffer): |
1242 | 312 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
313 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1242 | 314 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
315 withPipeline(commandbuffer, pipeline): |
1242 | 316 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
317 withBind(commandbuffer, (constset, mainset, otherset1), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
318 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 319 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
320 withBind(commandbuffer, (constset, mainset, otherset2), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
321 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1242 | 322 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
323 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
324 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
325 updateGPUBuffer(mainset.data.renderSettings) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
326 updateGPUBuffer(otherset1.data.objectSettings) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
327 renderdata.flushAllMemory() |
1204 | 328 |
329 # cleanup | |
1203 | 330 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
331 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
332 destroyRenderData(renderdata) |
1204 | 333 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
334 proc test_05_cube(time: float32) = |
1231 | 335 type |
336 | |
337 UniformData = object | |
1232 | 338 mvp: Mat4 |
1231 | 339 Uniforms = object |
340 data: GPUValue[UniformData, UniformBufferMapped] | |
341 CubeShader = object | |
342 position {.VertexAttribute.}: Vec3f | |
343 color {.VertexAttribute.}: Vec4f | |
344 fragmentColor {.Pass.}: Vec4f | |
345 outColor {.ShaderOutput.}: Vec4f | |
346 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
347 # code | |
348 vertexCode = """void main() { | |
349 fragmentColor = color; | |
1232 | 350 gl_Position = vec4(position, 1) * data.mvp; |
1231 | 351 }""" |
352 fragmentCode = """void main() { | |
353 outColor = fragmentColor; | |
354 }""" | |
355 Mesh = object | |
356 position: GPUArray[Vec3f, VertexBuffer] | |
357 normals: GPUArray[Vec3f, VertexBuffer] | |
358 color: GPUArray[Vec4f, VertexBuffer] | |
359 | |
360 let quad = @[ | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
361 vec3(-0.5, -0.5), vec3(-0.5, +0.5), vec3(+0.5, +0.5), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
362 vec3(+0.5, +0.5), vec3(+0.5, -0.5), vec3(-0.5, -0.5), |
1231 | 363 ] |
1232 | 364 proc transf(data: seq[Vec3f], mat: Mat4): seq[Vec3f] = |
1231 | 365 for v in data: |
1232 | 366 result.add mat * v |
1231 | 367 |
368 var | |
369 vertices: seq[Vec3f] | |
370 colors: seq[Vec4f] | |
371 normals: seq[Vec3f] | |
372 | |
373 # front, red | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
374 vertices.add quad.transf(translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
375 colors.add newSeqWith(6, vec4(1, 0, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
376 normals.add newSeqWith(6, vec3(0, 0, -1)) |
1231 | 377 |
378 # back, cyan | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
379 vertices.add quad.transf(rotate(PI, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
380 colors.add newSeqWith(6, vec4(0, 1, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
381 normals.add newSeqWith(6, vec3(0, 0, 1)) |
1231 | 382 |
383 # right, green | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
384 vertices.add quad.transf(rotate(PI / 2, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
385 colors.add newSeqWith(6, vec4(0, 1, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
386 normals.add newSeqWith(6, vec3(-1, 0, 0)) |
1231 | 387 |
388 # left, magenta | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
389 vertices.add quad.transf(rotate(-PI / 2, Y) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
390 colors.add newSeqWith(6, vec4(1, 0, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
391 normals.add newSeqWith(6, vec3(1, 0, 0)) |
1231 | 392 |
393 # bottom, blue | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
394 vertices.add quad.transf(rotate(PI / 2, X) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
395 colors.add newSeqWith(6, vec4(0, 0, 1, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
396 normals.add newSeqWith(6, vec3(0, -1, 0)) |
1231 | 397 |
398 # top, yellow | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
399 vertices.add quad.transf(rotate(-PI / 2, X) * translate(0, 0, -0.5)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
400 colors.add newSeqWith(6, vec4(1, 1, 0, 1)) |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
401 normals.add newSeqWith(6, vec3(0, 1, 0)) |
1231 | 402 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
403 var renderdata = initRenderData() |
1231 | 404 |
405 var mesh = Mesh( | |
406 position: asGPUArray(vertices, VertexBuffer), | |
407 color: asGPUArray(colors, VertexBuffer), | |
408 normals: asGPUArray(normals, VertexBuffer), | |
409 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
410 assignBuffers(renderdata, mesh) |
1231 | 411 |
412 var floor = Mesh( | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
413 position: asGPUArray(quad.transf(scale(10, 10, 10) * rotate(-PI / 2, X) * translate(0, 0, 0.05)), VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
414 color: asGPUArray(newSeqWith(6, vec4(0.1, 0.1, 0.1, 1)), VertexBuffer), |
1231 | 415 normals: asGPUArray(newSeqWith(6, Y), VertexBuffer), |
416 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
417 assignBuffers(renderdata, floor) |
1231 | 418 |
419 var uniforms1 = asDescriptorSet( | |
420 Uniforms( | |
1232 | 421 data: asGPUValue(UniformData(mvp: Unit4), UniformBufferMapped) |
1231 | 422 ) |
423 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
424 assignBuffers(renderdata, uniforms1) |
1231 | 425 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
426 renderdata.flushAllMemory() |
1231 | 427 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
428 var pipeline = createPipeline[CubeShader](renderPass = vulkan.swapchain.renderPass) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
429 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
1231 | 430 |
1232 | 431 var tStart = getMonoTime() |
432 var t = tStart | |
1231 | 433 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
434 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
435 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
436 let tStartLoop = getMonoTime() - tStart |
1232 | 437 |
438 uniforms1.data.data.data.mvp = ( | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
439 projection(-PI / 2, getAspectRatio(), 0.01, 100) * |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
440 translate(0, 0, 2) * |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
441 rotate(PI / 4, X) * |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
442 rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) |
1232 | 443 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
444 updateGPUBuffer(uniforms1.data.data, flush = true) |
1242 | 445 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
446 withNextFrame(framebuffer, commandbuffer): |
1242 | 447 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
448 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
449 withPipeline(commandbuffer, pipeline): |
1242 | 450 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
451 withBind(commandbuffer, (uniforms1, ), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
452 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
453 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) |
1233
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
454 |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
455 let tEndLoop = getMonoTime() - tStart |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
456 let looptime = tEndLoop - tStartLoop |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
457 let waitTime = 16_666 - looptime.inMicroseconds |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
458 if waitTime > 0: |
1cf698973dca
did: cleanup tests and old platform layer files
sam <sam@basx.dev>
parents:
1232
diff
changeset
|
459 sleep((waitTime / 1000).int) |
1231 | 460 |
461 # cleanup | |
462 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
463 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
464 destroyRenderData(renderdata) |
1231 | 465 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
466 proc test_06_different_draw_modes(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
467 var renderdata = initRenderData() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
468 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
469 type |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
470 Shader = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
471 position {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
472 color {.VertexAttribute.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
473 fragmentColor {.Pass.}: Vec3f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
474 outColor {.ShaderOutput.}: Vec4f |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
475 # code |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
476 vertexCode: string = """void main() { |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
477 gl_PointSize = 100; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
478 fragmentColor = color; |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
479 gl_Position = vec4(position, 1);}""" |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
480 fragmentCode: string = """void main() { |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
481 outColor = vec4(fragmentColor, 1);}""" |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
482 TriangleMesh = object |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
483 position: GPUArray[Vec3f, VertexBuffer] |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
484 color: GPUArray[Vec3f, VertexBuffer] |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
485 var triangle = TriangleMesh( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
486 position: asGPUArray([vec3(-0.5, -0.5, 0), vec3(0, 0.5, 0), vec3(0.5, -0.5, 0)], VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
487 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
488 ) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
489 var lines = TriangleMesh( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
490 position: asGPUArray([vec3(-0.9, 0, 0), vec3(-0.05, -0.9, 0), vec3(0.05, -0.9, 0), vec3(0.9, 0, 0)], VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
491 color: asGPUArray([vec3(1, 1, 0), vec3(1, 1, 0), vec3(0, 1, 0), vec3(0, 1, 0)], VertexBuffer), |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
492 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
493 assignBuffers(renderdata, triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
494 assignBuffers(renderdata, lines) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
495 renderdata.flushAllMemory() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
496 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
497 var pipeline1 = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass, polygonMode = VK_POLYGON_MODE_LINE, lineWidth = 20'f32) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
498 var pipeline2 = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass, polygonMode = VK_POLYGON_MODE_POINT) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
499 var pipeline3 = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST, lineWidth = 5) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
500 var pipeline4 = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass, topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
501 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
502 var start = getMonoTime() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
503 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
504 withNextFrame(framebuffer, commandbuffer): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
505 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
506 withPipeline(commandbuffer, pipeline1): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
507 render(commandbuffer = commandbuffer, pipeline = pipeline1, mesh = triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
508 withPipeline(commandbuffer, pipeline2): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
509 render(commandbuffer = commandbuffer, pipeline = pipeline2, mesh = triangle) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
510 withPipeline(commandbuffer, pipeline3): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
511 render(commandbuffer = commandbuffer, pipeline = pipeline3, mesh = lines) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
512 withPipeline(commandbuffer, pipeline4): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
513 render(commandbuffer = commandbuffer, pipeline = pipeline4, mesh = lines) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
514 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
515 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
516 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
517 destroyPipeline(pipeline1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
518 destroyPipeline(pipeline2) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
519 destroyPipeline(pipeline3) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
520 destroyPipeline(pipeline4) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
521 destroyRenderData(renderdata) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
522 |
1242 | 523 proc test_07_png_texture(time: float32) = |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
524 var renderdata = initRenderData() |
1242 | 525 |
526 type | |
527 Uniforms = object | |
1252 | 528 texture1: Image[BGRA] |
1242 | 529 Shader = object |
530 position {.VertexAttribute.}: Vec3f | |
531 uv {.VertexAttribute.}: Vec2f | |
532 fragmentUv {.Pass.}: Vec2f | |
533 outColor {.ShaderOutput.}: Vec4f | |
534 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
535 # code | |
536 vertexCode: string = """ | |
537 void main() { | |
538 fragmentUv = uv; | |
539 gl_Position = vec4(position, 1); | |
540 }""" | |
541 fragmentCode: string = """ | |
542 void main() { | |
543 outColor = texture(texture1, fragmentUv); | |
544 }""" | |
545 Quad = object | |
546 position: GPUArray[Vec3f, VertexBuffer] | |
547 uv: GPUArray[Vec2f, VertexBuffer] | |
548 var mesh = Quad( | |
549 position: asGPUArray([ | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
550 vec3(-0.8, -0.5), vec3(-0.8, 0.5), vec3(0.8, 0.5), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
551 vec3(0.8, 0.5), vec3(0.8, -0.5), vec3(-0.8, -0.5), |
1242 | 552 ], VertexBuffer), |
553 uv: asGPUArray([ | |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
554 vec2(0, 1), vec2(0, 0), vec2(1, 0), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
555 vec2(1, 0), vec2(1, 1), vec2(0, 1), |
1242 | 556 ], VertexBuffer), |
557 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
558 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
559 renderdata.flushAllMemory() |
1242 | 560 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
561 var pipeline = createPipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
1242 | 562 var uniforms1 = asDescriptorSet( |
563 Uniforms( | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
564 texture1: loadImage[BGRA]("art.png"), |
1242 | 565 ) |
566 ) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
567 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
568 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
1242 | 569 |
570 var start = getMonoTime() | |
571 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
572 | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
573 withNextFrame(framebuffer, commandbuffer): |
1242 | 574 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
575 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1242 | 576 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
577 withPipeline(commandbuffer, pipeline): |
1242 | 578 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
579 withBind(commandbuffer, (uniforms1, ), pipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
580 render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
1242 | 581 |
582 # cleanup | |
583 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
584 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
585 destroyRenderData(renderdata) |
1242 | 586 |
587 proc test_08_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
588 var (offscreenRP, presentRP) = createIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
589 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
590 setupSwapchain(renderpass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
591 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
592 var renderdata = initRenderData() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
593 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
594 type |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
595 Uniforms = object |
1252 | 596 frameTexture: Image[BGRA] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
597 TriangleShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
598 position {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
599 color {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
600 fragmentColor {.Pass.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
601 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
602 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
603 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
604 fragmentColor = color; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
605 gl_Position = vec4(position, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
606 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
607 outColor = vec4(fragmentColor, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
608 PresentShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
609 position {.VertexAttribute.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
610 uv {.Pass.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
611 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
612 descriptorSets {.DescriptorSets.}: (Uniforms, ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
613 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
614 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
615 uv = ((position + 1) * 0.5) * vec2(1, -1); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
616 gl_Position = vec4(position, 0, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
617 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
618 vec2 uv1 = uv + vec2(0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
619 vec2 uv2 = uv + vec2(0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
620 vec2 uv3 = uv + vec2(-0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
621 vec2 uv4 = uv + vec2(-0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
622 outColor = ( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
623 texture(frameTexture, uv1) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
624 texture(frameTexture, uv2) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
625 texture(frameTexture, uv3) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
626 texture(frameTexture, uv4) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
627 ) / 4; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
628 }""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
629 TriangleMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
630 position: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
631 color: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
632 QuadMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
633 position: GPUArray[Vec2f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
634 indices: GPUArray[uint16, IndexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
635 var mesh = TriangleMesh( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
636 position: asGPUArray([vec3(-0.5, -0.5), vec3(0, 0.5), vec3(0.5, -0.5)], VertexBuffer), |
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
637 color: asGPUArray([vec3(0, 0, 1), vec3(0, 1, 0), vec3(1, 0, 0)], VertexBuffer), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
638 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
639 var quad = QuadMesh( |
1280
a89a70ea3da2
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1277
diff
changeset
|
640 position: asGPUArray([vec2(-1, -1), vec2(-1, 1), vec2(1, 1), vec2(1, -1)], VertexBuffer), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
641 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
|
642 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
643 var uniforms1 = asDescriptorSet( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
644 Uniforms( |
1252 | 645 frameTexture: Image[BGRA](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
646 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
647 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
648 assignBuffers(renderdata, mesh) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
649 assignBuffers(renderdata, quad) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
650 uploadImages(renderdata, uniforms1) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
651 renderdata.flushAllMemory() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
652 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
653 var |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
654 drawPipeline = createPipeline[TriangleShader](renderPass = offscreenRP) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
655 presentPipeline = createPipeline[PresentShader](renderPass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
656 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
657 initDescriptorSet(renderdata, presentPipeline.descriptorSetLayouts[0], uniforms1) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
658 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
659 # create depth buffer images (will not use the one in the swapchain |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
660 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
661 depthImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
662 depthImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
663 depthMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
664 if offscreenRP.depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
665 depthImage = svkCreate2DImage( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
666 width = vulkan.swapchain.width, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
667 height = vulkan.swapchain.height, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
668 format = DEPTH_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
669 usage = [VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
670 samples = offscreenRP.samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
671 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
672 let requirements = svkGetImageMemoryRequirements(depthImage) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
673 depthMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
674 requirements.size, |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
675 bestMemory(mappable = false, filter = requirements.memoryTypes) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
676 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
677 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
678 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
679 depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
680 depthMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
681 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
682 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
683 depthImageView = svkCreate2DImageView( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
684 image = depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
685 format = DEPTH_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
686 aspect = VK_IMAGE_ASPECT_DEPTH_BIT |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
687 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
688 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
689 # create msaa images (will not use the one in the swapchain |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
690 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
691 msaaImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
692 msaaImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
693 msaaMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
694 if offscreenRP.samples != VK_SAMPLE_COUNT_1_BIT: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
695 msaaImage = svkCreate2DImage( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
696 width = vulkan.swapchain.width, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
697 height = vulkan.swapchain.height, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
698 format = SURFACE_FORMAT, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
699 usage = [VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT], |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
700 samples = offscreenRP.samples, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
701 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
702 let requirements = svkGetImageMemoryRequirements(msaaImage) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
703 msaaMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
704 requirements.size, |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
705 bestMemory(mappable = false, filter = requirements.memoryTypes) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
706 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
707 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
708 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
709 msaaImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
710 msaaMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
711 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
712 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
713 msaaImageView = svkCreate2DImageView(image = msaaImage, format = SURFACE_FORMAT) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
714 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
715 var attachments: seq[VkImageView] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
716 if offscreenRP.samples == VK_SAMPLE_COUNT_1_BIT: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
717 if offscreenRP.depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
718 attachments = @[uniforms1.data.frameTexture.imageview, depthImageView] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
719 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
720 attachments = @[uniforms1.data.frameTexture.imageview] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
721 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
722 if offscreenRP.depthBuffer: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
723 attachments = @[msaaImageView, depthImageView, uniforms1.data.frameTexture.imageview] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
724 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
725 attachments = @[msaaImageView, uniforms1.data.frameTexture.imageview] |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
726 var offscreenFB = svkCreateFramebuffer( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
727 offscreenRP.vk, |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
728 vulkan.swapchain.width, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
729 vulkan.swapchain.height, |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
730 attachments |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
731 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
732 |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
733 var start = getMonoTime() |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
734 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
735 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
736 withNextFrame(framebuffer, commandbuffer): |
1242 | 737 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
738 withRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
739 withPipeline(commandbuffer, drawPipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
740 render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
741 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
742 withRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
743 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
744 withPipeline(commandbuffer, presentPipeline): |
1242 | 745 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
746 withBind(commandbuffer, (uniforms1, ), presentPipeline): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
747 render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
748 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
749 # cleanup |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
750 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
751 destroyPipeline(presentPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
752 destroyPipeline(drawPipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
753 destroyRenderData(renderdata) |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
754 if depthImage.Valid: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
755 vkDestroyImageView(vulkan.device, depthImageView, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
756 vkDestroyImage(vulkan.device, depthImage, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
757 vkFreeMemory(vulkan.device, depthMemory, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
758 if msaaImage.Valid: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
759 vkDestroyImageView(vulkan.device, msaaImageView, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
760 vkDestroyImage(vulkan.device, msaaImage, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
761 vkFreeMemory(vulkan.device, msaaMemory, nil) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
762 destroyRenderPass(offscreenRP) |
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
763 destroyRenderPass(presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
764 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
765 clearSwapchain() |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
766 |
1204 | 767 when isMainModule: |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
768 var time = 1'f32 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
769 initVulkan() |
1204 | 770 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
771 var mainRenderpass: RenderPass |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
772 var renderPasses = [ |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
773 (depthBuffer: false, samples: VK_SAMPLE_COUNT_1_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
774 (depthBuffer: false, samples: VK_SAMPLE_COUNT_4_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
775 (depthBuffer: true, samples: VK_SAMPLE_COUNT_1_BIT), |
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
776 (depthBuffer: true, samples: VK_SAMPLE_COUNT_4_BIT), |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
777 ] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
778 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
779 |
1204 | 780 # test normal |
1230 | 781 for i, (depthBuffer, samples) in renderPasses: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
782 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
783 setupSwapchain(renderpass = renderpass) |
1204 | 784 |
1230 | 785 # tests a simple triangle with minimalistic shader and vertex format |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
786 test_01_triangle(time) |
1230 | 787 |
788 # tests instanced triangles and quads, mixing meshes and instances | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
789 test_02_triangle_quad_instanced(time) |
1210 | 790 |
1230 | 791 # teste descriptor sets |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
792 test_03_simple_descriptorset(time) |
1204 | 793 |
1230 | 794 # tests multiple descriptor sets and arrays |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
795 test_04_multiple_descriptorsets(time) |
1231 | 796 |
797 # rotating cube | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1235
diff
changeset
|
798 test_05_cube(time) |
1204 | 799 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
800 # different draw modes (lines, points, and topologies) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
801 test_06_different_draw_modes(time) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
802 |
1242 | 803 # load PNG texture |
804 test_07_png_texture(time) | |
805 | |
1230 | 806 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1285
6d16003406fb
add: missing destroy-function for renderpass
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
807 destroyRenderPass(renderpass) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
808 clearSwapchain() |
1204 | 809 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
810 # test multiple render passes |
1235
c70fee6568f6
did: improv render tests to run without user input
sam <sam@basx.dev>
parents:
1233
diff
changeset
|
811 for i, (depthBuffer, samples) in renderPasses: |
1242 | 812 test_08_triangle_2pass(time, depthBuffer, samples) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
813 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1280
diff
changeset
|
814 destroyVulkan() |