From 0d9996e223ee6893acba95c7f5100d8345044e6a Mon Sep 17 00:00:00 2001 From: Jonathan Marek Date: Thu, 9 Apr 2020 21:01:35 -0400 Subject: [PATCH] turnip: enable 422_UNORM formats Signed-off-by: Jonathan Marek Part-of: --- src/freedreno/vulkan/tu_formats.c | 32 +++++++++++++++++++++++-------- src/freedreno/vulkan/tu_image.c | 14 ++++++++++---- src/freedreno/vulkan/vk_format.h | 12 +++++++++++- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index bf76e93b36b..8ecdbdbdc90 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -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 diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index 1808d78a45d..0867c30f0a6 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -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; diff --git a/src/freedreno/vulkan/vk_format.h b/src/freedreno/vulkan/vk_format.h index 7b041b60625..516ba7a2ec4 100644 --- a/src/freedreno/vulkan/vk_format.h +++ b/src/freedreno/vulkan/vk_format.h @@ -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); } -- 2.30.2