Mercurial > games > semicongine
annotate tests/test_rendering.nim @ 1230:51221494caeb
fix: uncomment all tests
author | sam <sam@basx.dev> |
---|---|
date | Fri, 19 Jul 2024 04:49:18 +0700 |
parents | 5dcb503ef0c0 |
children | 70f6c1cfe005 |
rev | line source |
---|---|
1203 | 1 import std/options |
1204 | 2 import std/random |
3 | |
1223
55896320c8bf
fix: references to new package not updated
sam <sam@basx.dev>
parents:
1214
diff
changeset
|
4 import ../semiconginev2 |
1203 | 5 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
6 proc test_01_triangle(nFrames: int, swapchain: var Swapchain) = |
1203 | 7 var renderdata = InitRenderData() |
8 | |
9 type | |
10 TrianglShader = object | |
11 position {.VertexAttribute.}: Vec3f | |
12 color {.VertexAttribute.}: Vec3f | |
13 fragmentColor {.Pass.}: Vec3f | |
14 outColor {.ShaderOutput.}: Vec4f | |
15 # code | |
16 vertexCode: string = """void main() { | |
17 fragmentColor = color; | |
18 gl_Position = vec4(position, 1);}""" | |
19 fragmentCode: string = """void main() { | |
20 outColor = vec4(fragmentColor, 1);}""" | |
21 TriangleMesh = object | |
22 position: GPUArray[Vec3f, VertexBuffer] | |
23 color: GPUArray[Vec3f, VertexBuffer] | |
24 var mesh = TriangleMesh( | |
1204 | 25 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
1203 | 26 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
27 ) | |
1204 | 28 AssignBuffers(renderdata, mesh) |
29 renderdata.FlushAllMemory() | |
1203 | 30 |
31 var | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
32 pipeline = CreatePipeline[TrianglShader](renderPass = swapchain.renderPass) |
1203 | 33 |
1204 | 34 var c = 0 |
35 while UpdateInputs() and c < nFrames: | |
1203 | 36 WithNextFrame(swapchain, framebuffer, commandbuffer): |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
37 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
1203 | 38 WithPipeline(commandbuffer, pipeline): |
1204 | 39 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
40 inc c | |
1203 | 41 |
42 # cleanup | |
1204 | 43 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1203 | 44 DestroyPipeline(pipeline) |
45 DestroyRenderData(renderdata) | |
46 | |
47 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
48 proc test_02_triangle_quad_instanced(nFrames: int, swapchain: var Swapchain) = |
1204 | 49 var renderdata = InitRenderData() |
50 | |
51 type | |
52 SomeShader = object | |
53 position {.VertexAttribute.}: Vec3f | |
54 color {.VertexAttribute.}: Vec3f | |
55 pos {.InstanceAttribute.}: Vec3f | |
56 scale {.InstanceAttribute.}: float32 | |
57 fragmentColor {.Pass.}: Vec3f | |
58 outColor {.ShaderOutput.}: Vec4f | |
59 # code | |
60 vertexCode: string = """void main() { | |
61 fragmentColor = color; | |
62 gl_Position = vec4((position * scale) + pos, 1);}""" | |
63 fragmentCode: string = """void main() { | |
64 outColor = vec4(fragmentColor, 1);}""" | |
65 TriangleMesh = object | |
66 position: GPUArray[Vec3f, VertexBuffer] | |
67 color: GPUArray[Vec3f, VertexBuffer] | |
68 QuadMesh = object | |
69 position: GPUArray[Vec3f, VertexBuffer] | |
70 color: GPUArray[Vec3f, VertexBuffer] | |
71 indices: GPUArray[uint16, IndexBuffer] | |
72 Instances = object | |
73 pos: GPUArray[Vec3f, VertexBuffer] | |
74 scale: GPUArray[float32, VertexBuffer] | |
75 var tri = TriangleMesh( | |
76 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
77 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | |
78 ) | |
79 var quad = QuadMesh( | |
80 position: asGPUArray([NewVec3f(-0.3, -0.3), NewVec3f(-0.3, 0.3), NewVec3f(0.3, 0.3), NewVec3f(0.3, -0.3)], VertexBuffer), | |
81 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | |
82 color: asGPUArray([NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1), NewVec3f(1, 1, 1)], VertexBuffer), | |
83 ) | |
84 | |
85 var instancesA: Instances | |
86 for n in 1..100: | |
87 instancesA.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(-0.8'f32 .. 0'f32)) | |
88 instancesA.scale.data.add rand(0.3'f32 .. 0.4'f32) | |
89 var instancesB: Instances | |
90 for n in 1..100: | |
91 instancesB.pos.data.add NewVec3f(rand(-0.8'f32 .. 0.8'f32), rand(0'f32 .. 0.8'f32)) | |
92 instancesB.scale.data.add rand(0.1'f32 .. 0.2'f32) | |
93 | |
94 AssignBuffers(renderdata, tri) | |
95 AssignBuffers(renderdata, quad) | |
96 AssignBuffers(renderdata, instancesA) | |
97 AssignBuffers(renderdata, instancesB) | |
98 renderdata.FlushAllMemory() | |
99 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
100 var pipeline = CreatePipeline[SomeShader](renderPass = swapchain.renderPass) |
1204 | 101 |
102 var c = 0 | |
103 while UpdateInputs() and c < nFrames: | |
104 WithNextFrame(swapchain, framebuffer, commandbuffer): | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
105 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
1204 | 106 WithPipeline(commandbuffer, pipeline): |
107 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) | |
108 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) | |
109 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) | |
110 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) | |
111 inc c | |
112 | |
113 # cleanup | |
114 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
115 DestroyPipeline(pipeline) | |
116 DestroyRenderData(renderdata) | |
117 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
118 proc test_03_simple_descriptorset(nFrames: int, swapchain: var Swapchain) = |
1210 | 119 var renderdata = InitRenderData() |
120 | |
121 type | |
122 Material = object | |
123 baseColor: Vec3f | |
124 | |
125 Uniforms = object | |
126 material: GPUValue[Material, UniformBuffer] | |
1228 | 127 texture1: Image[TVec4[uint8]] |
1210 | 128 |
129 QuadShader = object | |
130 position {.VertexAttribute.}: Vec3f | |
131 fragmentColor {.Pass.}: Vec3f | |
132 uv {.Pass.}: Vec2f | |
133 outColor {.ShaderOutput.}: Vec4f | |
134 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
135 # code | |
136 vertexCode: string = """void main() { | |
137 fragmentColor = material.baseColor; | |
138 gl_Position = vec4(position, 1); | |
139 gl_Position.x += ((material.baseColor.b - 0.5) * 2) - 0.5; | |
140 uv = position.xy + 0.5; | |
141 }""" | |
142 fragmentCode: string = """void main() { | |
143 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" | |
144 QuadMesh = object | |
145 position: GPUArray[Vec3f, VertexBuffer] | |
146 indices: GPUArray[uint16, IndexBuffer] | |
147 | |
1212
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
148 let R = TVec4[uint8]([255'u8, 0'u8, 0'u8, 255'u8]) |
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
149 let G = TVec4[uint8]([0'u8, 255'u8, 0'u8, 255'u8]) |
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
150 let B = TVec4[uint8]([0'u8, 0'u8, 255'u8, 255'u8]) |
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
151 let W = TVec4[uint8]([255'u8, 255'u8, 255'u8, 255'u8]) |
1210 | 152 var |
153 quad = QuadMesh( | |
154 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
155 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | |
156 ) | |
157 uniforms1 = asDescriptorSet( | |
158 Uniforms( | |
159 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), | |
1228 | 160 texture1: Image[TVec4[uint8]](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST), |
1210 | 161 ) |
162 ) | |
163 uniforms2 = asDescriptorSet( | |
164 Uniforms( | |
165 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), | |
1228 | 166 texture1: Image[TVec4[uint8]](width: 2, height: 2, data: @[R, G, B, W]), |
1212
518a952eccbf
did: increase texture format compatability
sam <sam@basx.dev>
parents:
1211
diff
changeset
|
167 ) |
1210 | 168 ) |
169 | |
170 AssignBuffers(renderdata, quad) | |
171 AssignBuffers(renderdata, uniforms1) | |
172 AssignBuffers(renderdata, uniforms2) | |
1228 | 173 UploadImages(renderdata, uniforms1) |
174 UploadImages(renderdata, uniforms2) | |
1210 | 175 renderdata.FlushAllMemory() |
176 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
177 var pipeline = CreatePipeline[QuadShader](renderPass = swapchain.renderPass) |
1210 | 178 |
179 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | |
180 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) | |
181 | |
182 var c = 0 | |
183 while UpdateInputs() and c < nFrames: | |
184 WithNextFrame(swapchain, framebuffer, commandbuffer): | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
185 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
1210 | 186 WithPipeline(commandbuffer, pipeline): |
187 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF): | |
188 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
189 WithBind(commandbuffer, (uniforms2, ), pipeline, swapchain.currentFiF): | |
190 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
191 inc c | |
192 | |
193 # cleanup | |
194 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
195 DestroyPipeline(pipeline) | |
196 DestroyRenderData(renderdata) | |
197 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
198 proc test_04_multiple_descriptorsets(nFrames: int, swapchain: var Swapchain) = |
1204 | 199 var renderdata = InitRenderData() |
1203 | 200 |
1204 | 201 type |
202 RenderSettings = object | |
1209 | 203 brigthness: float32 |
1210 | 204 Material = object |
205 baseColor: Vec3f | |
1209 | 206 ObjectSettings = object |
1210 | 207 scale: float32 |
208 materialIndex: uint32 | |
209 Constants = object | |
210 offset: Vec2f | |
211 | |
212 ConstSet = object | |
213 constants: GPUValue[Constants, UniformBuffer] | |
1209 | 214 MainSet = object |
215 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] | |
1210 | 216 material: array[2, GPUValue[Material, UniformBuffer]] |
1228 | 217 texture1: array[2, Image[TVec1[uint8]]] |
1209 | 218 OtherSet = object |
1210 | 219 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] |
1209 | 220 |
1204 | 221 QuadShader = object |
222 position {.VertexAttribute.}: Vec3f | |
223 fragmentColor {.Pass.}: Vec3f | |
1210 | 224 uv {.Pass.}: Vec2f |
1204 | 225 outColor {.ShaderOutput.}: Vec4f |
1210 | 226 descriptorSets {.DescriptorSets.}: (ConstSet, MainSet, OtherSet) |
1204 | 227 # code |
228 vertexCode: string = """void main() { | |
1210 | 229 fragmentColor = material[objectSettings.materialIndex].baseColor * renderSettings.brigthness; |
230 gl_Position = vec4(position * objectSettings.scale, 1); | |
231 gl_Position.xy += constants.offset.xy; | |
232 gl_Position.x += material[objectSettings.materialIndex].baseColor.b - 0.5; | |
233 uv = position.xy + 0.5; | |
234 }""" | |
1204 | 235 fragmentCode: string = """void main() { |
1210 | 236 outColor = vec4(fragmentColor * texture(texture1[objectSettings.materialIndex], uv).rrr, 1); |
237 }""" | |
1204 | 238 QuadMesh = object |
239 position: GPUArray[Vec3f, VertexBuffer] | |
240 indices: GPUArray[uint16, IndexBuffer] | |
1203 | 241 |
1204 | 242 var quad = QuadMesh( |
1209 | 243 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
1204 | 244 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
1209 | 245 ) |
1210 | 246 var constset = asDescriptorSet( |
247 ConstSet( | |
248 constants: asGPUValue(Constants(offset: NewVec2f(-0.3, 0.2)), UniformBuffer), | |
249 ) | |
250 ) | |
251 let G = TVec1[uint8]([50'u8]) | |
252 let W = TVec1[uint8]([255'u8]) | |
253 var mainset = asDescriptorSet( | |
1209 | 254 MainSet( |
255 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), | |
1210 | 256 material: [ |
257 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), | |
258 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), | |
259 ], | |
260 texture1: [ | |
1228 | 261 Image[TVec1[uint8]](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST), |
262 Image[TVec1[uint8]](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST), | |
1210 | 263 ], |
264 ), | |
265 ) | |
266 var otherset1 = asDescriptorSet( | |
267 OtherSet( | |
268 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 0), UniformBufferMapped), | |
1209 | 269 ) |
1204 | 270 ) |
1210 | 271 var otherset2 = asDescriptorSet( |
1209 | 272 OtherSet( |
1210 | 273 objectSettings: asGPUValue(ObjectSettings(scale: 1.0, materialIndex: 1), UniformBufferMapped), |
1209 | 274 ) |
1204 | 275 ) |
1209 | 276 |
1204 | 277 AssignBuffers(renderdata, quad) |
1210 | 278 AssignBuffers(renderdata, constset) |
279 AssignBuffers(renderdata, mainset) | |
280 AssignBuffers(renderdata, otherset1) | |
281 AssignBuffers(renderdata, otherset2) | |
1228 | 282 UploadImages(renderdata, mainset) |
1204 | 283 renderdata.FlushAllMemory() |
284 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
285 var pipeline = CreatePipeline[QuadShader](renderPass = swapchain.renderPass) |
1204 | 286 |
1210 | 287 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], constset) |
288 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[1], mainset) | |
289 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) | |
290 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
|
291 |
1204 | 292 var c = 0 |
293 while UpdateInputs() and c < nFrames: | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
294 TimeAndLog: |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
295 WithNextFrame(swapchain, framebuffer, commandbuffer): |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
296 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
297 WithPipeline(commandbuffer, pipeline): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
298 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline, swapchain.currentFiF): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
299 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
300 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline, swapchain.currentFiF): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
301 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
1210 | 302 mainset.data.renderSettings.data.brigthness = (c.float32 / nFrames.float32) |
303 otherset1.data.objectSettings.data.scale = 0.5 + (c.float32 / nFrames.float32) | |
304 UpdateGPUBuffer(mainset.data.renderSettings) | |
305 UpdateGPUBuffer(otherset1.data.objectSettings) | |
1205
f7530247a21f
did: improve descriptor-set handling, add simple descriptor set test
sam <sam@basx.dev>
parents:
1204
diff
changeset
|
306 renderdata.FlushAllMemory() |
1204 | 307 inc c |
308 | |
309 # cleanup | |
1203 | 310 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1204 | 311 DestroyPipeline(pipeline) |
312 DestroyRenderData(renderdata) | |
313 | |
1230 | 314 proc test_05_triangle_2pass(nFrames: int, depthBuffer: bool, samples: VkSampleCountFlagBits) = |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
315 var |
1230 | 316 (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
317 swapchain = InitSwapchain(renderpass = presentRP).get() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
318 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
319 var renderdata = InitRenderData() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
320 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
321 type |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
322 Uniforms = object |
1228 | 323 frameTexture: Image[TVec4[uint8]] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
324 TriangleShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
325 position {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
326 color {.VertexAttribute.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
327 fragmentColor {.Pass.}: Vec3f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
328 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
329 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
330 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
331 fragmentColor = color; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
332 gl_Position = vec4(position, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
333 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
334 outColor = vec4(fragmentColor, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
335 PresentShader = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
336 position {.VertexAttribute.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
337 uv {.Pass.}: Vec2f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
338 outColor {.ShaderOutput.}: Vec4f |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
339 descriptorSets {.DescriptorSets.}: (Uniforms, ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
340 # code |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
341 vertexCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
342 uv = ((position + 1) * 0.5) * vec2(1, -1); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
343 gl_Position = vec4(position, 0, 1);}""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
344 fragmentCode: string = """void main() { |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
345 vec2 uv1 = uv + vec2(0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
346 vec2 uv2 = uv + vec2(0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
347 vec2 uv3 = uv + vec2(-0.001, 0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
348 vec2 uv4 = uv + vec2(-0.001, -0.001); |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
349 outColor = ( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
350 texture(frameTexture, uv1) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
351 texture(frameTexture, uv2) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
352 texture(frameTexture, uv3) + |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
353 texture(frameTexture, uv4) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
354 ) / 4; |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
355 }""" |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
356 TriangleMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
357 position: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
358 color: GPUArray[Vec3f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
359 QuadMesh = object |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
360 position: GPUArray[Vec2f, VertexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
361 indices: GPUArray[uint16, IndexBuffer] |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
362 var mesh = TriangleMesh( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
363 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(0, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
364 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
365 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
366 var quad = QuadMesh( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
367 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
368 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
|
369 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
370 var uniforms1 = asDescriptorSet( |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
371 Uniforms( |
1228 | 372 frameTexture: Image[TVec4[uint8]](width: swapchain.width, height: swapchain.height, isRenderTarget: true), |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
373 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
374 ) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
375 AssignBuffers(renderdata, mesh) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
376 AssignBuffers(renderdata, quad) |
1228 | 377 UploadImages(renderdata, uniforms1) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
378 renderdata.FlushAllMemory() |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
379 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
380 var |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
381 drawPipeline = CreatePipeline[TriangleShader](renderPass = offscreenRP) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
382 presentPipeline = CreatePipeline[PresentShader](renderPass = presentRP) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
383 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
384 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
|
385 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
386 # 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
|
387 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
388 depthImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
389 depthImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
390 depthMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
391 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
|
392 depthImage = svkCreate2DImage( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
393 width = swapchain.width, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
394 height = swapchain.height, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
399 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
|
400 depthMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
401 requirements.size, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
402 BestMemory(mappable = false, filter = requirements.memoryTypes) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
403 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
404 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
405 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
406 depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
407 depthMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
408 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
409 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
410 depthImageView = svkCreate2DImageView( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
411 image = depthImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
412 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
|
413 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
|
414 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
415 |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
416 # 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
|
417 var |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
418 msaaImage: VkImage |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
419 msaaImageView: VkImageView |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
420 msaaMemory: VkDeviceMemory |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
421 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
|
422 msaaImage = svkCreate2DImage( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
423 width = swapchain.width, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
424 height = swapchain.height, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
429 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
|
430 msaaMemory = svkAllocateMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
431 requirements.size, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
432 BestMemory(mappable = false, filter = requirements.memoryTypes) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
433 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
434 checkVkResult vkBindImageMemory( |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
435 vulkan.device, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
436 msaaImage, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
437 msaaMemory, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
438 0, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
439 ) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
440 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
|
441 |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 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
|
446 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
447 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
|
448 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
449 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
|
450 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
|
451 else: |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
452 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
|
453 echo attachments |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
454 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
|
455 offscreenRP.vk, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
456 swapchain.width, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
457 swapchain.height, |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
458 attachments |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
459 ) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
460 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
461 var c = 0 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
462 while UpdateInputs() and c < nFrames: |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
463 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
464 TimeAndLog: |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
465 WithNextFrame(swapchain, framebuffer, commandbuffer): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
466 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
467 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
468 WithPipeline(commandbuffer, drawPipeline): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
469 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
470 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
471 WithRenderPass(presentRP, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
472 WithPipeline(commandbuffer, presentPipeline): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
473 WithBind(commandbuffer, (uniforms1, ), presentPipeline, swapchain.currentFiF): |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
474 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
475 inc c |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
476 |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
477 # cleanup |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
478 checkVkResult vkDeviceWaitIdle(vulkan.device) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
479 DestroyPipeline(presentPipeline) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
480 DestroyPipeline(drawPipeline) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 vkFreeMemory(vulkan.device, msaaMemory, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
490 vkDestroyRenderPass(vulkan.device, offscreenRP.vk, nil) |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
491 vkDestroyRenderPass(vulkan.device, presentRP.vk, nil) |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
492 vkDestroyFramebuffer(vulkan.device, offscreenFB, nil) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
493 DestroySwapchain(swapchain) |
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
494 |
1204 | 495 when isMainModule: |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
496 var nFrames = 1000 |
1204 | 497 InitVulkan() |
498 | |
1229
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
499 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
|
500 var renderPasses = [ |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
501 (depthBuffer: false, 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
|
502 (depthBuffer: false, samples: VK_SAMPLE_COUNT_4_BIT), |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
503 (depthBuffer: true, 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
|
504 (depthBuffer: true, samples: VK_SAMPLE_COUNT_4_BIT), |
5dcb503ef0c0
did: refactor renderpass a bit, enable depth buffering and msaa on offscreen-rendering
sam <sam@basx.dev>
parents:
1228
diff
changeset
|
505 ] |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
506 |
1204 | 507 # test normal |
1230 | 508 for i, (depthBuffer, samples) in renderPasses: |
509 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | |
510 var swapchain = InitSwapchain(renderpass = renderpass).get() | |
1204 | 511 |
1230 | 512 # tests a simple triangle with minimalistic shader and vertex format |
513 test_01_triangle(nFrames, swapchain) | |
514 | |
515 # tests instanced triangles and quads, mixing meshes and instances | |
516 test_02_triangle_quad_instanced(nFrames, swapchain) | |
1210 | 517 |
1230 | 518 # teste descriptor sets |
519 test_03_simple_descriptorset(nFrames, swapchain) | |
1204 | 520 |
1230 | 521 # tests multiple descriptor sets and arrays |
522 test_04_multiple_descriptorsets(nFrames, swapchain) | |
1204 | 523 |
1230 | 524 checkVkResult vkDeviceWaitIdle(vulkan.device) |
525 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | |
526 DestroySwapchain(swapchain) | |
1204 | 527 |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
528 # test multiple render passes |
1230 | 529 for i, (depthBuffer, samples) in renderPasses: |
530 test_05_triangle_2pass(nFrames, depthBuffer, samples) | |
1214
04e446a7eb2b
add: multipass renderer, finish tets for now
sam <sam@basx.dev>
parents:
1213
diff
changeset
|
531 |
1203 | 532 DestroyVulkan() |