annotate semicongine/renderer.nim @ 408:848a6845a588

did: overhaul dynamic array-api in a few places
author Sam <sam@basx.dev>
date Thu, 04 Jan 2024 21:13:11 +0700
parents ffc265916415
children a430b5febe22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/options
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
2 import std/tables
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
3 import std/strformat
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
4 import std/sequtils
353
61c5d5fe9d93 add: multi-material for meshes
Sam <sam@basx.dev>
parents: 349
diff changeset
5 import std/strutils
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
6 import std/logging
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
7
206
7f921d7d0a2b did: small refactoring of module structure
Sam <sam@basx.dev>
parents: 205
diff changeset
8 import ./core
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
9 import ./vulkan/buffer
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
10 import ./vulkan/device
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
11 import ./vulkan/drawable
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
12 import ./vulkan/physicaldevice
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
13 import ./vulkan/pipeline
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
14 import ./vulkan/renderpass
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
15 import ./vulkan/swapchain
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
16 import ./vulkan/shader
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
17 import ./vulkan/descriptor
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
18 import ./vulkan/image
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
19
247
beb41c93aa3f fix: gltf loading
Sam <sam@basx.dev>
parents: 243
diff changeset
20 import ./scene
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
21 import ./mesh
366
857cd931d24b add: function-based animations, preparing-refactring for better material system, hashable dynamic arrays
Sam <sam@basx.dev>
parents: 365
diff changeset
22 import ./material
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
23
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
24 const TRANSFORM_ATTRIBUTE = "transform"
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
25 const MATERIALINDEX_ATTRIBUTE = "materialIndex"
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
26 const VERTEX_ATTRIB_ALIGNMENT = 4 # used for buffer alignment
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
27
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
28 type
339
55c9183f7ece add: nice mesh API, fix: copying of whole scenedata all the time
Sam <sam@basx.dev>
parents: 334
diff changeset
29 SceneData = ref object
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
30 drawables*: seq[tuple[drawable: Drawable, mesh: Mesh]]
156
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
31 vertexBuffers*: Table[MemoryPerformanceHint, Buffer]
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
32 indexBuffer*: Buffer
266
fd1a95f433d1 add: better material loading system, still far from great
Sam <sam@basx.dev>
parents: 263
diff changeset
33 uniformBuffers*: Table[VkPipeline, seq[Buffer]] # one per frame-in-flight
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
34 textures*: Table[VkPipeline, Table[string, seq[VulkanTexture]]] # per frame-in-flight
156
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
35 attributeLocation*: Table[string, MemoryPerformanceHint]
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
36 vertexBufferOffsets*: Table[(Mesh, string), int]
323
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
37 descriptorPools*: Table[VkPipeline, DescriptorPool]
241
671b9267a533 fix: separate descriptors per scene
Sam <sam@basx.dev>
parents: 238
diff changeset
38 descriptorSets*: Table[VkPipeline, seq[DescriptorSet]]
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
39 materials: Table[MaterialType, seq[MaterialData]]
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
40 Renderer* = object
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
41 device: Device
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
42 surfaceFormat: VkSurfaceFormatKHR
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
43 renderPass: RenderPass
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
44 swapchain: Swapchain
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
45 scenedata: Table[Scene, SceneData]
323
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
46 emptyTexture: VulkanTexture
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
47
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
48 proc initRenderer*(device: Device, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor=Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32]), backFaceCulling=true): Renderer =
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
49 assert device.vk.valid
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
50
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
51 result.device = device
363
451b7ccfe722 improve 2D collision, add some vector functionality, allow shaders/pipelines to be ordered for deterministic rendering order
Sam <sam@basx.dev>
parents: 361
diff changeset
52 result.renderPass = device.simpleForwardRenderPass(shaders, clearColor=clearColor, backFaceCulling=backFaceCulling)
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
53 result.surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
54 # use last renderpass as output for swapchain
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
55 let swapchain = device.createSwapchain(result.renderPass.vk, result.surfaceFormat, device.firstGraphicsQueue().get().family)
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
56 if not swapchain.isSome:
127
5871acc2977e did: big refactoring
Sam <sam@basx.dev>
parents:
diff changeset
57 raise newException(Exception, "Unable to create swapchain")
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
58
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
59 result.swapchain = swapchain.get()
323
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
60 result.emptyTexture = device.uploadTexture(EMPTYTEXTURE)
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
61
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
62 func inputs(renderer: Renderer, scene: Scene): seq[ShaderAttribute] =
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
63 var found: Table[string, ShaderAttribute]
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
64 for i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
65 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[i].shaderPipelines:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
66 if scene.usesMaterial(materialType):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
67 for input in shaderPipeline.inputs:
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
68 if found.contains(input.name):
342
8c67f67b62fb fix: attributes with same name but different gpu memory lead to wrong results
Sam <sam@basx.dev>
parents: 341
diff changeset
69 assert input.name == found[input.name].name, &"{input.name}: {input.name} != {found[input.name].name}"
8c67f67b62fb fix: attributes with same name but different gpu memory lead to wrong results
Sam <sam@basx.dev>
parents: 341
diff changeset
70 assert input.theType == found[input.name].theType, &"{input.name}: {input.theType} != {found[input.name].theType}"
8c67f67b62fb fix: attributes with same name but different gpu memory lead to wrong results
Sam <sam@basx.dev>
parents: 341
diff changeset
71 assert input.arrayCount == found[input.name].arrayCount, &"{input.name}: {input.arrayCount} != {found[input.name].arrayCount}"
8c67f67b62fb fix: attributes with same name but different gpu memory lead to wrong results
Sam <sam@basx.dev>
parents: 341
diff changeset
72 assert input.memoryPerformanceHint == found[input.name].memoryPerformanceHint, &"{input.name}: {input.memoryPerformanceHint} != {found[input.name].memoryPerformanceHint}"
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
73 else:
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
74 result.add input
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
75 found[input.name] = input
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
76
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
77 func materialCompatibleWithPipeline(scene: Scene, materialType: MaterialType, shaderPipeline: ShaderPipeline): (bool, string) =
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
78 for uniform in shaderPipeline.uniforms:
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
79 if scene.shaderGlobals.contains(uniform.name):
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
80 if scene.shaderGlobals[uniform.name].theType != uniform.theType:
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
81 return (true, &"shader uniform needs type {uniform.theType} but scene global is of type {scene.shaderGlobals[uniform.name].theType}")
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
82 else:
406
7d926cc81620 some fixes + some intermedite state
Sam <sam@basx.dev>
parents: 384
diff changeset
83 if not materialType.hasMatchingAttribute(uniform):
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
84 return (true, &"shader uniform '{uniform.name}' was not found in scene globals or scene materials")
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
85 for texture in shaderPipeline.samplers:
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
86 if scene.shaderGlobals.contains(texture.name):
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
87 if scene.shaderGlobals[texture.name].theType != texture.theType:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
88 return (true, &"shader texture '{texture.name}' needs type {texture.theType} but scene global is of type {scene.shaderGlobals[texture.name].theType}")
333
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
89 else:
406
7d926cc81620 some fixes + some intermedite state
Sam <sam@basx.dev>
parents: 384
diff changeset
90 if not materialType.hasMatchingAttribute(texture):
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
91 return (true, &"Required texture for shader texture '{texture.name}' was not found in scene materials")
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
92
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
93 return (false, "")
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
94
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
95 func meshCompatibleWithPipeline(scene: Scene, mesh: Mesh, shaderPipeline: ShaderPipeline): (bool, string) =
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
96 for input in shaderPipeline.inputs:
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
97 if input.name in [TRANSFORM_ATTRIBUTE, MATERIALINDEX_ATTRIBUTE]: # will be populated automatically
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
98 assert input.perInstance == true, &"Currently the {input.name} attribute must be a per instance attribute"
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
99 continue
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
100 if not (input.name in mesh[].attributes):
357
2942ec187cbe allow more openArrays, better debug output, better default exports
Sam <sam@basx.dev>
parents: 353
diff changeset
101 return (true, &"Shader input '{input.name}' is not available for mesh")
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
102 if input.theType != mesh[].attributeType(input.name):
357
2942ec187cbe allow more openArrays, better debug output, better default exports
Sam <sam@basx.dev>
parents: 353
diff changeset
103 return (true, &"Shader input '{input.name}' expects type {input.theType}, but mesh has {mesh[].attributeType(input.name)}")
333
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
104 if not input.perInstance and not mesh[].vertexAttributes.contains(input.name):
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
105 return (true, &"Shader input '{input.name}' expected to be vertex attribute, but mesh has no such vertex attribute (available are: {mesh[].vertexAttributes})")
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
106 if input.perInstance and not mesh[].instanceAttributes.contains(input.name):
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
107 return (true, &"Shader input '{input.name}' expected to be per instance attribute, but mesh has no such instance attribute (available are: {mesh[].instanceAttributes})")
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
108
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
109 let pipelineCompatability = scene.materialCompatibleWithPipeline(mesh.material.theType, shaderPipeline)
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
110 if pipelineCompatability[0]:
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
111 return (true, pipelineCompatability[1])
353
61c5d5fe9d93 add: multi-material for meshes
Sam <sam@basx.dev>
parents: 349
diff changeset
112 return (false, "")
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
113
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
114 func checkSceneIntegrity(renderer: Renderer, scene: Scene) =
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
115 # TODO: this and the sub-functions can likely be simplified a ton
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
116 if scene.meshes.len == 0:
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
117 return
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
118
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
119 var foundRenderableObject = false
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
120 var materialTypes: seq[MaterialType]
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
121 for i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
122 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[i].shaderPipelines:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
123 materialTypes.add materialType
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
124 for mesh in scene.meshes:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
125 if mesh.material.theType == materialType:
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
126 foundRenderableObject = true
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
127 let (error, message) = scene.meshCompatibleWithPipeline(mesh, shaderPipeline)
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
128 assert not error, &"Mesh '{mesh}' not compatible with assigned shaderPipeline ({materialType}) because: {message}"
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
129
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
130 if not foundRenderableObject:
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
131 var matTypes: Table[string, MaterialType]
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
132 for mesh in scene.meshes:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
133 if not matTypes.contains(mesh.material.name):
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
134 matTypes[mesh.material.name] = mesh.material.theType
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
135 assert false, &"Scene '{scene.name}' has been added but materials are not compatible with any registered shader: Materials in scene: {matTypes}, registered shader-materialtypes: {materialTypes}"
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
136
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
137 proc setupDrawableBuffers*(renderer: var Renderer, scene: var Scene) =
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
138 assert not (scene in renderer.scenedata)
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
139
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
140 var scenedata = SceneData()
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
141
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
142 # find all material data and group it by material type
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
143 for mesh in scene.meshes:
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
144 if not scenedata.materials.contains(mesh.material.theType):
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
145 scenedata.materials[mesh.material.theType] = @[]
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
146 if not scenedata.materials[mesh.material.theType].contains(mesh.material):
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
147 scenedata.materials[mesh.material.theType].add mesh.material
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
148
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
149 # automatically populate material and tranform attributes
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
150 for mesh in scene.meshes:
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
151 if not (TRANSFORM_ATTRIBUTE in mesh[].attributes):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
152 mesh[].initInstanceAttribute(TRANSFORM_ATTRIBUTE, Unit4)
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
153 if not (MATERIALINDEX_ATTRIBUTE in mesh[].attributes):
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
154 mesh[].initInstanceAttribute(MATERIALINDEX_ATTRIBUTE, uint16(scenedata.materials[mesh.material.theType].find(mesh.material)))
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
155
329
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
156 renderer.checkSceneIntegrity(scene)
69e18f69713b add: scene/shader compatability check, fix collision code to work with new APIs
Sam <sam@basx.dev>
parents: 328
diff changeset
157
375
2388119b2989 did: clenaup, fix: texture handling
Sam <sam@basx.dev>
parents: 372
diff changeset
158 let inputs = renderer.inputs(scene)
333
27aaf43e18b4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 331
diff changeset
159
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
160 # create index buffer if necessary
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
161 var indicesBufferSize = 0
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
162 for mesh in scene.meshes:
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
163 if mesh[].indexType != MeshIndexType.None:
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
164 let indexAlignment = case mesh[].indexType
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
165 of MeshIndexType.None: 0
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
166 of Tiny: 1
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
167 of Small: 2
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
168 of Big: 4
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
169 # index value alignment required by Vulkan
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
170 if indicesBufferSize mod indexAlignment != 0:
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
171 indicesBufferSize += indexAlignment - (indicesBufferSize mod indexAlignment)
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
172 indicesBufferSize += mesh[].indexSize
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
173 if indicesBufferSize > 0:
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
174 scenedata.indexBuffer = renderer.device.createBuffer(
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
175 size=indicesBufferSize,
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
176 usage=[VK_BUFFER_USAGE_INDEX_BUFFER_BIT],
156
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
177 requireMappable=false,
151
a46923cb0790 did: better memory selection
Sam <sam@basx.dev>
parents: 146
diff changeset
178 preferVRAM=true,
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
179 )
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
180
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
181 # calculcate offsets for attributes in vertex buffers
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
182 # trying to use one buffer per memory type
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
183 var perLocationSizes: Table[MemoryPerformanceHint, int]
222
ddfc54036e00 add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents: 211
diff changeset
184 for hint in MemoryPerformanceHint:
ddfc54036e00 add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents: 211
diff changeset
185 perLocationSizes[hint] = 0
138
62bc83b8a8c7 fix: mixing memory location types is not working
Sam <sam@basx.dev>
parents: 137
diff changeset
186 for attribute in inputs:
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
187 scenedata.attributeLocation[attribute.name] = attribute.memoryPerformanceHint
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
188 # setup one buffer per attribute-location-type
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
189 for mesh in scene.meshes:
316
b145a05c2459 add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents: 315
diff changeset
190 # align size to VERTEX_ATTRIB_ALIGNMENT bytes (the important thing is the correct alignment of the offsets, but
237
2fca78b0c0d6 fix: incorrect vertex data alignment
Sam <sam@basx.dev>
parents: 228
diff changeset
191 # we need to expand the buffer size as well, therefore considering alignment already here as well
2fca78b0c0d6 fix: incorrect vertex data alignment
Sam <sam@basx.dev>
parents: 228
diff changeset
192 if perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0:
2fca78b0c0d6 fix: incorrect vertex data alignment
Sam <sam@basx.dev>
parents: 228
diff changeset
193 perLocationSizes[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT)
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
194 perLocationSizes[attribute.memoryPerformanceHint] += mesh[].attributeSize(attribute.name)
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
195
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
196 # create vertex buffers
156
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
197 for memoryPerformanceHint, bufferSize in perLocationSizes.pairs:
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
198 if bufferSize > 0:
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
199 scenedata.vertexBuffers[memoryPerformanceHint] = renderer.device.createBuffer(
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
200 size=bufferSize,
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
201 usage=[VK_BUFFER_USAGE_VERTEX_BUFFER_BIT],
156
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
202 requireMappable=memoryPerformanceHint==PreferFastWrite,
134647ed5b60 did: refactor memory selection
Sam <sam@basx.dev>
parents: 151
diff changeset
203 preferVRAM=true,
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
204 )
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
205
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
206 # calculate offset of each attribute for all meshes
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
207 var perLocationOffsets: Table[MemoryPerformanceHint, int]
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
208 var indexBufferOffset = 0
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
209 for hint in MemoryPerformanceHint:
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
210 perLocationOffsets[hint] = 0
328
8d0ffcacc7e3 did: some cleanup
Sam <sam@basx.dev>
parents: 327
diff changeset
211
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
212 for mesh in scene.meshes:
138
62bc83b8a8c7 fix: mixing memory location types is not working
Sam <sam@basx.dev>
parents: 137
diff changeset
213 for attribute in inputs:
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
214 scenedata.vertexBufferOffsets[(mesh, attribute.name)] = perLocationOffsets[attribute.memoryPerformanceHint]
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
215 if mesh[].attributes.contains(attribute.name):
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
216 let size = mesh[].getRawData(attribute.name)[1]
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
217 perLocationOffsets[attribute.memoryPerformanceHint] += size
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
218 if perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0:
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
219 perLocationOffsets[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT)
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
220
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
221 # fill offsets per shaderPipeline (as sequence corresponds to shader input binding)
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
222 var offsets: Table[VkPipeline, seq[(string, MemoryPerformanceHint, int)]]
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
223 for subpass_i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
224 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[subpass_i].shaderPipelines:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
225 if scene.usesMaterial(materialType):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
226 offsets[shaderPipeline.vk] = newSeq[(string, MemoryPerformanceHint, int)]()
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
227 for attribute in shaderPipeline.inputs:
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
228 offsets[shaderPipeline.vk].add (attribute.name, attribute.memoryPerformanceHint, scenedata.vertexBufferOffsets[(mesh, attribute.name)])
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
229
328
8d0ffcacc7e3 did: some cleanup
Sam <sam@basx.dev>
parents: 327
diff changeset
230 # create drawables
288
5af702c95b16 add: what seems like a working animation system, atm integrated with entities, will add more for meshes
Sam <sam@basx.dev>
parents: 270
diff changeset
231 let indexed = mesh.indexType != MeshIndexType.None
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
232 var drawable = Drawable(
365
a6bcee717532 add: mesh name to drawable
Sam <sam@basx.dev>
parents: 363
diff changeset
233 name: mesh.name,
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
234 elementCount: if indexed: mesh[].indicesCount else: mesh[].vertexCount,
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
235 bufferOffsets: offsets,
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
236 instanceCount: mesh[].instanceCount,
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
237 indexed: indexed,
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
238 )
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
239 if indexed:
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
240 let indexAlignment = case mesh.indexType
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
241 of MeshIndexType.None: 0
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
242 of Tiny: 1
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
243 of Small: 2
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
244 of Big: 4
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
245 # index value alignment required by Vulkan
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
246 if indexBufferOffset mod indexAlignment != 0:
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
247 indexBufferOffset += indexAlignment - (indexBufferOffset mod indexAlignment)
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
248 drawable.indexBufferOffset = indexBufferOffset
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
249 drawable.indexType = mesh.indexType
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
250 var (pdata, size) = mesh[].getRawIndexData()
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
251 scenedata.indexBuffer.setData(pdata, size, indexBufferOffset)
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
252 indexBufferOffset += size
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
253 scenedata.drawables.add (drawable, mesh)
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
254
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
255 # setup uniforms and textures (anything descriptor)
375
2388119b2989 did: clenaup, fix: texture handling
Sam <sam@basx.dev>
parents: 372
diff changeset
256 var uploadedTextures: Table[Texture, VulkanTexture]
192
659992f14dd6 add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents: 191
diff changeset
257 for subpass_i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
258 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[subpass_i].shaderPipelines:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
259 if scene.usesMaterial(materialType):
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
260 # gather textures
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
261 scenedata.textures[shaderPipeline.vk] = initTable[string, seq[VulkanTexture]]()
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
262 for texture in shaderPipeline.samplers:
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
263 scenedata.textures[shaderPipeline.vk][texture.name] = newSeq[VulkanTexture]()
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
264 if scene.shaderGlobals.contains(texture.name):
408
848a6845a588 did: overhaul dynamic array-api in a few places
Sam <sam@basx.dev>
parents: 407
diff changeset
265 for textureValue in scene.shaderGlobals[texture.name][Texture][]:
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
266 if not uploadedTextures.contains(textureValue):
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
267 uploadedTextures[textureValue] = renderer.device.uploadTexture(textureValue)
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
268 scenedata.textures[shaderPipeline.vk][texture.name].add uploadedTextures[textureValue]
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
269 else:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
270 var foundTexture = false
375
2388119b2989 did: clenaup, fix: texture handling
Sam <sam@basx.dev>
parents: 372
diff changeset
271 for material in scene.getMaterials(materialType):
406
7d926cc81620 some fixes + some intermedite state
Sam <sam@basx.dev>
parents: 384
diff changeset
272 if material.hasMatchingAttribute(texture):
7d926cc81620 some fixes + some intermedite state
Sam <sam@basx.dev>
parents: 384
diff changeset
273 foundTexture = true
408
848a6845a588 did: overhaul dynamic array-api in a few places
Sam <sam@basx.dev>
parents: 407
diff changeset
274 let value = material[texture.name, Texture][]
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
275 assert value.len == 1, &"Mesh material attribute '{texture.name}' has texture-array, but only single textures are allowed"
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
276 if not uploadedTextures.contains(value[0]):
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
277 uploadedTextures[value[0]] = renderer.device.uploadTexture(value[0])
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
278 scenedata.textures[shaderPipeline.vk][texture.name].add uploadedTextures[value[0]]
375
2388119b2989 did: clenaup, fix: texture handling
Sam <sam@basx.dev>
parents: 372
diff changeset
279 assert foundTexture, &"No texture found in shaderGlobals or materials for '{texture.name}'"
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
280 let nTextures = scenedata.textures[shaderPipeline.vk][texture.name].len
375
2388119b2989 did: clenaup, fix: texture handling
Sam <sam@basx.dev>
parents: 372
diff changeset
281 assert (texture.arrayCount == 0 and nTextures == 1) or texture.arrayCount == nTextures, &"Shader assigned to render '{materialType}' expected {texture.arrayCount} textures for '{texture.name}' but got {nTextures}"
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
282
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
283 # gather uniform sizes
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
284 var uniformBufferSize = 0
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
285 for uniform in shaderPipeline.uniforms:
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
286 uniformBufferSize += uniform.size
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
287 if uniformBufferSize > 0:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
288 scenedata.uniformBuffers[shaderPipeline.vk] = newSeq[Buffer]()
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
289 for frame_i in 0 ..< renderer.swapchain.inFlightFrames:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
290 scenedata.uniformBuffers[shaderPipeline.vk].add renderer.device.createBuffer(
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
291 size=uniformBufferSize,
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
292 usage=[VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT],
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
293 requireMappable=true,
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
294 preferVRAM=true,
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
295 )
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
296
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
297 # setup descriptors
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
298 var poolsizes = @[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, renderer.swapchain.inFlightFrames)]
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
299 if scenedata.textures[shaderPipeline.vk].len > 0:
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
300 var textureCount = 0
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
301 for textures in scenedata.textures[shaderPipeline.vk].values:
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
302 textureCount += textures.len
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
303 poolsizes.add (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, renderer.swapchain.inFlightFrames * textureCount * 2)
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
304
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
305 scenedata.descriptorPools[shaderPipeline.vk] = renderer.device.createDescriptorSetPool(poolsizes)
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
306
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
307 scenedata.descriptorSets[shaderPipeline.vk] = shaderPipeline.setupDescriptors(
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
308 scenedata.descriptorPools[shaderPipeline.vk],
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
309 scenedata.uniformBuffers.getOrDefault(shaderPipeline.vk, @[]),
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
310 scenedata.textures[shaderPipeline.vk],
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
311 inFlightFrames=renderer.swapchain.inFlightFrames,
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
312 emptyTexture=renderer.emptyTexture,
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
313 )
192
659992f14dd6 add: textures now support in shader via scene data, also: improved config handling a bit, more to come
Sam <sam@basx.dev>
parents: 191
diff changeset
314 for frame_i in 0 ..< renderer.swapchain.inFlightFrames:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
315 scenedata.descriptorSets[shaderPipeline.vk][frame_i].writeDescriptorSet()
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
316
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
317 renderer.scenedata[scene] = scenedata
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
318
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
319 proc refreshMeshAttributeData(renderer: Renderer, scene: var Scene, drawable: Drawable, mesh: Mesh, attribute: string) =
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
320 debug &"Refreshing data on mesh mesh for {attribute}"
222
ddfc54036e00 add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents: 211
diff changeset
321 # ignore attributes that are not used in this shader
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
322 if not (attribute in renderer.scenedata[scene].attributeLocation):
222
ddfc54036e00 add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents: 211
diff changeset
323 return
340
01ccd1393e7f did: try to reduce seq copying...
Sam <sam@basx.dev>
parents: 339
diff changeset
324
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
325 let (pdata, size) = mesh[].getRawData(attribute)
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
326 let memoryPerformanceHint = renderer.scenedata[scene].attributeLocation[attribute]
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
327 renderer.scenedata[scene].vertexBuffers[memoryPerformanceHint].setData(pdata, size, renderer.scenedata[scene].vertexBufferOffsets[(mesh, attribute)])
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
328
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
329 proc updateMeshData*(renderer: var Renderer, scene: var Scene, forceAll=false) =
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
330 assert scene in renderer.scenedata
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
331
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
332 for (drawable, mesh) in renderer.scenedata[scene].drawables.mitems:
369
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
333 if mesh[].attributes.contains(TRANSFORM_ATTRIBUTE):
807f111cc4f3 fix: setup of materials, still need to check with multiple materials in scene (maybe write new test?)
Sam <sam@basx.dev>
parents: 367
diff changeset
334 mesh[].updateInstanceTransforms(TRANSFORM_ATTRIBUTE)
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
335 let attrs = (if forceAll: mesh[].attributes else: mesh[].dirtyAttributes)
327
a63bd8f29252 add: make same attribute for different shaders work correctly, yipie!
Sam <sam@basx.dev>
parents: 326
diff changeset
336 for attribute in attrs:
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
337 renderer.refreshMeshAttributeData(scene, drawable, mesh, attribute)
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
338 debug &"Update mesh attribute {attribute}"
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
339 mesh[].clearDirtyAttributes()
288
5af702c95b16 add: what seems like a working animation system, atm integrated with entities, will add more for meshes
Sam <sam@basx.dev>
parents: 270
diff changeset
340
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
341 proc updateUniformData*(renderer: var Renderer, scene: var Scene, forceAll=false) =
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
342 assert scene in renderer.scenedata
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
343 # TODO: maybe check for dirty materials too, but atm we copy materials into the
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
344 # renderers scenedata, so they are immutable after initialization, would
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
345 # need to allow updates of materials too in order to make sense
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
346
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
347 let dirty = scene.dirtyShaderGlobals
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
348 if not forceAll and dirty.len == 0:
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
349 return
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
350
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
351 if forceAll:
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
352 debug "Update uniforms because 'forceAll' was given"
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
353 else:
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
354 debug &"Update uniforms because of dirty scene globals: {dirty}"
228
6b02e108ba54 add: small refactoring
Sam <sam@basx.dev>
parents: 222
diff changeset
355
330
04531bec3583 did: remove some stuff from the heap, maybe nicer?
Sam <sam@basx.dev>
parents: 329
diff changeset
356 # loop over all used shaders/pipelines
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
357 for i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
358 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[i].shaderPipelines:
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
359 if (
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
360 scene.usesMaterial(materialType) and
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
361 renderer.scenedata[scene].uniformBuffers.hasKey(shaderPipeline.vk) and
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
362 renderer.scenedata[scene].uniformBuffers[shaderPipeline.vk].len != 0
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
363 ):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
364 assert renderer.scenedata[scene].uniformBuffers[shaderPipeline.vk][renderer.swapchain.currentInFlight].vk.valid
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
365 if forceAll:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
366 for buffer in renderer.scenedata[scene].uniformBuffers[shaderPipeline.vk]:
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
367 assert buffer.vk.valid
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
368
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
369 var offset = 0
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
370 # loop over all uniforms of the shader-shaderPipeline
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
371 for uniform in shaderPipeline.uniforms:
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
372 if dirty.contains(uniform.name) or forceAll: # only update uniforms if necessary
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
373 var value = initDataList(uniform.theType)
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
374 if scene.shaderGlobals.hasKey(uniform.name):
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
375 assert scene.shaderGlobals[uniform.name].thetype == uniform.thetype
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
376 value = scene.shaderGlobals[uniform.name]
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
377 else:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
378 var foundValue = false
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
379 for material in renderer.scenedata[scene].materials[materialType]:
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
380 if material.hasMatchingAttribute(uniform):
408
848a6845a588 did: overhaul dynamic array-api in a few places
Sam <sam@basx.dev>
parents: 407
diff changeset
381 value.appendValues(material[uniform.name])
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
382 foundValue = true
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
383 assert foundValue, &"Uniform '{uniform.name}' not found in scene shaderGlobals or materials"
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
384 assert (uniform.arrayCount == 0 and value.len == 1) or value.len == uniform.arrayCount, &"Uniform '{uniform.name}' found has wrong length (shader declares {uniform.arrayCount} but shaderGlobals and materials provide {value.len})"
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
385 let (pdata, size) = value.getRawData()
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
386 assert size == uniform.size, "During uniform update: gathered value has size {size} but uniform expects size {uniform.size}"
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
387 debug &" update uniform {uniform.name} with value: {value}"
334
2533f524bdb6 fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents: 333
diff changeset
388 # TODO: technically we would only need to update the uniform buffer of the current
407
ffc265916415 did: improve/refactor some of the material API
Sam <sam@basx.dev>
parents: 406
diff changeset
389 # frameInFlight (I think), but we don't track for which frame the shaderglobals are no longer dirty
334
2533f524bdb6 fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents: 333
diff changeset
390 # therefore we have to update the uniform values in all buffers, of all inFlightframes (usually 2)
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
391 for buffer in renderer.scenedata[scene].uniformBuffers[shaderPipeline.vk]:
334
2533f524bdb6 fix: remaining tests and an issue with updating uniforms
Sam <sam@basx.dev>
parents: 333
diff changeset
392 buffer.setData(pdata, size, offset)
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
393 offset += uniform.size
331
05fb85ba97dd did: undid using meshes as values, ref is much better, fix a few things, fix a few huge performance issues
Sam <sam@basx.dev>
parents: 330
diff changeset
394 scene.clearDirtyShaderGlobals()
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
395
326
4ec852355750 fix: many issues, better mesh-handling, still need to cope with different binding numbers when using different pipelines...
Sam <sam@basx.dev>
parents: 323
diff changeset
396 proc render*(renderer: var Renderer, scene: Scene) =
142
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
397 assert scene in renderer.scenedata
9c0d7839dc91 add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents: 140
diff changeset
398
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
399 var
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
400 commandBufferResult = renderer.swapchain.nextFrame()
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
401 commandBuffer: VkCommandBuffer
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
402
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
403 if not commandBufferResult.isSome:
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
404 let res = renderer.swapchain.recreate()
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
405 if res.isSome:
205
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
406 var oldSwapchain = renderer.swapchain
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
407 renderer.swapchain = res.get()
205
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
408 checkVkResult renderer.device.vk.vkDeviceWaitIdle()
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
409 oldSwapchain.destroy()
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
410 return
228
6b02e108ba54 add: small refactoring
Sam <sam@basx.dev>
parents: 222
diff changeset
411
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
412 commandBuffer = commandBufferResult.get()
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
413 commandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer())
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
414
322
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
415 debug "Scene buffers:"
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
416 for (location, buffer) in renderer.scenedata[scene].vertexBuffers.pairs:
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
417 debug " ", location, ": ", buffer
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
418 debug " Index buffer: ", renderer.scenedata[scene].indexBuffer
6dab370d1758 add: first, incomplete version of material use
Sam <sam@basx.dev>
parents: 321
diff changeset
419
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
420 for i in 0 ..< renderer.renderPass.subpasses.len:
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
421 for (materialType, shaderPipeline) in renderer.renderPass.subpasses[i].shaderPipelines:
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
422 if scene.usesMaterial(materialType):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
423 debug &"Start shaderPipeline for '{materialType}'"
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
424 commandBuffer.vkCmdBindPipeline(renderer.renderPass.subpasses[i].pipelineBindPoint, shaderPipeline.vk)
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
425 commandBuffer.vkCmdBindDescriptorSets(renderer.renderPass.subpasses[i].pipelineBindPoint, shaderPipeline.layout, 0, 1, addr(renderer.scenedata[scene].descriptorSets[shaderPipeline.vk][renderer.swapchain.currentInFlight].vk), 0, nil)
367
7ef01f1841b3 did: improve material system a ton, more to come
Sam <sam@basx.dev>
parents: 366
diff changeset
426 for (drawable, mesh) in renderer.scenedata[scene].drawables.filterIt(it[1].visible and it[1].material.theType == materialType):
377
e5c6b14b4060 did: small refactoring and some bug fixes
Sam <sam@basx.dev>
parents: 375
diff changeset
427 drawable.draw(commandBuffer, vertexBuffers=renderer.scenedata[scene].vertexBuffers, indexBuffer=renderer.scenedata[scene].indexBuffer, shaderPipeline.vk)
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
428
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
429 if i < renderer.renderPass.subpasses.len - 1:
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
430 commandBuffer.vkCmdNextSubpass(VK_SUBPASS_CONTENTS_INLINE)
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
431
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
432 commandBuffer.endRenderCommands()
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
433
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
434 if not renderer.swapchain.swap():
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
435 let res = renderer.swapchain.recreate()
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
436 if res.isSome:
205
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
437 var oldSwapchain = renderer.swapchain
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
438 renderer.swapchain = res.get()
205
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
439 checkVkResult renderer.device.vk.vkDeviceWaitIdle()
24d18cd8be8a did: try to simplfy swapchain recreation, not sure if it is a good idea
Sam <sam@basx.dev>
parents: 201
diff changeset
440 oldSwapchain.destroy()
132
25fe4972ef9c add: support for smooth swapchain-recreation
Sam <sam@basx.dev>
parents: 131
diff changeset
441
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
442 func framesRendered*(renderer: Renderer): uint64 =
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
443 renderer.swapchain.framesRendered
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
444
140
29f0109c5222 add: some helper functions
Sam <sam@basx.dev>
parents: 138
diff changeset
445 func valid*(renderer: Renderer): bool =
29f0109c5222 add: some helper functions
Sam <sam@basx.dev>
parents: 138
diff changeset
446 renderer.device.vk.valid
29f0109c5222 add: some helper functions
Sam <sam@basx.dev>
parents: 138
diff changeset
447
361
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
448 proc destroy*(renderer: var Renderer, scene: Scene) =
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
449 var scenedata = renderer.scenedata[scene]
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
450
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
451 for buffer in scenedata.vertexBuffers.mvalues:
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
452 assert buffer.vk.valid
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
453 buffer.destroy()
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
454 if scenedata.indexBuffer.vk.valid:
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
455 assert scenedata.indexBuffer.vk.valid
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
456 scenedata.indexBuffer.destroy()
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
457 for pipelineUniforms in scenedata.uniformBuffers.mvalues:
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
458 for buffer in pipelineUniforms.mitems:
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
459 assert buffer.vk.valid
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
460 buffer.destroy()
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
461 var destroyedTextures: seq[VkImage]
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
462 for pipelineTextures in scenedata.textures.mvalues:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
463 for textures in pipelineTextures.mvalues:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
464 for texture in textures.mitems:
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
465 if not destroyedTextures.contains(texture.image.vk):
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
466 destroyedTextures.add texture.image.vk
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
467 texture.destroy()
361
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
468 for descriptorPool in scenedata.descriptorPools.mvalues:
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
469 descriptorPool.destroy()
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
470 renderer.scenedata.del(scene)
361
97e913c0e7fe add: better scene handling, add API to unload scene (not tested yet though)
Sam <sam@basx.dev>
parents: 360
diff changeset
471
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
472 proc destroy*(renderer: var Renderer) =
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
473 for scenedata in renderer.scenedata.mvalues:
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
474 for buffer in scenedata.vertexBuffers.mvalues:
189
df92519d4d68 add: initial code for texture support, not finished, had to completely refactor how to handle material-data (ie scene-wide data, sorry if you ever read this
Sam <sam@basx.dev>
parents: 164
diff changeset
475 assert buffer.vk.valid
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
476 buffer.destroy()
315
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
477 if scenedata.indexBuffer.vk.valid:
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
478 assert scenedata.indexBuffer.vk.valid
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
479 scenedata.indexBuffer.destroy()
4921ec86dcb4 did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents: 308
diff changeset
480 for pipelineUniforms in scenedata.uniformBuffers.mvalues:
266
fd1a95f433d1 add: better material loading system, still far from great
Sam <sam@basx.dev>
parents: 263
diff changeset
481 for buffer in pipelineUniforms.mitems:
fd1a95f433d1 add: better material loading system, still far from great
Sam <sam@basx.dev>
parents: 263
diff changeset
482 assert buffer.vk.valid
fd1a95f433d1 add: better material loading system, still far from great
Sam <sam@basx.dev>
parents: 263
diff changeset
483 buffer.destroy()
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
484 var destroyedTextures: seq[VkImage]
372
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
485 for pipelineTextures in scenedata.textures.mvalues:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
486 for textures in pipelineTextures.mvalues:
eb2ac324a162 fix: finally supporting different material types + indexed materials correctly, incl. textures... I hope...
Sam <sam@basx.dev>
parents: 369
diff changeset
487 for texture in textures.mitems:
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
488 if not destroyedTextures.contains(texture.image.vk):
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
489 destroyedTextures.add texture.image.vk
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
490 texture.destroy()
323
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
491 for descriptorPool in scenedata.descriptorPools.mvalues:
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
492 descriptorPool.destroy()
384
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
493 for scene in renderer.scenedata.keys.toSeq:
eaf084ba80e5 fix: cleanup when multiple textures use same vulkan image
Sam <sam@basx.dev>
parents: 382
diff changeset
494 renderer.scenedata.del(scene)
323
9defff46da48 add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents: 322
diff changeset
495 renderer.emptyTexture.destroy()
131
11666d28e04d add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents: 129
diff changeset
496 renderer.renderPass.destroy()
128
9901ec3831d1 did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents: 127
diff changeset
497 renderer.swapchain.destroy()