Mesa (master): gallium/hash_table: consolidate hash tables with pointer keys
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Feb 26 21:14:03 UTC 2020
Module: Mesa
Branch: master
Commit: a01a875081bd52bc1c3c142a60af678171ce6c33
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a01a875081bd52bc1c3c142a60af678171ce6c33
Author: Marek Olšák <marek.olsak at amd.com>
Date: Wed Feb 5 14:10:48 2020 -0500
gallium/hash_table: consolidate hash tables with pointer keys
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3722>
---
src/gallium/auxiliary/util/u_debug_flush.c | 15 +--------------
src/gallium/auxiliary/util/u_debug_refcnt.c | 21 +--------------------
src/gallium/auxiliary/util/u_debug_stack.c | 17 +----------------
src/gallium/auxiliary/util/u_debug_symbol.c | 17 +----------------
src/gallium/auxiliary/util/u_hash_table.c | 22 ++++++++++++++++++++++
src/gallium/auxiliary/util/u_hash_table.h | 6 ++++++
src/gallium/drivers/lima/lima_bo.c | 16 ++--------------
src/gallium/drivers/v3d/v3d_screen.c | 14 +-------------
src/gallium/drivers/vc4/vc4_screen.c | 14 +-------------
src/gallium/state_trackers/omx/tizonia/h264dprc.c | 14 +-------------
src/gallium/state_trackers/va/context.c | 4 ++--
src/gallium/state_trackers/va/va_private.h | 10 ----------
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 14 ++------------
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 18 +++---------------
src/gallium/winsys/svga/drm/vmw_context.c | 13 +------------
src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 16 ++--------------
16 files changed, 47 insertions(+), 184 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_debug_flush.c b/src/gallium/auxiliary/util/u_debug_flush.c
index 62cbd1f61bd..ef1b0557b8b 100644
--- a/src/gallium/auxiliary/util/u_debug_flush.c
+++ b/src/gallium/auxiliary/util/u_debug_flush.c
@@ -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;
diff --git a/src/gallium/auxiliary/util/u_debug_refcnt.c b/src/gallium/auxiliary/util/u_debug_refcnt.c
index ec95f87260c..c1560fb7dc0 100644
--- a/src/gallium/auxiliary/util/u_debug_refcnt.c
+++ b/src/gallium/auxiliary/util/u_debug_refcnt.c
@@ -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) {
diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c
index 235e116671b..585fdcee8bc 100644
--- a/src/gallium/auxiliary/util/u_debug_stack.c
+++ b/src/gallium/auxiliary/util/u_debug_stack.c
@@ -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)
{
diff --git a/src/gallium/auxiliary/util/u_debug_symbol.c b/src/gallium/auxiliary/util/u_debug_symbol.c
index 4ea6c8d07b0..20581c9c4d3 100644
--- a/src/gallium/auxiliary/util/u_debug_symbol.c
+++ b/src/gallium/auxiliary/util/u_debug_symbol.c
@@ -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)
{
diff --git a/src/gallium/auxiliary/util/u_hash_table.c b/src/gallium/auxiliary/util/u_hash_table.c
index 00b9154d16a..0a2863dcc0c 100644
--- a/src/gallium/auxiliary/util/u_hash_table.c
+++ b/src/gallium/auxiliary/util/u_hash_table.c
@@ -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,
diff --git a/src/gallium/auxiliary/util/u_hash_table.h b/src/gallium/auxiliary/util/u_hash_table.h
index ac00db8a00b..cf0c58cd287 100644
--- a/src/gallium/auxiliary/util/u_hash_table.h
+++ b/src/gallium/auxiliary/util/u_hash_table.h
@@ -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,
diff --git a/src/gallium/drivers/lima/lima_bo.c b/src/gallium/drivers/lima/lima_bo.c
index fb1f1e73619..17197c48279 100644
--- a/src/gallium/drivers/lima/lima_bo.c
+++ b/src/gallium/drivers/lima/lima_bo.c
@@ -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;
diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c
index a449e458035..8031ea727e0 100644
--- a/src/gallium/drivers/v3d/v3d_screen.c
+++ b/src/gallium/drivers/v3d/v3d_screen.c
@@ -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);
diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
index 2be0b6c3fbe..3b14681c42d 100644
--- a/src/gallium/drivers/vc4/vc4_screen.c
+++ b/src/gallium/drivers/vc4/vc4_screen.c
@@ -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);
diff --git a/src/gallium/state_trackers/omx/tizonia/h264dprc.c b/src/gallium/state_trackers/omx/tizonia/h264dprc.c
index cac62a82e72..5678bd7ac8c 100644
--- a/src/gallium/state_trackers/omx/tizonia/h264dprc.c
+++ b/src/gallium/state_trackers/omx/tizonia/h264dprc.c
@@ -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;
}
diff --git a/src/gallium/state_trackers/va/context.c b/src/gallium/state_trackers/va/context.c
index 2cb3a6c9268..70d4bac63a7 100644
--- a/src/gallium/state_trackers/va/context.c
+++ b/src/gallium/state_trackers/va/context.c
@@ -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;
diff --git a/src/gallium/state_trackers/va/va_private.h b/src/gallium/state_trackers/va/va_private.h
index bed1189b9d1..aa3b74c0b6e 100644
--- a/src/gallium/state_trackers/va/va_private.h
+++ b/src/gallium/state_trackers/va/va_private.h
@@ -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)
{
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
index fdabb8b6228..0b28d0a4269 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
@@ -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);
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 31a6758fe90..0ea43c1959b 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -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);
diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c
index 6ab43cb998c..2950d719629 100644
--- a/src/gallium/winsys/svga/drm/vmw_context.c
+++ b/src/gallium/winsys/svga/drm/vmw_context.c
@@ -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;
diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
index 32dbb4f7d86..53d8fdf3eda 100644
--- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
+++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c
@@ -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;
More information about the mesa-commit
mailing list