#ifndef DISK_CACHE_H
#define DISK_CACHE_H
-#ifdef ENABLE_SHADER_CACHE
+#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
+#include <stdio.h>
+#include "util/build_id.h"
#endif
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/stat.h>
+#include "util/mesa-sha1.h"
#ifdef __cplusplus
extern "C" {
#define CACHE_ITEM_TYPE_UNKNOWN 0x0
#define CACHE_ITEM_TYPE_GLSL 0x1
+typedef void
+(*disk_cache_put_cb) (const void *key, signed long keySize,
+ const void *value, signed long valueSize);
+
+typedef signed long
+(*disk_cache_get_cb) (const void *key, signed long keySize,
+ void *value, signed long valueSize);
+
struct cache_item_metadata {
/**
* The cache item type. This could be used to identify a GLSL cache item,
return buf;
}
+#ifdef HAVE_DLADDR
static inline bool
disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
{
-#ifdef ENABLE_SHADER_CACHE
Dl_info info;
struct stat st;
if (!dladdr(ptr, &info) || !info.dli_fname) {
if (stat(info.dli_fname, &st)) {
return false;
}
+
+ if (!st.st_mtime) {
+ fprintf(stderr, "Mesa: The provided filesystem timestamp for the cache "
+ "is bogus! Disabling On-disk cache.\n");
+ return false;
+ }
+
*timestamp = st.st_mtime;
+
+ return true;
+}
+
+static inline bool
+disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx)
+{
+ uint32_t timestamp;
+
+#ifdef HAVE_DL_ITERATE_PHDR
+ const struct build_id_note *note = NULL;
+ if ((note = build_id_find_nhdr_for_addr(ptr))) {
+ _mesa_sha1_update(ctx, build_id_data(note), build_id_length(note));
+ } else
+#endif
+ if (disk_cache_get_function_timestamp(ptr, ×tamp)) {
+ _mesa_sha1_update(ctx, ×tamp, sizeof(timestamp));
+ } else
+ return false;
return true;
+}
#else
+static inline bool
+disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx)
+{
return false;
-#endif
}
+#endif
/* Provide inlined stub functions if the shader cache is disabled. */
void
disk_cache_destroy(struct disk_cache *cache);
+/* Wait for all previous disk_cache_put() calls to be processed (used for unit
+ * testing).
+ */
+void
+disk_cache_wait_for_idle(struct disk_cache *cache);
+
/**
* Remove the item in the cache under the name \key.
*/
disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
cache_key key);
+void
+disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_put_cb put,
+ disk_cache_get_cb get);
+
#else
static inline struct disk_cache *
return;
}
+static inline void
+disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_put_cb put,
+ disk_cache_get_cb get)
+{
+ return;
+}
+
#endif /* ENABLE_SHADER_CACHE */
#ifdef __cplusplus