vkr: add vkr_context_{add,remove}_object

They are wrappers to util_hash_table_{set,remove}_u64 with added sanity
checks.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent 47b8232e41
commit 74ee5345ed
  1. 39
      src/venus/vkr_common.h
  2. 22
      src/venus/vkr_context.h

@ -314,4 +314,43 @@ vkr_find_pnext(const void *chain, VkStructureType type)
return NULL;
}
static inline bool
vkr_is_recognized_object_type(VkObjectType type)
{
switch (type) {
/* VK_VERSION_1_0 */
case VK_OBJECT_TYPE_INSTANCE:
case VK_OBJECT_TYPE_PHYSICAL_DEVICE:
case VK_OBJECT_TYPE_DEVICE:
case VK_OBJECT_TYPE_QUEUE:
case VK_OBJECT_TYPE_SEMAPHORE:
case VK_OBJECT_TYPE_COMMAND_BUFFER:
case VK_OBJECT_TYPE_FENCE:
case VK_OBJECT_TYPE_DEVICE_MEMORY:
case VK_OBJECT_TYPE_BUFFER:
case VK_OBJECT_TYPE_IMAGE:
case VK_OBJECT_TYPE_EVENT:
case VK_OBJECT_TYPE_QUERY_POOL:
case VK_OBJECT_TYPE_BUFFER_VIEW:
case VK_OBJECT_TYPE_IMAGE_VIEW:
case VK_OBJECT_TYPE_SHADER_MODULE:
case VK_OBJECT_TYPE_PIPELINE_CACHE:
case VK_OBJECT_TYPE_PIPELINE_LAYOUT:
case VK_OBJECT_TYPE_RENDER_PASS:
case VK_OBJECT_TYPE_PIPELINE:
case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT:
case VK_OBJECT_TYPE_SAMPLER:
case VK_OBJECT_TYPE_DESCRIPTOR_POOL:
case VK_OBJECT_TYPE_DESCRIPTOR_SET:
case VK_OBJECT_TYPE_FRAMEBUFFER:
case VK_OBJECT_TYPE_COMMAND_POOL:
/* VK_VERSION_1_1 */
case VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION:
case VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE:
return true;
default:
return false;
}
}
#endif /* VKR_COMMON_H */

@ -63,12 +63,32 @@ struct vkr_context {
struct vkr_instance *instance;
};
static inline void
vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj)
{
assert(vkr_is_recognized_object_type(obj->type));
/* TODO we might hit these at the moment */
assert(obj->id);
assert(!util_hash_table_get_u64(ctx->object_table, obj->id));
util_hash_table_set_u64(ctx->object_table, obj->id, obj);
}
static inline void
vkr_context_remove_object(struct vkr_context *ctx, struct vkr_object *obj)
{
assert(util_hash_table_get_u64(ctx->object_table, obj->id));
/* this frees obj */
util_hash_table_remove_u64(ctx->object_table, obj->id);
}
static inline void
vkr_context_remove_objects(struct vkr_context *ctx, struct list_head *objects)
{
struct vkr_object *obj, *tmp;
LIST_FOR_EACH_ENTRY_SAFE (obj, tmp, objects, track_head)
util_hash_table_remove_u64(ctx->object_table, obj->id);
vkr_context_remove_object(ctx, obj);
/* objects should be reinitialized if to be reused */
}

Loading…
Cancel
Save