Mesa (main): anv: move internal RT shaders to the internal cache

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat May 28 10:47:22 UTC 2022


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

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Fri May 27 11:27:55 2022 +0300

anv: move internal RT shaders to the internal cache

Those shaders are just like the blorp ones.

v2: Use a single internal cache for blorp/RT (Jason)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Fixes: 7f1e82306c9b ("anv: Switch to the new common pipeline cache")
Reviewed-by: Jason Ekstrand <jason.ekstrand at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16741>

---

 src/intel/vulkan/anv_blorp.c    | 22 +++-------------------
 src/intel/vulkan/anv_device.c   | 25 +++++++++++++++++++------
 src/intel/vulkan/anv_pipeline.c | 24 +++++++++++++++---------
 src/intel/vulkan/anv_private.h  |  4 ++--
 4 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index 9e9e7d617f1..a7c64cf73a6 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -32,7 +32,7 @@ lookup_blorp_shader(struct blorp_batch *batch,
    struct anv_device *device = blorp->driver_ctx;
 
    struct anv_shader_bin *bin =
-      anv_device_search_for_kernel(device, device->blorp_cache,
+      anv_device_search_for_kernel(device, device->internal_cache,
                                    key, key_size, NULL);
    if (!bin)
       return false;
@@ -65,7 +65,7 @@ upload_blorp_shader(struct blorp_batch *batch, uint32_t stage,
    };
 
    struct anv_shader_bin *bin =
-      anv_device_upload_kernel(device, device->blorp_cache, stage,
+      anv_device_upload_kernel(device, device->internal_cache, stage,
                                key, key_size, kernel, kernel_size,
                                prog_data, prog_data_size,
                                NULL, 0, NULL, &bind_map);
@@ -84,23 +84,9 @@ upload_blorp_shader(struct blorp_batch *batch, uint32_t stage,
    return true;
 }
 
-bool
+void
 anv_device_init_blorp(struct anv_device *device)
 {
-   /* BLORP needs its own pipeline cache because, unlike the rest of ANV, it
-    * won't work at all without the cache.  It depends on it for shaders to
-    * remain resident while it runs.  Therefore, we need a special cache just
-    * for BLORP that's forced to always be enabled.
-    */
-   struct vk_pipeline_cache_create_info pcc_info = {
-      .force_enable = true,
-   };
-   device->blorp_cache =
-      vk_pipeline_cache_create(&device->vk, &pcc_info, NULL);
-   if (device->blorp_cache == NULL)
-      return false;
-
-
    const struct blorp_config config = {
       .use_mesh_shading = device->physical->vk.supported_extensions.NV_mesh_shader,
    };
@@ -134,13 +120,11 @@ anv_device_init_blorp(struct anv_device *device)
    default:
       unreachable("Unknown hardware generation");
    }
-   return true;
 }
 
 void
 anv_device_finish_blorp(struct anv_device *device)
 {
-   vk_pipeline_cache_destroy(device->blorp_cache, NULL);
    blorp_finish(&device->blorp);
 }
 
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index d2934e364de..8dc893972e9 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -3462,15 +3462,27 @@ VkResult anv_CreateDevice(
       goto fail_trivial_batch_bo_and_scratch_pool;
    }
 
-   result = anv_device_init_rt_shaders(device);
-   if (result != VK_SUCCESS)
+   /* Internal shaders need their own pipeline cache because, unlike the rest
+    * of ANV, it won't work at all without the cache. It depends on it for
+    * shaders to remain resident while it runs. Therefore, we need a special
+    * cache just for BLORP/RT that's forced to always be enabled.
+    */
+   pcc_info.force_enable = true;
+   device->internal_cache =
+      vk_pipeline_cache_create(&device->vk, &pcc_info, NULL);
+   if (device->internal_cache == NULL) {
+      result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
       goto fail_default_pipeline_cache;
+   }
 
-   if (!anv_device_init_blorp(device)) {
+   result = anv_device_init_rt_shaders(device);
+   if (result != VK_SUCCESS) {
       result = vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
-      goto fail_rt_shaders;
+      goto fail_internal_cache;
    }
 
+   anv_device_init_blorp(device);
+
    anv_device_init_border_colors(device);
 
    anv_device_perf_init(device);
@@ -3481,8 +3493,8 @@ VkResult anv_CreateDevice(
 
    return VK_SUCCESS;
 
- fail_rt_shaders:
-   anv_device_finish_rt_shaders(device);
+ fail_internal_cache:
+   vk_pipeline_cache_destroy(device->internal_cache, NULL);
  fail_default_pipeline_cache:
    vk_pipeline_cache_destroy(device->default_pipeline_cache, NULL);
  fail_trivial_batch_bo_and_scratch_pool:
@@ -3556,6 +3568,7 @@ void anv_DestroyDevice(
 
    anv_device_finish_rt_shaders(device);
 
+   vk_pipeline_cache_destroy(device->internal_cache, NULL);
    vk_pipeline_cache_destroy(device->default_pipeline_cache, NULL);
 
 #ifdef HAVE_VALGRIND
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 10e77e5f003..246a56ce962 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -3062,7 +3062,7 @@ anv_device_init_rt_shaders(struct anv_device *device)
       },
    };
    device->rt_trampoline =
-      anv_device_search_for_kernel(device, device->default_pipeline_cache,
+      anv_device_search_for_kernel(device, device->internal_cache,
                                    &trampoline_key, sizeof(trampoline_key),
                                    &cache_hit);
    if (device->rt_trampoline == NULL) {
@@ -3092,7 +3092,7 @@ anv_device_init_rt_shaders(struct anv_device *device)
          brw_compile_cs(device->physical->compiler, tmp_ctx, &params);
 
       device->rt_trampoline =
-         anv_device_upload_kernel(device, device->default_pipeline_cache,
+         anv_device_upload_kernel(device, device->internal_cache,
                                   MESA_SHADER_COMPUTE,
                                   &trampoline_key, sizeof(trampoline_key),
                                   tramp_data,
@@ -3107,6 +3107,11 @@ anv_device_init_rt_shaders(struct anv_device *device)
          return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
    }
 
+   /* The cache already has a reference and it's not going anywhere so there
+    * is no need to hold a second reference.
+    */
+   anv_shader_bin_unref(device, device->rt_trampoline);
+
    struct brw_rt_trivial_return {
       char name[16];
       struct brw_bs_prog_key key;
@@ -3114,7 +3119,7 @@ anv_device_init_rt_shaders(struct anv_device *device)
       .name = "rt-trivial-ret",
    };
    device->rt_trivial_return =
-      anv_device_search_for_kernel(device, device->default_pipeline_cache,
+      anv_device_search_for_kernel(device, device->internal_cache,
                                    &return_key, sizeof(return_key),
                                    &cache_hit);
    if (device->rt_trivial_return == NULL) {
@@ -3140,7 +3145,7 @@ anv_device_init_rt_shaders(struct anv_device *device)
          brw_compile_bs(device->physical->compiler, tmp_ctx, &params);
 
       device->rt_trivial_return =
-         anv_device_upload_kernel(device, device->default_pipeline_cache,
+         anv_device_upload_kernel(device, device->internal_cache,
                                   MESA_SHADER_CALLABLE,
                                   &return_key, sizeof(return_key),
                                   return_data, return_prog_data.base.program_size,
@@ -3149,12 +3154,15 @@ anv_device_init_rt_shaders(struct anv_device *device)
 
       ralloc_free(tmp_ctx);
 
-      if (device->rt_trivial_return == NULL) {
-         anv_shader_bin_unref(device, device->rt_trampoline);
+      if (device->rt_trivial_return == NULL)
          return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
-      }
    }
 
+   /* The cache already has a reference and it's not going anywhere so there
+    * is no need to hold a second reference.
+    */
+   anv_shader_bin_unref(device, device->rt_trivial_return);
+
    return VK_SUCCESS;
 }
 
@@ -3163,8 +3171,6 @@ anv_device_finish_rt_shaders(struct anv_device *device)
 {
    if (!device->vk.enabled_extensions.KHR_ray_tracing_pipeline)
       return;
-
-   anv_shader_bin_unref(device, device->rt_trampoline);
 }
 
 VkResult
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 4ee0e1ca331..d75c06a8f62 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -1197,7 +1197,7 @@ struct anv_device {
     struct anv_state                            null_surface_state;
 
     struct vk_pipeline_cache *                  default_pipeline_cache;
-    struct vk_pipeline_cache *                  blorp_cache;
+    struct vk_pipeline_cache *                  internal_cache;
     struct blorp_context                        blorp;
 
     struct anv_state                            border_colors;
@@ -1318,7 +1318,7 @@ anv_mocs(const struct anv_device *device,
    return isl_mocs(&device->isl_dev, usage, bo && bo->is_external);
 }
 
-bool anv_device_init_blorp(struct anv_device *device);
+void anv_device_init_blorp(struct anv_device *device);
 void anv_device_finish_blorp(struct anv_device *device);
 
 enum anv_bo_alloc_flags {



More information about the mesa-commit mailing list