[Mesa-dev] [PATCH v3 07/14] anv: Move shader hashing to anv_pipeline

Iago Toral itoral at igalia.com
Wed May 3 06:25:24 UTC 2017


On Thu, 2017-04-27 at 09:31 -0700, Jason Ekstrand wrote:
> Shader hashing is very closely related to shader
> compilation.  Putting
> them right next to each other in anv_pipeline makes it easier to
> verify
> that we're actually hashing everything we need to be hashing.

Maybe add that this version also hashes the shader stage.

> ---
>  src/intel/vulkan/anv_pipeline.c       | 59
> ++++++++++++++++++++++++++++-------
>  src/intel/vulkan/anv_pipeline_cache.c | 27 ----------------
>  src/intel/vulkan/anv_private.h        |  6 ----
>  3 files changed, 47 insertions(+), 45 deletions(-)
> 
> diff --git a/src/intel/vulkan/anv_pipeline.c
> b/src/intel/vulkan/anv_pipeline.c
> index 9d0dc69..0685d0a 100644
> --- a/src/intel/vulkan/anv_pipeline.c
> +++ b/src/intel/vulkan/anv_pipeline.c
> @@ -331,6 +331,35 @@ populate_cs_prog_key(const struct
> gen_device_info *devinfo,
>     populate_sampler_prog_key(devinfo, &key->tex);
>  }
>  
> +static void
> +anv_pipeline_hash_shader(struct anv_pipeline *pipeline,
> +                         struct anv_shader_module *module,
> +                         const char *entrypoint,
> +                         gl_shader_stage stage,
> +                         const VkSpecializationInfo *spec_info,
> +                         const void *key, size_t key_size,
> +                         unsigned char *sha1_out)
> +{
> +   struct mesa_sha1 ctx;
> +
> +   _mesa_sha1_init(&ctx);
> +   if (pipeline->layout) {
> +      _mesa_sha1_update(&ctx, pipeline->layout->sha1,
> +                        sizeof(pipeline->layout->sha1));
> +   }
> +   _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
> +   _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
> +   _mesa_sha1_update(&ctx, &stage, sizeof(stage));
> +   /* hash in shader stage, pipeline layout? */

This comment above seems outdated.

Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>

> +   if (spec_info) {
> +      _mesa_sha1_update(&ctx, spec_info->pMapEntries,
> +                        spec_info->mapEntryCount *
> sizeof(*spec_info->pMapEntries));
> +      _mesa_sha1_update(&ctx, spec_info->pData, spec_info-
> >dataSize);
> +   }
> +   _mesa_sha1_update(&ctx, key, key_size);
> +   _mesa_sha1_final(&ctx, sha1_out);
> +}
> +
>  static nir_shader *
>  anv_pipeline_compile(struct anv_pipeline *pipeline,
>                       struct anv_shader_module *module,
> @@ -463,8 +492,9 @@ anv_pipeline_compile_vs(struct anv_pipeline
> *pipeline,
>     populate_vs_prog_key(&pipeline->device->info, &key);
>  
>     if (cache) {
> -      anv_hash_shader(sha1, &key, sizeof(key), module, entrypoint,
> -                      pipeline->layout, spec_info);
> +      anv_pipeline_hash_shader(pipeline, module, entrypoint,
> +                               MESA_SHADER_VERTEX, spec_info,
> +                               &key, sizeof(key), sha1);
>        bin = anv_pipeline_cache_search(cache, sha1, 20);
>     }
>  
> @@ -587,10 +617,12 @@ anv_pipeline_compile_tcs_tes(struct
> anv_pipeline *pipeline,
>     tcs_key.input_vertices = info->pTessellationState-
> >patchControlPoints;
>  
>     if (cache) {
> -      anv_hash_shader(tcs_sha1, &tcs_key, sizeof(tcs_key),
> tcs_module,
> -                      tcs_entrypoint, pipeline->layout,
> tcs_spec_info);
> -      anv_hash_shader(tes_sha1, &tes_key, sizeof(tes_key),
> tes_module,
> -                      tes_entrypoint, pipeline->layout,
> tes_spec_info);
> +      anv_pipeline_hash_shader(pipeline, tcs_module, tcs_entrypoint,
> +                               MESA_SHADER_TESS_CTRL, tcs_spec_info,
> +                               &tcs_key, sizeof(tcs_key), tcs_sha1);
> +      anv_pipeline_hash_shader(pipeline, tes_module, tes_entrypoint,
> +                               MESA_SHADER_TESS_EVAL, tes_spec_info,
> +                               &tes_key, sizeof(tes_key), tes_sha1);
>        memcpy(&tcs_sha1[20], tes_sha1, 20);
>        memcpy(&tes_sha1[20], tcs_sha1, 20);
>        tcs_bin = anv_pipeline_cache_search(cache, tcs_sha1,
> sizeof(tcs_sha1));
> @@ -724,8 +756,9 @@ anv_pipeline_compile_gs(struct anv_pipeline
> *pipeline,
>     populate_gs_prog_key(&pipeline->device->info, &key);
>  
>     if (cache) {
> -      anv_hash_shader(sha1, &key, sizeof(key), module, entrypoint,
> -                      pipeline->layout, spec_info);
> +      anv_pipeline_hash_shader(pipeline, module, entrypoint,
> +                               MESA_SHADER_GEOMETRY, spec_info,
> +                               &key, sizeof(key), sha1);
>        bin = anv_pipeline_cache_search(cache, sha1, 20);
>     }
>  
> @@ -801,8 +834,9 @@ anv_pipeline_compile_fs(struct anv_pipeline
> *pipeline,
>     populate_wm_prog_key(pipeline, info, &key);
>  
>     if (cache) {
> -      anv_hash_shader(sha1, &key, sizeof(key), module, entrypoint,
> -                      pipeline->layout, spec_info);
> +      anv_pipeline_hash_shader(pipeline, module, entrypoint,
> +                               MESA_SHADER_FRAGMENT, spec_info,
> +                               &key, sizeof(key), sha1);
>        bin = anv_pipeline_cache_search(cache, sha1, 20);
>     }
>  
> @@ -923,8 +957,9 @@ anv_pipeline_compile_cs(struct anv_pipeline
> *pipeline,
>     populate_cs_prog_key(&pipeline->device->info, &key);
>  
>     if (cache) {
> -      anv_hash_shader(sha1, &key, sizeof(key), module, entrypoint,
> -                      pipeline->layout, spec_info);
> +      anv_pipeline_hash_shader(pipeline, module, entrypoint,
> +                               MESA_SHADER_COMPUTE, spec_info,
> +                               &key, sizeof(key), sha1);
>        bin = anv_pipeline_cache_search(cache, sha1, 20);
>     }
>  
> diff --git a/src/intel/vulkan/anv_pipeline_cache.c
> b/src/intel/vulkan/anv_pipeline_cache.c
> index cdd8215..cbca14a 100644
> --- a/src/intel/vulkan/anv_pipeline_cache.c
> +++ b/src/intel/vulkan/anv_pipeline_cache.c
> @@ -21,7 +21,6 @@
>   * IN THE SOFTWARE.
>   */
>  
> -#include "util/mesa-sha1.h"
>  #include "util/hash_table.h"
>  #include "util/debug.h"
>  #include "anv_private.h"
> @@ -198,32 +197,6 @@ anv_pipeline_cache_finish(struct
> anv_pipeline_cache *cache)
>     }
>  }
>  
> -void
> -anv_hash_shader(unsigned char *hash, const void *key, size_t
> key_size,
> -                struct anv_shader_module *module,
> -                const char *entrypoint,
> -                const struct anv_pipeline_layout *pipeline_layout,
> -                const VkSpecializationInfo *spec_info)
> -{
> -   struct mesa_sha1 ctx;
> -
> -   _mesa_sha1_init(&ctx);
> -   _mesa_sha1_update(&ctx, key, key_size);
> -   _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
> -   _mesa_sha1_update(&ctx, entrypoint, strlen(entrypoint));
> -   if (pipeline_layout) {
> -      _mesa_sha1_update(&ctx, pipeline_layout->sha1,
> -                        sizeof(pipeline_layout->sha1));
> -   }
> -   /* hash in shader stage, pipeline layout? */
> -   if (spec_info) {
> -      _mesa_sha1_update(&ctx, spec_info->pMapEntries,
> -                        spec_info->mapEntryCount * sizeof spec_info-
> >pMapEntries[0]);
> -      _mesa_sha1_update(&ctx, spec_info->pData, spec_info-
> >dataSize);
> -   }
> -   _mesa_sha1_final(&ctx, hash);
> -}
> -
>  static struct anv_shader_bin *
>  anv_pipeline_cache_search_locked(struct anv_pipeline_cache *cache,
>                                   const void *key_data, uint32_t
> key_size)
> diff --git a/src/intel/vulkan/anv_private.h
> b/src/intel/vulkan/anv_private.h
> index 47d8cd2..b7a9bbf 100644
> --- a/src/intel/vulkan/anv_private.h
> +++ b/src/intel/vulkan/anv_private.h
> @@ -1686,12 +1686,6 @@ struct anv_shader_module {
>     char                                         data[0];
>  };
>  
> -void anv_hash_shader(unsigned char *hash, const void *key, size_t
> key_size,
> -                     struct anv_shader_module *module,
> -                     const char *entrypoint,
> -                     const struct anv_pipeline_layout
> *pipeline_layout,
> -                     const VkSpecializationInfo *spec_info);
> -
>  static inline gl_shader_stage
>  vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
>  {


More information about the mesa-dev mailing list