nvk: Dedicated allocations override internal
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Mon, 17 Jul 2023 21:49:24 +0000 (16:49 -0500)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:32:06 +0000 (21:32 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/nvk_device_memory.c
src/nouveau/vulkan/nvk_device_memory.h
src/nouveau/vulkan/nvk_image.c

index d229068..375a5b8 100644 (file)
@@ -3,6 +3,7 @@
 #include "nouveau_bo.h"
 
 #include "nvk_device.h"
+#include "nvk_image.h"
 #include "nvk_physical_device.h"
 #include "nv_push.h"
 
@@ -191,10 +192,31 @@ nvk_AllocateMemory(VkDevice device,
    struct nvk_device_memory *mem;
    VkResult result;
 
-   result = nvk_allocate_memory(dev, pAllocateInfo, NULL, pAllocator, &mem);
+   const VkMemoryDedicatedAllocateInfo *dedicated_info =
+      vk_find_struct_const(pAllocateInfo->pNext,
+                           MEMORY_DEDICATED_ALLOCATE_INFO);
+
+   struct nvk_image_plane *dedicated_image_plane = NULL;
+   struct nvk_memory_tiling_info tile_info, *p_tile_info = NULL;
+   if (dedicated_info && dedicated_info->image != VK_NULL_HANDLE) {
+      VK_FROM_HANDLE(nvk_image, image, dedicated_info->image);
+      if (image->plane_count == 1 && image->planes[0].nil.pte_kind) {
+         dedicated_image_plane = &image->planes[0];
+         tile_info = (struct nvk_memory_tiling_info) {
+            .tile_mode = image->planes[0].nil.tile_mode,
+            .pte_kind = image->planes[0].nil.pte_kind,
+         };
+         p_tile_info = &tile_info;
+      }
+   }
+
+   result = nvk_allocate_memory(dev, pAllocateInfo, p_tile_info,
+                                pAllocator, &mem);
    if (result != VK_SUCCESS)
       return result;
 
+   mem->dedicated_image_plane = dedicated_image_plane;
+
    *pMem = nvk_device_memory_to_handle(mem);
 
    return VK_SUCCESS;
index cb24b12..a8cfe43 100644 (file)
@@ -8,12 +8,15 @@
 #include "util/list.h"
 
 struct nvk_device;
+struct nvk_image_plane;
 
 struct nvk_device_memory {
    struct vk_device_memory vk;
 
    struct list_head link;
 
+   struct nvk_image_plane *dedicated_image_plane;
+
    struct nouveau_ws_bo *bo;
 
    void *map;
index 17c97c8..8cfa435 100644 (file)
@@ -409,15 +409,8 @@ nvk_image_plane_alloc_internal(struct nvk_device *dev,
       .tile_mode = plane->nil.tile_mode,
       .pte_kind = plane->nil.pte_kind,
    };
-   VkResult result = nvk_allocate_memory(dev, &alloc_info, &tile_info,
-                                         pAllocator, &plane->internal);
-   if (result != VK_SUCCESS)
-      return result;
-
-   plane->mem = plane->internal;
-   plane->offset = 0;
-
-   return VK_SUCCESS;
+   return nvk_allocate_memory(dev, &alloc_info, &tile_info,
+                              pAllocator, &plane->internal);
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL
@@ -610,7 +603,14 @@ nvk_image_plane_bind(struct nvk_image_plane *plane,
                      uint64_t *offset_B)
 {
    *offset_B = ALIGN_POT(*offset_B, plane->nil.align_B);
-   if (plane->internal == NULL) {
+   if (mem->dedicated_image_plane == plane) {
+      assert(*offset_B == 0);
+      plane->mem = mem;
+      plane->offset = 0;
+   } else if (plane->internal != NULL) {
+      plane->mem = plane->internal;
+      plane->offset = 0;
+   } else {
       plane->mem = mem;
       plane->offset = *offset_B;
    }