vulkan: Add common code for VK_EXT_shader_module_identifier.
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17332>
This commit is contained in:
parent
6d66a43a70
commit
0119de08f2
|
@ -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));
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue