From 9b3679aff2adfb4097c4eacd853905bc049c8544 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 20 Mar 2023 14:34:35 +0100 Subject: [PATCH] radv: implement radv_shader_create_cached() This function takes a radv_shader_binary and writes it to the disk cache before creating and returning a radv_shader cache entry. The key of the cache entry is the full SHA1 hash of the binary. This way, we will be able to deduplicate identical shaders. Part-of: --- src/amd/vulkan/radv_pipeline_cache.c | 19 +++++++++++++++++++ src/amd/vulkan/radv_shader.h | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index a220075..97f7130 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -279,6 +279,25 @@ radv_shader_serialize(struct vk_pipeline_cache_object *object, struct blob *blob return true; } +struct radv_shader * +radv_shader_create_cached(struct radv_device *device, struct vk_pipeline_cache *cache, + const struct radv_shader_binary *binary) +{ + if (radv_is_cache_disabled(device)) + return radv_shader_create(device, binary); + + uint8_t hash[SHA1_DIGEST_LENGTH]; + _mesa_sha1_compute(binary, binary->total_size, hash); + + /* TODO: Skip disk-cache for meta-shaders because they are stored in a different cache file */ + + struct vk_pipeline_cache_object *shader_obj; + shader_obj = vk_pipeline_cache_create_and_insert_object(cache, hash, SHA1_DIGEST_LENGTH, binary, + binary->total_size, &radv_shader_ops); + + return shader_obj ? container_of(shader_obj, struct radv_shader, base) : NULL; +} + const struct vk_pipeline_cache_object_ops radv_shader_ops = { .serialize = radv_shader_serialize, .deserialize = radv_shader_deserialize, diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index 1b5b2e9..b40e9c6 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -572,6 +572,11 @@ struct radv_shader_args; struct radv_shader *radv_shader_create(struct radv_device *device, const struct radv_shader_binary *binary); + +struct radv_shader *radv_shader_create_cached(struct radv_device *device, + struct vk_pipeline_cache *cache, + const struct radv_shader_binary *binary); + struct radv_shader *radv_shader_nir_to_asm( struct radv_device *device, struct radv_pipeline_stage *stage, struct nir_shader *const *shaders, int shader_count, const struct radv_pipeline_key *key, bool keep_shader_info, bool keep_statistic_info, -- 2.7.4