annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
1 import ./vulkan
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
2 import ./vulkan_helpers
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
3 import ./math/vector
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
4 import ./math/matrix
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
5 import ./buffer
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
6
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
7 type
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
8 DescriptorType = SomeNumber|Vec|Mat
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
9 Descriptor*[T:DescriptorType] = object
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
10 value*: T
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
11
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
12 proc createUniformDescriptorLayout*(device: VkDevice, shaderStage: VkShaderStageFlags, binding: uint32): VkDescriptorSetLayout =
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
13 var
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
14 layoutbinding = VkDescriptorSetLayoutBinding(
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
15 binding: binding,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
16 descriptorType: VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
17 descriptorCount: 1,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
18 stageFlags: shaderStage,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
19 pImmutableSamplers: nil,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
20 )
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
21 layoutInfo = VkDescriptorSetLayoutCreateInfo(
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
22 sType: VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
23 bindingCount: 1,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
24 pBindings: addr(layoutbinding)
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
25 )
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
26 checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result))
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
27
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
28 proc createUniformBuffers*[nBuffers: static int, T](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] =
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
29 let size = sizeof(T)
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
30 for i in 0 ..< nBuffers:
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
31 var buffer = InitBuffer(
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
32 device,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
33 physicalDevice,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
34 uint64(size),
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
35 {UniformBuffer},
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
36 {VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT},
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
37 persistentMapping=true,
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
38 )
917d99d5eb89 add: missing file
Sam <sam@basx.dev>
parents:
diff changeset
39 result[i] = buffer