Skip to content
Snippets Groups Projects
Commit 70a91ad6 authored by Dave Airlie's avatar Dave Airlie
Browse files

nvk/memory: port memory/buffer/image over to VMA allocations.

One change needed here is the min alignment for memory allocations
has to be suitable for any users. Since the only one we know about
is (1 << 16), we have to force that for all allocations that need
VRAM.

This also drops all the internal image stuff.
parent 8fa3884e
No related merge requests found
......@@ -33,7 +33,13 @@ nvk_DestroyBuffer(VkDevice _device,
if (!buffer)
return;
#if NVK_NEW_UAPI == 1
if (buffer->mem) {
struct nouveau_ws_device *dev = device->pdev->dev;
nouveau_ws_bo_unbind_vma(dev, buffer->addr, buffer->aligned_size);
nouveau_ws_free_vma(dev, buffer->addr, buffer->aligned_size);
}
#endif
vk_buffer_destroy(&device->vk, pAllocator, &buffer->vk);
}
......@@ -76,7 +82,18 @@ nvk_BindBufferMemory2(VkDevice _device,
VK_FROM_HANDLE(nvk_buffer, buffer, pBindInfos[i].buffer);
buffer->mem = mem;
#if NVK_NEW_UAPI == 0
buffer->addr = mem->bo->offset + pBindInfos[i].memoryOffset;
#else
VK_FROM_HANDLE(nvk_device, device, _device);
struct nouveau_ws_device *dev = device->pdev->dev;
buffer->addr = nouveau_ws_alloc_vma(dev, buffer->aligned_size, 4096);
nouveau_ws_bo_bind_vma(device->pdev->dev,
mem->bo->handle,
buffer->addr,
buffer->aligned_size,
pBindInfos[i].memoryOffset, 0);
#endif
}
return VK_SUCCESS;
}
......
......@@ -76,21 +76,27 @@ nvk_allocate_memory(struct nvk_device *device,
{
VkMemoryType *type = &device->pdev->mem_types[pAllocateInfo->memoryTypeIndex];
struct nvk_device_memory *mem;
uint64_t align = (1ULL << 12), size;
mem = vk_object_alloc(&device->vk, pAllocator, sizeof(*mem),
VK_OBJECT_TYPE_DEVICE_MEMORY);
if (!mem)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
enum nouveau_ws_bo_flags flags;
if (type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
if (type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
flags = NOUVEAU_WS_BO_LOCAL;
else
align = (1ULL << 16);
} else
flags = NOUVEAU_WS_BO_GART;
if (type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
flags |= NOUVEAU_WS_BO_MAP;
size = pAllocateInfo->allocationSize;
#if NVK_NEW_UAPI == 1
flags |= NOUVEAU_WS_BO_NO_VMA;
size = ALIGN(size, align);
#endif
mem->map = NULL;
if (tile_info) {
mem->bo = nouveau_ws_bo_new_tiled(device->pdev->dev,
......@@ -100,7 +106,7 @@ nvk_allocate_memory(struct nvk_device *device,
flags);
} else {
mem->bo = nouveau_ws_bo_new(device->pdev->dev,
pAllocateInfo->allocationSize, 0, flags);
size, align, flags);
}
if (!mem->bo) {
vk_object_free(&device->vk, pAllocator, mem);
......
......@@ -292,6 +292,7 @@ nvk_CreateImage(VkDevice _device,
return result;
}
#if NVK_NEW_UAPI == 0
if (image->nil.pte_kind) {
assert(device->pdev->mem_heaps[0].flags &
VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
......@@ -317,6 +318,7 @@ nvk_CreateImage(VkDevice _device,
image->mem = image->internal;
image->offset = 0;
}
#endif
*pImage = nvk_image_to_handle(image);
......@@ -334,8 +336,16 @@ nvk_DestroyImage(VkDevice _device,
if (!image)
return;
#if NVK_NEW_UAPI == 0
if (image->internal)
nvk_free_memory(device, image->internal, pAllocator);
#else
struct nouveau_ws_device *dev = device->pdev->dev;
if (image->mem) {
nouveau_ws_bo_unbind_vma(dev, image->addr, image->nil.size_B);
nouveau_ws_free_vma(dev, image->addr, image->nil.size_B);
}
#endif
nvk_image_finish(image);
vk_free2(&device->vk.alloc, pAllocator, image);
......@@ -411,11 +421,25 @@ nvk_BindImageMemory2(VkDevice _device,
VK_FROM_HANDLE(nvk_device_memory, mem, pBindInfos[i].memory);
VK_FROM_HANDLE(nvk_image, image, pBindInfos[i].image);
#if NVK_NEW_UAPI == 0
if (image->internal)
continue;
#endif
image->mem = mem;
image->offset = pBindInfos[i].memoryOffset;
#if NVK_NEW_UAPI == 1
VK_FROM_HANDLE(nvk_device, device, _device);
struct nouveau_ws_device *dev = device->pdev->dev;
image->addr = nouveau_ws_alloc_vma(dev, image->nil.size_B, image->nil.align_B);
nouveau_ws_bo_bind_vma(device->pdev->dev,
mem->bo->handle,
image->addr,
image->nil.size_B,
image->offset,
image->nil.pte_kind);
#endif
}
return VK_SUCCESS;
}
......@@ -17,12 +17,16 @@ nvk_get_image_format_features(struct nvk_physical_device *pdevice,
struct nvk_image {
struct vk_image vk;
#if NVK_NEW_UAPI == 0
/* Used for internal dedicated allocations */
struct nvk_device_memory *internal;
#endif
struct nvk_device_memory *mem;
VkDeviceSize offset;
#if NVK_NEW_UAPI == 1
VkDeviceSize addr;
#endif
struct nil_image nil;
};
......@@ -31,7 +35,11 @@ VK_DEFINE_HANDLE_CASTS(nvk_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
static inline uint64_t
nvk_image_base_address(const struct nvk_image *image)
{
#if NVK_NEW_UAPI == 0
return image->mem->bo->offset + image->offset;
#else
return image->addr;
#endif
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment