Mesa (master): panfrost: Implement pan_bucket_index helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 15 23:14:22 UTC 2019


Module: Mesa
Branch: master
Commit: eb398683d764077aafa00937bc8aa8fc666b15c3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=eb398683d764077aafa00937bc8aa8fc666b15c3

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Mon Jul 15 08:47:59 2019 -0700

panfrost: Implement pan_bucket_index helper

We'll use this whenever we need to lookup a bucket.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>

---

 src/gallium/drivers/panfrost/pan_bo_cache.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/gallium/drivers/panfrost/pan_bo_cache.c b/src/gallium/drivers/panfrost/pan_bo_cache.c
index da4a9a21e56..4fb96c8efb5 100644
--- a/src/gallium/drivers/panfrost/pan_bo_cache.c
+++ b/src/gallium/drivers/panfrost/pan_bo_cache.c
@@ -25,6 +25,7 @@
  */
 
 #include "pan_screen.h"
+#include "util/u_math.h"
 
 /* This file implements a userspace BO cache. Allocating and freeing
  * GPU-visible buffers is very expensive, and even the extra kernel roundtrips
@@ -41,6 +42,30 @@
  * around the linked list.
  */
 
+/* Helper to calculate the bucket index of a BO */
+
+static unsigned
+pan_bucket_index(unsigned size)
+{
+        /* Round down to POT to compute a bucket index */
+
+        unsigned bucket_index = util_logbase2(size);
+
+        /* Clamp the bucket index; all huge allocations will be
+         * sorted into the largest bucket */
+
+        bucket_index = MIN2(bucket_index, MAX_BO_CACHE_BUCKET);
+
+        /* The minimum bucket size must equal the minimum allocation
+         * size; the maximum we clamped */
+
+        assert(bucket_index >= MIN_BO_CACHE_BUCKET);
+        assert(bucket_index <= MAX_BO_CACHE_BUCKET);
+
+        /* Reindex from 0 */
+        return (bucket_index - MIN_BO_CACHE_BUCKET);
+}
+
 /* Tries to fetch a BO of sufficient size with the appropriate flags from the
  * BO cache. If it succeeds, it returns that BO and removes the BO from the
  * cache. If it fails, it returns NULL signaling the caller to allocate a new




More information about the mesa-commit mailing list