From: Faith Ekstrand Date: Wed, 27 Sep 2023 20:10:22 +0000 (-0500) Subject: nvk: Cache NIR shaders X-Git-Tag: upstream/23.3.3~1505 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=968cefbff113d3e49c384aafa29d07f4f31a5a80;p=platform%2Fupstream%2Fmesa.git nvk: Cache NIR shaders We can't cache shader binaries just yet but this at least lets us cache the output of spirv_to_nir and the initial optimize. Part-of: --- diff --git a/src/nouveau/vulkan/nvk_compute_pipeline.c b/src/nouveau/vulkan/nvk_compute_pipeline.c index 88e577e..7056ff4 100644 --- a/src/nouveau/vulkan/nvk_compute_pipeline.c +++ b/src/nouveau/vulkan/nvk_compute_pipeline.c @@ -183,7 +183,7 @@ nvk_compute_pipeline_create(struct nvk_device *dev, nir_shader *nir; result = nvk_shader_stage_to_nir(dev, &pCreateInfo->stage, &robustness, - NULL, &nir); + cache, NULL, &nir); if (result != VK_SUCCESS) goto fail; diff --git a/src/nouveau/vulkan/nvk_graphics_pipeline.c b/src/nouveau/vulkan/nvk_graphics_pipeline.c index a6026e5..ea3d684 100644 --- a/src/nouveau/vulkan/nvk_graphics_pipeline.c +++ b/src/nouveau/vulkan/nvk_graphics_pipeline.c @@ -310,7 +310,7 @@ nvk_graphics_pipeline_create(struct nvk_device *dev, pCreateInfo->pNext, sinfo->pNext); result = nvk_shader_stage_to_nir(dev, sinfo, &robustness[stage], - NULL, &nir[stage]); + cache, NULL, &nir[stage]); if (result != VK_SUCCESS) goto fail; } diff --git a/src/nouveau/vulkan/nvk_shader.c b/src/nouveau/vulkan/nvk_shader.c index cd56eac..d442ac7 100644 --- a/src/nouveau/vulkan/nvk_shader.c +++ b/src/nouveau/vulkan/nvk_shader.c @@ -13,6 +13,7 @@ #include "vk_nir_convert_ycbcr.h" #include "vk_pipeline.h" +#include "vk_pipeline_cache.h" #include "vk_pipeline_layout.h" #include "vk_shader_module.h" #include "vk_ycbcr_conversion.h" @@ -24,6 +25,8 @@ #include "nv50_ir_driver.h" +#include "util/mesa-sha1.h" + #include "cla097.h" #include "clc397.h" #include "clc597.h" @@ -421,16 +424,32 @@ VkResult nvk_shader_stage_to_nir(struct nvk_device *dev, const VkPipelineShaderStageCreateInfo *sinfo, const struct vk_pipeline_robustness_state *rstate, + struct vk_pipeline_cache *cache, void *mem_ctx, struct nir_shader **nir_out) { struct nvk_physical_device *pdev = nvk_device_physical(dev); const gl_shader_stage stage = vk_to_mesa_shader_stage(sinfo->stage); const nir_shader_compiler_options *nir_options = nvk_physical_device_nir_options(pdev, stage); + + unsigned char stage_sha1[SHA1_DIGEST_LENGTH]; + vk_pipeline_hash_shader_stage(sinfo, rstate, stage_sha1); + + if (cache == NULL) + cache = dev->mem_cache; + + nir_shader *nir = vk_pipeline_cache_lookup_nir(cache, stage_sha1, + sizeof(stage_sha1), + nir_options, NULL, + mem_ctx); + if (nir != NULL) { + *nir_out = nir; + return VK_SUCCESS; + } + const struct spirv_to_nir_options spirv_options = nvk_physical_device_spirv_options(pdev, rstate); - nir_shader *nir; VkResult result = vk_pipeline_shader_stage_to_nir(&dev->vk, sinfo, &spirv_options, nir_options, @@ -438,6 +457,8 @@ nvk_shader_stage_to_nir(struct nvk_device *dev, if (result != VK_SUCCESS) return result; + vk_pipeline_cache_add_nir(cache, stage_sha1, sizeof(stage_sha1), nir); + *nir_out = nir; return VK_SUCCESS; diff --git a/src/nouveau/vulkan/nvk_shader.h b/src/nouveau/vulkan/nvk_shader.h index f2ac9a5..8c4c58d 100644 --- a/src/nouveau/vulkan/nvk_shader.h +++ b/src/nouveau/vulkan/nvk_shader.h @@ -14,6 +14,7 @@ struct nvk_device; struct nvk_physical_device; struct nvk_pipeline_compilation_ctx; +struct vk_pipeline_cache; struct vk_pipeline_layout; struct vk_pipeline_robustness_state; struct vk_shader_module; @@ -129,6 +130,7 @@ VkResult nvk_shader_stage_to_nir(struct nvk_device *dev, const VkPipelineShaderStageCreateInfo *sinfo, const struct vk_pipeline_robustness_state *rstate, + struct vk_pipeline_cache *cache, void *mem_ctx, struct nir_shader **nir_out); void