1 /*
2 * Copyright © 2022 Collabora, Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "vk_buffer.h"
25
26 #include "vk_alloc.h"
27 #include "vk_device.h"
28
29 void
vk_buffer_init(struct vk_device * device,struct vk_buffer * buffer,const VkBufferCreateInfo * pCreateInfo)30 vk_buffer_init(struct vk_device *device,
31 struct vk_buffer *buffer,
32 const VkBufferCreateInfo *pCreateInfo)
33 {
34 vk_object_base_init(device, &buffer->base, VK_OBJECT_TYPE_BUFFER);
35
36 assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
37 assert(pCreateInfo->size > 0);
38
39 buffer->create_flags = pCreateInfo->flags;
40 buffer->size = pCreateInfo->size;
41 buffer->usage = pCreateInfo->usage;
42 }
43
44 void *
vk_buffer_create(struct vk_device * device,const VkBufferCreateInfo * pCreateInfo,const VkAllocationCallbacks * alloc,size_t size)45 vk_buffer_create(struct vk_device *device,
46 const VkBufferCreateInfo *pCreateInfo,
47 const VkAllocationCallbacks *alloc,
48 size_t size)
49 {
50 struct vk_buffer *buffer =
51 vk_zalloc2(&device->alloc, alloc, size, 8,
52 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
53 if (buffer == NULL)
54 return NULL;
55
56 vk_buffer_init(device, buffer, pCreateInfo);
57
58 return buffer;
59 }
60
61 void
vk_buffer_finish(struct vk_buffer * buffer)62 vk_buffer_finish(struct vk_buffer *buffer)
63 {
64 vk_object_base_finish(&buffer->base);
65 }
66
67 void
vk_buffer_destroy(struct vk_device * device,const VkAllocationCallbacks * alloc,struct vk_buffer * buffer)68 vk_buffer_destroy(struct vk_device *device,
69 const VkAllocationCallbacks *alloc,
70 struct vk_buffer *buffer)
71 {
72 vk_object_free(device, alloc, buffer);
73 }
74