mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 13:20:14 +01:00
panfrost: Implement pan_bucket_index helper
We'll use this whenever we need to lookup a bucket. Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
This commit is contained in:
parent
270733fe6a
commit
eb398683d7
1 changed files with 25 additions and 0 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pan_screen.h"
|
#include "pan_screen.h"
|
||||||
|
#include "util/u_math.h"
|
||||||
|
|
||||||
/* This file implements a userspace BO cache. Allocating and freeing
|
/* This file implements a userspace BO cache. Allocating and freeing
|
||||||
* GPU-visible buffers is very expensive, and even the extra kernel roundtrips
|
* GPU-visible buffers is very expensive, and even the extra kernel roundtrips
|
||||||
|
|
@ -41,6 +42,30 @@
|
||||||
* around the linked list.
|
* 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
|
/* 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
|
* 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
|
* cache. If it fails, it returns NULL signaling the caller to allocate a new
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue