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 <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38702>
This commit is contained in:
Mohamed Ahmed
2025-10-03 19:43:37 +03:00
committed by Marge Bot
parent 21165c7972
commit dcaf64102f

View File

@@ -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;
}