[Mesa-dev] [PATCH 2/7] glsl: Add stubs for the case of --disable-shader-cache

Carl Worth cworth at cworth.org
Wed Feb 4 13:52:56 PST 2015


If Mesa is being compiled with no shader cache, (whether due to
explicit user request or due to a missing library dependency), then we
want to incur no cost on the implementation. To achieve this with as
little fuss as possible, (that is, without sprinkling #ifdef
throughout every call into cache functions), we implement inlined
stubs to make all of the called functions do nothing.

For these stubs, the configure script is updated to provide a new
ENABLE_SHADER_CACHE preprocessor definition that can be queried at
compile time.
---
 configure.ac              |  3 +++
 src/glsl/Makefile.sources |  1 +
 src/glsl/cache.h          | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/configure.ac b/configure.ac
index a4c5c74..c081b7b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1062,6 +1062,9 @@ if test "x$with_sha1" = "x"; then
     fi
 fi
 AM_CONDITIONAL([ENABLE_SHADER_CACHE], [test x$enable_shader_cache = xyes])
+if test "x$enable_shader_cache" = "xyes"; then
+   AC_DEFINE([ENABLE_SHADER_CACHE], [1], [Enable shader cache])
+fi
 
 # Check for libdrm
 PKG_CHECK_MODULES([LIBDRM], [libdrm >= $LIBDRM_REQUIRED],
diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index 6237627..8375f6e 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -67,6 +67,7 @@ LIBGLSL_FILES = \
 	$(GLSL_SRCDIR)/ast_type.cpp \
 	$(GLSL_SRCDIR)/blob.c \
 	$(GLSL_SRCDIR)/blob.h \
+	$(GLSL_SRCDIR)/cache.h \
 	$(GLSL_SRCDIR)/builtin_functions.cpp \
 	$(GLSL_SRCDIR)/builtin_type_macros.h \
 	$(GLSL_SRCDIR)/builtin_types.cpp \
diff --git a/src/glsl/cache.h b/src/glsl/cache.h
index 5e9b3a8..51be663 100644
--- a/src/glsl/cache.h
+++ b/src/glsl/cache.h
@@ -45,6 +45,10 @@ extern "C" {
 
 typedef uint8_t cache_key[CACHE_KEY_SIZE];
 
+/* Provide inlined stub functions if the shader cache is disabled. */
+
+#ifdef ENABLE_SHADER_CACHE
+
 /**
  * Create a new cache object.
  *
@@ -114,6 +118,41 @@ cache_get(struct program_cache *cache, cache_key key, size_t *size);
 int
 cache_has(struct program_cache *cache, cache_key key);
 
+#else
+
+static inline struct program_cache *
+cache_create(void)
+{
+   return NULL;
+}
+
+static inline void
+cache_put(struct program_cache *cache, cache_key key,
+          const void *data, size_t size)
+{
+   return 0;
+}
+
+static inline void
+cache_mark(struct program_cache *cache, cache_key key)
+{
+   return;
+}
+
+static inline uint8_t *
+cache_get(struct program_cache *cache, cache_key key, size_t *size)
+{
+   return NULL;
+}
+
+static inline int
+cache_has(struct program_cache *cache, cache_key key)
+{
+   return 0;
+}
+
+#endif /* ENABLE_SHADER_CACHE */
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.1.4



More information about the mesa-dev mailing list