From 7f0c06e1306d6f4aa597dbacec477b812ccb2d86 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 17 Jul 2023 16:49:24 -0500 Subject: [PATCH] nvk: Dedicated allocations override internal Part-of: --- src/nouveau/vulkan/nvk_device_memory.c | 24 +++++++++++++++++++++++- src/nouveau/vulkan/nvk_device_memory.h | 3 +++ src/nouveau/vulkan/nvk_image.c | 20 ++++++++++---------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/nouveau/vulkan/nvk_device_memory.c b/src/nouveau/vulkan/nvk_device_memory.c index d22906815b2..375a5b8be3f 100644 --- a/src/nouveau/vulkan/nvk_device_memory.c +++ b/src/nouveau/vulkan/nvk_device_memory.c @@ -3,6 +3,7 @@ #include "nouveau_bo.h" #include "nvk_device.h" +#include "nvk_image.h" #include "nvk_physical_device.h" #include "nv_push.h" @@ -191,10 +192,31 @@ nvk_AllocateMemory(VkDevice device, struct nvk_device_memory *mem; VkResult result; - result = nvk_allocate_memory(dev, pAllocateInfo, NULL, pAllocator, &mem); + const VkMemoryDedicatedAllocateInfo *dedicated_info = + vk_find_struct_const(pAllocateInfo->pNext, + MEMORY_DEDICATED_ALLOCATE_INFO); + + struct nvk_image_plane *dedicated_image_plane = NULL; + struct nvk_memory_tiling_info tile_info, *p_tile_info = NULL; + if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) { + VK_FROM_HANDLE(nvk_image, image, dedicated_info->image); + if (image->plane_count == 1 && image->planes[0].nil.pte_kind) { + dedicated_image_plane = &image->planes[0]; + tile_info = (struct nvk_memory_tiling_info) { + .tile_mode = image->planes[0].nil.tile_mode, + .pte_kind = image->planes[0].nil.pte_kind, + }; + p_tile_info = &tile_info; + } + } + + result = nvk_allocate_memory(dev, pAllocateInfo, p_tile_info, + pAllocator, &mem); if (result != VK_SUCCESS) return result; + mem->dedicated_image_plane = dedicated_image_plane; + *pMem = nvk_device_memory_to_handle(mem); return VK_SUCCESS; diff --git a/src/nouveau/vulkan/nvk_device_memory.h b/src/nouveau/vulkan/nvk_device_memory.h index cb24b122b3a..a8cfe4397bc 100644 --- a/src/nouveau/vulkan/nvk_device_memory.h +++ b/src/nouveau/vulkan/nvk_device_memory.h @@ -8,12 +8,15 @@ #include "util/list.h" struct nvk_device; +struct nvk_image_plane; struct nvk_device_memory { struct vk_device_memory vk; struct list_head link; + struct nvk_image_plane *dedicated_image_plane; + struct nouveau_ws_bo *bo; void *map; diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 17c97c88a73..8cfa435ac56 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -409,15 +409,8 @@ nvk_image_plane_alloc_internal(struct nvk_device *dev, .tile_mode = plane->nil.tile_mode, .pte_kind = plane->nil.pte_kind, }; - VkResult result = nvk_allocate_memory(dev, &alloc_info, &tile_info, - pAllocator, &plane->internal); - if (result != VK_SUCCESS) - return result; - - plane->mem = plane->internal; - plane->offset = 0; - - return VK_SUCCESS; + return nvk_allocate_memory(dev, &alloc_info, &tile_info, + pAllocator, &plane->internal); } VKAPI_ATTR VkResult VKAPI_CALL @@ -610,7 +603,14 @@ nvk_image_plane_bind(struct nvk_image_plane *plane, uint64_t *offset_B) { *offset_B = ALIGN_POT(*offset_B, plane->nil.align_B); - if (plane->internal == NULL) { + if (mem->dedicated_image_plane == plane) { + assert(*offset_B == 0); + plane->mem = mem; + plane->offset = 0; + } else if (plane->internal != NULL) { + plane->mem = plane->internal; + plane->offset = 0; + } else { plane->mem = mem; plane->offset = *offset_B; }