diff --git a/src/asahi/vulkan/hk_cmd_draw.c b/src/asahi/vulkan/hk_cmd_draw.c index a31098eb6fa..ecfa5d6b7b3 100644 --- a/src/asahi/vulkan/hk_cmd_draw.c +++ b/src/asahi/vulkan/hk_cmd_draw.c @@ -992,28 +992,34 @@ hk_CmdEndRendering(VkCommandBuffer commandBuffer) } } +static void +hk_init_heap(const void *data) { + struct hk_cmd_buffer *cmd = (struct hk_cmd_buffer *) data; + struct hk_device *dev = hk_cmd_buffer_device(cmd); + + perf_debug(cmd, "Allocating heap"); + + size_t size = 128 * 1024 * 1024; + dev->heap = agx_bo_create(&dev->dev, size, 0, 0, "Geometry heap"); + + /* The geometry state buffer is initialized here and then is treated by + * the CPU as rodata, even though the GPU uses it for scratch internally. + */ + off_t off = dev->rodata.heap - dev->rodata.bo->va->addr; + struct poly_heap *map = agx_bo_map(dev->rodata.bo) + off; + + *map = (struct poly_heap){ + .base = dev->heap->va->addr, + .size = size, + }; +} + static uint64_t hk_heap(struct hk_cmd_buffer *cmd) { struct hk_device *dev = hk_cmd_buffer_device(cmd); - if (unlikely(!dev->heap)) { - perf_debug(cmd, "Allocating heap"); - - size_t size = 128 * 1024 * 1024; - dev->heap = agx_bo_create(&dev->dev, size, 0, 0, "Geometry heap"); - - /* The geometry state buffer is initialized here and then is treated by - * the CPU as rodata, even though the GPU uses it for scratch internally. - */ - off_t off = dev->rodata.heap - dev->rodata.bo->va->addr; - struct poly_heap *map = agx_bo_map(dev->rodata.bo) + off; - - *map = (struct poly_heap){ - .base = dev->heap->va->addr, - .size = size, - }; - } + util_call_once_data(&dev->heap_init_once, hk_init_heap, cmd); /* We need to free all allocations after each command buffer execution */ if (!cmd->uses_heap) { diff --git a/src/asahi/vulkan/hk_device.h b/src/asahi/vulkan/hk_device.h index c91ac744c1d..8f85f9415fe 100644 --- a/src/asahi/vulkan/hk_device.h +++ b/src/asahi/vulkan/hk_device.h @@ -92,6 +92,7 @@ struct hk_device { * expected to be a legitimate problem. If it is, we can rework later. */ struct agx_bo *heap; + util_once_flag heap_init_once; struct { struct agx_scratch vs, fs, cs;