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;
#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)
{
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,
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 );
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;
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;
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;
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;
}