All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
@ 2018-05-17 19:51 Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 02/10] lib: Clear packed YUV formats to black Ville Syrjala
                   ` (13 more replies)
  0 siblings, 14 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_aux.h |  7 +++++++
 lib/igt_fb.c  | 11 ++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 9bb03b77ed46..0eb96e442a7e 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -228,6 +228,13 @@ void intel_require_files(uint64_t count);
 	_a > _b ? _a : _b;		\
 })
 
+#define clamp(x, min, max) ({		\
+	typeof(min) _min = (min);	\
+	typeof(max) _max = (max);	\
+	typeof(x) _x = (x);		\
+	_x < _min ? _min : _x > _max ? _max : _x;	\
+})
+
 #define igt_swap(a, b) do {	\
 	typeof(a) _tmp = (a);	\
 	(a) = (b);		\
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 34b1a261b95c..ac3792f4c0db 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -30,6 +30,7 @@
 #include <inttypes.h>
 
 #include "drmtest.h"
+#include "igt_aux.h"
 #include "igt_fb.h"
 #include "igt_kms.h"
 #include "igt_x86.h"
@@ -1320,13 +1321,9 @@ struct fb_convert_blit_upload {
 	struct fb_blit_linear linear;
 };
 
-static uint8_t clamprgb(float val) {
-	if (val < 0)
-		return 0;
-	if (val > 255)
-		return 255;
-
-	return (uint8_t)val;
+static uint8_t clamprgb(float val)
+{
+	return clamp(val, 0.0f, 255.0f);
 }
 
 static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 02/10] lib: Clear packed YUV formats to black
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 03/10] lib: Don't use dumb buffers for YCbCr Ville Syrjala
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

As we do for NV12, let's also clear packed YUV formats to black instead
of zero. Avoids unexpected green screens.

v2: Nuke the debug messages

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index ac3792f4c0db..9596caee16a2 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -335,6 +335,16 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling)
 	}
 }
 
+static void *memset32(void *s, uint32_t c, size_t n)
+{
+	uint32_t *ptr = s;
+
+	for (int i = 0; i < n; i++)
+		*ptr++ = c;
+
+	return s;
+}
+
 /* helpers to create nice-looking framebuffers */
 static int create_bo_for_fb(int fd, int width, int height,
 			    struct format_desc_struct *format,
@@ -369,6 +379,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 
 		if (is_i915_device(fd)) {
 			uint8_t *ptr;
+			bool full_range = false; /* FIXME */
 
 			bo = gem_create(fd, size);
 			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
@@ -377,10 +388,23 @@ static int create_bo_for_fb(int fd, int width, int height,
 			ptr = gem_mmap__gtt(fd, bo, size, PROT_READ | PROT_WRITE);
 			igt_assert(*(uint32_t *)ptr == 0);
 
-			if (format->drm_id == DRM_FORMAT_NV12) {
-				/* component formats have a different zero point */
-				memset(ptr, 16, offsets[1]);
-				memset(ptr + offsets[1], 0x80, (height + 1)/2 * stride);
+			switch (format->drm_id) {
+			case DRM_FORMAT_NV12:
+				memset(ptr + offsets[0], full_range ? 0x00 : 0x10,
+				       calculated_stride * height);
+				memset(ptr + offsets[1], 0x80,
+				       calculated_stride * height/2);
+				break;
+			case DRM_FORMAT_YUYV:
+			case DRM_FORMAT_YVYU:
+				memset32(ptr, full_range ? 0x80008000 : 0x80108010,
+					 calculated_stride * height / 4);
+				break;
+			case DRM_FORMAT_UYVY:
+			case DRM_FORMAT_VYUY:
+				memset32(ptr, full_range ? 0x00800080 : 0x10801080,
+					 calculated_stride * height / 4);
+				break;
 			}
 			gem_munmap(ptr, size);
 
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 03/10] lib: Don't use dumb buffers for YCbCr
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 02/10] lib: Clear packed YUV formats to black Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc Ville Syrjala
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

We don't do the "black != zero" clearing for dumb buffers, so let's not
use them for YCbCr framebuffers.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 9596caee16a2..5cf2cd7d9e90 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -345,6 +345,20 @@ static void *memset32(void *s, uint32_t c, size_t n)
 	return s;
 }
 
+static bool is_yuv(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		return true;
+	default:
+		return false;
+	}
+}
+
 /* helpers to create nice-looking framebuffers */
 static int create_bo_for_fb(int fd, int width, int height,
 			    struct format_desc_struct *format,
@@ -359,7 +373,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 	if (offsets)
 		memset(offsets, 0, ARRAY_SIZE(format->plane_bpp) * sizeof(*offsets));
 
-	if (tiling || size || stride || format->planes > 1) {
+	if (tiling || size || stride || is_yuv(format->drm_id)) {
 		unsigned calculated_size, calculated_stride;
 
 		if (format->planes > 1)
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 02/10] lib: Clear packed YUV formats to black Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 03/10] lib: Don't use dumb buffers for YCbCr Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 20:13   ` Chris Wilson
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix Ville Syrjala
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Always populate the plane_bpp[] stuff, and use named initializers so
that we can actually see what's being set to what.

v2: Fix depth for xrgb8888

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 66 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 5cf2cd7d9e90..af8ba70b0a2a 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -57,26 +57,35 @@
  */
 
 /* drm fourcc/cairo format maps */
-#define DF(did, cid, ...)	\
-	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
 static struct format_desc_struct {
+	const char *name;
 	uint32_t drm_id;
 	cairo_format_t cairo_id;
-	const char *name;
-	int bpp;
 	int depth;
-	int planes;
+	int num_planes;
 	int plane_bpp[4];
 } format_desc[] = {
-	DF(RGB565,	RGB16_565,	16, 16),
-	//DF(RGB888,	INVALID,	24, 24),
-	DF(XRGB8888,	RGB24,		32, 24),
-	DF(XRGB2101010,	RGB30,		32, 30),
-	DF(ARGB8888,	ARGB32,		32, 32),
-	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
+	{ .name = "RGB565", .depth = 16, .drm_id = DRM_FORMAT_RGB565,
+	  .cairo_id = CAIRO_FORMAT_RGB16_565,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "XRGB8888", .depth = 24, .drm_id = DRM_FORMAT_XRGB8888,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "XRGB2101010", .depth = 30, .drm_id = DRM_FORMAT_XRGB2101010,
+	  .cairo_id = CAIRO_FORMAT_RGB30,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "ARGB8888", .depth = 32, .drm_id = DRM_FORMAT_ARGB8888,
+	  .cairo_id = CAIRO_FORMAT_ARGB32,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "NV12", .depth = -1, .drm_id = DRM_FORMAT_NV12,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 2, .plane_bpp = { 8, 16, },
+	},
 };
-#undef DF
-
 #define for_each_format(f)	\
 	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
 
@@ -195,7 +204,7 @@ static void calc_fb_size_planar(int fd, int width, int height,
 
 	*size_ret = 0;
 
-	for (plane = 0; plane < format->planes; plane++) {
+	for (plane = 0; plane < format->num_planes; plane++) {
 		unsigned plane_stride;
 
 		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
@@ -205,7 +214,7 @@ static void calc_fb_size_planar(int fd, int width, int height,
 			stride = plane_stride;
 	}
 
-	for (plane = 0; plane < format->planes; plane++) {
+	for (plane = 0; plane < format->num_planes; plane++) {
 		if (offsets)
 			offsets[plane] = *size_ret;
 
@@ -226,9 +235,9 @@ static void calc_fb_size_packed(int fd, int width, int height,
 				unsigned *size_ret, unsigned *stride_ret)
 {
 	unsigned int tile_width, tile_height, stride, size;
-	int byte_width = width * (format->bpp / 8);
+	int byte_width = width * (format->plane_bpp[0] / 8);
 
-	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width, &tile_height);
+	igt_get_fb_tile_size(fd, tiling, format->plane_bpp[0], &tile_width, &tile_height);
 
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
@@ -277,7 +286,7 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t drm_format, uint64
 	struct format_desc_struct *format = lookup_drm_format(drm_format);
 	igt_assert(format);
 
-	if (format->planes > 1)
+	if (format->num_planes > 1)
 		calc_fb_size_planar(fd, width, height, format, tiling, size_ret, stride_ret, NULL);
 	else
 		calc_fb_size_packed(fd, width, height, format, tiling, size_ret, stride_ret);
@@ -376,7 +385,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 	if (tiling || size || stride || is_yuv(format->drm_id)) {
 		unsigned calculated_size, calculated_stride;
 
-		if (format->planes > 1)
+		if (format->num_planes > 1)
 			calc_fb_size_planar(fd, width, height, format, tiling,
 					    &calculated_size, &calculated_stride, offsets);
 		else
@@ -439,8 +448,9 @@ static int create_bo_for_fb(int fd, int width, int height,
 		if (is_dumb)
 			*is_dumb = true;
 
-		return kmstest_dumb_create(fd, width, height, format->bpp, stride_ret,
-					   size_ret);
+		return kmstest_dumb_create(fd, width, height,
+					   format->plane_bpp[0],
+					   stride_ret, size_ret);
 	}
 }
 
@@ -842,7 +852,7 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 
 		handles[0] = fb->gem_handle;
 		pitches[0] = fb->stride;
-		for (i = 0; i < f->planes; i++) {
+		for (i = 0; i < f->num_planes; i++) {
 			handles[i] = fb->gem_handle;
 			pitches[i] = fb->stride;
 		}
@@ -858,13 +868,9 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	fb->drm_format = format;
 	fb->fb_id = fb_id;
 	fb->fd = fd;
-	fb->num_planes = f->planes ?: 1;
-	fb->plane_bpp[0] = f->bpp;
-	fb->plane_height[0] = height;
-	fb->plane_width[0] = width;
+	fb->num_planes = f->num_planes;
 
-	/* if f->planes is set, then plane_bpp is valid too so use that. */
-	for (i = 0; i < f->planes; i++) {
+	for (i = 0; i < f->num_planes; i++) {
 		fb->plane_bpp[i] = f->plane_bpp[i];
 		fb->plane_height[i] = planar_height(f, height, i);
 		fb->plane_width[i] = planar_width(f, width, i);
@@ -1683,7 +1689,7 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth)
 	struct format_desc_struct *f;
 
 	for_each_format(f)
-		if (f->bpp == bpp && f->depth == depth)
+		if (f->plane_bpp[0] == bpp && f->depth == depth)
 			return f->drm_id;
 
 
@@ -1706,7 +1712,7 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
 	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
 		     drm_format, igt_format_str(drm_format));
 
-	return f->bpp;
+	return f->plane_bpp[0];
 }
 
 /**
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (2 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 20:16   ` Chris Wilson
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding Ville Syrjala
                   ` (9 subsequent siblings)
  13 siblings, 1 reply; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Add a helper library for basic matrix math.

v2: Make the identity matrix static const (Chris)
    Add the m(row,col) macro (Chris)

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/Makefile.sources |   2 +
 lib/igt_matrix.c     | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_matrix.h     |  56 ++++++++++++++++++
 lib/meson.build      |   1 +
 4 files changed, 217 insertions(+)
 create mode 100644 lib/igt_matrix.c
 create mode 100644 lib/igt_matrix.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index c0c332061b6d..5453340a65e0 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -26,6 +26,8 @@ lib_source_list =	 	\
 	igt_gt.h		\
 	igt_gvt.c		\
 	igt_gvt.h		\
+	igt_matrix.c		\
+	igt_matrix.h		\
 	igt_primes.c		\
 	igt_primes.h		\
 	igt_rand.c		\
diff --git a/lib/igt_matrix.c b/lib/igt_matrix.c
new file mode 100644
index 000000000000..3fa6c96cae8a
--- /dev/null
+++ b/lib/igt_matrix.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt_core.h"
+#include "igt_matrix.h"
+
+#define m(row, col) ((col) * 4 + (row))
+
+/**
+ * SECTION:igt_matrix
+ * @short_description: Matrix math library
+ * @title: Matrix
+ * @include: igt.h
+ *
+ * This library contains helper functions for basic matrix math.
+ * The library operates on #igt_mat4 and #igt_vec4 structures.
+ */
+
+/**
+ * igt_matrix_print:
+ * @m: the matrix
+ *
+ * Print out the matrix elements.
+ */
+void igt_matrix_print(const struct igt_mat4 *m)
+{
+	for (int row = 0; row < 4; row++) {
+		igt_info("|");
+		for (int col = 0; col < 4; col++) {
+			igt_info("%4.4f,", m->d[m(row, col)]);
+		}
+		igt_info("|\n");
+	}
+}
+
+/**
+ * igt_matrix_identity:
+ *
+ * Returns:
+ * An identity matrix.
+ */
+struct igt_mat4 igt_matrix_identity(void)
+{
+	static const struct igt_mat4 ret = {
+		.d[m(0, 0)] = 1.0f,
+		.d[m(1, 1)] = 1.0f,
+		.d[m(2, 2)] = 1.0f,
+		.d[m(3, 3)] = 1.0f,
+	};
+
+	return ret;
+}
+
+/**
+ * igt_matrix_scale:
+ *
+ * Returns:
+ * An scaling matrix.
+ */
+struct igt_mat4 igt_matrix_scale(float x, float y, float z)
+{
+	struct igt_mat4 ret = {
+		.d[m(0, 0)] = x,
+		.d[m(1, 1)] = y,
+		.d[m(2, 2)] = z,
+		.d[m(3, 3)] = 1.0f,
+	};
+
+	return ret;
+}
+
+/**
+ * igt_matrix_translate:
+ *
+ * Returns:
+ * A translation matrix.
+ */
+struct igt_mat4 igt_matrix_translate(float x, float y, float z)
+{
+	struct igt_mat4 ret = {
+		.d[m(0, 0)] = 1.0f,
+		.d[m(1, 1)] = 1.0f,
+		.d[m(2, 2)] = 1.0f,
+		.d[m(0, 3)] = x,
+		.d[m(1, 3)] = y,
+		.d[m(2, 3)] = z,
+		.d[m(3, 3)] = 1.0f,
+	};
+
+	return ret;
+}
+
+/**
+ * igt_matrix_transform:
+ *
+ * Transform the vector @v by the matrix @m. @m is on the left,
+ * @v on the right.
+ *
+ * Returns:
+ * The transformed vector.
+ */
+struct igt_vec4 igt_matrix_transform(const struct igt_mat4 *m,
+				     const struct igt_vec4 *v)
+{
+	struct igt_vec4 ret = {};
+
+	for (int row = 0; row < 4; row++) {
+		for (int i = 0; i < 4; i++) {
+			ret.d[row] += m->d[m(row, i)] * v->d[i];
+		}
+	}
+
+	return ret;
+}
+
+/**
+ * igt_matrix_multiply:
+ *
+ * Multiply two matrices together. @a is on the left,
+ * @b on the right.
+ *
+ * Returns:
+ * The resulting matrix.
+ */
+struct igt_mat4 igt_matrix_multiply(const struct igt_mat4 *a,
+				    const struct igt_mat4 *b)
+{
+	struct igt_mat4 ret = {};
+
+	for (int col = 0; col < 4; col++) {
+		for (int row = 0; row < 4; row++) {
+			for (int i = 0; i < 4; i++)
+				ret.d[m(row, col)] += a->d[m(row, i)] * b->d[m(i, col)];
+		}
+	}
+
+	return ret;
+}
diff --git a/lib/igt_matrix.h b/lib/igt_matrix.h
new file mode 100644
index 000000000000..33acb815197b
--- /dev/null
+++ b/lib/igt_matrix.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __IGT_MATRIX_H__
+#define __IGT_MATRIX_H__
+
+/**
+ * igt_vec4:
+ * @d: vector elements
+ *
+ * A 4 element column vector (4x1 matrix).
+ */
+struct igt_vec4 {
+	float d[4];
+};
+
+/**
+ * igt_mat4:
+ * @d: matrix elements
+ *
+ * A 4x4 column major matrix.
+ */
+struct igt_mat4 {
+	float d[16];
+};
+
+void igt_matrix_print(const struct igt_mat4 *m);
+struct igt_mat4 igt_matrix_identity(void);
+struct igt_mat4 igt_matrix_scale(float x, float y, float z);
+struct igt_mat4 igt_matrix_translate(float x, float y, float z);
+struct igt_vec4 igt_matrix_transform(const struct igt_mat4 *m,
+				     const struct igt_vec4 *v);
+struct igt_mat4 igt_matrix_multiply(const struct igt_mat4 *a,
+				    const struct igt_mat4 *b);
+
+#endif /* __IGT_MATRIX_H__ */
diff --git a/lib/meson.build b/lib/meson.build
index 493874b34600..230c07884c87 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -9,6 +9,7 @@ lib_sources = [
 	'igt_aux.c',
 	'igt_gt.c',
 	'igt_gvt.c',
+	'igt_matrix.c',
 	'igt_primes.c',
 	'igt_rand.c',
 	'igt_stats.c',
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (3 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 20:48   ` Chris Wilson
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
                   ` (8 subsequent siblings)
  13 siblings, 1 reply; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Add some helpers for generating rgb<->ycbcr conversion matrices.

v2: Add enums for color_encoding/color_range
    Fix full range handling (lacked +-0.5<->+-1.0 scaling)

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/Makefile.sources     |   2 +
 lib/igt_color_encoding.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_color_encoding.h |  49 ++++++++++++++++
 lib/meson.build          |   1 +
 4 files changed, 199 insertions(+)
 create mode 100644 lib/igt_color_encoding.c
 create mode 100644 lib/igt_color_encoding.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 5453340a65e0..25435fe86393 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -21,6 +21,8 @@ lib_source_list =	 	\
 	igt_device.h		\
 	igt_aux.c		\
 	igt_aux.h		\
+	igt_color_encoding.c	\
+	igt_color_encoding.h	\
 	igt_edid_template.h	\
 	igt_gt.c		\
 	igt_gt.h		\
diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
new file mode 100644
index 000000000000..b1648a747fcb
--- /dev/null
+++ b/lib/igt_color_encoding.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt_color_encoding.h"
+#include "igt_matrix.h"
+
+struct color_encoding {
+	float kr, kb;
+};
+
+static const struct color_encoding color_encodings[IGT_NUM_COLOR_ENCODINGS] = {
+	[IGT_COLOR_YCBCR_BT601] = { .kr = .299f, .kb = .114f, },
+	[IGT_COLOR_YCBCR_BT709] = { .kr = .2126f, .kb = .0722f, },
+	[IGT_COLOR_YCBCR_BT2020] = { .kr = .2627f, .kb = .0593f, },
+};
+
+static struct igt_mat4 rgb_to_ycbcr_matrix(const struct color_encoding *e)
+{
+	float kr, kg, kb;
+
+	kr = e->kr;
+	kb = e->kb;
+	kg = 1.0f - kr - kb;
+
+	struct igt_mat4 ret = {
+		.d[0 * 4 + 0] = kr,
+		.d[1 * 4 + 0] = kg,
+		.d[2 * 4 + 0] = kb,
+
+		.d[0 * 4 + 1] = -kr / (1.0f - kb),
+		.d[1 * 4 + 1] = -kg / (1.0f - kb),
+		.d[2 * 4 + 1] = 1.0f,
+
+		.d[0 * 4 + 2] = 1.0f,
+		.d[1 * 4 + 2] = -kg / (1.0f - kr),
+		.d[2 * 4 + 2] = -kb / (1.0f - kr),
+
+		.d[3 * 4 + 3] = 1.0f,
+	};
+
+	return ret;
+}
+
+static struct igt_mat4 ycbcr_to_rgb_matrix(const struct color_encoding *e)
+{
+	float kr, kg, kb;
+
+	kr = e->kr;
+	kb = e->kb;
+	kg = 1.0f - kr - kb;
+
+	struct igt_mat4 ret = {
+		.d[0 * 4 + 0] = 1.0f,
+		.d[1 * 4 + 0] = 0.0f,
+		.d[2 * 4 + 0] = 1.0 - kr,
+
+		.d[0 * 4 + 1] = 1.0f,
+		.d[1 * 4 + 1] = -(1.0 - kb) * kb / kg,
+		.d[2 * 4 + 1] = -(1.0 - kr) * kr / kg,
+
+		.d[0 * 4 + 2] = 1.0f,
+		.d[1 * 4 + 2] = 1.0 - kb,
+		.d[2 * 4 + 2] = 0.0f,
+
+		.d[3 * 4 + 3] = 1.0f,
+	};
+
+	return ret;
+}
+
+static struct igt_mat4 ycbcr_input_convert_matrix(enum igt_color_range color_range)
+{
+	struct igt_mat4 t, s;
+
+	if (color_range == IGT_COLOR_YCBCR_FULL_RANGE) {
+		t = igt_matrix_translate(0.0f, -128.0f, -128.0f);
+		s = igt_matrix_scale(1.0f, 2.0f, 2.0f);
+	} else {
+		t = igt_matrix_translate(-16.0f, -128.0f, -128.0f);
+		s = igt_matrix_scale(255.0f / (235.0f - 16.0f),
+				     255.0f / (240.0f - 128.0f),
+				     255.0f / (240.0f - 128.0f));
+	}
+
+	return igt_matrix_multiply(&s, &t);
+}
+
+static struct igt_mat4 ycbcr_output_convert_matrix(enum igt_color_range color_range)
+{
+	struct igt_mat4 s, t;
+
+	if (color_range == IGT_COLOR_YCBCR_FULL_RANGE) {
+		s = igt_matrix_scale(1.0f, 0.5f, 0.5f);
+		t = igt_matrix_translate(0.0f, 128.0f, 128.0f);
+	} else {
+		s = igt_matrix_scale((235.0f - 16.0f) / 255.0f,
+				     (240.0f - 128.0f) / 255.0f,
+				     (240.0f - 128.0f) / 255.0f);
+		t = igt_matrix_translate(16.0f, 128.0f, 128.0f);
+	}
+
+	return igt_matrix_multiply(&t, &s);
+}
+
+struct igt_mat4 igt_ycbcr_to_rgb_matrix(enum igt_color_encoding color_encoding,
+					enum igt_color_range color_range)
+{
+	const struct color_encoding *e = &color_encodings[color_encoding];
+	struct igt_mat4 r, c;
+
+	r = ycbcr_input_convert_matrix(color_range);
+	c = ycbcr_to_rgb_matrix(e);
+
+	return igt_matrix_multiply(&c, &r);
+}
+
+struct igt_mat4 igt_rgb_to_ycbcr_matrix(enum igt_color_encoding color_encoding,
+					enum igt_color_range color_range)
+{
+	const struct color_encoding *e = &color_encodings[color_encoding];
+	struct igt_mat4 c, r;
+
+	c = rgb_to_ycbcr_matrix(e);
+	r = ycbcr_output_convert_matrix(color_range);
+
+	return igt_matrix_multiply(&r, &c);
+}
diff --git a/lib/igt_color_encoding.h b/lib/igt_color_encoding.h
new file mode 100644
index 000000000000..0d8c819322af
--- /dev/null
+++ b/lib/igt_color_encoding.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef __IGT_COLOR_ENCODING_H__
+#define __IGT_COLOR_ENCODING_H__
+
+#include <stdbool.h>
+
+#include "igt_matrix.h"
+
+enum igt_color_encoding {
+	IGT_COLOR_YCBCR_BT601,
+	IGT_COLOR_YCBCR_BT709,
+	IGT_COLOR_YCBCR_BT2020,
+	IGT_NUM_COLOR_ENCODINGS,
+};
+
+enum igt_color_range {
+	IGT_COLOR_YCBCR_LIMITED_RANGE,
+	IGT_COLOR_YCBCR_FULL_RANGE,
+	IGT_NUM_COLOR_RANGES,
+};
+
+struct igt_mat4 igt_ycbcr_to_rgb_matrix(enum igt_color_encoding color_encoding,
+					enum igt_color_range color_range);
+struct igt_mat4 igt_rgb_to_ycbcr_matrix(enum igt_color_encoding color_encoding,
+					enum igt_color_range color_range);
+
+#endif /* __IGT_COLOR_ENCODING_H__ */
diff --git a/lib/meson.build b/lib/meson.build
index 230c07884c87..6e361724f258 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -4,6 +4,7 @@ lib_sources = [
 	'i915/gem_scheduler.c',
 	'i915/gem_submission.c',
 	'i915/gem_ring.c',
+	'igt_color_encoding.c',
 	'igt_debugfs.c',
 	'igt_device.c',
 	'igt_aux.c',
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (4 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 21:49   ` Chris Wilson
  2018-05-18 19:56   ` [igt-dev] [PATCH i-g-t v4 " Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
                   ` (7 subsequent siblings)
  13 siblings, 2 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Probably horribly inefficient (not that the original code tried to be
particularly efficient), but at least this is now pretty generic so
it'll be super easy to add other color encodings and whatnot.

v2: Rebase
v3: Deal with the new color_encoding/range enums

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 134 +++++++++++++++++++++++++++++------------------------------
 1 file changed, 65 insertions(+), 69 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index af8ba70b0a2a..8aea5b52c8a9 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -31,8 +31,10 @@
 
 #include "drmtest.h"
 #include "igt_aux.h"
+#include "igt_color_encoding.h"
 #include "igt_fb.h"
 #include "igt_kms.h"
+#include "igt_matrix.h"
 #include "igt_x86.h"
 #include "ioctl_wrappers.h"
 #include "intel_batchbuffer.h"
@@ -1377,6 +1379,8 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
 	uint8_t *buf = malloc(blit->linear.size);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
 
 	/*
 	 * Reading from the BO is awfully slow because of lack of read caching,
@@ -1387,30 +1391,29 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	y = &buf[blit->linear.offsets[0]];
 	uv = &buf[blit->linear.offsets[1]];
 
-	/* Convert from limited color range BT.601 */
 	for (i = 0; i < fb->height / 2; i++) {
 		for (j = 0; j < fb->width; j++) {
-			float r_, g_, b_, y0, y1, cb, cr;
 			/* Convert 1x2 pixel blocks */
+			struct igt_vec4 yuv0, yuv1;
+			struct igt_vec4 rgb0, rgb1;
 
-			y0 = 1.164f * (y[j] - 16.f);
-			y1 = 1.164f * (y[j + planar_stride] - 16.f);
+			yuv0.d[0] = y[j];
+			yuv1.d[0] = y[j + planar_stride];
+			yuv0.d[1] = yuv1.d[1] = uv[j & ~1];
+			yuv0.d[2] = yuv1.d[2] = uv[j | 1];
+			yuv0.d[3] = yuv1.d[3] = 1.0f;
 
-			cb = uv[j & ~1] - 128.f;
-			cr = uv[j | 1] - 128.f;
+			rgb0 = igt_matrix_transform(&m, &yuv0);
+			rgb1 = igt_matrix_transform(&m, &yuv1);
 
-			r_ =  0.000f * cb +  1.596f * cr;
-			g_ = -0.392f * cb + -0.813f * cr;
-			b_ =  2.017f * cb +  0.000f * cr;
+			rgb24[j * 4 + 2] = clamprgb(rgb0.d[0]);
+			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(rgb1.d[0]);
 
-			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
-			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
+			rgb24[j * 4 + 1] = clamprgb(rgb0.d[1]);
+			rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(rgb1.d[1]);
 
-			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
-			rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(y1 + g_);
-
-			rgb24[j * 4] = clamprgb(y0 + b_);
-			rgb24[j * 4 + rgb24_stride] = clamprgb(y1 + b_);
+			rgb24[j * 4 + 0] = clamprgb(rgb0.d[2]);
+			rgb24[j * 4 + 0 + rgb24_stride] = clamprgb(rgb1.d[2]);
 		}
 
 		rgb24 += 2 * rgb24_stride;
@@ -1421,20 +1424,20 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	if (fb->height & 1) {
 		/* Convert last row */
 		for (j = 0; j < fb->width; j++) {
-			float r_, g_, b_, y0, cb, cr;
 			/* Convert single pixel */
+			struct igt_vec4 yuv;
+			struct igt_vec4 rgb;
 
-			cb = uv[j & ~1] - 128.f;
-			cr = uv[j | 1] - 128.f;
+			yuv.d[0] = y[j];
+			yuv.d[1] = uv[j & ~1];
+			yuv.d[2] = uv[j | 1];
+			yuv.d[3] = 1.0f;
 
-			y0 = 1.164f * (y[j] - 16.f);
-			r_ =  0.000f * cb +  1.596f * cr;
-			g_ = -0.392f * cb + -0.813f * cr;
-			b_ =  2.017f * cb +  0.000f * cr;
+			rgb = igt_matrix_transform(&m, &yuv);
 
-			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
-			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
-			rgb24[j * 4] = clamprgb(y0 + b_);
+			rgb24[j * 4 + 2] = clamprgb(rgb.d[0]);
+			rgb24[j * 4 + 1] = clamprgb(rgb.d[1]);
+			rgb24[j * 4] = clamprgb(rgb.d[2]);
 		}
 	}
 
@@ -1449,65 +1452,58 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
 	const uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride;
 	unsigned planar_stride = blit->linear.stride;
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
 
 	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
 		     "Conversion not implemented for !NV12 planar formats\n");
 
-	for (i = 0; i < fb->plane_height[0]; i++) {
-		/* Use limited color range BT.601 */
+	for (i = 0; i < fb->height / 2; i++) {
+		for (j = 0; j < fb->width; j++) {
+			struct igt_vec4 rgb0, rgb1;
+			struct igt_vec4 yuv0, yuv1;
 
-		for (j = 0; j < fb->plane_width[0]; j++) {
-			float yf = 0.257f * rgb24[j * 4 + 2] +
-				   0.504f * rgb24[j * 4 + 1] +
-				   0.098f * rgb24[j * 4] + 16;
+			rgb0.d[0] = rgb24[j * 4 + 2];
+			rgb0.d[1] = rgb24[j * 4 + 1];
+			rgb0.d[2] = rgb24[j * 4 + 0];
+			rgb0.d[3] = 1.0f;
 
-			y[j] = (uint8_t)yf;
-		}
+			rgb1.d[0] = rgb24[j * 4 + 2 + rgb24_stride];
+			rgb1.d[1] = rgb24[j * 4 + 1 + rgb24_stride];
+			rgb1.d[2] = rgb24[j * 4 + 0 + rgb24_stride];
+			rgb1.d[3] = 1.0f;
 
-		rgb24 += rgb24_stride;
-		y += planar_stride;
-	}
+			yuv0 = igt_matrix_transform(&m, &rgb0);
+			yuv1 = igt_matrix_transform(&m, &rgb1);
 
-	rgb24 = blit->rgb24.map;
+			y[j] = yuv0.d[0];
+			y[j + planar_stride] = yuv1.d[0];
 
-	for (i = 0; i < fb->height / 2; i++) {
-		for (j = 0; j < fb->plane_width[1]; j++) {
-			/*
-			 * Pixel center for Cb'Cr' is between the left top and
-			 * bottom pixel in a 2x2 block, so take the average.
-			 */
-			float uf = -0.148f/2 * rgb24[j * 8 + 2] +
-				   -0.148f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
-				   -0.291f/2 * rgb24[j * 8 + 1] +
-				   -0.291f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
-				    0.439f/2 * rgb24[j * 8] +
-				    0.439f/2 * rgb24[j * 8 + rgb24_stride] + 128;
-			float vf =  0.439f/2 * rgb24[j * 8 + 2] +
-				    0.439f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
-				   -0.368f/2 * rgb24[j * 8 + 1] +
-				   -0.368f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
-				   -0.071f/2 * rgb24[j * 8] +
-				   -0.071f/2 * rgb24[j * 8 + rgb24_stride] + 128;
-			uv[j * 2] = (uint8_t)uf;
-			uv[j * 2 + 1] = (uint8_t)vf;
+			uv[j * 2 + 0] = (yuv0.d[1] + yuv1.d[1]) / 2.0f;
+			uv[j * 2 + 1] = (yuv0.d[2] + yuv1.d[2]) / 2.0f;
 		}
 
 		rgb24 += 2 * rgb24_stride;
+		y += 2 * planar_stride;
 		uv += planar_stride;
 	}
 
 	/* Last row cannot be interpolated between 2 pixels, take the single value */
-	if (i < fb->plane_height[1]) {
-		for (j = 0; j < fb->plane_width[1]; j++) {
-			float uf = -0.148f * rgb24[j * 8 + 2] +
-				   -0.291f * rgb24[j * 8 + 1] +
-				    0.439f * rgb24[j * 8] + 128;
-			float vf =  0.439f * rgb24[j * 8 + 2] +
-				   -0.368f * rgb24[j * 8 + 1] +
-				   -0.071f * rgb24[j * 8] + 128;
-
-			uv[j * 2] = (uint8_t)uf;
-			uv[j * 2 + 1] = (uint8_t)vf;
+	if (fb->height & 1) {
+		for (j = 0; j < fb->width; j++) {
+			struct igt_vec4 rgb;
+			struct igt_vec4 yuv;
+
+			rgb.d[0] = rgb24[j * 4 + 2];
+			rgb.d[1] = rgb24[j * 4 + 1];
+			rgb.d[2] = rgb24[j * 4 + 0];
+			rgb.d[3] = 1.0f;
+
+			yuv = igt_matrix_transform(&m, &rgb);
+
+			y[j] = yuv.d[0];
+			uv[j * 2 + 0] = yuv.d[1];
+			uv[j * 2 + 1] = yuv.d[2];
 		}
 	}
 }
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (5 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 22:41   ` Chris Wilson
  2018-05-18 19:57   ` [igt-dev] [PATCH i-g-t v5 " Ville Syrjala
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb Ville Syrjala
                   ` (6 subsequent siblings)
  13 siblings, 2 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Reuse the __convert() cairo stuff to support packed YCbCr framebuffers.

v2: Allow odd fb width since some tests want it
v3: Use igt_memcpy_from_wc()
v4: Rebase due to color_encoding/range enums

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 195 insertions(+), 10 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 8aea5b52c8a9..5ea944f36270 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -87,6 +87,22 @@ static struct format_desc_struct {
 	  .cairo_id = CAIRO_FORMAT_RGB24,
 	  .num_planes = 2, .plane_bpp = { 8, 16, },
 	},
+	{ .name = "YUYV", .depth = -1, .drm_id = DRM_FORMAT_YUYV,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "YVYU", .depth = -1, .drm_id = DRM_FORMAT_YVYU,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "UYVY", .depth = -1, .drm_id = DRM_FORMAT_UYVY,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "VYUY", .depth = -1, .drm_id = DRM_FORMAT_VYUY,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
 };
 #define for_each_format(f)	\
 	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
@@ -1508,16 +1524,174 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
 	}
 }
 
+/* { Y0, U, Y1, V } */
+static const unsigned char swizzle_yuyv[] = { 0, 1, 2, 3 };
+static const unsigned char swizzle_yvyu[] = { 0, 3, 2, 1 };
+static const unsigned char swizzle_uyvy[] = { 1, 0, 3, 2 };
+static const unsigned char swizzle_vyuy[] = { 1, 2, 3, 0 };
+
+static const unsigned char *yuyv_swizzle(uint32_t format)
+{
+	switch (format) {
+	default:
+	case DRM_FORMAT_YUYV:
+		return swizzle_yuyv;
+	case DRM_FORMAT_YVYU:
+		return swizzle_yvyu;
+	case DRM_FORMAT_UYVY:
+		return swizzle_uyvy;
+	case DRM_FORMAT_VYUY:
+		return swizzle_vyuy;
+	}
+}
+
+static void convert_yuyv_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit,
+				  const unsigned char swz[4])
+{
+	int i, j;
+	const uint8_t *yuyv;
+	uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride, yuyv_stride = blit->linear.stride;
+	uint8_t *buf = malloc(blit->linear.size);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+
+	/*
+	 * Reading from the BO is awfully slow because of lack of read caching,
+	 * it's faster to copy the whole BO to a temporary buffer and convert
+	 * from there.
+	 */
+	igt_memcpy_from_wc(buf, blit->linear.map, blit->linear.size);
+	yuyv = buf;
+
+	for (i = 0; i < fb->height; i++) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 yuv0, yuv1;
+			struct igt_vec4 rgb0, rgb1;
+
+			yuv0.d[0] = yuyv[j * 4 + swz[0]];
+			yuv1.d[0] = yuyv[j * 4 + swz[2]];
+			yuv0.d[1] = yuv1.d[1] = yuyv[j * 4 + swz[1]];
+			yuv0.d[2] = yuv1.d[2] = yuyv[j * 4 + swz[3]];
+			yuv0.d[3] = yuv1.d[3] = 1.0f;
+
+			rgb0 = igt_matrix_transform(&m, &yuv0);
+			rgb1 = igt_matrix_transform(&m, &yuv1);
+
+			rgb24[j * 8 + 2] = clamprgb(rgb0.d[0]);
+			rgb24[j * 8 + 1] = clamprgb(rgb0.d[1]);
+			rgb24[j * 8 + 0] = clamprgb(rgb0.d[2]);
+
+			rgb24[j * 8 + 4 + 2] = clamprgb(rgb1.d[0]);
+			rgb24[j * 8 + 4 + 1] = clamprgb(rgb1.d[1]);
+			rgb24[j * 8 + 4 + 0] = clamprgb(rgb1.d[2]);
+		}
+		if (fb->width & 1) {
+			struct igt_vec4 yuv;
+			struct igt_vec4 rgb;
+
+			yuv.d[0] = yuyv[j * 4 + swz[0]];
+			yuv.d[1] = yuyv[j * 4 + swz[1]];
+			yuv.d[2] = yuyv[j * 4 + swz[3]];
+			yuv.d[3] = 1.0f;
+
+			rgb = igt_matrix_transform(&m, &yuv);
+
+			rgb24[j * 8 + 2] = clamprgb(rgb.d[0]);
+			rgb24[j * 8 + 1] = clamprgb(rgb.d[1]);
+			rgb24[j * 8 + 0] = clamprgb(rgb.d[2]);
+		}
+
+		rgb24 += rgb24_stride;
+		yuyv += yuyv_stride;
+	}
+
+	free(buf);
+}
+
+static void convert_rgb24_to_yuyv(struct igt_fb *fb, struct fb_convert_blit_upload *blit,
+				  const unsigned char swz[4])
+{
+	int i, j;
+	uint8_t *yuyv = blit->linear.map;
+	const uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride;
+	unsigned yuyv_stride = blit->linear.stride;
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+
+	igt_assert_f(fb->drm_format == DRM_FORMAT_YUYV ||
+		     fb->drm_format == DRM_FORMAT_YVYU ||
+		     fb->drm_format == DRM_FORMAT_UYVY ||
+		     fb->drm_format == DRM_FORMAT_VYUY,
+		     "Conversion not implemented for !YUYV planar formats\n");
+
+	for (i = 0; i < fb->height; i++) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 rgb0, rgb1;
+			struct igt_vec4 yuv0, yuv1;
+
+			rgb0.d[0] = rgb24[j * 8 + 2];
+			rgb0.d[1] = rgb24[j * 8 + 1];
+			rgb0.d[2] = rgb24[j * 8 + 0];
+			rgb0.d[3] = 1.0f;
+
+			rgb1.d[0] = rgb24[j * 8 + 4 + 2];
+			rgb1.d[1] = rgb24[j * 8 + 4 + 1];
+			rgb1.d[2] = rgb24[j * 8 + 4 + 0];
+			rgb1.d[3] = 1.0f;
+
+			yuv0 = igt_matrix_transform(&m, &rgb0);
+			yuv1 = igt_matrix_transform(&m, &rgb1);
+
+			yuyv[j * 4 + swz[0]] = yuv0.d[0];
+			yuyv[j * 4 + swz[2]] = yuv1.d[0];
+			yuyv[j * 4 + swz[1]] = (yuv0.d[1] + yuv1.d[1]) / 2.0f;
+			yuyv[j * 4 + swz[3]] = (yuv0.d[2] + yuv1.d[2]) / 2.0f;
+		}
+		if (fb->width & 1) {
+			struct igt_vec4 rgb;
+			struct igt_vec4 yuv;
+
+			rgb.d[0] = rgb24[j * 8 + 2];
+			rgb.d[1] = rgb24[j * 8 + 1];
+			rgb.d[2] = rgb24[j * 8 + 0];
+			rgb.d[3] = 1.0f;
+
+			yuv = igt_matrix_transform(&m, &rgb);
+
+			yuyv[j * 4 + swz[0]] = yuv.d[0];
+			yuyv[j * 4 + swz[1]] = yuv.d[1];
+			yuyv[j * 4 + swz[3]] = yuv.d[2];
+		}
+
+		rgb24 += rgb24_stride;
+		yuyv += yuyv_stride;
+	}
+}
+
 static void destroy_cairo_surface__convert(void *arg)
 {
 	struct fb_convert_blit_upload *blit = arg;
 	struct igt_fb *fb = blit->fb;
 
-	/* Convert back to planar! */
-	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
-		     "Conversion not implemented for !NV12 planar formats\n");
-
-	convert_rgb24_to_nv12(fb, blit);
+	/* Convert linear rgb back! */
+	switch(fb->drm_format) {
+	case DRM_FORMAT_NV12:
+		convert_rgb24_to_nv12(fb, blit);
+		break;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		convert_rgb24_to_yuyv(fb, blit, yuyv_swizzle(fb->drm_format));
+		break;
+	default:
+		igt_assert_f(false, "Conversion not implemented for formats 0x%x\n",
+			     fb->drm_format);
+	}
 
 	munmap(blit->rgb24.map, blit->rgb24.size);
 
@@ -1556,10 +1730,21 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
 		memcpy(blit->linear.offsets, fb->offsets, sizeof(fb->offsets));
 	}
 
-	/* Convert to linear! */
-	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
-		     "Conversion not implemented for !NV12 planar formats\n");
-	convert_nv12_to_rgb24(fb, blit);
+	/* Convert to linear rgb! */
+	switch(fb->drm_format) {
+	case DRM_FORMAT_NV12:
+		convert_nv12_to_rgb24(fb, blit);
+		break;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		convert_yuyv_to_rgb24(fb, blit, yuyv_swizzle(fb->drm_format));
+		break;
+	default:
+		igt_assert_f(false, "Conversion not implemented for formats 0x%x\n",
+			     fb->drm_format);
+	}
 
 	fb->cairo_surface =
 		cairo_image_surface_create_for_data(blit->rgb24.map,
@@ -1586,7 +1771,7 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
 	if (fb->cairo_surface == NULL) {
-		if (fb->num_planes > 1)
+		if (is_yuv(fb->drm_format))
 			create_cairo_surface__convert(fd, fb);
 		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (6 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 21:42   ` Chris Wilson
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 10/10] lib/kms: Respect fb color_encoding/color_range Ville Syrjala
                   ` (5 subsequent siblings)
  13 siblings, 1 reply; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Make igt_fb be aware of the color encoding/range. For now
we still hardcore everything to BT.709 limited range though.

v2: Default to BT.709

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 46 +++++++++++++++++++++++++++++-----------------
 lib/igt_fb.h |  4 ++++
 2 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 5ea944f36270..e68ce63e863c 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -388,6 +388,8 @@ static bool is_yuv(uint32_t format)
 
 /* helpers to create nice-looking framebuffers */
 static int create_bo_for_fb(int fd, int width, int height,
+			    enum igt_color_encoding color_encoding,
+			    enum igt_color_range color_range,
 			    struct format_desc_struct *format,
 			    uint64_t tiling, unsigned size, unsigned stride,
 			    unsigned *size_ret, unsigned *stride_ret,
@@ -420,7 +422,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 
 		if (is_i915_device(fd)) {
 			uint8_t *ptr;
-			bool full_range = false; /* FIXME */
+			bool full_range = color_range == IGT_COLOR_YCBCR_FULL_RANGE;
 
 			bo = gem_create(fd, size);
 			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
@@ -495,7 +497,10 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
 				  unsigned stride, unsigned *size_ret,
 				  unsigned *stride_ret, bool *is_dumb)
 {
-	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
+	return create_bo_for_fb(fd, width, height,
+				IGT_COLOR_YCBCR_BT709,
+				IGT_COLOR_YCBCR_LIMITED_RANGE,
+				lookup_drm_format(format),
 				modifier, 0, stride, size_ret, stride_ret, NULL, is_dumb);
 }
 
@@ -837,6 +842,9 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 			   struct igt_fb *fb, unsigned bo_size,
 			   unsigned bo_stride)
 {
+	/* FIXME allow the caller to pass these in */
+	enum igt_color_encoding color_encoding = IGT_COLOR_YCBCR_BT709;
+	enum igt_color_range color_range = IGT_COLOR_YCBCR_LIMITED_RANGE;
 	struct format_desc_struct *f = lookup_drm_format(format);
 	uint32_t fb_id;
 	int i;
@@ -847,8 +855,9 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 
 	igt_debug("%s(width=%d, height=%d, format=0x%x, tiling=0x%"PRIx64", size=%d)\n",
 		  __func__, width, height, format, tiling, bo_size);
-	fb->gem_handle = create_bo_for_fb(fd, width, height, f,
-					  tiling, bo_size, bo_stride,
+	fb->gem_handle = create_bo_for_fb(fd, width, height,
+					  color_encoding, color_range,
+					  f, tiling, bo_size, bo_stride,
 					  &fb->size, &fb->stride,
 					  fb->offsets, &fb->is_dumb);
 	igt_assert(fb->gem_handle > 0);
@@ -887,6 +896,8 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	fb->fb_id = fb_id;
 	fb->fd = fd;
 	fb->num_planes = f->num_planes;
+	fb->color_encoding = color_encoding;
+	fb->color_range = color_range;
 
 	for (i = 0; i < f->num_planes; i++) {
 		fb->plane_bpp[i] = f->plane_bpp[i];
@@ -1263,11 +1274,12 @@ static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linea
 	 * destination, tiling it at the same time.
 	 */
 	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
-					       lookup_drm_format(fb->drm_format),
-					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
-					       0, &linear->size,
-					       &linear->stride,
-					       linear->offsets, &linear->is_dumb);
+					  fb->color_encoding, fb->color_range,
+					  lookup_drm_format(fb->drm_format),
+					  LOCAL_DRM_FORMAT_MOD_NONE, 0,
+					  0, &linear->size,
+					  &linear->stride,
+					  linear->offsets, &linear->is_dumb);
 
 	igt_assert(linear->handle > 0);
 
@@ -1395,8 +1407,8 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
 	uint8_t *buf = malloc(blit->linear.size);
-	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
-						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(fb->color_encoding,
+						    fb->color_range);
 
 	/*
 	 * Reading from the BO is awfully slow because of lack of read caching,
@@ -1468,8 +1480,8 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
 	const uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride;
 	unsigned planar_stride = blit->linear.stride;
-	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
-						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(fb->color_encoding,
+						    fb->color_range);
 
 	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
 		     "Conversion not implemented for !NV12 planar formats\n");
@@ -1553,8 +1565,8 @@ static void convert_yuyv_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride, yuyv_stride = blit->linear.stride;
 	uint8_t *buf = malloc(blit->linear.size);
-	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
-						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(fb->color_encoding,
+						    fb->color_range);
 
 	/*
 	 * Reading from the BO is awfully slow because of lack of read caching,
@@ -1618,8 +1630,8 @@ static void convert_rgb24_to_yuyv(struct igt_fb *fb, struct fb_convert_blit_uplo
 	const uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride;
 	unsigned yuyv_stride = blit->linear.stride;
-	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
-						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(fb->color_encoding,
+						    fb->color_range);
 
 	igt_assert_f(fb->drm_format == DRM_FORMAT_YUYV ||
 		     fb->drm_format == DRM_FORMAT_YVYU ||
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 023b069db592..f947059d383c 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -36,6 +36,8 @@
 
 #include <i915_drm.h>
 
+#include "igt_color_encoding.h"
+
 /**
  * igt_fb_t:
  * @fb_id: KMS ID of the framebuffer
@@ -66,6 +68,8 @@ typedef struct igt_fb {
 	uint32_t drm_format;
 	int width;
 	int height;
+	enum igt_color_encoding color_encoding;
+	enum igt_color_range color_range;
 	unsigned int stride;
 	uint64_t tiling;
 	unsigned int size;
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t 10/10] lib/kms: Respect fb color_encoding/color_range
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (7 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb Ville Syrjala
@ 2018-05-17 19:51 ` Ville Syrjala
  2018-05-17 20:09 ` [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Chris Wilson
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-17 19:51 UTC (permalink / raw)
  To: igt-dev

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

Configure the plane color_encoding/color_range based on what the
fb contents are.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_kms.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  9 +++++++
 2 files changed, 85 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 0cee0c06390b..56fa0dc609a0 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -173,6 +173,8 @@ const char * const igt_plane_prop_names[IGT_NUM_PLANE_PROPS] = {
 	[IGT_PLANE_TYPE] = "type",
 	[IGT_PLANE_ROTATION] = "rotation",
 	[IGT_PLANE_IN_FORMATS] = "IN_FORMATS",
+	[IGT_PLANE_COLOR_ENCODING] = "COLOR_ENCODING",
+	[IGT_PLANE_COLOR_RANGE] = "COLOR_RANGE",
 };
 
 const char * const igt_crtc_prop_names[IGT_NUM_CRTC_PROPS] = {
@@ -194,6 +196,61 @@ const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = {
 	[IGT_CONNECTOR_BROADCAST_RGB] = "Broadcast RGB",
 };
 
+static const char * const igt_color_encoding_names[IGT_NUM_COLOR_ENCODINGS] = {
+	[IGT_COLOR_YCBCR_BT601] = "ITU-R BT.601 YCbCr",
+	[IGT_COLOR_YCBCR_BT709] = "ITU-R BT.709 YCbCr",
+	[IGT_COLOR_YCBCR_BT2020] = "ITU-R BT.2020 YCbCr",
+};
+
+static const char * const igt_color_range_names[IGT_NUM_COLOR_RANGES] = {
+	[IGT_COLOR_YCBCR_FULL_RANGE] = "YCbCr full range",
+	[IGT_COLOR_YCBCR_LIMITED_RANGE] = "YCbCr limited range",
+};
+
+static void parse_enum_prop(drmModePropertyPtr prop,
+			    int num_enums,
+			    uint64_t values[],
+			    const char * const enum_names[])
+{
+	igt_assert((prop->flags & ~(DRM_MODE_PROP_IMMUTABLE |
+				    DRM_MODE_PROP_ATOMIC)) == DRM_MODE_PROP_ENUM);
+	igt_assert(prop->count_enums == prop->count_values);
+	igt_assert(prop->count_enums >= 1);
+	igt_assert(!!(prop->flags & DRM_MODE_PROP_IMMUTABLE) == (prop->count_enums == 1));
+
+	for (int i = 0; i < prop->count_enums; i++) {
+		for (int j = 0; j < num_enums; j++) {
+			if (strcmp(prop->enums[i].name, enum_names[j]))
+				continue;
+
+			values[j] = prop->enums[i].value;
+		}
+	}
+}
+
+static void
+parse_color_encoding_prop(igt_plane_t *plane, drmModePropertyPtr prop)
+{
+	parse_enum_prop(prop, ARRAY_SIZE(igt_color_encoding_names),
+			plane->color_encoding.values,
+			igt_color_encoding_names);
+}
+
+static void
+parse_color_range_prop(igt_plane_t *plane, drmModePropertyPtr prop)
+{
+	parse_enum_prop(prop, ARRAY_SIZE(igt_color_range_names),
+			plane->color_range.values,
+			igt_color_range_names);
+}
+
+typedef void (*parse_plane_prop_t)(igt_plane_t *plane, drmModePropertyPtr prop);
+
+static const parse_plane_prop_t igt_parse_plane_prop[IGT_NUM_PLANE_PROPS] = {
+	[IGT_PLANE_COLOR_ENCODING] = parse_color_encoding_prop,
+	[IGT_PLANE_COLOR_RANGE] = parse_color_range_prop,
+};
+
 /*
  * Retrieve all the properies specified in props_name and store them into
  * plane->props.
@@ -218,6 +275,9 @@ igt_fill_plane_props(igt_display_t *display, igt_plane_t *plane,
 			if (strcmp(prop->name, prop_names[j]) != 0)
 				continue;
 
+			if (igt_parse_plane_prop[j])
+				igt_parse_plane_prop[j](plane, prop);
+
 			plane->props[j] = props->props[i];
 			break;
 		}
@@ -1721,6 +1781,13 @@ static void igt_plane_reset(igt_plane_t *plane)
 	igt_plane_set_prop_value(plane, IGT_PLANE_FB_ID, 0);
 	igt_plane_set_prop_value(plane, IGT_PLANE_CRTC_ID, 0);
 
+	if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_ENCODING))
+		igt_plane_set_prop_value(plane, IGT_PLANE_COLOR_ENCODING,
+					 plane->color_encoding.values[IGT_COLOR_YCBCR_BT601]);
+	if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_RANGE))
+		igt_plane_set_prop_value(plane, IGT_PLANE_COLOR_RANGE,
+					 plane->color_range.values[IGT_COLOR_YCBCR_LIMITED_RANGE]);
+
 	/* Use default rotation */
 	if (igt_plane_has_prop(plane, IGT_PLANE_ROTATION))
 		igt_plane_set_prop_value(plane, IGT_PLANE_ROTATION, IGT_ROTATION_0);
@@ -3546,6 +3613,15 @@ void igt_plane_set_fb(igt_plane_t *plane, struct igt_fb *fb)
 		/* set default src pos/size as fb size */
 		igt_fb_set_position(fb, plane, 0, 0);
 		igt_fb_set_size(fb, plane, fb->width, fb->height);
+
+		if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_ENCODING))
+			igt_plane_set_prop_value(plane,
+						 IGT_PLANE_COLOR_ENCODING,
+						 plane->color_encoding.values[fb->color_encoding]);
+		if (igt_plane_has_prop(plane, IGT_PLANE_COLOR_RANGE))
+			igt_plane_set_prop_value(plane,
+						 IGT_PLANE_COLOR_RANGE,
+						 plane->color_range.values[fb->color_range]);
 	} else {
 		igt_plane_set_size(plane, 0, 0);
 
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 0e75d0c9e6b9..509a0ed2de3d 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -263,6 +263,8 @@ enum igt_atomic_plane_properties {
        IGT_PLANE_TYPE,
        IGT_PLANE_ROTATION,
        IGT_PLANE_IN_FORMATS,
+       IGT_PLANE_COLOR_ENCODING,
+       IGT_PLANE_COLOR_RANGE,
        IGT_NUM_PLANE_PROPS
 };
 
@@ -307,6 +309,13 @@ typedef struct {
 	/* gem handle for fb */
 	uint32_t gem_handle;
 
+	struct {
+		uint64_t values[IGT_NUM_COLOR_ENCODINGS];
+	} color_encoding;
+	struct {
+		uint64_t values[IGT_NUM_COLOR_RANGES];
+	} color_range;
+
 	uint64_t changed;
 	uint32_t props[IGT_NUM_PLANE_PROPS];
 	uint64_t values[IGT_NUM_PLANE_PROPS];
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (8 preceding siblings ...)
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 10/10] lib/kms: Respect fb color_encoding/color_range Ville Syrjala
@ 2018-05-17 20:09 ` Chris Wilson
  2018-05-17 20:29 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] " Patchwork
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 20:09 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:39)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc Ville Syrjala
@ 2018-05-17 20:13   ` Chris Wilson
  2018-05-18 12:42     ` Ville Syrjälä
  0 siblings, 1 reply; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 20:13 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:42)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Always populate the plane_bpp[] stuff, and use named initializers so
> that we can actually see what's being set to what.
> 
> v2: Fix depth for xrgb8888
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

> ---
>  lib/igt_fb.c | 66 +++++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 36 insertions(+), 30 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 5cf2cd7d9e90..af8ba70b0a2a 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -57,26 +57,35 @@
>   */
>  
>  /* drm fourcc/cairo format maps */
> -#define DF(did, cid, ...)      \
> -       { DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
>  static struct format_desc_struct {
> +       const char *name;
>         uint32_t drm_id;
>         cairo_format_t cairo_id;
> -       const char *name;
> -       int bpp;
>         int depth;
> -       int planes;
> +       int num_planes;
>         int plane_bpp[4];
>  } format_desc[] = {
> -       DF(RGB565,      RGB16_565,      16, 16),
> -       //DF(RGB888,    INVALID,        24, 24),
> -       DF(XRGB8888,    RGB24,          32, 24),
> -       DF(XRGB2101010, RGB30,          32, 30),
> -       DF(ARGB8888,    ARGB32,         32, 32),
> -       DF(NV12,        RGB24,          32, -1, 2, {8, 16}),
> +       { .name = "RGB565", .depth = 16, .drm_id = DRM_FORMAT_RGB565,
> +         .cairo_id = CAIRO_FORMAT_RGB16_565,
> +         .num_planes = 1, .plane_bpp = { 16, },
> +       },

There's no enum to suggest
	[MY_FORMAT_DESC_A] = {
		.name = "XRGB8888", .depth = 24, .drm_id = DRM_FORMAT_XRGB8888,
		.cairo_id = CAIRO_FORMAT_RGB24,
		.num_planes = 1, .plane_bpp = { 32, },
	}
?
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix Ville Syrjala
@ 2018-05-17 20:16   ` Chris Wilson
  0 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 20:16 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:43)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add a helper library for basic matrix math.
> 
> v2: Make the identity matrix static const (Chris)
>     Add the m(row,col) macro (Chris)
> 
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Surprised no determinant, invert or transpose ;)
They usually turn up before too long.
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (9 preceding siblings ...)
  2018-05-17 20:09 ` [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Chris Wilson
@ 2018-05-17 20:29 ` Patchwork
  2018-05-17 23:38 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 27+ messages in thread
From: Patchwork @ 2018-05-17 20:29 UTC (permalink / raw)
  To: Ville Syrjala; +Cc: igt-dev

== Series Details ==

Series: series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
URL   : https://patchwork.freedesktop.org/series/43360/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4193 -> IGTPW_1373 =

== Summary - SUCCESS ==

  No regressions found.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/43360/revisions/1/mbox/

== Known issues ==

  Here are the changes found in IGTPW_1373 that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@kms_flip@basic-flip-vs-modeset:
      fi-cnl-y3:          PASS -> INCOMPLETE (fdo#105086)

    
    ==== Possible fixes ====

    igt@kms_pipe_crc_basic@nonblocking-crc-pipe-a-frame-sequence:
      fi-cfl-s3:          FAIL (fdo#103481) -> PASS +1

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      fi-cnl-psr:         DMESG-WARN (fdo#104951) -> PASS

    
  fdo#103481 https://bugs.freedesktop.org/show_bug.cgi?id=103481
  fdo#104951 https://bugs.freedesktop.org/show_bug.cgi?id=104951
  fdo#105086 https://bugs.freedesktop.org/show_bug.cgi?id=105086


== Participating hosts (41 -> 39) ==

  Additional (3): fi-kbl-guc fi-cfl-guc fi-snb-2520m 
  Missing    (5): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan fi-skl-6700hq 


== Build changes ==

    * IGT: IGT_4485 -> IGTPW_1373
    * Piglit: piglit_4485 -> piglit_4487

  CI_DRM_4193: 9322e3903ce6c89bde0c24877fe730b808427caf @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1373: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1373/
  IGT_4485: eccae1360d6d01e73c6af2bd97122cef708207ef @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  piglit_4485: 62ef6b0db8967e7021fd3e0b57d03ff164b984fe @ git://anongit.freedesktop.org/piglit
  piglit_4487: 6ab75f7eb5e1dccbb773e1739beeb2d7cbd6ad0d @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1373/issues.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding Ville Syrjala
@ 2018-05-17 20:48   ` Chris Wilson
  0 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 20:48 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:44)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add some helpers for generating rgb<->ycbcr conversion matrices.
> 
> v2: Add enums for color_encoding/color_range
>     Fix full range handling (lacked +-0.5<->+-1.0 scaling)
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  lib/Makefile.sources     |   2 +
>  lib/igt_color_encoding.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_color_encoding.h |  49 ++++++++++++++++
>  lib/meson.build          |   1 +
>  4 files changed, 199 insertions(+)
>  create mode 100644 lib/igt_color_encoding.c
>  create mode 100644 lib/igt_color_encoding.h
> 
> diff --git a/lib/Makefile.sources b/lib/Makefile.sources
> index 5453340a65e0..25435fe86393 100644
> --- a/lib/Makefile.sources
> +++ b/lib/Makefile.sources
> @@ -21,6 +21,8 @@ lib_source_list =             \
>         igt_device.h            \
>         igt_aux.c               \
>         igt_aux.h               \
> +       igt_color_encoding.c    \
> +       igt_color_encoding.h    \
>         igt_edid_template.h     \
>         igt_gt.c                \
>         igt_gt.h                \
> diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
> new file mode 100644
> index 000000000000..b1648a747fcb
> --- /dev/null
> +++ b/lib/igt_color_encoding.c
> @@ -0,0 +1,147 @@
> +/*
> + * Copyright © 2018 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include "igt_color_encoding.h"
> +#include "igt_matrix.h"
> +
> +struct color_encoding {
> +       float kr, kb;
> +};
> +
> +static const struct color_encoding color_encodings[IGT_NUM_COLOR_ENCODINGS] = {
> +       [IGT_COLOR_YCBCR_BT601] = { .kr = .299f, .kb = .114f, },
> +       [IGT_COLOR_YCBCR_BT709] = { .kr = .2126f, .kb = .0722f, },
> +       [IGT_COLOR_YCBCR_BT2020] = { .kr = .2627f, .kb = .0593f, },

Ok.

> +};
> +
> +static struct igt_mat4 rgb_to_ycbcr_matrix(const struct color_encoding *e)
> +{
> +       float kr, kg, kb;
> +
> +       kr = e->kr;
> +       kb = e->kb;
> +       kg = 1.0f - kr - kb;

Ok.

> +
> +       struct igt_mat4 ret = {
> +               .d[0 * 4 + 0] = kr,

Meh, I wish you exported m(row,col) so that I don't have to think about
the matrix layout.

> +               .d[1 * 4 + 0] = kg,
> +               .d[2 * 4 + 0] = kb,
> +
> +               .d[0 * 4 + 1] = -kr / (1.0f - kb),
> +               .d[1 * 4 + 1] = -kg / (1.0f - kb),
> +               .d[2 * 4 + 1] = 1.0f,

Wiki gives

y = kr * R + kg * G + kb * B

cb = 0.5 * (B - y) / (1 - kb)
cr = 0.5 * (R - y) / (1 - kb)


2*cb*(1-kb) = (B - (kr * R + kg * G + kb * B))
            = -kr * R - kg * G + (1 - kb) * B
2*cb        = -kr/(1-kb) * R + -kg/(1-kb) * G + B

And the factor of 2 falls out in the range conversion.

Ok, you've convinced me the maths checks out.
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb Ville Syrjala
@ 2018-05-17 21:42   ` Chris Wilson
  0 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 21:42 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:47)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Make igt_fb be aware of the color encoding/range. For now
> we still hardcore everything to BT.709 limited range though.
> 
> v2: Default to BT.709
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
@ 2018-05-17 21:49   ` Chris Wilson
  2018-05-18 12:41     ` Ville Syrjälä
  2018-05-18 19:56   ` [igt-dev] [PATCH i-g-t v4 " Ville Syrjala
  1 sibling, 1 reply; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 21:49 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:45)
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Probably horribly inefficient (not that the original code tried to be
> particularly efficient), but at least this is now pretty generic so
> it'll be super easy to add other color encodings and whatnot.
> 
> v2: Rebase
> v3: Deal with the new color_encoding/range enums
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  lib/igt_fb.c | 134 +++++++++++++++++++++++++++++------------------------------
>  1 file changed, 65 insertions(+), 69 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index af8ba70b0a2a..8aea5b52c8a9 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -31,8 +31,10 @@
>  
>  #include "drmtest.h"
>  #include "igt_aux.h"
> +#include "igt_color_encoding.h"
>  #include "igt_fb.h"
>  #include "igt_kms.h"
> +#include "igt_matrix.h"
>  #include "igt_x86.h"
>  #include "ioctl_wrappers.h"
>  #include "intel_batchbuffer.h"
> @@ -1377,6 +1379,8 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
>         uint8_t *rgb24 = blit->rgb24.map;
>         unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
>         uint8_t *buf = malloc(blit->linear.size);
> +       struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
> +                                                   IGT_COLOR_YCBCR_LIMITED_RANGE);
>  
>         /*
>          * Reading from the BO is awfully slow because of lack of read caching,
> @@ -1387,30 +1391,29 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
>         y = &buf[blit->linear.offsets[0]];
>         uv = &buf[blit->linear.offsets[1]];
>  
> -       /* Convert from limited color range BT.601 */
>         for (i = 0; i < fb->height / 2; i++) {
>                 for (j = 0; j < fb->width; j++) {
> -                       float r_, g_, b_, y0, y1, cb, cr;
>                         /* Convert 1x2 pixel blocks */
> +                       struct igt_vec4 yuv0, yuv1;
> +                       struct igt_vec4 rgb0, rgb1;
>  
> -                       y0 = 1.164f * (y[j] - 16.f);
> -                       y1 = 1.164f * (y[j + planar_stride] - 16.f);
> +                       yuv0.d[0] = y[j];
> +                       yuv1.d[0] = y[j + planar_stride];
> +                       yuv0.d[1] = yuv1.d[1] = uv[j & ~1];
> +                       yuv0.d[2] = yuv1.d[2] = uv[j | 1];
> +                       yuv0.d[3] = yuv1.d[3] = 1.0f;
>  
> -                       cb = uv[j & ~1] - 128.f;
> -                       cr = uv[j | 1] - 128.f;
> +                       rgb0 = igt_matrix_transform(&m, &yuv0);
> +                       rgb1 = igt_matrix_transform(&m, &yuv1);

Ok.

> -                       r_ =  0.000f * cb +  1.596f * cr;
> -                       g_ = -0.392f * cb + -0.813f * cr;
> -                       b_ =  2.017f * cb +  0.000f * cr;
> +                       rgb24[j * 4 + 2] = clamprgb(rgb0.d[0]);
> +                       rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(rgb1.d[0]);
>  
> -                       rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> -                       rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
> +                       rgb24[j * 4 + 1] = clamprgb(rgb0.d[1]);
> +                       rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(rgb1.d[1]);
>  
> -                       rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> -                       rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(y1 + g_);
> -
> -                       rgb24[j * 4] = clamprgb(y0 + b_);
> -                       rgb24[j * 4 + rgb24_stride] = clamprgb(y1 + b_);
> +                       rgb24[j * 4 + 0] = clamprgb(rgb0.d[2]);
> +                       rgb24[j * 4 + 0 + rgb24_stride] = clamprgb(rgb1.d[2]);

Ok.

>                 }
>  
>                 rgb24 += 2 * rgb24_stride;
> @@ -1421,20 +1424,20 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
>         if (fb->height & 1) {
>                 /* Convert last row */
>                 for (j = 0; j < fb->width; j++) {
> -                       float r_, g_, b_, y0, cb, cr;
>                         /* Convert single pixel */
> +                       struct igt_vec4 yuv;
> +                       struct igt_vec4 rgb;
>  
> -                       cb = uv[j & ~1] - 128.f;
> -                       cr = uv[j | 1] - 128.f;
> +                       yuv.d[0] = y[j];
> +                       yuv.d[1] = uv[j & ~1];
> +                       yuv.d[2] = uv[j | 1];
> +                       yuv.d[3] = 1.0f;
>  
> -                       y0 = 1.164f * (y[j] - 16.f);
> -                       r_ =  0.000f * cb +  1.596f * cr;
> -                       g_ = -0.392f * cb + -0.813f * cr;
> -                       b_ =  2.017f * cb +  0.000f * cr;
> +                       rgb = igt_matrix_transform(&m, &yuv);
>  
> -                       rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> -                       rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> -                       rgb24[j * 4] = clamprgb(y0 + b_);
> +                       rgb24[j * 4 + 2] = clamprgb(rgb.d[0]);
> +                       rgb24[j * 4 + 1] = clamprgb(rgb.d[1]);
> +                       rgb24[j * 4] = clamprgb(rgb.d[2]);

                          rgb24[j * 4 + 2] = clamprgb(rgb.d[0]);
                          rgb24[j * 4 + 1] = clamprgb(rgb.d[1]);
                          rgb24[j * 4 + 0] = clamprgb(rgb.d[2]);
?

>                 }
>         }
>  
> @@ -1449,65 +1452,58 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
>         const uint8_t *rgb24 = blit->rgb24.map;
>         unsigned rgb24_stride = blit->rgb24.stride;
>         unsigned planar_stride = blit->linear.stride;
> +       struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
> +                                                   IGT_COLOR_YCBCR_LIMITED_RANGE);
>  
>         igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
>                      "Conversion not implemented for !NV12 planar formats\n");
>  
> -       for (i = 0; i < fb->plane_height[0]; i++) {
> -               /* Use limited color range BT.601 */
> +       for (i = 0; i < fb->height / 2; i++) {
> +               for (j = 0; j < fb->width; j++) {
> +                       struct igt_vec4 rgb0, rgb1;
> +                       struct igt_vec4 yuv0, yuv1;
>  
> -               for (j = 0; j < fb->plane_width[0]; j++) {
> -                       float yf = 0.257f * rgb24[j * 4 + 2] +
> -                                  0.504f * rgb24[j * 4 + 1] +
> -                                  0.098f * rgb24[j * 4] + 16;
> +                       rgb0.d[0] = rgb24[j * 4 + 2];
> +                       rgb0.d[1] = rgb24[j * 4 + 1];
> +                       rgb0.d[2] = rgb24[j * 4 + 0];
> +                       rgb0.d[3] = 1.0f;
>  
> -                       y[j] = (uint8_t)yf;
> -               }
> +                       rgb1.d[0] = rgb24[j * 4 + 2 + rgb24_stride];
> +                       rgb1.d[1] = rgb24[j * 4 + 1 + rgb24_stride];
> +                       rgb1.d[2] = rgb24[j * 4 + 0 + rgb24_stride];
> +                       rgb1.d[3] = 1.0f;
>  
> -               rgb24 += rgb24_stride;
> -               y += planar_stride;
> -       }
> +                       yuv0 = igt_matrix_transform(&m, &rgb0);
> +                       yuv1 = igt_matrix_transform(&m, &rgb1);
>  
> -       rgb24 = blit->rgb24.map;
> +                       y[j] = yuv0.d[0];
> +                       y[j + planar_stride] = yuv1.d[0];
>  
> -       for (i = 0; i < fb->height / 2; i++) {
> -               for (j = 0; j < fb->plane_width[1]; j++) {
> -                       /*
> -                        * Pixel center for Cb'Cr' is between the left top and
> -                        * bottom pixel in a 2x2 block, so take the average.
> -                        */
> -                       float uf = -0.148f/2 * rgb24[j * 8 + 2] +
> -                                  -0.148f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
> -                                  -0.291f/2 * rgb24[j * 8 + 1] +
> -                                  -0.291f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
> -                                   0.439f/2 * rgb24[j * 8] +
> -                                   0.439f/2 * rgb24[j * 8 + rgb24_stride] + 128;
> -                       float vf =  0.439f/2 * rgb24[j * 8 + 2] +
> -                                   0.439f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
> -                                  -0.368f/2 * rgb24[j * 8 + 1] +
> -                                  -0.368f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
> -                                  -0.071f/2 * rgb24[j * 8] +
> -                                  -0.071f/2 * rgb24[j * 8 + rgb24_stride] + 128;
> -                       uv[j * 2] = (uint8_t)uf;
> -                       uv[j * 2 + 1] = (uint8_t)vf;
> +                       uv[j * 2 + 0] = (yuv0.d[1] + yuv1.d[1]) / 2.0f;
> +                       uv[j * 2 + 1] = (yuv0.d[2] + yuv1.d[2]) / 2.0f;

Keep the comment about averaging tl+br. Why only 2 points btw?

>                 }
>  
>                 rgb24 += 2 * rgb24_stride;
> +               y += 2 * planar_stride;
>                 uv += planar_stride;
>         }
>  
>         /* Last row cannot be interpolated between 2 pixels, take the single value */
> -       if (i < fb->plane_height[1]) {
> -               for (j = 0; j < fb->plane_width[1]; j++) {
> -                       float uf = -0.148f * rgb24[j * 8 + 2] +
> -                                  -0.291f * rgb24[j * 8 + 1] +
> -                                   0.439f * rgb24[j * 8] + 128;
> -                       float vf =  0.439f * rgb24[j * 8 + 2] +
> -                                  -0.368f * rgb24[j * 8 + 1] +
> -                                  -0.071f * rgb24[j * 8] + 128;
> -
> -                       uv[j * 2] = (uint8_t)uf;
> -                       uv[j * 2 + 1] = (uint8_t)vf;
> +       if (fb->height & 1) {
> +               for (j = 0; j < fb->width; j++) {
> +                       struct igt_vec4 rgb;
> +                       struct igt_vec4 yuv;
> +
> +                       rgb.d[0] = rgb24[j * 4 + 2];
> +                       rgb.d[1] = rgb24[j * 4 + 1];
> +                       rgb.d[2] = rgb24[j * 4 + 0];
> +                       rgb.d[3] = 1.0f;
> +
> +                       yuv = igt_matrix_transform(&m, &rgb);
> +
> +                       y[j] = yuv.d[0];
> +                       uv[j * 2 + 0] = yuv.d[1];
> +                       uv[j * 2 + 1] = yuv.d[2];

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
@ 2018-05-17 22:41   ` Chris Wilson
  2018-05-18 13:00     ` Ville Syrjälä
  2018-05-18 19:57   ` [igt-dev] [PATCH i-g-t v5 " Ville Syrjala
  1 sibling, 1 reply; 27+ messages in thread
From: Chris Wilson @ 2018-05-17 22:41 UTC (permalink / raw)
  To: Ville Syrjala, igt-dev

Quoting Ville Syrjala (2018-05-17 20:51:46)
> +/* { Y0, U, Y1, V } */
> +static const unsigned char swizzle_yuyv[] = { 0, 1, 2, 3 };
> +static const unsigned char swizzle_yvyu[] = { 0, 3, 2, 1 };
> +static const unsigned char swizzle_uyvy[] = { 1, 0, 3, 2 };

> +static const unsigned char swizzle_vyuy[] = { 1, 2, 3, 0 };

This one stands out as backwards. Is it a vyuy_rev?
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [igt-dev] ✗ Fi.CI.IGT: failure for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (10 preceding siblings ...)
  2018-05-17 20:29 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] " Patchwork
@ 2018-05-17 23:38 ` Patchwork
  2018-05-18 20:30 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3) Patchwork
  2018-05-19  6:30 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
  13 siblings, 0 replies; 27+ messages in thread
From: Patchwork @ 2018-05-17 23:38 UTC (permalink / raw)
  To: Ville Syrjala; +Cc: igt-dev

== Series Details ==

Series: series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion
URL   : https://patchwork.freedesktop.org/series/43360/
State : failure

== Summary ==

= CI Bug Log - changes from IGT_4485_full -> IGTPW_1373_full =

== Summary - FAILURE ==

  Serious unknown changes coming with IGTPW_1373_full absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_1373_full, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/43360/revisions/1/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in IGTPW_1373_full:

  === IGT changes ===

    ==== Possible regressions ====

    igt@kms_ccs@pipe-a-crc-primary-rotation-180:
      shard-glk:          PASS -> CRASH +5
      shard-apl:          PASS -> CRASH +3

    igt@kms_ccs@pipe-b-crc-primary-basic:
      shard-kbl:          PASS -> CRASH +7

    igt@kms_plane_scaling@pipe-a-scaler-with-pixel-format:
      shard-glk:          PASS -> FAIL +3

    igt@kms_plane_scaling@pipe-c-scaler-with-pixel-format:
      shard-apl:          PASS -> FAIL +5

    
    ==== Warnings ====

    igt@gem_exec_schedule@deep-render:
      shard-kbl:          PASS -> SKIP +1

    igt@kms_ccs@pipe-a-crc-sprite-planes-basic:
      shard-apl:          FAIL (fdo#106510) -> CRASH +1

    igt@kms_cursor_crc@cursor-128x128-random:
      shard-snb:          SKIP -> PASS

    
== Known issues ==

  Here are the changes found in IGTPW_1373_full that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@gem_eio@throttle:
      shard-snb:          PASS -> DMESG-WARN (fdo#106523) +4
      shard-hsw:          PASS -> DMESG-WARN (fdo#106523) +4

    igt@gem_eio@unwedge-stress:
      shard-glk:          PASS -> DMESG-WARN (fdo#106523) +5
      shard-kbl:          PASS -> DMESG-WARN (fdo#106523) +1

    igt@gem_eio@wait-wedge-10ms:
      shard-apl:          PASS -> DMESG-WARN (fdo#106523) +6

    igt@kms_flip@2x-flip-vs-expired-vblank:
      shard-glk:          PASS -> FAIL (fdo#102887)

    igt@kms_flip@plain-flip-fb-recreate-interruptible:
      shard-glk:          PASS -> FAIL (fdo#100368) +1

    igt@kms_flip@plain-flip-ts-check:
      shard-hsw:          PASS -> FAIL (fdo#100368)

    igt@kms_flip_tiling@flip-y-tiled:
      shard-glk:          PASS -> FAIL (fdo#104724)

    igt@kms_frontbuffer_tracking@fbc-2p-primscrn-shrfb-msflip-blt:
      shard-glk:          PASS -> FAIL (fdo#103167, fdo#104724)

    igt@kms_plane_multiple@atomic-pipe-a-tiling-x:
      shard-snb:          PASS -> FAIL (fdo#103166, fdo#104724)

    igt@kms_plane_scaling@pipe-b-scaler-with-pixel-format:
      shard-kbl:          PASS -> FAIL (fdo#106026) +5

    
    ==== Possible fixes ====

    igt@gem_ctx_isolation@vecs0-s3:
      shard-kbl:          INCOMPLETE (fdo#103665) -> PASS +1

    igt@gem_eio@hibernate:
      shard-hsw:          DMESG-WARN (fdo#106523) -> PASS +5

    igt@gem_eio@in-flight-contexts-10ms:
      shard-snb:          DMESG-WARN (fdo#106523) -> PASS +5

    igt@gem_eio@in-flight-internal-immediate:
      shard-glk:          DMESG-WARN (fdo#106523) -> PASS +5

    igt@gem_eio@in-flight-suspend:
      shard-kbl:          DMESG-WARN (fdo#106523) -> PASS +3
      shard-apl:          DMESG-WARN (fdo#106523) -> PASS +6

    igt@kms_flip@flip-vs-expired-vblank-interruptible:
      shard-glk:          FAIL (fdo#105707) -> PASS +1

    igt@kms_flip_tiling@flip-to-x-tiled:
      shard-glk:          FAIL (fdo#104724) -> PASS

    igt@kms_flip_tiling@flip-to-y-tiled:
      shard-glk:          FAIL (fdo#103822, fdo#104724) -> PASS

    igt@perf_pmu@idle-vcs0:
      shard-glk:          INCOMPLETE (k.org#198133, fdo#103359) -> PASS

    
  fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
  fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
  fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
  fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
  fdo#103359 https://bugs.freedesktop.org/show_bug.cgi?id=103359
  fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
  fdo#103822 https://bugs.freedesktop.org/show_bug.cgi?id=103822
  fdo#104724 https://bugs.freedesktop.org/show_bug.cgi?id=104724
  fdo#105707 https://bugs.freedesktop.org/show_bug.cgi?id=105707
  fdo#106026 https://bugs.freedesktop.org/show_bug.cgi?id=106026
  fdo#106510 https://bugs.freedesktop.org/show_bug.cgi?id=106510
  fdo#106523 https://bugs.freedesktop.org/show_bug.cgi?id=106523
  k.org#198133 https://bugzilla.kernel.org/show_bug.cgi?id=198133


== Participating hosts (5 -> 5) ==

  No changes in participating hosts


== Build changes ==

    * IGT: IGT_4485 -> IGTPW_1373
    * Linux: CI_DRM_4191 -> CI_DRM_4193
    * Piglit: piglit_4485 -> piglit_4487

  CI_DRM_4191: 70daebf1a83c2ed6eff118d2a2806086c0c89027 @ git://anongit.freedesktop.org/gfx-ci/linux
  CI_DRM_4193: 9322e3903ce6c89bde0c24877fe730b808427caf @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1373: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1373/
  IGT_4485: eccae1360d6d01e73c6af2bd97122cef708207ef @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  piglit_4485: 62ef6b0db8967e7021fd3e0b57d03ff164b984fe @ git://anongit.freedesktop.org/piglit
  piglit_4487: 6ab75f7eb5e1dccbb773e1739beeb2d7cbd6ad0d @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1373/shards.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion
  2018-05-17 21:49   ` Chris Wilson
@ 2018-05-18 12:41     ` Ville Syrjälä
  0 siblings, 0 replies; 27+ messages in thread
From: Ville Syrjälä @ 2018-05-18 12:41 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

On Thu, May 17, 2018 at 10:49:32PM +0100, Chris Wilson wrote:
> Quoting Ville Syrjala (2018-05-17 20:51:45)
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > Probably horribly inefficient (not that the original code tried to be
> > particularly efficient), but at least this is now pretty generic so
> > it'll be super easy to add other color encodings and whatnot.
> > 
> > v2: Rebase
> > v3: Deal with the new color_encoding/range enums
> > 
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  lib/igt_fb.c | 134 +++++++++++++++++++++++++++++------------------------------
> >  1 file changed, 65 insertions(+), 69 deletions(-)
> > 
> > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > index af8ba70b0a2a..8aea5b52c8a9 100644
> > --- a/lib/igt_fb.c
> > +++ b/lib/igt_fb.c
> > @@ -31,8 +31,10 @@
> >  
> >  #include "drmtest.h"
> >  #include "igt_aux.h"
> > +#include "igt_color_encoding.h"
> >  #include "igt_fb.h"
> >  #include "igt_kms.h"
> > +#include "igt_matrix.h"
> >  #include "igt_x86.h"
> >  #include "ioctl_wrappers.h"
> >  #include "intel_batchbuffer.h"
> > @@ -1377,6 +1379,8 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
> >         uint8_t *rgb24 = blit->rgb24.map;
> >         unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
> >         uint8_t *buf = malloc(blit->linear.size);
> > +       struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
> > +                                                   IGT_COLOR_YCBCR_LIMITED_RANGE);
> >  
> >         /*
> >          * Reading from the BO is awfully slow because of lack of read caching,
> > @@ -1387,30 +1391,29 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
> >         y = &buf[blit->linear.offsets[0]];
> >         uv = &buf[blit->linear.offsets[1]];
> >  
> > -       /* Convert from limited color range BT.601 */
> >         for (i = 0; i < fb->height / 2; i++) {
> >                 for (j = 0; j < fb->width; j++) {
> > -                       float r_, g_, b_, y0, y1, cb, cr;
> >                         /* Convert 1x2 pixel blocks */
> > +                       struct igt_vec4 yuv0, yuv1;
> > +                       struct igt_vec4 rgb0, rgb1;
> >  
> > -                       y0 = 1.164f * (y[j] - 16.f);
> > -                       y1 = 1.164f * (y[j + planar_stride] - 16.f);
> > +                       yuv0.d[0] = y[j];
> > +                       yuv1.d[0] = y[j + planar_stride];
> > +                       yuv0.d[1] = yuv1.d[1] = uv[j & ~1];
> > +                       yuv0.d[2] = yuv1.d[2] = uv[j | 1];
> > +                       yuv0.d[3] = yuv1.d[3] = 1.0f;
> >  
> > -                       cb = uv[j & ~1] - 128.f;
> > -                       cr = uv[j | 1] - 128.f;
> > +                       rgb0 = igt_matrix_transform(&m, &yuv0);
> > +                       rgb1 = igt_matrix_transform(&m, &yuv1);
> 
> Ok.
> 
> > -                       r_ =  0.000f * cb +  1.596f * cr;
> > -                       g_ = -0.392f * cb + -0.813f * cr;
> > -                       b_ =  2.017f * cb +  0.000f * cr;
> > +                       rgb24[j * 4 + 2] = clamprgb(rgb0.d[0]);
> > +                       rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(rgb1.d[0]);
> >  
> > -                       rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> > -                       rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
> > +                       rgb24[j * 4 + 1] = clamprgb(rgb0.d[1]);
> > +                       rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(rgb1.d[1]);
> >  
> > -                       rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> > -                       rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(y1 + g_);
> > -
> > -                       rgb24[j * 4] = clamprgb(y0 + b_);
> > -                       rgb24[j * 4 + rgb24_stride] = clamprgb(y1 + b_);
> > +                       rgb24[j * 4 + 0] = clamprgb(rgb0.d[2]);
> > +                       rgb24[j * 4 + 0 + rgb24_stride] = clamprgb(rgb1.d[2]);
> 
> Ok.
> 
> >                 }
> >  
> >                 rgb24 += 2 * rgb24_stride;
> > @@ -1421,20 +1424,20 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
> >         if (fb->height & 1) {
> >                 /* Convert last row */
> >                 for (j = 0; j < fb->width; j++) {
> > -                       float r_, g_, b_, y0, cb, cr;
> >                         /* Convert single pixel */
> > +                       struct igt_vec4 yuv;
> > +                       struct igt_vec4 rgb;
> >  
> > -                       cb = uv[j & ~1] - 128.f;
> > -                       cr = uv[j | 1] - 128.f;
> > +                       yuv.d[0] = y[j];
> > +                       yuv.d[1] = uv[j & ~1];
> > +                       yuv.d[2] = uv[j | 1];
> > +                       yuv.d[3] = 1.0f;
> >  
> > -                       y0 = 1.164f * (y[j] - 16.f);
> > -                       r_ =  0.000f * cb +  1.596f * cr;
> > -                       g_ = -0.392f * cb + -0.813f * cr;
> > -                       b_ =  2.017f * cb +  0.000f * cr;
> > +                       rgb = igt_matrix_transform(&m, &yuv);
> >  
> > -                       rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> > -                       rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> > -                       rgb24[j * 4] = clamprgb(y0 + b_);
> > +                       rgb24[j * 4 + 2] = clamprgb(rgb.d[0]);
> > +                       rgb24[j * 4 + 1] = clamprgb(rgb.d[1]);
> > +                       rgb24[j * 4] = clamprgb(rgb.d[2]);
> 
>                           rgb24[j * 4 + 2] = clamprgb(rgb.d[0]);
>                           rgb24[j * 4 + 1] = clamprgb(rgb.d[1]);
>                           rgb24[j * 4 + 0] = clamprgb(rgb.d[2]);
> ?

Sure. Looks less messy that way.

> 
> >                 }
> >         }
> >  
> > @@ -1449,65 +1452,58 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
> >         const uint8_t *rgb24 = blit->rgb24.map;
> >         unsigned rgb24_stride = blit->rgb24.stride;
> >         unsigned planar_stride = blit->linear.stride;
> > +       struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
> > +                                                   IGT_COLOR_YCBCR_LIMITED_RANGE);
> >  
> >         igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
> >                      "Conversion not implemented for !NV12 planar formats\n");
> >  
> > -       for (i = 0; i < fb->plane_height[0]; i++) {
> > -               /* Use limited color range BT.601 */
> > +       for (i = 0; i < fb->height / 2; i++) {
> > +               for (j = 0; j < fb->width; j++) {
> > +                       struct igt_vec4 rgb0, rgb1;
> > +                       struct igt_vec4 yuv0, yuv1;
> >  
> > -               for (j = 0; j < fb->plane_width[0]; j++) {
> > -                       float yf = 0.257f * rgb24[j * 4 + 2] +
> > -                                  0.504f * rgb24[j * 4 + 1] +
> > -                                  0.098f * rgb24[j * 4] + 16;
> > +                       rgb0.d[0] = rgb24[j * 4 + 2];
> > +                       rgb0.d[1] = rgb24[j * 4 + 1];
> > +                       rgb0.d[2] = rgb24[j * 4 + 0];
> > +                       rgb0.d[3] = 1.0f;
> >  
> > -                       y[j] = (uint8_t)yf;
> > -               }
> > +                       rgb1.d[0] = rgb24[j * 4 + 2 + rgb24_stride];
> > +                       rgb1.d[1] = rgb24[j * 4 + 1 + rgb24_stride];
> > +                       rgb1.d[2] = rgb24[j * 4 + 0 + rgb24_stride];
> > +                       rgb1.d[3] = 1.0f;
> >  
> > -               rgb24 += rgb24_stride;
> > -               y += planar_stride;
> > -       }
> > +                       yuv0 = igt_matrix_transform(&m, &rgb0);
> > +                       yuv1 = igt_matrix_transform(&m, &rgb1);
> >  
> > -       rgb24 = blit->rgb24.map;
> > +                       y[j] = yuv0.d[0];
> > +                       y[j + planar_stride] = yuv1.d[0];
> >  
> > -       for (i = 0; i < fb->height / 2; i++) {
> > -               for (j = 0; j < fb->plane_width[1]; j++) {
> > -                       /*
> > -                        * Pixel center for Cb'Cr' is between the left top and
> > -                        * bottom pixel in a 2x2 block, so take the average.
> > -                        */
> > -                       float uf = -0.148f/2 * rgb24[j * 8 + 2] +
> > -                                  -0.148f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
> > -                                  -0.291f/2 * rgb24[j * 8 + 1] +
> > -                                  -0.291f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
> > -                                   0.439f/2 * rgb24[j * 8] +
> > -                                   0.439f/2 * rgb24[j * 8 + rgb24_stride] + 128;
> > -                       float vf =  0.439f/2 * rgb24[j * 8 + 2] +
> > -                                   0.439f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
> > -                                  -0.368f/2 * rgb24[j * 8 + 1] +
> > -                                  -0.368f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
> > -                                  -0.071f/2 * rgb24[j * 8] +
> > -                                  -0.071f/2 * rgb24[j * 8 + rgb24_stride] + 128;
> > -                       uv[j * 2] = (uint8_t)uf;
> > -                       uv[j * 2 + 1] = (uint8_t)vf;
> > +                       uv[j * 2 + 0] = (yuv0.d[1] + yuv1.d[1]) / 2.0f;
> > +                       uv[j * 2 + 1] = (yuv0.d[2] + yuv1.d[2]) / 2.0f;
> 
> Keep the comment about averaging tl+br. Why only 2 points btw?

Lazy I guess. Hmm. Somehow this doesn't even look right to me now. I
think I'll have to actually figure out what I was doing here, and test
it on actual hardware.

> 
> >                 }
> >  
> >                 rgb24 += 2 * rgb24_stride;
> > +               y += 2 * planar_stride;
> >                 uv += planar_stride;
> >         }
> >  
> >         /* Last row cannot be interpolated between 2 pixels, take the single value */
> > -       if (i < fb->plane_height[1]) {
> > -               for (j = 0; j < fb->plane_width[1]; j++) {
> > -                       float uf = -0.148f * rgb24[j * 8 + 2] +
> > -                                  -0.291f * rgb24[j * 8 + 1] +
> > -                                   0.439f * rgb24[j * 8] + 128;
> > -                       float vf =  0.439f * rgb24[j * 8 + 2] +
> > -                                  -0.368f * rgb24[j * 8 + 1] +
> > -                                  -0.071f * rgb24[j * 8] + 128;
> > -
> > -                       uv[j * 2] = (uint8_t)uf;
> > -                       uv[j * 2 + 1] = (uint8_t)vf;
> > +       if (fb->height & 1) {
> > +               for (j = 0; j < fb->width; j++) {
> > +                       struct igt_vec4 rgb;
> > +                       struct igt_vec4 yuv;
> > +
> > +                       rgb.d[0] = rgb24[j * 4 + 2];
> > +                       rgb.d[1] = rgb24[j * 4 + 1];
> > +                       rgb.d[2] = rgb24[j * 4 + 0];
> > +                       rgb.d[3] = 1.0f;
> > +
> > +                       yuv = igt_matrix_transform(&m, &rgb);
> > +
> > +                       y[j] = yuv.d[0];
> > +                       uv[j * 2 + 0] = yuv.d[1];
> > +                       uv[j * 2 + 1] = yuv.d[2];
> 
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> -Chris

-- 
Ville Syrjälä
Intel
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc
  2018-05-17 20:13   ` Chris Wilson
@ 2018-05-18 12:42     ` Ville Syrjälä
  0 siblings, 0 replies; 27+ messages in thread
From: Ville Syrjälä @ 2018-05-18 12:42 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

On Thu, May 17, 2018 at 09:13:06PM +0100, Chris Wilson wrote:
> Quoting Ville Syrjala (2018-05-17 20:51:42)
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > Always populate the plane_bpp[] stuff, and use named initializers so
> > that we can actually see what's being set to what.
> > 
> > v2: Fix depth for xrgb8888
> > 
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> 
> > ---
> >  lib/igt_fb.c | 66 +++++++++++++++++++++++++++++++++---------------------------
> >  1 file changed, 36 insertions(+), 30 deletions(-)
> > 
> > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > index 5cf2cd7d9e90..af8ba70b0a2a 100644
> > --- a/lib/igt_fb.c
> > +++ b/lib/igt_fb.c
> > @@ -57,26 +57,35 @@
> >   */
> >  
> >  /* drm fourcc/cairo format maps */
> > -#define DF(did, cid, ...)      \
> > -       { DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
> >  static struct format_desc_struct {
> > +       const char *name;
> >         uint32_t drm_id;
> >         cairo_format_t cairo_id;
> > -       const char *name;
> > -       int bpp;
> >         int depth;
> > -       int planes;
> > +       int num_planes;
> >         int plane_bpp[4];
> >  } format_desc[] = {
> > -       DF(RGB565,      RGB16_565,      16, 16),
> > -       //DF(RGB888,    INVALID,        24, 24),
> > -       DF(XRGB8888,    RGB24,          32, 24),
> > -       DF(XRGB2101010, RGB30,          32, 30),
> > -       DF(ARGB8888,    ARGB32,         32, 32),
> > -       DF(NV12,        RGB24,          32, -1, 2, {8, 16}),
> > +       { .name = "RGB565", .depth = 16, .drm_id = DRM_FORMAT_RGB565,
> > +         .cairo_id = CAIRO_FORMAT_RGB16_565,
> > +         .num_planes = 1, .plane_bpp = { 16, },
> > +       },
> 
> There's no enum to suggest
> 	[MY_FORMAT_DESC_A] = {
> 		.name = "XRGB8888", .depth = 24, .drm_id = DRM_FORMAT_XRGB8888,
> 		.cairo_id = CAIRO_FORMAT_RGB24,
> 		.num_planes = 1, .plane_bpp = { 32, },
> 	}
> ?

I don't think we have anything like that atm.

-- 
Ville Syrjälä
Intel
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers
  2018-05-17 22:41   ` Chris Wilson
@ 2018-05-18 13:00     ` Ville Syrjälä
  2018-05-18 13:17       ` Chris Wilson
  0 siblings, 1 reply; 27+ messages in thread
From: Ville Syrjälä @ 2018-05-18 13:00 UTC (permalink / raw)
  To: Chris Wilson; +Cc: igt-dev

On Thu, May 17, 2018 at 11:41:56PM +0100, Chris Wilson wrote:
> Quoting Ville Syrjala (2018-05-17 20:51:46)
> > +/* { Y0, U, Y1, V } */
> > +static const unsigned char swizzle_yuyv[] = { 0, 1, 2, 3 };
> > +static const unsigned char swizzle_yvyu[] = { 0, 3, 2, 1 };
> > +static const unsigned char swizzle_uyvy[] = { 1, 0, 3, 2 };
> 
> > +static const unsigned char swizzle_vyuy[] = { 1, 2, 3, 0 };
> 
> This one stands out as backwards. Is it a vyuy_rev?

Hmm. I think it's correct.

swizzle[] tells us in which offset in the macropixel we find the
component. The index determines which component we want.

swizzle[0] = offset of Y0
swizzle[1] = offset of U
swizzle[2] = offset of Y1
swizzle[3] = offset of V

so for the vyuy case the macropixel layout will be:

byte: 0          1          2          3
      swizzle[3] swizzel[0] swizzle[1] swizzle[2]
      V          Y0         U          Y1

Seems to make some sense, at least to me.

-- 
Ville Syrjälä
Intel
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers
  2018-05-18 13:00     ` Ville Syrjälä
@ 2018-05-18 13:17       ` Chris Wilson
  0 siblings, 0 replies; 27+ messages in thread
From: Chris Wilson @ 2018-05-18 13:17 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: igt-dev

Quoting Ville Syrjälä (2018-05-18 14:00:06)
> On Thu, May 17, 2018 at 11:41:56PM +0100, Chris Wilson wrote:
> > Quoting Ville Syrjala (2018-05-17 20:51:46)
> > > +/* { Y0, U, Y1, V } */
> > > +static const unsigned char swizzle_yuyv[] = { 0, 1, 2, 3 };
> > > +static const unsigned char swizzle_yvyu[] = { 0, 3, 2, 1 };
> > > +static const unsigned char swizzle_uyvy[] = { 1, 0, 3, 2 };
> > 
> > > +static const unsigned char swizzle_vyuy[] = { 1, 2, 3, 0 };
> > 
> > This one stands out as backwards. Is it a vyuy_rev?
> 
> Hmm. I think it's correct.
> 
> swizzle[] tells us in which offset in the macropixel we find the
> component. The index determines which component we want.
> 
> swizzle[0] = offset of Y0
> swizzle[1] = offset of U
> swizzle[2] = offset of Y1
> swizzle[3] = offset of V

So I was reading it as the inverse mapping,

swizzle_vyuy:
	byte 0 = v, read offset 1
	byte 1 = y, read offset 2
	byte 2 = u, read offset 3
	byte 3 = y, read offset 0

but the incoming offsets are yuyv, so I read { 1, 2, 3, 0 } as uyvy.

From thinking that
	swizzle_rgba = { 0, 1, 2, 3 }
	swizzle_rrrr = { 0, 0, 0, 0 }
-Chris
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t v4 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
  2018-05-17 21:49   ` Chris Wilson
@ 2018-05-18 19:56   ` Ville Syrjala
  1 sibling, 0 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-18 19:56 UTC (permalink / raw)
  To: igt-dev

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

Probably horribly inefficient (not that the original code tried to be
particularly efficient), but at least this is now pretty generic so
it'll be super easy to add other color encodings and whatnot.

v2: Rebase
v3: Deal with the new color_encoding/range enums
v4: Fix the code to actually work, and do things in 2x2 blocks
    Keep the chroma siting comment and pimp it up a bit

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 228 +++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 159 insertions(+), 69 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index af8ba70b0a2a..5f37974f3904 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -31,8 +31,10 @@
 
 #include "drmtest.h"
 #include "igt_aux.h"
+#include "igt_color_encoding.h"
 #include "igt_fb.h"
 #include "igt_kms.h"
+#include "igt_matrix.h"
 #include "igt_x86.h"
 #include "ioctl_wrappers.h"
 #include "intel_batchbuffer.h"
@@ -1370,6 +1372,21 @@ static uint8_t clamprgb(float val)
 	return clamp(val, 0.0f, 255.0f);
 }
 
+static void read_rgb(struct igt_vec4 *rgb, const uint8_t *rgb24)
+{
+	rgb->d[0] = rgb24[2];
+	rgb->d[1] = rgb24[1];
+	rgb->d[2] = rgb24[0];
+	rgb->d[3] = 1.0f;
+}
+
+static void write_rgb(uint8_t *rgb24, const struct igt_vec4 *rgb)
+{
+	rgb24[2] = clamprgb(rgb->d[0]);
+	rgb24[1] = clamprgb(rgb->d[1]);
+	rgb24[0] = clamprgb(rgb->d[2]);
+}
+
 static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
 {
 	int i, j;
@@ -1377,6 +1394,8 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
 	uint8_t *buf = malloc(blit->linear.size);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
 
 	/*
 	 * Reading from the BO is awfully slow because of lack of read caching,
@@ -1387,30 +1406,49 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 	y = &buf[blit->linear.offsets[0]];
 	uv = &buf[blit->linear.offsets[1]];
 
-	/* Convert from limited color range BT.601 */
 	for (i = 0; i < fb->height / 2; i++) {
-		for (j = 0; j < fb->width; j++) {
-			float r_, g_, b_, y0, y1, cb, cr;
-			/* Convert 1x2 pixel blocks */
-
-			y0 = 1.164f * (y[j] - 16.f);
-			y1 = 1.164f * (y[j + planar_stride] - 16.f);
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x2 pixel blocks */
+			struct igt_vec4 yuv[4];
+			struct igt_vec4 rgb[4];
+
+			yuv[0].d[0] = y[j * 2 + 0];
+			yuv[1].d[0] = y[j * 2 + 1];
+			yuv[2].d[0] = y[j * 2 + 0 + planar_stride];
+			yuv[3].d[0] = y[j * 2 + 1 + planar_stride];
+
+			yuv[0].d[1] = yuv[1].d[1] = yuv[2].d[1] = yuv[3].d[1] = uv[j * 2 + 0];
+			yuv[0].d[2] = yuv[1].d[2] = yuv[2].d[2] = yuv[3].d[2] = uv[j * 2 + 1];
+			yuv[0].d[3] = yuv[1].d[3] = yuv[2].d[3] = yuv[3].d[3] = 1.0f;
+
+			rgb[0] = igt_matrix_transform(&m, &yuv[0]);
+			rgb[1] = igt_matrix_transform(&m, &yuv[1]);
+			rgb[2] = igt_matrix_transform(&m, &yuv[2]);
+			rgb[3] = igt_matrix_transform(&m, &yuv[3]);
+
+			write_rgb(&rgb24[j * 8 + 0], &rgb[0]);
+			write_rgb(&rgb24[j * 8 + 4], &rgb[1]);
+			write_rgb(&rgb24[j * 8 + 0 + rgb24_stride], &rgb[2]);
+			write_rgb(&rgb24[j * 8 + 4 + rgb24_stride], &rgb[3]);
+		}
 
-			cb = uv[j & ~1] - 128.f;
-			cr = uv[j | 1] - 128.f;
+		if (fb->width & 1) {
+			/* Convert 1x2 pixel block */
+			struct igt_vec4 yuv[2];
+			struct igt_vec4 rgb[2];
 
-			r_ =  0.000f * cb +  1.596f * cr;
-			g_ = -0.392f * cb + -0.813f * cr;
-			b_ =  2.017f * cb +  0.000f * cr;
+			yuv[0].d[0] = y[j * 2 + 0];
+			yuv[1].d[0] = y[j * 2 + 0 + planar_stride];
 
-			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
-			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
+			yuv[0].d[1] = yuv[1].d[1] = uv[j * 2 + 0];
+			yuv[0].d[2] = yuv[1].d[2] = uv[j * 2 + 1];
+			yuv[0].d[3] = yuv[1].d[3] = 1.0f;
 
-			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
-			rgb24[j * 4 + 1 + rgb24_stride] = clamprgb(y1 + g_);
+			rgb[0] = igt_matrix_transform(&m, &yuv[0]);
+			rgb[1] = igt_matrix_transform(&m, &yuv[1]);
 
-			rgb24[j * 4] = clamprgb(y0 + b_);
-			rgb24[j * 4 + rgb24_stride] = clamprgb(y1 + b_);
+			write_rgb(&rgb24[j * 8 + 0], &rgb[0]);
+			write_rgb(&rgb24[j * 8 + 0 + rgb24_stride], &rgb[1]);
 		}
 
 		rgb24 += 2 * rgb24_stride;
@@ -1420,21 +1458,37 @@ static void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_uplo
 
 	if (fb->height & 1) {
 		/* Convert last row */
-		for (j = 0; j < fb->width; j++) {
-			float r_, g_, b_, y0, cb, cr;
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 yuv[2];
+			struct igt_vec4 rgb[2];
+
+			yuv[0].d[0] = y[j * 2 + 0];
+			yuv[1].d[0] = y[j * 2 + 1];
+			yuv[0].d[1] = yuv[1].d[1] = uv[j * 2 + 0];
+			yuv[0].d[2] = yuv[1].d[2] = uv[j * 2 + 1];
+			yuv[0].d[3] = yuv[1].d[3] = 1.0f;
+
+			rgb[0] = igt_matrix_transform(&m, &yuv[0]);
+			rgb[1] = igt_matrix_transform(&m, &yuv[1]);
+
+			write_rgb(&rgb24[j * 8 + 0], &rgb[0]);
+			write_rgb(&rgb24[j * 8 + 4], &rgb[0]);
+		}
+
+		if (fb->width & 1) {
 			/* Convert single pixel */
+			struct igt_vec4 yuv;
+			struct igt_vec4 rgb;
 
-			cb = uv[j & ~1] - 128.f;
-			cr = uv[j | 1] - 128.f;
+			yuv.d[0] = y[j * 2 + 0];
+			yuv.d[1] = uv[j * 2 + 0];
+			yuv.d[2] = uv[j * 2 + 1];
+			yuv.d[3] = 1.0f;
 
-			y0 = 1.164f * (y[j] - 16.f);
-			r_ =  0.000f * cb +  1.596f * cr;
-			g_ = -0.392f * cb + -0.813f * cr;
-			b_ =  2.017f * cb +  0.000f * cr;
+			rgb = igt_matrix_transform(&m, &yuv);
 
-			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
-			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
-			rgb24[j * 4] = clamprgb(y0 + b_);
+			write_rgb(&rgb24[j * 8 + 0], &rgb);
 		}
 	}
 
@@ -1449,65 +1503,101 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
 	const uint8_t *rgb24 = blit->rgb24.map;
 	unsigned rgb24_stride = blit->rgb24.stride;
 	unsigned planar_stride = blit->linear.stride;
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
 
 	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
 		     "Conversion not implemented for !NV12 planar formats\n");
 
-	for (i = 0; i < fb->plane_height[0]; i++) {
-		/* Use limited color range BT.601 */
-
-		for (j = 0; j < fb->plane_width[0]; j++) {
-			float yf = 0.257f * rgb24[j * 4 + 2] +
-				   0.504f * rgb24[j * 4 + 1] +
-				   0.098f * rgb24[j * 4] + 16;
+	for (i = 0; i < fb->height / 2; i++) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x2 pixel blocks */
+			struct igt_vec4 rgb[4];
+			struct igt_vec4 yuv[4];
+
+			read_rgb(&rgb[0], &rgb24[j * 8 + 0]);
+			read_rgb(&rgb[1], &rgb24[j * 8 + 4]);
+			read_rgb(&rgb[2], &rgb24[j * 8 + 0 + rgb24_stride]);
+			read_rgb(&rgb[3], &rgb24[j * 8 + 4 + rgb24_stride]);
+
+			yuv[0] = igt_matrix_transform(&m, &rgb[0]);
+			yuv[1] = igt_matrix_transform(&m, &rgb[1]);
+			yuv[2] = igt_matrix_transform(&m, &rgb[2]);
+			yuv[3] = igt_matrix_transform(&m, &rgb[3]);
+
+			y[j * 2 + 0] = yuv[0].d[0];
+			y[j * 2 + 1] = yuv[1].d[0];
+			y[j * 2 + 0 + planar_stride] = yuv[2].d[0];
+			y[j * 2 + 1 + planar_stride] = yuv[3].d[0];
 
-			y[j] = (uint8_t)yf;
+			/*
+			 * We assume the MPEG2 chroma siting convention, where
+			 * pixel center for Cb'Cr' is between the left top and
+			 * bottom pixel in a 2x2 block, so take the average.
+			 */
+			uv[j * 2 + 0] = (yuv[0].d[1] + yuv[2].d[1]) / 2.0f;
+			uv[j * 2 + 1] = (yuv[0].d[2] + yuv[2].d[2]) / 2.0f;
 		}
 
-		rgb24 += rgb24_stride;
-		y += planar_stride;
-	}
+		if (fb->width & 1) {
+			/* Convert 1x2 pixel block */
+			struct igt_vec4 rgb[2];
+			struct igt_vec4 yuv[2];
 
-	rgb24 = blit->rgb24.map;
+			read_rgb(&rgb[0], &rgb24[j * 8 + 0]);
+			read_rgb(&rgb[2], &rgb24[j * 8 + 0 + rgb24_stride]);
+
+			yuv[0] = igt_matrix_transform(&m, &rgb[0]);
+			yuv[1] = igt_matrix_transform(&m, &rgb[1]);
+
+			y[j * 2 + 0] = yuv[0].d[0];
+			y[j * 2 + 0 + planar_stride] = yuv[1].d[0];
 
-	for (i = 0; i < fb->height / 2; i++) {
-		for (j = 0; j < fb->plane_width[1]; j++) {
 			/*
-			 * Pixel center for Cb'Cr' is between the left top and
+			 * We assume the MPEG2 chroma siting convention, where
+			 * pixel center for Cb'Cr' is between the left top and
 			 * bottom pixel in a 2x2 block, so take the average.
 			 */
-			float uf = -0.148f/2 * rgb24[j * 8 + 2] +
-				   -0.148f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
-				   -0.291f/2 * rgb24[j * 8 + 1] +
-				   -0.291f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
-				    0.439f/2 * rgb24[j * 8] +
-				    0.439f/2 * rgb24[j * 8 + rgb24_stride] + 128;
-			float vf =  0.439f/2 * rgb24[j * 8 + 2] +
-				    0.439f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
-				   -0.368f/2 * rgb24[j * 8 + 1] +
-				   -0.368f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
-				   -0.071f/2 * rgb24[j * 8] +
-				   -0.071f/2 * rgb24[j * 8 + rgb24_stride] + 128;
-			uv[j * 2] = (uint8_t)uf;
-			uv[j * 2 + 1] = (uint8_t)vf;
+			uv[j * 2 + 0] = (yuv[0].d[1] + yuv[1].d[1]) / 2.0f;
+			uv[j * 2 + 1] = (yuv[0].d[2] + yuv[1].d[2]) / 2.0f;
 		}
 
 		rgb24 += 2 * rgb24_stride;
+		y += 2 * planar_stride;
 		uv += planar_stride;
 	}
 
 	/* Last row cannot be interpolated between 2 pixels, take the single value */
-	if (i < fb->plane_height[1]) {
-		for (j = 0; j < fb->plane_width[1]; j++) {
-			float uf = -0.148f * rgb24[j * 8 + 2] +
-				   -0.291f * rgb24[j * 8 + 1] +
-				    0.439f * rgb24[j * 8] + 128;
-			float vf =  0.439f * rgb24[j * 8 + 2] +
-				   -0.368f * rgb24[j * 8 + 1] +
-				   -0.071f * rgb24[j * 8] + 128;
-
-			uv[j * 2] = (uint8_t)uf;
-			uv[j * 2 + 1] = (uint8_t)vf;
+	if (fb->height & 1) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 rgb[2];
+			struct igt_vec4 yuv[2];
+
+			read_rgb(&rgb[0], &rgb24[j * 8 + 0]);
+			read_rgb(&rgb[1], &rgb24[j * 8 + 4]);
+
+			yuv[0] = igt_matrix_transform(&m, &rgb[0]);
+			yuv[1] = igt_matrix_transform(&m, &rgb[1]);
+
+			y[j * 2 + 0] = yuv[0].d[0];
+			y[j * 2 + 1] = yuv[1].d[0];
+			uv[j * 2 + 0] = yuv[0].d[1];
+			uv[j * 2 + 1] = yuv[0].d[2];
+		}
+
+		if (fb->width & 1) {
+			/* Convert single pixel */
+			struct igt_vec4 rgb;
+			struct igt_vec4 yuv;
+
+			read_rgb(&rgb, &rgb24[j * 8 + 0]);
+
+			yuv = igt_matrix_transform(&m, &rgb);
+
+			y[j * 2 + 0] = yuv.d[0];
+			uv[j * 2 + 0] = yuv.d[1];
+			uv[j * 2 + 1] = yuv.d[2];
 		}
 	}
 }
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] [PATCH i-g-t v5 08/10] lib: Add support for rendering into packed YCbCr framebuffers
  2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
  2018-05-17 22:41   ` Chris Wilson
@ 2018-05-18 19:57   ` Ville Syrjala
  1 sibling, 0 replies; 27+ messages in thread
From: Ville Syrjala @ 2018-05-18 19:57 UTC (permalink / raw)
  To: igt-dev

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

Reuse the __convert() cairo stuff to support packed YCbCr framebuffers.

v2: Allow odd fb width since some tests want it
v3: Use igt_memcpy_from_wc()
v4: Rebase due to color_encoding/range enums
v5: Follow the fixed nv12 code

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 180 insertions(+), 10 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 5f37974f3904..b7ddbe959128 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -87,6 +87,22 @@ static struct format_desc_struct {
 	  .cairo_id = CAIRO_FORMAT_RGB24,
 	  .num_planes = 2, .plane_bpp = { 8, 16, },
 	},
+	{ .name = "YUYV", .depth = -1, .drm_id = DRM_FORMAT_YUYV,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "YVYU", .depth = -1, .drm_id = DRM_FORMAT_YVYU,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "UYVY", .depth = -1, .drm_id = DRM_FORMAT_UYVY,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "VYUY", .depth = -1, .drm_id = DRM_FORMAT_VYUY,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
 };
 #define for_each_format(f)	\
 	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
@@ -1602,16 +1618,159 @@ static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_uplo
 	}
 }
 
+/* { Y0, U, Y1, V } */
+static const unsigned char swizzle_yuyv[] = { 0, 1, 2, 3 };
+static const unsigned char swizzle_yvyu[] = { 0, 3, 2, 1 };
+static const unsigned char swizzle_uyvy[] = { 1, 0, 3, 2 };
+static const unsigned char swizzle_vyuy[] = { 1, 2, 3, 0 };
+
+static const unsigned char *yuyv_swizzle(uint32_t format)
+{
+	switch (format) {
+	default:
+	case DRM_FORMAT_YUYV:
+		return swizzle_yuyv;
+	case DRM_FORMAT_YVYU:
+		return swizzle_yvyu;
+	case DRM_FORMAT_UYVY:
+		return swizzle_uyvy;
+	case DRM_FORMAT_VYUY:
+		return swizzle_vyuy;
+	}
+}
+
+static void convert_yuyv_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit,
+				  const unsigned char swz[4])
+{
+	int i, j;
+	const uint8_t *yuyv;
+	uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride, yuyv_stride = blit->linear.stride;
+	uint8_t *buf = malloc(blit->linear.size);
+	struct igt_mat4 m = igt_ycbcr_to_rgb_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+
+	/*
+	 * Reading from the BO is awfully slow because of lack of read caching,
+	 * it's faster to copy the whole BO to a temporary buffer and convert
+	 * from there.
+	 */
+	igt_memcpy_from_wc(buf, blit->linear.map, blit->linear.size);
+	yuyv = buf;
+
+	for (i = 0; i < fb->height; i++) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 yuv[2];
+			struct igt_vec4 rgb[2];
+
+			yuv[0].d[0] = yuyv[j * 4 + swz[0]];
+			yuv[1].d[0] = yuyv[j * 4 + swz[2]];
+			yuv[0].d[1] = yuv[1].d[1] = yuyv[j * 4 + swz[1]];
+			yuv[0].d[2] = yuv[1].d[2] = yuyv[j * 4 + swz[3]];
+			yuv[0].d[3] = yuv[1].d[3] = 1.0f;
+
+			rgb[0] = igt_matrix_transform(&m, &yuv[0]);
+			rgb[1] = igt_matrix_transform(&m, &yuv[1]);
+
+			write_rgb(&rgb24[j * 8 + 0], &rgb[0]);
+			write_rgb(&rgb24[j * 8 + 4], &rgb[1]);
+		}
+
+		if (fb->width & 1) {
+			struct igt_vec4 yuv;
+			struct igt_vec4 rgb;
+
+			yuv.d[0] = yuyv[j * 4 + swz[0]];
+			yuv.d[1] = yuyv[j * 4 + swz[1]];
+			yuv.d[2] = yuyv[j * 4 + swz[3]];
+			yuv.d[3] = 1.0f;
+
+			rgb = igt_matrix_transform(&m, &yuv);
+
+			write_rgb(&rgb24[j * 8 + 0], &rgb);
+		}
+
+		rgb24 += rgb24_stride;
+		yuyv += yuyv_stride;
+	}
+
+	free(buf);
+}
+
+static void convert_rgb24_to_yuyv(struct igt_fb *fb, struct fb_convert_blit_upload *blit,
+				  const unsigned char swz[4])
+{
+	int i, j;
+	uint8_t *yuyv = blit->linear.map;
+	const uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride;
+	unsigned yuyv_stride = blit->linear.stride;
+	struct igt_mat4 m = igt_rgb_to_ycbcr_matrix(IGT_COLOR_YCBCR_BT601,
+						    IGT_COLOR_YCBCR_LIMITED_RANGE);
+
+	igt_assert_f(fb->drm_format == DRM_FORMAT_YUYV ||
+		     fb->drm_format == DRM_FORMAT_YVYU ||
+		     fb->drm_format == DRM_FORMAT_UYVY ||
+		     fb->drm_format == DRM_FORMAT_VYUY,
+		     "Conversion not implemented for !YUYV planar formats\n");
+
+	for (i = 0; i < fb->height; i++) {
+		for (j = 0; j < fb->width / 2; j++) {
+			/* Convert 2x1 pixel blocks */
+			struct igt_vec4 rgb[2];
+			struct igt_vec4 yuv[2];
+
+			read_rgb(&rgb[0], &rgb24[j * 8 + 0]);
+			read_rgb(&rgb[1], &rgb24[j * 8 + 4]);
+
+			yuv[0] = igt_matrix_transform(&m, &rgb[0]);
+			yuv[1] = igt_matrix_transform(&m, &rgb[1]);
+
+			yuyv[j * 4 + swz[0]] = yuv[0].d[0];
+			yuyv[j * 4 + swz[2]] = yuv[1].d[0];
+			yuyv[j * 4 + swz[1]] = (yuv[0].d[1] + yuv[1].d[1]) / 2.0f;
+			yuyv[j * 4 + swz[3]] = (yuv[0].d[2] + yuv[1].d[2]) / 2.0f;
+		}
+
+		if (fb->width & 1) {
+			struct igt_vec4 rgb;
+			struct igt_vec4 yuv;
+
+			read_rgb(&rgb, &rgb24[j * 8 + 0]);
+
+			yuv = igt_matrix_transform(&m, &rgb);
+
+			yuyv[j * 4 + swz[0]] = yuv.d[0];
+			yuyv[j * 4 + swz[1]] = yuv.d[1];
+			yuyv[j * 4 + swz[3]] = yuv.d[2];
+		}
+
+		rgb24 += rgb24_stride;
+		yuyv += yuyv_stride;
+	}
+}
+
 static void destroy_cairo_surface__convert(void *arg)
 {
 	struct fb_convert_blit_upload *blit = arg;
 	struct igt_fb *fb = blit->fb;
 
-	/* Convert back to planar! */
-	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
-		     "Conversion not implemented for !NV12 planar formats\n");
-
-	convert_rgb24_to_nv12(fb, blit);
+	/* Convert linear rgb back! */
+	switch(fb->drm_format) {
+	case DRM_FORMAT_NV12:
+		convert_rgb24_to_nv12(fb, blit);
+		break;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		convert_rgb24_to_yuyv(fb, blit, yuyv_swizzle(fb->drm_format));
+		break;
+	default:
+		igt_assert_f(false, "Conversion not implemented for formats 0x%x\n",
+			     fb->drm_format);
+	}
 
 	munmap(blit->rgb24.map, blit->rgb24.size);
 
@@ -1650,10 +1809,21 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
 		memcpy(blit->linear.offsets, fb->offsets, sizeof(fb->offsets));
 	}
 
-	/* Convert to linear! */
-	igt_assert_f(fb->drm_format == DRM_FORMAT_NV12,
-		     "Conversion not implemented for !NV12 planar formats\n");
-	convert_nv12_to_rgb24(fb, blit);
+	/* Convert to linear rgb! */
+	switch(fb->drm_format) {
+	case DRM_FORMAT_NV12:
+		convert_nv12_to_rgb24(fb, blit);
+		break;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_VYUY:
+		convert_yuyv_to_rgb24(fb, blit, yuyv_swizzle(fb->drm_format));
+		break;
+	default:
+		igt_assert_f(false, "Conversion not implemented for formats 0x%x\n",
+			     fb->drm_format);
+	}
 
 	fb->cairo_surface =
 		cairo_image_surface_create_for_data(blit->rgb24.map,
@@ -1680,7 +1850,7 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
 	if (fb->cairo_surface == NULL) {
-		if (fb->num_planes > 1)
+		if (is_yuv(fb->drm_format))
 			create_cairo_surface__convert(fd, fb);
 		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
-- 
2.16.1

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

^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3)
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (11 preceding siblings ...)
  2018-05-17 23:38 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
@ 2018-05-18 20:30 ` Patchwork
  2018-05-19  6:30 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
  13 siblings, 0 replies; 27+ messages in thread
From: Patchwork @ 2018-05-18 20:30 UTC (permalink / raw)
  To: Ville Syrjala; +Cc: igt-dev

== Series Details ==

Series: series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3)
URL   : https://patchwork.freedesktop.org/series/43360/
State : success

== Summary ==

= CI Bug Log - changes from CI_DRM_4193 -> IGTPW_1377 =

== Summary - WARNING ==

  Minor unknown changes coming with IGTPW_1377 need to be verified
  manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_1377, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/43360/revisions/3/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in IGTPW_1377:

  === IGT changes ===

    ==== Warnings ====

    igt@gem_exec_gttfill@basic:
      fi-pnv-d510:        SKIP -> PASS

    
== Known issues ==

  Here are the changes found in IGTPW_1377 that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@kms_flip@basic-flip-vs-dpms:
      fi-hsw-4770r:       PASS -> DMESG-WARN (fdo#105602)

    
    ==== Possible fixes ====

    igt@gem_mmap_gtt@basic-small-bo-tiledx:
      fi-gdg-551:         FAIL (fdo#102575) -> PASS

    igt@kms_pipe_crc_basic@nonblocking-crc-pipe-a-frame-sequence:
      fi-cfl-s3:          FAIL (fdo#103481) -> PASS +1

    igt@kms_pipe_crc_basic@suspend-read-crc-pipe-a:
      fi-cnl-psr:         DMESG-WARN (fdo#104951) -> PASS

    
  fdo#102575 https://bugs.freedesktop.org/show_bug.cgi?id=102575
  fdo#103481 https://bugs.freedesktop.org/show_bug.cgi?id=103481
  fdo#104951 https://bugs.freedesktop.org/show_bug.cgi?id=104951
  fdo#105602 https://bugs.freedesktop.org/show_bug.cgi?id=105602


== Participating hosts (41 -> 37) ==

  Additional (3): fi-kbl-guc fi-cfl-guc fi-snb-2520m 
  Missing    (7): fi-ilk-m540 fi-byt-j1900 fi-byt-squawks fi-bsw-cyan fi-ctg-p8600 fi-glk-j4005 fi-skl-6700hq 


== Build changes ==

    * IGT: IGT_4485 -> IGTPW_1377
    * Piglit: piglit_4485 -> piglit_4487

  CI_DRM_4193: 9322e3903ce6c89bde0c24877fe730b808427caf @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1377: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1377/
  IGT_4485: eccae1360d6d01e73c6af2bd97122cef708207ef @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  piglit_4485: 62ef6b0db8967e7021fd3e0b57d03ff164b984fe @ git://anongit.freedesktop.org/piglit
  piglit_4487: 6ab75f7eb5e1dccbb773e1739beeb2d7cbd6ad0d @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1377/issues.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

* [igt-dev] ✗ Fi.CI.IGT: failure for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3)
  2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
                   ` (12 preceding siblings ...)
  2018-05-18 20:30 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3) Patchwork
@ 2018-05-19  6:30 ` Patchwork
  13 siblings, 0 replies; 27+ messages in thread
From: Patchwork @ 2018-05-19  6:30 UTC (permalink / raw)
  To: Ville Syrjala; +Cc: igt-dev

== Series Details ==

Series: series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3)
URL   : https://patchwork.freedesktop.org/series/43360/
State : failure

== Summary ==

= CI Bug Log - changes from IGT_4485_full -> IGTPW_1377_full =

== Summary - FAILURE ==

  Serious unknown changes coming with IGTPW_1377_full absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in IGTPW_1377_full, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://patchwork.freedesktop.org/api/1.0/series/43360/revisions/3/mbox/

== Possible new issues ==

  Here are the unknown changes that may have been introduced in IGTPW_1377_full:

  === IGT changes ===

    ==== Possible regressions ====

    igt@kms_ccs@pipe-a-crc-primary-rotation-180:
      shard-glk:          PASS -> CRASH +5
      shard-apl:          PASS -> CRASH +3

    igt@kms_ccs@pipe-b-crc-primary-basic:
      shard-kbl:          PASS -> CRASH +7

    igt@kms_plane_scaling@pipe-a-scaler-with-pixel-format:
      shard-glk:          PASS -> FAIL +5

    igt@kms_plane_scaling@pipe-c-scaler-with-pixel-format:
      shard-apl:          PASS -> FAIL +5

    igt@kms_universal_plane@cursor-fb-leak-pipe-c:
      shard-kbl:          PASS -> FAIL

    
    ==== Warnings ====

    igt@gem_exec_schedule@deep-bsd2:
      shard-kbl:          SKIP -> PASS

    igt@gem_mocs_settings@mocs-rc6-bsd1:
      shard-kbl:          PASS -> SKIP

    igt@kms_ccs@pipe-a-crc-sprite-planes-basic:
      shard-apl:          FAIL (fdo#106510) -> CRASH +1

    igt@kms_cursor_crc@cursor-128x128-random:
      shard-snb:          SKIP -> PASS

    
== Known issues ==

  Here are the changes found in IGTPW_1377_full that come from known issues:

  === IGT changes ===

    ==== Issues hit ====

    igt@drv_selftest@live_gtt:
      shard-apl:          PASS -> INCOMPLETE (fdo#103927)

    igt@gem_ctx_isolation@vcs1-s3:
      shard-kbl:          PASS -> INCOMPLETE (fdo#103665)

    igt@gem_eio@execbuf:
      shard-glk:          PASS -> DMESG-WARN (fdo#106523) +5

    igt@gem_eio@in-flight-1us:
      shard-apl:          PASS -> DMESG-WARN (fdo#106523) +3

    igt@gem_eio@unwedge-stress:
      shard-snb:          PASS -> DMESG-WARN (fdo#106523) +4
      shard-kbl:          PASS -> DMESG-WARN (fdo#106523) +1

    igt@gem_eio@wait-wedge-1us:
      shard-hsw:          PASS -> DMESG-WARN (fdo#106523) +4

    igt@gem_ppgtt@blt-vs-render-ctxn:
      shard-kbl:          PASS -> INCOMPLETE (fdo#103665, fdo#106023)

    igt@kms_flip@2x-flip-vs-modeset:
      shard-hsw:          PASS -> DMESG-WARN (fdo#102614)

    igt@kms_flip@2x-plain-flip-ts-check-interruptible:
      shard-hsw:          PASS -> FAIL (fdo#100368)

    igt@kms_flip@blocking-wf_vblank:
      shard-hsw:          PASS -> FAIL (fdo#103928)

    igt@kms_flip@dpms-vs-vblank-race:
      shard-glk:          PASS -> FAIL (fdo#103060)

    igt@kms_flip_tiling@flip-y-tiled:
      shard-glk:          PASS -> FAIL (fdo#104724)

    igt@kms_frontbuffer_tracking@fbc-farfromfence:
      shard-kbl:          PASS -> DMESG-WARN (fdo#103558, fdo#105602) +9

    igt@kms_plane_scaling@pipe-b-scaler-with-pixel-format:
      shard-kbl:          PASS -> FAIL (fdo#106026) +5

    
    ==== Possible fixes ====

    igt@gem_ctx_isolation@vecs0-s3:
      shard-kbl:          INCOMPLETE (fdo#103665) -> PASS +1

    igt@gem_eio@hibernate:
      shard-hsw:          DMESG-WARN (fdo#106523) -> PASS +3

    igt@gem_eio@in-flight-contexts-10ms:
      shard-snb:          DMESG-WARN (fdo#106523) -> PASS +4

    igt@gem_eio@in-flight-immediate:
      shard-apl:          DMESG-WARN (fdo#106523) -> PASS +3

    igt@gem_eio@in-flight-internal-immediate:
      shard-glk:          DMESG-WARN (fdo#106523) -> PASS +4

    igt@gem_eio@suspend:
      shard-kbl:          DMESG-WARN (fdo#106523) -> PASS

    igt@kms_flip@2x-plain-flip-ts-check-interruptible:
      shard-glk:          FAIL (fdo#100368) -> PASS

    igt@kms_flip@flip-vs-expired-vblank-interruptible:
      shard-glk:          FAIL (fdo#105707) -> PASS +1

    igt@kms_flip_tiling@flip-to-x-tiled:
      shard-glk:          FAIL (fdo#104724) -> PASS

    igt@kms_flip_tiling@flip-to-y-tiled:
      shard-glk:          FAIL (fdo#103822, fdo#104724) -> PASS

    igt@perf_pmu@idle-vcs0:
      shard-glk:          INCOMPLETE (fdo#103359, k.org#198133) -> PASS

    
  fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
  fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
  fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
  fdo#103359 https://bugs.freedesktop.org/show_bug.cgi?id=103359
  fdo#103558 https://bugs.freedesktop.org/show_bug.cgi?id=103558
  fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
  fdo#103822 https://bugs.freedesktop.org/show_bug.cgi?id=103822
  fdo#103927 https://bugs.freedesktop.org/show_bug.cgi?id=103927
  fdo#103928 https://bugs.freedesktop.org/show_bug.cgi?id=103928
  fdo#104724 https://bugs.freedesktop.org/show_bug.cgi?id=104724
  fdo#105602 https://bugs.freedesktop.org/show_bug.cgi?id=105602
  fdo#105707 https://bugs.freedesktop.org/show_bug.cgi?id=105707
  fdo#106023 https://bugs.freedesktop.org/show_bug.cgi?id=106023
  fdo#106026 https://bugs.freedesktop.org/show_bug.cgi?id=106026
  fdo#106510 https://bugs.freedesktop.org/show_bug.cgi?id=106510
  fdo#106523 https://bugs.freedesktop.org/show_bug.cgi?id=106523
  k.org#198133 https://bugzilla.kernel.org/show_bug.cgi?id=198133


== Participating hosts (5 -> 5) ==

  No changes in participating hosts


== Build changes ==

    * IGT: IGT_4485 -> IGTPW_1377
    * Linux: CI_DRM_4191 -> CI_DRM_4193
    * Piglit: piglit_4485 -> piglit_4487

  CI_DRM_4191: 70daebf1a83c2ed6eff118d2a2806086c0c89027 @ git://anongit.freedesktop.org/gfx-ci/linux
  CI_DRM_4193: 9322e3903ce6c89bde0c24877fe730b808427caf @ git://anongit.freedesktop.org/gfx-ci/linux
  IGTPW_1377: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1377/
  IGT_4485: eccae1360d6d01e73c6af2bd97122cef708207ef @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
  piglit_4485: 62ef6b0db8967e7021fd3e0b57d03ff164b984fe @ git://anongit.freedesktop.org/piglit
  piglit_4487: 6ab75f7eb5e1dccbb773e1739beeb2d7cbd6ad0d @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1377/shards.html
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2018-05-19  6:30 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17 19:51 [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Ville Syrjala
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 02/10] lib: Clear packed YUV formats to black Ville Syrjala
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 03/10] lib: Don't use dumb buffers for YCbCr Ville Syrjala
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 04/10] lib: Clean up format_desc Ville Syrjala
2018-05-17 20:13   ` Chris Wilson
2018-05-18 12:42     ` Ville Syrjälä
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 05/10] lib: Add igt_matrix Ville Syrjala
2018-05-17 20:16   ` Chris Wilson
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 06/10] lib: Add igt_color_encoding Ville Syrjala
2018-05-17 20:48   ` Chris Wilson
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 07/10] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
2018-05-17 21:49   ` Chris Wilson
2018-05-18 12:41     ` Ville Syrjälä
2018-05-18 19:56   ` [igt-dev] [PATCH i-g-t v4 " Ville Syrjala
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 08/10] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
2018-05-17 22:41   ` Chris Wilson
2018-05-18 13:00     ` Ville Syrjälä
2018-05-18 13:17       ` Chris Wilson
2018-05-18 19:57   ` [igt-dev] [PATCH i-g-t v5 " Ville Syrjala
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 09/10] lib/fb: Add color_encoding/color_range to igt_fb Ville Syrjala
2018-05-17 21:42   ` Chris Wilson
2018-05-17 19:51 ` [igt-dev] [PATCH i-g-t 10/10] lib/kms: Respect fb color_encoding/color_range Ville Syrjala
2018-05-17 20:09 ` [igt-dev] [PATCH i-g-t 01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion Chris Wilson
2018-05-17 20:29 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] " Patchwork
2018-05-17 23:38 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-05-18 20:30 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/10] lib: Add clamp() to igt_aux and use it for ycbcr<->rgb conversion (rev3) Patchwork
2018-05-19  6:30 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.