Mesa (main): anv: Clean up pipeline cache helpers a bit

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Apr 22 20:10:57 UTC 2022


Module: Mesa
Branch: main
Commit: 2d3b3b757ad0eaef6abcb6ef81fc73b65b9a83d8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2d3b3b757ad0eaef6abcb6ef81fc73b65b9a83d8

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Mon Oct  4 14:24:57 2021 -0500

anv: Clean up pipeline cache helpers a bit

Instead of having two different helpers, delete the pipeline_cache ones.
Also, instead of manually handling the cache == NULL case in every
vkCreateFooPipelines call, handle it inside the helpers.  This means
that BLORP can use them too by passing cache=NULL.

Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13184>

---

 src/intel/vulkan/anv_blorp.c          | 11 +++--
 src/intel/vulkan/anv_pipeline_cache.c | 91 ++++++++++-------------------------
 src/intel/vulkan/anv_private.h        | 15 ------
 src/intel/vulkan/genX_pipeline.c      | 12 -----
 4 files changed, 31 insertions(+), 98 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 4e932ac5d97..b9743d9b47f 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -32,7 +32,8 @@ lookup_blorp_shader(struct blorp_batch *batch,
    struct anv_device *device = blorp->driver_ctx;
 
    struct anv_shader_bin *bin =
-      anv_pipeline_cache_search(device->blorp_cache, key, key_size);
+      anv_device_search_for_kernel(device, device->blorp_cache,
+                                   key, key_size, NULL);
    if (!bin)
       return false;
 
@@ -64,10 +65,10 @@ upload_blorp_shader(struct blorp_batch *batch, uint32_t stage,
    };
 
    struct anv_shader_bin *bin =
-      anv_pipeline_cache_upload_kernel(device->blorp_cache, stage,
-                                       key, key_size, kernel, kernel_size,
-                                       prog_data, prog_data_size,
-                                       NULL, 0, NULL, &bind_map);
+      anv_device_upload_kernel(device, device->blorp_cache, stage,
+                               key, key_size, kernel, kernel_size,
+                               prog_data, prog_data_size,
+                               NULL, 0, NULL, &bind_map);
 
    if (!bin)
       return false;
diff --git a/src/intel/vulkan/anv_pipeline_cache.c b/src/intel/vulkan/anv_pipeline_cache.c
index 31c2d8f653a..639879f642e 100644
--- a/src/intel/vulkan/anv_pipeline_cache.c
+++ b/src/intel/vulkan/anv_pipeline_cache.c
@@ -293,64 +293,24 @@ anv_shader_bin_deserialize(struct vk_device *vk_device,
    return &shader->base;
 }
 
-struct anv_shader_bin *
-anv_pipeline_cache_search(struct vk_pipeline_cache *cache,
-                          const void *key_data, uint32_t key_size)
-{
-   struct vk_pipeline_cache_object *object =
-      vk_pipeline_cache_lookup_object(cache, key_data, key_size,
-                                      &anv_shader_bin_ops, NULL);
-   if (object == NULL)
-      return NULL;
-
-   return container_of(object, struct anv_shader_bin, base);
-}
-
-struct anv_shader_bin *
-anv_pipeline_cache_upload_kernel(struct vk_pipeline_cache *cache,
-                                 gl_shader_stage stage,
-                                 const void *key_data, uint32_t key_size,
-                                 const void *kernel_data, uint32_t kernel_size,
-                                 const struct brw_stage_prog_data *prog_data,
-                                 uint32_t prog_data_size,
-                                 const struct brw_compile_stats *stats,
-                                 uint32_t num_stats,
-                                 const nir_xfb_info *xfb_info,
-                                 const struct anv_pipeline_bind_map *bind_map)
-{
-   struct anv_device *device =
-      container_of(cache->base.device, struct anv_device, vk);
-
-   struct anv_shader_bin *shader =
-      anv_shader_bin_create(device, stage,
-                            key_data, key_size,
-                            kernel_data, kernel_size,
-                            prog_data, prog_data_size,
-                            stats, num_stats,
-                            xfb_info, bind_map);
-   if (shader == NULL)
-      return NULL;
-
-   struct vk_pipeline_cache_object *cached =
-      vk_pipeline_cache_add_object(cache, &shader->base);
-
-   return container_of(cached, struct anv_shader_bin, base);
-}
-
 struct anv_shader_bin *
 anv_device_search_for_kernel(struct anv_device *device,
                              struct vk_pipeline_cache *cache,
                              const void *key_data, uint32_t key_size,
                              bool *user_cache_hit)
 {
-   *user_cache_hit = false;
-
+   /* Use the default pipeline cache if none is specified */
    if (cache == NULL)
-      return NULL;
+      cache = device->default_pipeline_cache;
 
+   bool cache_hit = false;
    struct vk_pipeline_cache_object *object =
       vk_pipeline_cache_lookup_object(cache, key_data, key_size,
-                                      &anv_shader_bin_ops, user_cache_hit);
+                                      &anv_shader_bin_ops, &cache_hit);
+   if (user_cache_hit != NULL) {
+      *user_cache_hit = object != NULL && cache_hit &&
+                        cache != device->default_pipeline_cache;
+   }
    if (object == NULL)
       return NULL;
 
@@ -370,25 +330,24 @@ anv_device_upload_kernel(struct anv_device *device,
                          const nir_xfb_info *xfb_info,
                          const struct anv_pipeline_bind_map *bind_map)
 {
-   struct anv_shader_bin *bin;
-   if (cache) {
-      bin = anv_pipeline_cache_upload_kernel(cache, stage, key_data, key_size,
-                                             kernel_data, kernel_size,
-                                             prog_data, prog_data_size,
-                                             stats, num_stats,
-                                             xfb_info, bind_map);
-   } else {
-      bin = anv_shader_bin_create(device, stage, key_data, key_size,
-                                  kernel_data, kernel_size,
-                                  prog_data, prog_data_size,
-                                  stats, num_stats,
-                                  xfb_info, bind_map);
-   }
+   /* Use the default pipeline cache if none is specified */
+   if (cache == NULL)
+      cache = device->default_pipeline_cache;
 
-   if (bin == NULL)
+   struct anv_shader_bin *shader =
+      anv_shader_bin_create(device, stage,
+                            key_data, key_size,
+                            kernel_data, kernel_size,
+                            prog_data, prog_data_size,
+                            stats, num_stats,
+                            xfb_info, bind_map);
+   if (shader == NULL)
       return NULL;
 
-   return bin;
+   struct vk_pipeline_cache_object *cached =
+      vk_pipeline_cache_add_object(cache, &shader->base);
+
+   return container_of(cached, struct anv_shader_bin, base);
 }
 
 #define SHA1_KEY_SIZE 20
@@ -401,7 +360,7 @@ anv_device_search_for_nir(struct anv_device *device,
                           void *mem_ctx)
 {
    if (cache == NULL)
-      return false;
+      cache = device->default_pipeline_cache;
 
    return vk_pipeline_cache_lookup_nir(cache, sha1_key, SHA1_KEY_SIZE,
                                        nir_options, NULL, mem_ctx);
@@ -414,7 +373,7 @@ anv_device_upload_nir(struct anv_device *device,
                       unsigned char sha1_key[SHA1_KEY_SIZE])
 {
    if (cache == NULL)
-      return;
+      cache = device->default_pipeline_cache;
 
    vk_pipeline_cache_add_nir(cache, sha1_key, SHA1_KEY_SIZE, nir);
 }
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 96b21059080..9d5b81a0303 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1106,21 +1106,6 @@ struct anv_pipeline_bind_map;
 
 extern const struct vk_pipeline_cache_object_ops *const anv_cache_import_ops[2];
 
-struct anv_shader_bin *
-anv_pipeline_cache_search(struct vk_pipeline_cache *cache,
-                          const void *key, uint32_t key_size);
-struct anv_shader_bin *
-anv_pipeline_cache_upload_kernel(struct vk_pipeline_cache *cache,
-                                 gl_shader_stage stage,
-                                 const void *key_data, uint32_t key_size,
-                                 const void *kernel_data, uint32_t kernel_size,
-                                 const struct brw_stage_prog_data *prog_data,
-                                 uint32_t prog_data_size,
-                                 const struct brw_compile_stats *stats,
-                                 uint32_t num_stats,
-                                 const struct nir_xfb_info *xfb_info,
-                                 const struct anv_pipeline_bind_map *bind_map);
-
 struct anv_shader_bin *
 anv_device_search_for_kernel(struct anv_device *device,
                              struct vk_pipeline_cache *cache,
diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c
index 91aa50b1b45..0d774cfcd5c 100644
--- a/src/intel/vulkan/genX_pipeline.c
+++ b/src/intel/vulkan/genX_pipeline.c
@@ -2791,10 +2791,6 @@ genX(graphics_pipeline_create)(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
 
-   /* Use the default pipeline cache if none is specified */
-   if (cache == NULL)
-      cache = device->default_pipeline_cache;
-
    pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pipeline == NULL)
@@ -3099,10 +3095,6 @@ compute_pipeline_create(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO);
 
-   /* Use the default pipeline cache if none is specified */
-   if (cache == NULL)
-      cache = device->default_pipeline_cache;
-
    pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (pipeline == NULL)
@@ -3244,10 +3236,6 @@ ray_tracing_pipeline_create(
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR);
 
-   /* Use the default pipeline cache if none is specified */
-   if (cache == NULL)
-      cache = device->default_pipeline_cache;
-
    VK_MULTIALLOC(ma);
    VK_MULTIALLOC_DECL(&ma, struct anv_ray_tracing_pipeline, pipeline, 1);
    VK_MULTIALLOC_DECL(&ma, struct anv_rt_shader_group, groups, pCreateInfo->groupCount);



More information about the mesa-commit mailing list