radv: make use of on-disk cache
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 11 Oct 2017 01:10:31 +0000 (12:10 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Wed, 11 Oct 2017 21:52:38 +0000 (08:52 +1100)
If the app provided in-memory pipeline cache doesn't yet contain
what we are looking for, or it doesn't provide one at all then we
fallback to the on-disk cache.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_pipeline_cache.c

index 625c58e66c71d7cf774050b30185c25ac9c2d228..94437e2b30cf3cfdf8fca4e7655234c9a8f890cc 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "util/mesa-sha1.h"
 #include "util/debug.h"
+#include "util/disk_cache.h"
 #include "util/u_atomic.h"
 #include "radv_debug.h"
 #include "radv_private.h"
@@ -165,8 +166,16 @@ radv_create_shader_variant_from_pipeline_cache(struct radv_device *device,
        else
                entry = radv_pipeline_cache_search(device->mem_cache, sha1);
 
-       if (!entry)
-               return NULL;
+       if (!entry) {
+               uint8_t disk_sha1[20];
+               disk_cache_compute_key(device->physical_device->disk_cache,
+                                      sha1, 20, disk_sha1);
+               entry = (struct cache_entry *)
+                       disk_cache_get(device->physical_device->disk_cache,
+                                      disk_sha1, NULL);
+               if (!entry)
+                       return NULL;
+       }
 
        if (!entry->variant) {
                struct radv_shader_variant *variant;
@@ -301,6 +310,20 @@ radv_pipeline_cache_insert_shader(struct radv_device *device,
        entry->rsrc1 = variant->rsrc1;
        entry->rsrc2 = variant->rsrc2;
        entry->code_size = code_size;
+
+       /* Set variant to NULL so we have reproducible cache items */
+       entry->variant = NULL;
+
+       /* Always add cache items to disk. This will allow collection of
+        * compiled shaders by third parties such as steam, even if the app
+        * implements its own pipeline cache.
+        */
+       uint8_t disk_sha1[20];
+       disk_cache_compute_key(device->physical_device->disk_cache, sha1, 20,
+                              disk_sha1);
+       disk_cache_put(device->physical_device->disk_cache,
+                      disk_sha1, entry, entry_size(entry), NULL);
+
        entry->variant = variant;
        p_atomic_inc(&variant->ref_count);