radv: add radv_hash_shaders() helper
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 14 Oct 2017 01:42:40 +0000 (12:42 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 17 Oct 2017 22:19:35 +0000 (09:19 +1100)
This will be used to create a hash of the combined shaders in the
pipeline.

Signed-off-by: Timothy Arceri <tarceri@itsqueeze.com>
Acked-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_pipeline_cache.c
src/amd/vulkan/radv_private.h

index d721f8b9f9e233dd3e80b67bab4058d8d21b3237..7924be0c90955d3c42b17db9d4222cdeeef2c8a2 100644 (file)
@@ -122,6 +122,39 @@ radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
        _mesa_sha1_final(&ctx, hash);
 }
 
+void
+radv_hash_shaders(unsigned char *hash,
+                 const VkPipelineShaderStageCreateInfo **stages,
+                 const struct radv_pipeline_layout *layout,
+                 const struct ac_shader_variant_key *keys,
+                 uint32_t flags)
+{
+       struct mesa_sha1 ctx;
+
+       _mesa_sha1_init(&ctx);
+       if (keys)
+               _mesa_sha1_update(&ctx, keys, sizeof(*keys) * MESA_SHADER_STAGES);
+       if (layout)
+               _mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
+
+       for (int i = 0; i < MESA_SHADER_STAGES; ++i) {
+               if (stages[i]) {
+                       RADV_FROM_HANDLE(radv_shader_module, module, stages[i]->module);
+                       const VkSpecializationInfo *spec_info = stages[i]->pSpecializationInfo;
+
+                       _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
+                       _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName));
+                       if (spec_info) {
+                               _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, &flags, 4);
+       _mesa_sha1_final(&ctx, hash);
+}
+
 
 static struct cache_entry *
 radv_pipeline_cache_search_unlocked(struct radv_pipeline_cache *cache,
index 5be070634072fc9ab2df3dda9a4804c6fc659fa8..3fb182b4e3b316f883d4394c6dd2fb3e0c781983 100644 (file)
@@ -986,6 +986,13 @@ radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
                 const struct ac_shader_variant_key *key,
                 uint32_t flags);
 
+void
+radv_hash_shaders(unsigned char *hash,
+                 const VkPipelineShaderStageCreateInfo **stages,
+                 const struct radv_pipeline_layout *layout,
+                 const struct ac_shader_variant_key *keys,
+                 uint32_t flags);
+
 static inline gl_shader_stage
 vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
 {