Mercurial > games > semicongine
annotate src/semicongine/renderer.nim @ 323:9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 19 Aug 2023 22:24:06 +0700 |
parents | 6dab370d1758 |
children | 4ec852355750 |
rev | line source |
---|---|
127 | 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 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
4 import std/logging |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
5 import std/sequtils |
127 | 6 |
206
7f921d7d0a2b
did: small refactoring of module structure
Sam <sam@basx.dev>
parents:
205
diff
changeset
|
7 import ./core |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
8 import ./vulkan/buffer |
127 | 9 import ./vulkan/device |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
10 import ./vulkan/drawable |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
11 import ./vulkan/physicaldevice |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
12 import ./vulkan/pipeline |
127 | 13 import ./vulkan/renderpass |
14 import ./vulkan/swapchain | |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
15 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
|
16 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
|
17 import ./vulkan/image |
127 | 18 |
247 | 19 import ./scene |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
20 import ./mesh |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
21 |
127 | 22 type |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
23 SceneData = object |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
24 drawables*: OrderedTable[Mesh, Drawable] |
156 | 25 vertexBuffers*: Table[MemoryPerformanceHint, Buffer] |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
26 indexBuffer*: Buffer |
266
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
27 uniformBuffers*: Table[VkPipeline, seq[Buffer]] # one per frame-in-flight |
243
3b388986c7fd
did: refactor texture data structures, add more complete (untested) material import
Sam <sam@basx.dev>
parents:
242
diff
changeset
|
28 textures*: Table[string, seq[VulkanTexture]] # per frame-in-flight |
156 | 29 attributeLocation*: Table[string, MemoryPerformanceHint] |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
30 attributeBindingNumber*: Table[string, int] |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
31 transformAttribute: string # name of attribute that is used for per-instance mesh transformation |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
32 materialIndexAttribute: string # name of attribute that is used for material selection |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
33 materials: seq[Material] |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
34 entityTransformationCache: Table[Mesh, Mat4] # remembers last transformation, avoid to send GPU-updates if no changes |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
35 descriptorPools*: Table[VkPipeline, DescriptorPool] |
241 | 36 descriptorSets*: Table[VkPipeline, seq[DescriptorSet]] |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
37 Renderer* = object |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
38 device: Device |
127 | 39 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
|
40 renderPass: RenderPass |
127 | 41 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
|
42 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
|
43 emptyTexture: VulkanTexture |
127 | 44 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
45 func usesMaterialType(scenedata: SceneData, materialType: string): bool = |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
46 for drawable in scenedata.drawables.values: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
47 if drawable.mesh.material.materialType == materialType: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
48 return true |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
49 return false |
127 | 50 |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
51 proc initRenderer*(device: Device, shaders: Table[string, ShaderConfiguration], clearColor=Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32])): Renderer = |
127 | 52 assert device.vk.valid |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
53 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
54 result.device = device |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
55 result.renderPass = device.simpleForwardRenderPass(shaders, clearColor=clearColor) |
127 | 56 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
|
57 # 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
|
58 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
|
59 if not swapchain.isSome: |
127 | 60 raise newException(Exception, "Unable to create swapchain") |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
61 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
62 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
|
63 result.emptyTexture = device.uploadTexture(EMPTYTEXTURE) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
64 |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
65 func inputs(renderer: Renderer): seq[ShaderAttribute] = |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
66 for i in 0 ..< renderer.renderPass.subpasses.len: |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
67 for pipeline in renderer.renderPass.subpasses[i].pipelines.values: |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
68 result.add pipeline.inputs |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
69 |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
70 func samplers(renderer: Renderer): seq[ShaderAttribute] = |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
71 for i in 0 ..< renderer.renderPass.subpasses.len: |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
72 for pipeline in renderer.renderPass.subpasses[i].pipelines.values: |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
73 result.add pipeline.samplers |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
74 |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
75 proc setupDrawableBuffers*(renderer: var Renderer, scene: Scene) = |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
76 assert not (scene in renderer.scenedata) |
237 | 77 const VERTEX_ATTRIB_ALIGNMENT = 4 # used for buffer alignment |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
78 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
79 let |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
80 inputs = renderer.inputs |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
81 samplers = renderer.samplers |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
82 var scenedata = SceneData() |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
83 |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
84 # if mesh transformation are handled through the scenegraph-transformation, set it up here |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
85 if scene.transformAttribute != "": |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
86 var hasTransformAttribute = false |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
87 for input in inputs: |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
88 if input.name == scene.transformAttribute: |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
89 assert input.perInstance == true, $input |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
90 assert getDataType[Mat4]() == input.thetype, $input |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
91 hasTransformAttribute = true |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
92 assert hasTransformAttribute |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
93 scenedata.transformAttribute = scene.transformAttribute |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
94 |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
95 # check if we have support for material indices, if required |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
96 if scene.materialIndexAttribute != "": |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
97 var hasMaterialIndexAttribute = false |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
98 for input in inputs: |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
99 if input.name == scene.materialIndexAttribute: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
100 assert getDataType[uint16]() == input.thetype |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
101 hasMaterialIndexAttribute = true |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
102 assert hasMaterialIndexAttribute |
321
30117d8f0052
did next step in renderpipeline-refactoring, using shaderconfiguration objects instead for less ambigious shader-pipeline configuration
Sam <sam@basx.dev>
parents:
317
diff
changeset
|
103 scenedata.materialIndexAttribute = scene.materialIndexAttribute |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
104 |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
105 for mesh in allComponentsOfType[Mesh](scene.root): |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
106 if mesh.material != nil and not scenedata.materials.contains(mesh.material): |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
107 scenedata.materials.add mesh.material |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
108 for textureName, texture in mesh.material.textures.pairs: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
109 if not scenedata.textures.hasKey(textureName): |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
110 scenedata.textures[textureName] = @[] |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
111 scenedata.textures[textureName].add renderer.device.uploadTexture(texture) |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
112 |
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
|
113 # find all meshes, populate missing attribute values for shader |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
114 var allMeshes: seq[Mesh] |
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
|
115 for mesh in allComponentsOfType[Mesh](scene.root): |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
116 allMeshes.add mesh |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
117 for inputAttr in inputs: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
118 if scenedata.materialIndexAttribute != "" and inputAttr.name == scenedata.materialIndexAttribute: |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
119 assert mesh.material != nil, "Missing material specification for mesh. Either set the 'materials' attribute or pass the argument 'materialIndexAttribute=\"\"' when calling 'addScene'" |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
120 let matIndex = scenedata.materials.find(mesh.material) |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
121 if matIndex < 0: |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
122 raise newException(Exception, &"Required material '{mesh.material}' not available in scene (available are: {scenedata.materials})") |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
123 mesh.initAttribute(inputAttr, uint16(matIndex)) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
124 elif not mesh.hasAttribute(inputAttr.name): |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
125 warn(&"Mesh is missing data for shader attribute {inputAttr.name}, auto-filling with empty values") |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
126 mesh.initAttribute(inputAttr) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
127 assert mesh.attributeType(inputAttr.name) == inputAttr.thetype, &"mesh attribute {inputAttr.name} has type {mesh.attributeType(inputAttr.name)} but shader expects {inputAttr.thetype}" |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
128 |
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
|
129 # create index buffer if necessary |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
130 var indicesBufferSize = 0'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
131 for mesh in allMeshes: |
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
|
132 if mesh.indexType != MeshIndexType.None: |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
133 let indexAlignment = case mesh.indexType |
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
|
134 of MeshIndexType.None: 0'u64 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
135 of Tiny: 1'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
136 of Small: 2'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
137 of Big: 4'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
138 # index value alignment required by Vulkan |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
139 if indicesBufferSize mod indexAlignment != 0: |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
140 indicesBufferSize += indexAlignment - (indicesBufferSize mod indexAlignment) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
141 indicesBufferSize += mesh.indexSize |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
142 if indicesBufferSize > 0: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
143 scenedata.indexBuffer = renderer.device.createBuffer( |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
144 size=indicesBufferSize, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
145 usage=[VK_BUFFER_USAGE_INDEX_BUFFER_BIT], |
156 | 146 requireMappable=false, |
151 | 147 preferVRAM=true, |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
148 ) |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
149 |
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
|
150 # create vertex buffers and calculcate offsets |
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
|
151 # trying to use one buffer per memory type |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
152 var |
156 | 153 perLocationOffsets: Table[MemoryPerformanceHint, uint64] |
154 perLocationSizes: Table[MemoryPerformanceHint, uint64] | |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
155 bindingNumber = 0 |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
156 for hint in MemoryPerformanceHint: |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
157 perLocationOffsets[hint] = 0 |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
158 perLocationSizes[hint] = 0 |
138
62bc83b8a8c7
fix: mixing memory location types is not working
Sam <sam@basx.dev>
parents:
137
diff
changeset
|
159 for attribute in inputs: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
160 scenedata.attributeLocation[attribute.name] = attribute.memoryPerformanceHint |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
161 scenedata.attributeBindingNumber[attribute.name] = bindingNumber |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
162 inc bindingNumber |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
163 # setup one buffer per attribute-location-type |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
164 for mesh in allMeshes: |
316
b145a05c2459
add: changing rendering system, not finished yet, also upgrading to Nim 2
Sam <sam@basx.dev>
parents:
315
diff
changeset
|
165 # align size to VERTEX_ATTRIB_ALIGNMENT bytes (the important thing is the correct alignment of the offsets, but |
237 | 166 # we need to expand the buffer size as well, therefore considering alignment already here as well |
167 if perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: | |
168 perLocationSizes[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) | |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
169 perLocationSizes[attribute.memoryPerformanceHint] += mesh.attributeSize(attribute.name) |
156 | 170 for memoryPerformanceHint, bufferSize in perLocationSizes.pairs: |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
171 if bufferSize > 0: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
172 scenedata.vertexBuffers[memoryPerformanceHint] = renderer.device.createBuffer( |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
173 size=bufferSize, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
174 usage=[VK_BUFFER_USAGE_VERTEX_BUFFER_BIT], |
156 | 175 requireMappable=memoryPerformanceHint==PreferFastWrite, |
176 preferVRAM=true, | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
177 ) |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
178 |
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
|
179 # fill vertex buffers |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
180 var indexBufferOffset = 0'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
181 for mesh in allMeshes: |
164
7a0ca5c01095
fix: buffer update with staging buffer not correctly working
Sam <sam@basx.dev>
parents:
157
diff
changeset
|
182 var offsets: seq[(string, MemoryPerformanceHint, uint64)] |
138
62bc83b8a8c7
fix: mixing memory location types is not working
Sam <sam@basx.dev>
parents:
137
diff
changeset
|
183 for attribute in inputs: |
164
7a0ca5c01095
fix: buffer update with staging buffer not correctly working
Sam <sam@basx.dev>
parents:
157
diff
changeset
|
184 offsets.add (attribute.name, attribute.memoryPerformanceHint, perLocationOffsets[attribute.memoryPerformanceHint]) |
138
62bc83b8a8c7
fix: mixing memory location types is not working
Sam <sam@basx.dev>
parents:
137
diff
changeset
|
185 var (pdata, size) = mesh.getRawData(attribute.name) |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
186 if pdata != nil: # no data |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
187 scenedata.vertexBuffers[attribute.memoryPerformanceHint].setData(pdata, size, perLocationOffsets[attribute.memoryPerformanceHint]) |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
188 perLocationOffsets[attribute.memoryPerformanceHint] += size |
237 | 189 if perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: |
190 perLocationOffsets[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
191 |
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
|
192 let indexed = mesh.indexType != MeshIndexType.None |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
193 var drawable = Drawable( |
308
c73224f9d38f
add: some API improvments for vector, entity, and some other stuff
Sam <sam@basx.dev>
parents:
288
diff
changeset
|
194 mesh: mesh, |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
195 elementCount: if indexed: mesh.indicesCount else: mesh.vertexCount, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
196 bufferOffsets: offsets, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
197 instanceCount: mesh.instanceCount, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
198 indexed: indexed, |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
199 ) |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
200 if indexed: |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
201 let indexAlignment = case mesh.indexType |
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
|
202 of MeshIndexType.None: 0'u64 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
203 of Tiny: 1'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
204 of Small: 2'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
205 of Big: 4'u64 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
206 # index value alignment required by Vulkan |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
207 if indexBufferOffset mod indexAlignment != 0: |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
208 indexBufferOffset += indexAlignment - (indexBufferOffset mod indexAlignment) |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
209 drawable.indexBufferOffset = indexBufferOffset |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
210 drawable.indexType = mesh.indexType |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
211 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
|
212 scenedata.indexBuffer.setData(pdata, size, indexBufferOffset) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
213 indexBufferOffset += size |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
214 scenedata.drawables[mesh] = drawable |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
215 |
263
d1ee2a815fa1
add: some api improvments, preparing for font-loading
Sam <sam@basx.dev>
parents:
251
diff
changeset
|
216 # setup uniforms and samplers |
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
|
217 for subpass_i in 0 ..< renderer.renderPass.subpasses.len: |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
218 for material, pipeline in renderer.renderPass.subpasses[subpass_i].pipelines.pairs: |
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
|
219 var uniformBufferSize = 0'u64 |
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
|
220 for uniform in pipeline.uniforms: |
228 | 221 uniformBufferSize += uniform.size |
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
|
222 if uniformBufferSize > 0: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
223 scenedata.uniformBuffers[pipeline.vk] = newSeq[Buffer]() |
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
|
224 for frame_i in 0 ..< renderer.swapchain.inFlightFrames: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
225 scenedata.uniformBuffers[pipeline.vk].add renderer.device.createBuffer( |
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
|
226 size=uniformBufferSize, |
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
|
227 usage=[VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT], |
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
|
228 requireMappable=true, |
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
|
229 preferVRAM=true, |
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
|
230 ) |
251
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
231 |
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
232 var poolsizes = @[(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, uint32(renderer.swapchain.inFlightFrames))] |
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
233 if samplers.len > 0: |
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
234 var samplercount = 0'u32 |
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
235 for sampler in samplers: |
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
236 samplercount += (if sampler.arrayCount == 0: 1'u32 else: sampler.arrayCount) |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
237 poolsizes.add (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, uint32(renderer.swapchain.inFlightFrames) * samplercount * 2) |
251
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
238 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
239 scenedata.descriptorPools[pipeline.vk] = renderer.device.createDescriptorSetPool(poolsizes) |
251
9289776cd61c
fix: add descriptor pool per scene, use zippy instead of zip
sam <sam@basx.dev>
parents:
247
diff
changeset
|
240 |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
241 scenedata.descriptorSets[pipeline.vk] = pipeline.setupDescriptors( |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
242 scenedata.descriptorPools[pipeline.vk], |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
243 scenedata.uniformBuffers.getOrDefault(pipeline.vk, @[]), |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
244 scenedata.textures, |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
245 inFlightFrames=renderer.swapchain.inFlightFrames, |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
246 emptyTexture=renderer.emptyTexture, |
270
563ca4a82931
did: overhaul some of the mesh-data uploading and transformation handling, added: text/font rendering
Sam <sam@basx.dev>
parents:
266
diff
changeset
|
247 ) |
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
|
248 for frame_i in 0 ..< renderer.swapchain.inFlightFrames: |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
249 scenedata.descriptorSets[pipeline.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
|
250 |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
251 renderer.scenedata[scene] = scenedata |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
252 |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
253 proc refreshMeshAttributeData(sceneData: var SceneData, mesh: Mesh, attribute: string) = |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
254 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
|
255 # ignore attributes that are not used in this shader |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
256 if not (attribute in sceneData.attributeLocation): |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
211
diff
changeset
|
257 return |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
258 var (pdata, size) = mesh.getRawData(attribute) |
156 | 259 let memoryPerformanceHint = sceneData.attributeLocation[attribute] |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
260 let bindingNumber = sceneData.attributeBindingNumber[attribute] |
164
7a0ca5c01095
fix: buffer update with staging buffer not correctly working
Sam <sam@basx.dev>
parents:
157
diff
changeset
|
261 sceneData.vertexBuffers[memoryPerformanceHint].setData(pdata, size, sceneData.drawables[mesh].bufferOffsets[bindingNumber][2]) |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
262 |
228 | 263 proc updateMeshData*(renderer: var Renderer, scene: Scene) = |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
264 assert scene in renderer.scenedata |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
265 |
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
|
266 for mesh in allComponentsOfType[Mesh](scene.root): |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
267 # if mesh transformation attribute is enabled, update the model matrix |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
268 if renderer.scenedata[scene].transformAttribute != "": |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
269 let transform = mesh.entity.getModelTransform() |
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
|
270 if not (mesh in renderer.scenedata[scene].entityTransformationCache) or renderer.scenedata[scene].entityTransformationCache[mesh] != transform or mesh.areInstanceTransformsDirty : |
270
563ca4a82931
did: overhaul some of the mesh-data uploading and transformation handling, added: text/font rendering
Sam <sam@basx.dev>
parents:
266
diff
changeset
|
271 var updatedTransform = newSeq[Mat4](int(mesh.instanceCount)) |
563ca4a82931
did: overhaul some of the mesh-data uploading and transformation handling, added: text/font rendering
Sam <sam@basx.dev>
parents:
266
diff
changeset
|
272 for i in 0 ..< mesh.instanceCount: |
563ca4a82931
did: overhaul some of the mesh-data uploading and transformation handling, added: text/font rendering
Sam <sam@basx.dev>
parents:
266
diff
changeset
|
273 updatedTransform[i] = transform * mesh.getInstanceTransform(i) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
274 debug &"Update mesh transformation" |
270
563ca4a82931
did: overhaul some of the mesh-data uploading and transformation handling, added: text/font rendering
Sam <sam@basx.dev>
parents:
266
diff
changeset
|
275 mesh.updateInstanceData(renderer.scenedata[scene].transformAttribute, updatedTransform) |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
276 renderer.scenedata[scene].entityTransformationCache[mesh] = transform |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
277 |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
278 # update any changed mesh attributes |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
279 for attribute in mesh.vertexAttributes: |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
280 if mesh.hasDataChanged(attribute): |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
281 renderer.scenedata[scene].refreshMeshAttributeData(mesh, attribute) |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
282 debug &"Update mesh vertex attribute {attribute}" |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
283 for attribute in mesh.instanceAttributes: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
284 if mesh.hasDataChanged(attribute): |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
285 renderer.scenedata[scene].refreshMeshAttributeData(mesh, attribute) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
286 debug &"Update mesh instance attribute {attribute}" |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
287 var m = mesh |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
288 m.clearDataChanged() |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
289 |
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
|
290 proc updateAnimations*(renderer: var Renderer, scene: var Scene, dt: float32) = |
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
|
291 for animation in allComponentsOfType[EntityAnimation](scene.root): |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
292 debug &"Update animation {animation}" |
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
|
293 animation.update(dt) |
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
|
294 |
228 | 295 proc updateUniformData*(renderer: var Renderer, scene: var Scene) = |
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
|
296 assert scene in renderer.scenedata |
228 | 297 |
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
|
298 for i in 0 ..< renderer.renderPass.subpasses.len: |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
299 for materialType, pipeline in renderer.renderPass.subpasses[i].pipelines.pairs: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
300 if renderer.scenedata[scene].usesMaterialType(materialType) and renderer.scenedata[scene].uniformBuffers.hasKey(pipeline.vk) and renderer.scenedata[scene].uniformBuffers[pipeline.vk].len != 0: |
266
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
301 assert renderer.scenedata[scene].uniformBuffers[pipeline.vk][renderer.swapchain.currentInFlight].vk.valid |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
302 var offset = 0'u64 |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
303 for uniform in pipeline.uniforms: |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
304 if not scene.shaderGlobals.hasKey(uniform.name): |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
305 raise newException(Exception, &"Uniform '{uniform.name}' not found in scene shaderGlobals") |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
306 if uniform.thetype != scene.shaderGlobals[uniform.name].thetype: |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
307 raise newException(Exception, &"Uniform '{uniform.name}' has wrong type {uniform.thetype}, required is {scene.shaderGlobals[uniform.name].thetype}") |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
308 debug &"Update uniforms {uniform.name}" |
266
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
309 let (pdata, size) = scene.shaderGlobals[uniform.name].getRawData() |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
310 renderer.scenedata[scene].uniformBuffers[pipeline.vk][renderer.swapchain.currentInFlight].setData(pdata, size, offset) |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
311 offset += size |
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
|
312 |
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
|
313 proc render*(renderer: var Renderer, scene: var Scene) = |
142
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
314 assert scene in renderer.scenedata |
9c0d7839dc91
add: correct mesh buffer data updates to GPU
Sam <sam@basx.dev>
parents:
140
diff
changeset
|
315 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
316 var |
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
317 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
|
318 commandBuffer: VkCommandBuffer |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
319 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 return |
228 | 328 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
329 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
|
330 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
|
331 |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
332 debug "Scene buffers:" |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
333 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
|
334 debug " ", location, ": ", buffer |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
335 debug " Index buffer: ", renderer.scenedata[scene].indexBuffer |
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
336 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
337 for i in 0 ..< renderer.renderPass.subpasses.len: |
322
6dab370d1758
add: first, incomplete version of material use
Sam <sam@basx.dev>
parents:
321
diff
changeset
|
338 for materialType, pipeline in renderer.renderPass.subpasses[i].pipelines.pairs: |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
339 if renderer.scenedata[scene].usesMaterialType(materialType): |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
340 debug &"Start pipeline for {materialType}" |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
341 commandBuffer.vkCmdBindPipeline(renderer.renderPass.subpasses[i].pipelineBindPoint, pipeline.vk) |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
342 commandBuffer.vkCmdBindDescriptorSets(renderer.renderPass.subpasses[i].pipelineBindPoint, pipeline.layout, 0, 1, addr(renderer.scenedata[scene].descriptorSets[pipeline.vk][renderer.swapchain.currentInFlight].vk), 0, nil) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
343 |
323
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
344 for drawable in renderer.scenedata[scene].drawables.values: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
345 if drawable.mesh.material != nil and drawable.mesh.material.materialType == materialType: |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
346 drawable.draw(commandBuffer, vertexBuffers=renderer.scenedata[scene].vertexBuffers, indexBuffer=renderer.scenedata[scene].indexBuffer) |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
347 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
348 if i < renderer.renderPass.subpasses.len - 1: |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
349 commandBuffer.vkCmdNextSubpass(VK_SUBPASS_CONTENTS_INLINE) |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
350 |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
351 commandBuffer.endRenderCommands() |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
352 |
131
11666d28e04d
add: recreation of swapchain (at least on linux, windows will likely fail, needs testing
Sam <sam@basx.dev>
parents:
129
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 oldSwapchain.destroy() |
132
25fe4972ef9c
add: support for smooth swapchain-recreation
Sam <sam@basx.dev>
parents:
131
diff
changeset
|
360 |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
361 func framesRendered*(renderer: Renderer): uint64 = |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
362 renderer.swapchain.framesRendered |
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
363 |
140 | 364 func valid*(renderer: Renderer): bool = |
365 renderer.device.vk.valid | |
366 | |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
367 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
|
368 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
|
369 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
|
370 assert buffer.vk.valid |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
371 buffer.destroy() |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
372 if scenedata.indexBuffer.vk.valid: |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
373 assert scenedata.indexBuffer.vk.valid |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
374 scenedata.indexBuffer.destroy() |
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
375 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
|
376 for buffer in pipelineUniforms.mitems: |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
377 assert buffer.vk.valid |
fd1a95f433d1
add: better material loading system, still far from great
Sam <sam@basx.dev>
parents:
263
diff
changeset
|
378 buffer.destroy() |
315
4921ec86dcb4
did: preparations to refactor material system, still tons to do
Sam <sam@basx.dev>
parents:
308
diff
changeset
|
379 for textures in scenedata.textures.mvalues: |
201 | 380 for texture in textures.mitems: |
381 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
|
382 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
|
383 descriptorPool.destroy() |
9defff46da48
add: first complete working version of multiple materials and shaders per scene, yipie :)
Sam <sam@basx.dev>
parents:
322
diff
changeset
|
384 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
|
385 renderer.renderPass.destroy() |
128
9901ec3831d1
did: finish refactoring of render pipeline, yipi! :)
Sam <sam@basx.dev>
parents:
127
diff
changeset
|
386 renderer.swapchain.destroy() |