vkr: add and use vkr_context_alloc_object

A helper function that loads the id from the handle automatically.

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 fe22c46d40
commit e56b1f08a5
  1. 5
      src/venus/vkr_common.h
  2. 10
      src/venus/vkr_context.h
  3. 6
      src/venus/vkr_device.c
  4. 6
      src/venus/vkr_device_memory.c
  5. 6
      src/venus/vkr_instance.c
  6. 6
      src/venus/vkr_render_pass.c

@ -54,13 +54,12 @@
#define CREATE_OBJECT(obj, vkr_type, vk_obj, vk_cmd, vk_arg) \ #define CREATE_OBJECT(obj, vkr_type, vk_obj, vk_cmd, vk_arg) \
struct vkr_device *_dev = (struct vkr_device *)args->device; \ struct vkr_device *_dev = (struct vkr_device *)args->device; \
\ \
struct vkr_##vkr_type *obj = calloc(1, sizeof(*obj)); \ struct vkr_##vkr_type *obj = vkr_context_alloc_object( \
ctx, sizeof(*obj), VK_OBJECT_TYPE_##vk_obj, args->vk_arg); \
if (!obj) { \ if (!obj) { \
args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; \ args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; \
return; \ return; \
} \ } \
obj->base.type = VK_OBJECT_TYPE_##vk_obj; \
obj->base.id = vkr_cs_handle_load_id((const void **)args->vk_arg, obj->base.type); \
\ \
vn_replace_##vk_cmd##_args_handle(args); \ vn_replace_##vk_cmd##_args_handle(args); \
args->ret = \ args->ret = \

@ -65,6 +65,16 @@ struct vkr_context {
char *instance_name; char *instance_name;
}; };
static inline void *
vkr_context_alloc_object(UNUSED struct vkr_context *ctx,
size_t size,
VkObjectType type,
const void *id_handle)
{
const vkr_object_id id = vkr_cs_handle_load_id((const void **)id_handle, type);
return vkr_object_alloc(size, type, id);
}
static inline void static inline void
vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj) vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj)
{ {

@ -179,16 +179,14 @@ vkr_dispatch_vkCreateDevice(struct vn_dispatch_context *dispatch,
((VkDeviceCreateInfo *)args->pCreateInfo)->enabledExtensionCount = ext_count; ((VkDeviceCreateInfo *)args->pCreateInfo)->enabledExtensionCount = ext_count;
} }
struct vkr_device *dev = calloc(1, sizeof(*dev)); struct vkr_device *dev =
vkr_context_alloc_object(ctx, sizeof(*dev), VK_OBJECT_TYPE_DEVICE, args->pDevice);
if (!dev) { if (!dev) {
args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
free(exts); free(exts);
return; return;
} }
dev->base.type = VK_OBJECT_TYPE_DEVICE;
dev->base.id = vkr_cs_handle_load_id((const void **)args->pDevice, dev->base.type);
vn_replace_vkCreateDevice_args_handle(args); vn_replace_vkCreateDevice_args_handle(args);
args->ret = vkCreateDevice(args->physicalDevice, args->pCreateInfo, NULL, args->ret = vkCreateDevice(args->physicalDevice, args->pCreateInfo, NULL,
&dev->base.handle.device); &dev->base.handle.device);

@ -100,7 +100,8 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch,
} }
} }
struct vkr_device_memory *mem = calloc(1, sizeof(*mem)); struct vkr_device_memory *mem = vkr_context_alloc_object(
ctx, sizeof(*mem), VK_OBJECT_TYPE_DEVICE_MEMORY, args->pMemory);
if (!mem) { if (!mem) {
if (import_resource_info) if (import_resource_info)
close(import_fd_info.fd); close(import_fd_info.fd);
@ -108,9 +109,6 @@ vkr_dispatch_vkAllocateMemory(struct vn_dispatch_context *dispatch,
return; return;
} }
mem->base.type = VK_OBJECT_TYPE_DEVICE_MEMORY;
mem->base.id = vkr_cs_handle_load_id((const void **)args->pMemory, mem->base.type);
vn_replace_vkAllocateMemory_args_handle(args); vn_replace_vkAllocateMemory_args_handle(args);
args->ret = vkAllocateMemory(args->device, args->pAllocateInfo, NULL, args->ret = vkAllocateMemory(args->device, args->pAllocateInfo, NULL,
&mem->base.handle.device_memory); &mem->base.handle.device_memory);

@ -180,15 +180,13 @@ vkr_dispatch_vkCreateInstance(struct vn_dispatch_context *dispatch,
} }
create_info->pApplicationInfo = &app_info; create_info->pApplicationInfo = &app_info;
struct vkr_instance *instance = calloc(1, sizeof(*instance)); struct vkr_instance *instance = vkr_context_alloc_object(
ctx, sizeof(*instance), VK_OBJECT_TYPE_INSTANCE, args->pInstance);
if (!instance) { if (!instance) {
args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
return; return;
} }
instance->base.type = VK_OBJECT_TYPE_INSTANCE;
instance->base.id =
vkr_cs_handle_load_id((const void **)args->pInstance, instance->base.type);
instance->api_version = app_info.apiVersion; instance->api_version = app_info.apiVersion;
vn_replace_vkCreateInstance_args_handle(args); vn_replace_vkCreateInstance_args_handle(args);

@ -29,14 +29,12 @@ vkr_dispatch_vkCreateRenderPass2(struct vn_dispatch_context *dispatch,
struct vkr_context *ctx = dispatch->data; struct vkr_context *ctx = dispatch->data;
struct vkr_device *dev = (struct vkr_device *)args->device; struct vkr_device *dev = (struct vkr_device *)args->device;
struct vkr_render_pass *pass = calloc(1, sizeof(*pass)); struct vkr_render_pass *pass = vkr_context_alloc_object(
ctx, sizeof(*pass), VK_OBJECT_TYPE_RENDER_PASS, args->pRenderPass);
if (!pass) { if (!pass) {
args->ret = VK_ERROR_OUT_OF_HOST_MEMORY; args->ret = VK_ERROR_OUT_OF_HOST_MEMORY;
return; return;
} }
pass->base.type = VK_OBJECT_TYPE_RENDER_PASS;
pass->base.id =
vkr_cs_handle_load_id((const void **)args->pRenderPass, pass->base.type);
vn_replace_vkCreateRenderPass2_args_handle(args); vn_replace_vkCreateRenderPass2_args_handle(args);
args->ret = dev->CreateRenderPass2(args->device, args->pCreateInfo, NULL, args->ret = dev->CreateRenderPass2(args->device, args->pCreateInfo, NULL,

Loading…
Cancel
Save