Mesa (main): iris: Add and use bucket_info_for_heap
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Dec 14 07:54:54 UTC 2021
Module: Mesa
Branch: main
Commit: 305677e242e9092cd37e2bdee1cbfbd04fc0a436
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=305677e242e9092cd37e2bdee1cbfbd04fc0a436
Author: Nanley Chery <nanley.g.chery at intel.com>
Date: Wed Dec 1 13:48:57 2021 -0500
iris: Add and use bucket_info_for_heap
Add a helper that maps a heap to the related cache bucket information.
This avoids complicating existing ternaries when new cache buckets are
added.
Rework:
* Jordan: Add default and set pointers in default branch of
bucket_info_for_heap to prevent "may be used uninitialized" warning
in release builds.
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14012>
---
src/gallium/drivers/iris/iris_bufmgr.c | 41 ++++++++++++++++++++++++----------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index 6bc04549ba3..18571f81daf 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -269,6 +269,28 @@ find_and_ref_external_bo(struct hash_table *ht, unsigned int key)
return bo;
}
+static void
+bucket_info_for_heap(struct iris_bufmgr *bufmgr, enum iris_heap heap,
+ struct bo_cache_bucket **cache_bucket, int **num_buckets)
+{
+ switch (heap) {
+ case IRIS_HEAP_SYSTEM_MEMORY:
+ *cache_bucket = bufmgr->cache_bucket;
+ *num_buckets = &bufmgr->num_buckets;
+ break;
+ case IRIS_HEAP_DEVICE_LOCAL:
+ *cache_bucket = bufmgr->local_cache_bucket;
+ *num_buckets = &bufmgr->num_local_buckets;
+ break;
+ case IRIS_HEAP_MAX:
+ default:
+ *cache_bucket = NULL;
+ *num_buckets = NULL;
+ unreachable("invalid heap");
+ }
+
+ assert(**num_buckets < BUCKET_ARRAY_SIZE);
+}
/**
* This function finds the correct bucket fit for the input size.
* The function works with O(1) complexity when the requested size
@@ -306,12 +328,11 @@ bucket_for_size(struct iris_bufmgr *bufmgr, uint64_t size,
/* Calculating the index based on the row and column. */
const unsigned index = (row * 4) + (col - 1);
- bool local = heap == IRIS_HEAP_DEVICE_LOCAL;
- int num_buckets = local ? bufmgr->num_local_buckets : bufmgr->num_buckets;
- struct bo_cache_bucket *buckets = local ?
- bufmgr->local_cache_bucket : bufmgr->cache_bucket;
+ int *num_buckets;
+ struct bo_cache_bucket *buckets;
+ bucket_info_for_heap(bufmgr, heap, &buckets, &num_buckets);
- return (index < num_buckets) ? &buckets[index] : NULL;
+ return (index < *num_buckets) ? &buckets[index] : NULL;
}
enum iris_memory_zone
@@ -1996,15 +2017,11 @@ iris_bo_export_gem_handle_for_device(struct iris_bo *bo, int drm_fd,
static void
add_bucket(struct iris_bufmgr *bufmgr, int size, enum iris_heap heap)
{
- bool local = heap == IRIS_HEAP_DEVICE_LOCAL;
- int *num_buckets = local ?
- &bufmgr->num_local_buckets : &bufmgr->num_buckets;
-
- struct bo_cache_bucket *buckets = local ?
- bufmgr->local_cache_bucket : bufmgr->cache_bucket;
+ int *num_buckets;
+ struct bo_cache_bucket *buckets;
+ bucket_info_for_heap(bufmgr, heap, &buckets, &num_buckets);
unsigned int i = (*num_buckets)++;
- assert(i < BUCKET_ARRAY_SIZE);
list_inithead(&buckets[i].head);
buckets[i].size = size;
More information about the mesa-commit
mailing list