turnip: Add buffer allocation & mapping support.
authorBas Nieuwenhuizen <basni@chromium.org>
Fri, 10 Aug 2018 11:19:22 +0000 (13:19 +0200)
committerChia-I Wu <olvaffe@gmail.com>
Mon, 11 Mar 2019 17:01:33 +0000 (10:01 -0700)
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_private.h

index fe10f048133f4a5c4fbfbee240c13be560da0ea1..e0c27166818ac709f4bf5747850ab691bf573e1a 100644 (file)
@@ -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
index 21237fd14e7bd429afe532b45d251c331ab37435..35c51ac2c84223c2335f2f5e17ce714908348b9d 100644 (file)
@@ -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;
 };