asahi: Label BOs internally

This will help debugging memory usage problems.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19971>
This commit is contained in:
Alyssa Rosenzweig 2022-11-20 18:35:18 -05:00 committed by Marge Bot
parent 4a8134975e
commit 860f5d77c6
6 changed files with 35 additions and 9 deletions

View file

@ -83,10 +83,14 @@ struct agx_bo {
/* Used while decoding, mapped */
bool mapped;
/* For debugging */
const char *label;
};
struct agx_bo *
agx_bo_create(struct agx_device *dev, unsigned size, unsigned flags);
agx_bo_create(struct agx_device *dev, unsigned size, unsigned flags,
const char *label);
void agx_bo_reference(struct agx_bo *bo);
void agx_bo_unreference(struct agx_bo *bo);

View file

@ -232,7 +232,8 @@ agx_bo_export(struct agx_bo *bo)
}
struct agx_bo *
agx_bo_create(struct agx_device *dev, unsigned size, unsigned flags)
agx_bo_create(struct agx_device *dev, unsigned size, unsigned flags,
const char *label)
{
struct agx_bo *bo;
assert(size > 0);
@ -248,6 +249,7 @@ agx_bo_create(struct agx_device *dev, unsigned size, unsigned flags)
return NULL;
}
bo->label = label;
p_atomic_set(&bo->refcnt, 1);
if (dev->debug & AGX_DBG_TRACE)

View file

@ -36,8 +36,8 @@
static struct agx_bo *
agx_pool_alloc_backing(struct agx_pool *pool, size_t bo_sz)
{
struct agx_bo *bo = agx_bo_create(pool->dev, bo_sz,
pool->create_flags);
struct agx_bo *bo = agx_bo_create(pool->dev, bo_sz, pool->create_flags,
"Pool");
util_dynarray_append(&pool->bos, struct agx_bo *, bo);
pool->transient_bo = bo;

View file

@ -46,7 +46,7 @@ agx_batch_init(struct agx_context *ctx,
}
if (!batch->encoder) {
batch->encoder = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER);
batch->encoder = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER, "Encoder");
batch->encoder_current = batch->encoder->ptr.cpu;
batch->encoder_end = batch->encoder_current + batch->encoder->size;
} else {
@ -55,11 +55,11 @@ agx_batch_init(struct agx_context *ctx,
}
if (!batch->scissor.bo) {
batch->scissor.bo = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER);
batch->scissor.bo = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER, "Scissors");
}
if (!batch->depth_bias.bo) {
batch->depth_bias.bo = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER);
batch->depth_bias.bo = agx_bo_create(dev, 0x80000, AGX_MEMORY_TYPE_FRAMEBUFFER, "Depth bias");
}
batch->clear = 0;

View file

@ -483,7 +483,26 @@ agx_resource_create_with_modifiers(struct pipe_screen *screen,
}
}
nresource->bo = agx_bo_create(dev, nresource->layout.size_B, AGX_MEMORY_TYPE_FRAMEBUFFER);
/* Guess a label based on the bind */
unsigned bind = templ->bind;
const char *label =
(bind & PIPE_BIND_INDEX_BUFFER) ? "Index buffer" :
(bind & PIPE_BIND_SCANOUT) ? "Scanout" :
(bind & PIPE_BIND_DISPLAY_TARGET) ? "Display target" :
(bind & PIPE_BIND_SHARED) ? "Shared resource" :
(bind & PIPE_BIND_RENDER_TARGET) ? "Render target" :
(bind & PIPE_BIND_DEPTH_STENCIL) ? "Depth/stencil buffer" :
(bind & PIPE_BIND_SAMPLER_VIEW) ? "Texture" :
(bind & PIPE_BIND_VERTEX_BUFFER) ? "Vertex buffer" :
(bind & PIPE_BIND_CONSTANT_BUFFER) ? "Constant buffer" :
(bind & PIPE_BIND_GLOBAL) ? "Global memory" :
(bind & PIPE_BIND_SHADER_BUFFER) ? "Shader buffer" :
(bind & PIPE_BIND_SHADER_IMAGE) ? "Shader image" :
"Other resource";
nresource->bo = agx_bo_create(dev, nresource->layout.size_B,
AGX_MEMORY_TYPE_FRAMEBUFFER, label);
if (!nresource->bo) {
FREE(nresource);

View file

@ -1151,7 +1151,8 @@ agx_compile_variant(struct agx_device *dev,
agx_compile_shader_nir(nir, &key->base, debug, &binary, &compiled->info);
if (binary.size) {
compiled->bo = agx_bo_create(dev, binary.size, AGX_MEMORY_TYPE_SHADER);
compiled->bo = agx_bo_create(dev, binary.size, AGX_MEMORY_TYPE_SHADER,
"Executable");
memcpy(compiled->bo->ptr.cpu, binary.data, binary.size);
}