zink: allow sparse buffers to be suballocated
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Fri, 7 Jan 2022 17:56:31 +0000 (12:56 -0500)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Jan 2022 15:51:30 +0000 (15:51 +0000)
this is now symmetrical since the backing memory was being cached,
and there's no reason not to allow this since memory is no longer in use
by the time it gets returned to the cache

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14381>

src/gallium/drivers/zink/zink_bo.c

index 017a964..60d21cf 100644 (file)
@@ -357,7 +357,7 @@ sparse_backing_alloc(struct zink_screen *screen, struct zink_bo *bo,
       size = MAX2(size, ZINK_SPARSE_BUFFER_PAGE_SIZE);
 
       buf = zink_bo_create(screen, size, ZINK_SPARSE_BUFFER_PAGE_SIZE,
-                           ZINK_HEAP_DEVICE_LOCAL, ZINK_ALLOC_NO_SUBALLOC, NULL);
+                           ZINK_HEAP_DEVICE_LOCAL, 0, NULL);
       if (!buf) {
          FREE(best_backing->chunks);
          FREE(best_backing);
@@ -708,8 +708,8 @@ buffer_commit_single(struct zink_screen *screen, struct zink_resource *res, stru
    VkSparseMemoryBind mem_bind;
    mem_bind.resourceOffset = offset;
    mem_bind.size = MIN2(res->base.b.width0 - offset, size);
-   mem_bind.memory = commit ? bo->mem : VK_NULL_HANDLE;
-   mem_bind.memoryOffset = 0;
+   mem_bind.memory = commit ? (bo->mem ? bo->mem : bo->u.slab.real->mem) : VK_NULL_HANDLE;
+   mem_bind.memoryOffset = commit ? (bo->mem ? 0 : bo->offset) : 0;
    mem_bind.flags = 0;
    sparse_bind.pBinds = &mem_bind;
 
@@ -841,8 +841,8 @@ texture_commit_single(struct zink_screen *screen, struct zink_resource *res, str
    ibind.subresource = *subresource;
    ibind.offset = *offset;
    ibind.extent = *extents;
-   ibind.memory = commit ? bo->mem : VK_NULL_HANDLE;
-   ibind.memoryOffset = 0;
+   ibind.memory = commit ? (bo->mem ? bo->mem : bo->u.slab.real->mem) : VK_NULL_HANDLE;
+   ibind.memoryOffset = commit ? (bo->mem ? 0 : bo->offset) : 0;
    ibind.flags = 0;
    sparse_ibind.image = res->obj->image;
    sparse_ibind.bindCount = 1;