nvk: Do internal dedicated allocations for ZS images
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Tue, 31 Jan 2023 02:11:54 +0000 (20:11 -0600)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:58 +0000 (21:31 +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
src/nouveau/vulkan/nvk_image.h

index 28c8f73..1697701 100644 (file)
@@ -72,6 +72,7 @@ zero_vram(struct nvk_device *dev, struct nouveau_ws_bo *bo)
 VkResult
 nvk_allocate_memory(struct nvk_device *device,
                     const VkMemoryAllocateInfo *pAllocateInfo,
+                    const struct nvk_memory_tiling_info *tile_info,
                     const VkAllocationCallbacks *pAllocator,
                     struct nvk_device_memory **mem_out)
 {
@@ -92,7 +93,16 @@ nvk_allocate_memory(struct nvk_device *device,
       flags |= NOUVEAU_WS_BO_MAP;
 
    mem->map = NULL;
-   mem->bo = nouveau_ws_bo_new(device->pdev->dev, pAllocateInfo->allocationSize, 0, flags);
+   if (tile_info) {
+      mem->bo = nouveau_ws_bo_new_tiled(device->pdev->dev,
+                                        pAllocateInfo->allocationSize, 0,
+                                        tile_info->pte_kind,
+                                        tile_info->tile_mode,
+                                        flags);
+   } else {
+      mem->bo = nouveau_ws_bo_new(device->pdev->dev,
+                                  pAllocateInfo->allocationSize, 0, flags);
+   }
    if (!mem->bo) {
       vk_object_free(&device->vk, pAllocator, mem);
       return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -158,7 +168,7 @@ nvk_AllocateMemory(
    struct nvk_device_memory *mem;
    VkResult result;
 
-   result = nvk_allocate_memory(device, pAllocateInfo, pAllocator, &mem);
+   result = nvk_allocate_memory(device, pAllocateInfo, NULL, pAllocator, &mem);
    if (result != VK_SUCCESS)
       return result;
 
index 0a5b6d6..b1dfd48 100644 (file)
@@ -19,8 +19,14 @@ struct nvk_device_memory {
 
 VK_DEFINE_HANDLE_CASTS(nvk_device_memory, base, VkDeviceMemory, VK_OBJECT_TYPE_DEVICE_MEMORY)
 
+struct nvk_memory_tiling_info {
+   uint16_t tile_mode;
+   uint8_t pte_kind;
+};
+
 VkResult nvk_allocate_memory(struct nvk_device *device,
                              const VkMemoryAllocateInfo *pAllocateInfo,
+                             const struct nvk_memory_tiling_info *tile_info,
                              const VkAllocationCallbacks *pAllocator,
                              struct nvk_device_memory **mem_out);
 
index 6ef498f..6ff85bf 100644 (file)
@@ -259,6 +259,32 @@ nvk_CreateImage(VkDevice _device,
       return result;
    }
 
+   if (image->nil.pte_kind) {
+      assert(device->pdev->mem_heaps[0].flags &
+             VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
+
+      const VkMemoryAllocateInfo alloc_info = {
+         .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+         .allocationSize = image->nil.size_B,
+         .memoryTypeIndex = 0,
+      };
+      const struct nvk_memory_tiling_info tile_info = {
+         .tile_mode = image->nil.tile_mode,
+         .pte_kind = image->nil.pte_kind,
+      };
+
+      result = nvk_allocate_memory(device, &alloc_info, &tile_info,
+                                   pAllocator, &image->internal);
+      if (result != VK_SUCCESS) {
+         nvk_image_finish(image);
+         vk_free2(&device->vk.alloc, pAllocator, image);
+         return result;
+      }
+
+      image->mem = image->internal;
+      image->offset = 0;
+   }
+
    *pImage = nvk_image_to_handle(image);
 
    return VK_SUCCESS;
@@ -275,6 +301,9 @@ nvk_DestroyImage(VkDevice _device,
    if (!image)
       return;
 
+   if (image->internal)
+      nvk_free_memory(device, image->internal, pAllocator);
+
    nvk_image_finish(image);
    vk_free2(&device->vk.alloc, pAllocator, image);
 }
@@ -338,6 +367,9 @@ nvk_BindImageMemory2(VkDevice _device,
       VK_FROM_HANDLE(nvk_device_memory, mem, pBindInfos[i].memory);
       VK_FROM_HANDLE(nvk_image, image, pBindInfos[i].image);
 
+      if (image->internal)
+         continue;
+
       image->mem = mem;
       image->offset = pBindInfos[i].memoryOffset;
    }
index 4b69aa7..e1fc705 100644 (file)
@@ -17,6 +17,10 @@ nvk_get_image_format_features(struct nvk_physical_device *pdevice,
 
 struct nvk_image {
    struct vk_image vk;
+
+   /* Used for internal dedicated allocations */
+   struct nvk_device_memory *internal;
+
    struct nvk_device_memory *mem;
    VkDeviceSize offset;