nvk: Do internal dedicated allocations for ZS images

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand
2023-01-30 20:11:54 -06:00
committed by Marge Bot
parent ba70017f68
commit 78009a1a9a
4 changed files with 54 additions and 2 deletions

View File

@@ -72,6 +72,7 @@ zero_vram(struct nvk_device *dev, struct nouveau_ws_bo *bo)
VkResult
nvk_allocate_memory(struct nvk_device *device,
const VkMemoryAllocateInfo *pAllocateInfo,
const struct nvk_memory_tiling_info *tile_info,
const VkAllocationCallbacks *pAllocator,
struct nvk_device_memory **mem_out)
{
@@ -92,7 +93,16 @@ nvk_allocate_memory(struct nvk_device *device,
flags |= NOUVEAU_WS_BO_MAP;
mem->map = NULL;
mem->bo = nouveau_ws_bo_new(device->pdev->dev, pAllocateInfo->allocationSize, 0, flags);
if (tile_info) {
mem->bo = nouveau_ws_bo_new_tiled(device->pdev->dev,
pAllocateInfo->allocationSize, 0,
tile_info->pte_kind,
tile_info->tile_mode,
flags);
} else {
mem->bo = nouveau_ws_bo_new(device->pdev->dev,
pAllocateInfo->allocationSize, 0, flags);
}
if (!mem->bo) {
vk_object_free(&device->vk, pAllocator, mem);
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -158,7 +168,7 @@ nvk_AllocateMemory(
struct nvk_device_memory *mem;
VkResult result;
result = nvk_allocate_memory(device, pAllocateInfo, pAllocator, &mem);
result = nvk_allocate_memory(device, pAllocateInfo, NULL, pAllocator, &mem);
if (result != VK_SUCCESS)
return result;

View File

@@ -19,8 +19,14 @@ struct nvk_device_memory {
VK_DEFINE_HANDLE_CASTS(nvk_device_memory, base, VkDeviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY)
struct nvk_memory_tiling_info {
uint16_t tile_mode;
uint8_t pte_kind;
};
VkResult nvk_allocate_memory(struct nvk_device *device,
const VkMemoryAllocateInfo *pAllocateInfo,
const struct nvk_memory_tiling_info *tile_info,
const VkAllocationCallbacks *pAllocator,
struct nvk_device_memory **mem_out);

View File

@@ -259,6 +259,32 @@ nvk_CreateImage(VkDevice _device,
return result;
}
if (image->nil.pte_kind) {
assert(device->pdev->mem_heaps[0].flags &
VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
const VkMemoryAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = image->nil.size_B,
.memoryTypeIndex = 0,
};
const struct nvk_memory_tiling_info tile_info = {
.tile_mode = image->nil.tile_mode,
.pte_kind = image->nil.pte_kind,
};
result = nvk_allocate_memory(device, &alloc_info, &tile_info,
pAllocator, &image->internal);
if (result != VK_SUCCESS) {
nvk_image_finish(image);
vk_free2(&device->vk.alloc, pAllocator, image);
return result;
}
image->mem = image->internal;
image->offset = 0;
}
*pImage = nvk_image_to_handle(image);
return VK_SUCCESS;
@@ -275,6 +301,9 @@ nvk_DestroyImage(VkDevice _device,
if (!image)
return;
if (image->internal)
nvk_free_memory(device, image->internal, pAllocator);
nvk_image_finish(image);
vk_free2(&device->vk.alloc, pAllocator, image);
}
@@ -338,6 +367,9 @@ nvk_BindImageMemory2(VkDevice _device,
VK_FROM_HANDLE(nvk_device_memory, mem, pBindInfos[i].memory);
VK_FROM_HANDLE(nvk_image, image, pBindInfos[i].image);
if (image->internal)
continue;
image->mem = mem;
image->offset = pBindInfos[i].memoryOffset;
}

View File

@@ -17,6 +17,10 @@ nvk_get_image_format_features(struct nvk_physical_device *pdevice,
struct nvk_image {
struct vk_image vk;
/* Used for internal dedicated allocations */
struct nvk_device_memory *internal;
struct nvk_device_memory *mem;
VkDeviceSize offset;