summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2016-11-11 13:31:06 -0800
committerKenneth Graunke <[email protected]>2017-01-17 21:47:10 -0800
commitf9edc550b2bb76f77e33b6cb122a91f266bc5958 (patch)
treed837ff13224d56aa2b9be0a510c82d5a61cecb92 /src
parente7d4008ebfe561ee0aa3df6cdcfd39a8842ed659 (diff)
i965: Make a helper for finding an existing shader variant.
We had five copies of the same "walk the cache and look for an existing shader variant for this program" code. Now we have one helper function that returns the key. Signed-off-by: Kenneth Graunke <[email protected]> Reviewed-by: Eduardo Lima Mitev <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/dri/i965/brw_gs.c22
-rw-r--r--src/mesa/drivers/dri/i965/brw_program_cache.c38
-rw-r--r--src/mesa/drivers/dri/i965/brw_state.h5
-rw-r--r--src/mesa/drivers/dri/i965/brw_tcs.c22
-rw-r--r--src/mesa/drivers/dri/i965/brw_tes.c22
-rw-r--r--src/mesa/drivers/dri/i965/brw_vs.c22
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm.c22
7 files changed, 68 insertions, 85 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_gs.c b/src/mesa/drivers/dri/i965/brw_gs.c
index b7fb9f9c1ea..299620311a5 100644
--- a/src/mesa/drivers/dri/i965/brw_gs.c
+++ b/src/mesa/drivers/dri/i965/brw_gs.c
@@ -40,26 +40,14 @@ static void
brw_gs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
const struct brw_gs_prog_key *key)
{
- struct brw_cache_item *c = NULL;
- const struct brw_gs_prog_key *old_key = NULL;
- bool found = false;
-
perf_debug("Recompiling geometry shader for program %d\n", prog->Id);
- for (unsigned int i = 0; i < brw->cache.size; i++) {
- for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_CACHE_GS_PROG) {
- old_key = c->key;
-
- if (old_key->program_string_id == key->program_string_id)
- break;
- }
- }
- if (c)
- break;
- }
+ bool found = false;
+ const struct brw_gs_prog_key *old_key =
+ brw_find_previous_compile(&brw->cache, BRW_CACHE_GS_PROG,
+ key->program_string_id);
- if (!c) {
+ if (!old_key) {
perf_debug(" Didn't find previous compile in the shader cache for "
"debug\n");
return;
diff --git a/src/mesa/drivers/dri/i965/brw_program_cache.c b/src/mesa/drivers/dri/i965/brw_program_cache.c
index 3947904ac50..3d95372bc0e 100644
--- a/src/mesa/drivers/dri/i965/brw_program_cache.c
+++ b/src/mesa/drivers/dri/i965/brw_program_cache.c
@@ -55,6 +55,27 @@
#define FILE_DEBUG_FLAG DEBUG_STATE
+static unsigned
+get_program_string_id(enum brw_cache_id cache_id, const void *key)
+{
+ switch (cache_id) {
+ case BRW_CACHE_VS_PROG:
+ return ((struct brw_vs_prog_key *) key)->program_string_id;
+ case BRW_CACHE_TCS_PROG:
+ return ((struct brw_tcs_prog_key *) key)->program_string_id;
+ case BRW_CACHE_TES_PROG:
+ return ((struct brw_tes_prog_key *) key)->program_string_id;
+ case BRW_CACHE_GS_PROG:
+ return ((struct brw_gs_prog_key *) key)->program_string_id;
+ case BRW_CACHE_CS_PROG:
+ return ((struct brw_cs_prog_key *) key)->program_string_id;
+ case BRW_CACHE_FS_PROG:
+ return ((struct brw_wm_prog_key *) key)->program_string_id;
+ default:
+ unreachable("no program string id for this kind of program");
+ }
+}
+
static GLuint
hash_key(struct brw_cache_item *item)
{
@@ -268,6 +289,23 @@ brw_alloc_item_data(struct brw_cache *cache, uint32_t size)
return offset;
}
+const void *
+brw_find_previous_compile(struct brw_cache *cache,
+ enum brw_cache_id cache_id,
+ unsigned program_string_id)
+{
+ for (unsigned i = 0; i < cache->size; i++) {
+ for (struct brw_cache_item *c = cache->items[i]; c; c = c->next) {
+ if (c->cache_id == cache_id &&
+ get_program_string_id(cache_id, c->key) == program_string_id) {
+ return c->key;
+ }
+ }
+ }
+
+ return NULL;
+}
+
void
brw_upload_cache(struct brw_cache *cache,
enum brw_cache_id cache_id,
diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h
index 176557b7c45..bd82212be4d 100644
--- a/src/mesa/drivers/dri/i965/brw_state.h
+++ b/src/mesa/drivers/dri/i965/brw_state.h
@@ -235,6 +235,11 @@ bool brw_search_cache(struct brw_cache *cache,
const void *key,
GLuint key_size,
uint32_t *inout_offset, void *inout_aux);
+
+const void *brw_find_previous_compile(struct brw_cache *cache,
+ enum brw_cache_id cache_id,
+ unsigned program_string_id);
+
void brw_program_cache_check_size(struct brw_context *brw);
void brw_init_caches( struct brw_context *brw );
diff --git a/src/mesa/drivers/dri/i965/brw_tcs.c b/src/mesa/drivers/dri/i965/brw_tcs.c
index 78ad257e3b9..bbba7496fa6 100644
--- a/src/mesa/drivers/dri/i965/brw_tcs.c
+++ b/src/mesa/drivers/dri/i965/brw_tcs.c
@@ -120,27 +120,15 @@ static void
brw_tcs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
const struct brw_tcs_prog_key *key)
{
- struct brw_cache_item *c = NULL;
- const struct brw_tcs_prog_key *old_key = NULL;
- bool found = false;
-
perf_debug("Recompiling tessellation control shader for program %d\n",
prog->Id);
- for (unsigned int i = 0; i < brw->cache.size; i++) {
- for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_CACHE_TCS_PROG) {
- old_key = c->key;
-
- if (old_key->program_string_id == key->program_string_id)
- break;
- }
- }
- if (c)
- break;
- }
+ bool found = false;
+ const struct brw_tcs_prog_key *old_key =
+ brw_find_previous_compile(&brw->cache, BRW_CACHE_TCS_PROG,
+ key->program_string_id);
- if (!c) {
+ if (!old_key) {
perf_debug(" Didn't find previous compile in the shader cache for "
"debug\n");
return;
diff --git a/src/mesa/drivers/dri/i965/brw_tes.c b/src/mesa/drivers/dri/i965/brw_tes.c
index 57dcda7140a..cb12b9c5a69 100644
--- a/src/mesa/drivers/dri/i965/brw_tes.c
+++ b/src/mesa/drivers/dri/i965/brw_tes.c
@@ -38,27 +38,15 @@ static void
brw_tes_debug_recompile(struct brw_context *brw, struct gl_program *prog,
const struct brw_tes_prog_key *key)
{
- struct brw_cache_item *c = NULL;
- const struct brw_tes_prog_key *old_key = NULL;
- bool found = false;
-
perf_debug("Recompiling tessellation evaluation shader for program %d\n",
prog->Id);
- for (unsigned int i = 0; i < brw->cache.size; i++) {
- for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_CACHE_TES_PROG) {
- old_key = c->key;
-
- if (old_key->program_string_id == key->program_string_id)
- break;
- }
- }
- if (c)
- break;
- }
+ bool found = false;
+ const struct brw_tes_prog_key *old_key =
+ brw_find_previous_compile(&brw->cache, BRW_CACHE_TES_PROG,
+ key->program_string_id);
- if (!c) {
+ if (!old_key) {
perf_debug(" Didn't find previous compile in the shader cache for "
"debug\n");
return;
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index afb1f203308..5d199393181 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -88,26 +88,14 @@ static void
brw_vs_debug_recompile(struct brw_context *brw, struct gl_program *prog,
const struct brw_vs_prog_key *key)
{
- struct brw_cache_item *c = NULL;
- const struct brw_vs_prog_key *old_key = NULL;
- bool found = false;
-
perf_debug("Recompiling vertex shader for program %d\n", prog->Id);
- for (unsigned int i = 0; i < brw->cache.size; i++) {
- for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_CACHE_VS_PROG) {
- old_key = c->key;
-
- if (old_key->program_string_id == key->program_string_id)
- break;
- }
- }
- if (c)
- break;
- }
+ bool found = false;
+ const struct brw_vs_prog_key *old_key =
+ brw_find_previous_compile(&brw->cache, BRW_CACHE_VS_PROG,
+ key->program_string_id);
- if (!c) {
+ if (!old_key) {
perf_debug(" Didn't find previous compile in the shader cache for "
"debug\n");
return;
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index bd2b24a3bfa..a774720202a 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -70,26 +70,14 @@ static void
brw_wm_debug_recompile(struct brw_context *brw, struct gl_program *prog,
const struct brw_wm_prog_key *key)
{
- struct brw_cache_item *c = NULL;
- const struct brw_wm_prog_key *old_key = NULL;
- bool found = false;
-
perf_debug("Recompiling fragment shader for program %d\n", prog->Id);
- for (unsigned int i = 0; i < brw->cache.size; i++) {
- for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_CACHE_FS_PROG) {
- old_key = c->key;
-
- if (old_key->program_string_id == key->program_string_id)
- break;
- }
- }
- if (c)
- break;
- }
+ bool found = false;
+ const struct brw_wm_prog_key *old_key =
+ brw_find_previous_compile(&brw->cache, BRW_CACHE_FS_PROG,
+ key->program_string_id);
- if (!c) {
+ if (!old_key) {
perf_debug(" Didn't find previous compile in the shader cache for debug\n");
return;
}