# HG changeset patch # User sam # Date 1719020714 -25200 # Node ID 58694b30b9cb89993f1ea2ab3f176466f7b1d36f # Parent 7b4d4d85d9f5a1c28af9db43d5d3540c0a0ed78a add: some stuff diff -r 7b4d4d85d9f5 -r 58694b30b9cb static_utils.nim --- a/static_utils.nim Sat Jun 22 02:26:16 2024 +0700 +++ b/static_utils.nim Sat Jun 22 08:45:14 2024 +0700 @@ -20,7 +20,7 @@ template PassFlat* {.pragma.} template ShaderOutput* {.pragma.} -const INFLIGHTFRAMES = 2 +const INFLIGHTFRAMES = 2'u32 type 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] ShaderObject*[TShader] = object @@ -530,14 +530,14 @@ if nSamplers + nUniformBuffers > 0: var poolSizes: seq[VkDescriptorPoolSize] if nUniformBuffers > 0: - poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, descriptorCount: nSamplers * INFLIGHTFRAMES.uint32) + poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, descriptorCount: nSamplers * INFLIGHTFRAMES) if nSamplers > 0: - poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, descriptorCount: nUniformBuffers * INFLIGHTFRAMES.uint32) + poolSizes.add VkDescriptorPoolSize(thetype: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, descriptorCount: nUniformBuffers * INFLIGHTFRAMES) var poolInfo = VkDescriptorPoolCreateInfo( sType: VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, poolSizeCount: uint32(poolSizes.len), pPoolSizes: poolSizes.ToCPointer, - maxSets: (nUniformBuffers + nSamplers) * INFLIGHTFRAMES.uint32 * 2, # good formula? no idea... + maxSets: (nUniformBuffers + nSamplers) * INFLIGHTFRAMES * 2, # good formula? no idea... ) var pool: VkDescriptorPool checkVkResult vkCreateDescriptorPool(device, addr(poolInfo), nil, addr(pool)) @@ -551,6 +551,28 @@ ) checkVkResult vkAllocateDescriptorSets(device, addr(allocInfo), result.descriptorSets.ToCPointer) + # write descriptor sets + # TODO + var descriptorSetWrites: seq[VkWriteDescriptorSet] + for XY in descriptors?: + + bufferInfos.add VkDescriptorBufferInfo( + buffer: descriptor.buffer.vk, + offset: descriptor.offset, + range: descriptor.size, + ) + descriptorSetWrites.add VkWriteDescriptorSet( + sType: VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + dstSet: descriptorSet.vk, + dstBinding: i, + dstArrayElement: 0, + descriptorType: descriptor.vkType, + descriptorCount: uint32(descriptor.count), + pBufferInfo: addr bufferInfos[^1], + ) + + vkUpdateDescriptorSets(device, uint32(descriptorSetWrites.len), descriptorSetWrites.ToCPointer, 0, nil) + proc CreateRenderable[TMesh, TInstance]( mesh: TMesh, instance: TInstance, @@ -625,6 +647,7 @@ globals: TGlobals, commandBuffer: VkCommandBuffer, ) = + {.error: "Need to write descriptor sets".} static: AssertCompatible(TShader, TMesh, TInstance, TGlobals) if renderable.vertexBuffers.len > 0: commandBuffer.vkCmdBindVertexBuffers(