From 213e895da06bfd4522a6cb4b3a55a070a1792f67 Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Tue, 28 May 2024 09:09:43 +0200 Subject: [PATCH] panvk: Allow compressed formats Compressed formats were disabled because of the different layout for u_interleaved(compressed), where the 16x16 texel tile model for non-compressed is replaced by a 4x4 block tile. This prevents us from creating RGBA views of compressed images, which break copies. The simple option is to keep compressed images linear. The more complex one would be to patch coordinates/frag-coords on the shader side when we're dealing with a compressed texture/color-attachment, but given we're using vk_meta for copies, it's not something we can easily do, so let's go for the first option and see if we want to revisit it later. Signed-off-by: Boris Brezillon Reviewed-by: Mary Guillemard Part-of: --- src/panfrost/vulkan/panvk_physical_device.c | 37 ++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/panfrost/vulkan/panvk_physical_device.c b/src/panfrost/vulkan/panvk_physical_device.c index a50c98d90c7..c2a1cff9219 100644 --- a/src/panfrost/vulkan/panvk_physical_device.c +++ b/src/panfrost/vulkan/panvk_physical_device.c @@ -919,28 +919,49 @@ panvk_DestroyDevice(VkDevice _device, const VkAllocationCallbacks *pAllocator) panvk_arch_dispatch(arch, destroy_device, device, pAllocator); } +static bool +format_is_supported(struct panvk_physical_device *physical_device, + const struct panfrost_format fmt) +{ + /* If the format ID is zero, it's not supported. */ + if (!fmt.hw) + return false; + + /* Compressed formats (ID < 32) are optional. We need to check against + * the supported formats reported by the GPU. */ + unsigned idx = MALI_EXTRACT_INDEX(fmt.hw); + if (MALI_EXTRACT_TYPE(idx) == MALI_FORMAT_COMPRESSED) { + uint32_t supported_compr_fmts = + panfrost_query_compressed_formats(&physical_device->kmod.props); + + assert(idx < 32); + + if (!(BITFIELD_BIT(idx) & supported_compr_fmts)) + return false; + } + + return true; +} + static void get_format_properties(struct panvk_physical_device *physical_device, VkFormat format, VkFormatProperties *out_properties) { VkFormatFeatureFlags tex = 0, buffer = 0; enum pipe_format pfmt = vk_format_to_pipe_format(format); + + if (pfmt == PIPE_FORMAT_NONE) + goto end; + const struct panfrost_format fmt = physical_device->formats.all[pfmt]; - if (!pfmt || !fmt.hw) + if (!format_is_supported(physical_device, fmt)) goto end; /* 3byte formats are not supported by the buffer <-> image copy helpers. */ if (util_format_get_blocksize(pfmt) == 3) goto end; - /* We don't support compressed formats yet: this is causing trouble when - * doing a vkCmdCopyImage() between a compressed and a non-compressed format - * on a tiled/AFBC resource. - */ - if (util_format_is_compressed(pfmt)) - goto end; - buffer |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;