From ced950e42f4a95ef410e63c2d26a2119e0c3c40b Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 22 Sep 2021 10:31:19 +0200 Subject: [PATCH] radv: store the post-processed shader binary config to the cache This will allow us to reduce the size of radv_shader_info which is stored in the cache entry. Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/amd/vulkan/radv_pipeline_cache.c | 2 +- src/amd/vulkan/radv_shader.c | 15 ++++++++++++--- src/amd/vulkan/radv_shader.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index 7cbd4e10678..709ecbe2294 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -353,7 +353,7 @@ radv_create_shader_variants_from_pipeline_cache( memcpy(binary, p, entry->binary_sizes[i]); p += entry->binary_sizes[i]; - entry->variants[i] = radv_shader_variant_create(device, binary, false); + entry->variants[i] = radv_shader_variant_create(device, binary, false, true); free(binary); } else if (entry->binary_sizes[i]) { p += entry->binary_sizes[i]; diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c index 63bf77f8e76..815e847e953 100644 --- a/src/amd/vulkan/radv_shader.c +++ b/src/amd/vulkan/radv_shader.c @@ -1378,7 +1378,7 @@ radv_postprocess_config(const struct radv_device *device, const struct ac_shader struct radv_shader_variant * radv_shader_variant_create(struct radv_device *device, const struct radv_shader_binary *binary, - bool keep_shader_info) + bool keep_shader_info, bool from_cache) { struct ac_shader_config config = {0}; struct ac_rtld_binary rtld_binary = {0}; @@ -1452,7 +1452,13 @@ radv_shader_variant_create(struct radv_device *device, const struct radv_shader_ } variant->info = binary->info; - radv_postprocess_config(device, &config, &binary->info, binary->stage, &variant->config); + + if (from_cache) { + /* Copy the shader binary configuration from the cache. */ + memcpy(&variant->config, &binary->config, sizeof(variant->config)); + } else { + radv_postprocess_config(device, &config, &binary->info, binary->stage, &variant->config); + } void *dest_ptr = radv_alloc_shader_memory(device, variant); if (!dest_ptr) { @@ -1617,7 +1623,7 @@ shader_variant_compile(struct radv_device *device, struct vk_shader_module *modu binary->info = *info; struct radv_shader_variant *variant = - radv_shader_variant_create(device, binary, keep_shader_info); + radv_shader_variant_create(device, binary, keep_shader_info, false); if (!variant) { free(binary); return NULL; @@ -1646,6 +1652,9 @@ shader_variant_compile(struct radv_device *device, struct vk_shader_module *modu } } + /* Copy the shader binary configuration to store it in the cache. */ + memcpy(&binary->config, &variant->config, sizeof(binary->config)); + if (binary_out) *binary_out = binary; else diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h index 2f232ad854e..d6c9f9dc197 100644 --- a/src/amd/vulkan/radv_shader.h +++ b/src/amd/vulkan/radv_shader.h @@ -434,7 +434,7 @@ VkResult radv_create_shaders(struct radv_pipeline *pipeline, struct radv_shader_variant *radv_shader_variant_create(struct radv_device *device, const struct radv_shader_binary *binary, - bool keep_shader_info); + bool keep_shader_info, bool from_cache); struct radv_shader_variant *radv_shader_variant_compile( struct radv_device *device, struct vk_shader_module *module, struct nir_shader *const *shaders, int shader_count, struct radv_pipeline_layout *layout, const struct radv_pipeline_key *key,