From 02b4647a1c67b5643de10a27852e46ac2327286a Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Fri, 29 Aug 2025 16:21:06 -0400 Subject: [PATCH] nvk: Add a dedicated_image to nvk_device_memory Also refactor the dedicated image handling a tiny bit to make the next bit easier. Reviewed-by: Mel Henning Part-of: --- src/nouveau/vulkan/nvk_device_memory.c | 18 ++++++++++-------- src/nouveau/vulkan/nvk_device_memory.h | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/nouveau/vulkan/nvk_device_memory.c b/src/nouveau/vulkan/nvk_device_memory.c index 6b6258c8552..72d81673b8b 100644 --- a/src/nouveau/vulkan/nvk_device_memory.c +++ b/src/nouveau/vulkan/nvk_device_memory.c @@ -133,6 +133,11 @@ nvk_AllocateMemory(VkDevice device, struct nvk_device_memory *mem; VkResult result = VK_SUCCESS; + mem = vk_device_memory_create(&dev->vk, pAllocateInfo, + pAllocator, sizeof(*mem)); + if (!mem) + return vk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY); + const VkImportMemoryFdInfoKHR *fd_info = vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR); const VkExportMemoryAllocateInfo *export_info = @@ -153,10 +158,12 @@ nvk_AllocateMemory(VkDevice device, uint32_t alignment = pdev->nvkmd->bind_align_B; uint8_t pte_kind = 0, tile_mode = 0; - if (dedicated_info != NULL) { + if (dedicated_info != NULL && dedicated_info->image != VK_NULL_HANDLE) { VK_FROM_HANDLE(nvk_image, image, dedicated_info->image); - if (image != NULL && - image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { + + mem->dedicated_image = image; + + if (image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) { /* This image might be shared with GL so we need to set the BO flags * such that GL can bind and use it. */ @@ -170,11 +177,6 @@ nvk_AllocateMemory(VkDevice device, const uint64_t aligned_size = align64(pAllocateInfo->allocationSize, alignment); - mem = vk_device_memory_create(&dev->vk, pAllocateInfo, - pAllocator, sizeof(*mem)); - if (!mem) - return vk_error(dev, VK_ERROR_OUT_OF_HOST_MEMORY); - const bool is_import = fd_info && fd_info->handleType; if (is_import) { assert(fd_info->handleType == diff --git a/src/nouveau/vulkan/nvk_device_memory.h b/src/nouveau/vulkan/nvk_device_memory.h index 4d2f751f111..cfceeae5352 100644 --- a/src/nouveau/vulkan/nvk_device_memory.h +++ b/src/nouveau/vulkan/nvk_device_memory.h @@ -11,11 +11,14 @@ #include "util/list.h" +struct nvk_image; struct nvkmd_mem; struct nvk_device_memory { struct vk_device_memory vk; + struct nvk_image *dedicated_image; + struct nvkmd_mem *mem; };