From 8e52e8183c2dec8bf0ef85284f8883dc392b7acd Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Fri, 10 Aug 2018 13:19:22 +0200 Subject: [PATCH] turnip: Add buffer allocation & mapping support. --- src/freedreno/vulkan/tu_device.c | 27 ++++++++++++++++++++++----- src/freedreno/vulkan/tu_private.h | 4 +++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index fe10f048133..e0c27166818 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -1245,6 +1245,19 @@ tu_alloc_memory(struct tu_device *device, if (mem == NULL) return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); + mem->bo = fd_bo_new(device->physical_device->drm_device, pAllocateInfo->allocationSize, + DRM_FREEDRENO_GEM_CACHE_WCOMBINE | + DRM_FREEDRENO_GEM_TYPE_KMEM); + if (!mem->bo) { + vk_free2(&device->alloc, pAllocator, mem); + return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); + } + mem->size = pAllocateInfo->allocationSize; + mem->type_index = pAllocateInfo->memoryTypeIndex; + + mem->map = NULL; + mem->user_ptr = NULL; + *pMem = tu_device_memory_to_handle(mem); return VK_SUCCESS; @@ -1271,6 +1284,9 @@ tu_FreeMemory(VkDevice _device, if (mem == NULL) return; + if (mem->bo) + fd_bo_del(mem->bo); + vk_free2(&device->alloc, pAllocator, mem); } @@ -1290,8 +1306,12 @@ tu_MapMemory(VkDevice _device, return VK_SUCCESS; } - if (mem->user_ptr) + if (mem->user_ptr) { *ppData = mem->user_ptr; + } else if (!mem->map){ + *ppData = mem->map = fd_bo_map(mem->bo); + } else + *ppData = mem->map; if (*ppData) { *ppData += offset; @@ -1304,10 +1324,7 @@ tu_MapMemory(VkDevice _device, void tu_UnmapMemory(VkDevice _device, VkDeviceMemory _memory) { - TU_FROM_HANDLE(tu_device_memory, mem, _memory); - - if (mem == NULL) - return; + /* I do not see any unmapping done by the freedreno Gallium driver. */ } VkResult diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index 21237fd14e7..35c51ac2c84 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -442,12 +442,14 @@ struct tu_device struct tu_device_memory { + struct fd_bo *bo; + VkDeviceSize size; /* for dedicated allocations */ struct tu_image *image; struct tu_buffer *buffer; + uint32_t type_index; - VkDeviceSize map_size; void *map; void *user_ptr; }; -- 2.30.2