Mesa (master): util: import cache.c/h from glsl

Marek Olšák mareko at kemper.freedesktop.org
Tue Nov 15 19:22:34 UTC 2016


Module: Mesa
Branch: master
Commit: 31727300e177b11c2b2b267838b59b090cb605d0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=31727300e177b11c2b2b267838b59b090cb605d0

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Nov 13 16:38:01 2016 +0100

util: import cache.c/h from glsl

It's not dependent on GLSL and it can be useful for shader caches that don't
deal with GLSL.

v2: address review comments
v3: keep the other 3 lines in configure.ac

Reviewed-by: Emil Velikov <emil.velikov at collabora.com>

---

 configure.ac                                     |  1 -
 src/compiler/Makefile.glsl.am                    |  4 ----
 src/compiler/Makefile.sources                    |  4 ----
 src/compiler/glsl/tests/cache_test.c             | 22 +---------------------
 src/util/Makefile.sources                        |  2 ++
 src/{compiler/glsl/cache.c => util/disk_cache.c} | 16 +++++++++-------
 src/{compiler/glsl/cache.h => util/disk_cache.h} | 11 +++++------
 7 files changed, 17 insertions(+), 43 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9d62b90..b89bf23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1361,7 +1361,6 @@ if test "x$with_sha1" = "x"; then
         AC_MSG_ERROR([Cannot enable shader cache (no SHA-1 implementation found)])
     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
diff --git a/src/compiler/Makefile.glsl.am b/src/compiler/Makefile.glsl.am
index 3eac677..5b1d74e 100644
--- a/src/compiler/Makefile.glsl.am
+++ b/src/compiler/Makefile.glsl.am
@@ -131,10 +131,6 @@ glsl_libglsl_la_SOURCES =				\
 	$(LIBGLSL_GENERATED_FILES)			\
 	$(LIBGLSL_FILES)
 
-if ENABLE_SHADER_CACHE
-glsl_libglsl_la_SOURCES += $(LIBGLSL_SHADER_CACHE_FILES)
-endif
-
 glsl_libstandalone_la_SOURCES = \
 	$(GLSL_COMPILER_CXX_FILES)
 
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources
index 08d93e0..d05bcac 100644
--- a/src/compiler/Makefile.sources
+++ b/src/compiler/Makefile.sources
@@ -136,10 +136,6 @@ LIBGLSL_FILES = \
 	glsl/s_expression.cpp \
 	glsl/s_expression.h
 
-LIBGLSL_SHADER_CACHE_FILES = \
-	glsl/cache.c \
-	glsl/cache.h
-
 # glsl_compiler
 
 GLSL_COMPILER_CXX_FILES = \
diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index 724dfcd..94a3c1d 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -32,31 +32,11 @@
 #include <stdarg.h>
 
 #include "util/mesa-sha1.h"
-#include "cache.h"
+#include "util/disk_cache.h"
 
 bool error = false;
 
 #ifdef ENABLE_SHADER_CACHE
-void
-_mesa_warning(void *ctx, const char *fmt, ...);
-
-void
-_mesa_warning(void *ctx, const char *fmt, ...)
-{
-    va_list vargs;
-    (void) ctx;
-
-    va_start(vargs, fmt);
-
-    /* This output is not thread-safe, but that's good enough for the
-     * standalone compiler.
-     */
-    fprintf(stderr, "Mesa warning: ");
-    vfprintf(stderr, fmt, vargs);
-    fprintf(stderr, "\n");
-
-    va_end(vargs);
-}
 
 static void
 expect_equal(uint64_t actual, uint64_t expected, const char *test)
diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index c5531c8..b7ca347 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -4,6 +4,8 @@ MESA_UTIL_FILES :=	\
 	bitset.h \
 	debug.c \
 	debug.h \
+	disk_cache.c \
+	disk_cache.h \
 	format_r11g11b10f.h \
 	format_rgb9e5.h \
 	format_srgb.h \
diff --git a/src/compiler/glsl/cache.c b/src/util/disk_cache.c
similarity index 98%
rename from src/compiler/glsl/cache.c
rename to src/util/disk_cache.c
index e74c27d..79242aa 100644
--- a/src/compiler/glsl/cache.c
+++ b/src/util/disk_cache.c
@@ -21,6 +21,8 @@
  * IN THE SOFTWARE.
  */
 
+#ifdef ENABLE_SHADER_CACHE
+
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
@@ -40,7 +42,7 @@
 #include "util/ralloc.h"
 #include "main/errors.h"
 
-#include "cache.h"
+#include "disk_cache.h"
 
 /* Number of bits to mask off from a cache key to get an index. */
 #define CACHE_INDEX_KEY_BITS 16
@@ -86,9 +88,8 @@ mkdir_if_needed(char *path)
       if (S_ISDIR(sb.st_mode)) {
          return 0;
       } else {
-         _mesa_warning(NULL,
-                       "Cannot use %s for shader cache (not a directory)"
-                       "---disabling.\n", path);
+         fprintf(stderr, "Cannot use %s for shader cache (not a directory)"
+                         "---disabling.\n", path);
          return -1;
       }
    }
@@ -97,9 +98,8 @@ mkdir_if_needed(char *path)
    if (ret == 0 || (ret == -1 && errno == EEXIST))
      return 0;
 
-   _mesa_warning(NULL,
-                 "Failed to create %s for shader cache (%s)---disabling.\n",
-                 path, strerror(errno));
+   fprintf(stderr, "Failed to create %s for shader cache (%s)---disabling.\n",
+           path, strerror(errno));
 
    return -1;
 }
@@ -708,3 +708,5 @@ cache_has_key(struct program_cache *cache, cache_key key)
 
    return memcmp(entry, key, CACHE_KEY_SIZE) == 0;
 }
+
+#endif
diff --git a/src/compiler/glsl/cache.h b/src/util/disk_cache.h
similarity index 99%
rename from src/compiler/glsl/cache.h
rename to src/util/disk_cache.h
index d804169..d4d9398 100644
--- a/src/compiler/glsl/cache.h
+++ b/src/util/disk_cache.h
@@ -21,17 +21,16 @@
  * IN THE SOFTWARE.
  */
 
-#pragma once
-#ifndef CACHE_H
-#define CACHE_H
+#ifndef DISK_CACHE_H
+#define DISK_CACHE_H
+
+#include <stdint.h>
+#include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdint.h>
-#include <stdbool.h>
-
 /* Size of cache keys in bytes. */
 #define CACHE_KEY_SIZE 20
 




More information about the mesa-commit mailing list