dzn: Support native image copies when formats are compatible
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 30 Jun 2022 11:17:12 +0000 (04:17 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 6 Jul 2022 06:15:46 +0000 (06:15 +0000)
CopyTextureRegion() works fine if the formats belong to the
same group (matching the same _TYPELESS type), so let's avoid
creating a temporary resource in that case.

Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17368>

src/microsoft/vulkan/dzn_cmd_buffer.c

index a1bc1fc..123d643 100644 (file)
@@ -3013,9 +3013,24 @@ dzn_CmdCopyImage2(VkCommandBuffer commandBuffer,
 
    assert(src->vk.samples == dst->vk.samples);
 
-   bool requires_temp_res = src->vk.format != dst->vk.format &&
-                            src->vk.tiling != VK_IMAGE_TILING_LINEAR &&
-                            dst->vk.tiling != VK_IMAGE_TILING_LINEAR;
+   bool requires_temp_res = false;
+
+   for (uint32_t i = 0; i < info->regionCount; i++) {
+      const VkImageCopy2 *region = &info->pRegions[i];
+
+      dzn_foreach_aspect(aspect, region->srcSubresource.aspectMask) {
+         assert(aspect & region->dstSubresource.aspectMask);
+
+         if (!dzn_image_formats_are_compatible(device, src->vk.format, dst->vk.format,
+                                               VK_IMAGE_USAGE_TRANSFER_SRC_BIT, aspect) &&
+             src->vk.tiling != VK_IMAGE_TILING_LINEAR &&
+             dst->vk.tiling != VK_IMAGE_TILING_LINEAR) {
+            requires_temp_res = true;
+            break;
+         }
+      }
+   }
+
    bool use_blit = false;
    if (src->vk.samples > 1) {
       use_blit = requires_temp_res;