diff --git a/src/venus/vkr_context.c b/src/venus/vkr_context.c index ef5f571..d534421 100644 --- a/src/venus/vkr_context.c +++ b/src/venus/vkr_context.c @@ -10,6 +10,9 @@ #include "virgl_protocol.h" /* for transfer_mode */ #include "vrend_iov.h" +#define XXH_INLINE_ALL +#include "util/xxhash.h" + #include "vkr_buffer.h" #include "vkr_command_buffer.h" #include "vkr_context.h" @@ -550,7 +553,7 @@ vkr_context_destroy(struct virgl_context *base) } _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); - util_hash_table_destroy_u64(ctx->object_table); + util_hash_table_destroy(ctx->object_table); struct vkr_queue_sync *sync, *tmp; LIST_FOR_EACH_ENTRY_SAFE (sync, tmp, &ctx->signaled_syncs, head) @@ -582,6 +585,18 @@ vkr_context_init_base(struct vkr_context *ctx) ctx->base.submit_fence = vkr_context_submit_fence; } +static unsigned +vkr_hash_u64(void *key) +{ + return XXH32(key, sizeof(uint64_t), 0); +} + +static int +vkr_key_u64_equal(void *key1, void *key2) +{ + return *(const uint64_t *)key1 != *(const uint64_t *)key2; +} + static void destroy_func_object(void *val) { @@ -639,7 +654,8 @@ vkr_context_create(size_t debug_len, const char *debug_name) list_inithead(&ctx->rings); - ctx->object_table = util_hash_table_create_u64(destroy_func_object); + ctx->object_table = + util_hash_table_create(vkr_hash_u64, vkr_key_u64_equal, destroy_func_object); ctx->resource_table = _mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal); if (!ctx->object_table || !ctx->resource_table) @@ -669,7 +685,7 @@ vkr_context_create(size_t debug_len, const char *debug_name) fail: if (ctx->object_table) - util_hash_table_destroy_u64(ctx->object_table); + util_hash_table_destroy(ctx->object_table); if (ctx->resource_table) _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); mtx_destroy(&ctx->mutex); diff --git a/src/venus/vkr_context.h b/src/venus/vkr_context.h index 84a746e..ad3ed63 100644 --- a/src/venus/vkr_context.h +++ b/src/venus/vkr_context.h @@ -49,7 +49,7 @@ struct vkr_context { mtx_t mutex; struct list_head rings; - struct util_hash_table_u64 *object_table; + struct util_hash_table *object_table; struct hash_table *resource_table; struct list_head newly_exported_memories; @@ -95,7 +95,7 @@ vkr_context_get_resource(struct vkr_context *ctx, uint32_t res_id) static inline bool vkr_context_validate_object_id(struct vkr_context *ctx, vkr_object_id id) { - if (unlikely(!id || util_hash_table_get_u64(ctx->object_table, id))) { + if (unlikely(!id || util_hash_table_get(ctx->object_table, &id))) { vkr_cs_decoder_set_fatal(&ctx->decoder); return false; } @@ -121,18 +121,18 @@ vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj) { assert(vkr_is_recognized_object_type(obj->type)); assert(obj->id); - assert(!util_hash_table_get_u64(ctx->object_table, obj->id)); + assert(!util_hash_table_get(ctx->object_table, &obj->id)); - util_hash_table_set_u64(ctx->object_table, obj->id, obj); + util_hash_table_set(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)); + assert(util_hash_table_get(ctx->object_table, &obj->id)); /* this frees obj */ - util_hash_table_remove_u64(ctx->object_table, obj->id); + util_hash_table_remove(ctx->object_table, &obj->id); } static inline void @@ -147,7 +147,7 @@ vkr_context_remove_objects(struct vkr_context *ctx, struct list_head *objects) static inline void * vkr_context_get_object(struct vkr_context *ctx, vkr_object_id obj_id) { - return util_hash_table_get_u64(ctx->object_table, obj_id); + return util_hash_table_get(ctx->object_table, &obj_id); } static inline const char * diff --git a/src/venus/vkr_cs.c b/src/venus/vkr_cs.c index 6748e9e..ff3440d 100644 --- a/src/venus/vkr_cs.c +++ b/src/venus/vkr_cs.c @@ -169,7 +169,7 @@ vkr_cs_encoder_write_internal(struct vkr_cs_encoder *enc, void vkr_cs_decoder_init(struct vkr_cs_decoder *dec, - const struct util_hash_table_u64 *object_table) + const struct util_hash_table *object_table) { memset(dec, 0, sizeof(*dec)); dec->object_table = object_table; diff --git a/src/venus/vkr_cs.h b/src/venus/vkr_cs.h index d39474c..fbcf263 100644 --- a/src/venus/vkr_cs.h +++ b/src/venus/vkr_cs.h @@ -52,7 +52,7 @@ struct vkr_cs_decoder_temp_pool { }; struct vkr_cs_decoder { - const struct util_hash_table_u64 *object_table; + const struct util_hash_table *object_table; bool fatal_error; struct vkr_cs_decoder_temp_pool temp_pool; @@ -113,7 +113,7 @@ vkr_cs_encoder_write(struct vkr_cs_encoder *enc, void vkr_cs_decoder_init(struct vkr_cs_decoder *dec, - const struct util_hash_table_u64 *object_table); + const struct util_hash_table *object_table); void vkr_cs_decoder_fini(struct vkr_cs_decoder *dec); @@ -197,7 +197,7 @@ vkr_cs_decoder_lookup_object(const struct vkr_cs_decoder *dec, if (!id) return NULL; - obj = util_hash_table_get_u64((struct util_hash_table_u64 *)dec->object_table, id); + obj = util_hash_table_get((struct util_hash_table *)dec->object_table, &id); if (!obj || obj->type != type) vkr_cs_decoder_set_fatal(dec);