libagx: use common heap alloc for tessellator

this gets us bounds checking.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34661>
This commit is contained in:
Alyssa Rosenzweig 2025-04-23 11:05:25 -04:00 committed by Marge Bot
parent d339bf7a98
commit 4685d8e2d9
2 changed files with 23 additions and 12 deletions

View file

@ -113,10 +113,17 @@ static_assert(sizeof(struct agx_heap) == 4 * 4);
#ifdef __OPENCL_VERSION__
static inline uint
agx_heap_alloc_nonatomic_offs(global struct agx_heap *heap, uint size_B)
_agx_heap_alloc_offs(global struct agx_heap *heap, uint size_B, bool atomic)
{
uint offs = heap->bottom;
heap->bottom += align(size_B, 16);
size_B = align(size_B, 16);
uint offs;
if (atomic) {
offs = atomic_fetch_add((volatile atomic_uint *)(&heap->bottom), size_B);
} else {
offs = heap->bottom;
heap->bottom = offs + size_B;
}
/* Use printf+abort because assert is stripped from release builds. */
if (heap->bottom >= heap->size) {
@ -130,6 +137,18 @@ agx_heap_alloc_nonatomic_offs(global struct agx_heap *heap, uint size_B)
return offs;
}
static inline uint
agx_heap_alloc_nonatomic_offs(global struct agx_heap *heap, uint size_B)
{
return _agx_heap_alloc_offs(heap, size_B, false);
}
static inline uint
agx_heap_alloc_atomic_offs(global struct agx_heap *heap, uint size_B)
{
return _agx_heap_alloc_offs(heap, size_B, true);
}
static inline global void *
agx_heap_alloc_nonatomic(global struct agx_heap *heap, uint size_B)
{

View file

@ -117,14 +117,6 @@ tess_factors(constant struct libagx_tess_args *p, uint patch)
return p->tcs_buffer + (patch * p->tcs_stride_el);
}
static inline uint
libagx_heap_alloc(global struct agx_heap *heap, uint size_B)
{
// TODO: drop align to 4 I think
return atomic_fetch_add((volatile atomic_uint *)(&heap->bottom),
align(size_B, 8));
}
/*
* Generate an indexed draw for a patch with the computed number of indices.
* This allocates heap memory for the index buffer, returning the allocated
@ -196,7 +188,7 @@ libagx_heap_alloc_points(constant struct libagx_tess_args *p, uint patch,
}
uint32_t elsize_B = sizeof(struct libagx_tess_point);
uint32_t alloc_B = libagx_heap_alloc(p->heap, elsize_B * count);
uint32_t alloc_B = agx_heap_alloc_atomic_offs(p->heap, elsize_B * count);
uint32_t alloc_el = alloc_B / elsize_B;
p->coord_allocs[patch] = alloc_el;