Module: Mesa
Branch: main
Commit: 0ce49d43476295b2df8f4d330866d93607b9feb6
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0ce49d43476295b2df8f4d330866d93607b9feb6

Author: Faith Ekstrand <faith.ekstr...@collabora.com>
Date:   Thu Nov  2 17:03:51 2023 -0500

nvk: Fix nvk_heap_free() for contiguous heaps

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26035>

---

 src/nouveau/vulkan/nvk_heap.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/nouveau/vulkan/nvk_heap.c b/src/nouveau/vulkan/nvk_heap.c
index 6de646bfc9e..7fe5830ef6e 100644
--- a/src/nouveau/vulkan/nvk_heap.c
+++ b/src/nouveau/vulkan/nvk_heap.c
@@ -224,20 +224,30 @@ nvk_heap_free_locked(struct nvk_device *dev, struct 
nvk_heap *heap,
 {
    assert(addr + size > addr);
 
-   for (uint32_t bo_idx = 0; bo_idx < heap->bo_count; bo_idx++) {
-      if (addr < heap->bos[bo_idx].bo->offset)
-         continue;
-
-      uint64_t bo_offset = addr - heap->bos[bo_idx].bo->offset;
-      if (bo_offset >= heap->bos[bo_idx].bo->size)
-         continue;
+   if (heap->contiguous) {
+      assert(heap->bo_count == 1);
+      uint64_t bo_offset = addr;
 
-      assert(bo_offset + size <= heap->bos[bo_idx].bo->size);
-      uint64_t vma = encode_vma(bo_idx, bo_offset);
+      assert(bo_offset + size <= heap->bos[0].bo->size);
+      uint64_t vma = encode_vma(0, bo_offset);
 
       util_vma_heap_free(&heap->heap, vma, size);
+   } else {
+      for (uint32_t bo_idx = 0; bo_idx < heap->bo_count; bo_idx++) {
+         if (addr < heap->bos[bo_idx].bo->offset)
+            continue;
 
-      break;
+         uint64_t bo_offset = addr - heap->bos[bo_idx].bo->offset;
+         if (bo_offset >= heap->bos[bo_idx].bo->size)
+            continue;
+
+         assert(bo_offset + size <= heap->bos[bo_idx].bo->size);
+         uint64_t vma = encode_vma(bo_idx, bo_offset);
+
+         util_vma_heap_free(&heap->heap, vma, size);
+         return;
+      }
+      assert(!"Failed to find heap BO");
    }
 }
 

Reply via email to