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:

committed by
Marge Bot

parent
a8ff1bdc83
commit
bb5145bcb8
@@ -930,10 +930,12 @@ llvmpipe_destroy_screen(struct pipe_screen *_screen)
|
||||
close(screen->udmabuf_fd);
|
||||
#endif
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
util_vma_heap_finish(&screen->mem_heap);
|
||||
|
||||
close(screen->fd_mem_alloc);
|
||||
mtx_destroy(&screen->mem_mutex);
|
||||
#endif
|
||||
mtx_destroy(&screen->rast_mutex);
|
||||
mtx_destroy(&screen->cs_mutex);
|
||||
FREE(screen);
|
||||
@@ -1175,15 +1177,17 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
|
||||
screen->udmabuf_fd = open("/dev/udmabuf", O_RDWR);
|
||||
#endif
|
||||
|
||||
screen->fd_mem_alloc = os_create_anonymous_file(0, "allocation fd");
|
||||
(void) mtx_init(&screen->mem_mutex, mtx_plain);
|
||||
|
||||
uint64_t alignment;
|
||||
if (!os_get_page_size(&alignment))
|
||||
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);
|
||||
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),
|
||||
"llvmpipe (LLVM " MESA_LLVM_VERSION_STRING ", %u bits)",
|
||||
|
@@ -79,10 +79,12 @@ struct llvmpipe_screen
|
||||
int udmabuf_fd;
|
||||
#endif
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
int fd_mem_alloc;
|
||||
mtx_t mem_mutex;
|
||||
uint64_t mem_file_size;
|
||||
struct util_vma_heap mem_heap;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1290,17 +1290,18 @@ llvmpipe_memory_barrier(struct pipe_context *pipe,
|
||||
static struct pipe_memory_allocation *
|
||||
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);
|
||||
uint64_t alignment;
|
||||
if (!os_get_page_size(&alignment))
|
||||
alignment = 256;
|
||||
|
||||
mem->fd = screen->fd_mem_alloc;
|
||||
mem->size = align64(size, alignment);
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
|
||||
|
||||
mem->cpu_addr = MAP_FAILED;
|
||||
mem->fd = screen->fd_mem_alloc;
|
||||
|
||||
mtx_lock(&screen->mem_mutex);
|
||||
|
||||
@@ -1330,16 +1331,17 @@ static void
|
||||
llvmpipe_free_memory(struct pipe_screen *pscreen,
|
||||
struct pipe_memory_allocation *pmem)
|
||||
{
|
||||
struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
|
||||
struct llvmpipe_memory_allocation *mem = (struct llvmpipe_memory_allocation *)pmem;
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
struct llvmpipe_screen *screen = llvmpipe_screen(pscreen);
|
||||
|
||||
if (mem->fd) {
|
||||
mtx_lock(&screen->mem_mutex);
|
||||
util_vma_heap_free(&screen->mem_heap, mem->offset, mem->size);
|
||||
mtx_unlock(&screen->mem_mutex);
|
||||
}
|
||||
|
||||
#if DETECT_OS_LINUX
|
||||
if (mem->cpu_addr != MAP_FAILED)
|
||||
munmap(mem->cpu_addr, mem->size);
|
||||
#else
|
||||
|
Reference in New Issue
Block a user