vulkan: Migrate shader module hash to BLAKE3.

Shaders are the largest thing we hash now, so they benefit from a faster
hash.

Change the field name from `sha1` to `hash` to avoid tying the definition
to a particular algorithm. This doubles down as a precaution against
callers still assuming a 20-byte hash (in which case the compilation will
error out).

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22571>
This commit is contained in:
Tatsuyuki Ishi
2023-04-19 14:43:47 +09:00
committed by Marge Bot
parent e5173e62d7
commit b69a1b4153
4 changed files with 15 additions and 14 deletions

View File

@@ -1099,7 +1099,7 @@ radv_copy_shader_stage_create_info(struct radv_device *device, uint32_t stageCou
vk_object_base_init(&device->vk, &new_module->base, VK_OBJECT_TYPE_SHADER_MODULE);
new_module->nir = NULL;
memcpy(new_module->sha1, module->sha1, sizeof(module->sha1));
memcpy(new_module->hash, module->hash, sizeof(module->hash));
new_module->size = module->size;
memcpy(new_module->data, module->data, module->size);

View File

@@ -32,6 +32,7 @@
#include "nir_serialize.h"
#include "util/mesa-sha1.h"
#include "util/mesa-blake3.h"
bool
vk_pipeline_shader_stage_is_null(const VkPipelineShaderStageCreateInfo *info)
@@ -176,12 +177,12 @@ vk_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *info,
_mesa_sha1_update(&ctx, &info->stage, sizeof(info->stage));
if (module) {
_mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
_mesa_sha1_update(&ctx, module->hash, sizeof(module->hash));
} else if (minfo) {
unsigned char spirv_sha1[SHA1_DIGEST_LENGTH];
blake3_hash spirv_hash;
_mesa_sha1_compute(minfo->pCode, minfo->codeSize, spirv_sha1);
_mesa_sha1_update(&ctx, spirv_sha1, sizeof(spirv_sha1));
_mesa_blake3_compute(minfo->pCode, minfo->codeSize, spirv_hash);
_mesa_sha1_update(&ctx, spirv_hash, sizeof(spirv_hash));
} 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. */

View File

@@ -23,7 +23,6 @@
#include "vk_shader_module.h"
#include "util/mesa-sha1.h"
#include "vk_alloc.h"
#include "vk_common_entrypoints.h"
#include "vk_device.h"
@@ -43,7 +42,7 @@ void vk_shader_module_init(struct vk_device *device,
module->size = create_info->codeSize;
memcpy(module->data, create_info->pCode, module->size);
_mesa_sha1_compute(module->data, module->size, module->sha1);
_mesa_blake3_compute(module->data, module->size, module->hash);
}
VKAPI_ATTR VkResult VKAPI_CALL
@@ -71,7 +70,7 @@ vk_common_CreateShaderModule(VkDevice _device,
return VK_SUCCESS;
}
const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE] = "MESA-SHA1";
const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE] = "MESA-BLAKE3";
VKAPI_ATTR void VKAPI_CALL
vk_common_GetShaderModuleIdentifierEXT(VkDevice _device,
@@ -79,8 +78,8 @@ vk_common_GetShaderModuleIdentifierEXT(VkDevice _device,
VkShaderModuleIdentifierEXT *pIdentifier)
{
VK_FROM_HANDLE(vk_shader_module, module, _module);
memcpy(pIdentifier->identifier, module->sha1, sizeof(module->sha1));
pIdentifier->identifierSize = sizeof(module->sha1);
memcpy(pIdentifier->identifier, module->hash, sizeof(module->hash));
pIdentifier->identifierSize = sizeof(module->hash);
}
VKAPI_ATTR void VKAPI_CALL
@@ -88,9 +87,9 @@ vk_common_GetShaderModuleCreateInfoIdentifierEXT(VkDevice _device,
const VkShaderModuleCreateInfo *pCreateInfo,
VkShaderModuleIdentifierEXT *pIdentifier)
{
_mesa_sha1_compute(pCreateInfo->pCode, pCreateInfo->codeSize,
pIdentifier->identifier);
pIdentifier->identifierSize = SHA1_DIGEST_LENGTH;
_mesa_blake3_compute(pCreateInfo->pCode, pCreateInfo->codeSize,
pIdentifier->identifier);
pIdentifier->identifierSize = sizeof(blake3_hash);
}
VKAPI_ATTR void VKAPI_CALL

View File

@@ -26,6 +26,7 @@
#include <vulkan/vulkan_core.h>
#include "util/mesa-blake3.h"
#include "compiler/shader_enums.h"
#include "vk_object.h"
@@ -40,7 +41,7 @@ struct spirv_to_nir_options;
struct vk_shader_module {
struct vk_object_base base;
struct nir_shader *nir;
unsigned char sha1[20];
blake3_hash hash;
uint32_t size;
char data[0];
};