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 <kenneth@whitecape.org> Reviewed-by: Eduardo Lima Mitev <elima@igalia.com>
This commit is contained in:
@@ -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;
|
||||
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 (old_key->program_string_id == key->program_string_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
if (!old_key) {
|
||||
perf_debug(" Didn't find previous compile in the shader cache for "
|
||||
"debug\n");
|
||||
return;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
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 (old_key->program_string_id == key->program_string_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
if (!old_key) {
|
||||
perf_debug(" Didn't find previous compile in the shader cache for "
|
||||
"debug\n");
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
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 (old_key->program_string_id == key->program_string_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
if (!old_key) {
|
||||
perf_debug(" Didn't find previous compile in the shader cache for "
|
||||
"debug\n");
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
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 (old_key->program_string_id == key->program_string_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
if (!old_key) {
|
||||
perf_debug(" Didn't find previous compile in the shader cache for "
|
||||
"debug\n");
|
||||
return;
|
||||
|
||||
@@ -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;
|
||||
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 (old_key->program_string_id == key->program_string_id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!c) {
|
||||
if (!old_key) {
|
||||
perf_debug(" Didn't find previous compile in the shader cache for debug\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user