nvk: add hashing for shaders

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25550>
This commit is contained in:
Thomas H.P. Andersen 2023-10-04 20:38:01 +02:00 committed by Marge Bot
parent 1cb6b4f82d
commit 3e13d0fcd9
4 changed files with 53 additions and 0 deletions

View file

@ -188,6 +188,10 @@ nvk_compute_pipeline_create(struct nvk_device *dev,
nvk_lower_nir(dev, nir, &robustness, false, pipeline_layout, shader);
unsigned char sha1[SHA1_DIGEST_LENGTH];
nvk_hash_shader(sha1, &pCreateInfo->stage, &robustness, false,
pipeline_layout, NULL);
result = nvk_compile_nir(pdev, nir, pipeline_flags, &robustness, NULL,
shader);
ralloc_free(nir);

View file

@ -233,6 +233,11 @@ nvk_graphics_pipeline_create(struct nvk_device *dev,
fs_key = &fs_key_tmp;
}
unsigned char sha1[SHA1_DIGEST_LENGTH];
nvk_hash_shader(sha1, sinfo, &robustness[stage],
state.rp->view_mask != 0,
pipeline_layout, fs_key);
result = nvk_compile_nir(pdev, nir[stage], pipeline_flags,
&robustness[stage], fs_key,
&pipeline->base.shaders[stage]);

View file

@ -514,3 +514,39 @@ nvk_shader_finish(struct nvk_device *dev, struct nvk_shader *shader)
if (shader->nak)
nak_shader_bin_destroy(shader->nak);
}
void
nvk_hash_shader(unsigned char *hash,
const VkPipelineShaderStageCreateInfo *sinfo,
const struct vk_pipeline_robustness_state *rs,
bool is_multiview,
const struct vk_pipeline_layout *layout,
const struct nak_fs_key *fs_key)
{
struct mesa_sha1 ctx;
_mesa_sha1_init(&ctx);
unsigned char stage_sha1[SHA1_DIGEST_LENGTH];
vk_pipeline_hash_shader_stage(sinfo, rs, stage_sha1);
_mesa_sha1_update(&ctx, stage_sha1, sizeof(stage_sha1));
_mesa_sha1_update(&ctx, &is_multiview, sizeof(is_multiview));
if (layout) {
_mesa_sha1_update(&ctx, &layout->create_flags,
sizeof(layout->create_flags));
_mesa_sha1_update(&ctx, &layout->set_count, sizeof(layout->set_count));
for (int i = 0; i < layout->set_count; i++) {
struct nvk_descriptor_set_layout *set =
vk_to_nvk_descriptor_set_layout(layout->set_layouts[i]);
_mesa_sha1_update(&ctx, &set->sha1, sizeof(set->sha1));
}
}
if(fs_key)
_mesa_sha1_update(&ctx, fs_key, sizeof(*fs_key));
_mesa_sha1_final(&ctx, hash);
}

View file

@ -130,6 +130,14 @@ nvk_shader_upload(struct nvk_device *dev, struct nvk_shader *shader);
void
nvk_shader_finish(struct nvk_device *dev, struct nvk_shader *shader);
void
nvk_hash_shader(unsigned char *hash,
const VkPipelineShaderStageCreateInfo *sinfo,
const struct vk_pipeline_robustness_state *rstate,
bool is_multiview,
const struct vk_pipeline_layout *layout,
const struct nak_fs_key *fs_key);
/* Codegen wrappers.
*
* TODO: Delete these once NAK supports everything.