gallium/hash_table: consolidate hash tables with pointer keys
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3722>
This commit is contained in:
@@ -102,18 +102,6 @@ debug_flush_capture_frame(int start, int depth)
|
||||
return frames;
|
||||
}
|
||||
|
||||
static int
|
||||
debug_flush_pointer_compare(void *key1, void *key2)
|
||||
{
|
||||
return (key1 == key2) ? 0 : 1;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
debug_flush_pointer_hash(void *key)
|
||||
{
|
||||
return (unsigned) (uintptr_t) key;
|
||||
}
|
||||
|
||||
struct debug_flush_buf *
|
||||
debug_flush_buf_create(boolean supports_persistent, unsigned bt_depth)
|
||||
{
|
||||
@@ -171,8 +159,7 @@ debug_flush_ctx_create(UNUSED boolean catch_reference_of_mapped,
|
||||
if (!fctx)
|
||||
goto out_no_ctx;
|
||||
|
||||
fctx->ref_hash = util_hash_table_create(debug_flush_pointer_hash,
|
||||
debug_flush_pointer_compare);
|
||||
fctx->ref_hash = util_hash_table_create_ptr_keys();
|
||||
|
||||
if (!fctx->ref_hash)
|
||||
goto out_no_ref_hash;
|
||||
|
||||
@@ -58,25 +58,6 @@ static struct util_hash_table *serials_hash;
|
||||
static unsigned serials_last;
|
||||
|
||||
|
||||
static unsigned
|
||||
hash_ptr(void *p)
|
||||
{
|
||||
return (unsigned) (uintptr_t) p;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
compare_ptr(void *a, void *b)
|
||||
{
|
||||
if (a == b)
|
||||
return 0;
|
||||
else if (a < b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a small integer serial number for the given pointer.
|
||||
*/
|
||||
@@ -96,7 +77,7 @@ debug_serial(void *p, unsigned *pserial)
|
||||
|
||||
mtx_lock(&serials_mutex);
|
||||
if (!serials_hash)
|
||||
serials_hash = util_hash_table_create(hash_ptr, compare_ptr);
|
||||
serials_hash = util_hash_table_create_ptr_keys();
|
||||
|
||||
serial = (unsigned) (uintptr_t) util_hash_table_get(serials_hash, p);
|
||||
if (!serial) {
|
||||
|
||||
@@ -49,21 +49,6 @@
|
||||
struct util_hash_table* symbols_hash;
|
||||
static mtx_t symbols_mutex = _MTX_INITIALIZER_NP;
|
||||
|
||||
static unsigned hash_ptr(void* p)
|
||||
{
|
||||
return (unsigned)(uintptr_t)p;
|
||||
}
|
||||
|
||||
static int compare_ptr(void* a, void* b)
|
||||
{
|
||||
if(a == b)
|
||||
return 0;
|
||||
else if(a < b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO with some refactoring we might be able to re-use debug_symbol_name_cached()
|
||||
* instead.. otoh if using libunwind I think u_debug_symbol could just be excluded
|
||||
* from build?
|
||||
@@ -76,7 +61,7 @@ symbol_name_cached(unw_cursor_t *cursor, unw_proc_info_t *pip)
|
||||
|
||||
mtx_lock(&symbols_mutex);
|
||||
if(!symbols_hash)
|
||||
symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
|
||||
symbols_hash = util_hash_table_create_ptr_keys();
|
||||
name = util_hash_table_get(symbols_hash, addr);
|
||||
if(!name)
|
||||
{
|
||||
|
||||
@@ -273,21 +273,6 @@ debug_symbol_print(const void *addr)
|
||||
struct util_hash_table* symbols_hash;
|
||||
static mtx_t symbols_mutex = _MTX_INITIALIZER_NP;
|
||||
|
||||
static unsigned hash_ptr(void* p)
|
||||
{
|
||||
return (unsigned)(uintptr_t)p;
|
||||
}
|
||||
|
||||
static int compare_ptr(void* a, void* b)
|
||||
{
|
||||
if(a == b)
|
||||
return 0;
|
||||
else if(a < b)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char*
|
||||
debug_symbol_name_cached(const void *addr)
|
||||
{
|
||||
@@ -303,7 +288,7 @@ debug_symbol_name_cached(const void *addr)
|
||||
|
||||
mtx_lock(&symbols_mutex);
|
||||
if(!symbols_hash)
|
||||
symbols_hash = util_hash_table_create(hash_ptr, compare_ptr);
|
||||
symbols_hash = util_hash_table_create_ptr_keys();
|
||||
name = util_hash_table_get(symbols_hash, (void*)addr);
|
||||
if(!name)
|
||||
{
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_hash_table.h"
|
||||
#include "util/hash_table.h"
|
||||
|
||||
|
||||
struct util_hash_table
|
||||
@@ -94,6 +95,27 @@ util_hash_table_create(unsigned (*hash)(void *key),
|
||||
}
|
||||
|
||||
|
||||
static unsigned
|
||||
pointer_hash(void *key)
|
||||
{
|
||||
return _mesa_hash_pointer(key);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
pointer_compare(void *a, void *b)
|
||||
{
|
||||
return a != b;
|
||||
}
|
||||
|
||||
|
||||
struct util_hash_table *
|
||||
util_hash_table_create_ptr_keys(void)
|
||||
{
|
||||
return util_hash_table_create(pointer_hash, pointer_compare);
|
||||
}
|
||||
|
||||
|
||||
static inline struct cso_hash_iter
|
||||
util_hash_table_find_iter(struct util_hash_table *ht,
|
||||
void *key,
|
||||
|
||||
@@ -59,6 +59,12 @@ struct util_hash_table *
|
||||
util_hash_table_create(unsigned (*hash)(void *key),
|
||||
int (*compare)(void *key1, void *key2));
|
||||
|
||||
/**
|
||||
* Create a hash table where the keys are generic pointers.
|
||||
*/
|
||||
struct util_hash_table *
|
||||
util_hash_table_create_ptr_keys(void);
|
||||
|
||||
|
||||
enum pipe_error
|
||||
util_hash_table_set(struct util_hash_table *ht,
|
||||
|
||||
@@ -40,25 +40,13 @@
|
||||
#include "lima_bo.h"
|
||||
#include "lima_util.h"
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
bool lima_bo_table_init(struct lima_screen *screen)
|
||||
{
|
||||
screen->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
||||
screen->bo_handles = util_hash_table_create_ptr_keys();
|
||||
if (!screen->bo_handles)
|
||||
return false;
|
||||
|
||||
screen->bo_flink_names = util_hash_table_create(handle_hash, handle_compare);
|
||||
screen->bo_flink_names = util_hash_table_create_ptr_keys();
|
||||
if (!screen->bo_flink_names)
|
||||
goto err_out0;
|
||||
|
||||
|
||||
@@ -612,18 +612,6 @@ v3d_screen_is_format_supported(struct pipe_screen *pscreen,
|
||||
return true;
|
||||
}
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static const void *
|
||||
v3d_screen_get_compiler_options(struct pipe_screen *pscreen,
|
||||
enum pipe_shader_ir ir, unsigned shader)
|
||||
@@ -686,7 +674,7 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config,
|
||||
}
|
||||
list_inithead(&screen->bo_cache.time_list);
|
||||
(void)mtx_init(&screen->bo_handles_mutex, mtx_plain);
|
||||
screen->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
||||
screen->bo_handles = util_hash_table_create_ptr_keys();
|
||||
|
||||
#if defined(USE_V3D_SIMULATOR)
|
||||
v3d_simulator_init(screen);
|
||||
|
||||
@@ -437,18 +437,6 @@ vc4_screen_query_dmabuf_modifiers(struct pipe_screen *pscreen,
|
||||
}
|
||||
}
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static bool
|
||||
vc4_get_chip_info(struct vc4_screen *screen)
|
||||
{
|
||||
@@ -525,7 +513,7 @@ vc4_screen_create(int fd, struct renderonly *ro)
|
||||
|
||||
list_inithead(&screen->bo_cache.time_list);
|
||||
(void) mtx_init(&screen->bo_handles_mutex, mtx_plain);
|
||||
screen->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
||||
screen->bo_handles = util_hash_table_create_ptr_keys();
|
||||
|
||||
screen->has_control_flow =
|
||||
vc4_has_feature(screen, DRM_VC4_PARAM_SUPPORTS_BRANCHES);
|
||||
|
||||
@@ -46,18 +46,6 @@
|
||||
|
||||
unsigned dec_frame_delta;
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static enum pipe_error hash_table_clear_item_callback(void *key, void *value, void *data)
|
||||
{
|
||||
struct pipe_video_buffer *video_buffer = (struct pipe_video_buffer *)value;
|
||||
@@ -434,7 +422,7 @@ static OMX_ERRORTYPE h264d_prc_allocate_resources(void *ap_obj, OMX_U32 a_pid)
|
||||
|
||||
list_inithead(&priv->codec_data.h264.dpb_list);
|
||||
|
||||
priv->video_buffer_map = util_hash_table_create(handle_hash, handle_compare);
|
||||
priv->video_buffer_map = util_hash_table_create_ptr_keys();
|
||||
|
||||
return OMX_ErrorNone;
|
||||
}
|
||||
|
||||
@@ -302,11 +302,11 @@ vlVaCreateContext(VADriverContextP ctx, VAConfigID config_id, int picture_width,
|
||||
switch (u_reduce_video_profile(context->templat.profile)) {
|
||||
case PIPE_VIDEO_FORMAT_MPEG4_AVC:
|
||||
context->desc.h264enc.rate_ctrl.rate_ctrl_method = config->rc;
|
||||
context->desc.h264enc.frame_idx = util_hash_table_create(handle_hash, handle_compare);
|
||||
context->desc.h264enc.frame_idx = util_hash_table_create_ptr_keys();
|
||||
break;
|
||||
case PIPE_VIDEO_FORMAT_HEVC:
|
||||
context->desc.h265enc.rc.rate_ctrl_method = config->rc;
|
||||
context->desc.h265enc.frame_idx = util_hash_table_create(handle_hash, handle_compare);
|
||||
context->desc.h265enc.frame_idx = util_hash_table_create_ptr_keys();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -63,16 +63,6 @@
|
||||
#define SOS (8 + 4 * 2)
|
||||
#define MAX_MJPEG_SLICE_HEADER_SIZE (SOI + DQT + DHT + DRI + SOF + SOS)
|
||||
|
||||
static inline unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static inline int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static inline enum pipe_video_chroma_format
|
||||
ChromaToPipe(int format)
|
||||
{
|
||||
|
||||
@@ -269,16 +269,6 @@ static bool amdgpu_read_registers(struct radeon_winsys *rws,
|
||||
0xffffffff, 0, out) == 0;
|
||||
}
|
||||
|
||||
static unsigned hash_pointer(void *key)
|
||||
{
|
||||
return _mesa_hash_pointer(key);
|
||||
}
|
||||
|
||||
static int compare_pointers(void *key1, void *key2)
|
||||
{
|
||||
return key1 != key2;
|
||||
}
|
||||
|
||||
static bool amdgpu_winsys_unref(struct radeon_winsys *rws)
|
||||
{
|
||||
struct amdgpu_screen_winsys *sws = amdgpu_screen_winsys(rws);
|
||||
@@ -359,7 +349,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
|
||||
/* Look up the winsys from the dev table. */
|
||||
simple_mtx_lock(&dev_tab_mutex);
|
||||
if (!dev_tab)
|
||||
dev_tab = util_hash_table_create(hash_pointer, compare_pointers);
|
||||
dev_tab = util_hash_table_create_ptr_keys();
|
||||
|
||||
/* Initialize the amdgpu device. This should always return the same pointer
|
||||
* for the same fd. */
|
||||
@@ -463,7 +453,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config,
|
||||
pipe_reference_init(&aws->reference, 1);
|
||||
|
||||
list_inithead(&aws->global_bo_list);
|
||||
aws->bo_export_table = util_hash_table_create(hash_pointer, compare_pointers);
|
||||
aws->bo_export_table = util_hash_table_create_ptr_keys();
|
||||
|
||||
(void) simple_mtx_init(&aws->sws_list_lock, mtx_plain);
|
||||
(void) simple_mtx_init(&aws->global_bo_list_lock, mtx_plain);
|
||||
|
||||
@@ -809,18 +809,6 @@ static bool radeon_winsys_unref(struct radeon_winsys *ws)
|
||||
return destroy;
|
||||
}
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static void radeon_pin_threads_to_L3_cache(struct radeon_winsys *ws,
|
||||
unsigned cache)
|
||||
{
|
||||
@@ -911,9 +899,9 @@ radeon_drm_winsys_create(int fd, const struct pipe_screen_config *config,
|
||||
(void) mtx_init(&ws->hyperz_owner_mutex, mtx_plain);
|
||||
(void) mtx_init(&ws->cmask_owner_mutex, mtx_plain);
|
||||
|
||||
ws->bo_names = util_hash_table_create(handle_hash, handle_compare);
|
||||
ws->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
||||
ws->bo_vas = util_hash_table_create(handle_hash, handle_compare);
|
||||
ws->bo_names = util_hash_table_create_ptr_keys();
|
||||
ws->bo_handles = util_hash_table_create_ptr_keys();
|
||||
ws->bo_vas = util_hash_table_create_ptr_keys();
|
||||
(void) mtx_init(&ws->bo_handles_mutex, mtx_plain);
|
||||
(void) mtx_init(&ws->vm32.mutex, mtx_plain);
|
||||
(void) mtx_init(&ws->vm64.mutex, mtx_plain);
|
||||
|
||||
@@ -691,17 +691,6 @@ vmw_swc_destroy(struct svga_winsys_context *swc)
|
||||
FREE(vswc);
|
||||
}
|
||||
|
||||
static unsigned vmw_hash_ptr(void *p)
|
||||
{
|
||||
return (unsigned)(unsigned long)p;
|
||||
}
|
||||
|
||||
static int vmw_ptr_compare(void *key1, void *key2)
|
||||
{
|
||||
return (key1 == key2) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* vmw_svga_winsys_vgpu10_shader_screate - The winsys shader_crate callback
|
||||
*
|
||||
@@ -844,7 +833,7 @@ vmw_svga_winsys_context_create(struct svga_winsys_screen *sws)
|
||||
if(!vswc->validate)
|
||||
goto out_no_validate;
|
||||
|
||||
vswc->hash = util_hash_table_create(vmw_hash_ptr, vmw_ptr_compare);
|
||||
vswc->hash = util_hash_table_create_ptr_keys();
|
||||
if (!vswc->hash)
|
||||
goto out_no_hash;
|
||||
|
||||
|
||||
@@ -794,18 +794,6 @@ static int virgl_drm_get_caps(struct virgl_winsys *vws,
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||
|
||||
static unsigned handle_hash(void *key)
|
||||
{
|
||||
return PTR_TO_UINT(key);
|
||||
}
|
||||
|
||||
static int handle_compare(void *key1, void *key2)
|
||||
{
|
||||
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
|
||||
}
|
||||
|
||||
static struct pipe_fence_handle *
|
||||
virgl_cs_create_fence(struct virgl_winsys *vws, int fd)
|
||||
{
|
||||
@@ -974,8 +962,8 @@ virgl_drm_winsys_create(int drmFD)
|
||||
qdws);
|
||||
(void) mtx_init(&qdws->mutex, mtx_plain);
|
||||
(void) mtx_init(&qdws->bo_handles_mutex, mtx_plain);
|
||||
qdws->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
||||
qdws->bo_names = util_hash_table_create(handle_hash, handle_compare);
|
||||
qdws->bo_handles = util_hash_table_create_ptr_keys();
|
||||
qdws->bo_names = util_hash_table_create_ptr_keys();
|
||||
qdws->base.destroy = virgl_drm_winsys_destroy;
|
||||
|
||||
qdws->base.transfer_put = virgl_bo_transfer_put;
|
||||
|
||||
Reference in New Issue
Block a user