turnip: Always use UINT formats for copies.
authorBas Nieuwenhuizen <basni@chromium.org>
Fri, 20 Sep 2019 11:49:44 +0000 (13:49 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Fri, 27 Sep 2019 13:05:21 +0000 (15:05 +0200)
Looks like r16_unorm might have precision issues.

dEQP-VK.api.copy_and_blit.core.image_to_image.all_formats.color.r16_unorm.r16_unorm.general_general

fails, but the dumped images in the xml are the same so
I'd guess the low bits are the issue.

r8_unorm and r16_uint work.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/freedreno/vulkan/tu_meta_copy.c

index f000c947b96903565e375d845fa10734f4d39cce..5e915e97836aaa85b5cd18543cd7a2ee20e0c1db 100644 (file)
@@ -89,6 +89,32 @@ tu_dma_prepare(struct tu_cmd_buffer *cmdbuf)
    tu_cs_emit(&cmdbuf->cs, 0x10000000);
 }
 
+/* Always use UINT formats to avoid precision issues.
+ *
+ * Example failure it avoids:
+ *   - dEQP-VK.api.copy_and_blit.core.image_to_image.all_formats.color.r16_unorm.r16_unorm.general_general
+ */
+static VkFormat
+tu_canonical_copy_format(VkFormat format)
+{
+   switch (vk_format_get_blocksizebits(format)) {
+   case 8:
+      return VK_FORMAT_R8_UINT;
+   case 16:
+      return VK_FORMAT_R16_UINT;
+   case 32:
+      return VK_FORMAT_R32_UINT;
+   case 64:
+      return VK_FORMAT_R32G32_UINT;
+   case 96:
+      return VK_FORMAT_R32G32B32_UINT;
+   case 128:
+      return VK_FORMAT_R32G32B32A32_UINT;
+   default:
+      unreachable("unhandled format size");
+   }
+}
+
 static void
 tu_copy_buffer(struct tu_cmd_buffer *cmdbuf,
                struct tu_bo *src_bo,
@@ -357,7 +383,7 @@ tu_copy_buffer_to_image(struct tu_cmd_buffer *cmdbuf,
    tu_cs_emit_pkt7(&cmdbuf->cs, CP_SET_MARKER, 1);
    tu_cs_emit(&cmdbuf->cs, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
 
-   VkFormat format = dst_image->vk_format;
+   VkFormat format = tu_canonical_copy_format(dst_image->vk_format);
    const enum a6xx_color_fmt rb_fmt = tu6_get_native_format(format)->rb;
 
    const uint32_t blit_cntl = blit_control(rb_fmt) | 0x20000000;
@@ -547,7 +573,7 @@ tu_copy_image_to_buffer(struct tu_cmd_buffer *cmdbuf,
    tu_cs_emit_pkt7(&cmdbuf->cs, CP_SET_MARKER, 1);
    tu_cs_emit(&cmdbuf->cs, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
 
-   VkFormat format = src_image->vk_format;
+   VkFormat format = tu_canonical_copy_format(src_image->vk_format);
    const enum a6xx_color_fmt rb_fmt = tu6_get_native_format(format)->rb;
 
    unsigned dst_pixel_stride = copy_info->bufferRowLength
@@ -743,7 +769,7 @@ tu_copy_image_to_image(struct tu_cmd_buffer *cmdbuf,
    tu_cs_emit_pkt7(&cmdbuf->cs, CP_SET_MARKER, 1);
    tu_cs_emit(&cmdbuf->cs, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
 
-   VkFormat format = src_image->vk_format;
+   VkFormat format = tu_canonical_copy_format(src_image->vk_format);
    const enum a6xx_color_fmt rb_fmt = tu6_get_native_format(format)->rb;
    const uint32_t blit_cntl = blit_control(rb_fmt) | 0x20000000;