radv: enable shaders cache for libraries with GPL
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 6 Jan 2023 08:01:12 +0000 (09:01 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 4 Apr 2023 14:47:39 +0000 (14:47 +0000)
This was the last missing feature for GPL. The main problem is that
the on-disk shaders cache size will increase a lot because we don't
deduplicate shaders but there is on-going work to improve that.

We also can't use the shaders cache for libraries created with the
RETAIN_LINK_TIME_OPTIMIZATION flag and module identifiers because we
don't know the SPIR-V and thus can't retain NIR shaders for linking.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22264>

src/amd/vulkan/radv_pipeline.c

index 3ed4158..63b595f 100644 (file)
@@ -3211,16 +3211,6 @@ radv_graphics_pipeline_compile(struct radv_graphics_pipeline *pipeline,
 
    int64_t pipeline_start = os_time_get_nano();
 
-   /* Skip the shaders cache when any of the below are true:
-    * - fast-linking is enabled because it's useless to cache unoptimized pipelines
-    * - shaders are captured because it's for debugging purposes
-    * - libraries are created with GPL
-    */
-   if (fast_linking_enabled || keep_executable_info ||
-       (pCreateInfo->flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR)) {
-      skip_shaders_cache = true;
-   }
-
    for (unsigned i = 0; i < MESA_VULKAN_SHADER_STAGES; i++) {
       stages[i].entrypoint = NULL;
       stages[i].nir = NULL;
@@ -3247,6 +3237,23 @@ radv_graphics_pipeline_compile(struct radv_graphics_pipeline *pipeline,
       pipeline->base.pipeline_hash = *(uint64_t *)hash;
    }
 
+   /* Skip the shaders cache when any of the below are true:
+    * - fast-linking is enabled because it's useless to cache unoptimized pipelines
+    * - shaders are captured because it's for debugging purposes
+    * - graphics pipeline libraries are created with the RETAIN_LINK_TIME_OPTIMIZATION flag and
+    *   module identifiers are used (ie. no SPIR-V provided).
+    */
+   if (fast_linking_enabled || keep_executable_info) {
+      skip_shaders_cache = true;
+   } else if ((pCreateInfo->flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) && retain_shaders) {
+      for (uint32_t i = 0; i < MESA_VULKAN_SHADER_STAGES; i++) {
+         if (stages[i].entrypoint && !stages[i].spirv.size) {
+            skip_shaders_cache = true;
+            break;
+         }
+      }
+   }
+
    bool found_in_application_cache = true;
    if (!skip_shaders_cache &&
        radv_create_shaders_from_pipeline_cache(device, cache, hash, &pipeline->base, NULL, 0,