From 9eb76ab6386b9b59b01e79fab35a21e26a52ba98 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sat, 18 Feb 2023 23:32:30 +0100 Subject: [PATCH] radv: Add helper to hash stages. Part-of: --- src/amd/vulkan/radv_pipeline_cache.c | 52 ++++++++++++++++------------ src/amd/vulkan/radv_private.h | 3 ++ 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index dba7143546b..d3c125ca8cc 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -147,6 +147,34 @@ radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_stage *stages, _mesa_sha1_final(&ctx, hash); } +void +radv_hash_rt_stages(struct mesa_sha1 *ctx, const VkPipelineShaderStageCreateInfo *stages, + unsigned stage_count) +{ + for (unsigned i = 0; i < stage_count; ++i) { + RADV_FROM_HANDLE(vk_shader_module, module, stages[i].module); + const VkSpecializationInfo *spec_info = stages[i].pSpecializationInfo; + + const VkPipelineShaderStageModuleIdentifierCreateInfoEXT *iinfo = vk_find_struct_const( + stages[i].pNext, PIPELINE_SHADER_STAGE_MODULE_IDENTIFIER_CREATE_INFO_EXT); + + if (module) { + _mesa_sha1_update(ctx, module->sha1, sizeof(module->sha1)); + } else { + assert(iinfo); + assert(iinfo->identifierSize <= VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT); + _mesa_sha1_update(ctx, iinfo->pIdentifier, iinfo->identifierSize); + } + + _mesa_sha1_update(ctx, stages[i].pName, strlen(stages[i].pName)); + if (spec_info && spec_info->mapEntryCount) { + _mesa_sha1_update(ctx, spec_info->pMapEntries, + spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]); + _mesa_sha1_update(ctx, spec_info->pData, spec_info->dataSize); + } + } +} + void radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, const struct radv_pipeline_key *key, uint32_t flags) @@ -160,29 +188,7 @@ radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKH _mesa_sha1_update(&ctx, key, sizeof(*key)); - for (uint32_t i = 0; i < pCreateInfo->stageCount; ++i) { - RADV_FROM_HANDLE(vk_shader_module, module, pCreateInfo->pStages[i].module); - const VkSpecializationInfo *spec_info = pCreateInfo->pStages[i].pSpecializationInfo; - - const VkPipelineShaderStageModuleIdentifierCreateInfoEXT *iinfo = - vk_find_struct_const(pCreateInfo->pStages[i].pNext, - PIPELINE_SHADER_STAGE_MODULE_IDENTIFIER_CREATE_INFO_EXT); - - if (module) { - _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1)); - } else { - assert(iinfo); - assert(iinfo->identifierSize <= VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT); - _mesa_sha1_update(&ctx, iinfo->pIdentifier, iinfo->identifierSize); - } - - _mesa_sha1_update(&ctx, pCreateInfo->pStages[i].pName, strlen(pCreateInfo->pStages[i].pName)); - if (spec_info && spec_info->mapEntryCount) { - _mesa_sha1_update(&ctx, spec_info->pMapEntries, - spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]); - _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize); - } - } + radv_hash_rt_stages(&ctx, pCreateInfo->pStages, pCreateInfo->stageCount); for (uint32_t i = 0; i < pCreateInfo->groupCount; i++) { _mesa_sha1_update(&ctx, &pCreateInfo->pGroups[i].type, diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index a11cc80af01..c0a2e22b856 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -1992,6 +1992,9 @@ void radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_stage *st uint32_t stage_count, const struct radv_pipeline_layout *layout, const struct radv_pipeline_key *key, uint32_t flags); +void radv_hash_rt_stages(struct mesa_sha1 *ctx, const VkPipelineShaderStageCreateInfo *stages, + unsigned stage_count); + void radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, const struct radv_pipeline_key *key, uint32_t flags);