llvmpipe: only use vma allocations on linux

this was broken on other platforms

Fixes: a062544d3d ("llvmpipe: Use an anonymous file for memory allocations")

Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30229>
This commit is contained in:
Mike Blumenkrantz 2024-07-17 12:58:28 -04:00 committed by Marge Bot
parent a8ff1bdc83
commit bb5145bcb8
3 changed files with 15 additions and 7 deletions

View file

@ -930,10 +930,12 @@ llvmpipe_destroy_screen(struct pipe_screen *_screen)
close(screen->udmabuf_fd); close(screen->udmabuf_fd);
#endif #endif
#if DETECT_OS_LINUX
util_vma_heap_finish(&screen->mem_heap); util_vma_heap_finish(&screen->mem_heap);
close(screen->fd_mem_alloc); close(screen->fd_mem_alloc);
mtx_destroy(&screen->mem_mutex); mtx_destroy(&screen->mem_mutex);
#endif
mtx_destroy(&screen->rast_mutex); mtx_destroy(&screen->rast_mutex);
mtx_destroy(&screen->cs_mutex); mtx_destroy(&screen->cs_mutex);
FREE(screen); FREE(screen);
@ -1175,15 +1177,17 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
screen->udmabuf_fd = open("/dev/udmabuf", O_RDWR); screen->udmabuf_fd = open("/dev/udmabuf", O_RDWR);
#endif #endif
screen->fd_mem_alloc = os_create_anonymous_file(0, "allocation fd");
(void) mtx_init(&screen->mem_mutex, mtx_plain);
uint64_t alignment; uint64_t alignment;
if (!os_get_page_size(&alignment)) if (!os_get_page_size(&alignment))
alignment = 256; alignment = 256;
#if DETECT_OS_LINUX
(void) mtx_init(&screen->mem_mutex, mtx_plain);
util_vma_heap_init(&screen->mem_heap, alignment, UINT64_MAX - alignment); util_vma_heap_init(&screen->mem_heap, alignment, UINT64_MAX - alignment);
screen->mem_heap.alloc_high = false; screen->mem_heap.alloc_high = false;
screen->fd_mem_alloc = os_create_anonymous_file(0, "allocation fd");
#endif
snprintf(screen->renderer_string, sizeof(screen->renderer_string), snprintf(screen->renderer_string, sizeof(screen->renderer_string),
"llvmpipe (LLVM " MESA_LLVM_VERSION_STRING ", %u bits)", "llvmpipe (LLVM " MESA_LLVM_VERSION_STRING ", %u bits)",

View file

@ -79,10 +79,12 @@ struct llvmpipe_screen
int udmabuf_fd; int udmabuf_fd;
#endif #endif
#if DETECT_OS_LINUX
int fd_mem_alloc; int fd_mem_alloc;
mtx_t mem_mutex; mtx_t mem_mutex;
uint64_t mem_file_size; uint64_t mem_file_size;
struct util_vma_heap mem_heap; struct util_vma_heap mem_heap;
#endif
}; };

View file

@ -1290,17 +1290,18 @@ llvmpipe_memory_barrier(struct pipe_context *pipe,
static struct pipe_memory_allocation * static struct pipe_memory_allocation *
llvmpipe_allocate_memory(struct pipe_screen *_screen, uint64_t size) llvmpipe_allocate_memory(struct pipe_screen *_screen, uint64_t size)
{ {
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
struct llvmpipe_memory_allocation *mem = CALLOC_STRUCT(llvmpipe_memory_allocation); struct llvmpipe_memory_allocation *mem = CALLOC_STRUCT(llvmpipe_memory_allocation);
uint64_t alignment; uint64_t alignment;
if (!os_get_page_size(&alignment)) if (!os_get_page_size(&alignment))
alignment = 256; alignment = 256;
mem->fd = screen->fd_mem_alloc;
mem->size = align64(size, alignment); mem->size = align64(size, alignment);
#if DETECT_OS_LINUX #if DETECT_OS_LINUX
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
mem->cpu_addr = MAP_FAILED; mem->cpu_addr = MAP_FAILED;
mem->fd = screen->fd_mem_alloc;
mtx_lock(&screen->mem_mutex); mtx_lock(&screen->mem_mutex);
@ -1330,16 +1331,17 @@ static void
llvmpipe_free_memory(struct pipe_screen *pscreen, llvmpipe_free_memory(struct pipe_screen *pscreen,
struct pipe_memory_allocation *pmem) struct pipe_memory_allocation *pmem)
{ {
struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
struct llvmpipe_memory_allocation *mem = (struct llvmpipe_memory_allocation *)pmem; struct llvmpipe_memory_allocation *mem = (struct llvmpipe_memory_allocation *)pmem;
#if DETECT_OS_LINUX
struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
if (mem->fd) { if (mem->fd) {
mtx_lock(&screen->mem_mutex); mtx_lock(&screen->mem_mutex);
util_vma_heap_free(&screen->mem_heap, mem->offset, mem->size); util_vma_heap_free(&screen->mem_heap, mem->offset, mem->size);
mtx_unlock(&screen->mem_mutex); mtx_unlock(&screen->mem_mutex);
} }
#if DETECT_OS_LINUX
if (mem->cpu_addr != MAP_FAILED) if (mem->cpu_addr != MAP_FAILED)
munmap(mem->cpu_addr, mem->size); munmap(mem->cpu_addr, mem->size);
#else #else