Mercurial > games > semicongine
changeset 491:f18331a8a314
add: missing file
author | Sam <sam@basx.dev> |
---|---|
date | Sat, 14 Jan 2023 14:08:45 +0700 |
parents | aae5426c09df |
children | d63d980fa3bb |
files | src/zamikongine/descriptor.nim |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/zamikongine/descriptor.nim Sat Jan 14 14:08:45 2023 +0700 @@ -0,0 +1,39 @@ +import ./vulkan +import ./vulkan_helpers +import ./math/vector +import ./math/matrix +import ./buffer + +type + DescriptorType = SomeNumber|Vec|Mat + Descriptor*[T:DescriptorType] = object + value*: T + +proc createUniformDescriptorLayout*(device: VkDevice, shaderStage: VkShaderStageFlags, binding: uint32): VkDescriptorSetLayout = + var + layoutbinding = VkDescriptorSetLayoutBinding( + binding: binding, + descriptorType: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + descriptorCount: 1, + stageFlags: shaderStage, + pImmutableSamplers: nil, + ) + layoutInfo = VkDescriptorSetLayoutCreateInfo( + sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + bindingCount: 1, + pBindings: addr(layoutbinding) + ) + checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result)) + +proc createUniformBuffers*[nBuffers: static int, T](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] = + let size = sizeof(T) + for i in 0 ..< nBuffers: + var buffer = InitBuffer( + device, + physicalDevice, + uint64(size), + {UniformBuffer}, + {VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT}, + persistentMapping=true, + ) + result[i] = buffer