| 1 |
/* |
| 2 |
* Copyright 2017-2018 Alyssa Rosenzweig |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
#pragma once |
| 8 |
|
| 9 |
#include <stddef.h> |
| 10 |
#include "agx_bo.h" |
| 11 |
|
| 12 |
#include "util/u_dynarray.h" |
| 13 |
|
| 14 |
/* Represents a pool of memory that can only grow, used to allocate objects |
| 15 |
* with the same lifetime as the pool itself. In OpenGL, a pool is owned by the |
| 16 |
* batch for transient structures. In Vulkan, it may be owned by e.g. the |
| 17 |
* command pool */ |
| 18 |
|
| 19 |
struct agx_pool { |
| 20 |
/* Parent device for allocation */ |
| 21 |
struct agx_device *dev; |
| 22 |
|
| 23 |
/* BOs allocated by this pool */ |
| 24 |
struct util_dynarray bos; |
| 25 |
|
| 26 |
/* Current transient BO */ |
| 27 |
struct agx_bo *transient_bo; |
| 28 |
|
| 29 |
/* Within the topmost transient BO, how much has been used? */ |
| 30 |
unsigned transient_offset; |
| 31 |
|
| 32 |
/* BO flags to use in the pool */ |
| 33 |
unsigned create_flags; |
| 34 |
|
| 35 |
/* Label for pool allocations */ |
| 36 |
const char *label; |
| 37 |
}; |
| 38 |
|
| 39 |
void agx_pool_init(struct agx_pool *pool, struct agx_device *dev, |
| 40 |
const char *label, unsigned create_flags, bool prealloc); |
| 41 |
|
| 42 |
void agx_pool_cleanup(struct agx_pool *pool); |
| 43 |
|
| 44 |
struct agx_ptr agx_pool_alloc_aligned_with_bo(struct agx_pool *pool, size_t sz, |
| 45 |
unsigned alignment, |
| 46 |
struct agx_bo **bo); |
| 47 |
|
| 48 |
static inline struct agx_ptr |
| 49 |
agx_pool_alloc_aligned(struct agx_pool *pool, size_t sz, unsigned alignment) |
| 50 |
{ |
| 51 |
return agx_pool_alloc_aligned_with_bo(pool, sz, alignment, NULL); |
| 52 |
} |
| 53 |
|
| 54 |
uint64_t agx_pool_upload(struct agx_pool *pool, const void *data, size_t sz); |
| 55 |
|
| 56 |
uint64_t agx_pool_upload_aligned_with_bo(struct agx_pool *pool, |
| 57 |
const void *data, size_t sz, |
| 58 |
unsigned alignment, |
| 59 |
struct agx_bo **bo); |
| 60 |
|
| 61 |
static inline uint64_t |
| 62 |
agx_pool_upload_aligned(struct agx_pool *pool, const void *data, size_t sz, |
| 63 |
unsigned alignment) |
| 64 |
{ |
| 65 |
return agx_pool_upload_aligned_with_bo(pool, data, sz, alignment, NULL); |
| 66 |
} |