comparison src/zamikongine/descriptor.nim @ 30:917d99d5eb89

add: missing file
author Sam <sam@basx.dev>
date Sat, 14 Jan 2023 14:08:45 +0700
parents
children 9edca5dc4e93
comparison
equal deleted inserted replaced
29:da922b506570 30:917d99d5eb89
1 import ./vulkan
2 import ./vulkan_helpers
3 import ./math/vector
4 import ./math/matrix
5 import ./buffer
6
7 type
8 DescriptorType = SomeNumber|Vec|Mat
9 Descriptor*[T:DescriptorType] = object
10 value*: T
11
12 proc createUniformDescriptorLayout*(device: VkDevice, shaderStage: VkShaderStageFlags, binding: uint32): VkDescriptorSetLayout =
13 var
14 layoutbinding = VkDescriptorSetLayoutBinding(
15 binding: binding,
16 descriptorType: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
17 descriptorCount: 1,
18 stageFlags: shaderStage,
19 pImmutableSamplers: nil,
20 )
21 layoutInfo = VkDescriptorSetLayoutCreateInfo(
22 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
23 bindingCount: 1,
24 pBindings: addr(layoutbinding)
25 )
26 checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result))
27
28 proc createUniformBuffers*[nBuffers: static int, T](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] =
29 let size = sizeof(T)
30 for i in 0 ..< nBuffers:
31 var buffer = InitBuffer(
32 device,
33 physicalDevice,
34 uint64(size),
35 {UniformBuffer},
36 {VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT},
37 persistentMapping=true,
38 )
39 result[i] = buffer