vkr: add and use vkr_object_alloc

A helper function that asserts.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
macos/master
Chia-I Wu 3 years ago
parent acea53663d
commit fe22c46d40
  1. 17
      src/venus/vkr_common.h
  2. 5
      src/venus/vkr_physical_device.c
  3. 5
      src/venus/vkr_queue.c

@ -334,4 +334,21 @@ vkr_is_recognized_object_type(VkObjectType type)
} }
} }
static inline void *
vkr_object_alloc(size_t size, VkObjectType type, vkr_object_id id)
{
assert(size >= sizeof(struct vkr_object));
assert(vkr_is_recognized_object_type(type));
struct vkr_object *obj = calloc(1, size);
if (!obj)
return NULL;
/* obj is only half-initialized */
obj->type = type;
obj->id = id;
return obj;
}
#endif /* VKR_COMMON_H */ #endif /* VKR_COMMON_H */

@ -197,14 +197,13 @@ vkr_dispatch_vkEnumeratePhysicalDevices(struct vn_dispatch_context *dispatch,
continue; continue;
} }
physical_dev = calloc(1, sizeof(*physical_dev)); physical_dev =
vkr_object_alloc(sizeof(*physical_dev), VK_OBJECT_TYPE_PHYSICAL_DEVICE, id);
if (!physical_dev) { if (!physical_dev) {
args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
break; break;
} }
physical_dev->base.type = VK_OBJECT_TYPE_PHYSICAL_DEVICE;
physical_dev->base.id = id;
physical_dev->base.handle.physical_device = instance->physical_device_handles[i]; physical_dev->base.handle.physical_device = instance->physical_device_handles[i];
vkr_physical_device_init_properties(physical_dev); vkr_physical_device_init_properties(physical_dev);

@ -240,12 +240,11 @@ vkr_queue_create(struct vkr_context *ctx,
struct vkr_queue *queue; struct vkr_queue *queue;
int ret; int ret;
queue = calloc(1, sizeof(*queue)); /* id is set to 0 until vkr_queue_assign_object_id */
queue = vkr_object_alloc(sizeof(*queue), VK_OBJECT_TYPE_QUEUE, 0);
if (!queue) if (!queue)
return NULL; return NULL;
queue->base.type = VK_OBJECT_TYPE_QUEUE;
/* queue->base.id is not assigned until vkr_queue_assign_object_id */
queue->base.handle.queue = handle; queue->base.handle.queue = handle;
queue->context = ctx; queue->context = ctx;

Loading…
Cancel
Save