aboutsummaryrefslogtreecommitdiffstats
path: root/src/freedreno
diff options
context:
space:
mode:
authorBas Nieuwenhuizen <[email protected]>2018-08-10 13:19:22 +0200
committerChia-I Wu <[email protected]>2019-03-11 10:01:33 -0700
commit8e52e8183c2dec8bf0ef85284f8883dc392b7acd (patch)
treee438c69510d627ed4a7460fc31132fba56787d8c /src/freedreno
parenta0d62e4337e1bdbd918c4be997fed6b31c8a7e9e (diff)
turnip: Add buffer allocation & mapping support.
Diffstat (limited to 'src/freedreno')
-rw-r--r--src/freedreno/vulkan/tu_device.c27
-rw-r--r--src/freedreno/vulkan/tu_private.h4
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;
};