diff --git a/src/venus/vkr_common.h b/src/venus/vkr_common.h index 73816e6..d788f27 100644 --- a/src/venus/vkr_common.h +++ b/src/venus/vkr_common.h @@ -19,6 +19,7 @@ #include "c11/threads.h" #include "pipe/p_compiler.h" +#include "util/hash_table.h" #include "util/os_misc.h" #include "util/u_double_list.h" #include "util/u_hash_table.h" diff --git a/src/venus/vkr_context.c b/src/venus/vkr_context.c index 29dfb86..da1fac9 100644 --- a/src/venus/vkr_context.c +++ b/src/venus/vkr_context.c @@ -549,7 +549,7 @@ vkr_context_destroy(struct virgl_context *base) vkr_instance_destroy(ctx, ctx->instance); } - util_hash_table_destroy(ctx->resource_table); + _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); util_hash_table_destroy_u64(ctx->object_table); struct vkr_queue_sync *sync, *tmp; @@ -589,10 +589,10 @@ destroy_func_object(void *val) free(obj); } -static void -destroy_func_resource(void *val) +void +vkr_context_free_resource(struct hash_entry *entry) { - struct vkr_resource_attachment *att = val; + struct vkr_resource_attachment *att = entry->data; struct vkr_device_memory *mem, *tmp; LIST_FOR_EACH_ENTRY_SAFE (mem, tmp, &att->memories, exported_head) @@ -641,7 +641,7 @@ vkr_context_create(size_t debug_len, const char *debug_name) ctx->object_table = util_hash_table_create_u64(destroy_func_object); ctx->resource_table = - util_hash_table_create(hash_func_u32, compare_func, destroy_func_resource); + _mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal); if (!ctx->object_table || !ctx->resource_table) goto fail; @@ -671,7 +671,7 @@ fail: if (ctx->object_table) util_hash_table_destroy_u64(ctx->object_table); if (ctx->resource_table) - util_hash_table_destroy(ctx->resource_table); + _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); mtx_destroy(&ctx->mutex); free(ctx->debug_name); free(ctx); diff --git a/src/venus/vkr_context.h b/src/venus/vkr_context.h index 163d408..cccac54 100644 --- a/src/venus/vkr_context.h +++ b/src/venus/vkr_context.h @@ -50,7 +50,7 @@ struct vkr_context { struct list_head rings; struct util_hash_table_u64 *object_table; - struct util_hash_table *resource_table; + struct hash_table *resource_table; struct list_head newly_exported_memories; struct vkr_cs_encoder encoder; @@ -65,23 +65,31 @@ struct vkr_context { char *instance_name; }; +void +vkr_context_free_resource(struct hash_entry *entry); + static inline void vkr_context_add_resource(struct vkr_context *ctx, struct vkr_resource_attachment *att) { - const uint32_t res_id = att->resource->res_id; - util_hash_table_set(ctx->resource_table, uintptr_to_pointer(res_id), att); + assert(!_mesa_hash_table_search(ctx->resource_table, &att->resource->res_id)); + _mesa_hash_table_insert(ctx->resource_table, &att->resource->res_id, att); } static inline void vkr_context_remove_resource(struct vkr_context *ctx, uint32_t res_id) { - util_hash_table_remove(ctx->resource_table, uintptr_to_pointer(res_id)); + struct hash_entry *entry = _mesa_hash_table_search(ctx->resource_table, &res_id); + if (likely(entry)) { + vkr_context_free_resource(entry); + _mesa_hash_table_remove(ctx->resource_table, entry); + } } static inline struct vkr_resource_attachment * vkr_context_get_resource(struct vkr_context *ctx, uint32_t res_id) { - return util_hash_table_get(ctx->resource_table, uintptr_to_pointer(res_id)); + const struct hash_entry *entry = _mesa_hash_table_search(ctx->resource_table, &res_id); + return likely(entry) ? entry->data : NULL; } static inline bool