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

Timothy Arceri tarceri at itsqueeze.com
Wed Oct 11 04:11:38 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  | 13 +++++++++++++
 src/amd/vulkan/radv_private.h |  6 ++++++
 src/util/disk_cache.h         | 15 +++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index d414d8ca85..23f5e70321 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -345,20 +345,32 @@ radv_physical_device_init(struct radv_physical_device *device,
 	}
 
 	if (radv_device_get_cache_uuid(device->rad_info.family, device->cache_uuid)) {
 		radv_finish_wsi(device);
 		device->ws->destroy(device->ws);
 		result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
 				   "cannot generate UUID");
 		goto fail;
 	}
 
+	/* These flags affect shader compilation. */
+	uint64_t shader_env_flags =
+		(device->instance->perftest_flags & RADV_PERFTEST_SISCHED ? 0x1 : 0) |
+		(device->instance->debug_flags & RADV_DEBUG_UNSAFE_MATH ? 0x2 : 0);
+
+	/* The gpu id is already embeded in the uuid so we just pass "radv"
+	 * when creating the cache.
+	 */
+	char buf[VK_UUID_SIZE + 1];
+	disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE);
+	device->disk_cache = disk_cache_create("radv", buf, shader_env_flags);
+
 	result = radv_extensions_register(instance,
 					&device->extensions,
 					common_device_extensions,
 					ARRAY_SIZE(common_device_extensions));
 	if (result != VK_SUCCESS)
 		goto fail;
 
 	if (device->rad_info.chip_class >= VI && device->rad_info.max_se >= 2) {
 		result = radv_extensions_register(instance,
 						&device->extensions,
@@ -395,20 +407,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 548952faa9..e673527811 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -270,20 +270,26 @@ struct radv_physical_device {
 	uint8_t                                     driver_uuid[VK_UUID_SIZE];
 	uint8_t                                     device_uuid[VK_UUID_SIZE];
 	uint8_t                                     cache_uuid[VK_UUID_SIZE];
 
 	int local_fd;
 	struct wsi_device                       wsi_device;
 	struct radv_extensions                      extensions;
 
 	bool has_rbplus; /* if RB+ register exist */
 	bool rbplus_allowed; /* if RB+ is allowed */
+
+
+	/* 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 d2e4d9a69c..488b297ead 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -58,20 +58,35 @@ struct cache_item_metadata {
     */
    uint32_t type;
 
    /** GLSL cache item metadata */
    cache_key *keys;   /* sha1 list of shaders that make up the cache item */
    uint32_t num_keys;
 };
 
 struct disk_cache;
 
+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.13.6



More information about the mesa-dev mailing list