[Mesa-dev] [PATCH 1/2] util: import cache.c/h from glsl
Marek Olšák
maraeo at gmail.com
Sun Nov 13 16:05:12 UTC 2016
From: Marek Olšák <marek.olsak at amd.com>
---
src/compiler/Makefile.glsl.am | 4 ----
src/compiler/Makefile.sources | 4 ----
src/compiler/glsl/tests/cache_test.c | 2 +-
src/util/Makefile.sources | 2 ++
src/{compiler/glsl/cache.c => util/disk_cache.c} | 16 +++++++++-------
src/{compiler/glsl/cache.h => util/disk_cache.h} | 4 ++--
6 files changed, 14 insertions(+), 18 deletions(-)
rename src/{compiler/glsl/cache.c => util/disk_cache.c} (98%)
rename src/{compiler/glsl/cache.h => util/disk_cache.h} (99%)
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
@@ -124,24 +124,20 @@ glsl_glcpp_glcpp_LDADD = \
-lm
glsl_libglsl_la_LIBADD = \
nir/libnir.la \
glsl/libglcpp.la
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)
glsl_libstandalone_la_LIBADD = \
glsl/libglsl.la \
$(top_builddir)/src/libglsl_util.la \
$(top_builddir)/src/util/libmesautil.la \
$(PTHREAD_LIBS)
glsl_compiler_SOURCES = \
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
@@ -129,24 +129,20 @@ LIBGLSL_FILES = \
glsl/opt_redundant_jumps.cpp \
glsl/opt_structure_splitting.cpp \
glsl/opt_swizzle_swizzle.cpp \
glsl/opt_tree_grafting.cpp \
glsl/opt_vectorize.cpp \
glsl/program.h \
glsl/propagate_invariance.cpp \
glsl/s_expression.cpp \
glsl/s_expression.h
-LIBGLSL_SHADER_CACHE_FILES = \
- glsl/cache.c \
- glsl/cache.h
-
# glsl_compiler
GLSL_COMPILER_CXX_FILES = \
glsl/ir_builder_print_visitor.cpp \
glsl/ir_builder_print_visitor.h \
glsl/opt_add_neg_to_sub.h \
glsl/standalone_scaffolding.cpp \
glsl/standalone_scaffolding.h \
glsl/standalone.cpp \
glsl/standalone.h
diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index 724dfcd..fce2bf4 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -25,21 +25,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ftw.h>
#include <errno.h>
#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, ...)
{
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
@@ -1,16 +1,18 @@
MESA_UTIL_FILES := \
bitscan.c \
bitscan.h \
bitset.h \
debug.c \
debug.h \
+ disk_cache.c \
+ disk_cache.h \
format_r11g11b10f.h \
format_rgb9e5.h \
format_srgb.h \
half_float.c \
half_float.h \
hash_table.c \
hash_table.h \
list.h \
macros.h \
mesa-sha1.c \
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..6a97d44 100644
--- a/src/compiler/glsl/cache.c
+++ b/src/util/disk_cache.c
@@ -33,21 +33,23 @@
#include <fcntl.h>
#include <pwd.h>
#include <errno.h>
#include <dirent.h>
#include "util/u_atomic.h"
#include "util/mesa-sha1.h"
#include "util/ralloc.h"
#include "main/errors.h"
-#include "cache.h"
+#include "disk_cache.h"
+
+#ifdef ENABLE_SHADER_CACHE
/* Number of bits to mask off from a cache key to get an index. */
#define CACHE_INDEX_KEY_BITS 16
/* Mask for computing an index from a key. */
#define CACHE_INDEX_KEY_MASK ((1 << CACHE_INDEX_KEY_BITS) - 1)
/* The number of keys that can be stored in the index. */
#define CACHE_INDEX_MAX_KEYS (1 << CACHE_INDEX_KEY_BITS)
@@ -79,34 +81,32 @@ mkdir_if_needed(char *path)
{
struct stat sb;
/* If the path exists already, then our work is done if it's a
* directory, but it's an error if it is not.
*/
if (stat(path, &sb) == 0) {
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;
}
}
int ret = mkdir(path, 0755);
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;
}
/* Concatenate an existing path and a new name to form a new path. If the new
* path does not exist as a directory, create it then return the resulting
* name of the new path (ralloc'ed off of 'ctx').
*
* Returns NULL on any error, such as:
*
@@ -701,10 +701,12 @@ bool
cache_has_key(struct program_cache *cache, cache_key key)
{
uint32_t *key_chunk = (uint32_t *) key;
int i = *key_chunk & CACHE_INDEX_KEY_MASK;
unsigned char *entry;
entry = &cache->stored_keys[i + CACHE_KEY_SIZE];
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..066233f 100644
--- a/src/compiler/glsl/cache.h
+++ b/src/util/disk_cache.h
@@ -15,22 +15,22 @@
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma once
-#ifndef CACHE_H
-#define CACHE_H
+#ifndef DISK_CACHE_H
+#define DISK_CACHE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
/* Size of cache keys in bytes. */
#define CACHE_KEY_SIZE 20
--
2.7.4
More information about the mesa-dev
mailing list