mesa/src/asahi/lib/pool.h
Alyssa Rosenzweig 0f974d1f90 asahi: Convert to SPDX headers
Also drop my email address in the copyright lines and fix some "Copyright 208
Alyssa Rosenzweig" lines, I'm not *that* old. Together this drops a lot of
boilerplate without losing any meaningful licensing information. SPDX is already
in use for the MIT-licensed code in turnip, venus, and a few other scattered
parts of the tree, so this should be ok from a Mesa licensing standpoint.

This reduces friction to create new files, by parsing the copy/paste boilerplate
and being short enough you can easily type it out if you want.  It makes new
files seem less daunting: 20 lines of header for 30 lines of code is
discouraging, but 2 lines of header for 30 lines of code is reasonable for a
simple compiler pass. This has technical effects, as lowering the barrier to
making new files should encourage people to split code into more modular files
with (hopefully positive) effects on project compile time.

This helps with consistency between files. Across the tree we have at least a
half dozen variants of the MIT license text (probably more), plus code that uses
SPDX headers instead. I've already been using SPDX headers in Asahi manually, so
you can tell old vs new code based on the headers.

Finally, it means less for reviewers to scroll through adding files. Minimal
actual cognitive burden for reviewers thanks to banner blindness, but the big
headers still bloat diffs that add/delete files.

I originally proposed this in December (for much more of the tree) but someone
requested I wait until January to discuss. I've been trying to get in touch with
them since then. It is now almost April and, with still no response, I'd like to
press forward with this. So with a joint sign-off from the major authors of the
code in question, let's do this.

Signed-off-by: Asahi Lina <lina@asahilina.net>
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Emma Anholt <emma@anholt.net>
Acked-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Eric Engestrom <eric@igalia.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Rose Hudson <rose@krx.sh>
Acked-by: Lyude Paul [over IRC: "yes I'm fine with that"]
Meh'd-by: Rob Clark <robdclark@chromium.org>

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22062>
2023-03-28 05:14:00 +00:00

122 lines
3.9 KiB
C

/*
* Copyright 2017-2018 Alyssa Rosenzweig
* SPDX-License-Identifier: MIT
*
*/
#ifndef __AGX_POOL_H__
#define __AGX_POOL_H__
#include <stddef.h>
#include "asahi/lib/agx_pack.h"
#include "agx_bo.h"
#include "util/u_dynarray.h"
/* Represents a pool of memory that can only grow, used to allocate objects
* with the same lifetime as the pool itself. In OpenGL, a pool is owned by the
* batch for transient structures. In Vulkan, it may be owned by e.g. the
* command pool */
struct agx_pool {
/* Parent device for allocation */
struct agx_device *dev;
/* BOs allocated by this pool */
struct util_dynarray bos;
/* Current transient BO */
struct agx_bo *transient_bo;
/* Within the topmost transient BO, how much has been used? */
unsigned transient_offset;
/* BO flags to use in the pool */
unsigned create_flags;
};
void agx_pool_init(struct agx_pool *pool, struct agx_device *dev,
unsigned create_flags, bool prealloc);
void agx_pool_cleanup(struct agx_pool *pool);
static inline unsigned
agx_pool_num_bos(struct agx_pool *pool)
{
return util_dynarray_num_elements(&pool->bos, struct agx_bo *);
}
void agx_pool_get_bo_handles(struct agx_pool *pool, uint32_t *handles);
/* Represents a fat pointer for GPU-mapped memory, returned from the transient
* allocator and not used for much else */
struct agx_ptr agx_pool_alloc_aligned_with_bo(struct agx_pool *pool, size_t sz,
unsigned alignment,
struct agx_bo **bo);
static inline struct agx_ptr
agx_pool_alloc_aligned(struct agx_pool *pool, size_t sz, unsigned alignment)
{
return agx_pool_alloc_aligned_with_bo(pool, sz, alignment, NULL);
}
uint64_t agx_pool_upload(struct agx_pool *pool, const void *data, size_t sz);
uint64_t agx_pool_upload_aligned_with_bo(struct agx_pool *pool,
const void *data, size_t sz,
unsigned alignment,
struct agx_bo **bo);
static inline uint64_t
agx_pool_upload_aligned(struct agx_pool *pool, const void *data, size_t sz,
unsigned alignment)
{
return agx_pool_upload_aligned_with_bo(pool, data, sz, alignment, NULL);
}
struct agx_desc_alloc_info {
unsigned size;
unsigned align;
unsigned nelems;
};
#define AGX_DESC_ARRAY(count, name) \
{ \
.size = MALI_##name##_LENGTH, .align = MALI_##name##_ALIGN, \
.nelems = count, \
}
#define AGX_DESC(name) AGX_DESC_ARRAY(1, name)
#define AGX_DESC_AGGREGATE(...) \
(struct agx_desc_alloc_info[]) \
{ \
__VA_ARGS__, {0}, \
}
static inline struct agx_ptr
agx_pool_alloc_descs(struct agx_pool *pool,
const struct agx_desc_alloc_info *descs)
{
unsigned size = 0;
unsigned align = descs[0].align;
for (unsigned i = 0; descs[i].size; i++) {
assert(!(size & (descs[i].align - 1)));
size += descs[i].size * descs[i].nelems;
}
return agx_pool_alloc_aligned(pool, size, align);
}
#define agx_pool_alloc_desc(pool, name) \
agx_pool_alloc_descs(pool, AGX_DESC_AGGREGATE(AGX_DESC(name)))
#define agx_pool_alloc_desc_array(pool, count, name) \
agx_pool_alloc_descs(pool, AGX_DESC_AGGREGATE(AGX_DESC_ARRAY(count, name)))
#define agx_pool_alloc_desc_aggregate(pool, ...) \
agx_pool_alloc_descs(pool, AGX_DESC_AGGREGATE(__VA_ARGS__))
#endif