[Mesa-dev] [PATCH 5/4] radv: create on-disk shader cache

Timothy Arceri tarceri at itsqueeze.com
Wed Mar 15 05:57:43 UTC 2017


This is the drivers on-disk cache intended to be used as a
fallback as opposed to the pipeline cache provided by apps.
---
 src/amd/vulkan/radv_device.c  |  8 ++++++++
 src/amd/vulkan/radv_private.h |  5 +++++
 src/util/disk_cache.h         | 15 +++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 65e6a2c..f31fde2 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -222,20 +222,27 @@ radv_physical_device_init(struct radv_physical_device *device,
 	}
 
 	if (radv_device_get_cache_uuid(device->rad_info.family, device->uuid)) {
 		radv_finish_wsi(device);
 		device->ws->destroy(device->ws);
 		result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
 				   "cannot generate UUID");
 		goto fail;
 	}
 
+	/* The gpu id is already embeded in the uuid so we just pass "radv"
+	 * when creating the cache.
+	 */
+	char buf[VK_UUID_SIZE];
+	disk_cache_format_hex_id(buf, device->uuid, VK_UUID_SIZE);
+	device->disk_cache = disk_cache_create("radv", buf);
+
 	result = radv_extensions_register(instance,
 					&device->extensions,
 					common_device_extensions,
 					ARRAY_SIZE(common_device_extensions));
 	if (result != VK_SUCCESS)
 		goto fail;
 
 	fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
 	device->name = device->rad_info.name;
 
@@ -245,20 +252,21 @@ fail:
 	close(fd);
 	return result;
 }
 
 static void
 radv_physical_device_finish(struct radv_physical_device *device)
 {
 	radv_extensions_finish(device->instance, &device->extensions);
 	radv_finish_wsi(device);
 	device->ws->destroy(device->ws);
+	disk_cache_destroy(device->disk_cache);
 	close(device->local_fd);
 }
 
 
 static void *
 default_alloc_func(void *pUserData, size_t size, size_t align,
                    VkSystemAllocationScope allocationScope)
 {
 	return malloc(size);
 }
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index cbd2968..1fece19 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -262,20 +262,25 @@ struct radv_physical_device {
 
 	struct radeon_winsys *ws;
 	struct radeon_info rad_info;
 	char                                        path[20];
 	const char *                                name;
 	uint8_t                                     uuid[VK_UUID_SIZE];
 
 	int local_fd;
 	struct wsi_device                       wsi_device;
 	struct radv_extensions                      extensions;
+
+	/* This is the drivers on-disk cache used as a fallback as opposed to
+	 * the pipeline cache defined by apps.
+	 */
+	struct disk_cache *                         disk_cache;
 };
 
 struct radv_instance {
 	VK_LOADER_DATA                              _loader_data;
 
 	VkAllocationCallbacks                       alloc;
 
 	uint32_t                                    apiVersion;
 	int                                         physicalDeviceCount;
 	struct radv_physical_device                 physicalDevices[RADV_MAX_DRM_DEVICES];
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 3659b6d..ca15f74 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -53,20 +53,35 @@ get_arch_bitness_str(void)
         return "32";
 #endif
     if (sizeof(void *) == 8)
         return "64";
 
     /* paranoia check which will be dropped by the optimiser */
     assert(!"unknown_arch");
     return "unknown_arch";
 }
 
+static inline char *
+disk_cache_format_hex_id(char *buf, const uint8_t *hex_id, unsigned size)
+{
+   static const char hex_digits[] = "0123456789abcdef";
+   unsigned i;
+
+   for (i = 0; i < size; i += 2) {
+      buf[i] = hex_digits[hex_id[i >> 1] >> 4];
+      buf[i + 1] = hex_digits[hex_id[i >> 1] & 0x0f];
+   }
+   buf[i] = '\0';
+
+   return buf;
+}
+
 static inline bool
 disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
 {
 #ifdef ENABLE_SHADER_CACHE
    Dl_info info;
    struct stat st;
    if (!dladdr(ptr, &info) || !info.dli_fname) {
       return false;
    }
    if (stat(info.dli_fname, &st)) {
-- 
2.9.3



More information about the mesa-dev mailing list