From 74ee5345ed7a7c57acc65b49419282111bb6634c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 9 Aug 2021 11:08:00 -0700 Subject: [PATCH] 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 Reviewed-by: Ryan Neph Reviewed-by: Yiwei Zhang --- src/venus/vkr_common.h | 39 +++++++++++++++++++++++++++++++++++++++ src/venus/vkr_context.h | 22 +++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/venus/vkr_common.h b/src/venus/vkr_common.h index d57b6c3..6430137 100644 --- a/src/venus/vkr_common.h +++ b/src/venus/vkr_common.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 */ diff --git a/src/venus/vkr_context.h b/src/venus/vkr_context.h index 7310fc3..47b302a 100644 --- a/src/venus/vkr_context.h +++ b/src/venus/vkr_context.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 */ }