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