[igt-dev] [PATCH v2 4/4] lib/igt_fb: Add support for Y410/Y416 formats, v2.

Juha-Pekka Heikkila juhapekka.heikkila at gmail.com
Thu Feb 7 12:43:38 UTC 2019


This look good to me.

Reviewed-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>

On 7.2.2019 11.21, Maarten Lankhorst wrote:
> 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 at linux.intel.com>
> ---
>   include/drm-uapi/drm_fourcc.h |   3 +
>   lib/igt_color_encoding.c      |   2 +
>   lib/igt_fb.c                  | 204 ++++++++++++++++++++++++++++++----
>   3 files changed, 185 insertions(+), 24 deletions(-)
> 
> diff --git a/include/drm-uapi/drm_fourcc.h b/include/drm-uapi/drm_fourcc.h
> index ff9ea02766ee..62b4ba023a4d 100644
> --- a/include/drm-uapi/drm_fourcc.h
> +++ b/include/drm-uapi/drm_fourcc.h
> @@ -157,6 +157,9 @@ extern "C" {
>   #define DRM_FORMAT_Y212		fourcc_code('Y', '2', '1', '2')
>   #define DRM_FORMAT_Y216		fourcc_code('Y', '2', '1', '6')
>   
> +#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_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 6f82fcec62e4..bc9575fca1b4 100644
> --- a/lib/igt_color_encoding.c
> +++ b/lib/igt_color_encoding.c
> @@ -147,6 +147,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 cccd6bb98395..b8c82b985fd3 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -199,6 +199,16 @@ static const struct format_desc_struct {
>   	  .num_planes = 1, .plane_bpp = { 32, },
>   	  .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 },
> @@ -584,6 +594,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);
> @@ -1649,10 +1681,11 @@ static void convert_src_put(const struct fb_convert *cvt,
>   }
>   
>   struct yuv_parameters {
> -	unsigned	y_inc;
> +	unsigned	ay_inc;
>   	unsigned	uv_inc;
> -	unsigned	y_stride;
> +	unsigned	ay_stride;
>   	unsigned	uv_stride;
> +	unsigned	a_offset;
>   	unsigned	y_offset;
>   	unsigned	u_offset;
>   	unsigned	v_offset;
> @@ -1667,7 +1700,7 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
>   	case DRM_FORMAT_P010:
>   	case DRM_FORMAT_P012:
>   	case DRM_FORMAT_P016:
> -		params->y_inc = 1;
> +		params->ay_inc = 1;
>   		params->uv_inc = 2;
>   		break;
>   
> @@ -1678,12 +1711,13 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
>   	case DRM_FORMAT_Y210:
>   	case DRM_FORMAT_Y212:
>   	case DRM_FORMAT_Y216:
> -		params->y_inc = 2;
> +		params->ay_inc = 2;
>   		params->uv_inc = 4;
>   		break;
>   
> +	case DRM_FORMAT_Y416:
>   	case DRM_FORMAT_XYUV8888:
> -		params->y_inc = 4;
> +		params->ay_inc = 4;
>   		params->uv_inc = 4;
>   		break;
>   	}
> @@ -1693,7 +1727,7 @@ static void get_yuv_parameters(struct igt_fb *fb, struct yuv_parameters *params)
>   	case DRM_FORMAT_P010:
>   	case DRM_FORMAT_P012:
>   	case DRM_FORMAT_P016:
> -		params->y_stride = fb->strides[0];
> +		params->ay_stride = fb->strides[0];
>   		params->uv_stride = fb->strides[1];
>   		break;
>   
> @@ -1705,7 +1739,8 @@ 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:
> -		params->y_stride = fb->strides[0];
> +	case DRM_FORMAT_Y416:
> +		params->ay_stride = fb->strides[0];
>   		params->uv_stride = fb->strides[0];
>   		break;
>   	}
> @@ -1757,6 +1792,13 @@ 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->a_offset = fb->offsets[0] + 6;
> +		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;
> @@ -1808,7 +1850,7 @@ static void convert_yuv_to_rgb24(struct fb_convert *cvt)
>   			write_rgb(rgb_tmp, &rgb);
>   
>   			rgb_tmp += bpp;
> -			y_tmp += params.y_inc;
> +			y_tmp += params.ay_inc;
>   
>   			if ((src_fmt->hsub == 1) || (j % src_fmt->hsub)) {
>   				u_tmp += params.uv_inc;
> @@ -1817,7 +1859,7 @@ static void convert_yuv_to_rgb24(struct fb_convert *cvt)
>   		}
>   
>   		rgb24 += rgb24_stride;
> -		y += params.y_stride;
> +		y += params.ay_stride;
>   
>   		if ((src_fmt->vsub == 1) || (i % src_fmt->vsub)) {
>   			u += params.uv_stride;
> @@ -1868,7 +1910,7 @@ static void convert_rgb24_to_yuv(struct fb_convert *cvt)
>   			rgb_tmp += bpp;
>   
>   			*y_tmp = yuv.d[0];
> -			y_tmp += params.y_inc;
> +			y_tmp += params.ay_inc;
>   
>   			if ((i % dst_fmt->vsub) || (j % dst_fmt->hsub))
>   				continue;
> @@ -1905,7 +1947,7 @@ static void convert_rgb24_to_yuv(struct fb_convert *cvt)
>   		}
>   
>   		rgb24 += rgb24_stride;
> -		y += params.y_stride;
> +		y += params.ay_stride;
>   
>   		if ((i % dst_fmt->vsub) == (dst_fmt->vsub - 1)) {
>   			u += params.uv_stride;
> @@ -1929,13 +1971,13 @@ static void write_rgbf(float *rgb24, const struct igt_vec4 *rgb)
>   	rgb24[2] = rgb->d[2];
>   }
>   
> -static void convert_yuv16_to_float(struct fb_convert *cvt)
> +static void convert_yuv16_to_float(struct fb_convert *cvt, bool alpha)
>   {
>   	const struct format_desc_struct *src_fmt =
>   		lookup_drm_format(cvt->src.fb->drm_format);
>   	int i, j;
> -	uint8_t fpp = 3;
> -	uint16_t *y, *u, *v;
> +	uint8_t fpp = alpha ? 4 : 3;
> +	uint16_t *a, *y, *u, *v;
>   	float *ptr = cvt->dst.ptr;
>   	unsigned int float_stride = cvt->dst.fb->strides[0] / sizeof(*ptr);
>   	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(cvt->src.fb->drm_format,
> @@ -1954,11 +1996,13 @@ static void convert_yuv16_to_float(struct fb_convert *cvt)
>   		   !(params.u_offset % sizeof(*buf)) &&
>   		   !(params.v_offset % sizeof(*buf)));
>   
> +	a = buf + params.a_offset / sizeof(*buf);
>   	y = buf + params.y_offset / sizeof(*buf);
>   	u = buf + params.u_offset / sizeof(*buf);
>   	v = buf + params.v_offset / sizeof(*buf);
>   
>   	for (i = 0; i < cvt->dst.fb->height; i++) {
> +		const uint16_t *a_tmp = a;
>   		const uint16_t *y_tmp = y;
>   		const uint16_t *u_tmp = u;
>   		const uint16_t *v_tmp = v;
> @@ -1975,8 +2019,13 @@ static void convert_yuv16_to_float(struct fb_convert *cvt)
>   			rgb = igt_matrix_transform(&m, &yuv);
>   			write_rgbf(rgb_tmp, &rgb);
>   
> +			if (alpha) {
> +				rgb_tmp[3] = ((float)*a_tmp) / 65535.f;
> +				a_tmp += params.ay_inc;
> +			}
> +
>   			rgb_tmp += fpp;
> -			y_tmp += params.y_inc;
> +			y_tmp += params.ay_inc;
>   
>   			if ((src_fmt->hsub == 1) || (j % src_fmt->hsub)) {
>   				u_tmp += params.uv_inc;
> @@ -1985,7 +2034,9 @@ static void convert_yuv16_to_float(struct fb_convert *cvt)
>   		}
>   
>   		ptr += float_stride;
> -		y += params.y_stride / sizeof(*y);
> +
> +		a += params.ay_stride / sizeof(*a);
> +		y += params.ay_stride / sizeof(*y);
>   
>   		if ((src_fmt->vsub == 1) || (i % src_fmt->vsub)) {
>   			u += params.uv_stride / sizeof(*u);
> @@ -1996,14 +2047,14 @@ static void convert_yuv16_to_float(struct fb_convert *cvt)
>   	convert_src_put(cvt, buf);
>   }
>   
> -static void convert_float_to_yuv16(struct fb_convert *cvt)
> +static void convert_float_to_yuv16(struct fb_convert *cvt, bool alpha)
>   {
>   	const struct format_desc_struct *dst_fmt =
>   		lookup_drm_format(cvt->dst.fb->drm_format);
>   	int i, j;
> -	uint16_t *y, *u, *v;
> +	uint16_t *a, *y, *u, *v;
>   	const float *ptr = cvt->src.ptr;
> -	uint8_t fpp = 3;
> +	uint8_t fpp = alpha ? 4 : 3;
>   	unsigned float_stride = cvt->src.fb->strides[0] / sizeof(*ptr);
>   	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(cvt->src.fb->drm_format,
>   						    cvt->dst.fb->drm_format,
> @@ -2015,16 +2066,19 @@ static void convert_float_to_yuv16(struct fb_convert *cvt)
>   		   igt_format_is_yuv(cvt->dst.fb->drm_format));
>   
>   	get_yuv_parameters(cvt->dst.fb, &params);
> -	igt_assert(!(params.y_offset % sizeof(*y)) &&
> +	igt_assert(!(params.a_offset % sizeof(*a)) &&
> +		   !(params.y_offset % sizeof(*y)) &&
>   		   !(params.u_offset % sizeof(*u)) &&
>   		   !(params.v_offset % sizeof(*v)));
>   
> +	a = cvt->dst.ptr + params.a_offset;
>   	y = cvt->dst.ptr + params.y_offset;
>   	u = cvt->dst.ptr + params.u_offset;
>   	v = cvt->dst.ptr + params.v_offset;
>   
>   	for (i = 0; i < cvt->dst.fb->height; i++) {
>   		const float *rgb_tmp = ptr;
> +		uint16_t *a_tmp = a;
>   		uint16_t *y_tmp = y;
>   		uint16_t *u_tmp = u;
>   		uint16_t *v_tmp = v;
> @@ -2037,10 +2091,15 @@ static void convert_float_to_yuv16(struct fb_convert *cvt)
>   			read_rgbf(&rgb, rgb_tmp);
>   			yuv = igt_matrix_transform(&m, &rgb);
>   
> +			if (alpha) {
> +				*a_tmp = rgb_tmp[3] * 65535.f + .5f;
> +				a_tmp += params.ay_inc;
> +			}
> +
>   			rgb_tmp += fpp;
>   
>   			*y_tmp = yuv.d[0];
> -			y_tmp += params.y_inc;
> +			y_tmp += params.ay_inc;
>   
>   			if ((i % dst_fmt->vsub) || (j % dst_fmt->hsub))
>   				continue;
> @@ -2077,7 +2136,8 @@ static void convert_float_to_yuv16(struct fb_convert *cvt)
>   		}
>   
>   		ptr += float_stride;
> -		y += params.y_stride / sizeof(*y);
> +		a += params.ay_stride / sizeof(*a);
> +		y += params.ay_stride / sizeof(*y);
>   
>   		if ((i % dst_fmt->vsub) == (dst_fmt->vsub - 1)) {
>   			u += params.uv_stride / sizeof(*u);
> @@ -2086,6 +2146,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);
> @@ -2161,7 +2303,13 @@ static void fb_convert(struct fb_convert *cvt)
>   		case DRM_FORMAT_Y210:
>   		case DRM_FORMAT_Y212:
>   		case DRM_FORMAT_Y216:
> -			convert_yuv16_to_float(cvt);
> +			convert_yuv16_to_float(cvt, false);
> +			return;
> +		case DRM_FORMAT_Y410:
> +			convert_Y410_to_float(cvt);
> +			return;
> +		case DRM_FORMAT_Y416:
> +			convert_yuv16_to_float(cvt, true);
>   			return;
>   		}
>   	} else if (cvt->src.fb->drm_format == IGT_FORMAT_FLOAT) {
> @@ -2172,7 +2320,13 @@ static void fb_convert(struct fb_convert *cvt)
>   		case DRM_FORMAT_Y210:
>   		case DRM_FORMAT_Y212:
>   		case DRM_FORMAT_Y216:
> -			convert_float_to_yuv16(cvt);
> +			convert_float_to_yuv16(cvt, false);
> +			return;
> +		case DRM_FORMAT_Y410:
> +			convert_float_to_Y410(cvt);
> +			return;
> +		case DRM_FORMAT_Y416:
> +			convert_float_to_yuv16(cvt, true);
>   			return;
>   		}
>   	}
> @@ -2564,6 +2718,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:
> 



More information about the igt-dev mailing list