[Mesa-dev] [PATCH 4/9] radv: add radv_hash_shaders() helper

Timothy Arceri tarceri at itsqueeze.com
Sat Oct 14 23:36:42 UTC 2017


From: Bas Nieuwenhuizen <basni at google.com>

This will be used to create a hash of the combined shaders in the
pipeline.

Signed-off-by: Timothy Arceri <tarceri at itsqueeze.com>
---
 src/amd/vulkan/radv_pipeline_cache.c | 33 +++++++++++++++++++++++++++++++++
 src/amd/vulkan/radv_private.h        |  7 +++++++
 2 files changed, 40 insertions(+)

diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index 15b159a698..feffb4e77b 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -115,20 +115,53 @@ radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
 		_mesa_sha1_update(&ctx, layout->sha1, sizeof(layout->sha1));
 	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);
 }
 
+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,
 				    const unsigned char *sha1)
 {
 	const uint32_t mask = cache->table_size - 1;
 	const uint32_t start = (*(uint32_t *) sha1);
 
 	if (cache->table_size == 0)
 		return NULL;
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index b0cb8679fd..110d141085 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -980,20 +980,27 @@ struct ac_shader_variant_key;
 #define RADV_HASH_SHADER_SISCHED             (1 << 1)
 #define RADV_HASH_SHADER_UNSAFE_MATH         (1 << 2)
 void
 radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
 		 const char *entrypoint,
 		 const VkSpecializationInfo *spec_info,
 		 const struct radv_pipeline_layout *layout,
 		 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)
 {
 	assert(__builtin_popcount(vk_stage) == 1);
 	return ffs(vk_stage) - 1;
 }
 
 static inline VkShaderStageFlagBits
 mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
 {
-- 
2.13.6



More information about the mesa-dev mailing list