Mesa (main): vulkan: Add common code for VK_EXT_shader_module_identifier.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jul 6 16:56:45 UTC 2022
Module: Mesa
Branch: main
Commit: 0119de08f25dbb85ca0941619428762d02435ec9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0119de08f25dbb85ca0941619428762d02435ec9
Author: Hans-Kristian Arntzen <post at arntzen-software.no>
Date: Fri Jul 1 11:44:55 2022 +0200
vulkan: Add common code for VK_EXT_shader_module_identifier.
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17332>
---
src/vulkan/runtime/vk_pipeline.c | 16 ++++++++++++----
src/vulkan/runtime/vk_shader_module.c | 22 ++++++++++++++++++++++
src/vulkan/runtime/vk_shader_module.h | 2 ++
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/src/vulkan/runtime/vk_pipeline.c b/src/vulkan/runtime/vk_pipeline.c
index 76d5d25aa91..ecef45f3c75 100644
--- a/src/vulkan/runtime/vk_pipeline.c
+++ b/src/vulkan/runtime/vk_pipeline.c
@@ -117,19 +117,27 @@ vk_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *info,
return;
}
+ const VkShaderModuleCreateInfo *minfo =
+ vk_find_struct_const(info->pNext, SHADER_MODULE_CREATE_INFO);
+ const VkPipelineShaderStageModuleIdentifierCreateInfoEXT *iinfo =
+ vk_find_struct_const(info->pNext, PIPELINE_SHADER_STAGE_MODULE_IDENTIFIER_CREATE_INFO_EXT);
+
struct mesa_sha1 ctx;
_mesa_sha1_init(&ctx);
if (module) {
_mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
- } else {
- const VkShaderModuleCreateInfo *minfo =
- vk_find_struct_const(info->pNext, SHADER_MODULE_CREATE_INFO);
+ } else if (minfo) {
unsigned char spirv_sha1[SHA1_DIGEST_LENGTH];
- assert(minfo);
_mesa_sha1_compute(minfo->pCode, minfo->codeSize, spirv_sha1);
_mesa_sha1_update(&ctx, spirv_sha1, sizeof(spirv_sha1));
+ } else {
+ /* It is legal to pass in arbitrary identifiers as long as they don't exceed
+ * the limit. Shaders with bogus identifiers are more or less guaranteed to fail. */
+ assert(iinfo);
+ assert(iinfo->identifierSize <= VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT);
+ _mesa_sha1_update(&ctx, iinfo->pIdentifier, iinfo->identifierSize);
}
_mesa_sha1_update(&ctx, info->pName, strlen(info->pName));
diff --git a/src/vulkan/runtime/vk_shader_module.c b/src/vulkan/runtime/vk_shader_module.c
index e50d26550be..7519d52b5fc 100644
--- a/src/vulkan/runtime/vk_shader_module.c
+++ b/src/vulkan/runtime/vk_shader_module.c
@@ -60,6 +60,28 @@ vk_common_CreateShaderModule(VkDevice _device,
return VK_SUCCESS;
}
+const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE] = "MESA-SHA1";
+
+VKAPI_ATTR void VKAPI_CALL
+vk_common_GetShaderModuleIdentifierEXT(VkDevice _device,
+ VkShaderModule _module,
+ VkShaderModuleIdentifierEXT *pIdentifier)
+{
+ VK_FROM_HANDLE(vk_shader_module, module, _module);
+ memcpy(pIdentifier->identifier, module->sha1, sizeof(module->sha1));
+ pIdentifier->identifierSize = sizeof(module->sha1);
+}
+
+VKAPI_ATTR void VKAPI_CALL
+vk_common_GetShaderModuleCreateInfoIdentifierEXT(VkDevice _device,
+ const VkShaderModuleCreateInfo *pCreateInfo,
+ VkShaderModuleIdentifierEXT *pIdentifier)
+{
+ _mesa_sha1_compute(pCreateInfo->pCode, pCreateInfo->codeSize,
+ pIdentifier->identifier);
+ pIdentifier->identifierSize = SHA1_DIGEST_LENGTH;
+}
+
VKAPI_ATTR void VKAPI_CALL
vk_common_DestroyShaderModule(VkDevice _device,
VkShaderModule _module,
diff --git a/src/vulkan/runtime/vk_shader_module.h b/src/vulkan/runtime/vk_shader_module.h
index fbd584d19d7..430abaf9aec 100644
--- a/src/vulkan/runtime/vk_shader_module.h
+++ b/src/vulkan/runtime/vk_shader_module.h
@@ -45,6 +45,8 @@ struct vk_shader_module {
char data[0];
};
+extern const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE];
+
VK_DEFINE_NONDISP_HANDLE_CASTS(vk_shader_module, base, VkShaderModule,
VK_OBJECT_TYPE_SHADER_MODULE)
More information about the mesa-commit
mailing list