gallium: Add dmabuf arg to memory fd allocation API

Modify the memory fd allocation API to provide an argument to specify
if the allocating fd should be a dmabuf.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27805>
This commit is contained in:
Lucas Fryzek
2024-02-26 17:12:11 -05:00
committed by Marge Bot
parent e4ae665f93
commit 7e5c5d313b
4 changed files with 15 additions and 9 deletions
@@ -635,7 +635,8 @@ trace_screen_allocate_memory(struct pipe_screen *_screen,
static struct pipe_memory_allocation *
trace_screen_allocate_memory_fd(struct pipe_screen *_screen,
uint64_t size,
int *fd)
int *fd,
bool dmabuf)
{
struct trace_screen *tr_scr = trace_screen(_screen);
struct pipe_screen *screen = tr_scr->screen;
@@ -646,8 +647,9 @@ trace_screen_allocate_memory_fd(struct pipe_screen *_screen,
trace_dump_arg(ptr, screen);
trace_dump_arg(uint, size);
trace_dump_arg(ptr, fd);
trace_dump_arg(bool, dmabuf);
result = screen->allocate_memory_fd(screen, size, fd);
result = screen->allocate_memory_fd(screen, size, fd, dmabuf);
trace_dump_ret(ptr, result);
+5 -3
View File
@@ -360,7 +360,7 @@ llvmpipe_memobj_create_from_handle(struct pipe_screen *pscreen,
struct llvmpipe_memory_object *memobj = CALLOC_STRUCT(llvmpipe_memory_object);
if (handle->type == WINSYS_HANDLE_TYPE_FD &&
pscreen->import_memory_fd(pscreen, handle->handle, &memobj->data, &memobj->size)) {
pscreen->import_memory_fd(pscreen, handle->handle, &memobj->data, &memobj->size, false)) {
return &memobj->b;
}
free(memobj);
@@ -991,7 +991,8 @@ static const char *driver_id = "llvmpipe" MESA_GIT_SHA1;
static struct pipe_memory_allocation *
llvmpipe_allocate_memory_fd(struct pipe_screen *screen,
uint64_t size,
int *fd)
int *fd,
bool dmabuf)
{
uint64_t alignment;
if (!os_get_page_size(&alignment))
@@ -1005,7 +1006,8 @@ static bool
llvmpipe_import_memory_fd(struct pipe_screen *screen,
int fd,
struct pipe_memory_allocation **ptr,
uint64_t *size)
uint64_t *size,
bool dmabuf)
{
return os_import_memory_fd(fd, (void**)ptr, size, driver_id);
}
+2 -2
View File
@@ -1776,7 +1776,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory(
#ifdef PIPE_MEMORY_FD
else if(import_info) {
uint64_t size;
if(!device->pscreen->import_memory_fd(device->pscreen, import_info->fd, &mem->pmem, &size)) {
if(!device->pscreen->import_memory_fd(device->pscreen, import_info->fd, &mem->pmem, &size, false)) {
close(import_info->fd);
error = VK_ERROR_INVALID_EXTERNAL_HANDLE;
goto fail;
@@ -1795,7 +1795,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory(
mem->memory_type = LVP_DEVICE_MEMORY_TYPE_OPAQUE_FD;
}
else if (export_info && export_info->handleTypes) {
mem->pmem = device->pscreen->allocate_memory_fd(device->pscreen, pAllocateInfo->allocationSize, &mem->backed_fd);
mem->pmem = device->pscreen->allocate_memory_fd(device->pscreen, pAllocateInfo->allocationSize, &mem->backed_fd, false);
if (!mem->pmem || mem->backed_fd < 0) {
goto fail;
}
+4 -2
View File
@@ -667,7 +667,8 @@ struct pipe_screen {
*/
struct pipe_memory_allocation *(*allocate_memory_fd)(struct pipe_screen *screen,
uint64_t size,
int *fd);
int *fd,
bool dmabuf);
/**
* Import memory from an fd-handle.
@@ -675,7 +676,8 @@ struct pipe_screen {
bool (*import_memory_fd)(struct pipe_screen *screen,
int fd,
struct pipe_memory_allocation **pmem,
uint64_t *size);
uint64_t *size,
bool dmabuf);
/**
* Free previously allocated fd-based memory.