Mercurial > games > semicongine
comparison static_utils.nim @ 1180:d554f8185815 compiletime-tests
add: tons of work on descriptors
| author | sam <sam@basx.dev> |
|---|---|
| date | Tue, 02 Jul 2024 06:42:42 +0700 |
| parents | e1830f9b8af4 |
| children | 6b66e6c837bc |
comparison
equal
deleted
inserted
replaced
| 1179:e1830f9b8af4 | 1180:d554f8185815 |
|---|---|
| 16 template VertexAttribute {.pragma.} | 16 template VertexAttribute {.pragma.} |
| 17 template InstanceAttribute {.pragma.} | 17 template InstanceAttribute {.pragma.} |
| 18 template Pass {.pragma.} | 18 template Pass {.pragma.} |
| 19 template PassFlat {.pragma.} | 19 template PassFlat {.pragma.} |
| 20 template ShaderOutput {.pragma.} | 20 template ShaderOutput {.pragma.} |
| 21 template VertexIndices{.pragma.} | 21 template VertexIndices {.pragma.} |
| 22 template DescriptorSet {.pragma.} | |
| 22 | 23 |
| 23 const INFLIGHTFRAMES = 2'u32 | 24 const INFLIGHTFRAMES = 2'u32 |
| 24 const ACTIVE_DESCRIPTORSETS = 2 | 25 const MAX_DESCRIPTORSETS = 2 |
| 25 const MEMORY_ALIGNMENT = 65536'u64 # Align buffers inside memory along this alignment | 26 const MEMORY_ALIGNMENT = 65536'u64 # Align buffers inside memory along this alignment |
| 26 const BUFFER_ALIGNMENT = 64'u64 # align offsets inside buffers along this alignment | 27 const BUFFER_ALIGNMENT = 64'u64 # align offsets inside buffers along this alignment |
| 27 | 28 |
| 28 # some globals that will (likely?) never change during the life time of the engine | 29 # some globals that will (likely?) never change during the life time of the engine |
| 29 type | 30 type |
| 144 const `fieldname` {.inject.} = theFieldname | 145 const `fieldname` {.inject.} = theFieldname |
| 145 let `valuename` {.inject.} = value | 146 let `valuename` {.inject.} = value |
| 146 const `isinstancename` {.inject.} = hasCustomPragma(value, InstanceAttribute) | 147 const `isinstancename` {.inject.} = hasCustomPragma(value, InstanceAttribute) |
| 147 body | 148 body |
| 148 | 149 |
| 150 template ForDescriptorSets(shader: typed, setNumber, descriptorSet, body: untyped): untyped = | |
| 151 var n = 0 | |
| 152 for theFieldname, value in fieldPairs(shader): | |
| 153 when value.hasCustomPragma(DescriptorSet): | |
| 154 block: | |
| 155 let `setNumber` {.inject.} = n | |
| 156 let `descriptorSet` {.inject.} = value | |
| 157 body | |
| 158 n.inc | |
| 159 | |
| 149 template ForDescriptorFields(shader: typed, fieldname, typename, countname, bindingNumber, body: untyped): untyped = | 160 template ForDescriptorFields(shader: typed, fieldname, typename, countname, bindingNumber, body: untyped): untyped = |
| 150 var `bindingNumber` {.inject.} = 1'u32 | 161 var `bindingNumber` {.inject.} = 1'u32 |
| 151 for theFieldname, value in fieldPairs(shader): | 162 for theFieldname, value in fieldPairs(shader): |
| 152 const `fieldname` {.inject.} = theFieldname | |
| 153 when typeof(value) is Texture: | 163 when typeof(value) is Texture: |
| 154 block: | 164 block: |
| 165 const `fieldname` {.inject.} = theFieldname | |
| 155 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER | 166 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER |
| 156 const `countname` {.inject.} = 1'u32 | 167 const `countname` {.inject.} = 1'u32 |
| 157 body | 168 body |
| 158 `bindingNumber`.inc | 169 `bindingNumber`.inc |
| 159 elif typeof(value) is object: | 170 elif typeof(value) is object: |
| 160 block: | 171 block: |
| 172 const `fieldname` {.inject.} = theFieldname | |
| 161 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER | 173 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER |
| 162 const `countname` {.inject.} = 1'u32 | 174 const `countname` {.inject.} = 1'u32 |
| 163 body | 175 body |
| 164 `bindingNumber`.inc | 176 `bindingNumber`.inc |
| 165 elif typeof(value) is array: | 177 elif typeof(value) is array: |
| 166 when elementType(value) is Texture: | 178 when elementType(value) is Texture: |
| 167 block: | 179 block: |
| 180 const `fieldname` {.inject.} = theFieldname | |
| 168 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER | 181 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER |
| 169 const `countname` {.inject.} = uint32(typeof(value).len) | 182 const `countname` {.inject.} = uint32(typeof(value).len) |
| 170 body | 183 body |
| 171 `bindingNumber`.inc | 184 `bindingNumber`.inc |
| 172 elif elementType(value) is object: | 185 elif elementType(value) is object: |
| 173 block: | 186 block: |
| 187 const `fieldname` {.inject.} = theFieldname | |
| 174 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER | 188 const `typename` {.inject.} = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER |
| 175 const `countname` {.inject.} = uint32(typeof(value).len) | 189 const `countname` {.inject.} = uint32(typeof(value).len) |
| 176 body | 190 body |
| 177 `bindingNumber`.inc | 191 `bindingNumber`.inc |
| 178 | 192 |
| 246 GPUData = GPUArray | GPUValue | 260 GPUData = GPUArray | GPUValue |
| 247 | 261 |
| 248 Pipeline[TShader] = object | 262 Pipeline[TShader] = object |
| 249 pipeline: VkPipeline | 263 pipeline: VkPipeline |
| 250 layout: VkPipelineLayout | 264 layout: VkPipelineLayout |
| 251 descriptorSetLayouts: array[ACTIVE_DESCRIPTORSETS, VkDescriptorSetLayout] | 265 descriptorSetLayouts: array[MAX_DESCRIPTORSETS, VkDescriptorSetLayout] |
| 252 BufferType = enum | 266 BufferType = enum |
| 253 VertexBuffer, IndexBuffer, UniformBuffer | 267 VertexBuffer, IndexBuffer, UniformBuffer |
| 254 RenderData = object | 268 RenderData = object |
| 255 descriptorPool: VkDescriptorPool | 269 descriptorPool: VkDescriptorPool |
| 256 # tuple is memory and offset to next free allocation in that memory | 270 # tuple is memory and offset to next free allocation in that memory |
| 449 | 463 |
| 450 proc UpdateAllGPUBuffers[T](value: T) = | 464 proc UpdateAllGPUBuffers[T](value: T) = |
| 451 for name, fieldvalue in value.fieldPairs(): | 465 for name, fieldvalue in value.fieldPairs(): |
| 452 when typeof(fieldvalue) is GPUData: | 466 when typeof(fieldvalue) is GPUData: |
| 453 UpdateGPUBuffer(fieldvalue) | 467 UpdateGPUBuffer(fieldvalue) |
| 468 | |
| 469 proc AssertCompatible(TShader, TDescriptorSet: typedesc, DescriptorSetIndex: static int) = | |
| 470 ForDescriptorSets(default(TShader), setNumber, descriptorSet): | |
| 471 if setNumber == DescriptorSetIndex: | |
| 472 assert typeof(descriptorSet) is TDescriptorSet | |
| 473 | |
| 474 proc CreateDescriptorSet[T, TShader]( | |
| 475 renderData: RenderData, | |
| 476 pipeline: Pipeline[TShader], | |
| 477 value: T, | |
| 478 setNumber: static int | |
| 479 ): array[INFLIGHTFRAMES.int, VkDescriptorSet] = | |
| 480 | |
| 481 static: AssertCompatible(TShader, T, setNumber) | |
| 482 | |
| 483 var layouts = newSeqWith(result.len, pipeline.descriptorSetLayouts[setNumber]) | |
| 484 var allocInfo = VkDescriptorSetAllocateInfo( | |
| 485 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, | |
| 486 descriptorPool: renderData.descriptorPool, | |
| 487 descriptorSetCount: uint32(layouts.len), | |
| 488 pSetLayouts: layouts.ToCPointer, | |
| 489 ) | |
| 490 checkVkResult vkAllocateDescriptorSets(vulkan.device, addr(allocInfo), result.ToCPointer) | |
| 454 | 491 |
| 455 converter toVkIndexType(indexType: IndexType): VkIndexType = | 492 converter toVkIndexType(indexType: IndexType): VkIndexType = |
| 456 case indexType: | 493 case indexType: |
| 457 of None: VK_INDEX_TYPE_NONE_KHR | 494 of None: VK_INDEX_TYPE_NONE_KHR |
| 458 of UInt8: VK_INDEX_TYPE_UINT8_EXT | 495 of UInt8: VK_INDEX_TYPE_UINT8_EXT |
| 572 var uniforms: seq[string] | 609 var uniforms: seq[string] |
| 573 var samplers: seq[string] | 610 var samplers: seq[string] |
| 574 var vsInputLocation = 0'u32 | 611 var vsInputLocation = 0'u32 |
| 575 var passLocation = 0 | 612 var passLocation = 0 |
| 576 var fsOutputLocation = 0 | 613 var fsOutputLocation = 0 |
| 577 var descriptorBinding = 0 | 614 |
| 578 | 615 var descriptorSetCount = 0 |
| 579 for fieldname, value in fieldPairs(shader): | 616 for fieldname, value in fieldPairs(shader): |
| 580 # vertex shader inputs | 617 # vertex shader inputs |
| 581 when hasCustomPragma(value, VertexAttribute) or hasCustomPragma(value, InstanceAttribute): | 618 when hasCustomPragma(value, VertexAttribute) or hasCustomPragma(value, InstanceAttribute): |
| 582 assert typeof(value) is SupportedGPUType | 619 assert typeof(value) is SupportedGPUType |
| 583 vsInput.add "layout(location = " & $vsInputLocation & ") in " & GlslType(value) & " " & fieldname & ";" | 620 vsInput.add "layout(location = " & $vsInputLocation & ") in " & GlslType(value) & " " & fieldname & ";" |
| 584 for j in 0 ..< NumberOfVertexInputAttributeDescriptors(value): | 621 for j in 0 ..< NumberOfVertexInputAttributeDescriptors(value): |
| 585 vsInputLocation += NLocationSlots(value) | 622 vsInputLocation += NLocationSlots(value) |
| 623 | |
| 586 # intermediate values, passed between shaders | 624 # intermediate values, passed between shaders |
| 587 elif hasCustomPragma(value, Pass) or hasCustomPragma(value, PassFlat): | 625 elif hasCustomPragma(value, Pass) or hasCustomPragma(value, PassFlat): |
| 588 let flat = if hasCustomPragma(value, PassFlat): "flat " else: "" | 626 let flat = if hasCustomPragma(value, PassFlat): "flat " else: "" |
| 589 vsOutput.add "layout(location = " & $passLocation & ") " & flat & "out " & GlslType(value) & " " & fieldname & ";" | 627 vsOutput.add "layout(location = " & $passLocation & ") " & flat & "out " & GlslType(value) & " " & fieldname & ";" |
| 590 fsInput.add "layout(location = " & $passLocation & ") " & flat & "in " & GlslType(value) & " " & fieldname & ";" | 628 fsInput.add "layout(location = " & $passLocation & ") " & flat & "in " & GlslType(value) & " " & fieldname & ";" |
| 591 passLocation.inc | 629 passLocation.inc |
| 630 | |
| 631 # fragment shader output | |
| 592 elif hasCustomPragma(value, ShaderOutput): | 632 elif hasCustomPragma(value, ShaderOutput): |
| 593 fsOutput.add &"layout(location = " & $fsOutputLocation & ") out " & GlslType(value) & " " & fieldname & ";" | 633 fsOutput.add &"layout(location = " & $fsOutputLocation & ") out " & GlslType(value) & " " & fieldname & ";" |
| 594 fsOutputLocation.inc | 634 fsOutputLocation.inc |
| 595 elif typeof(value) is Texture: | 635 |
| 596 samplers.add "layout(binding = " & $descriptorBinding & ") uniform " & GlslType(value) & " " & fieldname & ";" | 636 # descriptor sets |
| 597 descriptorBinding.inc | 637 # need to consider 4 cases: uniform block, texture, uniform block array, texture array |
| 598 elif typeof(value) is object: | 638 elif hasCustomPragma(value, DescriptorSet): |
| 599 # TODO | 639 assert descriptorSetCount < MAX_DESCRIPTORSETS, &"{tt.name(TShader)}: maximum {MAX_DESCRIPTORSETS} allowed" |
| 600 uniforms.add "" | 640 |
| 601 descriptorBinding.inc | 641 var descriptorBinding = 0 |
| 602 elif typeof(value) is array: | 642 for descriptorName, descriptorValue in fieldPairs(value): |
| 603 when elementType(value) is Texture: | 643 |
| 604 let arrayDecl = "[" & $typeof(value).len & "]" | 644 when typeof(descriptorValue) is Texture: |
| 605 samplers.add "layout(binding = " & $descriptorBinding & ") uniform " & GlslType(default(elementType(value))) & " " & fieldname & "" & arrayDecl & ";" | 645 samplers.add "layout(set=" & $descriptorSetCount & ", binding = " & $descriptorBinding & ") uniform " & GlslType(descriptorValue) & " " & descriptorName & ";" |
| 606 descriptorBinding.inc | 646 descriptorBinding.inc |
| 607 elif elementType(value) is object: | 647 |
| 608 # TODO | 648 elif typeof(descriptorValue) is GPUValue: |
| 609 let arrayDecl = "[" & $typeof(value).len & "]" | 649 uniforms.add "layout(set=" & $descriptorSetCount & ", binding = " & $descriptorBinding & ") uniform T" & descriptorName & " {" |
| 610 # uniforms.add "layout(binding = " & $descriptorBinding & ") uniform " & GlslType(elementType(value)) & " " & fieldname & "" & arrayDecl & ";" | 650 when typeof(descriptorValue.data) is object: |
| 611 descriptorBinding.inc | 651 for blockFieldName, blockFieldValue in descriptorValue.data.fieldPairs(): |
| 612 else: | 652 assert typeof(blockFieldValue) is SupportedGPUType, "uniform block field '" & blockFieldName & "' is not a SupportedGPUType" |
| 613 {.error: "Unsupported shader field " & fieldname.} | 653 uniforms.add " " & GlslType(blockFieldValue) & " " & blockFieldName & ";" |
| 654 uniforms.add "} " & descriptorName & ";" | |
| 655 elif typeof(descriptorValue.data) is array: | |
| 656 for blockFieldName, blockFieldValue in default(elementType(descriptorValue.data)).fieldPairs(): | |
| 657 assert typeof(blockFieldValue) is SupportedGPUType, "uniform block field '" & blockFieldName & "' is not a SupportedGPUType" | |
| 658 uniforms.add " " & GlslType(blockFieldValue) & " " & blockFieldName & ";" | |
| 659 uniforms.add "} " & descriptorName & "[" & $descriptorValue.data.len & "];" | |
| 660 descriptorBinding.inc | |
| 661 elif typeof(descriptorValue) is array: | |
| 662 when elementType(descriptorValue) is Texture: | |
| 663 let arrayDecl = "[" & $typeof(descriptorValue).len & "]" | |
| 664 samplers.add "layout(set=" & $descriptorSetCount & ", binding = " & $descriptorBinding & ") uniform " & GlslType(default(elementType(descriptorValue))) & " " & descriptorName & "" & arrayDecl & ";" | |
| 665 descriptorBinding.inc | |
| 666 else: | |
| 667 {.error: "Unsupported shader descriptor field " & descriptorName.} | |
| 668 descriptorSetCount.inc | |
| 614 elif fieldname in ["vertexCode", "fragmentCode"]: | 669 elif fieldname in ["vertexCode", "fragmentCode"]: |
| 615 discard | 670 discard |
| 616 else: | 671 else: |
| 617 {.error: "Unsupported shader field '" & tt.name(TShader) & "." & fieldname & "' of type " & tt.name(typeof(value)).} | 672 {.error: "Unsupported shader field '" & tt.name(TShader) & "." & fieldname & "' of type " & tt.name(typeof(value)).} |
| 618 | 673 |
| 658 cullMode: VkCullModeFlagBits = VK_CULL_MODE_BACK_BIT, | 713 cullMode: VkCullModeFlagBits = VK_CULL_MODE_BACK_BIT, |
| 659 frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE, | 714 frontFace: VkFrontFace = VK_FRONT_FACE_CLOCKWISE, |
| 660 descriptorPoolLimit = 1024 | 715 descriptorPoolLimit = 1024 |
| 661 ): Pipeline[TShader] = | 716 ): Pipeline[TShader] = |
| 662 # create pipeline | 717 # create pipeline |
| 663 var layoutbindings: seq[VkDescriptorSetLayoutBinding] | 718 |
| 664 ForDescriptorFields(default(TShader), fieldName, descriptorType, descriptorCount, descriptorBindingNumber): | 719 ForDescriptorSets(default(TShader), setNumber, descriptorSet): |
| 665 layoutbindings.add VkDescriptorSetLayoutBinding( | 720 var layoutbindings: seq[VkDescriptorSetLayoutBinding] |
| 666 binding: descriptorBindingNumber, | 721 ForDescriptorFields(descriptorSet, fieldName, descriptorType, descriptorCount, descriptorBindingNumber): |
| 667 descriptorType: descriptorType, | 722 layoutbindings.add VkDescriptorSetLayoutBinding( |
| 668 descriptorCount: descriptorCount, | 723 binding: descriptorBindingNumber, |
| 669 stageFlags: VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), | 724 descriptorType: descriptorType, |
| 670 pImmutableSamplers: nil, | 725 descriptorCount: descriptorCount, |
| 671 ) | 726 stageFlags: VkShaderStageFlags(VK_SHADER_STAGE_ALL_GRAPHICS), |
| 672 var layoutCreateInfo = VkDescriptorSetLayoutCreateInfo( | 727 pImmutableSamplers: nil, |
| 673 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, | 728 ) |
| 674 bindingCount: layoutbindings.len.uint32, | 729 var layoutCreateInfo = VkDescriptorSetLayoutCreateInfo( |
| 675 pBindings: layoutbindings.ToCPointer | 730 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 676 ) | 731 bindingCount: layoutbindings.len.uint32, |
| 677 checkVkResult vkCreateDescriptorSetLayout(vulkan.device, addr(layoutCreateInfo), nil, addr(result.descriptorSetLayouts)) | 732 pBindings: layoutbindings.ToCPointer |
| 733 ) | |
| 734 checkVkResult vkCreateDescriptorSetLayout( | |
| 735 vulkan.device, | |
| 736 addr(layoutCreateInfo), | |
| 737 nil, | |
| 738 addr(result.descriptorSetLayouts[setNumber]) | |
| 739 ) | |
| 678 let pipelineLayoutInfo = VkPipelineLayoutCreateInfo( | 740 let pipelineLayoutInfo = VkPipelineLayoutCreateInfo( |
| 679 sType: VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, | 741 sType: VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 680 setLayoutCount: result.descriptorSetLayouts.len.uint32, | 742 setLayoutCount: result.descriptorSetLayouts.len.uint32, |
| 681 pSetLayouts: descriptorSetLayouts.ToCPointer, | 743 pSetLayouts: result.descriptorSetLayouts.ToCPointer, |
| 682 # pushConstantRangeCount: uint32(pushConstants.len), | 744 # pushConstantRangeCount: uint32(pushConstants.len), |
| 683 # pPushConstantRanges: pushConstants.ToCPointer, | 745 # pPushConstantRanges: pushConstants.ToCPointer, |
| 684 ) | 746 ) |
| 685 checkVkResult vkCreatePipelineLayout(vulkan.device, addr(pipelineLayoutInfo), nil, addr(result.layout)) | 747 checkVkResult vkCreatePipelineLayout(vulkan.device, addr(pipelineLayoutInfo), nil, addr(result.layout)) |
| 686 | 748 |
| 1075 let `fieldvalue` {.inject.} = value | 1137 let `fieldvalue` {.inject.} = value |
| 1076 body | 1138 body |
| 1077 | 1139 |
| 1078 proc WriteDescriptors[TShader, TUniforms, TGlobals](renderData: RenderData, uniforms: TUniforms, globals: TGlobals) = | 1140 proc WriteDescriptors[TShader, TUniforms, TGlobals](renderData: RenderData, uniforms: TUniforms, globals: TGlobals) = |
| 1079 var descriptorSetWrites: seq[VkWriteDescriptorSet] | 1141 var descriptorSetWrites: seq[VkWriteDescriptorSet] |
| 1080 # map (buffer + offset + range) to descriptor | |
| 1081 # map (texture) to descriptor | |
| 1082 ForDescriptorFields(default(TShader), fieldName, descriptorType, descriptorCount, descriptorBindingNumber): | 1142 ForDescriptorFields(default(TShader), fieldName, descriptorType, descriptorCount, descriptorBindingNumber): |
| 1083 static: echo fieldName, " ", descriptorType, " ", descriptorCount | |
| 1084 for frameInFlight in 0 ..< renderData.descriptorSets.len: | 1143 for frameInFlight in 0 ..< renderData.descriptorSets.len: |
| 1085 when descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: | 1144 when descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1086 when HasGPUValueField[TUniforms](fieldName): | 1145 when HasGPUValueField[TUniforms](fieldName): |
| 1087 WithGPUValueField(uniforms, fieldName, gpuValue): | 1146 WithGPUValueField(uniforms, fieldName, gpuValue): |
| 1088 let bufferInfo = VkDescriptorBufferInfo( | 1147 let bufferInfo = VkDescriptorBufferInfo( |
| 1154 nil, | 1213 nil, |
| 1155 ) | 1214 ) |
| 1156 ]# | 1215 ]# |
| 1157 | 1216 |
| 1158 proc AssertCompatible(TShader, TMesh, TInstance, TUniforms, TGlobals: typedesc) = | 1217 proc AssertCompatible(TShader, TMesh, TInstance, TUniforms, TGlobals: typedesc) = |
| 1159 # assert seq-fields of TMesh|TInstance == seq-fields of TShader | 1218 # TODO: overhaul this |
| 1160 # assert normal fields of TMesh|Globals == normal fields of TShaderDescriptors | |
| 1161 for inputName, inputValue in default(TShader).fieldPairs: | 1219 for inputName, inputValue in default(TShader).fieldPairs: |
| 1162 var foundField = false | 1220 var foundField = false |
| 1163 | 1221 |
| 1164 # Vertex input data | 1222 # Vertex input data |
| 1165 when hasCustomPragma(inputValue, VertexAttribute): | 1223 when hasCustomPragma(inputValue, VertexAttribute): |
| 1253 uniforms: TUniforms, | 1311 uniforms: TUniforms, |
| 1254 globals: TGlobals, | 1312 globals: TGlobals, |
| 1255 mesh: TMesh, | 1313 mesh: TMesh, |
| 1256 instances: TInstance, | 1314 instances: TInstance, |
| 1257 ) = | 1315 ) = |
| 1258 static: AssertCompatible(TShader, TMesh, TInstance, TUniforms, TGlobals) | 1316 discard |
| 1317 # static: AssertCompatible(TShader, TMesh, TInstance, TUniforms, TGlobals) | |
| 1259 #[ | 1318 #[ |
| 1260 if renderable.vertexBuffers.len > 0: | 1319 if renderable.vertexBuffers.len > 0: |
| 1261 commandBuffer.vkCmdBindVertexBuffers( | 1320 commandBuffer.vkCmdBindVertexBuffers( |
| 1262 firstBinding = 0'u32, | 1321 firstBinding = 0'u32, |
| 1263 bindingCount = uint32(renderable.vertexBuffers.len), | 1322 bindingCount = uint32(renderable.vertexBuffers.len), |
| 1302 objPosition: GPUArray[Vec3f, IndirectGPUMemory] | 1361 objPosition: GPUArray[Vec3f, IndirectGPUMemory] |
| 1303 MaterialA = object | 1362 MaterialA = object |
| 1304 reflection: float32 | 1363 reflection: float32 |
| 1305 baseColor: Vec3f | 1364 baseColor: Vec3f |
| 1306 UniformsA = object | 1365 UniformsA = object |
| 1366 defaultTexture: Texture | |
| 1367 defaultMaterial: GPUValue[MaterialA, IndirectGPUMemory] | |
| 1307 materials: GPUValue[array[3, MaterialA], IndirectGPUMemory] | 1368 materials: GPUValue[array[3, MaterialA], IndirectGPUMemory] |
| 1308 materialTextures: array[3, Texture] | 1369 materialTextures: array[3, Texture] |
| 1309 ShaderSettings = object | 1370 ShaderSettings = object |
| 1310 brightness: float32 | 1371 gamma: float32 |
| 1311 GlobalsA = object | 1372 GlobalsA = object |
| 1312 fontAtlas: Texture | 1373 fontAtlas: Texture |
| 1313 settings: GPUValue[ShaderSettings, IndirectGPUMemory] | 1374 settings: GPUValue[ShaderSettings, IndirectGPUMemory] |
| 1314 | 1375 |
| 1315 ShaderA = object | 1376 ShaderA = object |
| 1320 # intermediate | 1381 # intermediate |
| 1321 test {.Pass.}: float32 | 1382 test {.Pass.}: float32 |
| 1322 test1 {.PassFlat.}: Vec3f | 1383 test1 {.PassFlat.}: Vec3f |
| 1323 # output | 1384 # output |
| 1324 color {.ShaderOutput.}: Vec4f | 1385 color {.ShaderOutput.}: Vec4f |
| 1325 # uniforms | 1386 # descriptor sets |
| 1326 materials: array[3, MaterialA] | 1387 globals {.DescriptorSet.}: GlobalsA |
| 1327 settings: ShaderSettings | 1388 uniforms {.DescriptorSet.}: UniformsA |
| 1328 # textures | |
| 1329 fontAtlas: Texture | |
| 1330 materialTextures: array[3, Texture] | |
| 1331 # code | 1389 # code |
| 1332 vertexCode: string = "void main() {}" | 1390 vertexCode: string = "void main() {}" |
| 1333 fragmentCode: string = "void main() {}" | 1391 fragmentCode: string = "void main() {}" |
| 1334 | 1392 |
| 1335 let w = CreateWindow("test2") | 1393 let w = CreateWindow("test2") |
| 1459 UpdateAllGPUBuffers(instances1) | 1517 UpdateAllGPUBuffers(instances1) |
| 1460 UpdateAllGPUBuffers(uniforms1) | 1518 UpdateAllGPUBuffers(uniforms1) |
| 1461 UpdateAllGPUBuffers(myGlobals) | 1519 UpdateAllGPUBuffers(myGlobals) |
| 1462 renderdata.FlushDirectMemory() | 1520 renderdata.FlushDirectMemory() |
| 1463 | 1521 |
| 1522 var s1 = CreateDescriptorSet(renderdata, pipeline1, myGlobals, 0) | |
| 1523 var s2 = CreateDescriptorSet(renderdata, pipeline1, uniforms1, 1) | |
| 1524 | |
| 1464 # descriptors | 1525 # descriptors |
| 1465 WriteDescriptors[ShaderA, UniformsA, GlobalsA](renderdata, uniforms1, myGlobals) | 1526 # WriteDescriptors[ShaderA, UniformsA, GlobalsA](renderdata, uniforms1, myGlobals) |
| 1466 | 1527 |
| 1467 # create descriptor sets | 1528 # create descriptor sets |
| 1468 #[ | 1529 #[ |
| 1469 var descriptorSets: array[INFLIGHTFRAMES.int, VkDescriptorSet] | 1530 var descriptorSets: array[INFLIGHTFRAMES.int, VkDescriptorSet] |
| 1470 var layouts = newSeqWith(descriptorSets.len, pipeline.descriptorSetLayouts) | 1531 var layouts = newSeqWith(descriptorSets.len, pipeline.descriptorSetLayouts) |
