Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / util / disk_cache.h
index 488b297ead2762f38575b0023047f746576b2502..29fb37cea1100f1111fd706cf243288e0f286759 100644 (file)
 #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" {
@@ -50,6 +53,14 @@ typedef uint8_t cache_key[CACHE_KEY_SIZE];
 #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,
@@ -80,10 +91,10 @@ disk_cache_format_hex_id(char *buf, const uint8_t *hex_id, unsigned size)
    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) {
@@ -92,12 +103,42 @@ disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
    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, &timestamp)) {
+      _mesa_sha1_update(ctx, &timestamp, 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. */
 
@@ -139,6 +180,12 @@ disk_cache_create(const char *gpu_name, const char *timestamp,
 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.
  */
@@ -207,6 +254,10 @@ void
 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 *
@@ -260,6 +311,13 @@ disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
    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