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@collabora.com>
This commit is contained in:
Marek Olšák 2016-11-13 16:38:01 +01:00
parent 5b8876609e
commit 31727300e1
7 changed files with 17 additions and 43 deletions

View File

@ -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

View File

@ -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)

View File

@ -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 = \

View File

@ -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)

View File

@ -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 \

View File

@ -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

View File

@ -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