diff options
author | Fredrik Höglund <[email protected]> | 2018-01-25 18:12:14 +0100 |
---|---|---|
committer | Fredrik Höglund <[email protected]> | 2018-02-08 00:46:07 +0100 |
commit | 5a38d8f1036b949e442359f691956b48b32b0e30 (patch) | |
tree | 284ff293afd3e97137c6c487e7715209902d8293 /src/amd/vulkan/winsys | |
parent | 5dd385f378a7e264f79ce2004aef815b3d9e3388 (diff) |
radv: implement VK_EXT_external_memory_host
Ported from the radeonsi GL_AMD_pinned_memory implementation.
Signed-off-by: Fredrik Höglund <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src/amd/vulkan/winsys')
-rw-r--r-- | src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c index 603111d2ebc..9e83390568a 100644 --- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c +++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c @@ -403,6 +403,54 @@ radv_amdgpu_winsys_bo_unmap(struct radeon_winsys_bo *_bo) } static struct radeon_winsys_bo * +radv_amdgpu_winsys_bo_from_ptr(struct radeon_winsys *_ws, + void *pointer, + uint64_t size) +{ + struct radv_amdgpu_winsys *ws = radv_amdgpu_winsys(_ws); + amdgpu_bo_handle buf_handle; + struct radv_amdgpu_winsys_bo *bo; + uint64_t va; + amdgpu_va_handle va_handle; + + bo = CALLOC_STRUCT(radv_amdgpu_winsys_bo); + if (!bo) + return NULL; + + if (amdgpu_create_bo_from_user_mem(ws->dev, pointer, size, &buf_handle)) + goto error; + + if (amdgpu_va_range_alloc(ws->dev, amdgpu_gpu_va_range_general, + size, 1 << 12, 0, &va, &va_handle, 0)) + goto error_va_alloc; + + if (amdgpu_bo_va_op(buf_handle, 0, size, va, 0, AMDGPU_VA_OP_MAP)) + goto error_va_map; + + /* Initialize it */ + bo->base.va = va; + bo->va_handle = va_handle; + bo->size = size; + bo->ref_count = 1; + bo->ws = ws; + bo->bo = buf_handle; + bo->initial_domain = RADEON_DOMAIN_GTT; + + radv_amdgpu_add_buffer_to_global_list(bo); + return (struct radeon_winsys_bo *)bo; + +error_va_map: + amdgpu_va_range_free(va_handle); + +error_va_alloc: + amdgpu_bo_free(buf_handle); + +error: + FREE(bo); + return NULL; +} + +static struct radeon_winsys_bo * radv_amdgpu_winsys_bo_from_fd(struct radeon_winsys *_ws, int fd, unsigned *stride, unsigned *offset) @@ -540,6 +588,7 @@ void radv_amdgpu_bo_init_functions(struct radv_amdgpu_winsys *ws) ws->base.buffer_destroy = radv_amdgpu_winsys_bo_destroy; ws->base.buffer_map = radv_amdgpu_winsys_bo_map; ws->base.buffer_unmap = radv_amdgpu_winsys_bo_unmap; + ws->base.buffer_from_ptr = radv_amdgpu_winsys_bo_from_ptr; ws->base.buffer_from_fd = radv_amdgpu_winsys_bo_from_fd; ws->base.buffer_get_fd = radv_amdgpu_winsys_get_fd; ws->base.buffer_set_metadata = radv_amdgpu_winsys_bo_set_metadata; |