mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
radv/amdgpu: Use mmap directly.
To give more control. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27689>
This commit is contained in:
parent
cccbe1527c
commit
d779cda0ae
2 changed files with 35 additions and 4 deletions
|
|
@ -35,7 +35,9 @@
|
|||
#include <inttypes.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include "drm-uapi/amdgpu_drm.h"
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "util/os_time.h"
|
||||
#include "util/u_atomic.h"
|
||||
|
|
@ -335,6 +337,9 @@ radv_amdgpu_winsys_bo_destroy(struct radeon_winsys *_ws, struct radeon_winsys_bo
|
|||
free(bo->ranges);
|
||||
u_rwlock_destroy(&bo->lock);
|
||||
} else {
|
||||
if (bo->cpu_map)
|
||||
munmap(bo->cpu_map, bo->size);
|
||||
|
||||
if (ws->debug_all_bos)
|
||||
radv_amdgpu_global_bo_list_del(ws, bo);
|
||||
radv_amdgpu_bo_va_op(ws, bo->bo, 0, bo->size, bo->base.va, 0, 0, AMDGPU_VA_OP_UNMAP);
|
||||
|
|
@ -507,6 +512,7 @@ radv_amdgpu_winsys_bo_create(struct radeon_winsys *_ws, uint64_t size, unsigned
|
|||
bo->base.initial_domain = initial_domain;
|
||||
bo->base.use_global_list = false;
|
||||
bo->priority = priority;
|
||||
bo->cpu_map = NULL;
|
||||
|
||||
r = amdgpu_bo_export(buf_handle, amdgpu_bo_handle_type_kms, &bo->bo_handle);
|
||||
assert(!r);
|
||||
|
|
@ -554,11 +560,26 @@ static void *
|
|||
radv_amdgpu_winsys_bo_map(struct radeon_winsys *_ws, struct radeon_winsys_bo *_bo)
|
||||
{
|
||||
struct radv_amdgpu_winsys_bo *bo = radv_amdgpu_winsys_bo(_bo);
|
||||
int ret;
|
||||
void *data;
|
||||
ret = amdgpu_bo_cpu_map(bo->bo, &data);
|
||||
|
||||
/* Safeguard for the Quantic Dream layer skipping unmaps. */
|
||||
if (bo->cpu_map)
|
||||
return bo->cpu_map;
|
||||
|
||||
union drm_amdgpu_gem_mmap args;
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.in.handle = bo->bo_handle;
|
||||
|
||||
int ret =
|
||||
drmCommandWriteRead(amdgpu_device_get_fd(radv_amdgpu_winsys(_ws)->dev), DRM_AMDGPU_GEM_MMAP, &args, sizeof(args));
|
||||
if (ret)
|
||||
return NULL;
|
||||
|
||||
void *data = mmap(NULL, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
amdgpu_device_get_fd(radv_amdgpu_winsys(_ws)->dev), args.out.addr_ptr);
|
||||
if (data == MAP_FAILED)
|
||||
return NULL;
|
||||
|
||||
bo->cpu_map = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
@ -566,7 +587,13 @@ static void
|
|||
radv_amdgpu_winsys_bo_unmap(struct radeon_winsys *_ws, struct radeon_winsys_bo *_bo)
|
||||
{
|
||||
struct radv_amdgpu_winsys_bo *bo = radv_amdgpu_winsys_bo(_bo);
|
||||
amdgpu_bo_cpu_unmap(bo->bo);
|
||||
|
||||
/* Defense in depth against buggy apps. */
|
||||
if (!bo->cpu_map)
|
||||
return;
|
||||
|
||||
munmap(bo->cpu_map, bo->size);
|
||||
bo->cpu_map = NULL;
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
|
|
@ -645,6 +672,7 @@ radv_amdgpu_winsys_bo_from_ptr(struct radeon_winsys *_ws, void *pointer, uint64_
|
|||
bo->base.initial_domain = RADEON_DOMAIN_GTT;
|
||||
bo->base.use_global_list = false;
|
||||
bo->priority = priority;
|
||||
bo->cpu_map = NULL;
|
||||
|
||||
ASSERTED int r = amdgpu_bo_export(buf_handle, amdgpu_bo_handle_type_kms, &bo->bo_handle);
|
||||
assert(!r);
|
||||
|
|
@ -733,6 +761,7 @@ radv_amdgpu_winsys_bo_from_fd(struct radeon_winsys *_ws, int fd, unsigned priori
|
|||
bo->base.use_global_list = false;
|
||||
bo->size = result.alloc_size;
|
||||
bo->priority = priority;
|
||||
bo->cpu_map = NULL;
|
||||
|
||||
r = amdgpu_bo_export(result.buf_handle, amdgpu_bo_handle_type_kms, &bo->bo_handle);
|
||||
assert(!r);
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ struct radv_amdgpu_winsys_bo {
|
|||
struct {
|
||||
amdgpu_bo_handle bo;
|
||||
uint32_t bo_handle;
|
||||
|
||||
void *cpu_map;
|
||||
};
|
||||
/* virtual bo */
|
||||
struct {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue