annotate src/semicongine/vulkan/buffer.nim @ 105:4059aa0d689b

add: descriptors, better swapchain implementation
author Sam <sam@basx.dev>
date Fri, 24 Mar 2023 00:11:42 +0700
parents 110ed3ee5df8
children 0c5a74885796
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
89
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
1 import ./api
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
2 import ./device
89
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
3
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
4 type
105
4059aa0d689b add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 97
diff changeset
5 Buffer* = object
4059aa0d689b add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 97
diff changeset
6 device*: Device
4059aa0d689b add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 97
diff changeset
7 vk*: VkBuffer
4059aa0d689b add: descriptors, better swapchain implementation
Sam <sam@basx.dev>
parents: 97
diff changeset
8 size*: uint64
89
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
9
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
10 # currently no support for extended structure and concurrent/shared use
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
11 # (shardingMode = VK_SHARING_MODE_CONCURRENT not supported)
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
12 proc createBuffer(device: Device, size: uint64, flags: openArray[VkBufferCreateFlagBits], usage: openArray[VkBufferUsageFlagBits]): Buffer =
89
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
13 result.device = device
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
14 result.size = size
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
15 var createInfo = VkBufferCreateInfo(
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
16 sType: VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
17 flags: toBits(flags),
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
18 size: size,
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
19 usage: toBits(usage),
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
20 sharingMode: VK_SHARING_MODE_EXCLUSIVE,
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
21 )
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
22
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
23 checkVkResult vkCreateBuffer(
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
24 device=device.vk,
89
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
25 pCreateInfo=addr createInfo,
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
26 pAllocator=nil,
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
27 pBuffer=addr result.vk
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
28 )
6e8037c1f655 add: better vulkan wrappers
Sam <sam@basx.dev>
parents:
diff changeset
29
97
110ed3ee5df8 add: swapchain, images, fix some destroctors
Sam <sam@basx.dev>
parents: 94
diff changeset
30 proc destroy(buffer: var Buffer) =
94
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
31 assert buffer.device.vk.valid
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
32 assert buffer.vk.valid
f036546f5ea2 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 92
diff changeset
33 buffer.device.vk.vkDestroyBuffer(buffer.vk, nil)
97
110ed3ee5df8 add: swapchain, images, fix some destroctors
Sam <sam@basx.dev>
parents: 94
diff changeset
34 buffer.vk.reset()