From: Alyssa Rosenzweig Date: Mon, 15 Jul 2019 15:47:59 +0000 (-0700) Subject: panfrost: Implement pan_bucket_index helper X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eb398683d764077aafa00937bc8aa8fc666b15c3;p=mesa.git panfrost: Implement pan_bucket_index helper We'll use this whenever we need to lookup a bucket. Signed-off-by: Alyssa Rosenzweig --- 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