turnip: enable 422_UNORM formats
authorJonathan Marek <jonathan@marek.ca>
Fri, 10 Apr 2020 01:01:35 +0000 (21:01 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 20 May 2020 13:22:12 +0000 (13:22 +0000)
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4590>

src/freedreno/vulkan/tu_formats.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/vk_format.h

index bf76e93b36b4ee70b13f54ec7db5be3784b17728..8ecdbdbdc90a8ba7d94c22eafb381c338fc68534 100644 (file)
@@ -283,23 +283,39 @@ static const struct tu_native_format tu6_format_table[] = {
    TU6_xTx(ASTC_12x12_SRGB_BLOCK,      ASTC_12x12,        WZYX), /* 184 */
 };
 
+#define FMT_EXT_BASE VK_FORMAT_G8B8G8R8_422_UNORM
+#undef TU6_FMT
+#define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
+   [VK_FORMAT_##vkfmt - FMT_EXT_BASE] = {                   \
+      .fmt = FMT6_##hwfmt,                     \
+      .swap = swapfmt,                       \
+      .supported = valid,                    \
+   }
+
+static const struct tu_native_format tu6_format_table_ext[] = {
+   TU6_xTx(G8B8G8R8_422_UNORM,         R8G8R8B8_422_UNORM,        WZYX), /* 0 */
+   TU6_xTx(B8G8R8G8_422_UNORM,         G8R8B8R8_422_UNORM,        WZYX), /* 1 */
+};
+
 static struct tu_native_format
 tu6_get_native_format(VkFormat format)
 {
    struct tu_native_format fmt = {};
 
-   if (format >= ARRAY_SIZE(tu6_format_table))
-      return fmt;
-
-   if (!tu6_format_table[format].supported)
-      return fmt;
+   if (format < ARRAY_SIZE(tu6_format_table)) {
+      fmt = tu6_format_table[format];
+   } else if (format >= FMT_EXT_BASE) {
+      unsigned idx = format - FMT_EXT_BASE;
+      if (idx < ARRAY_SIZE(tu6_format_table_ext))
+         fmt = tu6_format_table_ext[idx];
+   }
 
-   if (vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE) {
+   if (fmt.supported && vk_format_to_pipe_format(format) == PIPE_FORMAT_NONE) {
       tu_finishme("vk_format %d missing matching pipe format.\n", format);
-      return fmt;
+      fmt.supported = false;
    }
 
-   return tu6_format_table[format];
+   return fmt;
 }
 
 struct tu_native_format
index 1808d78a45d28848bc82be25897db9ddbf86d0c7..0867c30f0a6a8bce481dcec7c9fa89beefabdc45 100644 (file)
@@ -89,9 +89,10 @@ tu_image_create(VkDevice _device,
    bool ubwc_enabled =
       !(device->physical_device->instance->debug_flags & TU_DEBUG_NOUBWC);
 
-   /* disable tiling when linear is requested and for compressed formats */
+   /* disable tiling when linear is requested and for YUYV/UYVY */
    if (pCreateInfo->tiling == VK_IMAGE_TILING_LINEAR ||
-       modifier == DRM_FORMAT_MOD_LINEAR) {
+       modifier == DRM_FORMAT_MOD_LINEAR ||
+       vk_format_description(image->vk_format)->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) {
       image->layout.tile_mode = TILE6_LINEAR;
       ubwc_enabled = false;
    }
@@ -204,6 +205,12 @@ tu6_texswiz(const VkComponentMapping *comps,
    };
 
    switch (format) {
+   case VK_FORMAT_G8B8G8R8_422_UNORM:
+   case VK_FORMAT_B8G8R8G8_422_UNORM:
+      swiz[0] = A6XX_TEX_Z;
+      swiz[1] = A6XX_TEX_X;
+      swiz[2] = A6XX_TEX_Y;
+      break;
    case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
    case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
       /* same hardware format is used for BC1_RGB / BC1_RGBA */
@@ -556,8 +563,7 @@ tu_GetImageSubresourceLayout(VkDevice _device,
                                         pSubresource->mipLevel,
                                         pSubresource->arrayLayer);
    pLayout->size = slice->size0;
-   pLayout->rowPitch =
-      slice->pitch * vk_format_get_blockheight(image->vk_format);
+   pLayout->rowPitch = slice->pitch;
    pLayout->arrayPitch = image->layout.layer_size;
    pLayout->depthPitch = slice->size0;
 
index 7b041b60625cd59c0b5135990e0701c57cf425e8..516ba7a2ec446c501c286a958cf518fe63a87981 100644 (file)
@@ -167,7 +167,8 @@ vk_format_compose_swizzles(const VkComponentMapping *mapping,
 static inline bool
 vk_format_is_compressed(VkFormat format)
 {
-   return util_format_is_compressed(vk_format_to_pipe_format(format));
+   /* this includes 4:2:2 formats, which are compressed formats for vulkan */
+   return vk_format_get_blockwidth(format) > 1;
 }
 
 static inline bool
@@ -312,6 +313,15 @@ vk_format_get_component_bits(VkFormat format,
                              enum util_format_colorspace colorspace,
                              unsigned component)
 {
+   switch (format) {
+   case VK_FORMAT_G8B8G8R8_422_UNORM:
+   case VK_FORMAT_B8G8R8G8_422_UNORM:
+      /* util_format_get_component_bits doesn't return what we want */
+      return 8;
+   default:
+      break;
+   }
+
    return util_format_get_component_bits(vk_format_to_pipe_format(format),
                                          colorspace, component);
 }