aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHyunjun Ko <[email protected]>2020-07-01 05:05:25 +0000
committerMarge Bot <[email protected]>2020-07-14 02:48:30 +0000
commit3a153137f4c0f0c1df55ffcf5878a592248737b3 (patch)
tree236cf9b4cbef2d3881319ae0383161a5553a9e03
parentf076c36367fddfb049b54746b5637c1444ce230f (diff)
vulkan: Adds helpers for vk_object (de)alloation and (de)initialization.
Signed-off-by: Hyunjun Ko <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5539>
-rw-r--r--src/vulkan/util/vk_object.c41
-rw-r--r--src/vulkan/util/vk_object.h18
2 files changed, 59 insertions, 0 deletions
diff --git a/src/vulkan/util/vk_object.c b/src/vulkan/util/vk_object.c
index 25e42f397e3..7fed00e42c7 100644
--- a/src/vulkan/util/vk_object.c
+++ b/src/vulkan/util/vk_object.c
@@ -77,6 +77,47 @@ vk_device_finish(UNUSED struct vk_device *device)
vk_object_base_finish(&device->base);
}
+void *
+vk_object_alloc(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ size_t size,
+ VkObjectType obj_type)
+{
+ void *ptr = vk_alloc2(&device->alloc, alloc, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (ptr == NULL)
+ return NULL;
+
+ vk_object_base_init(device, (struct vk_object_base *)ptr, obj_type);
+
+ return ptr;
+}
+
+void *
+vk_object_zalloc(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ size_t size,
+ VkObjectType obj_type)
+{
+ void *ptr = vk_zalloc2(&device->alloc, alloc, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (ptr == NULL)
+ return NULL;
+
+ vk_object_base_init(device, (struct vk_object_base *)ptr, obj_type);
+
+ return ptr;
+}
+
+void
+vk_object_free(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ void *data)
+{
+ vk_object_base_finish((struct vk_object_base *)data);
+ vk_free2(&device->alloc, alloc, data);
+}
+
VkResult
vk_private_data_slot_create(struct vk_device *device,
const VkPrivateDataSlotCreateInfoEXT* pCreateInfo,
diff --git a/src/vulkan/util/vk_object.h b/src/vulkan/util/vk_object.h
index 7550b6a422b..b93018fa1c1 100644
--- a/src/vulkan/util/vk_object.h
+++ b/src/vulkan/util/vk_object.h
@@ -124,6 +124,24 @@ void vk_device_finish(struct vk_device *device);
#define VK_FROM_HANDLE(__driver_type, __name, __handle) \
struct __driver_type *__name = __driver_type ## _from_handle(__handle)
+/* Helpers for vk object (de)allocation and (de)initialization */
+void *
+vk_object_alloc(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ size_t size,
+ VkObjectType vk_obj_type);
+
+void *
+vk_object_zalloc(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ size_t size,
+ VkObjectType vk_obj_type);
+
+void
+vk_object_free(struct vk_device *device,
+ const VkAllocationCallbacks *alloc,
+ void *data);
+
struct vk_private_data_slot {
struct vk_object_base base;