Module: Mesa Branch: main Commit: 3e13d0fcd9ff2e2a7a5f0b95a88724db2925cc96 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=3e13d0fcd9ff2e2a7a5f0b95a88724db2925cc96
Author: Thomas H.P. Andersen <pho...@gmail.com> Date: Wed Oct 4 20:38:01 2023 +0200 nvk: add hashing for shaders Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25550> --- src/nouveau/vulkan/nvk_compute_pipeline.c | 4 ++++ src/nouveau/vulkan/nvk_graphics_pipeline.c | 5 +++++ src/nouveau/vulkan/nvk_shader.c | 36 ++++++++++++++++++++++++++++++ src/nouveau/vulkan/nvk_shader.h | 8 +++++++ 4 files changed, 53 insertions(+) diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c b/src/nouveau/vulkan/nvk_compute_pipeline.c index a74b3765aa1..1b4fc88a423 100644 --- a/src/nouveau/vulkan/nvk_compute_pipeline.c +++ b/src/nouveau/vulkan/nvk_compute_pipeline.c @@ -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); diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c b/src/nouveau/vulkan/nvk_graphics_pipeline.c index 65795410865..bdad7fee6ef 100644 --- a/src/nouveau/vulkan/nvk_graphics_pipeline.c +++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c @@ -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]); diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index f37bf1f4478..850dcccf30b 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -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); +} diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h index dea5cdf0bd6..6e16e142d20 100644 --- a/src/nouveau/vulkan/nvk_shader.h +++ b/src/nouveau/vulkan/nvk_shader.h @@ -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.