[PATCH i-g-t] lib/igt_fb: Fix intel_buf surface init

Ville Syrjala ville.syrjala at linux.intel.com
Mon Sep 23 21:36:20 UTC 2024


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

The current coed is populating buf->ccs[] and buf->surface[]
in a rather inconsistent way.

It looks like for flat CCS platforms:
- we populate buf->ccs[] with some nonsense even though
  we shouldn't since the AUX stuff is completely hidden by
  the hardware
- we seem to stick data about the clear color into both
  both buf->ccs[] and buf->surfaces[] when it should be in neither

For non-flat CCS platforms the code seems more reasonable,
except it only manages to skip the clear color fumble by
the fact that num_planes is always odd with clear color
and thus the /2 will truncate it away.

Anyways, let's make the code make actual sense for all platforms
by properly calculating how many main surfaces and ccs surfaces
there should be.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_fb.c | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index b8ffd7cfb261..6deb2a221df6 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2636,6 +2636,35 @@ static int yuv_semiplanar_bpp(uint32_t drm_format)
 	}
 }
 
+static int intel_num_surfaces(const struct igt_fb *fb)
+{
+	int num_surfaces;
+
+	if (!igt_fb_is_ccs_modifier(fb->modifier))
+		return fb->num_planes;
+
+	num_surfaces = fb->num_planes;
+
+	if (igt_fb_is_gen12_rc_ccs_cc_modifier(fb->modifier))
+		num_surfaces--;
+
+	if (!HAS_FLATCCS(intel_get_drm_devid(fb->fd)))
+		num_surfaces /= 2;
+
+	return num_surfaces;
+}
+
+static int intel_num_ccs_surfaces(const struct igt_fb *fb)
+{
+	if (!igt_fb_is_ccs_modifier(fb->modifier))
+		return 0;
+
+	if (HAS_FLATCCS(intel_get_drm_devid(fb->fd)))
+		return 0;
+
+	return intel_num_surfaces(fb);
+}
+
 struct intel_buf *
 igt_fb_create_intel_buf(int fd, struct buf_ops *bops,
                         const struct igt_fb *fb,
@@ -2705,13 +2734,12 @@ igt_fb_create_intel_buf(int fd, struct buf_ops *bops,
 	if (buf->format_is_yuv_semiplanar)
 		buf->yuv_semiplanar_bpp = yuv_semiplanar_bpp(fb->drm_format);
 
-	if (igt_fb_is_ccs_modifier(fb->modifier)) {
-		num_surfaces = fb->num_planes / (HAS_FLATCCS(intel_get_drm_devid(fb->fd)) ? 1 : 2);
-		for (i = 0; i < num_surfaces; i++)
-			init_buf_ccs(buf, i,
-				     fb->offsets[num_surfaces + i],
-				     fb->strides[num_surfaces + i]);
-	}
+	num_surfaces = intel_num_surfaces(fb);
+
+	for (i = 0; i < intel_num_ccs_surfaces(fb); i++)
+		init_buf_ccs(buf, i,
+			     fb->offsets[num_surfaces + i],
+			     fb->strides[num_surfaces + i]);
 
 	igt_assert(fb->offsets[0] == 0);
 	for (i = 0; i < num_surfaces; i++) {
-- 
2.44.2



More information about the igt-dev mailing list