diff --git a/src/asahi/libagx/geometry.h b/src/asahi/libagx/geometry.h index 103f6b0fcd1..54ef991396b 100644 --- a/src/asahi/libagx/geometry.h +++ b/src/asahi/libagx/geometry.h @@ -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) { diff --git a/src/asahi/libagx/tessellator.cl b/src/asahi/libagx/tessellator.cl index 090064b7cf3..957230e422d 100644 --- a/src/asahi/libagx/tessellator.cl +++ b/src/asahi/libagx/tessellator.cl @@ -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;