From 1c24e9500b185b1547eeed55be3a8ff7e26f38bf Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Wed, 10 Mar 2021 12:14:29 -0800 Subject: [PATCH] freedreno/batch: Add a way to clone a batch key For autotune, the lifetime of it's hashtable keys doesn't match the batch, so we'll need to clone the key before inserting into the hashtable. Signed-off-by: Rob Clark Part-of: --- src/gallium/drivers/freedreno/freedreno_batch.h | 1 + src/gallium/drivers/freedreno/freedreno_batch_cache.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/gallium/drivers/freedreno/freedreno_batch.h b/src/gallium/drivers/freedreno/freedreno_batch.h index e39a65cb846..0665872cf16 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch.h +++ b/src/gallium/drivers/freedreno/freedreno_batch.h @@ -285,6 +285,7 @@ void fd_batch_check_size(struct fd_batch *batch) assert_dt; uint32_t fd_batch_key_hash(const void *_key); bool fd_batch_key_equals(const void *_a, const void *_b); +struct fd_batch_key * fd_batch_key_clone(void *mem_ctx, const struct fd_batch_key *key); /* not called directly: */ void __fd_batch_describe(char* buf, const struct fd_batch *batch) assert_dt; diff --git a/src/gallium/drivers/freedreno/freedreno_batch_cache.c b/src/gallium/drivers/freedreno/freedreno_batch_cache.c index 621862117f9..5c4b7d926e1 100644 --- a/src/gallium/drivers/freedreno/freedreno_batch_cache.c +++ b/src/gallium/drivers/freedreno/freedreno_batch_cache.c @@ -118,6 +118,15 @@ fd_batch_key_equals(const void *_a, const void *_b) (memcmp(a->surf, b->surf, sizeof(a->surf[0]) * a->num_surfs) == 0); } +struct fd_batch_key * +fd_batch_key_clone(void *mem_ctx, const struct fd_batch_key *key) +{ + unsigned sz = sizeof(struct fd_batch_key) + (sizeof(key->surf[0]) * key->num_surfs); + struct fd_batch_key *new_key = rzalloc_size(mem_ctx, sz); + memcpy(new_key, key, sz); + return new_key; +} + void fd_bc_init(struct fd_batch_cache *cache) {