vkr: use the newer hash_table to manage resources

The newer hash_table is supposed to be faster.

Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent 8249c00b02
commit 0e2eb9ca83
  1. 1
      src/venus/vkr_common.h
  2. 12
      src/venus/vkr_context.c
  3. 18
      src/venus/vkr_context.h

@ -19,6 +19,7 @@
#include "c11/threads.h" #include "c11/threads.h"
#include "pipe/p_compiler.h" #include "pipe/p_compiler.h"
#include "util/hash_table.h"
#include "util/os_misc.h" #include "util/os_misc.h"
#include "util/u_double_list.h" #include "util/u_double_list.h"
#include "util/u_hash_table.h" #include "util/u_hash_table.h"

@ -549,7 +549,7 @@ vkr_context_destroy(struct virgl_context *base)
vkr_instance_destroy(ctx, ctx->instance); 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); util_hash_table_destroy_u64(ctx->object_table);
struct vkr_queue_sync *sync, *tmp; struct vkr_queue_sync *sync, *tmp;
@ -589,10 +589,10 @@ destroy_func_object(void *val)
free(obj); free(obj);
} }
static void void
destroy_func_resource(void *val) 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; struct vkr_device_memory *mem, *tmp;
LIST_FOR_EACH_ENTRY_SAFE (mem, tmp, &att->memories, exported_head) 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->object_table = util_hash_table_create_u64(destroy_func_object);
ctx->resource_table = 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) if (!ctx->object_table || !ctx->resource_table)
goto fail; goto fail;
@ -671,7 +671,7 @@ fail:
if (ctx->object_table) if (ctx->object_table)
util_hash_table_destroy_u64(ctx->object_table); util_hash_table_destroy_u64(ctx->object_table);
if (ctx->resource_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); mtx_destroy(&ctx->mutex);
free(ctx->debug_name); free(ctx->debug_name);
free(ctx); free(ctx);

@ -50,7 +50,7 @@ struct vkr_context {
struct list_head rings; struct list_head rings;
struct util_hash_table_u64 *object_table; 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 list_head newly_exported_memories;
struct vkr_cs_encoder encoder; struct vkr_cs_encoder encoder;
@ -65,23 +65,31 @@ struct vkr_context {
char *instance_name; char *instance_name;
}; };
void
vkr_context_free_resource(struct hash_entry *entry);
static inline void static inline void
vkr_context_add_resource(struct vkr_context *ctx, struct vkr_resource_attachment *att) vkr_context_add_resource(struct vkr_context *ctx, struct vkr_resource_attachment *att)
{ {
const uint32_t res_id = att->resource->res_id; assert(!_mesa_hash_table_search(ctx->resource_table, &att->resource->res_id));
util_hash_table_set(ctx->resource_table, uintptr_to_pointer(res_id), att); _mesa_hash_table_insert(ctx->resource_table, &att->resource->res_id, att);
} }
static inline void static inline void
vkr_context_remove_resource(struct vkr_context *ctx, uint32_t res_id) 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 * static inline struct vkr_resource_attachment *
vkr_context_get_resource(struct vkr_context *ctx, uint32_t res_id) 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 static inline bool

Loading…
Cancel
Save