From 8f18c72f9abe49cd2f16dfa814bc7215bf5eab2f Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Wed, 12 Jan 2022 18:25:57 +0100 Subject: [PATCH] freedreno/fdl: Fix reinterpreting "size-compatible" formats It's allowed to reinterpret compressed formats as one of a few non-compressed formats with the same pixel size as the blocksize of the compressed format, and vice-versa. If we did this we'd wind up with an incorrect width/height. Fix that. Fixes dEQP-VK.image.sample_texture.*. Part-of: --- src/freedreno/fdl/fd6_view.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/freedreno/fdl/fd6_view.c b/src/freedreno/fdl/fd6_view.c index e950953b375..0f99dd0bb77 100644 --- a/src/freedreno/fdl/fd6_view.c +++ b/src/freedreno/fdl/fd6_view.c @@ -138,6 +138,28 @@ fdl6_view_init(struct fdl6_view *view, const struct fdl_layout **layouts, const struct fdl_layout *layout = layouts[0]; uint32_t width = u_minify(layout->width0, args->base_miplevel); uint32_t height = u_minify(layout->height0, args->base_miplevel); + + /* If reinterpreting a compressed format as a size-compatible uncompressed + * format, we need width/height in blocks, and vice-versa. In vulkan this + * includes single-plane 422 formats which util/format doesn't consider + * "compressed" (get_compressed() returns false). + */ + if (util_format_get_blockwidth(layout->format) > 1 && + util_format_get_blockwidth(args->format) == 1) { + width = util_format_get_nblocksx(layout->format, width); + } else if (util_format_get_blockwidth(layout->format) == 1 && + util_format_get_blockwidth(args->format) > 1) { + width *= util_format_get_blockwidth(args->format); + } + + if (util_format_get_blockheight(layout->format) > 1 && + util_format_get_blockheight(args->format) == 1) { + height = util_format_get_nblocksy(layout->format, height); + } else if (util_format_get_blockheight(layout->format) == 1 && + util_format_get_blockheight(args->format) > 1) { + height *= util_format_get_blockheight(args->format); + } + uint32_t storage_depth = args->layer_count; if (args->type == FDL_VIEW_TYPE_3D) { storage_depth = u_minify(layout->depth0, args->base_miplevel);