diff options
author | Dave Airlie <[email protected]> | 2011-06-03 11:05:47 +1000 |
---|---|---|
committer | Dave Airlie <[email protected]> | 2011-06-03 15:26:59 +1000 |
commit | 1dbcb83881f508280ed78dae6834d341936712f2 (patch) | |
tree | d22dab7208ebdd77c0ad8259d7dee62d0f8c5566 /src/gallium/auxiliary/cso_cache/cso_cache.c | |
parent | 970726dd6f9d5361cf7a4002d65ba24ac8baec20 (diff) |
cso: move cso hashes to a more table driven scheme
this removes a bad branch pain in the hash table lookup fn.
Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/cso_cache/cso_cache.c')
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_cache.c | 98 |
1 files changed, 17 insertions, 81 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 900c64df4b9..c6069927b25 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -37,13 +37,7 @@ struct cso_cache { - struct cso_hash *blend_hash; - struct cso_hash *depth_stencil_hash; - struct cso_hash *fs_hash; - struct cso_hash *vs_hash; - struct cso_hash *rasterizer_hash; - struct cso_hash *sampler_hash; - struct cso_hash *velements_hash; + struct cso_hash *hashes[CSO_CACHE_MAX]; int max_size; cso_sanitize_callback sanitize_cb; @@ -86,34 +80,10 @@ unsigned cso_construct_key(void *item, int item_size) return hash_key((item), item_size); } -static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type) +static INLINE struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type) { - struct cso_hash *hash = 0; - - switch(type) { - case CSO_BLEND: - hash = sc->blend_hash; - break; - case CSO_SAMPLER: - hash = sc->sampler_hash; - break; - case CSO_DEPTH_STENCIL_ALPHA: - hash = sc->depth_stencil_hash; - break; - case CSO_RASTERIZER: - hash = sc->rasterizer_hash; - break; - case CSO_FRAGMENT_SHADER: - hash = sc->fs_hash; - break; - case CSO_VERTEX_SHADER: - hash = sc->vs_hash; - break; - case CSO_VELEMENTS: - hash = sc->velements_hash; - break; - } - + struct cso_hash *hash; + hash = sc->hashes[type]; return hash; } @@ -298,17 +268,14 @@ void * cso_take_state(struct cso_cache *sc, struct cso_cache *cso_cache_create(void) { struct cso_cache *sc = MALLOC_STRUCT(cso_cache); + int i; if (sc == NULL) return NULL; sc->max_size = 4096; - sc->blend_hash = cso_hash_create(); - sc->sampler_hash = cso_hash_create(); - sc->depth_stencil_hash = cso_hash_create(); - sc->rasterizer_hash = cso_hash_create(); - sc->fs_hash = cso_hash_create(); - sc->vs_hash = cso_hash_create(); - sc->velements_hash = cso_hash_create(); + for (i = 0; i < CSO_CACHE_MAX; i++) + sc->hashes[i] = cso_hash_create(); + sc->sanitize_cb = sanitize_cb; sc->sanitize_data = 0; @@ -318,33 +285,9 @@ struct cso_cache *cso_cache_create(void) void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, cso_state_callback func, void *user_data) { - struct cso_hash *hash = 0; + struct cso_hash *hash = _cso_hash_for_type(sc, type); struct cso_hash_iter iter; - switch (type) { - case CSO_BLEND: - hash = sc->blend_hash; - break; - case CSO_SAMPLER: - hash = sc->sampler_hash; - break; - case CSO_DEPTH_STENCIL_ALPHA: - hash = sc->depth_stencil_hash; - break; - case CSO_RASTERIZER: - hash = sc->rasterizer_hash; - break; - case CSO_FRAGMENT_SHADER: - hash = sc->fs_hash; - break; - case CSO_VERTEX_SHADER: - hash = sc->vs_hash; - break; - case CSO_VELEMENTS: - hash = sc->velements_hash; - break; - } - iter = cso_hash_first_node(hash); while (!cso_hash_iter_is_null(iter)) { void *state = cso_hash_iter_data(iter); @@ -357,6 +300,7 @@ void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type, void cso_cache_delete(struct cso_cache *sc) { + int i; assert(sc); if (!sc) @@ -371,28 +315,20 @@ void cso_cache_delete(struct cso_cache *sc) cso_for_each_state(sc, CSO_SAMPLER, delete_sampler_state, 0); cso_for_each_state(sc, CSO_VELEMENTS, delete_velements, 0); - cso_hash_delete(sc->blend_hash); - cso_hash_delete(sc->sampler_hash); - cso_hash_delete(sc->depth_stencil_hash); - cso_hash_delete(sc->rasterizer_hash); - cso_hash_delete(sc->fs_hash); - cso_hash_delete(sc->vs_hash); - cso_hash_delete(sc->velements_hash); + for (i = 0; i < CSO_CACHE_MAX; i++) + cso_hash_delete(sc->hashes[i]); + FREE(sc); } void cso_set_maximum_cache_size(struct cso_cache *sc, int number) { + int i; + sc->max_size = number; - sanitize_hash(sc, sc->blend_hash, CSO_BLEND, sc->max_size); - sanitize_hash(sc, sc->depth_stencil_hash, CSO_DEPTH_STENCIL_ALPHA, - sc->max_size); - sanitize_hash(sc, sc->fs_hash, CSO_FRAGMENT_SHADER, sc->max_size); - sanitize_hash(sc, sc->vs_hash, CSO_VERTEX_SHADER, sc->max_size); - sanitize_hash(sc, sc->rasterizer_hash, CSO_RASTERIZER, sc->max_size); - sanitize_hash(sc, sc->sampler_hash, CSO_SAMPLER, sc->max_size); - sanitize_hash(sc, sc->velements_hash, CSO_VELEMENTS, sc->max_size); + for (i = 0; i < CSO_CACHE_MAX; i++) + sanitize_hash(sc, sc->hashes[i], i, sc->max_size); } int cso_maximum_cache_size(const struct cso_cache *sc) |