From 680c9129777e66472e5265119ada5ffa4a1c3a95 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Fri, 2 Feb 2024 12:01:31 -0800 Subject: [PATCH] venus: extract cache hash/equals functions into common drop the unnecessary casting in the equals function as well Signed-off-by: Juston Li Part-of: --- src/virtio/vulkan/vn_common.h | 12 ++++++++++++ src/virtio/vulkan/vn_image.c | 17 ++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/virtio/vulkan/vn_common.h b/src/virtio/vulkan/vn_common.h index 7456e260b16..4d21d923cf6 100644 --- a/src/virtio/vulkan/vn_common.h +++ b/src/virtio/vulkan/vn_common.h @@ -535,4 +535,16 @@ vn_tls_get_ring(struct vn_instance *instance); void vn_tls_destroy_ring(struct vn_tls_ring *tls_ring); +static inline uint32_t +vn_cache_key_hash_function(const void *key) +{ + return _mesa_hash_data(key, SHA1_DIGEST_LENGTH); +} + +static inline bool +vn_cache_key_equal_function(const void *key1, const void *key2) +{ + return memcmp(key1, key2, SHA1_DIGEST_LENGTH) == 0; +} + #endif /* VN_COMMON_H */ diff --git a/src/virtio/vulkan/vn_image.c b/src/virtio/vulkan/vn_image.c index db3e27b3f81..033a7d535fb 100644 --- a/src/virtio/vulkan/vn_image.c +++ b/src/virtio/vulkan/vn_image.c @@ -46,19 +46,6 @@ vn_image_cache_debug_dump(struct vn_image_reqs_cache *cache) vn_log(NULL, " skip %u\n", cache->debug.cache_skip_count); } -static uint32_t -vn_image_cache_key_hash_function(const void *key) -{ - return _mesa_hash_data(key, SHA1_DIGEST_LENGTH); -} - -static bool -vn_image_cache_key_equal_function(const void *void_a, const void *void_b) -{ - const struct vn_image_reqs_cache_entry *a = void_a, *b = void_b; - return memcmp(a, b, SHA1_DIGEST_LENGTH) == 0; -} - static bool vn_image_get_image_reqs_key(struct vn_device *dev, const VkImageCreateInfo *create_info, @@ -160,8 +147,8 @@ vn_image_reqs_cache_init(struct vn_device *dev) if (VN_PERF(NO_ASYNC_IMAGE_CREATE)) return; - cache->ht = _mesa_hash_table_create(NULL, vn_image_cache_key_hash_function, - vn_image_cache_key_equal_function); + cache->ht = _mesa_hash_table_create(NULL, vn_cache_key_hash_function, + vn_cache_key_equal_function); if (!cache->ht) return;