Mercurial > games > semicongine
comparison static_utils.nim @ 1165:58694b30b9cb compiletime-tests
add: some stuff
author | sam <sam@basx.dev> |
---|---|
date | Sat, 22 Jun 2024 08:45:14 +0700 |
parents | 7b4d4d85d9f5 |
children | 2e0b527c2753 |
comparison
equal
deleted
inserted
replaced
1164:7b4d4d85d9f5 | 1165:58694b30b9cb |
---|---|
18 template InstanceAttribute* {.pragma.} | 18 template InstanceAttribute* {.pragma.} |
19 template Pass* {.pragma.} | 19 template Pass* {.pragma.} |
20 template PassFlat* {.pragma.} | 20 template PassFlat* {.pragma.} |
21 template ShaderOutput* {.pragma.} | 21 template ShaderOutput* {.pragma.} |
22 | 22 |
23 const INFLIGHTFRAMES = 2 | 23 const INFLIGHTFRAMES = 2'u32 |
24 type | 24 type |
25 SupportedGPUType* = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64] | 25 SupportedGPUType* = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64] |
26 ShaderObject*[TShader] = object | 26 ShaderObject*[TShader] = object |
27 vertexShader: VkShaderModule | 27 vertexShader: VkShaderModule |
28 fragmentShader: VkShaderModule | 28 fragmentShader: VkShaderModule |
528 let nUniformBuffers = 0'u32 | 528 let nUniformBuffers = 0'u32 |
529 | 529 |
530 if nSamplers + nUniformBuffers > 0: | 530 if nSamplers + nUniformBuffers > 0: |
531 var poolSizes: seq[VkDescriptorPoolSize] | 531 var poolSizes: seq[VkDescriptorPoolSize] |
532 if nUniformBuffers > 0: | 532 if nUniformBuffers > 0: |
533 poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, descriptorCount: nSamplers * INFLIGHTFRAMES.uint32) | 533 poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, descriptorCount: nSamplers * INFLIGHTFRAMES) |
534 if nSamplers > 0: | 534 if nSamplers > 0: |
535 poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, descriptorCount: nUniformBuffers * INFLIGHTFRAMES.uint32) | 535 poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, descriptorCount: nUniformBuffers * INFLIGHTFRAMES) |
536 var poolInfo = VkDescriptorPoolCreateInfo( | 536 var poolInfo = VkDescriptorPoolCreateInfo( |
537 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, | 537 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, |
538 poolSizeCount: uint32(poolSizes.len), | 538 poolSizeCount: uint32(poolSizes.len), |
539 pPoolSizes: poolSizes.ToCPointer, | 539 pPoolSizes: poolSizes.ToCPointer, |
540 maxSets: (nUniformBuffers + nSamplers) * INFLIGHTFRAMES.uint32 * 2, # good formula? no idea... | 540 maxSets: (nUniformBuffers + nSamplers) * INFLIGHTFRAMES * 2, # good formula? no idea... |
541 ) | 541 ) |
542 var pool: VkDescriptorPool | 542 var pool: VkDescriptorPool |
543 checkVkResult vkCreateDescriptorPool(device, addr(poolInfo), nil, addr(pool)) | 543 checkVkResult vkCreateDescriptorPool(device, addr(poolInfo), nil, addr(pool)) |
544 | 544 |
545 var layouts = newSeqWith(result.descriptorSets.len, descriptorSetLayout) | 545 var layouts = newSeqWith(result.descriptorSets.len, descriptorSetLayout) |
548 descriptorPool: pool, | 548 descriptorPool: pool, |
549 descriptorSetCount: uint32(layouts.len), | 549 descriptorSetCount: uint32(layouts.len), |
550 pSetLayouts: layouts.ToCPointer, | 550 pSetLayouts: layouts.ToCPointer, |
551 ) | 551 ) |
552 checkVkResult vkAllocateDescriptorSets(device, addr(allocInfo), result.descriptorSets.ToCPointer) | 552 checkVkResult vkAllocateDescriptorSets(device, addr(allocInfo), result.descriptorSets.ToCPointer) |
553 | |
554 # write descriptor sets | |
555 # TODO | |
556 var descriptorSetWrites: seq[VkWriteDescriptorSet] | |
557 for XY in descriptors?: | |
558 | |
559 bufferInfos.add VkDescriptorBufferInfo( | |
560 buffer: descriptor.buffer.vk, | |
561 offset: descriptor.offset, | |
562 range: descriptor.size, | |
563 ) | |
564 descriptorSetWrites.add VkWriteDescriptorSet( | |
565 sType: VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, | |
566 dstSet: descriptorSet.vk, | |
567 dstBinding: i, | |
568 dstArrayElement: 0, | |
569 descriptorType: descriptor.vkType, | |
570 descriptorCount: uint32(descriptor.count), | |
571 pBufferInfo: addr bufferInfos[^1], | |
572 ) | |
573 | |
574 vkUpdateDescriptorSets(device, uint32(descriptorSetWrites.len), descriptorSetWrites.ToCPointer, 0, nil) | |
553 | 575 |
554 proc CreateRenderable[TMesh, TInstance]( | 576 proc CreateRenderable[TMesh, TInstance]( |
555 mesh: TMesh, | 577 mesh: TMesh, |
556 instance: TInstance, | 578 instance: TInstance, |
557 buffers: RenderBuffers, | 579 buffers: RenderBuffers, |
623 pipeline: Pipeline[TShader], | 645 pipeline: Pipeline[TShader], |
624 renderable: Renderable[TMesh, TInstance], | 646 renderable: Renderable[TMesh, TInstance], |
625 globals: TGlobals, | 647 globals: TGlobals, |
626 commandBuffer: VkCommandBuffer, | 648 commandBuffer: VkCommandBuffer, |
627 ) = | 649 ) = |
650 {.error: "Need to write descriptor sets".} | |
628 static: AssertCompatible(TShader, TMesh, TInstance, TGlobals) | 651 static: AssertCompatible(TShader, TMesh, TInstance, TGlobals) |
629 if renderable.vertexBuffers.len > 0: | 652 if renderable.vertexBuffers.len > 0: |
630 commandBuffer.vkCmdBindVertexBuffers( | 653 commandBuffer.vkCmdBindVertexBuffers( |
631 firstBinding = 0'u32, | 654 firstBinding = 0'u32, |
632 bindingCount = uint32(renderable.vertexBuffers.len), | 655 bindingCount = uint32(renderable.vertexBuffers.len), |