[PATCH i-g-t v2 2/6] lib/igt_fb: make blt_compression_format function more readable

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Tue Apr 23 14:32:42 UTC 2024


Intel blitter compression format getter sanitizing.

Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
---
 lib/igt_fb.c | 63 ++++++++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 26 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index f6f280b13..f9868e269 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2824,6 +2824,32 @@ static enum blt_color_depth blt_get_bpp(const struct igt_fb *fb)
 #define BLT_TARGET_MC(x) (x.compression == COMPRESSION_ENABLED && \
 			  x.compression_type == COMPRESSION_TYPE_MEDIA)
 
+const struct {
+	uint32_t key;
+	enum blt_compression_type type;
+	uint32_t return_value;
+} compression_mappings[] = {
+	{ CD_32bit, COMPRESSION_TYPE_3D, 8 },
+	{ DRM_FORMAT_XRGB8888, COMPRESSION_TYPE_MEDIA, 8 },
+	{ DRM_FORMAT_XYUV8888, COMPRESSION_TYPE_MEDIA, 9 },
+	{ DRM_FORMAT_NV12, COMPRESSION_TYPE_MEDIA, 9 },
+	{ DRM_FORMAT_P010, COMPRESSION_TYPE_MEDIA, 8 },
+	{ DRM_FORMAT_P012, COMPRESSION_TYPE_MEDIA, 8 },
+	{ DRM_FORMAT_P016, COMPRESSION_TYPE_MEDIA, 8 },
+};
+
+static uint32_t get_compression_return_value(uint32_t key, enum  blt_compression_type type)
+{
+	for (int i = 0; i < ARRAY_SIZE(compression_mappings); i++) {
+		if (compression_mappings[i].key == key &&
+		    compression_mappings[i].type == type) {
+			return compression_mappings[i].return_value;
+		}
+	}
+	igt_assert_f(0, "Unknown compression type or format\n");
+	return 0; // This line is to avoid compilation warnings, it will not be reached.
+}
+
 static uint32_t blt_compression_format(struct blt_copy_data *blt,
 				       const struct igt_fb *fb)
 {
@@ -2831,33 +2857,18 @@ static uint32_t blt_compression_format(struct blt_copy_data *blt,
 	    blt->dst.compression == COMPRESSION_DISABLED)
 		return 0;
 
-	if (BLT_TARGET_RC(blt->src) || BLT_TARGET_RC(blt->dst)) {
-		switch (blt->color_depth) {
-		case CD_32bit:
-			return 8;
-		default:
-			igt_assert_f(0, "COMPRESSION_TYPE_3D unknown color depth\n");
-		}
-	} else if (BLT_TARGET_MC(blt->src)) {
-		switch (fb->drm_format) {
-		case DRM_FORMAT_XRGB8888:
-			return 8;
-		case DRM_FORMAT_XYUV8888:
-			return 9;
-		case DRM_FORMAT_NV12:
-			return 9;
-		case DRM_FORMAT_P010:
-		case DRM_FORMAT_P012:
-		case DRM_FORMAT_P016:
-			return 8;
-		default:
-			igt_assert_f(0, "COMPRESSION_TYPE_MEDIA unknown format\n");
-		}
-	} else if (BLT_TARGET_MC(blt->dst)) {
+	if (BLT_TARGET_RC(blt->src) || BLT_TARGET_RC(blt->dst))
+		return get_compression_return_value(blt->color_depth,
+						    COMPRESSION_TYPE_3D);
+
+	if (BLT_TARGET_MC(blt->src))
+		return get_compression_return_value(fb->drm_format,
+						    COMPRESSION_TYPE_MEDIA);
+
+	if (BLT_TARGET_MC(blt->dst))
 		igt_assert_f(0, "Destination compression not supported on mc ccs\n");
-	} else {
-		igt_assert_f(0, "unknown compression\n");
-	}
+
+	igt_assert_f(0, "unknown compression\n");
 }
 
 static void blitcopy(const struct igt_fb *dst_fb,
-- 
2.25.1



More information about the igt-dev mailing list