mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
Mesa: short-circuit case when looking up the same program twice in cache
This commit is contained in:
parent
fa1b533012
commit
d63a36ef3a
2 changed files with 22 additions and 9 deletions
|
|
@ -44,6 +44,7 @@ struct cache_item
|
|||
struct gl_program_cache
|
||||
{
|
||||
struct cache_item **items;
|
||||
struct cache_item *last;
|
||||
GLuint size, n_items;
|
||||
};
|
||||
|
||||
|
|
@ -83,6 +84,8 @@ rehash(struct gl_program_cache *cache)
|
|||
struct cache_item *c, *next;
|
||||
GLuint size, i;
|
||||
|
||||
cache->last = NULL;
|
||||
|
||||
size = cache->size * 3;
|
||||
items = (struct cache_item**) _mesa_malloc(size * sizeof(*items));
|
||||
_mesa_memset(items, 0, size * sizeof(*items));
|
||||
|
|
@ -105,6 +108,8 @@ clear_cache(GLcontext *ctx, struct gl_program_cache *cache)
|
|||
{
|
||||
struct cache_item *c, *next;
|
||||
GLuint i;
|
||||
|
||||
cache->last = NULL;
|
||||
|
||||
for (i = 0; i < cache->size; i++) {
|
||||
for (c = cache->items[i]; c; c = next) {
|
||||
|
|
@ -149,18 +154,26 @@ _mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *cache)
|
|||
|
||||
|
||||
struct gl_program *
|
||||
_mesa_search_program_cache(const struct gl_program_cache *cache,
|
||||
_mesa_search_program_cache(struct gl_program_cache *cache,
|
||||
const void *key, GLuint keysize)
|
||||
{
|
||||
const GLuint hash = hash_key(key, keysize);
|
||||
struct cache_item *c;
|
||||
|
||||
for (c = cache->items[hash % cache->size]; c; c = c->next) {
|
||||
if (c->hash == hash && memcmp(c->key, key, keysize) == 0)
|
||||
return c->program;
|
||||
if (cache->last &&
|
||||
memcmp(cache->last->key, key, keysize) == 0) {
|
||||
return cache->last->program;
|
||||
}
|
||||
else {
|
||||
const GLuint hash = hash_key(key, keysize);
|
||||
struct cache_item *c;
|
||||
|
||||
return NULL;
|
||||
for (c = cache->items[hash % cache->size]; c; c = c->next) {
|
||||
if (c->hash == hash && memcmp(c->key, key, keysize) == 0) {
|
||||
cache->last = c;
|
||||
return c->program;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ _mesa_delete_program_cache(GLcontext *ctx, struct gl_program_cache *pc);
|
|||
|
||||
|
||||
extern struct gl_program *
|
||||
_mesa_search_program_cache(const struct gl_program_cache *cache,
|
||||
_mesa_search_program_cache(struct gl_program_cache *cache,
|
||||
const void *key, GLuint keysize);
|
||||
|
||||
extern void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue