mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-03 11:30:21 +01:00
hk: fix data race when initializing poly_heap
hk_heap is called during command buffer recording, which may be
concurrent, so writing dev->heap without synchronization is a data race.
Signed-off-by: Olivia Lee <olivia.lee@collabora.com>
Fixes: 5bc8284816 ("hk: add Vulkan driver for Apple GPUs")
Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37973>
This commit is contained in:
parent
b6d6c1af73
commit
bca29b1c92
2 changed files with 24 additions and 17 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue