diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index 9e403a53ec7..473c5887459 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -4086,6 +4086,25 @@ radv_lower_fs_output(nir_shader *nir, const struct radv_pipeline_key *pipeline_k return progress; } +static void +radv_pipeline_hash_shader(const unsigned char *spirv_sha1, const uint32_t spirv_sha1_size, + const char *entrypoint, gl_shader_stage stage, + const VkSpecializationInfo *spec_info, unsigned char *sha1_out) +{ + struct mesa_sha1 ctx; + _mesa_sha1_init(&ctx); + + _mesa_sha1_update(&ctx, spirv_sha1, spirv_sha1_size); + _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint)); + if (spec_info) { + _mesa_sha1_update(&ctx, spec_info->pMapEntries, + spec_info->mapEntryCount * sizeof(*spec_info->pMapEntries)); + _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize); + } + + _mesa_sha1_final(&ctx, sha1_out); +} + VkResult radv_create_shaders(struct radv_pipeline *pipeline, struct radv_pipeline_layout *pipeline_layout, struct radv_device *device, struct radv_pipeline_cache *cache, @@ -4134,6 +4153,10 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_pipeline_layout stages[stage].module->sha1); } + radv_pipeline_hash_shader(stages[stage].module->sha1, sizeof(stages[stage].module->sha1), + stages[stage].entrypoint, stage, stages[stage].spec_info, + stages[stage].shader_sha1); + pipeline->active_stages |= sinfo->stage; } @@ -4161,7 +4184,7 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_pipeline_layout if (custom_hash) memcpy(hash, custom_hash, 20); else { - radv_hash_shaders(hash, pStages, stageCount, pipeline_layout, pipeline_key, + radv_hash_shaders(hash, stages, pipeline_layout, pipeline_key, radv_get_hash_flags(device, keep_statistic_info)); } diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c index d3ab551f668..238f6a3ea1d 100644 --- a/src/amd/vulkan/radv_pipeline_cache.c +++ b/src/amd/vulkan/radv_pipeline_cache.c @@ -118,9 +118,9 @@ entry_size(struct cache_entry *entry) } void -radv_hash_shaders(unsigned char *hash, const VkPipelineShaderStageCreateInfo *stages, - uint32_t stageCount, const struct radv_pipeline_layout *layout, - const struct radv_pipeline_key *key, uint32_t flags) +radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_stage *stages, + const struct radv_pipeline_layout *layout, const struct radv_pipeline_key *key, + uint32_t flags) { struct mesa_sha1 ctx; @@ -130,17 +130,11 @@ radv_hash_shaders(unsigned char *hash, const VkPipelineShaderStageCreateInfo *st if (layout) _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1)); - for (uint32_t i = 0; i < stageCount; i++) { - RADV_FROM_HANDLE(vk_shader_module, module, stages[i].module); - const VkSpecializationInfo *spec_info = stages[i].pSpecializationInfo; + for (unsigned s = 0; s < MESA_VULKAN_SHADER_STAGES; s++) { + if (!stages[s].entrypoint) + continue; - _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1)); - _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); - } + _mesa_sha1_update(&ctx, stages[s].shader_sha1, sizeof(stages[s].shader_sha1)); } _mesa_sha1_update(&ctx, &flags, 4); _mesa_sha1_final(&ctx, hash); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index f774ac951c0..c28aa186847 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -1746,8 +1746,8 @@ struct radv_event { struct radv_pipeline_key; -void radv_hash_shaders(unsigned char *hash, const VkPipelineShaderStageCreateInfo *stages, - uint32_t stageCount, const struct radv_pipeline_layout *layout, +void radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_stage *stages, + const struct radv_pipeline_layout *layout, const struct radv_pipeline_key *key, uint32_t flags); void radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, @@ -1932,6 +1932,8 @@ struct radv_pipeline_stage { const char *entrypoint; const VkSpecializationInfo *spec_info; + unsigned char shader_sha1[20]; + nir_shader *nir; struct radv_shader_info info;