[Mesa-dev] [PATCH V3] r600/radeonsi: enable glsl/tgsi on-disk cache

Timothy Arceri tarceri at itsqueeze.com
Mon Feb 20 23:31:04 UTC 2017


For gpu generations that use LLVM we create a timestamp string
containing both the LLVM and Mesa build times, otherwise we just
use the Mesa build time.

V2: share code in r600_pipe_common as suggested by Marek.

V3: send the correct revision of V2
---
 src/gallium/drivers/radeon/r600_pipe_common.c | 51 +++++++++++++++++++++++++++
 src/gallium/drivers/radeon/r600_pipe_common.h |  3 ++
 2 files changed, 54 insertions(+)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index 1781584..614eef1 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -43,6 +43,10 @@
 #define HAVE_LLVM 0
 #endif
 
+#if HAVE_LLVM
+#include <llvm-c/TargetMachine.h>
+#endif
+
 #ifndef MESA_LLVM_VERSION_PATCH
 #define MESA_LLVM_VERSION_PATCH 0
 #endif
@@ -779,6 +783,49 @@ static const char* r600_get_chip_name(struct r600_common_screen *rscreen)
 	}
 }
 
+static void r600_disk_cache_create(struct r600_common_screen *rscreen)
+{
+	uint32_t mesa_timestamp;
+	if (disk_cache_get_function_timestamp(r600_disk_cache_create,
+					      &mesa_timestamp)) {
+		char *timestamp_str;
+		int res = -1;
+#if HAVE_LLVM
+		uint32_t llvm_timestamp;
+		if (disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo,
+						      &llvm_timestamp)) {
+
+			res = asprintf(&timestamp_str, "%u_%u", mesa_timestamp,
+				       llvm_timestamp);
+		} else {
+#endif
+			/* We only use a Mesa only timestamp if less than SI
+			 * because we must have an LLVM identifier to avoid
+			 * shaders not being rebuild when the LLVM version
+			 * changes.
+			 */
+			if (rscreen->chip_class < SI) {
+				res = asprintf(&timestamp_str, "%u",
+					       mesa_timestamp);
+			}
+#if HAVE_LLVM
+		}
+#endif
+		if (res != -1) {
+			rscreen->disk_shader_cache =
+				disk_cache_create(r600_get_chip_name(rscreen),
+						  timestamp_str);
+			free(timestamp_str);
+		}
+	}
+}
+
+static struct disk_cache *r600_get_disk_shader_cache(struct pipe_screen *pscreen)
+{
+	struct r600_common_screen *rscreen = (struct r600_common_screen*)pscreen;
+	return rscreen->disk_shader_cache;
+}
+
 static const char* r600_get_name(struct pipe_screen* pscreen)
 {
 	struct r600_common_screen *rscreen = (struct r600_common_screen*)pscreen;
@@ -1234,6 +1281,7 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
 	rscreen->b.get_name = r600_get_name;
 	rscreen->b.get_vendor = r600_get_vendor;
 	rscreen->b.get_device_vendor = r600_get_device_vendor;
+	rscreen->b.get_disk_shader_cache = r600_get_disk_shader_cache;
 	rscreen->b.get_compute_param = r600_get_compute_param;
 	rscreen->b.get_paramf = r600_get_paramf;
 	rscreen->b.get_timestamp = r600_get_timestamp;
@@ -1243,6 +1291,8 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
 	rscreen->b.resource_from_user_memory = r600_buffer_from_user_memory;
 	rscreen->b.query_memory_info = r600_query_memory_info;
 
+	r600_disk_cache_create(rscreen);
+
 	if (rscreen->info.has_uvd) {
 		rscreen->b.get_video_param = rvid_get_video_param;
 		rscreen->b.is_video_format_supported = rvid_is_format_supported;
@@ -1324,6 +1374,7 @@ void r600_destroy_common_screen(struct r600_common_screen *rscreen)
 
 	slab_destroy_parent(&rscreen->pool_transfers);
 
+	disk_cache_destroy(rscreen->disk_shader_cache);
 	rscreen->ws->destroy(rscreen->ws);
 	FREE(rscreen);
 }
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
index e8dbf5d..92b9532 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -36,6 +36,7 @@
 
 #include "radeon/radeon_winsys.h"
 
+#include "util/disk_cache.h"
 #include "util/u_blitter.h"
 #include "util/list.h"
 #include "util/u_range.h"
@@ -404,6 +405,8 @@ struct r600_common_screen {
 	bool				has_cp_dma;
 	bool				has_streamout;
 
+	struct disk_cache		*disk_shader_cache;
+
 	struct slab_parent_pool		pool_transfers;
 
 	/* Texture filter settings. */
-- 
2.9.3



More information about the mesa-dev mailing list