public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/2] lib/igt_fb: Add support for Y410/Y416 formats, v2.
Date: Fri,  8 Mar 2019 14:17:23 +0100	[thread overview]
Message-ID: <20190308131723.27785-2-maarten.lankhorst@linux.intel.com> (raw)
In-Reply-To: <20190308131723.27785-1-maarten.lankhorst@linux.intel.com>

Y410 is packed with compressed a channel and only 32 bpp, like
10 bits RGB formats. Y416 is a packed 16 bits per component format.

Changes since v1:
- Rebase on top of upstream YUV changes.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 include/drm-uapi/drm_fourcc.h |   4 +
 lib/igt_color_encoding.c      |   2 +
 lib/igt_fb.c                  | 133 ++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)

diff --git a/include/drm-uapi/drm_fourcc.h b/include/drm-uapi/drm_fourcc.h
index 9fa7cf7bb274..0c08c79476c5 100644
--- a/include/drm-uapi/drm_fourcc.h
+++ b/include/drm-uapi/drm_fourcc.h
@@ -169,6 +169,10 @@ extern "C" {
 #define DRM_FORMAT_Y412         fourcc_code('Y', '4', '1', '2') /* [63:0] X:x:V:x:Y:x:U:x 12:4:12:4:12:4:12:4 little endian */
 #define DRM_FORMAT_Y416         fourcc_code('Y', '4', '1', '6') /* [63:0] X:V:Y:U 16:16:16:16 little endian */
 
+#define DRM_FORMAT_Y410		fourcc_code('Y', '4', '1', '0') /* [31:0] A:V:Y:U 2:10:10:10 little endian */
+#define DRM_FORMAT_Y412		fourcc_code('Y', '4', '1', '2') /* [31:0] A:V:Y:U 2:10:10:10 little endian */
+#define DRM_FORMAT_Y416		fourcc_code('Y', '4', '1', '6') /* [127:0] A:V:Y:U 16:16:16:16 little endian */
+
 /*
  * packed YCbCr420 2x2 tiled formats
  * first 64 bits will contain Y,Cb,Cr components for a 2x2 tile
diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
index 9f9dc1439ee4..0ebdddcd49c5 100644
--- a/lib/igt_color_encoding.c
+++ b/lib/igt_color_encoding.c
@@ -154,6 +154,8 @@ static const struct color_encoding_format {
 	{ DRM_FORMAT_Y210, 65472.f, 4096.f, 60160.f, 4096.f, 32768.f, 61440.f },
 	{ DRM_FORMAT_Y212, 65520.f, 4096.f, 60160.f, 4096.f, 32768.f, 61440.f },
 	{ DRM_FORMAT_Y216, 65535.f, 4096.f, 60160.f, 4096.f, 32768.f, 61440.f },
+	{ DRM_FORMAT_Y410, 1023.f, 64.f, 940.f, 64.f, 512.f, 960.f },
+	{ DRM_FORMAT_Y416, 65535.f, 4096.f, 60160.f, 4096.f, 32768.f, 61440.f },
 };
 
 static const struct color_encoding_format *lookup_fourcc(uint32_t fourcc)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6c222c02a456..b738244c3920 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -221,6 +221,16 @@ static const struct format_desc_struct {
 	  .num_planes = 3, .plane_bpp = { 8, 8, 8, },
 	  .hsub = 2, .vsub = 1,
 	},
+	{ .name = "Y410", .depth = -1, .drm_id = DRM_FORMAT_Y410,
+	  .cairo_id = CAIRO_FORMAT_RGBA128F,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	  .hsub = 1, .vsub = 1,
+	},
+	{ .name = "Y416", .depth = -1, .drm_id = DRM_FORMAT_Y416,
+	  .cairo_id = CAIRO_FORMAT_RGBA128F,
+	  .num_planes = 1, .plane_bpp = { 64, },
+	  .hsub = 1, .vsub = 1,
+	},
 	{ .name = "P010", .depth = -1, .drm_id = DRM_FORMAT_P010,
 	  .cairo_id = CAIRO_FORMAT_RGB96F,
 	  .num_planes = 2, .plane_bpp = { 16, 32 },
@@ -662,6 +672,28 @@ static void clear_yuv_buffer(struct igt_fb *fb)
 			fb->strides[0] * fb->plane_height[0] / sizeof(wchar_t));
 		break;
 
+	case DRM_FORMAT_Y410:
+		wmemset(ptr + fb->offsets[0],
+			full_range ? 0xe0000200 : 0xe0010200,
+		fb->strides[0] * fb->plane_height[0] / sizeof(wchar_t));
+		break;
+	case DRM_FORMAT_Y416: {
+		struct ayuv16 { uint16_t u, y, v, a; };
+		const struct ayuv16 pixel = {
+			.a = 0xffff,
+			.v = full_range ? 0 : 0x1000,
+			.y = 0x8000,
+			.u = full_range ? 0 : 0x1000
+		};
+
+		for (int i = 0; i < fb->plane_height[0]; i++) {
+			struct ayuv16 *cur = ptr + fb->offsets[0] + fb->strides[0] * i;
+
+			for (int j = 0; i < fb->plane_width[0]; j++)
+				*cur++ = pixel;
+		}
+		break;
+		}
 	}
 
 	igt_fb_unmap_buffer(fb, ptr);
@@ -1808,6 +1840,7 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
 		params->uv_inc = 4;
 		break;
 
+	case DRM_FORMAT_Y416:
 	case DRM_FORMAT_XYUV8888:
 		params->y_inc = 4;
 		params->uv_inc = 4;
@@ -1838,6 +1871,7 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
 	case DRM_FORMAT_Y212:
 	case DRM_FORMAT_Y216:
 	case DRM_FORMAT_XYUV8888:
+	case DRM_FORMAT_Y416:
 		params->y_stride = fb->strides[0];
 		params->uv_stride = fb->strides[0];
 		break;
@@ -1912,6 +1946,12 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
 		params->v_offset = fb->offsets[0] + 6;
 		break;
 
+	case DRM_FORMAT_Y416:
+		params->y_offset = fb->offsets[0] + 2;
+		params->u_offset = fb->offsets[0];
+		params->v_offset = fb->offsets[0] + 4;
+		break;
+
 	case DRM_FORMAT_XYUV8888:
 		params->y_offset = fb->offsets[0] + 1;
 		params->u_offset = fb->offsets[0] + 2;
@@ -2140,6 +2180,7 @@ static void convert_yuv16_to_float(struct fb_convert *cvt)
 		}
 
 		ptr += float_stride;
+
 		y += params.y_stride / sizeof(*y);
 
 		if ((src_fmt->vsub == 1) || (i % src_fmt->vsub)) {
@@ -2241,6 +2282,88 @@ static void convert_float_to_yuv16(struct fb_convert *cvt)
 	}
 }
 
+static void convert_Y410_to_float(struct fb_convert *cvt)
+{
+	int i, j;
+	const uint32_t *yuyv;
+	uint32_t *buf;
+	float *ptr = cvt->dst.ptr;
+	unsigned int float_stride = cvt->dst.fb->strides[0] / sizeof(*ptr);
+	unsigned int yuyv_stride = cvt->src.fb->strides[0] / sizeof(*yuyv);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(cvt->src.fb->drm_format,
+						    cvt->dst.fb->drm_format,
+						    cvt->src.fb->color_encoding,
+						    cvt->src.fb->color_range);
+
+	igt_assert(cvt->src.fb->drm_format == DRM_FORMAT_Y410 &&
+		   cvt->dst.fb->drm_format == IGT_FORMAT_FLOAT);
+
+	yuyv = buf = convert_src_get(cvt);
+
+	for (i = 0; i < cvt->dst.fb->height; i++) {
+		for (j = 0; j < cvt->dst.fb->width; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 yuv;
+			struct igt_vec4 rgb;
+
+			yuv.d[0] = yuyv[j] & 0x3ff;
+			yuv.d[1] = (yuyv[j] >> 10) & 0x3ff;
+			yuv.d[2] = (yuyv[j] >> 20) & 0x3ff;
+			yuv.d[3] = 1.f;
+
+			rgb = igt_matrix_transform(&m, &yuv);
+
+			write_rgbf(&ptr[j * 4 + 0], &rgb);
+			ptr[j * 4 + 3] = (float)(yuyv[j] >> 30) / 3;
+		}
+
+		ptr += float_stride;
+		yuyv += yuyv_stride;
+	}
+
+	convert_src_put(cvt, buf);
+}
+
+static void convert_float_to_Y410(struct fb_convert *cvt)
+{
+	int i, j;
+	uint32_t *yuyv = cvt->dst.ptr;
+	const float *ptr = cvt->src.ptr;
+	unsigned float_stride = cvt->src.fb->strides[0] / sizeof(*ptr);
+	unsigned yuyv_stride = cvt->dst.fb->strides[0] / sizeof(*yuyv);
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(cvt->src.fb->drm_format,
+						    cvt->dst.fb->drm_format,
+						    cvt->dst.fb->color_encoding,
+						    cvt->dst.fb->color_range);
+
+	igt_assert(cvt->src.fb->drm_format == IGT_FORMAT_FLOAT &&
+		   cvt->dst.fb->drm_format == DRM_FORMAT_Y410);
+
+	for (i = 0; i < cvt->dst.fb->height; i++) {
+		for (j = 0; j < cvt->dst.fb->width; j++) {
+			struct igt_vec4 rgb;
+			struct igt_vec4 yuv;
+			uint8_t alpha = ptr[j * 4 + 3] * 3.f + .5f;
+			uint16_t y, cb, cr;
+
+			read_rgbf(&rgb, &ptr[j * 4 + 0]);
+
+			yuv = igt_matrix_transform(&m, &rgb);
+			cr = yuv.d[0];
+			y = yuv.d[1];
+			cb = yuv.d[2];
+
+			yuyv[j] = ((cr & 0x3ff) << 0) |
+				  ((y & 0x3ff) << 10) |
+				  ((cb & 0x3ff) << 20) |
+				  (alpha << 30);
+		}
+
+		ptr += float_stride;
+		yuyv += yuyv_stride;
+	}
+}
+
 static void convert_pixman(struct fb_convert *cvt)
 {
 	pixman_format_code_t src_pixman = drm_format_to_pixman(cvt->src.fb->drm_format);
@@ -2330,8 +2453,12 @@ static void fb_convert(struct fb_convert *cvt)
 		case DRM_FORMAT_Y210:
 		case DRM_FORMAT_Y212:
 		case DRM_FORMAT_Y216:
+		case DRM_FORMAT_Y416:
 			convert_yuv16_to_float(cvt);
 			return;
+		case DRM_FORMAT_Y410:
+			convert_Y410_to_float(cvt);
+			return;
 		}
 	} else if (cvt->src.fb->drm_format == IGT_FORMAT_FLOAT) {
 		switch (cvt->dst.fb->drm_format) {
@@ -2341,8 +2468,12 @@ static void fb_convert(struct fb_convert *cvt)
 		case DRM_FORMAT_Y210:
 		case DRM_FORMAT_Y212:
 		case DRM_FORMAT_Y216:
+		case DRM_FORMAT_Y416:
 			convert_float_to_yuv16(cvt);
 			return;
+		case DRM_FORMAT_Y410:
+			convert_float_to_Y410(cvt);
+			return;
 		}
 	}
 
@@ -2798,6 +2929,8 @@ bool igt_format_is_yuv(uint32_t drm_format)
 	case DRM_FORMAT_Y210:
 	case DRM_FORMAT_Y212:
 	case DRM_FORMAT_Y216:
+	case DRM_FORMAT_Y410:
+	case DRM_FORMAT_Y416:
 	case DRM_FORMAT_YUYV:
 	case DRM_FORMAT_YVYU:
 	case DRM_FORMAT_UYVY:
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-03-08 13:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 13:17 [igt-dev] [PATCH i-g-t 1/2] lib/igt_fb: Add support for Y21x formats as well, v2 Maarten Lankhorst
2019-03-08 13:17 ` Maarten Lankhorst [this message]
2019-03-08 17:23 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] " Patchwork
2019-03-08 21:25 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308131723.27785-2-maarten.lankhorst@linux.intel.com \
    --to=maarten.lankhorst@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox