summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdj0c <kdj0c@djinvi.net>2017-01-24 17:08:22 +0100
committerEdward O'Callaghan <funfunctor@folklore1984.net>2017-02-17 12:07:34 +1100
commit40fb9993005ba59ef80e74a1cd8236f938d27a4f (patch)
tree15a954d17f4aa3fc23a3f9ecf725c2d435bf3565
parentde12160a6415b002f938ec08966af7351e584b84 (diff)
radeonsi: add support for an on-disk shader cacheshader-cache-radeonsi5
V2 (Timothy Arceri): - when loading from disk cache also binary insert into memory cache.
-rw-r--r--src/gallium/drivers/radeonsi/si_pipe.h1
-rw-r--r--src/gallium/drivers/radeonsi/si_state_shaders.c43
2 files changed, 37 insertions, 7 deletions
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index fb24babe61..2470f8969d 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -27,6 +27,7 @@
#define SI_PIPE_H
#include "si_shader.h"
+#include "util/disk_cache.h"
#ifdef PIPE_ARCH_BIG_ENDIAN
#define SI_BIG_ENDIAN 1
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index bde02f520a..98904dead2 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -36,6 +36,9 @@
#include "util/u_memory.h"
#include "util/u_prim.h"
+#include "util/disk_cache.h"
+#include "util/mesa-sha1.h"
+
/* SHADER_CACHE */
/**
@@ -182,10 +185,12 @@ static bool si_load_shader_binary(struct si_shader *shader, void *binary)
*/
static bool si_shader_cache_insert_shader(struct si_screen *sscreen,
void *tgsi_binary,
- struct si_shader *shader)
+ struct si_shader *shader,
+ bool insert_into_disk_cache)
{
void *hw_binary;
struct hash_entry *entry;
+ uint8_t key[CACHE_KEY_SIZE];
entry = _mesa_hash_table_search(sscreen->shader_cache, tgsi_binary);
if (entry)
@@ -201,6 +206,11 @@ static bool si_shader_cache_insert_shader(struct si_screen *sscreen,
return false;
}
+ if (sscreen->b.b.disk_shader_cache && insert_into_disk_cache) {
+ _mesa_sha1_compute(tgsi_binary, *((uint32_t *)tgsi_binary), key);
+ disk_cache_put(sscreen->b.b.disk_shader_cache, key, hw_binary, *((uint32_t *) hw_binary));
+ }
+
return true;
}
@@ -210,12 +220,31 @@ static bool si_shader_cache_load_shader(struct si_screen *sscreen,
{
struct hash_entry *entry =
_mesa_hash_table_search(sscreen->shader_cache, tgsi_binary);
- if (!entry)
- return false;
+ if (!entry) {
+ if (sscreen->b.b.disk_shader_cache) {
+ uint8_t tg_key[CACHE_KEY_SIZE];
+ size_t tg_size = *((uint32_t *) tgsi_binary);
+ char *cached;
+
+ _mesa_sha1_compute(tgsi_binary, tg_size, tg_key);
+ cached = disk_cache_get(sscreen->b.b.disk_shader_cache, tg_key, &tg_size);
+ if (!cached)
+ return false;
- if (!si_load_shader_binary(shader, entry->data))
- return false;
+ if (!si_load_shader_binary(shader, cached))
+ return false;
+ if (!si_shader_cache_insert_shader(sscreen, tgsi_binary, shader, false))
+ FREE(tgsi_binary);
+ } else {
+ return false;
+ }
+ } else {
+ if (si_load_shader_binary(shader, entry->data))
+ FREE(tgsi_binary);
+ else
+ return false;
+ }
p_atomic_inc(&sscreen->b.num_shader_cache_hits);
return true;
}
@@ -251,6 +280,7 @@ bool si_init_shader_cache(struct si_screen *sscreen)
_mesa_hash_table_create(NULL,
si_shader_cache_key_hash,
si_shader_cache_key_equals);
+
return sscreen->shader_cache != NULL;
}
@@ -1374,7 +1404,6 @@ void si_init_shader_selector_async(void *job, int thread_index)
if (tgsi_binary &&
si_shader_cache_load_shader(sscreen, tgsi_binary, shader)) {
- FREE(tgsi_binary);
pipe_mutex_unlock(sscreen->shader_cache_mutex);
} else {
pipe_mutex_unlock(sscreen->shader_cache_mutex);
@@ -1390,7 +1419,7 @@ void si_init_shader_selector_async(void *job, int thread_index)
if (tgsi_binary) {
pipe_mutex_lock(sscreen->shader_cache_mutex);
- if (!si_shader_cache_insert_shader(sscreen, tgsi_binary, shader))
+ if (!si_shader_cache_insert_shader(sscreen, tgsi_binary, shader, true))
FREE(tgsi_binary);
pipe_mutex_unlock(sscreen->shader_cache_mutex);
}