This removes one level of indirection.
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
struct cso_cache {
- struct cso_hash *hashes[CSO_CACHE_MAX];
+ struct cso_hash hashes[CSO_CACHE_MAX];
int max_size;
cso_sanitize_callback sanitize_cb;
static inline struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type)
{
- struct cso_hash *hash;
- hash = sc->hashes[type];
- return hash;
+ return &sc->hashes[type];
}
static void delete_blend_state(void *state, UNUSED void *data)
sc->max_size = 4096;
for (i = 0; i < CSO_CACHE_MAX; i++)
- sc->hashes[i] = cso_hash_create();
+ cso_hash_init(&sc->hashes[i]);
sc->sanitize_cb = sanitize_cb;
sc->sanitize_data = 0;
cso_for_each_state(sc, CSO_VELEMENTS, delete_velements, 0);
for (i = 0; i < CSO_CACHE_MAX; i++)
- cso_hash_delete(sc->hashes[i]);
+ cso_hash_deinit(&sc->hashes[i]);
FREE(sc);
}
sc->max_size = number;
for (i = 0; i < CSO_CACHE_MAX; i++)
- sanitize_hash(sc, sc->hashes[i], i, sc->max_size);
+ sanitize_hash(sc, &sc->hashes[i], i, sc->max_size);
}
int cso_maximum_cache_size(const struct cso_cache *sc)
}
}
-struct cso_hash * cso_hash_create(void)
+bool cso_hash_init(struct cso_hash *hash)
{
- struct cso_hash *hash = MALLOC_STRUCT(cso_hash);
- if (!hash)
- return NULL;
-
hash->data.d = MALLOC_STRUCT(cso_hash_data);
- if (!hash->data.d) {
- FREE(hash);
- return NULL;
- }
+ if (!hash->data.d)
+ return false;
hash->data.d->fakeNext = 0;
hash->data.d->buckets = 0;
hash->data.d->userNumBits = (short)MinNumBits;
hash->data.d->numBits = 0;
hash->data.d->numBuckets = 0;
-
- return hash;
+ return true;
}
-void cso_hash_delete(struct cso_hash *hash)
+void cso_hash_deinit(struct cso_hash *hash)
{
struct cso_node *e_for_x = (struct cso_node *)(hash->data.d);
struct cso_node **bucket = (struct cso_node **)(hash->data.d->buckets);
}
FREE(hash->data.d->buckets);
FREE(hash->data.d);
- FREE(hash);
+ hash->data.d = NULL;
}
unsigned cso_hash_iter_key(struct cso_hash_iter iter)
int numBuckets;
};
-struct cso_hash *cso_hash_create(void);
-void cso_hash_delete(struct cso_hash *hash);
+bool cso_hash_init(struct cso_hash *hash);
+void cso_hash_deinit(struct cso_hash *hash);
int cso_hash_size(struct cso_hash *hash);
struct sanity_check_ctx
{
struct tgsi_iterate_context iter;
- struct cso_hash *regs_decl;
- struct cso_hash *regs_used;
- struct cso_hash *regs_ind_used;
+ struct cso_hash regs_decl;
+ struct cso_hash regs_used;
+ struct cso_hash regs_ind_used;
uint num_imms;
uint num_instructions;
const scan_register *reg)
{
void *data = cso_hash_find_data_from_template(
- ctx->regs_decl, scan_register_key(reg),
+ &ctx->regs_decl, scan_register_key(reg),
(void*)reg, sizeof(scan_register));
return data ? TRUE : FALSE;
}
uint file )
{
struct cso_hash_iter iter =
- cso_hash_first_node(ctx->regs_decl);
+ cso_hash_first_node(&ctx->regs_decl);
while (!cso_hash_iter_is_null(iter)) {
scan_register *reg = (scan_register *)cso_hash_iter_data(iter);
scan_register *reg)
{
void *data = cso_hash_find_data_from_template(
- ctx->regs_used, scan_register_key(reg),
+ &ctx->regs_used, scan_register_key(reg),
reg, sizeof(scan_register));
return data ? TRUE : FALSE;
}
struct sanity_check_ctx *ctx,
scan_register *reg)
{
- return cso_hash_contains(ctx->regs_ind_used, reg->file);
+ return cso_hash_contains(&ctx->regs_ind_used, reg->file);
}
static const char *file_names[TGSI_FILE_COUNT] =
if (!is_any_register_declared( ctx, reg->file ))
report_error( ctx, "%s: Undeclared %s register", file_names[reg->file], name );
if (!is_ind_register_used(ctx, reg))
- cso_hash_insert(ctx->regs_ind_used, reg->file, reg);
+ cso_hash_insert(&ctx->regs_ind_used, reg->file, reg);
else
FREE(reg);
}
}
}
if (!is_register_used( ctx, reg ))
- cso_hash_insert(ctx->regs_used, scan_register_key(reg), reg);
+ cso_hash_insert(&ctx->regs_used, scan_register_key(reg), reg);
else
FREE(reg);
}
if (is_register_declared( ctx, reg))
report_error( ctx, "%s[%u]: The same register declared more than once",
file_names[reg->file], reg->indices[0] );
- cso_hash_insert(ctx->regs_decl,
+ cso_hash_insert(&ctx->regs_decl,
scan_register_key(reg),
reg);
}
*/
reg = MALLOC(sizeof(scan_register));
fill_scan_register1d(reg, TGSI_FILE_IMMEDIATE, ctx->num_imms);
- cso_hash_insert(ctx->regs_decl, scan_register_key(reg), reg);
+ cso_hash_insert(&ctx->regs_decl, scan_register_key(reg), reg);
ctx->num_imms++;
/* Check data type validity.
*/
{
struct cso_hash_iter iter =
- cso_hash_first_node(ctx->regs_decl);
+ cso_hash_first_node(&ctx->regs_decl);
while (!cso_hash_iter_is_null(iter)) {
scan_register *reg = (scan_register *)cso_hash_iter_data(iter);
assert(reg->file < TGSI_FILE_COUNT);
FREE(reg);
}
- cso_hash_delete(hash);
+ cso_hash_deinit(hash);
}
boolean
ctx.iter.iterate_property = iter_property;
ctx.iter.epilog = epilog;
- ctx.regs_decl = cso_hash_create();
- ctx.regs_used = cso_hash_create();
- ctx.regs_ind_used = cso_hash_create();
+ cso_hash_init(&ctx.regs_decl);
+ cso_hash_init(&ctx.regs_used);
+ cso_hash_init(&ctx.regs_ind_used);
ctx.num_imms = 0;
ctx.num_instructions = 0;
ctx.print = debug_get_option_print_sanity();
retval = tgsi_iterate_shader( tokens, &ctx.iter );
- regs_hash_destroy(ctx.regs_decl);
- regs_hash_destroy(ctx.regs_used);
- regs_hash_destroy(ctx.regs_ind_used);
+ regs_hash_destroy(&ctx.regs_decl);
+ regs_hash_destroy(&ctx.regs_used);
+ regs_hash_destroy(&ctx.regs_ind_used);
if (retval == FALSE)
return FALSE;
#include "cso_cache/cso_hash.h"
struct translate_cache {
- struct cso_hash *hash;
+ struct cso_hash hash;
};
struct translate_cache * translate_cache_create( void )
return NULL;
}
- cache->hash = cso_hash_create();
+ cso_hash_init(&cache->hash);
return cache;
}
static inline void delete_translates(struct translate_cache *cache)
{
- struct cso_hash *hash = cache->hash;
+ struct cso_hash *hash = &cache->hash;
struct cso_hash_iter iter = cso_hash_first_node(hash);
while (!cso_hash_iter_is_null(iter)) {
struct translate *state = (struct translate*)cso_hash_iter_data(iter);
void translate_cache_destroy(struct translate_cache *cache)
{
delete_translates(cache);
- cso_hash_delete(cache->hash);
+ cso_hash_deinit(&cache->hash);
FREE(cache);
}
{
unsigned hash_key = create_key(key);
struct translate *translate = (struct translate*)
- cso_hash_find_data_from_template(cache->hash,
+ cso_hash_find_data_from_template(&cache->hash,
hash_key,
key, sizeof(*key));
if (!translate) {
/* create/insert */
translate = translate_create(key);
- cso_hash_insert(cache->hash, hash_key, translate);
+ cso_hash_insert(&cache->hash, hash_key, translate);
}
return translate;
struct util_hash_table
{
- struct cso_hash *cso;
+ struct cso_hash cso;
/** Hash function */
unsigned (*hash)(void *key);
if (!ht)
return NULL;
- ht->cso = cso_hash_create();
- if(!ht->cso) {
+ if (!cso_hash_init(&ht->cso)) {
FREE(ht);
return NULL;
}
struct cso_hash_iter iter;
struct util_hash_table_item *item;
- iter = cso_hash_find(ht->cso, key_hash);
+ iter = cso_hash_find(&ht->cso, key_hash);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
if (!ht->compare(item->key, key))
struct cso_hash_iter iter;
struct util_hash_table_item *item;
- iter = cso_hash_find(ht->cso, key_hash);
+ iter = cso_hash_find(&ht->cso, key_hash);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
if (!ht->compare(item->key, key))
item->key = key;
item->value = value;
- iter = cso_hash_insert(ht->cso, key_hash, item);
+ iter = cso_hash_insert(&ht->cso, key_hash, item);
if(cso_hash_iter_is_null(iter)) {
FREE(item);
return PIPE_ERROR_OUT_OF_MEMORY;
assert(item);
FREE(item);
- cso_hash_erase(ht->cso, iter);
+ cso_hash_erase(&ht->cso, iter);
}
if (!ht)
return;
- iter = cso_hash_first_node(ht->cso);
+ iter = cso_hash_first_node(&ht->cso);
while (!cso_hash_iter_is_null(iter)) {
- item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter));
+ item = (struct util_hash_table_item *)cso_hash_take(&ht->cso, cso_hash_iter_key(iter));
FREE(item);
- iter = cso_hash_first_node(ht->cso);
+ iter = cso_hash_first_node(&ht->cso);
}
}
if (!ht)
return PIPE_ERROR_BAD_INPUT;
- iter = cso_hash_first_node(ht->cso);
+ iter = cso_hash_first_node(&ht->cso);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
result = callback(item->key, item->value, data);
if (!ht)
return;
- iter = cso_hash_first_node(ht->cso);
+ iter = cso_hash_first_node(&ht->cso);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
FREE(item);
iter = cso_hash_iter_next(iter);
}
- cso_hash_delete(ht->cso);
+ cso_hash_deinit(&ht->cso);
FREE(ht);
}
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
- if(!us->u.hash)
- us->u.hash = cso_hash_create();
+ if (!us->u.hash.data.d)
+ cso_hash_init(&us->u.hash);
- ps = cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
+ ps = cso_hash_iter_data(cso_hash_find(&us->u.hash, (layer << 8) | level));
}
else
{
pipe_surface_init(ctx, ps, pt, level, layer);
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
- cso_hash_insert(us->u.hash, (layer << 8) | level, ps);
+ cso_hash_insert(&us->u.hash, (layer << 8) | level, ps);
else
us->u.array[level] = ps;
struct pipe_resource *pt = ps->texture;
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
- cso_hash_erase(us->u.hash, cso_hash_find(us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level));
+ cso_hash_erase(&us->u.hash, cso_hash_find(&us->u.hash, (ps->u.tex.first_layer << 8) | ps->u.tex.level));
}
else
us->u.array[ps->u.tex.level] = 0;
{
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
- if(us->u.hash)
+ if (&us->u.hash)
{
struct cso_hash_iter iter;
- iter = cso_hash_first_node(us->u.hash);
+ iter = cso_hash_first_node(&us->u.hash);
while (!cso_hash_iter_is_null(iter)) {
destroy_surface(cso_hash_iter_data(iter));
iter = cso_hash_iter_next(iter);
}
- cso_hash_delete(us->u.hash);
- us->u.hash = NULL;
+ cso_hash_deinit(&us->u.hash);
}
}
else
{
union
{
- struct cso_hash *hash;
+ struct cso_hash hash;
struct pipe_surface **array;
void* pv;
} u;
return 0;
if(unlikely(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE))
- return cso_hash_iter_data(cso_hash_find(us->u.hash, (layer << 8) | level));
+ return cso_hash_iter_data(cso_hash_find(&us->u.hash, (layer << 8) | level));
else
return us->u.array[level];
}
struct xa_shaders {
struct xa_context *r;
- struct cso_hash *vs_hash;
- struct cso_hash *fs_hash;
+ struct cso_hash vs_hash;
+ struct cso_hash fs_hash;
};
static inline void
struct xa_shaders *sc = CALLOC_STRUCT(xa_shaders);
sc->r = r;
- sc->vs_hash = cso_hash_create();
- sc->fs_hash = cso_hash_create();
+ cso_hash_init(&sc->vs_hash);
+ cso_hash_init(&sc->fs_hash);
return sc;
}
}
iter = cso_hash_erase(hash, iter);
}
- cso_hash_delete(hash);
+ cso_hash_deinit(hash);
}
void
xa_shaders_destroy(struct xa_shaders *sc)
{
- cache_destroy(sc->r->cso, sc->vs_hash, PIPE_SHADER_VERTEX);
- cache_destroy(sc->r->cso, sc->fs_hash, PIPE_SHADER_FRAGMENT);
+ cache_destroy(sc->r->cso, &sc->vs_hash, PIPE_SHADER_VERTEX);
+ cache_destroy(sc->r->cso, &sc->fs_hash, PIPE_SHADER_FRAGMENT);
FREE(sc);
}
void *vs, *fs;
vs = shader_from_cache(sc->r->pipe, PIPE_SHADER_VERTEX,
- sc->vs_hash, vs_traits);
+ &sc->vs_hash, vs_traits);
fs = shader_from_cache(sc->r->pipe, PIPE_SHADER_FRAGMENT,
- sc->fs_hash, fs_traits);
+ &sc->fs_hash, fs_traits);
debug_assert(vs && fs);
if (!vs || !fs)