From dcaf64102fc133f1e6358bbc22d70e7375e5e5c5 Mon Sep 17 00:00:00 2001 From: Mohamed Ahmed Date: Fri, 3 Oct 2025 19:43:37 +0300 Subject: [PATCH] nvk: Move non-sparse image plane VA allocation to bind time This is done in preparation of compression enablement to avoid allocating a VA and then delete it later because compressed images use the memory object VA and not the image plane VA. This guarantees we never put the image in an invalid state and saves us an alloc and free in case of compressed images. Reviewed-by: Mel Henning Part-of: --- src/nouveau/vulkan/nvk_image.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 331d9ddb54a..7dc9af6cf47 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -1112,16 +1112,19 @@ nvk_CreateImage(VkDevice _device, return result; } - for (uint8_t plane = 0; plane < image->plane_count; plane++) { - result = nvk_image_plane_alloc_va(dev, image, &image->planes[plane]); - if (result != VK_SUCCESS) - goto fail; - } + if (image->vk.create_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | + VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)) { + for (uint8_t plane = 0; plane < image->plane_count; plane++) { + result = nvk_image_plane_alloc_va(dev, image, &image->planes[plane]); + if (result != VK_SUCCESS) + goto fail; + } - if (image->stencil_copy_temp.nil.size_B > 0) { - result = nvk_image_plane_alloc_va(dev, image, &image->stencil_copy_temp); - if (result != VK_SUCCESS) - goto fail; + if (image->stencil_copy_temp.nil.size_B > 0) { + result = nvk_image_plane_alloc_va(dev, image, &image->stencil_copy_temp); + if (result != VK_SUCCESS) + goto fail; + } } if (image->linear_tiled_shadow.nil.size_B > 0) { @@ -1476,14 +1479,16 @@ nvk_image_plane_bind(struct nvk_device *dev, &plane_size_B, &plane_align_B); *offset_B = align64(*offset_B, plane_align_B); - if (plane->va != NULL) { - VkResult result = nvkmd_va_bind_mem(plane->va, &image->vk.base, 0, - mem->mem, *offset_B, - plane->va->size_B); + if (plane->nil.pte_kind != 0) { + VkResult result = nvk_image_plane_alloc_va(dev, image, plane); + if (result != VK_SUCCESS) + return result; + result = nvkmd_va_bind_mem(plane->va, &image->vk.base, 0, + mem->mem, *offset_B, + plane->va->size_B); if (result != VK_SUCCESS) return result; } else { - assert(plane->nil.pte_kind == 0); plane->addr = mem->mem->va->addr + *offset_B; }