mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-22 13:08:09 +02:00
When an allocation failure happens, the command buffer should be flagged as invalid, and anything using this memory from the CPU side should be skipped to avoid segfaults. For allocations going through memory pools owned by a command buffer we automate that with panvk_cmd_alloc_xx() macros. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Rebecca Mckeever <rebecca.mckeever@collabora.com> Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com> Reviewed-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com> Reviewed-by: John Anthony <john.anthony@arm.com> Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30969>
48 lines
1.7 KiB
C
48 lines
1.7 KiB
C
/*
|
|
* Copyright © 2024 Collabora Ltd.
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef PANVK_CMD_ALLOC_H
|
|
#define PANVK_CMD_ALLOC_H
|
|
|
|
#include "panvk_cmd_buffer.h"
|
|
#include "panvk_mempool.h"
|
|
|
|
static inline struct panfrost_ptr
|
|
panvk_cmd_alloc_from_pool(struct panvk_cmd_buffer *cmdbuf,
|
|
struct panvk_pool *pool,
|
|
struct panvk_pool_alloc_info info)
|
|
{
|
|
if (!info.size)
|
|
return (struct panfrost_ptr){0};
|
|
|
|
struct panfrost_ptr ptr =
|
|
pan_pool_alloc_aligned(&pool->base, info.size, info.alignment);
|
|
|
|
if (!ptr.gpu)
|
|
vk_command_buffer_set_error(&cmdbuf->vk,
|
|
VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
|
|
|
return ptr;
|
|
}
|
|
|
|
#define panvk_cmd_alloc_dev_mem(__cmdbuf, __poolnm, __sz, __alignment) \
|
|
panvk_cmd_alloc_from_pool(__cmdbuf, &(__cmdbuf)->__poolnm##_pool, \
|
|
(struct panvk_pool_alloc_info){ \
|
|
.size = __sz, \
|
|
.alignment = __alignment, \
|
|
})
|
|
|
|
#define panvk_cmd_alloc_desc_aggregate(__cmdbuf, ...) \
|
|
panvk_cmd_alloc_from_pool( \
|
|
__cmdbuf, &(__cmdbuf)->desc_pool, \
|
|
panvk_pool_descs_to_alloc_info(PAN_DESC_AGGREGATE(__VA_ARGS__)))
|
|
|
|
#define panvk_cmd_alloc_desc(__cmdbuf, __desc) \
|
|
panvk_cmd_alloc_desc_aggregate(__cmdbuf, PAN_DESC(__desc))
|
|
|
|
#define panvk_cmd_alloc_desc_array(__cmdbuf, __count, __desc) \
|
|
panvk_cmd_alloc_desc_aggregate(__cmdbuf, PAN_DESC_ARRAY(__count, __desc))
|
|
|
|
#endif
|