From: Faith Ekstrand Date: Tue, 31 Jan 2023 02:11:54 +0000 (-0600) Subject: nvk: Do internal dedicated allocations for ZS images X-Git-Tag: upstream/23.3.3~4348 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78009a1a9a650d045ff318759963412c73b4b39f;p=platform%2Fupstream%2Fmesa.git nvk: Do internal dedicated allocations for ZS images Part-of: --- diff --git a/src/nouveau/vulkan/nvk_device_memory.c b/src/nouveau/vulkan/nvk_device_memory.c index 28c8f73..1697701 100644 --- a/src/nouveau/vulkan/nvk_device_memory.c +++ b/src/nouveau/vulkan/nvk_device_memory.c @@ -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; diff --git a/src/nouveau/vulkan/nvk_device_memory.h b/src/nouveau/vulkan/nvk_device_memory.h index 0a5b6d6..b1dfd48 100644 --- a/src/nouveau/vulkan/nvk_device_memory.h +++ b/src/nouveau/vulkan/nvk_device_memory.h @@ -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); diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 6ef498f..6ff85bf 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -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; } diff --git a/src/nouveau/vulkan/nvk_image.h b/src/nouveau/vulkan/nvk_image.h index 4b69aa7..e1fc705 100644 --- a/src/nouveau/vulkan/nvk_image.h +++ b/src/nouveau/vulkan/nvk_image.h @@ -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;