All of lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format.
@ 2018-01-23 12:56 Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
                   ` (17 more replies)
  0 siblings, 18 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

This patch series will allow us to create framebuffers with NV12 support.
Tests don't have to handle NV12 differently, and can draw to it the same
way as any other format.

I've validated this against kms_plane.pixel-format-pipe-*-planes and
kms_plane_scaling, which will automatically use NV12 if available
because it filters usable formats through igt_get_all_cairo_formats().

Maarten Lankhorst (8):
  lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  lib/igt_fb: Pass format to igt_calc_fb_size
  lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  lib/intel_batchbuffer: Add delta argument to
    igt_blitter_fast_copy__raw
  lib/intel_batchbuffer: Add src/dst delta arguments to
    igt_blitter_fast_copy too
  lib/fb: Add support for creating planar framebuffers
  tests/kms_render: Copy all planes when copying fb
  lib/igt_fb: Add support for NV12 format through conversion

 lib/igt_fb.c                      | 629 ++++++++++++++++++++++++++++++--------
 lib/igt_fb.h                      |  13 +-
 lib/intel_batchbuffer.c           |  41 ++-
 lib/intel_batchbuffer.h           |  16 +-
 lib/ioctl_wrappers.c              |  11 +-
 lib/ioctl_wrappers.h              |   2 +-
 tests/gem_concurrent_all.c        |   4 +-
 tests/gem_read_read_speed.c       |   4 +-
 tests/kms_chv_cursor_fail.c       |   3 +-
 tests/kms_color.c                 |   4 +-
 tests/kms_concurrent.c            |   3 +-
 tests/kms_crtc_background_color.c |   2 +-
 tests/kms_cursor_crc.c            |  23 +-
 tests/kms_draw_crc.c              |   2 +-
 tests/kms_flip.c                  |   3 +-
 tests/kms_frontbuffer_tracking.c  |   4 +-
 tests/kms_mmap_write_crc.c        |   4 +-
 tests/kms_plane.c                 |   9 +-
 tests/kms_plane_multiple.c        |   3 +-
 tests/kms_plane_scaling.c         |   3 +-
 tests/kms_psr_sink_crc.c          |   2 +-
 tests/kms_render.c                |  17 +-
 tests/kms_rotation_crc.c          |   7 +-
 tests/kms_setmode.c               |   2 +-
 tests/prime_vgem.c                |   2 +-
 tests/testdisplay.c               |   8 +-
 26 files changed, 617 insertions(+), 204 deletions(-)

-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-23 15:50   ` Ville Syrjälä
  2018-01-31 17:03   ` Ville Syrjälä
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size Maarten Lankhorst
                   ` (16 subsequent siblings)
  17 siblings, 2 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

This will allow support for NV12 in the future, where igt_get_cairo_ctx
will return a RGB image to draw with, which will be converted in
igt_put_cairo_ctx so tests don't have to add special support for NV12.

This is the same as cairo_destroy + checking for errors, but not all
tests use this correctly so it's better to have a single handler for it.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c                      | 34 ++++++++++++++++++++++++----------
 lib/igt_fb.h                      |  1 +
 tests/kms_chv_cursor_fail.c       |  3 +--
 tests/kms_color.c                 |  4 ++--
 tests/kms_concurrent.c            |  3 +--
 tests/kms_crtc_background_color.c |  2 +-
 tests/kms_cursor_crc.c            | 23 +++++++++++++++++++----
 tests/kms_flip.c                  |  3 +--
 tests/kms_mmap_write_crc.c        |  4 ++--
 tests/kms_plane.c                 |  9 +++------
 tests/kms_plane_multiple.c        |  3 +--
 tests/kms_plane_scaling.c         |  3 +--
 tests/kms_psr_sink_crc.c          |  2 +-
 tests/kms_render.c                |  2 +-
 tests/kms_rotation_crc.c          |  2 +-
 tests/kms_setmode.c               |  2 +-
 tests/testdisplay.c               |  8 ++------
 17 files changed, 63 insertions(+), 45 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index ded639e833f1..39a83bae178a 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -771,8 +771,7 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
 
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_color(cr, 0, 0, width, height, r, g, b);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(fd, fb, cr);
 
 	return fb_id;
 }
@@ -809,8 +808,7 @@ unsigned int igt_create_pattern_fb(int fd, int width, int height,
 
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_test_pattern(cr, width, height);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(fd, fb, cr);
 
 	return fb_id;
 }
@@ -853,8 +851,7 @@ unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_color(cr, 0, 0, width, height, r, g, b);
 	igt_paint_test_pattern(cr, width, height);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(fd, fb, cr);
 
 	return fb_id;
 }
@@ -897,8 +894,7 @@ unsigned int igt_create_image_fb(int fd, int width, int height,
 
 	cr = igt_get_cairo_ctx(fd, fb);
 	igt_paint_image(cr, filename, 0, 0, width, height);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(fd, fb, cr);
 
 	return fb_id;
 }
@@ -998,7 +994,7 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
 			layout.right.x, layout.right.y,
 			layout.right.width, layout.right.height);
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, &fb, cr);
 
 	return fb_id;
 }
@@ -1206,7 +1202,7 @@ cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
  *
  * This initializes a cairo surface for @fb and then allocates a drawing context
  * for it. The return cairo drawing context should be released by calling
- * cairo_destroy(). This also sets a default font for drawing text on
+ * igt_put_cairo_ctx(). This also sets a default font for drawing text on
  * framebuffers.
  *
  * Returns:
@@ -1229,6 +1225,24 @@ cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb)
 	return cr;
 }
 
+/**
+ * igt_put_cairo_ctx:
+ * @fd: open i915 drm file descriptor
+ * @fb: pointer to an #igt_fb structure
+ * @cr: the cairo context returned by igt_get_cairo_ctx.
+ *
+ * This releases the cairo surface @cr returned by igt_get_cairo_ctx()
+ * for @fb, and writes the changes out to the framebuffer if cairo doesn't
+ * have native support for the format.
+ */
+void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr)
+{
+	cairo_status_t ret = cairo_status(cr);
+	igt_assert_f(ret == CAIRO_STATUS_SUCCESS, "Cairo failed to draw with %s\n", cairo_status_to_string(ret));
+
+	cairo_destroy(cr);
+}
+
 /**
  * igt_remove_fb:
  * @fd: open i915 drm file descriptor
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index d30a7340c76e..3004f0656029 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -131,6 +131,7 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
 cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
 cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
+void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr);
 void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
 			 double r, double g, double b);
 void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
diff --git a/tests/kms_chv_cursor_fail.c b/tests/kms_chv_cursor_fail.c
index 3e74df1142da..1bcf8469088e 100644
--- a/tests/kms_chv_cursor_fail.c
+++ b/tests/kms_chv_cursor_fail.c
@@ -87,8 +87,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
 	else
 		igt_paint_color_alpha(cr, 0, 0, data->fb.width, data->fb.height,
 				      0.0, 0.0, 0.0, 0.0);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
 }
 
 static void cursor_move(data_t *data, int x, int y, int i)
diff --git a/tests/kms_color.c b/tests/kms_color.c
index 3b0a88802c93..dc4fcce241be 100644
--- a/tests/kms_color.c
+++ b/tests/kms_color.c
@@ -86,7 +86,7 @@ static void paint_gradient_rectangles(data_t *data,
 					       colors[i].b);
 	}
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 }
 
 static void paint_rectangles(data_t *data,
@@ -103,7 +103,7 @@ static void paint_rectangles(data_t *data,
 				colors[i].r, colors[i].g, colors[i].b);
 	}
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 }
 
 static double *generate_table(uint32_t lut_size, double exp)
diff --git a/tests/kms_concurrent.c b/tests/kms_concurrent.c
index 3b2e601505c4..283acf8c8a7e 100644
--- a/tests/kms_concurrent.c
+++ b/tests/kms_concurrent.c
@@ -148,8 +148,7 @@ create_fb_for_mode_position(data_t *data, drmModeModeInfo *mode,
 				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
 	}
 
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
 }
 
 static void
diff --git a/tests/kms_crtc_background_color.c b/tests/kms_crtc_background_color.c
index e99c67bd185e..6407e19bafce 100644
--- a/tests/kms_crtc_background_color.c
+++ b/tests/kms_crtc_background_color.c
@@ -69,7 +69,7 @@ paint_background(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
 	b = (double) ((background & 0xFF0000) >> 16) / 255.0;
 	igt_paint_color_alpha(cr, 0, 0, w, h, r, g, b, alpha);
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->gfx_fd, &data->fb, cr);
 }
 
 static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
diff --git a/tests/kms_cursor_crc.c b/tests/kms_cursor_crc.c
index 4c5e00c074a5..a164839ee2cc 100644
--- a/tests/kms_cursor_crc.c
+++ b/tests/kms_cursor_crc.c
@@ -141,13 +141,16 @@ static void do_single_test(data_t *data, int x, int y)
 	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
 	igt_crc_t crc, ref_crc;
 	igt_plane_t *cursor;
-	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
+	cairo_t *cr;
 	int ret = 0;
 
 	igt_print_activity();
 
 	/* Hardware test */
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	igt_paint_test_pattern(cr, data->screenw, data->screenh);
+	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
+
 	cursor_enable(data);
 	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
 	igt_plane_set_position(cursor, x, y);
@@ -190,7 +193,9 @@ static void do_single_test(data_t *data, int x, int y)
 	igt_display_commit(display);
 
 	/* Now render the same in software and collect crc */
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	draw_cursor(cr, x, y, data->curw, data->curh);
+	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
 	igt_display_commit(display);
 
 	igt_wait_for_vblank(data->drm_fd, data->pipe);
@@ -198,20 +203,25 @@ static void do_single_test(data_t *data, int x, int y)
 	igt_assert_crc_equal(&crc, &ref_crc);
 
 	/* Clear screen afterwards */
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	igt_paint_color(cr, 0, 0, data->screenw, data->screenh, 0.0, 0.0, 0.0);
+	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
 }
 
 static void do_fail_test(data_t *data, int x, int y, int expect)
 {
 	igt_display_t *display = &data->display;
 	igt_plane_t *cursor;
-	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
+	cairo_t *cr;
 	int ret;
 
 	igt_print_activity();
 
 	/* Hardware test */
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	igt_paint_test_pattern(cr, data->screenw, data->screenh);
+	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
+
 	cursor_enable(data);
 	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
 	igt_plane_set_position(cursor, x, y);
@@ -446,7 +456,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
 
 	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
 	draw_cursor(cr, 0, 0, cur_w, cur_h);
-	igt_assert(cairo_status(cr) == 0);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
 }
 
 static bool has_nonsquare_cursors(uint32_t devid)
@@ -486,6 +496,7 @@ static void test_cursor_size(data_t *data)
 	/* Use a solid white rectangle as the cursor */
 	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
 	igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
 
 	/* Hardware test loop */
 	cursor_enable(data);
@@ -501,16 +512,20 @@ static void test_cursor_size(data_t *data)
 	}
 	cursor_disable(data);
 	/* Software test loop */
-	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
 		/* Now render the same in software and collect crc */
+		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 		igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
+		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
+
 		igt_display_commit(display);
 		igt_wait_for_vblank(data->drm_fd, data->pipe);
 		igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
 		/* Clear screen afterwards */
+		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
 		igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
 				0.0, 0.0, 0.0);
+		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
 		igt_assert_crc_equal(&crc[i], &ref_crc);
 	}
 }
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 710ea52b4a8a..b43e77123e7f 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -976,8 +976,7 @@ static void paint_flip_mode(struct igt_fb *fb, bool odd_frame)
 	cairo_set_source_rgb(cr, 1, 1, 1);
 	cairo_fill(cr);
 
-	igt_assert(!cairo_status(cr));
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, fb, cr);
 }
 
 static int
diff --git a/tests/kms_mmap_write_crc.c b/tests/kms_mmap_write_crc.c
index dd44ce97238a..279d0f67dd53 100644
--- a/tests/kms_mmap_write_crc.c
+++ b/tests/kms_mmap_write_crc.c
@@ -92,7 +92,7 @@ static void test(data_t *data)
 
 	cr = igt_get_cairo_ctx(data->drm_fd, fb);
 	igt_paint_test_pattern(cr, fb->width, fb->height);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 
 	/* flip to it to make it UC/WC and fully flushed */
 	igt_plane_set_fb(data->primary, fb);
@@ -135,7 +135,7 @@ static void test(data_t *data)
 	 * fully flushed */
 	cr = igt_get_cairo_ctx(data->drm_fd, fb);
 	igt_paint_test_pattern(cr, fb->width, fb->height);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 
 	igt_plane_set_fb(data->primary, fb);
 	igt_display_commit(display);
diff --git a/tests/kms_plane.c b/tests/kms_plane.c
index 9672763fe619..54bcffc16f4f 100644
--- a/tests/kms_plane.c
+++ b/tests/kms_plane.c
@@ -138,8 +138,7 @@ create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
 	igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
 			    0.0, 1.0, 0.0);
 	igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 }
 
 enum {
@@ -279,8 +278,7 @@ create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
 			mode->hdisplay, mode->vdisplay,
 			0.0, 0.0, 1.0);
 
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, fb, cr);
 }
 
 enum {
@@ -436,8 +434,7 @@ static void test_format_plane(data_t *data, enum pipe pipe,
 				0.0, 1.0, 0.0);
 		if (width >= 164 && height >= 164)
 			igt_paint_color(cr, 100, 100, 64, 64, 0.0, 0.0, 0.0);
-		igt_assert(cairo_status(cr) == 0);
-		cairo_destroy(cr);
+		igt_put_cairo_ctx(data->drm_fd, &fb, cr);
 
 		igt_plane_set_fb(plane, &fb);
 		igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
diff --git a/tests/kms_plane_multiple.c b/tests/kms_plane_multiple.c
index aea59df84d76..95b713858edc 100644
--- a/tests/kms_plane_multiple.c
+++ b/tests/kms_plane_multiple.c
@@ -173,8 +173,7 @@ create_fb_for_mode_position(data_t *data, igt_output_t *output, drmModeModeInfo
 				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
 		}
 
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
 }
 
 
diff --git a/tests/kms_plane_scaling.c b/tests/kms_plane_scaling.c
index c8283a3b23d1..d32f3441e8c9 100644
--- a/tests/kms_plane_scaling.c
+++ b/tests/kms_plane_scaling.c
@@ -120,8 +120,7 @@ static void paint_fb(data_t *d, struct igt_fb *fb)
 
 	cr = igt_get_cairo_ctx(d->drm_fd, fb);
 	igt_paint_color(cr, 0, 0, fb->width, fb->height, 0.0, 1.0, 0.0);
-	igt_assert(cairo_status(cr) == 0);
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(d->drm_fd, fb, cr);
 }
 
 static void check_scaling_pipe_plane_rot(data_t *d, igt_plane_t *plane,
diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
index 26cf434af64a..2b60acf34e77 100644
--- a/tests/kms_psr_sink_crc.c
+++ b/tests/kms_psr_sink_crc.c
@@ -91,7 +91,7 @@ static void create_cursor_fb(data_t *data)
 
 	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb_white);
 	igt_paint_color_alpha(cr, 0, 0, 64, 64, 1.0, 1.0, 1.0, 1.0);
-	igt_assert(cairo_status(cr) == 0);
+	igt_put_cairo_ctx(data->drm_fd, &data->fb_white, cr);
 }
 
 
diff --git a/tests/kms_render.c b/tests/kms_render.c
index d2208e38f84e..25a0c05b547c 100644
--- a/tests/kms_render.c
+++ b/tests/kms_render.c
@@ -55,7 +55,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
 	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
 	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, fb, cr);
 
 	return 0;
 }
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index 799cf1142579..5b190a0d03cb 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -120,7 +120,7 @@ paint_squares(data_t *data, igt_rotation_t rotation,
 	igt_paint_color(cr, 0, h / 2, w / 2, h / 2, RGB_COLOR(bl));
 	igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, RGB_COLOR(br));
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(data->gfx_fd, fb, cr);
 }
 
 static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c
index 206d360607bb..06241b191a0f 100644
--- a/tests/kms_setmode.c
+++ b/tests/kms_setmode.c
@@ -161,7 +161,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
 					  crtc_str[i]);
 	}
 
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, fb, cr);
 
 	return 0;
 }
diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index b0156c5cf0e1..0ff98a2b705e 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -227,9 +227,7 @@ paint_color_key(struct igt_fb *fb_info)
 	cairo_set_source_rgb(cr, .8, .8, .8);
 	cairo_fill(cr);
 
-	igt_assert(!cairo_status(cr));
-
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, fb_info, cr);
 }
 
 static void paint_image(cairo_t *cr, const char *file)
@@ -294,9 +292,7 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb)
 	if (qr_code)
 		paint_image(cr, "pass.png");
 
-	igt_assert(!cairo_status(cr));
-
-	cairo_destroy(cr);
+	igt_put_cairo_ctx(drm_fd, fb, cr);
 }
 
 static void sighandler(int signo)
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-25 11:51   ` Mika Kahola
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb Maarten Lankhorst
                   ` (15 subsequent siblings)
  17 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

bpp is only sufficient to calculate dimensions for packed formats, in
case of planar formats we need to pass the drm format fourcc, which
will give us better information.

This is required for supporting planar framebuffers.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c                     | 10 ++++++----
 lib/igt_fb.h                     |  2 +-
 tests/kms_frontbuffer_tracking.c |  4 +---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 39a83bae178a..da07d1a9e21f 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -147,7 +147,7 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
  * @fd: the DRM file descriptor
  * @width: width of the framebuffer in pixels
  * @height: height of the framebuffer in pixels
- * @bpp: bytes per pixel of the framebuffer
+ * @format: drm fourcc pixel format code
  * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
  * @size_ret: returned size for the framebuffer
  * @stride_ret: returned stride for the framebuffer
@@ -155,10 +155,11 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
  * This function returns valid stride and size values for a framebuffer with the
  * specified parameters.
  */
-void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
+void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t tiling,
 		      unsigned *size_ret, unsigned *stride_ret)
 {
 	unsigned int tile_width, tile_height, stride, size;
+	int bpp = igt_drm_format_to_bpp(format);
 	int byte_width = width * (bpp / 8);
 
 	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width, &tile_height);
@@ -249,13 +250,12 @@ static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
 			    unsigned *size_ret, unsigned *stride_ret,
 			    bool *is_dumb)
 {
-	int bpp = igt_drm_format_to_bpp(format);
 	int bo;
 
 	if (tiling || size || stride) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, bpp, tiling,
+		igt_calc_fb_size(fd, width, height, format, tiling,
 				 &calculated_size, &calculated_stride);
 		if (stride == 0)
 			stride = calculated_stride;
@@ -290,6 +290,8 @@ static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
 			return -EINVAL;
 		}
 	} else {
+		int bpp = igt_drm_format_to_bpp(format);
+
 		if (is_dumb)
 			*is_dumb = true;
 
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 3004f0656029..152798e9896b 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -90,7 +90,7 @@ enum igt_text_align {
 
 void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 			  unsigned *width_ret, unsigned *height_ret);
-void igt_calc_fb_size(int fd, int width, int height, int bpp, uint64_t tiling,
+void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t tiling,
 		      unsigned *size_ret, unsigned *stride_ret);
 unsigned int
 igt_create_fb_with_bo_size(int fd, int width, int height,
diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c
index 1601cab45b9a..ea5297538c34 100644
--- a/tests/kms_frontbuffer_tracking.c
+++ b/tests/kms_frontbuffer_tracking.c
@@ -541,7 +541,6 @@ static void create_fb(enum pixel_format pformat, int width, int height,
 {
 	uint32_t format;
 	unsigned int size, stride;
-	int bpp;
 	uint64_t tiling_for_size;
 
 	switch (pformat) {
@@ -576,13 +575,12 @@ static void create_fb(enum pixel_format pformat, int width, int height,
 	 * the same size regardless of tiling since we want to properly exercise
 	 * the Kernel's specific tiling-checking code paths without accidentally
 	 * hitting size-checking ones first. */
-	bpp = igt_drm_format_to_bpp(format);
 	if (plane == PLANE_CUR)
 		tiling_for_size = LOCAL_DRM_FORMAT_MOD_NONE;
 	else
 		tiling_for_size = opt.tiling;
 
-	igt_calc_fb_size(drm.fd, width, height, bpp, tiling_for_size, &size,
+	igt_calc_fb_size(drm.fd, width, height, format, tiling_for_size, &size,
 			 &stride);
 
 	igt_create_fb_with_bo_size(drm.fd, width, height, format, tiling, fb,
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-26  9:00   ` Mika Kahola
  2018-02-01 14:39   ` Ville Syrjälä
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw Maarten Lankhorst
                   ` (14 subsequent siblings)
  17 siblings, 2 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

By adding support for planar formats to igt_calc_fb_size and create_bo_for_fb,
we can calculate dimensions and create backing storage for planar framebuffers.

This is required for adding support to create planar framebuffers in the next patch.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 123 insertions(+), 45 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index da07d1a9e21f..6a331f06724b 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -54,14 +54,16 @@
  */
 
 /* drm fourcc/cairo format maps */
-#define DF(did, cid, _bpp, _depth)	\
-	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
+#define DF(did, cid, ...)	\
+	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
 static struct format_desc_struct {
 	uint32_t drm_id;
 	cairo_format_t cairo_id;
 	const char *name;
 	int bpp;
 	int depth;
+	int planes;
+	int plane_bpp[4];
 } format_desc[] = {
 	DF(RGB565,	RGB16_565,	16, 16),
 	//DF(RGB888,	INVALID,	24, 24),
@@ -74,6 +76,20 @@ static struct format_desc_struct {
 #define for_each_format(f)	\
 	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
 
+static struct format_desc_struct *lookup_drm_format(uint32_t drm_format)
+{
+	struct format_desc_struct *format;
+
+	for_each_format(format) {
+		if (format->drm_id != drm_format)
+			continue;
+
+		return format;
+	}
+
+	return NULL;
+}
+
 /**
  * igt_get_fb_tile_size:
  * @fd: the DRM file descriptor
@@ -142,27 +158,68 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 	}
 }
 
-/**
- * igt_calc_fb_size:
- * @fd: the DRM file descriptor
- * @width: width of the framebuffer in pixels
- * @height: height of the framebuffer in pixels
- * @format: drm fourcc pixel format code
- * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
- * @size_ret: returned size for the framebuffer
- * @stride_ret: returned stride for the framebuffer
- *
- * This function returns valid stride and size values for a framebuffer with the
- * specified parameters.
- */
-void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t tiling,
-		      unsigned *size_ret, unsigned *stride_ret)
+static unsigned planar_stride(struct format_desc_struct *format, unsigned width, int plane)
+{
+	unsigned cpp = format->plane_bpp[plane] / 8;
+
+	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
+		return (width + 1) / 2 * cpp;
+
+	return width * cpp;
+}
+
+static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
+{
+	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
+		return (height + 1) / 2;
+
+	return height;
+}
+
+static void calc_fb_size_planar(int fd, int width, int height,
+				struct format_desc_struct *format,
+				uint64_t tiling, unsigned *size_ret,
+				unsigned *stride_ret, unsigned *offsets)
+{
+	int plane;
+	unsigned stride = 0, tile_width, tile_height;
+
+	*size_ret = 0;
+
+	for (plane = 0; plane < format->planes; plane++) {
+		unsigned plane_stride;
+
+		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
+
+		plane_stride = ALIGN(planar_stride(format, width, plane), tile_width);
+		if (stride < plane_stride)
+			stride = plane_stride;
+	}
+
+	for (plane = 0; plane < format->planes; plane++) {
+		if (offsets)
+			offsets[plane] = *size_ret;
+
+		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
+
+		*size_ret += stride * ALIGN(planar_height(format, height, plane), tile_height);
+	}
+
+	if (offsets)
+		for (; plane < 4; plane++)
+			offsets[plane] = 0;
+
+	*stride_ret = stride;
+}
+
+static void calc_fb_size_packed(int fd, int width, int height,
+				struct format_desc_struct *format, uint64_t tiling,
+				unsigned *size_ret, unsigned *stride_ret)
 {
 	unsigned int tile_width, tile_height, stride, size;
-	int bpp = igt_drm_format_to_bpp(format);
-	int byte_width = width * (bpp / 8);
+	int byte_width = width * (format->bpp / 8);
 
-	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width, &tile_height);
+	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width, &tile_height);
 
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
@@ -176,7 +233,7 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t t
 		 * tiled. But then that failure is expected.
 		 */
 
-		v = width * bpp / 8;
+		v = byte_width;
 		for (stride = 512; stride < v; stride *= 2)
 			;
 
@@ -192,6 +249,31 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t t
 	*size_ret = size;
 }
 
+/**
+ * igt_calc_fb_size:
+ * @fd: the DRM file descriptor
+ * @width: width of the framebuffer in pixels
+ * @height: height of the framebuffer in pixels
+ * @format: drm fourcc pixel format code
+ * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
+ * @size_ret: returned size for the framebuffer
+ * @stride_ret: returned stride for the framebuffer
+ *
+ * This function returns valid stride and size values for a framebuffer with the
+ * specified parameters.
+ */
+void igt_calc_fb_size(int fd, int width, int height, uint32_t drm_format, uint64_t tiling,
+		      unsigned *size_ret, unsigned *stride_ret)
+{
+	struct format_desc_struct *format = lookup_drm_format(drm_format);
+	igt_assert(format);
+
+	if (format->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);
+}
+
 /**
  * igt_fb_mod_to_tiling:
  * @modifier: DRM framebuffer modifier
@@ -245,17 +327,20 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling)
 }
 
 /* helpers to create nice-looking framebuffers */
-static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
+static int create_bo_for_fb(int fd, int width, int height,
+			    struct format_desc_struct *format,
 			    uint64_t tiling, unsigned size, unsigned stride,
 			    unsigned *size_ret, unsigned *stride_ret,
 			    bool *is_dumb)
 {
 	int bo;
 
-	if (tiling || size || stride) {
+	igt_assert(format);
+
+	if (tiling || size || stride || format->planes > 1) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, format, tiling,
+		igt_calc_fb_size(fd, width, height, format->drm_id, tiling,
 				 &calculated_size, &calculated_stride);
 		if (stride == 0)
 			stride = calculated_stride;
@@ -290,12 +375,10 @@ static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
 			return -EINVAL;
 		}
 	} else {
-		int bpp = igt_drm_format_to_bpp(format);
-
 		if (is_dumb)
 			*is_dumb = true;
 
-		return kmstest_dumb_create(fd, width, height, bpp, stride_ret,
+		return kmstest_dumb_create(fd, width, height, format->bpp, stride_ret,
 					   size_ret);
 	}
 }
@@ -323,8 +406,8 @@ 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, format, modifier, 0, stride,
-			     size_ret, stride_ret, is_dumb);
+	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
+				modifier, 0, stride, size_ret, stride_ret, is_dumb);
 }
 
 /**
@@ -671,9 +754,10 @@ 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, format, tiling,
-					  bo_size, bo_stride, &fb->size,
-					  &fb->stride, &fb->is_dumb);
+	fb->gem_handle = create_bo_for_fb(fd, width, height,
+					  lookup_drm_format(format),
+					  tiling, bo_size, bo_stride,
+					  &fb->size, &fb->stride, &fb->is_dumb);
 	igt_assert(fb->gem_handle > 0);
 
 	igt_debug("%s(handle=%d, pitch=%d)\n",
@@ -1069,7 +1153,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 	 * destination, tiling it at the same time.
 	 */
 	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
-					       fb->drm_format,
+					       lookup_drm_format(fb->drm_format),
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
 					       0, &blit->linear.size,
 					       &blit->linear.stride,
@@ -1293,14 +1377,12 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth)
  */
 uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
 {
-	struct format_desc_struct *f;
+	struct format_desc_struct *f = lookup_drm_format(drm_format);
 
-	for_each_format(f)
-		if (f->drm_id == drm_format)
-			return f->bpp;
-
-	igt_assert_f(0, "can't find a bpp format for %08x (%s)\n",
+	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
 		     drm_format, igt_format_str(drm_format));
+
+	return f->bpp;
 }
 
 /**
@@ -1313,13 +1395,9 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
  */
 const char *igt_format_str(uint32_t drm_format)
 {
-	struct format_desc_struct *f;
-
-	for_each_format(f)
-		if (f->drm_id == drm_format)
-			return f->name;
+	struct format_desc_struct *f = lookup_drm_format(drm_format);
 
-	return "invalid";
+	return f ? f->name : "invalid";
 }
 
 /**
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (2 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-26  9:02   ` Mika Kahola
  2018-01-29 12:10   ` [igt-dev] [PATCH i-g-t] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw, v2 Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too Maarten Lankhorst
                   ` (13 subsequent siblings)
  17 siblings, 2 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

Adding a delta offset will allow us to copy planar framebuffers with this
function.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c            |  8 ++++----
 lib/intel_batchbuffer.c | 15 ++++++++++-----
 lib/intel_batchbuffer.h |  2 ++
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6a331f06724b..1251f462d24e 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1121,13 +1121,13 @@ static void destroy_cairo_surface__blit(void *arg)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(blit->fd,
-				   blit->linear.handle,
+				   blit->linear.handle, 0,
 				   blit->linear.stride,
 				   I915_TILING_NONE,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle,
+				   fb->gem_handle, 0,
 				   fb->stride,
 				   obj_tiling,
 				   0, 0 /* dst_x, dst_y */);
@@ -1169,13 +1169,13 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle,
+				   fb->gem_handle, 0,
 				   fb->stride,
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   blit->linear.handle,
+				   blit->linear.handle, 0,
 				   blit->linear.stride,
 				   I915_TILING_NONE,
 				   0, 0 /* dst_x, dst_y */);
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 9a53b6f8e706..3a199fa7ba57 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -554,11 +554,12 @@ static uint32_t fast_copy_dword1(unsigned int src_tiling,
 
 static void
 fill_relocation(struct drm_i915_gem_relocation_entry *reloc,
-		uint32_t gem_handle, uint32_t offset, /* in dwords */
+		uint32_t gem_handle, uint32_t delta, /* in bytes */
+		uint32_t offset, /* in dwords */
 		uint32_t read_domains, uint32_t write_domains)
 {
 	reloc->target_handle = gem_handle;
-	reloc->delta = 0;
+	reloc->delta = delta;
 	reloc->offset = offset * sizeof(uint32_t);
 	reloc->presumed_offset = 0;
 	reloc->read_domains = read_domains;
@@ -599,6 +600,7 @@ static void exec_blit(int fd,
  * igt_blitter_fast_copy__raw:
  * @fd: file descriptor of the i915 driver
  * @src_handle: GEM handle of the source buffer
+ * @src_delta: offset into the source GEM bo, in bytes
  * @src_stride: Stride (in bytes) of the source buffer
  * @src_tiling: Tiling mode of the source buffer
  * @src_x: X coordinate of the source region to copy
@@ -606,7 +608,8 @@ static void exec_blit(int fd,
  * @width: Width of the region to copy
  * @height: Height of the region to copy
  * @bpp: source and destination bits per pixel
- * @dst_handle: GEM handle of the source buffer
+ * @dst_handle: GEM handle of the destination buffer
+ * @dst_delta: offset into the destination GEM bo, in bytes
  * @dst_stride: Stride (in bytes) of the destination buffer
  * @dst_tiling: Tiling mode of the destination buffer
  * @dst_x: X coordinate of destination
@@ -617,6 +620,7 @@ static void exec_blit(int fd,
 void igt_blitter_fast_copy__raw(int fd,
 				/* src */
 				uint32_t src_handle,
+				unsigned int src_delta,
 				unsigned int src_stride,
 				unsigned int src_tiling,
 				unsigned int src_x, unsigned src_y,
@@ -629,6 +633,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* dst */
 				uint32_t dst_handle,
+				unsigned dst_delta,
 				unsigned int dst_stride,
 				unsigned int dst_tiling,
 				unsigned int dst_x, unsigned dst_y)
@@ -673,9 +678,9 @@ void igt_blitter_fast_copy__raw(int fd,
 	batch_handle = gem_create(fd, 4096);
 	gem_write(fd, batch_handle, 0, batch, sizeof(batch));
 
-	fill_relocation(&relocs[0], dst_handle, 4,
+	fill_relocation(&relocs[0], dst_handle, dst_delta, 4,
 			I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-	fill_relocation(&relocs[1], src_handle, 8, I915_GEM_DOMAIN_RENDER, 0);
+	fill_relocation(&relocs[1], src_handle, src_delta, 8, I915_GEM_DOMAIN_RENDER, 0);
 
 	fill_object(&objs[0], dst_handle, NULL, 0);
 	fill_object(&objs[1], src_handle, NULL, 0);
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 6bee41676627..a6d8f9863698 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -234,6 +234,7 @@ void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 void igt_blitter_fast_copy__raw(int fd,
 				/* src */
 				uint32_t src_handle,
+				unsigned int src_delta,
 				unsigned int src_stride,
 				unsigned int src_tiling,
 				unsigned int src_x, unsigned src_y,
@@ -246,6 +247,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* dst */
 				uint32_t dst_handle,
+				unsigned int dst_delta,
 				unsigned int dst_stride,
 				unsigned int dst_tiling,
 				unsigned int dst_x, unsigned dst_y);
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (3 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-26  9:04   ` Mika Kahola
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add support for creating planar framebuffers Maarten Lankhorst
                   ` (12 subsequent siblings)
  17 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

Nothing uses this currently, but other copy functions have the same delta now.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/intel_batchbuffer.c | 12 ++++++++----
 lib/intel_batchbuffer.h | 10 ++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 3a199fa7ba57..3c1689cd302c 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -695,12 +695,14 @@ void igt_blitter_fast_copy__raw(int fd,
  * igt_blitter_fast_copy:
  * @batch: batchbuffer object
  * @src: source i-g-t buffer object
+ * @src_delta: offset into the source i-g-t bo
  * @src_x: source pixel x-coordination
  * @src_y: source pixel y-coordination
  * @width: width of the copied rectangle
  * @height: height of the copied rectangle
  * @bpp: source and destination bits per pixel
  * @dst: destination i-g-t buffer object
+ * @dst_delta: offset into the destination i-g-t bo
  * @dst_x: destination pixel x-coordination
  * @dst_y: destination pixel y-coordination
  *
@@ -709,10 +711,12 @@ void igt_blitter_fast_copy__raw(int fd,
  * The source and destination surfaces cannot overlap.
  */
 void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
-			   struct igt_buf *src, unsigned src_x, unsigned src_y,
+			   struct igt_buf *src, unsigned src_delta,
+			   unsigned src_x, unsigned src_y,
 			   unsigned width, unsigned height,
 			   int bpp,
-			   struct igt_buf *dst, unsigned dst_x, unsigned dst_y)
+			   struct igt_buf *dst, unsigned dst_delta,
+			   unsigned dst_x, unsigned dst_y)
 {
 	uint32_t src_pitch, dst_pitch;
 	uint32_t dword0, dword1;
@@ -736,11 +740,11 @@ void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 	OUT_BATCH(dword1 | dst_pitch);
 	OUT_BATCH((dst_y << 16) | dst_x); /* dst x1,y1 */
 	OUT_BATCH(((dst_y + height) << 16) | (dst_x + width)); /* dst x2,y2 */
-	OUT_RELOC(dst->bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_RELOC(dst->bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, dst_delta);
 	OUT_BATCH(0);	/* dst address upper bits */
 	OUT_BATCH((src_y << 16) | src_x); /* src x1,y1 */
 	OUT_BATCH(src_pitch);
-	OUT_RELOC(src->bo, I915_GEM_DOMAIN_RENDER, 0, 0);
+	OUT_RELOC(src->bo, I915_GEM_DOMAIN_RENDER, 0, src_delta);
 	OUT_BATCH(0);	/* src address upper bits */
 	ADVANCE_BATCH();
 
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index a6d8f9863698..2c262d7d7e79 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -226,10 +226,12 @@ unsigned igt_buf_width(struct igt_buf *buf);
 unsigned igt_buf_height(struct igt_buf *buf);
 
 void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
-			  struct igt_buf *src, unsigned src_x, unsigned src_y,
-			  unsigned width, unsigned height,
-			  int bpp,
-			  struct igt_buf *dst, unsigned dst_x, unsigned dst_y);
+			   struct igt_buf *src, unsigned src_delta,
+			   unsigned src_x, unsigned src_y,
+			   unsigned width, unsigned height,
+			   int bpp,
+			   struct igt_buf *dst, unsigned dst_delta,
+			   unsigned dst_x, unsigned dst_y);
 
 void igt_blitter_fast_copy__raw(int fd,
 				/* src */
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add support for creating planar framebuffers
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (4 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-23 14:50   ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v2 Maarten Lankhorst
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb Maarten Lankhorst
                   ` (11 subsequent siblings)
  17 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

Add support to create planar framebuffers, but don't add formats
that support them yet. This first requires conversion to the RGB24 format.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c             | 75 +++++++++++++++++++++++++++++++++++-------------
 lib/igt_fb.h             | 10 +++++++
 lib/ioctl_wrappers.c     | 11 +++++--
 lib/ioctl_wrappers.h     |  2 +-
 tests/kms_draw_crc.c     |  2 +-
 tests/kms_rotation_crc.c |  5 ++--
 tests/prime_vgem.c       |  2 +-
 7 files changed, 80 insertions(+), 27 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 1251f462d24e..4d6b62a64ded 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -158,14 +158,19 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 	}
 }
 
+static unsigned planar_width(struct format_desc_struct *format, unsigned width, int plane)
+{
+	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
+		return (width + 1) / 2;
+
+	return width;
+}
+
 static unsigned planar_stride(struct format_desc_struct *format, unsigned width, int plane)
 {
 	unsigned cpp = format->plane_bpp[plane] / 8;
 
-	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
-		return (width + 1) / 2 * cpp;
-
-	return width * cpp;
+	return planar_width(format, width, plane) * cpp;
 }
 
 static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
@@ -331,7 +336,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 			    struct format_desc_struct *format,
 			    uint64_t tiling, unsigned size, unsigned stride,
 			    unsigned *size_ret, unsigned *stride_ret,
-			    bool *is_dumb)
+			    uint32_t *offsets, bool *is_dumb)
 {
 	int bo;
 
@@ -340,8 +345,15 @@ static int create_bo_for_fb(int fd, int width, int height,
 	if (tiling || size || stride || format->planes > 1) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, format->drm_id, tiling,
-				 &calculated_size, &calculated_stride);
+		if (format->planes > 1)
+			calc_fb_size_planar(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride, offsets);
+		else {
+			memset(offsets, 0, 4 * sizeof(*offsets));
+			calc_fb_size_packed(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride);
+		}
+
 		if (stride == 0)
 			stride = calculated_stride;
 		if (size == 0)
@@ -407,7 +419,7 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
 				  unsigned *stride_ret, bool *is_dumb)
 {
 	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
-				modifier, 0, stride, size_ret, stride_ret, is_dumb);
+				modifier, 0, stride, size_ret, stride_ret, NULL, is_dumb);
 }
 
 /**
@@ -748,16 +760,20 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 			   struct igt_fb *fb, unsigned bo_size,
 			   unsigned bo_stride)
 {
+	struct format_desc_struct *f = lookup_drm_format(format);
 	uint32_t fb_id;
+	int i;
+
+	igt_assert_f(f, "DRM format %08x not found\n", format);
 
 	memset(fb, 0, sizeof(*fb));
 
 	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,
-					  lookup_drm_format(format),
+	fb->gem_handle = create_bo_for_fb(fd, width, height, f,
 					  tiling, bo_size, bo_stride,
-					  &fb->size, &fb->stride, &fb->is_dumb);
+					  &fb->size, &fb->stride,
+					  fb->offsets, &fb->is_dumb);
 	igt_assert(fb->gem_handle > 0);
 
 	igt_debug("%s(handle=%d, pitch=%d)\n",
@@ -766,22 +782,24 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    tiling != LOCAL_I915_FORMAT_MOD_X_TILED) {
 		do_or_die(__kms_addfb(fd, fb->gem_handle, width, height,
-				      fb->stride, format, tiling,
+				      fb->stride, format, tiling, fb->offsets,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id));
 	} else {
 		uint32_t handles[4];
 		uint32_t pitches[4];
-		uint32_t offsets[4];
 
 		memset(handles, 0, sizeof(handles));
 		memset(pitches, 0, sizeof(pitches));
-		memset(offsets, 0, sizeof(offsets));
 
 		handles[0] = fb->gem_handle;
 		pitches[0] = fb->stride;
+		for (i = 0; i < f->planes; i++) {
+			handles[i] = fb->gem_handle;
+			pitches[i] = fb->stride;
+		}
 
 		do_or_die(drmModeAddFB2(fd, width, height, format,
-					handles, pitches, offsets,
+					handles, pitches, fb->offsets,
 					&fb_id, 0));
 	}
 
@@ -791,6 +809,17 @@ 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;
+
+	/* if f->planes is set, then plane_bpp is valid too so use that. */
+	for (i = 0; i < f->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);
+	}
 
 	return fb_id;
 }
@@ -1127,7 +1156,8 @@ static void destroy_cairo_surface__blit(void *arg)
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0 /* dst_x, dst_y */);
@@ -1143,6 +1173,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 	struct fb_blit_upload *blit;
 	cairo_format_t cairo_format;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
+	uint32_t offsets[4];
 
 	blit = malloc(sizeof(*blit));
 	igt_assert(blit);
@@ -1157,7 +1188,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
 					       0, &blit->linear.size,
 					       &blit->linear.stride,
-					       &blit->linear.is_dumb);
+					       offsets, &blit->linear.is_dumb);
 
 	igt_assert(blit->linear.handle > 0);
 
@@ -1169,7 +1200,8 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
@@ -1257,14 +1289,17 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
  * @fd: open drm file descriptor
  * @fb: pointer to an #igt_fb structure
  *
- * This function stores the contents of the supplied framebuffer into a cairo
- * surface and returns it.
+ * This function stores the contents of the supplied framebuffer's plane
+ * into a cairo surface and returns it.
  *
  * Returns:
  * A pointer to a cairo surface with the contents of the framebuffer.
  */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
+	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
+	igt_assert(fb->num_planes < 2);
+
 	if (fb->cairo_surface == NULL) {
 		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 152798e9896b..77fd88bb7aca 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -50,6 +50,11 @@
  * @size: size in bytes of the underlying backing storage
  * @cairo_surface: optionally attached cairo drawing surface
  * @domain: current domain for cache flushing tracking on i915.ko
+ * @num_planes: Amount of planes on this fb. >1 for planar formats.
+ * @offsets: Offset for each plane in bytes.
+ * @plane_bpp: The bpp for each plane.
+ * @plane_width: The width for each plane.
+ * @plane_height: The height for each plane.
  *
  * Tracking structure for KMS framebuffer objects.
  */
@@ -66,6 +71,11 @@ typedef struct igt_fb {
 	unsigned int size;
 	cairo_surface_t *cairo_surface;
 	unsigned int domain;
+	unsigned int num_planes;
+	uint32_t offsets[4];
+	unsigned int plane_bpp[4];
+	unsigned int plane_width[4];
+	unsigned int plane_height[4];
 } igt_fb_t;
 
 /**
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 39e8469e3985..10d958726da7 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1659,10 +1659,10 @@ void igt_require_fb_modifiers(int fd)
 
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id)
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id)
 {
 	struct drm_mode_fb_cmd2 f;
-	int ret;
+	int ret, i;
 
 	igt_require_fb_modifiers(fd);
 
@@ -1676,6 +1676,13 @@ int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 	f.pitches[0] = stride;
 	f.modifier[0] = modifier;
 
+	for (i = 1; i < 4 && offsets && offsets[i]; i++) {
+		f.handles[i] = handle;
+		f.pitches[i] = stride;
+		f.modifier[i] = modifier;
+		f.offsets[i] = offsets[i];
+	}
+
 	ret = igt_ioctl(fd, DRM_IOCTL_MODE_ADDFB2, &f);
 
 	*buf_id = f.fb_id;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index f7752aeab2c4..13fbe3c103c0 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -236,7 +236,7 @@ void igt_require_fb_modifiers(int fd);
  */
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id);
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id);
 
 /**
  * to_user_pointer:
diff --git a/tests/kms_draw_crc.c b/tests/kms_draw_crc.c
index 723e7a182c95..86dcf39285f3 100644
--- a/tests/kms_draw_crc.c
+++ b/tests/kms_draw_crc.c
@@ -163,7 +163,7 @@ static bool format_is_supported(uint32_t format, uint64_t modifier)
 						   format, modifier,
 						   0, NULL, &stride, NULL);
 	ret =  __kms_addfb(drm_fd, gem_handle, 64, 64,
-			   stride, format, modifier,
+			   stride, format, modifier, NULL,
 			   LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id);
 	drmModeRmFB(drm_fd, fb_id);
 	gem_close(drm_fd, gem_handle);
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index 5b190a0d03cb..f65562bae9eb 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -520,7 +520,7 @@ static void test_plane_rotation_ytiled_obj(data_t *data,
 	igt_assert_eq(ret, 0);
 
 	do_or_die(__kms_addfb(fd, gem_handle, w, h, stride,
-		  format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		  format, tiling, NULL, LOCAL_DRM_MODE_FB_MODIFIERS,
 		  &data->fb.fb_id));
 	data->fb.width = w;
 	data->fb.height = h;
@@ -601,7 +601,8 @@ static void test_plane_rotation_exhaust_fences(data_t *data,
 		}
 
 		ret = (__kms_addfb(fd, gem_handle, w, h, stride,
-		       format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		       format, tiling, NULL,
+		       LOCAL_DRM_MODE_FB_MODIFIERS,
 		       &data2[i].fb.fb_id));
 		if (ret) {
 			igt_warn("failed to create framebuffer\n");
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index a5f75d888bef..763c62e606f6 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -723,7 +723,7 @@ static void test_flip(int i915, int vgem, unsigned hang)
 
 		do_or_die(__kms_addfb(i915, handle[i],
 				      bo[i].width, bo[i].height, bo[i].pitch,
-				      DRM_FORMAT_XRGB8888, I915_TILING_NONE,
+				      DRM_FORMAT_XRGB8888, I915_TILING_NONE, NULL,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id[i]));
 		igt_assert(fb_id[i]);
 	}
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (5 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add support for creating planar framebuffers Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-26 13:56   ` Mika Kahola
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion Maarten Lankhorst
                   ` (10 subsequent siblings)
  17 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

This is required to make the test pass when we start enabling
planar formats in the future.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/intel_batchbuffer.c     | 14 ++++++++------
 lib/intel_batchbuffer.h     |  4 ++--
 tests/gem_concurrent_all.c  |  4 ++--
 tests/gem_read_read_speed.c |  4 ++--
 tests/kms_render.c          | 15 +++++++++------
 5 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 3c1689cd302c..9f162f09658a 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -310,10 +310,12 @@ intel_batchbuffer_data(struct intel_batchbuffer *batch,
  * intel_blt_copy:
  * @batch: batchbuffer object
  * @src_bo: source libdrm buffer object
+ * @src_delta: offset into the source bo, in bytes
  * @src_x1: source pixel x-coordination
  * @src_y1: source pixel y-coordination
  * @src_pitch: @src_bo's pitch in bytes
  * @dst_bo: destination libdrm buffer object
+ * @sdst_delta: offset into the source bo, in bytes
  * @dst_x1: destination pixel x-coordination
  * @dst_y1: destination pixel y-coordination
  * @dst_pitch: @dst_bo's pitch in bytes
@@ -326,8 +328,8 @@ intel_batchbuffer_data(struct intel_batchbuffer *batch,
  */
 void
 intel_blt_copy(struct intel_batchbuffer *batch,
-	       drm_intel_bo *src_bo, int src_x1, int src_y1, int src_pitch,
-	       drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int dst_pitch,
+	       drm_intel_bo *src_bo, uint32_t src_delta, int src_x1, int src_y1, int src_pitch,
+	       drm_intel_bo *dst_bo, uint32_t dst_delta, int dst_x1, int dst_y1, int dst_pitch,
 	       int width, int height, int bpp)
 {
 	const int gen = batch->gen;
@@ -387,10 +389,10 @@ intel_blt_copy(struct intel_batchbuffer *batch,
 		  dst_pitch);
 	OUT_BATCH((dst_y1 << 16) | dst_x1); /* dst x1,y1 */
 	OUT_BATCH(((dst_y1 + height) << 16) | (dst_x1 + width)); /* dst x2,y2 */
-	OUT_RELOC_FENCED(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_RELOC_FENCED(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, dst_delta);
 	OUT_BATCH((src_y1 << 16) | src_x1); /* src x1,y1 */
 	OUT_BATCH(src_pitch);
-	OUT_RELOC_FENCED(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
+	OUT_RELOC_FENCED(src_bo, I915_GEM_DOMAIN_RENDER, 0, src_delta);
 	ADVANCE_BATCH();
 
 #define CMD_POLY_STIPPLE_OFFSET       0x7906
@@ -431,8 +433,8 @@ intel_copy_bo(struct intel_batchbuffer *batch,
 	igt_assert(size % 4096 == 0);
 
 	intel_blt_copy(batch,
-		       src_bo, 0, 0, 4096,
-		       dst_bo, 0, 0, 4096,
+		       src_bo, 0, 0, 0, 4096,
+		       dst_bo, 0, 0, 0, 4096,
 		       4096/4, size/4096, 32);
 }
 
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 2c262d7d7e79..8c8c7ee543dd 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -181,8 +181,8 @@ intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
 
 void
 intel_blt_copy(struct intel_batchbuffer *batch,
-	      drm_intel_bo *src_bo, int src_x1, int src_y1, int src_pitch,
-	      drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int dst_pitch,
+	      drm_intel_bo *src_bo, uint32_t src_delta, int src_x1, int src_y1, int src_pitch,
+	      drm_intel_bo *dst_bo, uint32_t dst_delta, int dst_x1, int dst_y1, int dst_pitch,
 	      int width, int height, int bpp);
 void intel_copy_bo(struct intel_batchbuffer *batch,
 		   drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
index 201b491bc245..620f8c21083a 100644
--- a/tests/gem_concurrent_all.c
+++ b/tests/gem_concurrent_all.c
@@ -874,8 +874,8 @@ static void render_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *s
 static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst, drm_intel_bo *src)
 {
 	intel_blt_copy(b->batch,
-		       src, 0, 0, 4*b->width,
-		       dst, 0, 0, 4*b->width,
+		       src, 0, 0, 0, 4*b->width,
+		       dst, 0, 0, 0, 4*b->width,
 		       b->width, b->height, 32);
 }
 
diff --git a/tests/gem_read_read_speed.c b/tests/gem_read_read_speed.c
index 3dcf440c7f81..d879f1225440 100644
--- a/tests/gem_read_read_speed.c
+++ b/tests/gem_read_read_speed.c
@@ -83,8 +83,8 @@ static drm_intel_bo *bcs_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
 	drm_intel_bo_reference(bo);
 
 	intel_blt_copy(batch,
-		       src, 0, 0, 4*width,
-		       dst, 0, 0, 4*width,
+		       src, 0, 0, 0, 4*width,
+		       dst, 0, 0, 0, 4*width,
 		       width, height, 32);
 
 	return bo;
diff --git a/tests/kms_render.c b/tests/kms_render.c
index 25a0c05b547c..255cf3de39cf 100644
--- a/tests/kms_render.c
+++ b/tests/kms_render.c
@@ -64,7 +64,7 @@ static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
 {
 	drm_intel_bo *dst_bo;
 	drm_intel_bo *src_bo;
-	int bpp;
+	int i;
 	static drm_intel_bufmgr *bufmgr;
 	struct intel_batchbuffer *batch;
 	uint32_t devid;
@@ -79,7 +79,7 @@ static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
 	igt_assert(dst_fb->drm_format == src_fb->drm_format);
 	igt_assert(src_fb->drm_format == DRM_FORMAT_RGB565 ||
 	       igt_drm_format_to_bpp(src_fb->drm_format) != 16);
-	bpp = igt_drm_format_to_bpp(src_fb->drm_format);
+
 	dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
 					 dst_fb->gem_handle);
 	igt_assert(dst_bo);
@@ -87,10 +87,13 @@ static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
 					 src_fb->gem_handle);
 	igt_assert(src_bo);
 
-	intel_blt_copy(batch,
-		       src_bo, 0, 0, src_fb->width * bpp / 8,
-		       dst_bo, 0, 0, dst_fb->width * bpp / 8,
-		       src_fb->width, src_fb->height, bpp);
+	for (i = 0; i < src_fb->num_planes; i++) {
+		intel_blt_copy(batch,
+			      src_bo, src_fb->offsets[i], 0, 0, src_fb->stride,
+			      dst_bo, dst_fb->offsets[i], 0, 0, dst_fb->stride,
+			      src_fb->plane_width[i], src_fb->plane_height[i],
+			      src_fb->plane_bpp[i]);
+	}
 	intel_batchbuffer_flush(batch);
 	gem_quiescent_gpu(drm_fd);
 
-- 
2.15.1

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

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

* [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (6 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb Maarten Lankhorst
@ 2018-01-23 12:56 ` Maarten Lankhorst
  2018-01-31 13:45   ` Mika Kahola
  2018-01-23 14:28 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
                   ` (9 subsequent siblings)
  17 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 12:56 UTC (permalink / raw)
  To: igt-dev

For NV12 a format conversion is needed. Because YUV formats are not
fully defined with just a fourcc, I've chosen BT.709 limited range.
This puts the pixel center of the CbCr components between the top
left Y and bottom left Y:

Y   Y   Y   Y
UV      UV
Y   Y   Y   Y

Some work is put into optimising the conversion routines in order to
make it fast enough. Before converting nv12 to rgb24, it is copied to
a temporary buffer to take advantage of memory caching. This is
approximately 20x faster than directly reading the BO.

When testing on my KBL with a 1080p buffer, it takes approximately
.1s to convert either way, this is fast enough not to bother optimising
even further for me.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 318 insertions(+), 72 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 4d6b62a64ded..43b71e643586 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -70,6 +70,7 @@ static struct format_desc_struct {
 	DF(XRGB8888,	RGB24,		32, 24),
 	DF(XRGB2101010,	RGB30,		32, 30),
 	DF(ARGB8888,	ARGB32,		32, 32),
+	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
 };
 #undef DF
 
@@ -363,14 +364,20 @@ static int create_bo_for_fb(int fd, int width, int height,
 			*is_dumb = false;
 
 		if (is_i915_device(fd)) {
-			uint32_t *ptr;
+			uint8_t *ptr;
 
 			bo = gem_create(fd, size);
 			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
 
 			/* Ensure the framebuffer is preallocated */
-			ptr = gem_mmap__gtt(fd, bo, size, PROT_READ);
-			igt_assert(*ptr == 0);
+			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);
+			}
 			gem_munmap(ptr, size);
 
 			if (size_ret)
@@ -1126,103 +1133,117 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 		     drm_format, igt_format_str(drm_format));
 }
 
+struct fb_blit_linear {
+	uint32_t handle;
+	unsigned size, stride;
+	uint8_t *map;
+	bool is_dumb;
+	uint32_t offsets[4];
+};
+
 struct fb_blit_upload {
 	int fd;
 	struct igt_fb *fb;
-	struct {
-		uint32_t handle;
-		unsigned size, stride;
-		uint8_t *map;
-		bool is_dumb;
-	} linear;
+	struct fb_blit_linear linear;
 };
 
-static void destroy_cairo_surface__blit(void *arg)
+static void free_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
 {
-	struct fb_blit_upload *blit = arg;
-	struct igt_fb *fb = blit->fb;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
+	int i;
 
-	gem_munmap(blit->linear.map, blit->linear.size);
-	fb->cairo_surface = NULL;
+	gem_munmap(linear->map, linear->size);
+	gem_set_domain(fd, linear->handle,
+		       I915_GEM_DOMAIN_GTT, 0);
+
+	for (i = 0; i < fb->num_planes; i++)
+		igt_blitter_fast_copy__raw(fd,
+					   linear->handle,
+					   linear->offsets[i],
+					   linear->stride,
+					   I915_TILING_NONE,
+					   0, 0, /* src_x, src_y */
+					   fb->plane_width[i], fb->plane_height[i],
+					   fb->plane_bpp[i],
+					   fb->gem_handle,
+					   fb->offsets[i],
+					   fb->stride,
+					   obj_tiling,
+					   0, 0 /* dst_x, dst_y */);
+
+	gem_sync(fd, linear->handle);
+	gem_close(fd, linear->handle);
+}
 
-	gem_set_domain(blit->fd, blit->linear.handle,
-			I915_GEM_DOMAIN_GTT, 0);
+static void destroy_cairo_surface__blit(void *arg)
+{
+	struct fb_blit_upload *blit = arg;
 
-	igt_blitter_fast_copy__raw(blit->fd,
-				   blit->linear.handle, 0,
-				   blit->linear.stride,
-				   I915_TILING_NONE,
-				   0, 0, /* src_x, src_y */
-				   fb->width, fb->height,
-				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle,
-				   fb->offsets[0],
-				   fb->stride,
-				   obj_tiling,
-				   0, 0 /* dst_x, dst_y */);
-
-	gem_sync(blit->fd, blit->linear.handle);
-	gem_close(blit->fd, blit->linear.handle);
+	blit->fb->cairo_surface = NULL;
+
+	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
 
 	free(blit);
 }
 
-static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
+static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
 {
-	struct fb_blit_upload *blit;
-	cairo_format_t cairo_format;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
-	uint32_t offsets[4];
-
-	blit = malloc(sizeof(*blit));
-	igt_assert(blit);
+	int i;
 
 	/*
 	 * We create a linear BO that we'll map for the CPU to write to (using
 	 * cairo). This linear bo will be then blitted to its final
 	 * destination, tiling it at the same time.
 	 */
-	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
+	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
 					       lookup_drm_format(fb->drm_format),
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
-					       0, &blit->linear.size,
-					       &blit->linear.stride,
-					       offsets, &blit->linear.is_dumb);
-
-	igt_assert(blit->linear.handle > 0);
+					       0, &linear->size,
+					       &linear->stride,
+					       linear->offsets, &linear->is_dumb);
 
-	blit->fd = fd;
-	blit->fb = fb;
+	igt_assert(linear->handle > 0);
 
 	/* Copy fb content to linear BO */
-	gem_set_domain(fd, blit->linear.handle,
+	gem_set_domain(fd, linear->handle,
 			I915_GEM_DOMAIN_GTT, 0);
 
-	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle,
-				   fb->offsets[0],
-				   fb->stride,
-				   obj_tiling,
-				   0, 0, /* src_x, src_y */
-				   fb->width, fb->height,
-				   igt_drm_format_to_bpp(fb->drm_format),
-				   blit->linear.handle, 0,
-				   blit->linear.stride,
-				   I915_TILING_NONE,
-				   0, 0 /* dst_x, dst_y */);
-
-	gem_sync(fd, blit->linear.handle);
-
-	gem_set_domain(fd, blit->linear.handle,
+	for (i = 0; i < fb->num_planes; i++)
+		igt_blitter_fast_copy__raw(fd,
+					  fb->gem_handle,
+					  fb->offsets[i],
+					  fb->stride,
+					  obj_tiling,
+					  0, 0, /* src_x, src_y */
+					  fb->plane_width[i], fb->plane_height[i],
+					  fb->plane_bpp[i],
+					  linear->handle, linear->offsets[i],
+					  linear->stride,
+					  I915_TILING_NONE,
+					  0, 0 /* dst_x, dst_y */);
+
+	gem_sync(fd, linear->handle);
+
+	gem_set_domain(fd, linear->handle,
 		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 
 	/* Setup cairo context */
-	blit->linear.map = gem_mmap__cpu(fd,
-					 blit->linear.handle,
-					 0,
-					 blit->linear.size,
-					 PROT_READ | PROT_WRITE);
+	linear->map = gem_mmap__cpu(fd, linear->handle,
+				    0, linear->size, PROT_READ | PROT_WRITE);
+}
+
+static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
+{
+	struct fb_blit_upload *blit;
+	cairo_format_t cairo_format;
+
+	blit = malloc(sizeof(*blit));
+	igt_assert(blit);
+
+	blit->fd = fd;
+	blit->fb = fb;
+	setup_linear_mapping(fd, fb, &blit->linear);
 
 	cairo_format = drm_format_to_cairo(fb->drm_format);
 	fb->cairo_surface =
@@ -1284,6 +1305,232 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
 				    fb, destroy_cairo_surface__gtt);
 }
 
+struct fb_convert_blit_upload {
+	int fd;
+	struct igt_fb *fb;
+
+	struct {
+		uint8_t *map;
+		unsigned stride, size;
+	} rgb24;
+
+	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 void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
+{
+	int i, j;
+	const uint8_t *y, *uv;
+	uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
+	uint8_t *buf = malloc(blit->linear.size);
+
+	/*
+	 * 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.
+	 */
+	memcpy(buf, blit->linear.map, blit->linear.size);
+	y = &buf[blit->linear.offsets[0]];
+	uv = &buf[blit->linear.offsets[1]];
+
+	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);
+
+			cb = uv[j & ~1] - 128.f;
+			cr = uv[j | 1] - 128.f;
+
+			r_ = 0.000f * cb +  1.793f * cr;
+			g_ = -0.213f * cb + -0.533f * cr;
+			b_ = 2.112f * cb +  0.000f * cr;
+
+			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
+			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
+
+			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 += 2 * rgb24_stride;
+		y += 2 * planar_stride;
+		uv += planar_stride;
+	}
+
+	if (fb->height & 1) {
+		/* Convert last row */
+		for (j = 0; j < fb->width; j++) {
+			float r_, g_, b_, y0, cb, cr;
+			/* Convert single pixel */
+
+			cb = uv[j & ~1] - 128.f;
+			cr = uv[j | 1] - 128.f;
+
+			y0 = 1.164f * (y[j] - 16.f);
+			r_ =  0.000f * cb +  1.793f * cr;
+			g_ = -0.213f * cb + -0.533f * cr;
+			b_ =  2.112f * cb +  0.000f * cr;
+
+			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
+			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
+			rgb24[j * 4] = clamprgb(y0 + b_);
+		}
+	}
+
+	free(buf);
+}
+
+static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
+{
+	int i, j;
+	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
+	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
+	const uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride;
+	unsigned planar_stride = blit->linear.stride;
+
+	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.709 */
+
+		for (j = 0; j < fb->plane_width[0]; j++) {
+			float yf = 0.183f * rgb24[j * 4 + 2] +
+				   0.614f * rgb24[j * 4 + 1] +
+				   0.062f * rgb24[j * 4] + 16;
+
+			y[j] = (uint8_t)yf;
+		}
+
+		rgb24 += rgb24_stride;
+		y += planar_stride;
+	}
+
+	rgb24 = blit->rgb24.map;
+
+	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.101f/2 * rgb24[j * 8 + 2] +
+				   -0.101f/2 * rgb24[j * 8 + 2 + rgb24_stride] +
+				   -0.339f/2 * rgb24[j * 8 + 1] +
+				   -0.339f/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.339f/2 * rgb24[j * 8 + 1] +
+				   -0.339f/2 * rgb24[j * 8 + 1 + rgb24_stride] +
+				   -0.040f/2 * rgb24[j * 8] +
+				   -0.040f/2 * rgb24[j * 8 + rgb24_stride] + 128;
+			uv[j * 2] = (uint8_t)uf;
+			uv[j * 2 + 1] = (uint8_t)vf;
+		}
+
+		rgb24 += 2 * rgb24_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.101f * rgb24[j * 8 + 2] +
+				   -0.339f * rgb24[j * 8 + 1] +
+				    0.439f * rgb24[j * 8] + 128;
+			float vf =  0.439f * rgb24[j * 8 + 2] +
+				   -0.339f * rgb24[j * 8 + 1] +
+				   -0.040f * rgb24[j * 8] + 128;
+
+			uv[j * 2] = (uint8_t)uf;
+			uv[j * 2 + 1] = (uint8_t)vf;
+		}
+	}
+}
+
+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);
+
+	munmap(blit->rgb24.map, blit->rgb24.size);
+
+	if (blit->linear.handle)
+		free_linear_mapping(blit->fd, blit->fb, &blit->linear);
+	else
+		gem_munmap(blit->linear.map, fb->size);
+
+	free(blit);
+
+	fb->cairo_surface = NULL;
+}
+
+static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
+{
+	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
+	igt_assert(blit);
+
+	blit->fd = fd;
+	blit->fb = fb;
+	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
+	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height, sysconf(_SC_PAGESIZE));
+	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	igt_assert(blit->rgb24.map != MAP_FAILED);
+
+	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
+		setup_linear_mapping(fd, fb, &blit->linear);
+	} else {
+		blit->linear.handle = 0;
+		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
+					      PROT_READ | PROT_WRITE);
+		igt_assert(blit->linear.map);
+		blit->linear.stride = fb->stride;
+		blit->linear.size = fb->size;
+		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);
+
+	fb->cairo_surface =
+		cairo_image_surface_create_for_data(blit->rgb24.map,
+						    CAIRO_FORMAT_RGB24,
+						    fb->width, fb->height,
+						    blit->rgb24.stride);
+
+	cairo_surface_set_user_data(fb->cairo_surface,
+				    (cairo_user_data_key_t *)create_cairo_surface__convert,
+				    blit, destroy_cairo_surface__convert);
+}
+
 /**
  * igt_get_cairo_surface:
  * @fd: open drm file descriptor
@@ -1297,11 +1544,10 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
  */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
-	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
-	igt_assert(fb->num_planes < 2);
-
 	if (fb->cairo_surface == NULL) {
-		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+		if (fb->num_planes > 1)
+			create_cairo_surface__convert(fd, fb);
+		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
 			create_cairo_surface__blit(fd, fb);
 		else
-- 
2.15.1

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

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

* [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_fb: Add support for the NV12 format.
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (7 preceding siblings ...)
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion Maarten Lankhorst
@ 2018-01-23 14:28 ` Patchwork
  2018-01-23 15:41 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-23 14:28 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format.
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

IGT patchset tested on top of latest successful build
cb2e65dae7e8ca3f388f43aeec3e7d7dc5d2cfb4 man: Update for new igt-dev mailing list

with latest DRM-Tip kernel build CI_DRM_3673
cbdcbeb1eb09 drm-tip: 2018y-01m-23d-13h-00m-40s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                dmesg-fail -> DMESG-WARN (fi-elk-e7500) fdo#103989
Test kms_addfb_basic:
        Subgroup addfb25-bad-modifier:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-framebuffer-vs-set-tiling:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-modifier-no-flag:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-x-tiled:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-x-tiled-mismatch:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-yf-tiled:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-y-tiled:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup addfb25-y-tiled-small:
                skip       -> FAIL       (fi-gdg-551)
                skip       -> FAIL       (fi-blb-e6850)
                skip       -> FAIL       (fi-pnv-d510)
                skip       -> FAIL       (fi-bwr-2160)
                skip       -> FAIL       (fi-elk-e7500)
                skip       -> FAIL       (fi-ilk-650)
                skip       -> FAIL       (fi-snb-2520m)
                skip       -> FAIL       (fi-snb-2600)
                skip       -> FAIL       (fi-ivb-3520m)
                skip       -> FAIL       (fi-ivb-3770)
                skip       -> FAIL       (fi-byt-j1900)
                skip       -> FAIL       (fi-byt-n2820)
                skip       -> FAIL       (fi-hsw-4770)
                skip       -> FAIL       (fi-hsw-4770r)
                skip       -> FAIL       (fi-bdw-5557u)
                skip       -> FAIL       (fi-bdw-gvtdvm)
                skip       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup bad-pitch-0:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup bad-pitch-1024:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup bad-pitch-128:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557u)
                pass       -> FAIL       (fi-bdw-gvtdvm)
                pass       -> FAIL       (fi-bsw-n3050)
                pass       -> FAIL       (fi-skl-6260u)
                pass       -> FAIL       (fi-skl-6600u)
                pass       -> FAIL       (fi-skl-6700hq)
                pass       -> FAIL       (fi-skl-6700k2)
                pass       -> FAIL       (fi-skl-6770hq)
                pass       -> FAIL       (fi-skl-guc)
                pass       -> FAIL       (fi-skl-gvtdvm)
                pass       -> FAIL       (fi-bxt-dsi)
                pass       -> FAIL       (fi-bxt-j4205)
                pass       -> FAIL       (fi-kbl-7500u)
                pass       -> FAIL       (fi-kbl-7560u)
                pass       -> FAIL       (fi-kbl-r)
                pass       -> FAIL       (fi-glk-1)
        Subgroup bad-pitch-256:
                pass       -> FAIL       (fi-gdg-551)
                pass       -> FAIL       (fi-blb-e6850)
                pass       -> FAIL       (fi-pnv-d510)
                pass       -> FAIL       (fi-bwr-2160)
                pass       -> FAIL       (fi-elk-e7500)
                pass       -> FAIL       (fi-ilk-650)
                pass       -> FAIL       (fi-snb-2520m)
                pass       -> FAIL       (fi-snb-2600)
                pass       -> FAIL       (fi-ivb-3520m)
                pass       -> FAIL       (fi-ivb-3770)
                pass       -> FAIL       (fi-byt-j1900)
                pass       -> FAIL       (fi-byt-n2820)
                pass       -> FAIL       (fi-hsw-4770)
                pass       -> FAIL       (fi-hsw-4770r)
                pass       -> FAIL       (fi-bdw-5557

== Logs ==

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

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

* [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v2.
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add support for creating planar framebuffers Maarten Lankhorst
@ 2018-01-23 14:50   ` Maarten Lankhorst
  2018-01-24 10:53     ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v3 Maarten Lankhorst
  0 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-23 14:50 UTC (permalink / raw)
  To: igt-dev

Add support to create planar framebuffers, but don't add formats
that support them yet. This first requires conversion to the RGB24 format.

Changes since v1:
- Don't crash in igt_create_bo_with_dimensions().

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c             | 76 +++++++++++++++++++++++++++++++++++-------------
 lib/igt_fb.h             | 10 +++++++
 lib/ioctl_wrappers.c     | 11 +++++--
 lib/ioctl_wrappers.h     |  2 +-
 tests/kms_draw_crc.c     |  2 +-
 tests/kms_rotation_crc.c |  5 ++--
 tests/prime_vgem.c       |  2 +-
 7 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 1251f462d24e..c6525e17afe3 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -158,14 +158,19 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 	}
 }
 
+static unsigned planar_width(struct format_desc_struct *format, unsigned width, int plane)
+{
+	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
+		return (width + 1) / 2;
+
+	return width;
+}
+
 static unsigned planar_stride(struct format_desc_struct *format, unsigned width, int plane)
 {
 	unsigned cpp = format->plane_bpp[plane] / 8;
 
-	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
-		return (width + 1) / 2 * cpp;
-
-	return width * cpp;
+	return planar_width(format, width, plane) * cpp;
 }
 
 static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
@@ -331,7 +336,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 			    struct format_desc_struct *format,
 			    uint64_t tiling, unsigned size, unsigned stride,
 			    unsigned *size_ret, unsigned *stride_ret,
-			    bool *is_dumb)
+			    uint32_t *offsets, bool *is_dumb)
 {
 	int bo;
 
@@ -340,8 +345,16 @@ static int create_bo_for_fb(int fd, int width, int height,
 	if (tiling || size || stride || format->planes > 1) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, format->drm_id, tiling,
-				 &calculated_size, &calculated_stride);
+		if (format->planes > 1)
+			calc_fb_size_planar(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride, offsets);
+		else {
+			if (offsets)
+				memset(offsets, 0, 4 * sizeof(*offsets));
+			calc_fb_size_packed(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride);
+		}
+
 		if (stride == 0)
 			stride = calculated_stride;
 		if (size == 0)
@@ -407,7 +420,7 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
 				  unsigned *stride_ret, bool *is_dumb)
 {
 	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
-				modifier, 0, stride, size_ret, stride_ret, is_dumb);
+				modifier, 0, stride, size_ret, stride_ret, NULL, is_dumb);
 }
 
 /**
@@ -748,16 +761,20 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 			   struct igt_fb *fb, unsigned bo_size,
 			   unsigned bo_stride)
 {
+	struct format_desc_struct *f = lookup_drm_format(format);
 	uint32_t fb_id;
+	int i;
+
+	igt_assert_f(f, "DRM format %08x not found\n", format);
 
 	memset(fb, 0, sizeof(*fb));
 
 	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,
-					  lookup_drm_format(format),
+	fb->gem_handle = create_bo_for_fb(fd, width, height, f,
 					  tiling, bo_size, bo_stride,
-					  &fb->size, &fb->stride, &fb->is_dumb);
+					  &fb->size, &fb->stride,
+					  fb->offsets, &fb->is_dumb);
 	igt_assert(fb->gem_handle > 0);
 
 	igt_debug("%s(handle=%d, pitch=%d)\n",
@@ -766,22 +783,24 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    tiling != LOCAL_I915_FORMAT_MOD_X_TILED) {
 		do_or_die(__kms_addfb(fd, fb->gem_handle, width, height,
-				      fb->stride, format, tiling,
+				      fb->stride, format, tiling, fb->offsets,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id));
 	} else {
 		uint32_t handles[4];
 		uint32_t pitches[4];
-		uint32_t offsets[4];
 
 		memset(handles, 0, sizeof(handles));
 		memset(pitches, 0, sizeof(pitches));
-		memset(offsets, 0, sizeof(offsets));
 
 		handles[0] = fb->gem_handle;
 		pitches[0] = fb->stride;
+		for (i = 0; i < f->planes; i++) {
+			handles[i] = fb->gem_handle;
+			pitches[i] = fb->stride;
+		}
 
 		do_or_die(drmModeAddFB2(fd, width, height, format,
-					handles, pitches, offsets,
+					handles, pitches, fb->offsets,
 					&fb_id, 0));
 	}
 
@@ -791,6 +810,17 @@ 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;
+
+	/* if f->planes is set, then plane_bpp is valid too so use that. */
+	for (i = 0; i < f->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);
+	}
 
 	return fb_id;
 }
@@ -1127,7 +1157,8 @@ static void destroy_cairo_surface__blit(void *arg)
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0 /* dst_x, dst_y */);
@@ -1143,6 +1174,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 	struct fb_blit_upload *blit;
 	cairo_format_t cairo_format;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
+	uint32_t offsets[4];
 
 	blit = malloc(sizeof(*blit));
 	igt_assert(blit);
@@ -1157,7 +1189,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
 					       0, &blit->linear.size,
 					       &blit->linear.stride,
-					       &blit->linear.is_dumb);
+					       offsets, &blit->linear.is_dumb);
 
 	igt_assert(blit->linear.handle > 0);
 
@@ -1169,7 +1201,8 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
@@ -1257,14 +1290,17 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
  * @fd: open drm file descriptor
  * @fb: pointer to an #igt_fb structure
  *
- * This function stores the contents of the supplied framebuffer into a cairo
- * surface and returns it.
+ * This function stores the contents of the supplied framebuffer's plane
+ * into a cairo surface and returns it.
  *
  * Returns:
  * A pointer to a cairo surface with the contents of the framebuffer.
  */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
+	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
+	igt_assert(fb->num_planes < 2);
+
 	if (fb->cairo_surface == NULL) {
 		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 152798e9896b..77fd88bb7aca 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -50,6 +50,11 @@
  * @size: size in bytes of the underlying backing storage
  * @cairo_surface: optionally attached cairo drawing surface
  * @domain: current domain for cache flushing tracking on i915.ko
+ * @num_planes: Amount of planes on this fb. >1 for planar formats.
+ * @offsets: Offset for each plane in bytes.
+ * @plane_bpp: The bpp for each plane.
+ * @plane_width: The width for each plane.
+ * @plane_height: The height for each plane.
  *
  * Tracking structure for KMS framebuffer objects.
  */
@@ -66,6 +71,11 @@ typedef struct igt_fb {
 	unsigned int size;
 	cairo_surface_t *cairo_surface;
 	unsigned int domain;
+	unsigned int num_planes;
+	uint32_t offsets[4];
+	unsigned int plane_bpp[4];
+	unsigned int plane_width[4];
+	unsigned int plane_height[4];
 } igt_fb_t;
 
 /**
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 39e8469e3985..10d958726da7 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1659,10 +1659,10 @@ void igt_require_fb_modifiers(int fd)
 
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id)
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id)
 {
 	struct drm_mode_fb_cmd2 f;
-	int ret;
+	int ret, i;
 
 	igt_require_fb_modifiers(fd);
 
@@ -1676,6 +1676,13 @@ int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 	f.pitches[0] = stride;
 	f.modifier[0] = modifier;
 
+	for (i = 1; i < 4 && offsets && offsets[i]; i++) {
+		f.handles[i] = handle;
+		f.pitches[i] = stride;
+		f.modifier[i] = modifier;
+		f.offsets[i] = offsets[i];
+	}
+
 	ret = igt_ioctl(fd, DRM_IOCTL_MODE_ADDFB2, &f);
 
 	*buf_id = f.fb_id;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index f7752aeab2c4..13fbe3c103c0 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -236,7 +236,7 @@ void igt_require_fb_modifiers(int fd);
  */
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id);
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id);
 
 /**
  * to_user_pointer:
diff --git a/tests/kms_draw_crc.c b/tests/kms_draw_crc.c
index 723e7a182c95..86dcf39285f3 100644
--- a/tests/kms_draw_crc.c
+++ b/tests/kms_draw_crc.c
@@ -163,7 +163,7 @@ static bool format_is_supported(uint32_t format, uint64_t modifier)
 						   format, modifier,
 						   0, NULL, &stride, NULL);
 	ret =  __kms_addfb(drm_fd, gem_handle, 64, 64,
-			   stride, format, modifier,
+			   stride, format, modifier, NULL,
 			   LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id);
 	drmModeRmFB(drm_fd, fb_id);
 	gem_close(drm_fd, gem_handle);
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index 5b190a0d03cb..f65562bae9eb 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -520,7 +520,7 @@ static void test_plane_rotation_ytiled_obj(data_t *data,
 	igt_assert_eq(ret, 0);
 
 	do_or_die(__kms_addfb(fd, gem_handle, w, h, stride,
-		  format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		  format, tiling, NULL, LOCAL_DRM_MODE_FB_MODIFIERS,
 		  &data->fb.fb_id));
 	data->fb.width = w;
 	data->fb.height = h;
@@ -601,7 +601,8 @@ static void test_plane_rotation_exhaust_fences(data_t *data,
 		}
 
 		ret = (__kms_addfb(fd, gem_handle, w, h, stride,
-		       format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		       format, tiling, NULL,
+		       LOCAL_DRM_MODE_FB_MODIFIERS,
 		       &data2[i].fb.fb_id));
 		if (ret) {
 			igt_warn("failed to create framebuffer\n");
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index a5f75d888bef..763c62e606f6 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -723,7 +723,7 @@ static void test_flip(int i915, int vgem, unsigned hang)
 
 		do_or_die(__kms_addfb(i915, handle[i],
 				      bo[i].width, bo[i].height, bo[i].pitch,
-				      DRM_FORMAT_XRGB8888, I915_TILING_NONE,
+				      DRM_FORMAT_XRGB8888, I915_TILING_NONE, NULL,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id[i]));
 		igt_assert(fb_id[i]);
 	}
-- 
2.15.1

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

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

* [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev2)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (8 preceding siblings ...)
  2018-01-23 14:28 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
@ 2018-01-23 15:41 ` Patchwork
  2018-01-23 19:47 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-23 15:41 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev2)
URL   : https://patchwork.freedesktop.org/series/36965/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
37bd27f28a868c287faf361864a16e77b8d9246f tools/intel_vbt_decode: add --describe option

with latest DRM-Tip kernel build CI_DRM_3673
cbdcbeb1eb09 drm-tip: 2018y-01m-23d-13h-00m-40s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                dmesg-fail -> DMESG-WARN (fi-elk-e7500) fdo#103989

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:423s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:436s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:376s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:491s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:281s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:485s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:488s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:471s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:459s
fi-elk-e7500     total:224  pass:168  dwarn:10  dfail:0   fail:0   skip:45 
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:278s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:514s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:393s
fi-hsw-4770r     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:400s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:413s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:451s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:421s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:461s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:500s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:501s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:583s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:431s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:512s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:530s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:494s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:482s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:418s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:434s
fi-snb-2520m     total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:518s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:405s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:566s
fi-glk-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:473s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
@ 2018-01-23 15:50   ` Ville Syrjälä
  2018-01-24 12:26     ` Maarten Lankhorst
  2018-01-31 17:03   ` Ville Syrjälä
  1 sibling, 1 reply; 47+ messages in thread
From: Ville Syrjälä @ 2018-01-23 15:50 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

On Tue, Jan 23, 2018 at 01:56:35PM +0100, Maarten Lankhorst wrote:
> This will allow support for NV12 in the future, where igt_get_cairo_ctx
> will return a RGB image to draw with, which will be converted in
> igt_put_cairo_ctx so tests don't have to add special support for NV12.

Why do we need a special funciton? As in, can't you just do it the
same as we handle the gtt vs. blit stuff?

> 
> This is the same as cairo_destroy + checking for errors, but not all
> tests use this correctly so it's better to have a single handler for it.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c                      | 34 ++++++++++++++++++++++++----------
>  lib/igt_fb.h                      |  1 +
>  tests/kms_chv_cursor_fail.c       |  3 +--
>  tests/kms_color.c                 |  4 ++--
>  tests/kms_concurrent.c            |  3 +--
>  tests/kms_crtc_background_color.c |  2 +-
>  tests/kms_cursor_crc.c            | 23 +++++++++++++++++++----
>  tests/kms_flip.c                  |  3 +--
>  tests/kms_mmap_write_crc.c        |  4 ++--
>  tests/kms_plane.c                 |  9 +++------
>  tests/kms_plane_multiple.c        |  3 +--
>  tests/kms_plane_scaling.c         |  3 +--
>  tests/kms_psr_sink_crc.c          |  2 +-
>  tests/kms_render.c                |  2 +-
>  tests/kms_rotation_crc.c          |  2 +-
>  tests/kms_setmode.c               |  2 +-
>  tests/testdisplay.c               |  8 ++------
>  17 files changed, 63 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index ded639e833f1..39a83bae178a 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -771,8 +771,7 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_color(cr, 0, 0, width, height, r, g, b);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -809,8 +808,7 @@ unsigned int igt_create_pattern_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_test_pattern(cr, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -853,8 +851,7 @@ unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_color(cr, 0, 0, width, height, r, g, b);
>  	igt_paint_test_pattern(cr, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -897,8 +894,7 @@ unsigned int igt_create_image_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_image(cr, filename, 0, 0, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -998,7 +994,7 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
>  			layout.right.x, layout.right.y,
>  			layout.right.width, layout.right.height);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, &fb, cr);
>  
>  	return fb_id;
>  }
> @@ -1206,7 +1202,7 @@ cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>   *
>   * This initializes a cairo surface for @fb and then allocates a drawing context
>   * for it. The return cairo drawing context should be released by calling
> - * cairo_destroy(). This also sets a default font for drawing text on
> + * igt_put_cairo_ctx(). This also sets a default font for drawing text on
>   * framebuffers.
>   *
>   * Returns:
> @@ -1229,6 +1225,24 @@ cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb)
>  	return cr;
>  }
>  
> +/**
> + * igt_put_cairo_ctx:
> + * @fd: open i915 drm file descriptor
> + * @fb: pointer to an #igt_fb structure
> + * @cr: the cairo context returned by igt_get_cairo_ctx.
> + *
> + * This releases the cairo surface @cr returned by igt_get_cairo_ctx()
> + * for @fb, and writes the changes out to the framebuffer if cairo doesn't
> + * have native support for the format.
> + */
> +void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr)
> +{
> +	cairo_status_t ret = cairo_status(cr);
> +	igt_assert_f(ret == CAIRO_STATUS_SUCCESS, "Cairo failed to draw with %s\n", cairo_status_to_string(ret));
> +
> +	cairo_destroy(cr);
> +}
> +
>  /**
>   * igt_remove_fb:
>   * @fd: open i915 drm file descriptor
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index d30a7340c76e..3004f0656029 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -131,6 +131,7 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
>  cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
>  cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
> +void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr);
>  void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
>  			 double r, double g, double b);
>  void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
> diff --git a/tests/kms_chv_cursor_fail.c b/tests/kms_chv_cursor_fail.c
> index 3e74df1142da..1bcf8469088e 100644
> --- a/tests/kms_chv_cursor_fail.c
> +++ b/tests/kms_chv_cursor_fail.c
> @@ -87,8 +87,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
>  	else
>  		igt_paint_color_alpha(cr, 0, 0, data->fb.width, data->fb.height,
>  				      0.0, 0.0, 0.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  }
>  
>  static void cursor_move(data_t *data, int x, int y, int i)
> diff --git a/tests/kms_color.c b/tests/kms_color.c
> index 3b0a88802c93..dc4fcce241be 100644
> --- a/tests/kms_color.c
> +++ b/tests/kms_color.c
> @@ -86,7 +86,7 @@ static void paint_gradient_rectangles(data_t *data,
>  					       colors[i].b);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  static void paint_rectangles(data_t *data,
> @@ -103,7 +103,7 @@ static void paint_rectangles(data_t *data,
>  				colors[i].r, colors[i].g, colors[i].b);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  static double *generate_table(uint32_t lut_size, double exp)
> diff --git a/tests/kms_concurrent.c b/tests/kms_concurrent.c
> index 3b2e601505c4..283acf8c8a7e 100644
> --- a/tests/kms_concurrent.c
> +++ b/tests/kms_concurrent.c
> @@ -148,8 +148,7 @@ create_fb_for_mode_position(data_t *data, drmModeModeInfo *mode,
>  				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
>  	}
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
>  }
>  
>  static void
> diff --git a/tests/kms_crtc_background_color.c b/tests/kms_crtc_background_color.c
> index e99c67bd185e..6407e19bafce 100644
> --- a/tests/kms_crtc_background_color.c
> +++ b/tests/kms_crtc_background_color.c
> @@ -69,7 +69,7 @@ paint_background(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
>  	b = (double) ((background & 0xFF0000) >> 16) / 255.0;
>  	igt_paint_color_alpha(cr, 0, 0, w, h, r, g, b, alpha);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->gfx_fd, &data->fb, cr);
>  }
>  
>  static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
> diff --git a/tests/kms_cursor_crc.c b/tests/kms_cursor_crc.c
> index 4c5e00c074a5..a164839ee2cc 100644
> --- a/tests/kms_cursor_crc.c
> +++ b/tests/kms_cursor_crc.c
> @@ -141,13 +141,16 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
>  	igt_crc_t crc, ref_crc;
>  	igt_plane_t *cursor;
> -	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
> +	cairo_t *cr;
>  	int ret = 0;
>  
>  	igt_print_activity();
>  
>  	/* Hardware test */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_test_pattern(cr, data->screenw, data->screenh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  	cursor_enable(data);
>  	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
>  	igt_plane_set_position(cursor, x, y);
> @@ -190,7 +193,9 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_display_commit(display);
>  
>  	/* Now render the same in software and collect crc */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	draw_cursor(cr, x, y, data->curw, data->curh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  	igt_display_commit(display);
>  
>  	igt_wait_for_vblank(data->drm_fd, data->pipe);
> @@ -198,20 +203,25 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_assert_crc_equal(&crc, &ref_crc);
>  
>  	/* Clear screen afterwards */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_color(cr, 0, 0, data->screenw, data->screenh, 0.0, 0.0, 0.0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  }
>  
>  static void do_fail_test(data_t *data, int x, int y, int expect)
>  {
>  	igt_display_t *display = &data->display;
>  	igt_plane_t *cursor;
> -	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
> +	cairo_t *cr;
>  	int ret;
>  
>  	igt_print_activity();
>  
>  	/* Hardware test */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_test_pattern(cr, data->screenw, data->screenh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  	cursor_enable(data);
>  	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
>  	igt_plane_set_position(cursor, x, y);
> @@ -446,7 +456,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
>  	draw_cursor(cr, 0, 0, cur_w, cur_h);
> -	igt_assert(cairo_status(cr) == 0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  }
>  
>  static bool has_nonsquare_cursors(uint32_t devid)
> @@ -486,6 +496,7 @@ static void test_cursor_size(data_t *data)
>  	/* Use a solid white rectangle as the cursor */
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
>  	igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  
>  	/* Hardware test loop */
>  	cursor_enable(data);
> @@ -501,16 +512,20 @@ static void test_cursor_size(data_t *data)
>  	}
>  	cursor_disable(data);
>  	/* Software test loop */
> -	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
>  		/* Now render the same in software and collect crc */
> +		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  		igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
> +		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  		igt_display_commit(display);
>  		igt_wait_for_vblank(data->drm_fd, data->pipe);
>  		igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
>  		/* Clear screen afterwards */
> +		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  		igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
>  				0.0, 0.0, 0.0);
> +		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  		igt_assert_crc_equal(&crc[i], &ref_crc);
>  	}
>  }
> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> index 710ea52b4a8a..b43e77123e7f 100644
> --- a/tests/kms_flip.c
> +++ b/tests/kms_flip.c
> @@ -976,8 +976,7 @@ static void paint_flip_mode(struct igt_fb *fb, bool odd_frame)
>  	cairo_set_source_rgb(cr, 1, 1, 1);
>  	cairo_fill(cr);
>  
> -	igt_assert(!cairo_status(cr));
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  }
>  
>  static int
> diff --git a/tests/kms_mmap_write_crc.c b/tests/kms_mmap_write_crc.c
> index dd44ce97238a..279d0f67dd53 100644
> --- a/tests/kms_mmap_write_crc.c
> +++ b/tests/kms_mmap_write_crc.c
> @@ -92,7 +92,7 @@ static void test(data_t *data)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, fb);
>  	igt_paint_test_pattern(cr, fb->width, fb->height);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  
>  	/* flip to it to make it UC/WC and fully flushed */
>  	igt_plane_set_fb(data->primary, fb);
> @@ -135,7 +135,7 @@ static void test(data_t *data)
>  	 * fully flushed */
>  	cr = igt_get_cairo_ctx(data->drm_fd, fb);
>  	igt_paint_test_pattern(cr, fb->width, fb->height);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  
>  	igt_plane_set_fb(data->primary, fb);
>  	igt_display_commit(display);
> diff --git a/tests/kms_plane.c b/tests/kms_plane.c
> index 9672763fe619..54bcffc16f4f 100644
> --- a/tests/kms_plane.c
> +++ b/tests/kms_plane.c
> @@ -138,8 +138,7 @@ create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
>  	igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
>  			    0.0, 1.0, 0.0);
>  	igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  enum {
> @@ -279,8 +278,7 @@ create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
>  			mode->hdisplay, mode->vdisplay,
>  			0.0, 0.0, 1.0);
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  enum {
> @@ -436,8 +434,7 @@ static void test_format_plane(data_t *data, enum pipe pipe,
>  				0.0, 1.0, 0.0);
>  		if (width >= 164 && height >= 164)
>  			igt_paint_color(cr, 100, 100, 64, 64, 0.0, 0.0, 0.0);
> -		igt_assert(cairo_status(cr) == 0);
> -		cairo_destroy(cr);
> +		igt_put_cairo_ctx(data->drm_fd, &fb, cr);
>  
>  		igt_plane_set_fb(plane, &fb);
>  		igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
> diff --git a/tests/kms_plane_multiple.c b/tests/kms_plane_multiple.c
> index aea59df84d76..95b713858edc 100644
> --- a/tests/kms_plane_multiple.c
> +++ b/tests/kms_plane_multiple.c
> @@ -173,8 +173,7 @@ create_fb_for_mode_position(data_t *data, igt_output_t *output, drmModeModeInfo
>  				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
>  		}
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
>  }
>  
>  
> diff --git a/tests/kms_plane_scaling.c b/tests/kms_plane_scaling.c
> index c8283a3b23d1..d32f3441e8c9 100644
> --- a/tests/kms_plane_scaling.c
> +++ b/tests/kms_plane_scaling.c
> @@ -120,8 +120,7 @@ static void paint_fb(data_t *d, struct igt_fb *fb)
>  
>  	cr = igt_get_cairo_ctx(d->drm_fd, fb);
>  	igt_paint_color(cr, 0, 0, fb->width, fb->height, 0.0, 1.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(d->drm_fd, fb, cr);
>  }
>  
>  static void check_scaling_pipe_plane_rot(data_t *d, igt_plane_t *plane,
> diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
> index 26cf434af64a..2b60acf34e77 100644
> --- a/tests/kms_psr_sink_crc.c
> +++ b/tests/kms_psr_sink_crc.c
> @@ -91,7 +91,7 @@ static void create_cursor_fb(data_t *data)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb_white);
>  	igt_paint_color_alpha(cr, 0, 0, 64, 64, 1.0, 1.0, 1.0, 1.0);
> -	igt_assert(cairo_status(cr) == 0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb_white, cr);
>  }
>  
>  
> diff --git a/tests/kms_render.c b/tests/kms_render.c
> index d2208e38f84e..25a0c05b547c 100644
> --- a/tests/kms_render.c
> +++ b/tests/kms_render.c
> @@ -55,7 +55,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
>  	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
>  	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  
>  	return 0;
>  }
> diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
> index 799cf1142579..5b190a0d03cb 100644
> --- a/tests/kms_rotation_crc.c
> +++ b/tests/kms_rotation_crc.c
> @@ -120,7 +120,7 @@ paint_squares(data_t *data, igt_rotation_t rotation,
>  	igt_paint_color(cr, 0, h / 2, w / 2, h / 2, RGB_COLOR(bl));
>  	igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, RGB_COLOR(br));
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->gfx_fd, fb, cr);
>  }
>  
>  static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
> diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c
> index 206d360607bb..06241b191a0f 100644
> --- a/tests/kms_setmode.c
> +++ b/tests/kms_setmode.c
> @@ -161,7 +161,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
>  					  crtc_str[i]);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  
>  	return 0;
>  }
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index b0156c5cf0e1..0ff98a2b705e 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -227,9 +227,7 @@ paint_color_key(struct igt_fb *fb_info)
>  	cairo_set_source_rgb(cr, .8, .8, .8);
>  	cairo_fill(cr);
>  
> -	igt_assert(!cairo_status(cr));
> -
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb_info, cr);
>  }
>  
>  static void paint_image(cairo_t *cr, const char *file)
> @@ -294,9 +292,7 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb)
>  	if (qr_code)
>  		paint_image(cr, "pass.png");
>  
> -	igt_assert(!cairo_status(cr));
> -
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  }
>  
>  static void sighandler(int signo)
> -- 
> 2.15.1
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

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

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format.
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (9 preceding siblings ...)
  2018-01-23 15:41 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
@ 2018-01-23 19:47 ` Patchwork
  2018-01-23 22:30 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-23 19:47 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format.
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

Test kms_addfb_basic:
        Subgroup size-max:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-63:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-32:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup invalid-get-prop-any:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup unused-handle:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bo-too-small:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-128:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-yf-tiled:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-0:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-bad-modifier:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-x-tiled-mismatch:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-modifier-no-flag:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup tile-pitch-mismatch:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup invalid-get-prop:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-apl)
        Subgroup unused-pitches:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup unused-modifier:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup clobberred-modifier:
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-y-tiled:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-x-tiled:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup too-high:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-65536:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-1024:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup no-handle:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup too-wide:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bo-too-small-due-to-tiling:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-y-tiled-small:
                skip       -> FAIL       (shard-snb)
                skip       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup small-bo:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup invalid-set-prop-any:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-256:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup unused-offsets:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup basic-x-tiled:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup addfb25-framebuffer-vs-set-tiling:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup invalid-set-prop:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup framebuffer-vs-set-tiling:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup basic-y-tiled:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup basic:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup bad-pitch-999:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
Test kms_draw_crc:
        Subgroup draw-method-xrgb8888-mmap-cpu-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-blt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-cpu-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-render-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-cpu-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-render-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-render-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-gtt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl) fdo#103326
        Subgroup draw-method-rgb565-render-xtiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                skip       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-mmap-gtt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-pwrite-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-render-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                skip       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-gtt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-pwrite-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-blt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-wc-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-mmap-gtt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-pwrite-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-cpu-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-pwrite-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-pwrite-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-wc-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-wc-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-blt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-blt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-mmap-wc-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-cpu-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-render-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-mmap-cpu-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-gtt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-pwrite-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-blt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-blt-xtiled:
                pass       -> CRASH      (shard-snb)
                pass       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb8888-mmap-wc-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-xrgb2101010-mmap-gtt-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
        Subgroup draw-method-rgb565-mmap-wc-ytiled:
                skip       -> CRASH      (shard-snb)
                skip       -> CRASH      (shard-hsw)
                pass       -> CRASH      (shard-apl)
Test kms_rotation_crc:
        Subgroup sprite-rotation-90:
                pass       -> FAIL       (shard-apl) fdo#103356 +4
        Subgroup primary-rotation-90-flip:
                pass       -> FAIL       (shard-apl) fdo#103925 +2
        Subgroup primary-rotation-270:
                pass       -> FAIL       (shard-apl)
        Subgroup primary-rotation-270-flip:
                pass       -> FAIL       (shard-apl) fdo#103511
Test kms_flip:
        Subgroup 2x-flip-vs-expired-vblank:
                pass       -> FAIL       (shard-hsw) fdo#102887
        Subgroup flip-vs-modeset-vs-hang:
                pass       -> DMESG-WARN (shard-snb) fdo#103821 +1
        Subgroup vblank-vs-modeset-suspend-interruptible:
                skip       -> PASS       (shard-hsw) fdo#103540 +1
        Subgroup plain-flip-fb-recreate:
                pass       -> FAIL       (shard-apl) fdo#100368
Test perf:
        Subgroup oa-exponents:
                pass       -> FAIL       (shard-apl) fdo#102254
Test kms_busy:
        Subgroup extended-pageflip-hang-newfb-render-b:
                skip       -> PASS       (shard-snb)
Test gem_eio:
        Subgroup in-flight-suspend:
                fail       -> PASS       (shard-hsw) fdo#104676 +1
Test kms_render:
        Subgroup gpu-blit:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup direct-render:
                pass       -> FAIL       (shard-snb) fdo#104312
                pass       -> FAIL       (shard-hsw) fdo#102614
                pass       -> FAIL       (shard-apl)
Test kms_vblank:
        Subgroup query-forked-busy:
                skip       -> PASS       (shard-snb)
        Subgroup query-busy:
                skip       -> PASS       (shard-snb)

fdo#103326 https://bugs.freedesktop.org/show_bug.cgi?id=103326
fdo#103356 https://bugs.freedesktop.org/show_bug.cgi?id=103356
fdo#103925 https://bugs.freedesktop.org/show_bug.cgi?id=103925
fdo#103511 https://bugs.freedesktop.org/show_bug.cgi?id=103511
fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
fdo#103821 https://bugs.freedesktop.org/show_bug.cgi?id=103821
fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#102254 https://bugs.freedesktop.org/show_bug.cgi?id=102254
fdo#104676 https://bugs.freedesktop.org/show_bug.cgi?id=104676
fdo#104312 https://bugs.freedesktop.org/show_bug.cgi?id=104312
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614

shard-apl        total:2753 pass:1631 dwarn:1   dfail:0   fail:73  skip:1011 time:13913s
shard-hsw        total:2753 pass:1670 dwarn:1   dfail:0   fail:50  skip:995 time:15254s
shard-snb        total:2753 pass:1261 dwarn:3   dfail:0   fail:50  skip:1403 time:7907s
Blacklisted hosts:
shard-kbl        total:2747 pass:1732 dwarn:14  dfail:2   fail:74  skip:888 time:10411s

== Logs ==

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

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

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev2)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (10 preceding siblings ...)
  2018-01-23 19:47 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
@ 2018-01-23 22:30 ` Patchwork
  2018-01-24 12:16 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev3) Patchwork
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-23 22:30 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev2)
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

Test perf:
        Subgroup oa-exponents:
                pass       -> FAIL       (shard-apl) fdo#102254
Test drv_suspend:
        Subgroup forcewake:
                pass       -> SKIP       (shard-snb)
Test kms_rotation_crc:
        Subgroup sprite-rotation-90-pos-100-0:
                pass       -> FAIL       (shard-apl) fdo#103356 +4
        Subgroup primary-rotation-90:
                pass       -> FAIL       (shard-apl) fdo#103925 +2
        Subgroup primary-rotation-270-flip:
                pass       -> FAIL       (shard-apl) fdo#103511
        Subgroup primary-rotation-270:
                pass       -> FAIL       (shard-apl)
Test kms_cursor_crc:
        Subgroup cursor-256x256-suspend:
                pass       -> SKIP       (shard-snb) fdo#103375
Test kms_flip:
        Subgroup vblank-vs-modeset-suspend-interruptible:
                skip       -> PASS       (shard-hsw) fdo#103540 +1
Test kms_vblank:
        Subgroup query-idle:
                pass       -> INCOMPLETE (shard-hsw)
        Subgroup query-busy:
                skip       -> PASS       (shard-snb)
        Subgroup query-forked-busy:
                skip       -> PASS       (shard-snb)
Test kms_render:
        Subgroup gpu-blit:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup direct-render:
                pass       -> FAIL       (shard-snb) fdo#104312
                pass       -> FAIL       (shard-hsw) fdo#102614
                pass       -> FAIL       (shard-apl)
Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-offscren-pri-shrfb-draw-blt:
                pass       -> FAIL       (shard-snb) fdo#101623
Test kms_sysfs_edid_timing:
                warn       -> PASS       (shard-apl) fdo#100047
Test gem_eio:
        Subgroup in-flight-external:
                fail       -> PASS       (shard-hsw) fdo#104676
Test kms_busy:
        Subgroup extended-pageflip-hang-newfb-render-b:
                skip       -> PASS       (shard-snb)

fdo#102254 https://bugs.freedesktop.org/show_bug.cgi?id=102254
fdo#103356 https://bugs.freedesktop.org/show_bug.cgi?id=103356
fdo#103925 https://bugs.freedesktop.org/show_bug.cgi?id=103925
fdo#103511 https://bugs.freedesktop.org/show_bug.cgi?id=103511
fdo#103375 https://bugs.freedesktop.org/show_bug.cgi?id=103375
fdo#103540 https://bugs.freedesktop.org/show_bug.cgi?id=103540
fdo#104312 https://bugs.freedesktop.org/show_bug.cgi?id=104312
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#100047 https://bugs.freedesktop.org/show_bug.cgi?id=100047
fdo#104676 https://bugs.freedesktop.org/show_bug.cgi?id=104676

shard-apl        total:2753 pass:1704 dwarn:1   dfail:0   fail:35  skip:1013 time:13947s
shard-hsw        total:2646 pass:1669 dwarn:1   dfail:0   fail:11  skip:963 time:13864s
shard-snb        total:2753 pass:1314 dwarn:1   dfail:0   fail:13  skip:1425 time:7853s
Blacklisted hosts:
shard-kbl        total:2753 pass:1816 dwarn:14  dfail:0   fail:36  skip:887 time:10908s

== Logs ==

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

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

* [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v3.
  2018-01-23 14:50   ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v2 Maarten Lankhorst
@ 2018-01-24 10:53     ` Maarten Lankhorst
  2018-01-29  8:44       ` Mika Kahola
  0 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-24 10:53 UTC (permalink / raw)
  To: igt-dev

Add support to create planar framebuffers, but don't add formats
that support them yet. This first requires conversion to the RGB24 format.

Changes since v1:
- Don't crash in igt_create_bo_with_dimensions().
Changes since v2:
- Zero offsets for dumb fb too.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c             | 76 +++++++++++++++++++++++++++++++++++-------------
 lib/igt_fb.h             | 10 +++++++
 lib/ioctl_wrappers.c     | 11 +++++--
 lib/ioctl_wrappers.h     |  2 +-
 tests/kms_draw_crc.c     |  2 +-
 tests/kms_rotation_crc.c |  5 ++--
 tests/prime_vgem.c       |  2 +-
 7 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 1251f462d24e..9d60280f198e 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -158,14 +158,19 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
 	}
 }
 
+static unsigned planar_width(struct format_desc_struct *format, unsigned width, int plane)
+{
+	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
+		return (width + 1) / 2;
+
+	return width;
+}
+
 static unsigned planar_stride(struct format_desc_struct *format, unsigned width, int plane)
 {
 	unsigned cpp = format->plane_bpp[plane] / 8;
 
-	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
-		return (width + 1) / 2 * cpp;
-
-	return width * cpp;
+	return planar_width(format, width, plane) * cpp;
 }
 
 static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
@@ -331,17 +336,25 @@ static int create_bo_for_fb(int fd, int width, int height,
 			    struct format_desc_struct *format,
 			    uint64_t tiling, unsigned size, unsigned stride,
 			    unsigned *size_ret, unsigned *stride_ret,
-			    bool *is_dumb)
+			    uint32_t *offsets, bool *is_dumb)
 {
 	int bo;
 
 	igt_assert(format);
 
+	if (offsets)
+		memset(offsets, 0, 4 * sizeof(*offsets));
+
 	if (tiling || size || stride || format->planes > 1) {
 		unsigned calculated_size, calculated_stride;
 
-		igt_calc_fb_size(fd, width, height, format->drm_id, tiling,
-				 &calculated_size, &calculated_stride);
+		if (format->planes > 1)
+			calc_fb_size_planar(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride, offsets);
+		else
+			calc_fb_size_packed(fd, width, height, format, tiling,
+					    &calculated_size, &calculated_stride);
+
 		if (stride == 0)
 			stride = calculated_stride;
 		if (size == 0)
@@ -407,7 +420,7 @@ int igt_create_bo_with_dimensions(int fd, int width, int height,
 				  unsigned *stride_ret, bool *is_dumb)
 {
 	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
-				modifier, 0, stride, size_ret, stride_ret, is_dumb);
+				modifier, 0, stride, size_ret, stride_ret, NULL, is_dumb);
 }
 
 /**
@@ -748,16 +761,20 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 			   struct igt_fb *fb, unsigned bo_size,
 			   unsigned bo_stride)
 {
+	struct format_desc_struct *f = lookup_drm_format(format);
 	uint32_t fb_id;
+	int i;
+
+	igt_assert_f(f, "DRM format %08x not found\n", format);
 
 	memset(fb, 0, sizeof(*fb));
 
 	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,
-					  lookup_drm_format(format),
+	fb->gem_handle = create_bo_for_fb(fd, width, height, f,
 					  tiling, bo_size, bo_stride,
-					  &fb->size, &fb->stride, &fb->is_dumb);
+					  &fb->size, &fb->stride,
+					  fb->offsets, &fb->is_dumb);
 	igt_assert(fb->gem_handle > 0);
 
 	igt_debug("%s(handle=%d, pitch=%d)\n",
@@ -766,22 +783,24 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    tiling != LOCAL_I915_FORMAT_MOD_X_TILED) {
 		do_or_die(__kms_addfb(fd, fb->gem_handle, width, height,
-				      fb->stride, format, tiling,
+				      fb->stride, format, tiling, fb->offsets,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id));
 	} else {
 		uint32_t handles[4];
 		uint32_t pitches[4];
-		uint32_t offsets[4];
 
 		memset(handles, 0, sizeof(handles));
 		memset(pitches, 0, sizeof(pitches));
-		memset(offsets, 0, sizeof(offsets));
 
 		handles[0] = fb->gem_handle;
 		pitches[0] = fb->stride;
+		for (i = 0; i < f->planes; i++) {
+			handles[i] = fb->gem_handle;
+			pitches[i] = fb->stride;
+		}
 
 		do_or_die(drmModeAddFB2(fd, width, height, format,
-					handles, pitches, offsets,
+					handles, pitches, fb->offsets,
 					&fb_id, 0));
 	}
 
@@ -791,6 +810,17 @@ 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;
+
+	/* if f->planes is set, then plane_bpp is valid too so use that. */
+	for (i = 0; i < f->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);
+	}
 
 	return fb_id;
 }
@@ -1127,7 +1157,8 @@ static void destroy_cairo_surface__blit(void *arg)
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0 /* dst_x, dst_y */);
@@ -1143,6 +1174,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 	struct fb_blit_upload *blit;
 	cairo_format_t cairo_format;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
+	uint32_t offsets[4];
 
 	blit = malloc(sizeof(*blit));
 	igt_assert(blit);
@@ -1157,7 +1189,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
 					       0, &blit->linear.size,
 					       &blit->linear.stride,
-					       &blit->linear.is_dumb);
+					       offsets, &blit->linear.is_dumb);
 
 	igt_assert(blit->linear.handle > 0);
 
@@ -1169,7 +1201,8 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle, 0,
+				   fb->gem_handle,
+				   fb->offsets[0],
 				   fb->stride,
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
@@ -1257,14 +1290,17 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
  * @fd: open drm file descriptor
  * @fb: pointer to an #igt_fb structure
  *
- * This function stores the contents of the supplied framebuffer into a cairo
- * surface and returns it.
+ * This function stores the contents of the supplied framebuffer's plane
+ * into a cairo surface and returns it.
  *
  * Returns:
  * A pointer to a cairo surface with the contents of the framebuffer.
  */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
+	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
+	igt_assert(fb->num_planes < 2);
+
 	if (fb->cairo_surface == NULL) {
 		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 152798e9896b..77fd88bb7aca 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -50,6 +50,11 @@
  * @size: size in bytes of the underlying backing storage
  * @cairo_surface: optionally attached cairo drawing surface
  * @domain: current domain for cache flushing tracking on i915.ko
+ * @num_planes: Amount of planes on this fb. >1 for planar formats.
+ * @offsets: Offset for each plane in bytes.
+ * @plane_bpp: The bpp for each plane.
+ * @plane_width: The width for each plane.
+ * @plane_height: The height for each plane.
  *
  * Tracking structure for KMS framebuffer objects.
  */
@@ -66,6 +71,11 @@ typedef struct igt_fb {
 	unsigned int size;
 	cairo_surface_t *cairo_surface;
 	unsigned int domain;
+	unsigned int num_planes;
+	uint32_t offsets[4];
+	unsigned int plane_bpp[4];
+	unsigned int plane_width[4];
+	unsigned int plane_height[4];
 } igt_fb_t;
 
 /**
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 39e8469e3985..10d958726da7 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1659,10 +1659,10 @@ void igt_require_fb_modifiers(int fd)
 
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id)
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id)
 {
 	struct drm_mode_fb_cmd2 f;
-	int ret;
+	int ret, i;
 
 	igt_require_fb_modifiers(fd);
 
@@ -1676,6 +1676,13 @@ int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 	f.pitches[0] = stride;
 	f.modifier[0] = modifier;
 
+	for (i = 1; i < 4 && offsets && offsets[i]; i++) {
+		f.handles[i] = handle;
+		f.pitches[i] = stride;
+		f.modifier[i] = modifier;
+		f.offsets[i] = offsets[i];
+	}
+
 	ret = igt_ioctl(fd, DRM_IOCTL_MODE_ADDFB2, &f);
 
 	*buf_id = f.fb_id;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index f7752aeab2c4..13fbe3c103c0 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -236,7 +236,7 @@ void igt_require_fb_modifiers(int fd);
  */
 int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
 		uint32_t stride, uint32_t pixel_format, uint64_t modifier,
-		uint32_t flags, uint32_t *buf_id);
+		uint32_t *offsets, uint32_t flags, uint32_t *buf_id);
 
 /**
  * to_user_pointer:
diff --git a/tests/kms_draw_crc.c b/tests/kms_draw_crc.c
index 723e7a182c95..86dcf39285f3 100644
--- a/tests/kms_draw_crc.c
+++ b/tests/kms_draw_crc.c
@@ -163,7 +163,7 @@ static bool format_is_supported(uint32_t format, uint64_t modifier)
 						   format, modifier,
 						   0, NULL, &stride, NULL);
 	ret =  __kms_addfb(drm_fd, gem_handle, 64, 64,
-			   stride, format, modifier,
+			   stride, format, modifier, NULL,
 			   LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id);
 	drmModeRmFB(drm_fd, fb_id);
 	gem_close(drm_fd, gem_handle);
diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
index 5b190a0d03cb..f65562bae9eb 100644
--- a/tests/kms_rotation_crc.c
+++ b/tests/kms_rotation_crc.c
@@ -520,7 +520,7 @@ static void test_plane_rotation_ytiled_obj(data_t *data,
 	igt_assert_eq(ret, 0);
 
 	do_or_die(__kms_addfb(fd, gem_handle, w, h, stride,
-		  format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		  format, tiling, NULL, LOCAL_DRM_MODE_FB_MODIFIERS,
 		  &data->fb.fb_id));
 	data->fb.width = w;
 	data->fb.height = h;
@@ -601,7 +601,8 @@ static void test_plane_rotation_exhaust_fences(data_t *data,
 		}
 
 		ret = (__kms_addfb(fd, gem_handle, w, h, stride,
-		       format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
+		       format, tiling, NULL,
+		       LOCAL_DRM_MODE_FB_MODIFIERS,
 		       &data2[i].fb.fb_id));
 		if (ret) {
 			igt_warn("failed to create framebuffer\n");
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index a5f75d888bef..763c62e606f6 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -723,7 +723,7 @@ static void test_flip(int i915, int vgem, unsigned hang)
 
 		do_or_die(__kms_addfb(i915, handle[i],
 				      bo[i].width, bo[i].height, bo[i].pitch,
-				      DRM_FORMAT_XRGB8888, I915_TILING_NONE,
+				      DRM_FORMAT_XRGB8888, I915_TILING_NONE, NULL,
 				      LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id[i]));
 		igt_assert(fb_id[i]);
 	}
-- 
2.15.1

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

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

* [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev3)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (11 preceding siblings ...)
  2018-01-23 22:30 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
@ 2018-01-24 12:16 ` Patchwork
  2018-01-24 15:57 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-24 12:16 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev3)
URL   : https://patchwork.freedesktop.org/series/36965/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
63f7ef01908c9925bbacbbbac76fdc0ba15967c5 kms_vblank: Remove teardown code from cleanup_crtc

with latest DRM-Tip kernel build CI_DRM_3680
ef2011c63806 drm-tip: 2018y-01m-24d-09h-45m-08s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                dmesg-fail -> DMESG-WARN (fi-elk-e7500) fdo#103989 +1
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                incomplete -> PASS       (fi-snb-2520m) fdo#103713

fdo#103989 https://bugs.freedesktop.org/show_bug.cgi?id=103989
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:418s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:425s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:374s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:496s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:281s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:489s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:487s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:471s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:460s
fi-elk-e7500     total:224  pass:169  dwarn:9   dfail:0   fail:0   skip:45 
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:280s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:528s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:392s
fi-hsw-4770r     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:404s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:413s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:454s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:425s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:461s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:497s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:454s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:504s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:592s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:429s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:511s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:532s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:490s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:477s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:416s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:437s
fi-snb-2520m     total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:531s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:401s
Blacklisted hosts:
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:571s
fi-glk-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:473s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-23 15:50   ` Ville Syrjälä
@ 2018-01-24 12:26     ` Maarten Lankhorst
  2018-01-25 11:43       ` Mika Kahola
  0 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-24 12:26 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: igt-dev

Hey,

Op 23-01-18 om 16:50 schreef Ville Syrjälä:
> On Tue, Jan 23, 2018 at 01:56:35PM +0100, Maarten Lankhorst wrote:
>> This will allow support for NV12 in the future, where igt_get_cairo_ctx
>> will return a RGB image to draw with, which will be converted in
>> igt_put_cairo_ctx so tests don't have to add special support for NV12.
> Why do we need a special funciton? As in, can't you just do it the
> same as we handle the gtt vs. blit stuff?
>
The cairo_destroy() call will do the actual conversion back, but with this helper we can
actually check that every call to get() is followed by a put() and errors are consistently
checked. Not all callers have both, so I felt it better to put it in the core..

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

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

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev3)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (12 preceding siblings ...)
  2018-01-24 12:16 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev3) Patchwork
@ 2018-01-24 15:57 ` Patchwork
  2018-01-29 12:37 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev4) Patchwork
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-24 15:57 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev3)
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-offscren-pri-shrfb-draw-blt:
                pass       -> FAIL       (shard-snb) fdo#101623 +1
Test perf:
        Subgroup oa-exponents:
                pass       -> FAIL       (shard-apl) fdo#102254
Test kms_flip:
        Subgroup 2x-plain-flip-ts-check-interruptible:
                pass       -> FAIL       (shard-hsw)
        Subgroup flip-vs-expired-vblank:
                pass       -> FAIL       (shard-apl) fdo#102887
Test kms_render:
        Subgroup direct-render:
                pass       -> FAIL       (shard-snb) fdo#104312
                pass       -> FAIL       (shard-hsw) fdo#102614
                pass       -> FAIL       (shard-apl)
        Subgroup gpu-blit:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
Test gem_exec_suspend:
        Subgroup basic-s3:
                skip       -> PASS       (shard-snb) fdo#103880

fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#102254 https://bugs.freedesktop.org/show_bug.cgi?id=102254
fdo#102887 https://bugs.freedesktop.org/show_bug.cgi?id=102887
fdo#104312 https://bugs.freedesktop.org/show_bug.cgi?id=104312
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#103880 https://bugs.freedesktop.org/show_bug.cgi?id=103880

shard-apl        total:2838 pass:1748 dwarn:1   dfail:0   fail:27  skip:1062 time:12613s
shard-hsw        total:2838 pass:1732 dwarn:1   dfail:0   fail:14  skip:1090 time:11816s
shard-snb        total:2838 pass:1326 dwarn:1   dfail:0   fail:14  skip:1497 time:6621s
Blacklisted hosts:
shard-kbl        total:2838 pass:1861 dwarn:9   dfail:0   fail:26  skip:942 time:9646s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-24 12:26     ` Maarten Lankhorst
@ 2018-01-25 11:43       ` Mika Kahola
  2018-01-29 17:01         ` Maarten Lankhorst
  0 siblings, 1 reply; 47+ messages in thread
From: Mika Kahola @ 2018-01-25 11:43 UTC (permalink / raw)
  To: Maarten Lankhorst, Ville Syrjälä; +Cc: igt-dev

On Wed, 2018-01-24 at 13:26 +0100, Maarten Lankhorst wrote:
> Hey,
> 
> Op 23-01-18 om 16:50 schreef Ville Syrjälä:
> > 
> > On Tue, Jan 23, 2018 at 01:56:35PM +0100, Maarten Lankhorst wrote:
> > > 
> > > This will allow support for NV12 in the future, where
> > > igt_get_cairo_ctx
> > > will return a RGB image to draw with, which will be converted in
> > > igt_put_cairo_ctx so tests don't have to add special support for
> > > NV12.
> > Why do we need a special funciton? As in, can't you just do it the
> > same as we handle the gtt vs. blit stuff?
> > 
> The cairo_destroy() call will do the actual conversion back, but with
> this helper we can
> actually check that every call to get() is followed by a put() and
> errors are consistently
> checked. Not all callers have both, so I felt it better to put it in
> the core..

From the naming convention point of view, I would use set() instead of
put() as we have a get() as counterpart.

> 
> ~Maarten
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size Maarten Lankhorst
@ 2018-01-25 11:51   ` Mika Kahola
  0 siblings, 0 replies; 47+ messages in thread
From: Mika Kahola @ 2018-01-25 11:51 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> bpp is only sufficient to calculate dimensions for packed formats, in
> case of planar formats we need to pass the drm format fourcc, which
> will give us better information.
> 
> This is required for supporting planar framebuffers.
> 

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c                     | 10 ++++++----
>  lib/igt_fb.h                     |  2 +-
>  tests/kms_frontbuffer_tracking.c |  4 +---
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 39a83bae178a..da07d1a9e21f 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -147,7 +147,7 @@ void igt_get_fb_tile_size(int fd, uint64_t
> tiling, int fb_bpp,
>   * @fd: the DRM file descriptor
>   * @width: width of the framebuffer in pixels
>   * @height: height of the framebuffer in pixels
> - * @bpp: bytes per pixel of the framebuffer
> + * @format: drm fourcc pixel format code
>   * @tiling: tiling layout of the framebuffer (as framebuffer
> modifier)
>   * @size_ret: returned size for the framebuffer
>   * @stride_ret: returned stride for the framebuffer
> @@ -155,10 +155,11 @@ void igt_get_fb_tile_size(int fd, uint64_t
> tiling, int fb_bpp,
>   * This function returns valid stride and size values for a
> framebuffer with the
>   * specified parameters.
>   */
> -void igt_calc_fb_size(int fd, int width, int height, int bpp,
> uint64_t tiling,
> +void igt_calc_fb_size(int fd, int width, int height, uint32_t
> format, uint64_t tiling,
>  		      unsigned *size_ret, unsigned *stride_ret)
>  {
>  	unsigned int tile_width, tile_height, stride, size;
> +	int bpp = igt_drm_format_to_bpp(format);
>  	int byte_width = width * (bpp / 8);
>  
>  	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width,
> &tile_height);
> @@ -249,13 +250,12 @@ static int create_bo_for_fb(int fd, int width,
> int height, uint32_t format,
>  			    unsigned *size_ret, unsigned
> *stride_ret,
>  			    bool *is_dumb)
>  {
> -	int bpp = igt_drm_format_to_bpp(format);
>  	int bo;
>  
>  	if (tiling || size || stride) {
>  		unsigned calculated_size, calculated_stride;
>  
> -		igt_calc_fb_size(fd, width, height, bpp, tiling,
> +		igt_calc_fb_size(fd, width, height, format, tiling,
>  				 &calculated_size,
> &calculated_stride);
>  		if (stride == 0)
>  			stride = calculated_stride;
> @@ -290,6 +290,8 @@ static int create_bo_for_fb(int fd, int width,
> int height, uint32_t format,
>  			return -EINVAL;
>  		}
>  	} else {
> +		int bpp = igt_drm_format_to_bpp(format);
> +
>  		if (is_dumb)
>  			*is_dumb = true;
>  
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index 3004f0656029..152798e9896b 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -90,7 +90,7 @@ enum igt_text_align {
>  
>  void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
>  			  unsigned *width_ret, unsigned
> *height_ret);
> -void igt_calc_fb_size(int fd, int width, int height, int bpp,
> uint64_t tiling,
> +void igt_calc_fb_size(int fd, int width, int height, uint32_t
> format, uint64_t tiling,
>  		      unsigned *size_ret, unsigned *stride_ret);
>  unsigned int
>  igt_create_fb_with_bo_size(int fd, int width, int height,
> diff --git a/tests/kms_frontbuffer_tracking.c
> b/tests/kms_frontbuffer_tracking.c
> index 1601cab45b9a..ea5297538c34 100644
> --- a/tests/kms_frontbuffer_tracking.c
> +++ b/tests/kms_frontbuffer_tracking.c
> @@ -541,7 +541,6 @@ static void create_fb(enum pixel_format pformat,
> int width, int height,
>  {
>  	uint32_t format;
>  	unsigned int size, stride;
> -	int bpp;
>  	uint64_t tiling_for_size;
>  
>  	switch (pformat) {
> @@ -576,13 +575,12 @@ static void create_fb(enum pixel_format
> pformat, int width, int height,
>  	 * the same size regardless of tiling since we want to
> properly exercise
>  	 * the Kernel's specific tiling-checking code paths without
> accidentally
>  	 * hitting size-checking ones first. */
> -	bpp = igt_drm_format_to_bpp(format);
>  	if (plane == PLANE_CUR)
>  		tiling_for_size = LOCAL_DRM_FORMAT_MOD_NONE;
>  	else
>  		tiling_for_size = opt.tiling;
>  
> -	igt_calc_fb_size(drm.fd, width, height, bpp,
> tiling_for_size, &size,
> +	igt_calc_fb_size(drm.fd, width, height, format,
> tiling_for_size, &size,
>  			 &stride);
>  
>  	igt_create_fb_with_bo_size(drm.fd, width, height, format,
> tiling, fb,
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb Maarten Lankhorst
@ 2018-01-26  9:00   ` Mika Kahola
  2018-01-26 10:20     ` Maarten Lankhorst
  2018-02-01 14:39   ` Ville Syrjälä
  1 sibling, 1 reply; 47+ messages in thread
From: Mika Kahola @ 2018-01-26  9:00 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> By adding support for planar formats to igt_calc_fb_size and
> create_bo_for_fb,
> we can calculate dimensions and create backing storage for planar
> framebuffers.
> 
> This is required for adding support to create planar framebuffers in
> the next patch.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++----
> ------------
>  1 file changed, 123 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index da07d1a9e21f..6a331f06724b 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -54,14 +54,16 @@
>   */
>  
>  /* drm fourcc/cairo format maps */
> -#define DF(did, cid, _bpp, _depth)	\
> -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth
> }
> +#define DF(did, cid, ...)	\
> +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
>  static struct format_desc_struct {
>  	uint32_t drm_id;
>  	cairo_format_t cairo_id;
>  	const char *name;
>  	int bpp;
>  	int depth;
> +	int planes;
> +	int plane_bpp[4];
should we define a max value for this instead of hardcoded one?
>  } format_desc[] = {
>  	DF(RGB565,	RGB16_565,	16, 16),
>  	//DF(RGB888,	INVALID,	24, 24),
> @@ -74,6 +76,20 @@ static struct format_desc_struct {
>  #define for_each_format(f)	\
>  	for (f = format_desc; f - format_desc <
> ARRAY_SIZE(format_desc); f++)
>  
> +static struct format_desc_struct *lookup_drm_format(uint32_t
> drm_format)
> +{
> +	struct format_desc_struct *format;
> +
> +	for_each_format(format) {
> +		if (format->drm_id != drm_format)
> +			continue;
> +
> +		return format;
> +	}
> +
> +	return NULL;
> +}
> +
>  /**
>   * igt_get_fb_tile_size:
>   * @fd: the DRM file descriptor
> @@ -142,27 +158,68 @@ void igt_get_fb_tile_size(int fd, uint64_t
> tiling, int fb_bpp,
>  	}
>  }
>  
> -/**
> - * igt_calc_fb_size:
> - * @fd: the DRM file descriptor
> - * @width: width of the framebuffer in pixels
> - * @height: height of the framebuffer in pixels
> - * @format: drm fourcc pixel format code
> - * @tiling: tiling layout of the framebuffer (as framebuffer
> modifier)
> - * @size_ret: returned size for the framebuffer
> - * @stride_ret: returned stride for the framebuffer
> - *
> - * This function returns valid stride and size values for a
> framebuffer with the
> - * specified parameters.
> - */
> -void igt_calc_fb_size(int fd, int width, int height, uint32_t
> format, uint64_t tiling,
> -		      unsigned *size_ret, unsigned *stride_ret)
> +static unsigned planar_stride(struct format_desc_struct *format,
> unsigned width, int plane)
> +{
> +	unsigned cpp = format->plane_bpp[plane] / 8;
> +
> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> +		return (width + 1) / 2 * cpp;
> +
> +	return width * cpp;
> +}
> +
> +static unsigned planar_height(struct format_desc_struct *format,
> unsigned height, int plane)
> +{
> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> +		return (height + 1) / 2;
> +
> +	return height;
> +}
> +
> +static void calc_fb_size_planar(int fd, int width, int height,
> +				struct format_desc_struct *format,
> +				uint64_t tiling, unsigned *size_ret,
> +				unsigned *stride_ret, unsigned
> *offsets)
> +{
> +	int plane;
> +	unsigned stride = 0, tile_width, tile_height;
> +
> +	*size_ret = 0;
> +
> +	for (plane = 0; plane < format->planes; plane++) {
> +		unsigned plane_stride;
> +
> +		igt_get_fb_tile_size(fd, tiling, format-
> >plane_bpp[plane], &tile_width, &tile_height);
> +
> +		plane_stride = ALIGN(planar_stride(format, width,
> plane), tile_width);
> +		if (stride < plane_stride)
> +			stride = plane_stride;
> +	}
> +
> +	for (plane = 0; plane < format->planes; plane++) {
> +		if (offsets)
> +			offsets[plane] = *size_ret;
> +
> +		igt_get_fb_tile_size(fd, tiling, format-
> >plane_bpp[plane], &tile_width, &tile_height);
> +
> +		*size_ret += stride * ALIGN(planar_height(format,
> height, plane), tile_height);
> +	}
> +
> +	if (offsets)
> +		for (; plane < 4; plane++)
We could loop through max define value here too instead of hardcoded
one.

> +			offsets[plane] = 0;
> +
> +	*stride_ret = stride;
> +}
> +
> +static void calc_fb_size_packed(int fd, int width, int height,
> +				struct format_desc_struct *format,
> uint64_t tiling,
> +				unsigned *size_ret, unsigned
> *stride_ret)
>  {
>  	unsigned int tile_width, tile_height, stride, size;
> -	int bpp = igt_drm_format_to_bpp(format);
> -	int byte_width = width * (bpp / 8);
> +	int byte_width = width * (format->bpp / 8);
>  
> -	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width,
> &tile_height);
> +	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width,
> &tile_height);
>  
>  	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
>  	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
> @@ -176,7 +233,7 @@ void igt_calc_fb_size(int fd, int width, int
> height, uint32_t format, uint64_t t
>  		 * tiled. But then that failure is expected.
>  		 */
>  
> -		v = width * bpp / 8;
> +		v = byte_width;
>  		for (stride = 512; stride < v; stride *= 2)
>  			;
>  
> @@ -192,6 +249,31 @@ void igt_calc_fb_size(int fd, int width, int
> height, uint32_t format, uint64_t t
>  	*size_ret = size;
>  }
>  
> +/**
> + * igt_calc_fb_size:
> + * @fd: the DRM file descriptor
> + * @width: width of the framebuffer in pixels
> + * @height: height of the framebuffer in pixels
> + * @format: drm fourcc pixel format code
> + * @tiling: tiling layout of the framebuffer (as framebuffer
> modifier)
> + * @size_ret: returned size for the framebuffer
> + * @stride_ret: returned stride for the framebuffer
> + *
> + * This function returns valid stride and size values for a
> framebuffer with the
> + * specified parameters.
> + */
> +void igt_calc_fb_size(int fd, int width, int height, uint32_t
> drm_format, uint64_t tiling,
> +		      unsigned *size_ret, unsigned *stride_ret)
> +{
> +	struct format_desc_struct *format =
> lookup_drm_format(drm_format);
> +	igt_assert(format);
> +
> +	if (format->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);
> +}
> +
>  /**
>   * igt_fb_mod_to_tiling:
>   * @modifier: DRM framebuffer modifier
> @@ -245,17 +327,20 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling)
>  }
>  
>  /* helpers to create nice-looking framebuffers */
> -static int create_bo_for_fb(int fd, int width, int height, uint32_t
> format,
> +static int create_bo_for_fb(int fd, int width, int height,
> +			    struct format_desc_struct *format,
>  			    uint64_t tiling, unsigned size, unsigned
> stride,
>  			    unsigned *size_ret, unsigned
> *stride_ret,
>  			    bool *is_dumb)
>  {
>  	int bo;
>  
> -	if (tiling || size || stride) {
> +	igt_assert(format);
> +
> +	if (tiling || size || stride || format->planes > 1) {
>  		unsigned calculated_size, calculated_stride;
>  
> -		igt_calc_fb_size(fd, width, height, format, tiling,
> +		igt_calc_fb_size(fd, width, height, format->drm_id,
> tiling,
>  				 &calculated_size,
> &calculated_stride);
>  		if (stride == 0)
>  			stride = calculated_stride;
> @@ -290,12 +375,10 @@ static int create_bo_for_fb(int fd, int width,
> int height, uint32_t format,
>  			return -EINVAL;
>  		}
>  	} else {
> -		int bpp = igt_drm_format_to_bpp(format);
> -
>  		if (is_dumb)
>  			*is_dumb = true;
>  
> -		return kmstest_dumb_create(fd, width, height, bpp,
> stride_ret,
> +		return kmstest_dumb_create(fd, width, height,
> format->bpp, stride_ret,
>  					   size_ret);
>  	}
>  }
> @@ -323,8 +406,8 @@ 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, format, modifier,
> 0, stride,
> -			     size_ret, stride_ret, is_dumb);
> +	return create_bo_for_fb(fd, width, height,
> lookup_drm_format(format),
> +				modifier, 0, stride, size_ret,
> stride_ret, is_dumb);
>  }
>  
>  /**
> @@ -671,9 +754,10 @@ 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, format,
> tiling,
> -					  bo_size, bo_stride, &fb-
> >size,
> -					  &fb->stride, &fb-
> >is_dumb);
> +	fb->gem_handle = create_bo_for_fb(fd, width, height,
> +					  lookup_drm_format(format),
> +					  tiling, bo_size,
> bo_stride,
> +					  &fb->size, &fb->stride,
> &fb->is_dumb);
>  	igt_assert(fb->gem_handle > 0);
>  
>  	igt_debug("%s(handle=%d, pitch=%d)\n",
> @@ -1069,7 +1153,7 @@ static void create_cairo_surface__blit(int fd,
> struct igt_fb *fb)
>  	 * destination, tiling it at the same time.
>  	 */
>  	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb-
> >height,
> -					       fb->drm_format,
> +					       lookup_drm_format(fb-
> >drm_format),
>  					       LOCAL_DRM_FORMAT_MOD_
> NONE, 0,
>  					       0, &blit-
> >linear.size,
>  					       &blit->linear.stride,
> @@ -1293,14 +1377,12 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp,
> int depth)
>   */
>  uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
>  {
> -	struct format_desc_struct *f;
> +	struct format_desc_struct *f =
> lookup_drm_format(drm_format);
>  
> -	for_each_format(f)
> -		if (f->drm_id == drm_format)
> -			return f->bpp;
> -
> -	igt_assert_f(0, "can't find a bpp format for %08x (%s)\n",
> +	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
>  		     drm_format, igt_format_str(drm_format));
> +
> +	return f->bpp;
>  }
>  
>  /**
> @@ -1313,13 +1395,9 @@ uint32_t igt_drm_format_to_bpp(uint32_t
> drm_format)
>   */
>  const char *igt_format_str(uint32_t drm_format)
>  {
> -	struct format_desc_struct *f;
> -
> -	for_each_format(f)
> -		if (f->drm_id == drm_format)
> -			return f->name;
> +	struct format_desc_struct *f =
> lookup_drm_format(drm_format);
>  
> -	return "invalid";
> +	return f ? f->name : "invalid";
>  }
>  
>  /**
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw Maarten Lankhorst
@ 2018-01-26  9:02   ` Mika Kahola
  2018-01-29 12:10   ` [igt-dev] [PATCH i-g-t] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw, v2 Maarten Lankhorst
  1 sibling, 0 replies; 47+ messages in thread
From: Mika Kahola @ 2018-01-26  9:02 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> Adding a delta offset will allow us to copy planar framebuffers with
> this
> function.
> 

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c            |  8 ++++----
>  lib/intel_batchbuffer.c | 15 ++++++++++-----
>  lib/intel_batchbuffer.h |  2 ++
>  3 files changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 6a331f06724b..1251f462d24e 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -1121,13 +1121,13 @@ static void destroy_cairo_surface__blit(void
> *arg)
>  			I915_GEM_DOMAIN_GTT, 0);
>  
>  	igt_blitter_fast_copy__raw(blit->fd,
> -				   blit->linear.handle,
> +				   blit->linear.handle, 0,
>  				   blit->linear.stride,
>  				   I915_TILING_NONE,
>  				   0, 0, /* src_x, src_y */
>  				   fb->width, fb->height,
>  				   igt_drm_format_to_bpp(fb-
> >drm_format),
> -				   fb->gem_handle,
> +				   fb->gem_handle, 0,
>  				   fb->stride,
>  				   obj_tiling,
>  				   0, 0 /* dst_x, dst_y */);
> @@ -1169,13 +1169,13 @@ static void create_cairo_surface__blit(int
> fd, struct igt_fb *fb)
>  			I915_GEM_DOMAIN_GTT, 0);
>  
>  	igt_blitter_fast_copy__raw(fd,
> -				   fb->gem_handle,
> +				   fb->gem_handle, 0,
>  				   fb->stride,
>  				   obj_tiling,
>  				   0, 0, /* src_x, src_y */
>  				   fb->width, fb->height,
>  				   igt_drm_format_to_bpp(fb-
> >drm_format),
> -				   blit->linear.handle,
> +				   blit->linear.handle, 0,
>  				   blit->linear.stride,
>  				   I915_TILING_NONE,
>  				   0, 0 /* dst_x, dst_y */);
> diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
> index 9a53b6f8e706..3a199fa7ba57 100644
> --- a/lib/intel_batchbuffer.c
> +++ b/lib/intel_batchbuffer.c
> @@ -554,11 +554,12 @@ static uint32_t fast_copy_dword1(unsigned int
> src_tiling,
>  
>  static void
>  fill_relocation(struct drm_i915_gem_relocation_entry *reloc,
> -		uint32_t gem_handle, uint32_t offset, /* in dwords
> */
> +		uint32_t gem_handle, uint32_t delta, /* in bytes */
> +		uint32_t offset, /* in dwords */
>  		uint32_t read_domains, uint32_t write_domains)
>  {
>  	reloc->target_handle = gem_handle;
> -	reloc->delta = 0;
> +	reloc->delta = delta;
>  	reloc->offset = offset * sizeof(uint32_t);
>  	reloc->presumed_offset = 0;
>  	reloc->read_domains = read_domains;
> @@ -599,6 +600,7 @@ static void exec_blit(int fd,
>   * igt_blitter_fast_copy__raw:
>   * @fd: file descriptor of the i915 driver
>   * @src_handle: GEM handle of the source buffer
> + * @src_delta: offset into the source GEM bo, in bytes
>   * @src_stride: Stride (in bytes) of the source buffer
>   * @src_tiling: Tiling mode of the source buffer
>   * @src_x: X coordinate of the source region to copy
> @@ -606,7 +608,8 @@ static void exec_blit(int fd,
>   * @width: Width of the region to copy
>   * @height: Height of the region to copy
>   * @bpp: source and destination bits per pixel
> - * @dst_handle: GEM handle of the source buffer
> + * @dst_handle: GEM handle of the destination buffer
> + * @dst_delta: offset into the destination GEM bo, in bytes
>   * @dst_stride: Stride (in bytes) of the destination buffer
>   * @dst_tiling: Tiling mode of the destination buffer
>   * @dst_x: X coordinate of destination
> @@ -617,6 +620,7 @@ static void exec_blit(int fd,
>  void igt_blitter_fast_copy__raw(int fd,
>  				/* src */
>  				uint32_t src_handle,
> +				unsigned int src_delta,
>  				unsigned int src_stride,
>  				unsigned int src_tiling,
>  				unsigned int src_x, unsigned src_y,
> @@ -629,6 +633,7 @@ void igt_blitter_fast_copy__raw(int fd,
>  
>  				/* dst */
>  				uint32_t dst_handle,
> +				unsigned dst_delta,
>  				unsigned int dst_stride,
>  				unsigned int dst_tiling,
>  				unsigned int dst_x, unsigned dst_y)
> @@ -673,9 +678,9 @@ void igt_blitter_fast_copy__raw(int fd,
>  	batch_handle = gem_create(fd, 4096);
>  	gem_write(fd, batch_handle, 0, batch, sizeof(batch));
>  
> -	fill_relocation(&relocs[0], dst_handle, 4,
> +	fill_relocation(&relocs[0], dst_handle, dst_delta, 4,
>  			I915_GEM_DOMAIN_RENDER,
> I915_GEM_DOMAIN_RENDER);
> -	fill_relocation(&relocs[1], src_handle, 8,
> I915_GEM_DOMAIN_RENDER, 0);
> +	fill_relocation(&relocs[1], src_handle, src_delta, 8,
> I915_GEM_DOMAIN_RENDER, 0);
>  
>  	fill_object(&objs[0], dst_handle, NULL, 0);
>  	fill_object(&objs[1], src_handle, NULL, 0);
> diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
> index 6bee41676627..a6d8f9863698 100644
> --- a/lib/intel_batchbuffer.h
> +++ b/lib/intel_batchbuffer.h
> @@ -234,6 +234,7 @@ void igt_blitter_fast_copy(struct
> intel_batchbuffer *batch,
>  void igt_blitter_fast_copy__raw(int fd,
>  				/* src */
>  				uint32_t src_handle,
> +				unsigned int src_delta,
>  				unsigned int src_stride,
>  				unsigned int src_tiling,
>  				unsigned int src_x, unsigned src_y,
> @@ -246,6 +247,7 @@ void igt_blitter_fast_copy__raw(int fd,
>  
>  				/* dst */
>  				uint32_t dst_handle,
> +				unsigned int dst_delta,
>  				unsigned int dst_stride,
>  				unsigned int dst_tiling,
>  				unsigned int dst_x, unsigned dst_y);
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too Maarten Lankhorst
@ 2018-01-26  9:04   ` Mika Kahola
  0 siblings, 0 replies; 47+ messages in thread
From: Mika Kahola @ 2018-01-26  9:04 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> Nothing uses this currently, but other copy functions have the same
> delta now.
> 

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/intel_batchbuffer.c | 12 ++++++++----
>  lib/intel_batchbuffer.h | 10 ++++++----
>  2 files changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
> index 3a199fa7ba57..3c1689cd302c 100644
> --- a/lib/intel_batchbuffer.c
> +++ b/lib/intel_batchbuffer.c
> @@ -695,12 +695,14 @@ void igt_blitter_fast_copy__raw(int fd,
>   * igt_blitter_fast_copy:
>   * @batch: batchbuffer object
>   * @src: source i-g-t buffer object
> + * @src_delta: offset into the source i-g-t bo
>   * @src_x: source pixel x-coordination
>   * @src_y: source pixel y-coordination
>   * @width: width of the copied rectangle
>   * @height: height of the copied rectangle
>   * @bpp: source and destination bits per pixel
>   * @dst: destination i-g-t buffer object
> + * @dst_delta: offset into the destination i-g-t bo
>   * @dst_x: destination pixel x-coordination
>   * @dst_y: destination pixel y-coordination
>   *
> @@ -709,10 +711,12 @@ void igt_blitter_fast_copy__raw(int fd,
>   * The source and destination surfaces cannot overlap.
>   */
>  void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
> -			   struct igt_buf *src, unsigned src_x,
> unsigned src_y,
> +			   struct igt_buf *src, unsigned src_delta,
> +			   unsigned src_x, unsigned src_y,
>  			   unsigned width, unsigned height,
>  			   int bpp,
> -			   struct igt_buf *dst, unsigned dst_x,
> unsigned dst_y)
> +			   struct igt_buf *dst, unsigned dst_delta,
> +			   unsigned dst_x, unsigned dst_y)
>  {
>  	uint32_t src_pitch, dst_pitch;
>  	uint32_t dword0, dword1;
> @@ -736,11 +740,11 @@ void igt_blitter_fast_copy(struct
> intel_batchbuffer *batch,
>  	OUT_BATCH(dword1 | dst_pitch);
>  	OUT_BATCH((dst_y << 16) | dst_x); /* dst x1,y1 */
>  	OUT_BATCH(((dst_y + height) << 16) | (dst_x + width)); /*
> dst x2,y2 */
> -	OUT_RELOC(dst->bo, I915_GEM_DOMAIN_RENDER,
> I915_GEM_DOMAIN_RENDER, 0);
> +	OUT_RELOC(dst->bo, I915_GEM_DOMAIN_RENDER,
> I915_GEM_DOMAIN_RENDER, dst_delta);
>  	OUT_BATCH(0);	/* dst address upper bits */
>  	OUT_BATCH((src_y << 16) | src_x); /* src x1,y1 */
>  	OUT_BATCH(src_pitch);
> -	OUT_RELOC(src->bo, I915_GEM_DOMAIN_RENDER, 0, 0);
> +	OUT_RELOC(src->bo, I915_GEM_DOMAIN_RENDER, 0, src_delta);
>  	OUT_BATCH(0);	/* src address upper bits */
>  	ADVANCE_BATCH();
>  
> diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
> index a6d8f9863698..2c262d7d7e79 100644
> --- a/lib/intel_batchbuffer.h
> +++ b/lib/intel_batchbuffer.h
> @@ -226,10 +226,12 @@ unsigned igt_buf_width(struct igt_buf *buf);
>  unsigned igt_buf_height(struct igt_buf *buf);
>  
>  void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
> -			  struct igt_buf *src, unsigned src_x,
> unsigned src_y,
> -			  unsigned width, unsigned height,
> -			  int bpp,
> -			  struct igt_buf *dst, unsigned dst_x,
> unsigned dst_y);
> +			   struct igt_buf *src, unsigned src_delta,
> +			   unsigned src_x, unsigned src_y,
> +			   unsigned width, unsigned height,
> +			   int bpp,
> +			   struct igt_buf *dst, unsigned dst_delta,
> +			   unsigned dst_x, unsigned dst_y);
>  
>  void igt_blitter_fast_copy__raw(int fd,
>  				/* src */
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-26  9:00   ` Mika Kahola
@ 2018-01-26 10:20     ` Maarten Lankhorst
  2018-01-26 10:24       ` Mika Kahola
  0 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-26 10:20 UTC (permalink / raw)
  To: mika.kahola, igt-dev

Op 26-01-18 om 10:00 schreef Mika Kahola:
> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
>> By adding support for planar formats to igt_calc_fb_size and
>> create_bo_for_fb,
>> we can calculate dimensions and create backing storage for planar
>> framebuffers.
>>
>> This is required for adding support to create planar framebuffers in
>> the next patch.
>>
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> ---
>>  lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++----
>> ------------
>>  1 file changed, 123 insertions(+), 45 deletions(-)
>>
>> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
>> index da07d1a9e21f..6a331f06724b 100644
>> --- a/lib/igt_fb.c
>> +++ b/lib/igt_fb.c
>> @@ -54,14 +54,16 @@
>>   */
>>  
>>  /* drm fourcc/cairo format maps */
>> -#define DF(did, cid, _bpp, _depth)	\
>> -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth
>> }
>> +#define DF(did, cid, ...)	\
>> +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
>>  static struct format_desc_struct {
>>  	uint32_t drm_id;
>>  	cairo_format_t cairo_id;
>>  	const char *name;
>>  	int bpp;
>>  	int depth;
>> +	int planes;
>> +	int plane_bpp[4];
> should we define a max value for this instead of hardcoded one?
4 planes is the maximum ever. Alpha, R, G and B.
>>  } format_desc[] = {
>>  	DF(RGB565,	RGB16_565,	16, 16),
>>  	//DF(RGB888,	INVALID,	24, 24),
>> @@ -74,6 +76,20 @@ static struct format_desc_struct {
>>  #define for_each_format(f)	\
>>  	for (f = format_desc; f - format_desc <
>> ARRAY_SIZE(format_desc); f++)
>>  
>> +static struct format_desc_struct *lookup_drm_format(uint32_t
>> drm_format)
>> +{
>> +	struct format_desc_struct *format;
>> +
>> +	for_each_format(format) {
>> +		if (format->drm_id != drm_format)
>> +			continue;
>> +
>> +		return format;
>> +	}
>> +
>> +	return NULL;
>> +}
>> +
>>  /**
>>   * igt_get_fb_tile_size:
>>   * @fd: the DRM file descriptor
>> @@ -142,27 +158,68 @@ void igt_get_fb_tile_size(int fd, uint64_t
>> tiling, int fb_bpp,
>>  	}
>>  }
>>  
>> -/**
>> - * igt_calc_fb_size:
>> - * @fd: the DRM file descriptor
>> - * @width: width of the framebuffer in pixels
>> - * @height: height of the framebuffer in pixels
>> - * @format: drm fourcc pixel format code
>> - * @tiling: tiling layout of the framebuffer (as framebuffer
>> modifier)
>> - * @size_ret: returned size for the framebuffer
>> - * @stride_ret: returned stride for the framebuffer
>> - *
>> - * This function returns valid stride and size values for a
>> framebuffer with the
>> - * specified parameters.
>> - */
>> -void igt_calc_fb_size(int fd, int width, int height, uint32_t
>> format, uint64_t tiling,
>> -		      unsigned *size_ret, unsigned *stride_ret)
>> +static unsigned planar_stride(struct format_desc_struct *format,
>> unsigned width, int plane)
>> +{
>> +	unsigned cpp = format->plane_bpp[plane] / 8;
>> +
>> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
>> +		return (width + 1) / 2 * cpp;
>> +
>> +	return width * cpp;
>> +}
>> +
>> +static unsigned planar_height(struct format_desc_struct *format,
>> unsigned height, int plane)
>> +{
>> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
>> +		return (height + 1) / 2;
>> +
>> +	return height;
>> +}
>> +
>> +static void calc_fb_size_planar(int fd, int width, int height,
>> +				struct format_desc_struct *format,
>> +				uint64_t tiling, unsigned *size_ret,
>> +				unsigned *stride_ret, unsigned
>> *offsets)
>> +{
>> +	int plane;
>> +	unsigned stride = 0, tile_width, tile_height;
>> +
>> +	*size_ret = 0;
>> +
>> +	for (plane = 0; plane < format->planes; plane++) {
>> +		unsigned plane_stride;
>> +
>> +		igt_get_fb_tile_size(fd, tiling, format-
>>> plane_bpp[plane], &tile_width, &tile_height);
>> +
>> +		plane_stride = ALIGN(planar_stride(format, width,
>> plane), tile_width);
>> +		if (stride < plane_stride)
>> +			stride = plane_stride;
>> +	}
>> +
>> +	for (plane = 0; plane < format->planes; plane++) {
>> +		if (offsets)
>> +			offsets[plane] = *size_ret;
>> +
>> +		igt_get_fb_tile_size(fd, tiling, format-
>>> plane_bpp[plane], &tile_width, &tile_height);
>> +
>> +		*size_ret += stride * ALIGN(planar_height(format,
>> height, plane), tile_height);
>> +	}
>> +
>> +	if (offsets)
>> +		for (; plane < 4; plane++)
> We could loop through max define value here too instead of hardcoded
> one.
>
>> +			offsets[plane] = 0;
>> +
>> +	*stride_ret = stride;
>> +}
>> +
>> +static void calc_fb_size_packed(int fd, int width, int height,
>> +				struct format_desc_struct *format,
>> uint64_t tiling,
>> +				unsigned *size_ret, unsigned
>> *stride_ret)
>>  {
>>  	unsigned int tile_width, tile_height, stride, size;
>> -	int bpp = igt_drm_format_to_bpp(format);
>> -	int byte_width = width * (bpp / 8);
>> +	int byte_width = width * (format->bpp / 8);
>>  
>> -	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width,
>> &tile_height);
>> +	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width,
>> &tile_height);
>>  
>>  	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
>>  	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
>> @@ -176,7 +233,7 @@ void igt_calc_fb_size(int fd, int width, int
>> height, uint32_t format, uint64_t t
>>  		 * tiled. But then that failure is expected.
>>  		 */
>>  
>> -		v = width * bpp / 8;
>> +		v = byte_width;
>>  		for (stride = 512; stride < v; stride *= 2)
>>  			;
>>  
>> @@ -192,6 +249,31 @@ void igt_calc_fb_size(int fd, int width, int
>> height, uint32_t format, uint64_t t
>>  	*size_ret = size;
>>  }
>>  
>> +/**
>> + * igt_calc_fb_size:
>> + * @fd: the DRM file descriptor
>> + * @width: width of the framebuffer in pixels
>> + * @height: height of the framebuffer in pixels
>> + * @format: drm fourcc pixel format code
>> + * @tiling: tiling layout of the framebuffer (as framebuffer
>> modifier)
>> + * @size_ret: returned size for the framebuffer
>> + * @stride_ret: returned stride for the framebuffer
>> + *
>> + * This function returns valid stride and size values for a
>> framebuffer with the
>> + * specified parameters.
>> + */
>> +void igt_calc_fb_size(int fd, int width, int height, uint32_t
>> drm_format, uint64_t tiling,
>> +		      unsigned *size_ret, unsigned *stride_ret)
>> +{
>> +	struct format_desc_struct *format =
>> lookup_drm_format(drm_format);
>> +	igt_assert(format);
>> +
>> +	if (format->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);
>> +}
>> +
>>  /**
>>   * igt_fb_mod_to_tiling:
>>   * @modifier: DRM framebuffer modifier
>> @@ -245,17 +327,20 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling)
>>  }
>>  
>>  /* helpers to create nice-looking framebuffers */
>> -static int create_bo_for_fb(int fd, int width, int height, uint32_t
>> format,
>> +static int create_bo_for_fb(int fd, int width, int height,
>> +			    struct format_desc_struct *format,
>>  			    uint64_t tiling, unsigned size, unsigned
>> stride,
>>  			    unsigned *size_ret, unsigned
>> *stride_ret,
>>  			    bool *is_dumb)
>>  {
>>  	int bo;
>>  
>> -	if (tiling || size || stride) {
>> +	igt_assert(format);
>> +
>> +	if (tiling || size || stride || format->planes > 1) {
>>  		unsigned calculated_size, calculated_stride;
>>  
>> -		igt_calc_fb_size(fd, width, height, format, tiling,
>> +		igt_calc_fb_size(fd, width, height, format->drm_id,
>> tiling,
>>  				 &calculated_size,
>> &calculated_stride);
>>  		if (stride == 0)
>>  			stride = calculated_stride;
>> @@ -290,12 +375,10 @@ static int create_bo_for_fb(int fd, int width,
>> int height, uint32_t format,
>>  			return -EINVAL;
>>  		}
>>  	} else {
>> -		int bpp = igt_drm_format_to_bpp(format);
>> -
>>  		if (is_dumb)
>>  			*is_dumb = true;
>>  
>> -		return kmstest_dumb_create(fd, width, height, bpp,
>> stride_ret,
>> +		return kmstest_dumb_create(fd, width, height,
>> format->bpp, stride_ret,
>>  					   size_ret);
>>  	}
>>  }
>> @@ -323,8 +406,8 @@ 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, format, modifier,
>> 0, stride,
>> -			     size_ret, stride_ret, is_dumb);
>> +	return create_bo_for_fb(fd, width, height,
>> lookup_drm_format(format),
>> +				modifier, 0, stride, size_ret,
>> stride_ret, is_dumb);
>>  }
>>  
>>  /**
>> @@ -671,9 +754,10 @@ 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, format,
>> tiling,
>> -					  bo_size, bo_stride, &fb-
>>> size,
>> -					  &fb->stride, &fb-
>>> is_dumb);
>> +	fb->gem_handle = create_bo_for_fb(fd, width, height,
>> +					  lookup_drm_format(format),
>> +					  tiling, bo_size,
>> bo_stride,
>> +					  &fb->size, &fb->stride,
>> &fb->is_dumb);
>>  	igt_assert(fb->gem_handle > 0);
>>  
>>  	igt_debug("%s(handle=%d, pitch=%d)\n",
>> @@ -1069,7 +1153,7 @@ static void create_cairo_surface__blit(int fd,
>> struct igt_fb *fb)
>>  	 * destination, tiling it at the same time.
>>  	 */
>>  	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb-
>>> height,
>> -					       fb->drm_format,
>> +					       lookup_drm_format(fb-
>>> drm_format),
>>  					       LOCAL_DRM_FORMAT_MOD_
>> NONE, 0,
>>  					       0, &blit-
>>> linear.size,
>>  					       &blit->linear.stride,
>> @@ -1293,14 +1377,12 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp,
>> int depth)
>>   */
>>  uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
>>  {
>> -	struct format_desc_struct *f;
>> +	struct format_desc_struct *f =
>> lookup_drm_format(drm_format);
>>  
>> -	for_each_format(f)
>> -		if (f->drm_id == drm_format)
>> -			return f->bpp;
>> -
>> -	igt_assert_f(0, "can't find a bpp format for %08x (%s)\n",
>> +	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
>>  		     drm_format, igt_format_str(drm_format));
>> +
>> +	return f->bpp;
>>  }
>>  
>>  /**
>> @@ -1313,13 +1395,9 @@ uint32_t igt_drm_format_to_bpp(uint32_t
>> drm_format)
>>   */
>>  const char *igt_format_str(uint32_t drm_format)
>>  {
>> -	struct format_desc_struct *f;
>> -
>> -	for_each_format(f)
>> -		if (f->drm_id == drm_format)
>> -			return f->name;
>> +	struct format_desc_struct *f =
>> lookup_drm_format(drm_format);
>>  
>> -	return "invalid";
>> +	return f ? f->name : "invalid";
>>  }
>>  
>>  /**


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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-26 10:20     ` Maarten Lankhorst
@ 2018-01-26 10:24       ` Mika Kahola
  2018-01-26 12:01         ` Maarten Lankhorst
  0 siblings, 1 reply; 47+ messages in thread
From: Mika Kahola @ 2018-01-26 10:24 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Fri, 2018-01-26 at 11:20 +0100, Maarten Lankhorst wrote:
> Op 26-01-18 om 10:00 schreef Mika Kahola:
> > 
> > On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> > > 
> > > By adding support for planar formats to igt_calc_fb_size and
> > > create_bo_for_fb,
> > > we can calculate dimensions and create backing storage for planar
> > > framebuffers.
> > > 
> > > This is required for adding support to create planar framebuffers
> > > in
> > > the next patch.
> > > 
> > > Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.c
> > > om>
> > > ---
> > >  lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++
> > > ----
> > > ------------
> > >  1 file changed, 123 insertions(+), 45 deletions(-)
> > > 
> > > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > > index da07d1a9e21f..6a331f06724b 100644
> > > --- a/lib/igt_fb.c
> > > +++ b/lib/igt_fb.c
> > > @@ -54,14 +54,16 @@
> > >   */
> > >  
> > >  /* drm fourcc/cairo format maps */
> > > -#define DF(did, cid, _bpp, _depth)	\
> > > -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp,
> > > _depth
> > > }
> > > +#define DF(did, cid, ...)	\
> > > +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did,
> > > __VA_ARGS__ }
> > >  static struct format_desc_struct {
> > >  	uint32_t drm_id;
> > >  	cairo_format_t cairo_id;
> > >  	const char *name;
> > >  	int bpp;
> > >  	int depth;
> > > +	int planes;
> > > +	int plane_bpp[4];
> > should we define a max value for this instead of hardcoded one?
> 4 planes is the maximum ever. Alpha, R, G and B.
Yes, but even so I'm not really a fan of harcoded values.
> > 
> > > 
> > >  } format_desc[] = {
> > >  	DF(RGB565,	RGB16_565,	16, 16),
> > >  	//DF(RGB888,	INVALID,	24, 24),
> > > @@ -74,6 +76,20 @@ static struct format_desc_struct {
> > >  #define for_each_format(f)	\
> > >  	for (f = format_desc; f - format_desc <
> > > ARRAY_SIZE(format_desc); f++)
> > >  
> > > +static struct format_desc_struct *lookup_drm_format(uint32_t
> > > drm_format)
> > > +{
> > > +	struct format_desc_struct *format;
> > > +
> > > +	for_each_format(format) {
> > > +		if (format->drm_id != drm_format)
> > > +			continue;
> > > +
> > > +		return format;
> > > +	}
> > > +
> > > +	return NULL;
> > > +}
> > > +
> > >  /**
> > >   * igt_get_fb_tile_size:
> > >   * @fd: the DRM file descriptor
> > > @@ -142,27 +158,68 @@ void igt_get_fb_tile_size(int fd, uint64_t
> > > tiling, int fb_bpp,
> > >  	}
> > >  }
> > >  
> > > -/**
> > > - * igt_calc_fb_size:
> > > - * @fd: the DRM file descriptor
> > > - * @width: width of the framebuffer in pixels
> > > - * @height: height of the framebuffer in pixels
> > > - * @format: drm fourcc pixel format code
> > > - * @tiling: tiling layout of the framebuffer (as framebuffer
> > > modifier)
> > > - * @size_ret: returned size for the framebuffer
> > > - * @stride_ret: returned stride for the framebuffer
> > > - *
> > > - * This function returns valid stride and size values for a
> > > framebuffer with the
> > > - * specified parameters.
> > > - */
> > > -void igt_calc_fb_size(int fd, int width, int height, uint32_t
> > > format, uint64_t tiling,
> > > -		      unsigned *size_ret, unsigned *stride_ret)
> > > +static unsigned planar_stride(struct format_desc_struct *format,
> > > unsigned width, int plane)
> > > +{
> > > +	unsigned cpp = format->plane_bpp[plane] / 8;
> > > +
> > > +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> > > +		return (width + 1) / 2 * cpp;
> > > +
> > > +	return width * cpp;
> > > +}
> > > +
> > > +static unsigned planar_height(struct format_desc_struct *format,
> > > unsigned height, int plane)
> > > +{
> > > +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> > > +		return (height + 1) / 2;
> > > +
> > > +	return height;
> > > +}
> > > +
> > > +static void calc_fb_size_planar(int fd, int width, int height,
> > > +				struct format_desc_struct
> > > *format,
> > > +				uint64_t tiling, unsigned
> > > *size_ret,
> > > +				unsigned *stride_ret, unsigned
> > > *offsets)
> > > +{
> > > +	int plane;
> > > +	unsigned stride = 0, tile_width, tile_height;
> > > +
> > > +	*size_ret = 0;
> > > +
> > > +	for (plane = 0; plane < format->planes; plane++) {
> > > +		unsigned plane_stride;
> > > +
> > > +		igt_get_fb_tile_size(fd, tiling, format-
> > > > 
> > > > plane_bpp[plane], &tile_width, &tile_height);
> > > +
> > > +		plane_stride = ALIGN(planar_stride(format,
> > > width,
> > > plane), tile_width);
> > > +		if (stride < plane_stride)
> > > +			stride = plane_stride;
> > > +	}
> > > +
> > > +	for (plane = 0; plane < format->planes; plane++) {
> > > +		if (offsets)
> > > +			offsets[plane] = *size_ret;
> > > +
> > > +		igt_get_fb_tile_size(fd, tiling, format-
> > > > 
> > > > plane_bpp[plane], &tile_width, &tile_height);
> > > +
> > > +		*size_ret += stride *
> > > ALIGN(planar_height(format,
> > > height, plane), tile_height);
> > > +	}
> > > +
> > > +	if (offsets)
> > > +		for (; plane < 4; plane++)
> > We could loop through max define value here too instead of
> > hardcoded
> > one.
> > 
> > > 
> > > +			offsets[plane] = 0;
> > > +
> > > +	*stride_ret = stride;
> > > +}
> > > +
> > > +static void calc_fb_size_packed(int fd, int width, int height,
> > > +				struct format_desc_struct
> > > *format,
> > > uint64_t tiling,
> > > +				unsigned *size_ret, unsigned
> > > *stride_ret)
> > >  {
> > >  	unsigned int tile_width, tile_height, stride, size;
> > > -	int bpp = igt_drm_format_to_bpp(format);
> > > -	int byte_width = width * (bpp / 8);
> > > +	int byte_width = width * (format->bpp / 8);
> > >  
> > > -	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width,
> > > &tile_height);
> > > +	igt_get_fb_tile_size(fd, tiling, format->bpp,
> > > &tile_width,
> > > &tile_height);
> > >  
> > >  	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
> > >  	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
> > > @@ -176,7 +233,7 @@ void igt_calc_fb_size(int fd, int width, int
> > > height, uint32_t format, uint64_t t
> > >  		 * tiled. But then that failure is expected.
> > >  		 */
> > >  
> > > -		v = width * bpp / 8;
> > > +		v = byte_width;
> > >  		for (stride = 512; stride < v; stride *= 2)
> > >  			;
> > >  
> > > @@ -192,6 +249,31 @@ void igt_calc_fb_size(int fd, int width, int
> > > height, uint32_t format, uint64_t t
> > >  	*size_ret = size;
> > >  }
> > >  
> > > +/**
> > > + * igt_calc_fb_size:
> > > + * @fd: the DRM file descriptor
> > > + * @width: width of the framebuffer in pixels
> > > + * @height: height of the framebuffer in pixels
> > > + * @format: drm fourcc pixel format code
> > > + * @tiling: tiling layout of the framebuffer (as framebuffer
> > > modifier)
> > > + * @size_ret: returned size for the framebuffer
> > > + * @stride_ret: returned stride for the framebuffer
> > > + *
> > > + * This function returns valid stride and size values for a
> > > framebuffer with the
> > > + * specified parameters.
> > > + */
> > > +void igt_calc_fb_size(int fd, int width, int height, uint32_t
> > > drm_format, uint64_t tiling,
> > > +		      unsigned *size_ret, unsigned *stride_ret)
> > > +{
> > > +	struct format_desc_struct *format =
> > > lookup_drm_format(drm_format);
> > > +	igt_assert(format);
> > > +
> > > +	if (format->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);
> > > +}
> > > +
> > >  /**
> > >   * igt_fb_mod_to_tiling:
> > >   * @modifier: DRM framebuffer modifier
> > > @@ -245,17 +327,20 @@ uint64_t igt_fb_tiling_to_mod(uint64_t
> > > tiling)
> > >  }
> > >  
> > >  /* helpers to create nice-looking framebuffers */
> > > -static int create_bo_for_fb(int fd, int width, int height,
> > > uint32_t
> > > format,
> > > +static int create_bo_for_fb(int fd, int width, int height,
> > > +			    struct format_desc_struct *format,
> > >  			    uint64_t tiling, unsigned size,
> > > unsigned
> > > stride,
> > >  			    unsigned *size_ret, unsigned
> > > *stride_ret,
> > >  			    bool *is_dumb)
> > >  {
> > >  	int bo;
> > >  
> > > -	if (tiling || size || stride) {
> > > +	igt_assert(format);
> > > +
> > > +	if (tiling || size || stride || format->planes > 1) {
> > >  		unsigned calculated_size, calculated_stride;
> > >  
> > > -		igt_calc_fb_size(fd, width, height, format,
> > > tiling,
> > > +		igt_calc_fb_size(fd, width, height, format-
> > > >drm_id,
> > > tiling,
> > >  				 &calculated_size,
> > > &calculated_stride);
> > >  		if (stride == 0)
> > >  			stride = calculated_stride;
> > > @@ -290,12 +375,10 @@ static int create_bo_for_fb(int fd, int
> > > width,
> > > int height, uint32_t format,
> > >  			return -EINVAL;
> > >  		}
> > >  	} else {
> > > -		int bpp = igt_drm_format_to_bpp(format);
> > > -
> > >  		if (is_dumb)
> > >  			*is_dumb = true;
> > >  
> > > -		return kmstest_dumb_create(fd, width, height,
> > > bpp,
> > > stride_ret,
> > > +		return kmstest_dumb_create(fd, width, height,
> > > format->bpp, stride_ret,
> > >  					   size_ret);
> > >  	}
> > >  }
> > > @@ -323,8 +406,8 @@ 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, format,
> > > modifier,
> > > 0, stride,
> > > -			     size_ret, stride_ret, is_dumb);
> > > +	return create_bo_for_fb(fd, width, height,
> > > lookup_drm_format(format),
> > > +				modifier, 0, stride, size_ret,
> > > stride_ret, is_dumb);
> > >  }
> > >  
> > >  /**
> > > @@ -671,9 +754,10 @@ 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,
> > > format,
> > > tiling,
> > > -					  bo_size, bo_stride,
> > > &fb-
> > > > 
> > > > size,
> > > -					  &fb->stride, &fb-
> > > > 
> > > > is_dumb);
> > > +	fb->gem_handle = create_bo_for_fb(fd, width, height,
> > > +					  lookup_drm_format(form
> > > at),
> > > +					  tiling, bo_size,
> > > bo_stride,
> > > +					  &fb->size, &fb-
> > > >stride,
> > > &fb->is_dumb);
> > >  	igt_assert(fb->gem_handle > 0);
> > >  
> > >  	igt_debug("%s(handle=%d, pitch=%d)\n",
> > > @@ -1069,7 +1153,7 @@ static void create_cairo_surface__blit(int
> > > fd,
> > > struct igt_fb *fb)
> > >  	 * destination, tiling it at the same time.
> > >  	 */
> > >  	blit->linear.handle = create_bo_for_fb(fd, fb->width,
> > > fb-
> > > > 
> > > > height,
> > > -					       fb->drm_format,
> > > +					       lookup_drm_format
> > > (fb-
> > > > 
> > > > drm_format),
> > >  					       LOCAL_DRM_FORMAT_
> > > MOD_
> > > NONE, 0,
> > >  					       0, &blit-
> > > > 
> > > > linear.size,
> > >  					       &blit-
> > > >linear.stride,
> > > @@ -1293,14 +1377,12 @@ uint32_t igt_bpp_depth_to_drm_format(int
> > > bpp,
> > > int depth)
> > >   */
> > >  uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
> > >  {
> > > -	struct format_desc_struct *f;
> > > +	struct format_desc_struct *f =
> > > lookup_drm_format(drm_format);
> > >  
> > > -	for_each_format(f)
> > > -		if (f->drm_id == drm_format)
> > > -			return f->bpp;
> > > -
> > > -	igt_assert_f(0, "can't find a bpp format for %08x
> > > (%s)\n",
> > > +	igt_assert_f(f, "can't find a bpp format for %08x
> > > (%s)\n",
> > >  		     drm_format, igt_format_str(drm_format));
> > > +
> > > +	return f->bpp;
> > >  }
> > >  
> > >  /**
> > > @@ -1313,13 +1395,9 @@ uint32_t igt_drm_format_to_bpp(uint32_t
> > > drm_format)
> > >   */
> > >  const char *igt_format_str(uint32_t drm_format)
> > >  {
> > > -	struct format_desc_struct *f;
> > > -
> > > -	for_each_format(f)
> > > -		if (f->drm_id == drm_format)
> > > -			return f->name;
> > > +	struct format_desc_struct *f =
> > > lookup_drm_format(drm_format);
> > >  
> > > -	return "invalid";
> > > +	return f ? f->name : "invalid";
> > >  }
> > >  
> > >  /**
> 
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-26 10:24       ` Mika Kahola
@ 2018-01-26 12:01         ` Maarten Lankhorst
  2018-01-26 13:10           ` Mika Kahola
  0 siblings, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-26 12:01 UTC (permalink / raw)
  To: mika.kahola, igt-dev

Op 26-01-18 om 11:24 schreef Mika Kahola:
> On Fri, 2018-01-26 at 11:20 +0100, Maarten Lankhorst wrote:
>> Op 26-01-18 om 10:00 schreef Mika Kahola:
>>> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
>>>> By adding support for planar formats to igt_calc_fb_size and
>>>> create_bo_for_fb,
>>>> we can calculate dimensions and create backing storage for planar
>>>> framebuffers.
>>>>
>>>> This is required for adding support to create planar framebuffers
>>>> in
>>>> the next patch.
>>>>
>>>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.c
>>>> om>
>>>> ---
>>>>  lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++
>>>> ----
>>>> ------------
>>>>  1 file changed, 123 insertions(+), 45 deletions(-)
>>>>
>>>> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
>>>> index da07d1a9e21f..6a331f06724b 100644
>>>> --- a/lib/igt_fb.c
>>>> +++ b/lib/igt_fb.c
>>>> @@ -54,14 +54,16 @@
>>>>   */
>>>>  
>>>>  /* drm fourcc/cairo format maps */
>>>> -#define DF(did, cid, _bpp, _depth)	\
>>>> -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp,
>>>> _depth
>>>> }
>>>> +#define DF(did, cid, ...)	\
>>>> +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did,
>>>> __VA_ARGS__ }
>>>>  static struct format_desc_struct {
>>>>  	uint32_t drm_id;
>>>>  	cairo_format_t cairo_id;
>>>>  	const char *name;
>>>>  	int bpp;
>>>>  	int depth;
>>>> +	int planes;
>>>> +	int plane_bpp[4];
>>> should we define a max value for this instead of hardcoded one?
>> 4 planes is the maximum ever. Alpha, R, G and B.
> Yes, but even so I'm not really a fan of harcoded values.
Only the array definitions use those values. There aren't even planar formats that support > 4 planes,
and uapi/drm/drm_mode.h also uses 4 everywhere. It's fine unless we everextend the kernel api to support
more than 4 planes, but this is very unlikely since the hw doesn't even exist. I think it's fine to hardcode this. All users use ARRAY_SIZE or sizeof as appropriate, so it won't matter much.

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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-26 12:01         ` Maarten Lankhorst
@ 2018-01-26 13:10           ` Mika Kahola
  0 siblings, 0 replies; 47+ messages in thread
From: Mika Kahola @ 2018-01-26 13:10 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Fri, 2018-01-26 at 13:01 +0100, Maarten Lankhorst wrote:
> Op 26-01-18 om 11:24 schreef Mika Kahola:
> > 
> > On Fri, 2018-01-26 at 11:20 +0100, Maarten Lankhorst wrote:
> > > 
> > > Op 26-01-18 om 10:00 schreef Mika Kahola:
> > > > 
> > > > On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> > > > > 
> > > > > By adding support for planar formats to igt_calc_fb_size and
> > > > > create_bo_for_fb,
> > > > > we can calculate dimensions and create backing storage for
> > > > > planar
> > > > > framebuffers.
> > > > > 
> > > > > This is required for adding support to create planar
> > > > > framebuffers
> > > > > in
> > > > > the next patch.
> > > > > 
> > > > > Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.int
> > > > > el.c
> > > > > om>
> > > > > ---
> > > > >  lib/igt_fb.c | 168
> > > > > +++++++++++++++++++++++++++++++++++++++++++
> > > > > ----
> > > > > ------------
> > > > >  1 file changed, 123 insertions(+), 45 deletions(-)
> > > > > 
> > > > > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > > > > index da07d1a9e21f..6a331f06724b 100644
> > > > > --- a/lib/igt_fb.c
> > > > > +++ b/lib/igt_fb.c
> > > > > @@ -54,14 +54,16 @@
> > > > >   */
> > > > >  
> > > > >  /* drm fourcc/cairo format maps */
> > > > > -#define DF(did, cid, _bpp, _depth)	\
> > > > > -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp,
> > > > > _depth
> > > > > }
> > > > > +#define DF(did, cid, ...)	\
> > > > > +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did,
> > > > > __VA_ARGS__ }
> > > > >  static struct format_desc_struct {
> > > > >  	uint32_t drm_id;
> > > > >  	cairo_format_t cairo_id;
> > > > >  	const char *name;
> > > > >  	int bpp;
> > > > >  	int depth;
> > > > > +	int planes;
> > > > > +	int plane_bpp[4];
> > > > should we define a max value for this instead of hardcoded one?
> > > 4 planes is the maximum ever. Alpha, R, G and B.
> > Yes, but even so I'm not really a fan of harcoded values.
> Only the array definitions use those values. There aren't even planar
> formats that support > 4 planes,
> and uapi/drm/drm_mode.h also uses 4 everywhere. It's fine unless we
> everextend the kernel api to support
> more than 4 planes, but this is very unlikely since the hw doesn't
> even exist. I think it's fine to hardcode this. All users use
> ARRAY_SIZE or sizeof as appropriate, so it won't matter much.
What I was after on my comment was that when you are browsing through
the patch or the file itself, you don't realize that easily what is
meant with these hardcoded values. You have to stop for a second to
think and then you figure it out. The comment was all about enhancing
readability. For loops, maybe we could use ARRAY_SIZE() here too?

> 
> ~Maarten
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb Maarten Lankhorst
@ 2018-01-26 13:56   ` Mika Kahola
  2018-02-28 15:40     ` Arkadiusz Hiler
  0 siblings, 1 reply; 47+ messages in thread
From: Mika Kahola @ 2018-01-26 13:56 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> This is required to make the test pass when we start enabling
> planar formats in the future.
> 

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/intel_batchbuffer.c     | 14 ++++++++------
>  lib/intel_batchbuffer.h     |  4 ++--
>  tests/gem_concurrent_all.c  |  4 ++--
>  tests/gem_read_read_speed.c |  4 ++--
>  tests/kms_render.c          | 15 +++++++++------
>  5 files changed, 23 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
> index 3c1689cd302c..9f162f09658a 100644
> --- a/lib/intel_batchbuffer.c
> +++ b/lib/intel_batchbuffer.c
> @@ -310,10 +310,12 @@ intel_batchbuffer_data(struct intel_batchbuffer
> *batch,
>   * intel_blt_copy:
>   * @batch: batchbuffer object
>   * @src_bo: source libdrm buffer object
> + * @src_delta: offset into the source bo, in bytes
>   * @src_x1: source pixel x-coordination
>   * @src_y1: source pixel y-coordination
>   * @src_pitch: @src_bo's pitch in bytes
>   * @dst_bo: destination libdrm buffer object
> + * @sdst_delta: offset into the source bo, in bytes
>   * @dst_x1: destination pixel x-coordination
>   * @dst_y1: destination pixel y-coordination
>   * @dst_pitch: @dst_bo's pitch in bytes
> @@ -326,8 +328,8 @@ intel_batchbuffer_data(struct intel_batchbuffer
> *batch,
>   */
>  void
>  intel_blt_copy(struct intel_batchbuffer *batch,
> -	       drm_intel_bo *src_bo, int src_x1, int src_y1, int
> src_pitch,
> -	       drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int
> dst_pitch,
> +	       drm_intel_bo *src_bo, uint32_t src_delta, int src_x1,
> int src_y1, int src_pitch,
> +	       drm_intel_bo *dst_bo, uint32_t dst_delta, int dst_x1,
> int dst_y1, int dst_pitch,
>  	       int width, int height, int bpp)
>  {
>  	const int gen = batch->gen;
> @@ -387,10 +389,10 @@ intel_blt_copy(struct intel_batchbuffer *batch,
>  		  dst_pitch);
>  	OUT_BATCH((dst_y1 << 16) | dst_x1); /* dst x1,y1 */
>  	OUT_BATCH(((dst_y1 + height) << 16) | (dst_x1 + width)); /*
> dst x2,y2 */
> -	OUT_RELOC_FENCED(dst_bo, I915_GEM_DOMAIN_RENDER,
> I915_GEM_DOMAIN_RENDER, 0);
> +	OUT_RELOC_FENCED(dst_bo, I915_GEM_DOMAIN_RENDER,
> I915_GEM_DOMAIN_RENDER, dst_delta);
>  	OUT_BATCH((src_y1 << 16) | src_x1); /* src x1,y1 */
>  	OUT_BATCH(src_pitch);
> -	OUT_RELOC_FENCED(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
> +	OUT_RELOC_FENCED(src_bo, I915_GEM_DOMAIN_RENDER, 0,
> src_delta);
>  	ADVANCE_BATCH();
>  
>  #define CMD_POLY_STIPPLE_OFFSET       0x7906
> @@ -431,8 +433,8 @@ intel_copy_bo(struct intel_batchbuffer *batch,
>  	igt_assert(size % 4096 == 0);
>  
>  	intel_blt_copy(batch,
> -		       src_bo, 0, 0, 4096,
> -		       dst_bo, 0, 0, 4096,
> +		       src_bo, 0, 0, 0, 4096,
> +		       dst_bo, 0, 0, 0, 4096,
>  		       4096/4, size/4096, 32);
>  }
>  
> diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
> index 2c262d7d7e79..8c8c7ee543dd 100644
> --- a/lib/intel_batchbuffer.h
> +++ b/lib/intel_batchbuffer.h
> @@ -181,8 +181,8 @@ intel_batchbuffer_require_space(struct
> intel_batchbuffer *batch,
>  
>  void
>  intel_blt_copy(struct intel_batchbuffer *batch,
> -	      drm_intel_bo *src_bo, int src_x1, int src_y1, int
> src_pitch,
> -	      drm_intel_bo *dst_bo, int dst_x1, int dst_y1, int
> dst_pitch,
> +	      drm_intel_bo *src_bo, uint32_t src_delta, int src_x1,
> int src_y1, int src_pitch,
> +	      drm_intel_bo *dst_bo, uint32_t dst_delta, int dst_x1,
> int dst_y1, int dst_pitch,
>  	      int width, int height, int bpp);
>  void intel_copy_bo(struct intel_batchbuffer *batch,
>  		   drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
> diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c
> index 201b491bc245..620f8c21083a 100644
> --- a/tests/gem_concurrent_all.c
> +++ b/tests/gem_concurrent_all.c
> @@ -874,8 +874,8 @@ static void render_copy_bo(struct buffers *b,
> drm_intel_bo *dst, drm_intel_bo *s
>  static void blt_copy_bo(struct buffers *b, drm_intel_bo *dst,
> drm_intel_bo *src)
>  {
>  	intel_blt_copy(b->batch,
> -		       src, 0, 0, 4*b->width,
> -		       dst, 0, 0, 4*b->width,
> +		       src, 0, 0, 0, 4*b->width,
> +		       dst, 0, 0, 0, 4*b->width,
>  		       b->width, b->height, 32);
>  }
>  
> diff --git a/tests/gem_read_read_speed.c
> b/tests/gem_read_read_speed.c
> index 3dcf440c7f81..d879f1225440 100644
> --- a/tests/gem_read_read_speed.c
> +++ b/tests/gem_read_read_speed.c
> @@ -83,8 +83,8 @@ static drm_intel_bo *bcs_copy_bo(drm_intel_bo *dst,
> drm_intel_bo *src)
>  	drm_intel_bo_reference(bo);
>  
>  	intel_blt_copy(batch,
> -		       src, 0, 0, 4*width,
> -		       dst, 0, 0, 4*width,
> +		       src, 0, 0, 0, 4*width,
> +		       dst, 0, 0, 0, 4*width,
>  		       width, height, 32);
>  
>  	return bo;
> diff --git a/tests/kms_render.c b/tests/kms_render.c
> index 25a0c05b547c..255cf3de39cf 100644
> --- a/tests/kms_render.c
> +++ b/tests/kms_render.c
> @@ -64,7 +64,7 @@ static void gpu_blit(struct igt_fb *dst_fb, struct
> igt_fb *src_fb)
>  {
>  	drm_intel_bo *dst_bo;
>  	drm_intel_bo *src_bo;
> -	int bpp;
> +	int i;
>  	static drm_intel_bufmgr *bufmgr;
>  	struct intel_batchbuffer *batch;
>  	uint32_t devid;
> @@ -79,7 +79,7 @@ static void gpu_blit(struct igt_fb *dst_fb, struct
> igt_fb *src_fb)
>  	igt_assert(dst_fb->drm_format == src_fb->drm_format);
>  	igt_assert(src_fb->drm_format == DRM_FORMAT_RGB565 ||
>  	       igt_drm_format_to_bpp(src_fb->drm_format) != 16);
> -	bpp = igt_drm_format_to_bpp(src_fb->drm_format);
> +
>  	dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd,
> "destination",
>  					 dst_fb->gem_handle);
>  	igt_assert(dst_bo);
> @@ -87,10 +87,13 @@ static void gpu_blit(struct igt_fb *dst_fb,
> struct igt_fb *src_fb)
>  					 src_fb->gem_handle);
>  	igt_assert(src_bo);
>  
> -	intel_blt_copy(batch,
> -		       src_bo, 0, 0, src_fb->width * bpp / 8,
> -		       dst_bo, 0, 0, dst_fb->width * bpp / 8,
> -		       src_fb->width, src_fb->height, bpp);
> +	for (i = 0; i < src_fb->num_planes; i++) {
> +		intel_blt_copy(batch,
> +			      src_bo, src_fb->offsets[i], 0, 0,
> src_fb->stride,
> +			      dst_bo, dst_fb->offsets[i], 0, 0,
> dst_fb->stride,
> +			      src_fb->plane_width[i], src_fb-
> >plane_height[i],
> +			      src_fb->plane_bpp[i]);
> +	}
>  	intel_batchbuffer_flush(batch);
>  	gem_quiescent_gpu(drm_fd);
>  
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v3.
  2018-01-24 10:53     ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v3 Maarten Lankhorst
@ 2018-01-29  8:44       ` Mika Kahola
  0 siblings, 0 replies; 47+ messages in thread
From: Mika Kahola @ 2018-01-29  8:44 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Wed, 2018-01-24 at 11:53 +0100, Maarten Lankhorst wrote:
> Add support to create planar framebuffers, but don't add formats
> that support them yet. This first requires conversion to the RGB24
> format.
> 
> Changes since v1:
> - Don't crash in igt_create_bo_with_dimensions().
> Changes since v2:
> - Zero offsets for dumb fb too.
> 

Reviewed-by: Mika Kahola <mika.kahola@intel.com>

> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c             | 76 +++++++++++++++++++++++++++++++++++---
> ----------
>  lib/igt_fb.h             | 10 +++++++
>  lib/ioctl_wrappers.c     | 11 +++++--
>  lib/ioctl_wrappers.h     |  2 +-
>  tests/kms_draw_crc.c     |  2 +-
>  tests/kms_rotation_crc.c |  5 ++--
>  tests/prime_vgem.c       |  2 +-
>  7 files changed, 81 insertions(+), 27 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 1251f462d24e..9d60280f198e 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -158,14 +158,19 @@ void igt_get_fb_tile_size(int fd, uint64_t
> tiling, int fb_bpp,
>  	}
>  }
>  
> +static unsigned planar_width(struct format_desc_struct *format,
> unsigned width, int plane)
> +{
> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> +		return (width + 1) / 2;
> +
> +	return width;
> +}
> +
>  static unsigned planar_stride(struct format_desc_struct *format,
> unsigned width, int plane)
>  {
>  	unsigned cpp = format->plane_bpp[plane] / 8;
>  
> -	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> -		return (width + 1) / 2 * cpp;
> -
> -	return width * cpp;
> +	return planar_width(format, width, plane) * cpp;
>  }
>  
>  static unsigned planar_height(struct format_desc_struct *format,
> unsigned height, int plane)
> @@ -331,17 +336,25 @@ static int create_bo_for_fb(int fd, int width,
> int height,
>  			    struct format_desc_struct *format,
>  			    uint64_t tiling, unsigned size, unsigned
> stride,
>  			    unsigned *size_ret, unsigned
> *stride_ret,
> -			    bool *is_dumb)
> +			    uint32_t *offsets, bool *is_dumb)
>  {
>  	int bo;
>  
>  	igt_assert(format);
>  
> +	if (offsets)
> +		memset(offsets, 0, 4 * sizeof(*offsets));
> +
>  	if (tiling || size || stride || format->planes > 1) {
>  		unsigned calculated_size, calculated_stride;
>  
> -		igt_calc_fb_size(fd, width, height, format->drm_id,
> tiling,
> -				 &calculated_size,
> &calculated_stride);
> +		if (format->planes > 1)
> +			calc_fb_size_planar(fd, width, height,
> format, tiling,
> +					    &calculated_size,
> &calculated_stride, offsets);
> +		else
> +			calc_fb_size_packed(fd, width, height,
> format, tiling,
> +					    &calculated_size,
> &calculated_stride);
> +
>  		if (stride == 0)
>  			stride = calculated_stride;
>  		if (size == 0)
> @@ -407,7 +420,7 @@ int igt_create_bo_with_dimensions(int fd, int
> width, int height,
>  				  unsigned *stride_ret, bool
> *is_dumb)
>  {
>  	return create_bo_for_fb(fd, width, height,
> lookup_drm_format(format),
> -				modifier, 0, stride, size_ret,
> stride_ret, is_dumb);
> +				modifier, 0, stride, size_ret,
> stride_ret, NULL, is_dumb);
>  }
>  
>  /**
> @@ -748,16 +761,20 @@ igt_create_fb_with_bo_size(int fd, int width,
> int height,
>  			   struct igt_fb *fb, unsigned bo_size,
>  			   unsigned bo_stride)
>  {
> +	struct format_desc_struct *f = lookup_drm_format(format);
>  	uint32_t fb_id;
> +	int i;
> +
> +	igt_assert_f(f, "DRM format %08x not found\n", format);
>  
>  	memset(fb, 0, sizeof(*fb));
>  
>  	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,
> -					  lookup_drm_format(format),
> +	fb->gem_handle = create_bo_for_fb(fd, width, height, f,
>  					  tiling, bo_size,
> bo_stride,
> -					  &fb->size, &fb->stride,
> &fb->is_dumb);
> +					  &fb->size, &fb->stride,
> +					  fb->offsets, &fb-
> >is_dumb);
>  	igt_assert(fb->gem_handle > 0);
>  
>  	igt_debug("%s(handle=%d, pitch=%d)\n",
> @@ -766,22 +783,24 @@ igt_create_fb_with_bo_size(int fd, int width,
> int height,
>  	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
>  	    tiling != LOCAL_I915_FORMAT_MOD_X_TILED) {
>  		do_or_die(__kms_addfb(fd, fb->gem_handle, width,
> height,
> -				      fb->stride, format, tiling,
> +				      fb->stride, format, tiling,
> fb->offsets,
>  				      LOCAL_DRM_MODE_FB_MODIFIERS,
> &fb_id));
>  	} else {
>  		uint32_t handles[4];
>  		uint32_t pitches[4];
> -		uint32_t offsets[4];
>  
>  		memset(handles, 0, sizeof(handles));
>  		memset(pitches, 0, sizeof(pitches));
> -		memset(offsets, 0, sizeof(offsets));
>  
>  		handles[0] = fb->gem_handle;
>  		pitches[0] = fb->stride;
> +		for (i = 0; i < f->planes; i++) {
> +			handles[i] = fb->gem_handle;
> +			pitches[i] = fb->stride;
> +		}
>  
>  		do_or_die(drmModeAddFB2(fd, width, height, format,
> -					handles, pitches, offsets,
> +					handles, pitches, fb-
> >offsets,
>  					&fb_id, 0));
>  	}
>  
> @@ -791,6 +810,17 @@ 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;
> +
> +	/* if f->planes is set, then plane_bpp is valid too so use
> that. */
> +	for (i = 0; i < f->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);
> +	}
>  
>  	return fb_id;
>  }
> @@ -1127,7 +1157,8 @@ static void destroy_cairo_surface__blit(void
> *arg)
>  				   0, 0, /* src_x, src_y */
>  				   fb->width, fb->height,
>  				   igt_drm_format_to_bpp(fb-
> >drm_format),
> -				   fb->gem_handle, 0,
> +				   fb->gem_handle,
> +				   fb->offsets[0],
>  				   fb->stride,
>  				   obj_tiling,
>  				   0, 0 /* dst_x, dst_y */);
> @@ -1143,6 +1174,7 @@ static void create_cairo_surface__blit(int fd,
> struct igt_fb *fb)
>  	struct fb_blit_upload *blit;
>  	cairo_format_t cairo_format;
>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> +	uint32_t offsets[4];
>  
>  	blit = malloc(sizeof(*blit));
>  	igt_assert(blit);
> @@ -1157,7 +1189,7 @@ static void create_cairo_surface__blit(int fd,
> struct igt_fb *fb)
>  					       LOCAL_DRM_FORMAT_MOD_
> NONE, 0,
>  					       0, &blit-
> >linear.size,
>  					       &blit->linear.stride,
> -					       &blit-
> >linear.is_dumb);
> +					       offsets, &blit-
> >linear.is_dumb);
>  
>  	igt_assert(blit->linear.handle > 0);
>  
> @@ -1169,7 +1201,8 @@ static void create_cairo_surface__blit(int fd,
> struct igt_fb *fb)
>  			I915_GEM_DOMAIN_GTT, 0);
>  
>  	igt_blitter_fast_copy__raw(fd,
> -				   fb->gem_handle, 0,
> +				   fb->gem_handle,
> +				   fb->offsets[0],
>  				   fb->stride,
>  				   obj_tiling,
>  				   0, 0, /* src_x, src_y */
> @@ -1257,14 +1290,17 @@ static void create_cairo_surface__gtt(int fd,
> struct igt_fb *fb)
>   * @fd: open drm file descriptor
>   * @fb: pointer to an #igt_fb structure
>   *
> - * This function stores the contents of the supplied framebuffer
> into a cairo
> - * surface and returns it.
> + * This function stores the contents of the supplied framebuffer's
> plane
> + * into a cairo surface and returns it.
>   *
>   * Returns:
>   * A pointer to a cairo surface with the contents of the
> framebuffer.
>   */
>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>  {
> +	/* This doesn't work for planar formats for now, but we will
> convert them to RGB24 in the future. */
> +	igt_assert(fb->num_planes < 2);
> +
>  	if (fb->cairo_surface == NULL) {
>  		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
>  		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index 152798e9896b..77fd88bb7aca 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -50,6 +50,11 @@
>   * @size: size in bytes of the underlying backing storage
>   * @cairo_surface: optionally attached cairo drawing surface
>   * @domain: current domain for cache flushing tracking on i915.ko
> + * @num_planes: Amount of planes on this fb. >1 for planar formats.
> + * @offsets: Offset for each plane in bytes.
> + * @plane_bpp: The bpp for each plane.
> + * @plane_width: The width for each plane.
> + * @plane_height: The height for each plane.
>   *
>   * Tracking structure for KMS framebuffer objects.
>   */
> @@ -66,6 +71,11 @@ typedef struct igt_fb {
>  	unsigned int size;
>  	cairo_surface_t *cairo_surface;
>  	unsigned int domain;
> +	unsigned int num_planes;
> +	uint32_t offsets[4];
> +	unsigned int plane_bpp[4];
> +	unsigned int plane_width[4];
> +	unsigned int plane_height[4];
>  } igt_fb_t;
>  
>  /**
> diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
> index 39e8469e3985..10d958726da7 100644
> --- a/lib/ioctl_wrappers.c
> +++ b/lib/ioctl_wrappers.c
> @@ -1659,10 +1659,10 @@ void igt_require_fb_modifiers(int fd)
>  
>  int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t
> height,
>  		uint32_t stride, uint32_t pixel_format, uint64_t
> modifier,
> -		uint32_t flags, uint32_t *buf_id)
> +		uint32_t *offsets, uint32_t flags, uint32_t *buf_id)
>  {
>  	struct drm_mode_fb_cmd2 f;
> -	int ret;
> +	int ret, i;
>  
>  	igt_require_fb_modifiers(fd);
>  
> @@ -1676,6 +1676,13 @@ int __kms_addfb(int fd, uint32_t handle,
> uint32_t width, uint32_t height,
>  	f.pitches[0] = stride;
>  	f.modifier[0] = modifier;
>  
> +	for (i = 1; i < 4 && offsets && offsets[i]; i++) {
> +		f.handles[i] = handle;
> +		f.pitches[i] = stride;
> +		f.modifier[i] = modifier;
> +		f.offsets[i] = offsets[i];
> +	}
> +
>  	ret = igt_ioctl(fd, DRM_IOCTL_MODE_ADDFB2, &f);
>  
>  	*buf_id = f.fb_id;
> diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
> index f7752aeab2c4..13fbe3c103c0 100644
> --- a/lib/ioctl_wrappers.h
> +++ b/lib/ioctl_wrappers.h
> @@ -236,7 +236,7 @@ void igt_require_fb_modifiers(int fd);
>   */
>  int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t
> height,
>  		uint32_t stride, uint32_t pixel_format, uint64_t
> modifier,
> -		uint32_t flags, uint32_t *buf_id);
> +		uint32_t *offsets, uint32_t flags, uint32_t
> *buf_id);
>  
>  /**
>   * to_user_pointer:
> diff --git a/tests/kms_draw_crc.c b/tests/kms_draw_crc.c
> index 723e7a182c95..86dcf39285f3 100644
> --- a/tests/kms_draw_crc.c
> +++ b/tests/kms_draw_crc.c
> @@ -163,7 +163,7 @@ static bool format_is_supported(uint32_t format,
> uint64_t modifier)
>  						   format, modifier,
>  						   0, NULL, &stride,
> NULL);
>  	ret =  __kms_addfb(drm_fd, gem_handle, 64, 64,
> -			   stride, format, modifier,
> +			   stride, format, modifier, NULL,
>  			   LOCAL_DRM_MODE_FB_MODIFIERS, &fb_id);
>  	drmModeRmFB(drm_fd, fb_id);
>  	gem_close(drm_fd, gem_handle);
> diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
> index 5b190a0d03cb..f65562bae9eb 100644
> --- a/tests/kms_rotation_crc.c
> +++ b/tests/kms_rotation_crc.c
> @@ -520,7 +520,7 @@ static void test_plane_rotation_ytiled_obj(data_t
> *data,
>  	igt_assert_eq(ret, 0);
>  
>  	do_or_die(__kms_addfb(fd, gem_handle, w, h, stride,
> -		  format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
> +		  format, tiling, NULL, LOCAL_DRM_MODE_FB_MODIFIERS,
>  		  &data->fb.fb_id));
>  	data->fb.width = w;
>  	data->fb.height = h;
> @@ -601,7 +601,8 @@ static void
> test_plane_rotation_exhaust_fences(data_t *data,
>  		}
>  
>  		ret = (__kms_addfb(fd, gem_handle, w, h, stride,
> -		       format, tiling, LOCAL_DRM_MODE_FB_MODIFIERS,
> +		       format, tiling, NULL,
> +		       LOCAL_DRM_MODE_FB_MODIFIERS,
>  		       &data2[i].fb.fb_id));
>  		if (ret) {
>  			igt_warn("failed to create framebuffer\n");
> diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
> index a5f75d888bef..763c62e606f6 100644
> --- a/tests/prime_vgem.c
> +++ b/tests/prime_vgem.c
> @@ -723,7 +723,7 @@ static void test_flip(int i915, int vgem,
> unsigned hang)
>  
>  		do_or_die(__kms_addfb(i915, handle[i],
>  				      bo[i].width, bo[i].height,
> bo[i].pitch,
> -				      DRM_FORMAT_XRGB8888,
> I915_TILING_NONE,
> +				      DRM_FORMAT_XRGB8888,
> I915_TILING_NONE, NULL,
>  				      LOCAL_DRM_MODE_FB_MODIFIERS,
> &fb_id[i]));
>  		igt_assert(fb_id[i]);
>  	}
-- 
Mika Kahola - Intel OTC

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

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

* [igt-dev] [PATCH i-g-t] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw, v2.
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw Maarten Lankhorst
  2018-01-26  9:02   ` Mika Kahola
@ 2018-01-29 12:10   ` Maarten Lankhorst
  1 sibling, 0 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-29 12:10 UTC (permalink / raw)
  To: igt-dev

Adding a delta offset will allow us to copy planar framebuffers with this
function.

Changes since v1:
- Set src and destination addresses to the delta, in case BO is mapped at offset 0.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Mika Kahola <mika.kahola@intel.com> #v1
---
 lib/igt_fb.c            |  8 ++++----
 lib/intel_batchbuffer.c | 19 ++++++++++++-------
 lib/intel_batchbuffer.h |  2 ++
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6a331f06724b..1251f462d24e 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1121,13 +1121,13 @@ static void destroy_cairo_surface__blit(void *arg)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(blit->fd,
-				   blit->linear.handle,
+				   blit->linear.handle, 0,
 				   blit->linear.stride,
 				   I915_TILING_NONE,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle,
+				   fb->gem_handle, 0,
 				   fb->stride,
 				   obj_tiling,
 				   0, 0 /* dst_x, dst_y */);
@@ -1169,13 +1169,13 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
 			I915_GEM_DOMAIN_GTT, 0);
 
 	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle,
+				   fb->gem_handle, 0,
 				   fb->stride,
 				   obj_tiling,
 				   0, 0, /* src_x, src_y */
 				   fb->width, fb->height,
 				   igt_drm_format_to_bpp(fb->drm_format),
-				   blit->linear.handle,
+				   blit->linear.handle, 0,
 				   blit->linear.stride,
 				   I915_TILING_NONE,
 				   0, 0 /* dst_x, dst_y */);
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 9a53b6f8e706..127d847088e8 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -554,11 +554,12 @@ static uint32_t fast_copy_dword1(unsigned int src_tiling,
 
 static void
 fill_relocation(struct drm_i915_gem_relocation_entry *reloc,
-		uint32_t gem_handle, uint32_t offset, /* in dwords */
+		uint32_t gem_handle, uint32_t delta, /* in bytes */
+		uint32_t offset, /* in dwords */
 		uint32_t read_domains, uint32_t write_domains)
 {
 	reloc->target_handle = gem_handle;
-	reloc->delta = 0;
+	reloc->delta = delta;
 	reloc->offset = offset * sizeof(uint32_t);
 	reloc->presumed_offset = 0;
 	reloc->read_domains = read_domains;
@@ -599,6 +600,7 @@ static void exec_blit(int fd,
  * igt_blitter_fast_copy__raw:
  * @fd: file descriptor of the i915 driver
  * @src_handle: GEM handle of the source buffer
+ * @src_delta: offset into the source GEM bo, in bytes
  * @src_stride: Stride (in bytes) of the source buffer
  * @src_tiling: Tiling mode of the source buffer
  * @src_x: X coordinate of the source region to copy
@@ -606,7 +608,8 @@ static void exec_blit(int fd,
  * @width: Width of the region to copy
  * @height: Height of the region to copy
  * @bpp: source and destination bits per pixel
- * @dst_handle: GEM handle of the source buffer
+ * @dst_handle: GEM handle of the destination buffer
+ * @dst_delta: offset into the destination GEM bo, in bytes
  * @dst_stride: Stride (in bytes) of the destination buffer
  * @dst_tiling: Tiling mode of the destination buffer
  * @dst_x: X coordinate of destination
@@ -617,6 +620,7 @@ static void exec_blit(int fd,
 void igt_blitter_fast_copy__raw(int fd,
 				/* src */
 				uint32_t src_handle,
+				unsigned int src_delta,
 				unsigned int src_stride,
 				unsigned int src_tiling,
 				unsigned int src_x, unsigned src_y,
@@ -629,6 +633,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* dst */
 				uint32_t dst_handle,
+				unsigned dst_delta,
 				unsigned int dst_stride,
 				unsigned int dst_tiling,
 				unsigned int dst_x, unsigned dst_y)
@@ -659,11 +664,11 @@ void igt_blitter_fast_copy__raw(int fd,
 	batch[i++] = dword1 | dst_pitch;
 	batch[i++] = (dst_y << 16) | dst_x; /* dst x1,y1 */
 	batch[i++] = ((dst_y + height) << 16) | (dst_x + width); /* dst x2,y2 */
-	batch[i++] = 0; /* dst address lower bits */
+	batch[i++] = dst_delta; /* dst address lower bits */
 	batch[i++] = 0;	/* dst address upper bits */
 	batch[i++] = (src_y << 16) | src_x; /* src x1,y1 */
 	batch[i++] = src_pitch;
-	batch[i++] = 0; /* src address lower bits */
+	batch[i++] = src_delta; /* src address lower bits */
 	batch[i++] = 0;	/* src address upper bits */
 	batch[i++] = MI_BATCH_BUFFER_END;
 	batch[i++] = MI_NOOP;
@@ -673,9 +678,9 @@ void igt_blitter_fast_copy__raw(int fd,
 	batch_handle = gem_create(fd, 4096);
 	gem_write(fd, batch_handle, 0, batch, sizeof(batch));
 
-	fill_relocation(&relocs[0], dst_handle, 4,
+	fill_relocation(&relocs[0], dst_handle, dst_delta, 4,
 			I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-	fill_relocation(&relocs[1], src_handle, 8, I915_GEM_DOMAIN_RENDER, 0);
+	fill_relocation(&relocs[1], src_handle, src_delta, 8, I915_GEM_DOMAIN_RENDER, 0);
 
 	fill_object(&objs[0], dst_handle, NULL, 0);
 	fill_object(&objs[1], src_handle, NULL, 0);
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 6bee41676627..a6d8f9863698 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -234,6 +234,7 @@ void igt_blitter_fast_copy(struct intel_batchbuffer *batch,
 void igt_blitter_fast_copy__raw(int fd,
 				/* src */
 				uint32_t src_handle,
+				unsigned int src_delta,
 				unsigned int src_stride,
 				unsigned int src_tiling,
 				unsigned int src_x, unsigned src_y,
@@ -246,6 +247,7 @@ void igt_blitter_fast_copy__raw(int fd,
 
 				/* dst */
 				uint32_t dst_handle,
+				unsigned int dst_delta,
 				unsigned int dst_stride,
 				unsigned int dst_tiling,
 				unsigned int dst_x, unsigned dst_y);
-- 
2.15.1

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

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

* [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev4)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (13 preceding siblings ...)
  2018-01-24 15:57 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
@ 2018-01-29 12:37 ` Patchwork
  2018-01-29 17:29 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-29 12:37 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev4)
URL   : https://patchwork.freedesktop.org/series/36965/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
2649a091a0a67e6d4106024fb6d74cf7119f350f lib: Refactor igt_wait() to use library timers

with latest DRM-Tip kernel build CI_DRM_3689
2bbded26cfa2 drm-tip: 2018y-01m-29d-10h-43m-15s UTC integration manifest

No testlist changes.

Test debugfs_test:
        Subgroup read_all_entries:
                pass       -> INCOMPLETE (fi-snb-2520m) fdo#103713

fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:430s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:376s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:493s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:282s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:485s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:498s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:480s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:460s
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:574s
fi-elk-e7500     total:224  pass:168  dwarn:9   dfail:1   fail:0   skip:45 
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:282s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:515s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:396s
fi-hsw-4770r     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:400s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:414s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:451s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:423s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:460s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:499s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:452s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:503s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:583s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:437s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:512s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:529s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:491s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:494s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:419s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:435s
fi-snb-2520m     total:3    pass:2    dwarn:0   dfail:0   fail:0   skip:0  
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:407s
Blacklisted hosts:
fi-cnl-y2        total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:531s
fi-glk-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:472s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-25 11:43       ` Mika Kahola
@ 2018-01-29 17:01         ` Maarten Lankhorst
  0 siblings, 0 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-29 17:01 UTC (permalink / raw)
  To: mika.kahola, Ville Syrjälä; +Cc: igt-dev

Op 25-01-18 om 12:43 schreef Mika Kahola:
> On Wed, 2018-01-24 at 13:26 +0100, Maarten Lankhorst wrote:
>> Hey,
>>
>> Op 23-01-18 om 16:50 schreef Ville Syrjälä:
>>> On Tue, Jan 23, 2018 at 01:56:35PM +0100, Maarten Lankhorst wrote:
>>>> This will allow support for NV12 in the future, where
>>>> igt_get_cairo_ctx
>>>> will return a RGB image to draw with, which will be converted in
>>>> igt_put_cairo_ctx so tests don't have to add special support for
>>>> NV12.
>>> Why do we need a special funciton? As in, can't you just do it the
>>> same as we handle the gtt vs. blit stuff?
>>>
>> The cairo_destroy() call will do the actual conversion back, but with
>> this helper we can
>> actually check that every call to get() is followed by a put() and
>> errors are consistently
>> checked. Not all callers have both, so I felt it better to put it in
>> the core..
> From the naming convention point of view, I would use set() instead of
> put() as we have a get() as counterpart.
Lot of places using get() to acquire a ref, put() to release it. So I think it makes sense..

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

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

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev4)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (14 preceding siblings ...)
  2018-01-29 12:37 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev4) Patchwork
@ 2018-01-29 17:29 ` Patchwork
  2018-01-31 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev5) Patchwork
  2018-01-31 18:55 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-29 17:29 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev4)
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

Test syncobj_wait:
        Subgroup wait-any-snapshot:
                fail       -> PASS       (shard-apl)
Test kms_flip:
        Subgroup flip-vs-modeset-vs-hang:
                pass       -> DMESG-WARN (shard-snb) fdo#103821
Test gem_eio:
        Subgroup in-flight:
                dmesg-warn -> PASS       (shard-snb) fdo#104058
Test kms_render:
        Subgroup gpu-blit:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup direct-render:
                pass       -> FAIL       (shard-snb) fdo#104312
                pass       -> FAIL       (shard-hsw) fdo#102614
                pass       -> FAIL       (shard-apl)
Test kms_plane:
        Subgroup plane-panning-bottom-right-suspend-pipe-a-planes:
                skip       -> PASS       (shard-snb) fdo#102365
Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-primscrn-pri-shrfb-draw-blt:
                dmesg-fail -> PASS       (shard-apl) fdo#101623 +2
Test perf_pmu:
        Subgroup frequency:
                fail       -> PASS       (shard-apl) fdo#104829
Test kms_plane_multiple:
        Subgroup atomic-pipe-b-tiling-none:
                pass       -> FAIL       (shard-apl) fdo#103166
Test gem_tiled_swapping:
        Subgroup non-threaded:
                pass       -> SKIP       (shard-apl)

fdo#103821 https://bugs.freedesktop.org/show_bug.cgi?id=103821
fdo#104058 https://bugs.freedesktop.org/show_bug.cgi?id=104058
fdo#104312 https://bugs.freedesktop.org/show_bug.cgi?id=104312
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#102365 https://bugs.freedesktop.org/show_bug.cgi?id=102365
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#104829 https://bugs.freedesktop.org/show_bug.cgi?id=104829
fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166

shard-apl        total:2838 pass:1749 dwarn:1   dfail:0   fail:23  skip:1065 time:12698s
shard-hsw        total:2838 pass:1734 dwarn:1   dfail:0   fail:12  skip:1090 time:11881s
shard-snb        total:2838 pass:1327 dwarn:2   dfail:0   fail:12  skip:1497 time:6567s
Blacklisted hosts:
shard-kbl        total:2838 pass:1847 dwarn:22  dfail:2   fail:24  skip:943 time:9529s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion Maarten Lankhorst
@ 2018-01-31 13:45   ` Mika Kahola
  2018-01-31 14:32     ` Ville Syrjälä
  0 siblings, 1 reply; 47+ messages in thread
From: Mika Kahola @ 2018-01-31 13:45 UTC (permalink / raw)
  To: Maarten Lankhorst, igt-dev

On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> For NV12 a format conversion is needed. Because YUV formats are not
> fully defined with just a fourcc, I've chosen BT.709 limited range.
> This puts the pixel center of the CbCr components between the top
> left Y and bottom left Y:
> 
> Y   Y   Y   Y
> UV      UV
> Y   Y   Y   Y
> 
> Some work is put into optimising the conversion routines in order to
> make it fast enough. Before converting nv12 to rgb24, it is copied to
> a temporary buffer to take advantage of memory caching. This is
> approximately 20x faster than directly reading the BO.
> 
> When testing on my KBL with a 1080p buffer, it takes approximately
> .1s to convert either way, this is fast enough not to bother
> optimising
> even further for me.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++-
> ----------
>  1 file changed, 318 insertions(+), 72 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 4d6b62a64ded..43b71e643586 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -70,6 +70,7 @@ static struct format_desc_struct {
>  	DF(XRGB8888,	RGB24,		32, 24),
>  	DF(XRGB2101010,	RGB30,		32, 30),
>  	DF(ARGB8888,	ARGB32,		32, 32),
> +	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
>  };
>  #undef DF
>  
> @@ -363,14 +364,20 @@ static int create_bo_for_fb(int fd, int width,
> int height,
>  			*is_dumb = false;
>  
>  		if (is_i915_device(fd)) {
> -			uint32_t *ptr;
> +			uint8_t *ptr;
>  
>  			bo = gem_create(fd, size);
>  			gem_set_tiling(fd, bo,
> igt_fb_mod_to_tiling(tiling), stride);
>  
>  			/* Ensure the framebuffer is preallocated */
> -			ptr = gem_mmap__gtt(fd, bo, size,
> PROT_READ);
> -			igt_assert(*ptr == 0);
> +			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);
> +			}
>  			gem_munmap(ptr, size);
>  
>  			if (size_ret)
> @@ -1126,103 +1133,117 @@ static cairo_format_t
> drm_format_to_cairo(uint32_t drm_format)
>  		     drm_format, igt_format_str(drm_format));
>  }
>  
> +struct fb_blit_linear {
> +	uint32_t handle;
> +	unsigned size, stride;
> +	uint8_t *map;
> +	bool is_dumb;
> +	uint32_t offsets[4];
> +};
> +
>  struct fb_blit_upload {
>  	int fd;
>  	struct igt_fb *fb;
> -	struct {
> -		uint32_t handle;
> -		unsigned size, stride;
> -		uint8_t *map;
> -		bool is_dumb;
> -	} linear;
> +	struct fb_blit_linear linear;
>  };
>  
> -static void destroy_cairo_surface__blit(void *arg)
> +static void free_linear_mapping(int fd, struct igt_fb *fb, struct
> fb_blit_linear *linear)
>  {
> -	struct fb_blit_upload *blit = arg;
> -	struct igt_fb *fb = blit->fb;
>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> +	int i;
>  
> -	gem_munmap(blit->linear.map, blit->linear.size);
> -	fb->cairo_surface = NULL;
> +	gem_munmap(linear->map, linear->size);
> +	gem_set_domain(fd, linear->handle,
> +		       I915_GEM_DOMAIN_GTT, 0);
> +
> +	for (i = 0; i < fb->num_planes; i++)
> +		igt_blitter_fast_copy__raw(fd,
> +					   linear->handle,
> +					   linear->offsets[i],
> +					   linear->stride,
> +					   I915_TILING_NONE,
> +					   0, 0, /* src_x, src_y */
> +					   fb->plane_width[i], fb-
> >plane_height[i],
> +					   fb->plane_bpp[i],
> +					   fb->gem_handle,
> +					   fb->offsets[i],
> +					   fb->stride,
> +					   obj_tiling,
> +					   0, 0 /* dst_x, dst_y */);
> +
> +	gem_sync(fd, linear->handle);
> +	gem_close(fd, linear->handle);
> +}
>  
> -	gem_set_domain(blit->fd, blit->linear.handle,
> -			I915_GEM_DOMAIN_GTT, 0);
> +static void destroy_cairo_surface__blit(void *arg)
> +{
> +	struct fb_blit_upload *blit = arg;
>  
> -	igt_blitter_fast_copy__raw(blit->fd,
> -				   blit->linear.handle, 0,
> -				   blit->linear.stride,
> -				   I915_TILING_NONE,
> -				   0, 0, /* src_x, src_y */
> -				   fb->width, fb->height,
> -				   igt_drm_format_to_bpp(fb-
> >drm_format),
> -				   fb->gem_handle,
> -				   fb->offsets[0],
> -				   fb->stride,
> -				   obj_tiling,
> -				   0, 0 /* dst_x, dst_y */);
> -
> -	gem_sync(blit->fd, blit->linear.handle);
> -	gem_close(blit->fd, blit->linear.handle);
> +	blit->fb->cairo_surface = NULL;
> +
> +	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
>  
>  	free(blit);
>  }
>  
> -static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> +static void setup_linear_mapping(int fd, struct igt_fb *fb, struct
> fb_blit_linear *linear)
>  {
> -	struct fb_blit_upload *blit;
> -	cairo_format_t cairo_format;
>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> -	uint32_t offsets[4];
> -
> -	blit = malloc(sizeof(*blit));
> -	igt_assert(blit);
> +	int i;
>  
>  	/*
>  	 * We create a linear BO that we'll map for the CPU to write
> to (using
>  	 * cairo). This linear bo will be then blitted to its final
>  	 * destination, tiling it at the same time.
>  	 */
> -	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb-
> >height,
> +	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
>  					       lookup_drm_format(fb-
> >drm_format),
>  					       LOCAL_DRM_FORMAT_MOD_
> NONE, 0,
> -					       0, &blit-
> >linear.size,
> -					       &blit->linear.stride,
> -					       offsets, &blit-
> >linear.is_dumb);
> -
> -	igt_assert(blit->linear.handle > 0);
> +					       0, &linear->size,
> +					       &linear->stride,
> +					       linear->offsets,
> &linear->is_dumb);
>  
> -	blit->fd = fd;
> -	blit->fb = fb;
> +	igt_assert(linear->handle > 0);
>  
>  	/* Copy fb content to linear BO */
> -	gem_set_domain(fd, blit->linear.handle,
> +	gem_set_domain(fd, linear->handle,
>  			I915_GEM_DOMAIN_GTT, 0);
>  
> -	igt_blitter_fast_copy__raw(fd,
> -				   fb->gem_handle,
> -				   fb->offsets[0],
> -				   fb->stride,
> -				   obj_tiling,
> -				   0, 0, /* src_x, src_y */
> -				   fb->width, fb->height,
> -				   igt_drm_format_to_bpp(fb-
> >drm_format),
> -				   blit->linear.handle, 0,
> -				   blit->linear.stride,
> -				   I915_TILING_NONE,
> -				   0, 0 /* dst_x, dst_y */);
> -
> -	gem_sync(fd, blit->linear.handle);
> -
> -	gem_set_domain(fd, blit->linear.handle,
> +	for (i = 0; i < fb->num_planes; i++)
> +		igt_blitter_fast_copy__raw(fd,
> +					  fb->gem_handle,
> +					  fb->offsets[i],
> +					  fb->stride,
> +					  obj_tiling,
> +					  0, 0, /* src_x, src_y */
> +					  fb->plane_width[i], fb-
> >plane_height[i],
> +					  fb->plane_bpp[i],
> +					  linear->handle, linear-
> >offsets[i],
> +					  linear->stride,
> +					  I915_TILING_NONE,
> +					  0, 0 /* dst_x, dst_y */);
> +
> +	gem_sync(fd, linear->handle);
> +
> +	gem_set_domain(fd, linear->handle,
>  		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
>  
>  	/* Setup cairo context */
> -	blit->linear.map = gem_mmap__cpu(fd,
> -					 blit->linear.handle,
> -					 0,
> -					 blit->linear.size,
> -					 PROT_READ | PROT_WRITE);
> +	linear->map = gem_mmap__cpu(fd, linear->handle,
> +				    0, linear->size, PROT_READ |
> PROT_WRITE);
> +}
> +
> +static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> +{
> +	struct fb_blit_upload *blit;
> +	cairo_format_t cairo_format;
> +
> +	blit = malloc(sizeof(*blit));
> +	igt_assert(blit);
> +
> +	blit->fd = fd;
> +	blit->fb = fb;
> +	setup_linear_mapping(fd, fb, &blit->linear);
>  
>  	cairo_format = drm_format_to_cairo(fb->drm_format);
>  	fb->cairo_surface =
> @@ -1284,6 +1305,232 @@ static void create_cairo_surface__gtt(int fd,
> struct igt_fb *fb)
>  				    fb, destroy_cairo_surface__gtt);
>  }
>  
> +struct fb_convert_blit_upload {
> +	int fd;
> +	struct igt_fb *fb;
> +
> +	struct {
> +		uint8_t *map;
> +		unsigned stride, size;
> +	} rgb24;
> +
> +	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;
I'm thinking of this rounding issue. Should we use rounding to the
nearest integer here, instead of floor? Does the way we do rounding
have an effect on test results if we first grab the reference CRC and
then run a test in NV12 format?

> +}
> +
> +static void convert_nv12_to_rgb24(struct igt_fb *fb, struct
> fb_convert_blit_upload *blit)
> +{
> +	int i, j;
> +	const uint8_t *y, *uv;
> +	uint8_t *rgb24 = blit->rgb24.map;
> +	unsigned rgb24_stride = blit->rgb24.stride, planar_stride =
> blit->linear.stride;
> +	uint8_t *buf = malloc(blit->linear.size);
> +
> +	/*
> +	 * 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.
> +	 */
> +	memcpy(buf, blit->linear.map, blit->linear.size);
> +	y = &buf[blit->linear.offsets[0]];
> +	uv = &buf[blit->linear.offsets[1]];
> +
> +	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);
> +
> +			cb = uv[j & ~1] - 128.f;
> +			cr = uv[j | 1] - 128.f;
> +
> +			r_ = 0.000f * cb +  1.793f * cr;
> +			g_ = -0.213f * cb + -0.533f * cr;
> +			b_ = 2.112f * cb +  0.000f * cr;
> +
> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> +			rgb24[j * 4 + 2 + rgb24_stride] =
> clamprgb(y1 + r_);
> +
> +			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 += 2 * rgb24_stride;
> +		y += 2 * planar_stride;
> +		uv += planar_stride;
> +	}
> +
> +	if (fb->height & 1) {
> +		/* Convert last row */
> +		for (j = 0; j < fb->width; j++) {
> +			float r_, g_, b_, y0, cb, cr;
> +			/* Convert single pixel */
> +
> +			cb = uv[j & ~1] - 128.f;
> +			cr = uv[j | 1] - 128.f;
> +
> +			y0 = 1.164f * (y[j] - 16.f);
> +			r_ =  0.000f * cb +  1.793f * cr;
> +			g_ = -0.213f * cb + -0.533f * cr;
> +			b_ =  2.112f * cb +  0.000f * cr;
> +
Do you have a reference for these conversion coefficients? According
to https://www.fourcc.org/fccyvrgb.php there are a few opinions how
this conversion should be handled?

> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> +			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> +			rgb24[j * 4] = clamprgb(y0 + b_);
> +		}
> +	}
> +
> +	free(buf);
> +}
> +
> +static void convert_rgb24_to_nv12(struct igt_fb *fb, struct
> fb_convert_blit_upload *blit)
> +{
> +	int i, j;
> +	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
> +	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
> +	const uint8_t *rgb24 = blit->rgb24.map;
> +	unsigned rgb24_stride = blit->rgb24.stride;
> +	unsigned planar_stride = blit->linear.stride;
> +
> +	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.709 */
> +
> +		for (j = 0; j < fb->plane_width[0]; j++) {
> +			float yf = 0.183f * rgb24[j * 4 + 2] +
> +				   0.614f * rgb24[j * 4 + 1] +
> +				   0.062f * rgb24[j * 4] + 16;
> +
> +			y[j] = (uint8_t)yf;
We could use clamprgb() here too. Just in case.
> +		}
> +
> +		rgb24 += rgb24_stride;
> +		y += planar_stride;
> +	}
> +
> +	rgb24 = blit->rgb24.map;
> +
> +	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.101f/2 * rgb24[j * 8 + 2] +
> +				   -0.101f/2 * rgb24[j * 8 + 2 +
> rgb24_stride] +
> +				   -0.339f/2 * rgb24[j * 8 + 1] +
> +				   -0.339f/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.339f/2 * rgb24[j * 8 + 1] +
> +				   -0.339f/2 * rgb24[j * 8 + 1 +
> rgb24_stride] +
> +				   -0.040f/2 * rgb24[j * 8] +
> +				   -0.040f/2 * rgb24[j * 8 +
> rgb24_stride] + 128;
> +			uv[j * 2] = (uint8_t)uf;
> +			uv[j * 2 + 1] = (uint8_t)vf;
> 
Maybe add rounding & clamping here too?
> 
> +		}
> +
> +		rgb24 += 2 * rgb24_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.101f * rgb24[j * 8 + 2] +
> +				   -0.339f * rgb24[j * 8 + 1] +
> +				    0.439f * rgb24[j * 8] + 128;
> +			float vf =  0.439f * rgb24[j * 8 + 2] +
> +				   -0.339f * rgb24[j * 8 + 1] +
> +				   -0.040f * rgb24[j * 8] + 128;
> +
> +			uv[j * 2] = (uint8_t)uf;
> +			uv[j * 2 + 1] = (uint8_t)vf;
rounding & clamping?

> +		}
> +	}
> +}
> +
> +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);
> +
> +	munmap(blit->rgb24.map, blit->rgb24.size);
> +
> +	if (blit->linear.handle)
> +		free_linear_mapping(blit->fd, blit->fb, &blit-
> >linear);
> +	else
> +		gem_munmap(blit->linear.map, fb->size);
> +
> +	free(blit);
> +
> +	fb->cairo_surface = NULL;
> +}
> +
> +static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
> +{
> +	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
> +	igt_assert(blit);
> +
> +	blit->fd = fd;
> +	blit->fb = fb;
> +	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
> +	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height,
> sysconf(_SC_PAGESIZE));
> +	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ |
> PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	igt_assert(blit->rgb24.map != MAP_FAILED);
> +
> +	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> +	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
> +		setup_linear_mapping(fd, fb, &blit->linear);
> +	} else {
> +		blit->linear.handle = 0;
> +		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, 
> fb->size,
> +					      PROT_READ |
> PROT_WRITE);
> +		igt_assert(blit->linear.map);
> +		blit->linear.stride = fb->stride;
> +		blit->linear.size = fb->size;
> +		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);
> +
> +	fb->cairo_surface =
> +		cairo_image_surface_create_for_data(blit->rgb24.map,
> +						    CAIRO_FORMAT_RGB
> 24,
> +						    fb->width, fb-
> >height,
> +						    blit-
> >rgb24.stride);
> +
> +	cairo_surface_set_user_data(fb->cairo_surface,
> +				    (cairo_user_data_key_t
> *)create_cairo_surface__convert,
> +				    blit,
> destroy_cairo_surface__convert);
> +}
> +
>  /**
>   * igt_get_cairo_surface:
>   * @fd: open drm file descriptor
> @@ -1297,11 +1544,10 @@ static void create_cairo_surface__gtt(int fd,
> struct igt_fb *fb)
>   */
>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>  {
> -	/* This doesn't work for planar formats for now, but we will
> convert them to RGB24 in the future. */
> -	igt_assert(fb->num_planes < 2);
> -
>  	if (fb->cairo_surface == NULL) {
> -		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> +		if (fb->num_planes > 1)
> +			create_cairo_surface__convert(fd, fb);
> +		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED
> ||
>  		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
>  			create_cairo_surface__blit(fd, fb);
>  		else
-- 
Mika Kahola - Intel OTC

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

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

* Re: [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion
  2018-01-31 13:45   ` Mika Kahola
@ 2018-01-31 14:32     ` Ville Syrjälä
  2018-01-31 15:09       ` Maarten Lankhorst
  2018-01-31 16:52       ` [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2 Maarten Lankhorst
  0 siblings, 2 replies; 47+ messages in thread
From: Ville Syrjälä @ 2018-01-31 14:32 UTC (permalink / raw)
  To: Mika Kahola; +Cc: igt-dev

On Wed, Jan 31, 2018 at 03:45:37PM +0200, Mika Kahola wrote:
> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> > For NV12 a format conversion is needed. Because YUV formats are not
> > fully defined with just a fourcc, I've chosen BT.709 limited range.
> > This puts the pixel center of the CbCr components between the top
> > left Y and bottom left Y:
> > 
> > Y   Y   Y   Y
> > UV      UV
> > Y   Y   Y   Y
> > 
> > Some work is put into optimising the conversion routines in order to
> > make it fast enough. Before converting nv12 to rgb24, it is copied to
> > a temporary buffer to take advantage of memory caching. This is
> > approximately 20x faster than directly reading the BO.
> > 
> > When testing on my KBL with a 1080p buffer, it takes approximately
> > .1s to convert either way, this is fast enough not to bother
> > optimising
> > even further for me.
> > 
> > Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > ---
> >  lib/igt_fb.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++-
> > ----------
> >  1 file changed, 318 insertions(+), 72 deletions(-)
> > 
> > diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> > index 4d6b62a64ded..43b71e643586 100644
> > --- a/lib/igt_fb.c
> > +++ b/lib/igt_fb.c
> > @@ -70,6 +70,7 @@ static struct format_desc_struct {
> >  	DF(XRGB8888,	RGB24,		32, 24),
> >  	DF(XRGB2101010,	RGB30,		32, 30),
> >  	DF(ARGB8888,	ARGB32,		32, 32),
> > +	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
> >  };
> >  #undef DF
> >  
> > @@ -363,14 +364,20 @@ static int create_bo_for_fb(int fd, int width,
> > int height,
> >  			*is_dumb = false;
> >  
> >  		if (is_i915_device(fd)) {
> > -			uint32_t *ptr;
> > +			uint8_t *ptr;
> >  
> >  			bo = gem_create(fd, size);
> >  			gem_set_tiling(fd, bo,
> > igt_fb_mod_to_tiling(tiling), stride);
> >  
> >  			/* Ensure the framebuffer is preallocated */
> > -			ptr = gem_mmap__gtt(fd, bo, size,
> > PROT_READ);
> > -			igt_assert(*ptr == 0);
> > +			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);
> > +			}
> >  			gem_munmap(ptr, size);
> >  
> >  			if (size_ret)
> > @@ -1126,103 +1133,117 @@ static cairo_format_t
> > drm_format_to_cairo(uint32_t drm_format)
> >  		     drm_format, igt_format_str(drm_format));
> >  }
> >  
> > +struct fb_blit_linear {
> > +	uint32_t handle;
> > +	unsigned size, stride;
> > +	uint8_t *map;
> > +	bool is_dumb;
> > +	uint32_t offsets[4];
> > +};
> > +
> >  struct fb_blit_upload {
> >  	int fd;
> >  	struct igt_fb *fb;
> > -	struct {
> > -		uint32_t handle;
> > -		unsigned size, stride;
> > -		uint8_t *map;
> > -		bool is_dumb;
> > -	} linear;
> > +	struct fb_blit_linear linear;
> >  };
> >  
> > -static void destroy_cairo_surface__blit(void *arg)
> > +static void free_linear_mapping(int fd, struct igt_fb *fb, struct
> > fb_blit_linear *linear)
> >  {
> > -	struct fb_blit_upload *blit = arg;
> > -	struct igt_fb *fb = blit->fb;
> >  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> > +	int i;
> >  
> > -	gem_munmap(blit->linear.map, blit->linear.size);
> > -	fb->cairo_surface = NULL;
> > +	gem_munmap(linear->map, linear->size);
> > +	gem_set_domain(fd, linear->handle,
> > +		       I915_GEM_DOMAIN_GTT, 0);
> > +
> > +	for (i = 0; i < fb->num_planes; i++)
> > +		igt_blitter_fast_copy__raw(fd,
> > +					   linear->handle,
> > +					   linear->offsets[i],
> > +					   linear->stride,
> > +					   I915_TILING_NONE,
> > +					   0, 0, /* src_x, src_y */
> > +					   fb->plane_width[i], fb-
> > >plane_height[i],
> > +					   fb->plane_bpp[i],
> > +					   fb->gem_handle,
> > +					   fb->offsets[i],
> > +					   fb->stride,
> > +					   obj_tiling,
> > +					   0, 0 /* dst_x, dst_y */);
> > +
> > +	gem_sync(fd, linear->handle);
> > +	gem_close(fd, linear->handle);
> > +}
> >  
> > -	gem_set_domain(blit->fd, blit->linear.handle,
> > -			I915_GEM_DOMAIN_GTT, 0);
> > +static void destroy_cairo_surface__blit(void *arg)
> > +{
> > +	struct fb_blit_upload *blit = arg;
> >  
> > -	igt_blitter_fast_copy__raw(blit->fd,
> > -				   blit->linear.handle, 0,
> > -				   blit->linear.stride,
> > -				   I915_TILING_NONE,
> > -				   0, 0, /* src_x, src_y */
> > -				   fb->width, fb->height,
> > -				   igt_drm_format_to_bpp(fb-
> > >drm_format),
> > -				   fb->gem_handle,
> > -				   fb->offsets[0],
> > -				   fb->stride,
> > -				   obj_tiling,
> > -				   0, 0 /* dst_x, dst_y */);
> > -
> > -	gem_sync(blit->fd, blit->linear.handle);
> > -	gem_close(blit->fd, blit->linear.handle);
> > +	blit->fb->cairo_surface = NULL;
> > +
> > +	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
> >  
> >  	free(blit);
> >  }
> >  
> > -static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> > +static void setup_linear_mapping(int fd, struct igt_fb *fb, struct
> > fb_blit_linear *linear)
> >  {
> > -	struct fb_blit_upload *blit;
> > -	cairo_format_t cairo_format;
> >  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> > -	uint32_t offsets[4];
> > -
> > -	blit = malloc(sizeof(*blit));
> > -	igt_assert(blit);
> > +	int i;
> >  
> >  	/*
> >  	 * We create a linear BO that we'll map for the CPU to write
> > to (using
> >  	 * cairo). This linear bo will be then blitted to its final
> >  	 * destination, tiling it at the same time.
> >  	 */
> > -	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb-
> > >height,
> > +	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
> >  					       lookup_drm_format(fb-
> > >drm_format),
> >  					       LOCAL_DRM_FORMAT_MOD_
> > NONE, 0,
> > -					       0, &blit-
> > >linear.size,
> > -					       &blit->linear.stride,
> > -					       offsets, &blit-
> > >linear.is_dumb);
> > -
> > -	igt_assert(blit->linear.handle > 0);
> > +					       0, &linear->size,
> > +					       &linear->stride,
> > +					       linear->offsets,
> > &linear->is_dumb);
> >  
> > -	blit->fd = fd;
> > -	blit->fb = fb;
> > +	igt_assert(linear->handle > 0);
> >  
> >  	/* Copy fb content to linear BO */
> > -	gem_set_domain(fd, blit->linear.handle,
> > +	gem_set_domain(fd, linear->handle,
> >  			I915_GEM_DOMAIN_GTT, 0);
> >  
> > -	igt_blitter_fast_copy__raw(fd,
> > -				   fb->gem_handle,
> > -				   fb->offsets[0],
> > -				   fb->stride,
> > -				   obj_tiling,
> > -				   0, 0, /* src_x, src_y */
> > -				   fb->width, fb->height,
> > -				   igt_drm_format_to_bpp(fb-
> > >drm_format),
> > -				   blit->linear.handle, 0,
> > -				   blit->linear.stride,
> > -				   I915_TILING_NONE,
> > -				   0, 0 /* dst_x, dst_y */);
> > -
> > -	gem_sync(fd, blit->linear.handle);
> > -
> > -	gem_set_domain(fd, blit->linear.handle,
> > +	for (i = 0; i < fb->num_planes; i++)
> > +		igt_blitter_fast_copy__raw(fd,
> > +					  fb->gem_handle,
> > +					  fb->offsets[i],
> > +					  fb->stride,
> > +					  obj_tiling,
> > +					  0, 0, /* src_x, src_y */
> > +					  fb->plane_width[i], fb-
> > >plane_height[i],
> > +					  fb->plane_bpp[i],
> > +					  linear->handle, linear-
> > >offsets[i],
> > +					  linear->stride,
> > +					  I915_TILING_NONE,
> > +					  0, 0 /* dst_x, dst_y */);
> > +
> > +	gem_sync(fd, linear->handle);
> > +
> > +	gem_set_domain(fd, linear->handle,
> >  		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
> >  
> >  	/* Setup cairo context */
> > -	blit->linear.map = gem_mmap__cpu(fd,
> > -					 blit->linear.handle,
> > -					 0,
> > -					 blit->linear.size,
> > -					 PROT_READ | PROT_WRITE);
> > +	linear->map = gem_mmap__cpu(fd, linear->handle,
> > +				    0, linear->size, PROT_READ |
> > PROT_WRITE);
> > +}
> > +
> > +static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> > +{
> > +	struct fb_blit_upload *blit;
> > +	cairo_format_t cairo_format;
> > +
> > +	blit = malloc(sizeof(*blit));
> > +	igt_assert(blit);
> > +
> > +	blit->fd = fd;
> > +	blit->fb = fb;
> > +	setup_linear_mapping(fd, fb, &blit->linear);
> >  
> >  	cairo_format = drm_format_to_cairo(fb->drm_format);
> >  	fb->cairo_surface =
> > @@ -1284,6 +1305,232 @@ static void create_cairo_surface__gtt(int fd,
> > struct igt_fb *fb)
> >  				    fb, destroy_cairo_surface__gtt);
> >  }
> >  
> > +struct fb_convert_blit_upload {
> > +	int fd;
> > +	struct igt_fb *fb;
> > +
> > +	struct {
> > +		uint8_t *map;
> > +		unsigned stride, size;
> > +	} rgb24;
> > +
> > +	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;
> I'm thinking of this rounding issue. Should we use rounding to the
> nearest integer here, instead of floor? Does the way we do rounding
> have an effect on test results if we first grab the reference CRC and
> then run a test in NV12 format?
> 
> > +}
> > +
> > +static void convert_nv12_to_rgb24(struct igt_fb *fb, struct
> > fb_convert_blit_upload *blit)
> > +{
> > +	int i, j;
> > +	const uint8_t *y, *uv;
> > +	uint8_t *rgb24 = blit->rgb24.map;
> > +	unsigned rgb24_stride = blit->rgb24.stride, planar_stride =
> > blit->linear.stride;
> > +	uint8_t *buf = malloc(blit->linear.size);
> > +
> > +	/*
> > +	 * 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.
> > +	 */
> > +	memcpy(buf, blit->linear.map, blit->linear.size);
> > +	y = &buf[blit->linear.offsets[0]];
> > +	uv = &buf[blit->linear.offsets[1]];
> > +
> > +	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);
> > +
> > +			cb = uv[j & ~1] - 128.f;
> > +			cr = uv[j | 1] - 128.f;
> > +
> > +			r_ = 0.000f * cb +  1.793f * cr;
> > +			g_ = -0.213f * cb + -0.533f * cr;
> > +			b_ = 2.112f * cb +  0.000f * cr;
> > +
> > +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> > +			rgb24[j * 4 + 2 + rgb24_stride] =
> > clamprgb(y1 + r_);
> > +
> > +			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 += 2 * rgb24_stride;
> > +		y += 2 * planar_stride;
> > +		uv += planar_stride;
> > +	}
> > +
> > +	if (fb->height & 1) {
> > +		/* Convert last row */
> > +		for (j = 0; j < fb->width; j++) {
> > +			float r_, g_, b_, y0, cb, cr;
> > +			/* Convert single pixel */
> > +
> > +			cb = uv[j & ~1] - 128.f;
> > +			cr = uv[j | 1] - 128.f;
> > +
> > +			y0 = 1.164f * (y[j] - 16.f);
> > +			r_ =  0.000f * cb +  1.793f * cr;
> > +			g_ = -0.213f * cb + -0.533f * cr;
> > +			b_ =  2.112f * cb +  0.000f * cr;
> > +
> Do you have a reference for these conversion coefficients? According
> to https://www.fourcc.org/fccyvrgb.php there are a few opinions how
> this conversion should be handled?

We probably don't want to hardcode these in the code since we'll want to
test other encodings besides limited range BT.601. I think the cleanest
approach is to derive the coefficients from the Kr/Kb values, but that
might not lend itself well to tweaking the coefficients to match the
hardware output (if that's necessary).

> 
> > +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> > +			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> > +			rgb24[j * 4] = clamprgb(y0 + b_);
> > +		}
> > +	}
> > +
> > +	free(buf);
> > +}
> > +
> > +static void convert_rgb24_to_nv12(struct igt_fb *fb, struct
> > fb_convert_blit_upload *blit)
> > +{
> > +	int i, j;
> > +	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
> > +	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
> > +	const uint8_t *rgb24 = blit->rgb24.map;
> > +	unsigned rgb24_stride = blit->rgb24.stride;
> > +	unsigned planar_stride = blit->linear.stride;
> > +
> > +	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.709 */
> > +
> > +		for (j = 0; j < fb->plane_width[0]; j++) {
> > +			float yf = 0.183f * rgb24[j * 4 + 2] +
> > +				   0.614f * rgb24[j * 4 + 1] +
> > +				   0.062f * rgb24[j * 4] + 16;
> > +
> > +			y[j] = (uint8_t)yf;
> We could use clamprgb() here too. Just in case.
> > +		}
> > +
> > +		rgb24 += rgb24_stride;
> > +		y += planar_stride;
> > +	}
> > +
> > +	rgb24 = blit->rgb24.map;
> > +
> > +	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.101f/2 * rgb24[j * 8 + 2] +
> > +				   -0.101f/2 * rgb24[j * 8 + 2 +
> > rgb24_stride] +
> > +				   -0.339f/2 * rgb24[j * 8 + 1] +
> > +				   -0.339f/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.339f/2 * rgb24[j * 8 + 1] +
> > +				   -0.339f/2 * rgb24[j * 8 + 1 +
> > rgb24_stride] +
> > +				   -0.040f/2 * rgb24[j * 8] +
> > +				   -0.040f/2 * rgb24[j * 8 +
> > rgb24_stride] + 128;
> > +			uv[j * 2] = (uint8_t)uf;
> > +			uv[j * 2 + 1] = (uint8_t)vf;
> > 
> Maybe add rounding & clamping here too?
> > 
> > +		}
> > +
> > +		rgb24 += 2 * rgb24_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.101f * rgb24[j * 8 + 2] +
> > +				   -0.339f * rgb24[j * 8 + 1] +
> > +				    0.439f * rgb24[j * 8] + 128;
> > +			float vf =  0.439f * rgb24[j * 8 + 2] +
> > +				   -0.339f * rgb24[j * 8 + 1] +
> > +				   -0.040f * rgb24[j * 8] + 128;
> > +
> > +			uv[j * 2] = (uint8_t)uf;
> > +			uv[j * 2 + 1] = (uint8_t)vf;
> rounding & clamping?
> 
> > +		}
> > +	}
> > +}
> > +
> > +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);
> > +
> > +	munmap(blit->rgb24.map, blit->rgb24.size);
> > +
> > +	if (blit->linear.handle)
> > +		free_linear_mapping(blit->fd, blit->fb, &blit-
> > >linear);
> > +	else
> > +		gem_munmap(blit->linear.map, fb->size);
> > +
> > +	free(blit);
> > +
> > +	fb->cairo_surface = NULL;
> > +}
> > +
> > +static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
> > +{
> > +	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
> > +	igt_assert(blit);
> > +
> > +	blit->fd = fd;
> > +	blit->fb = fb;
> > +	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
> > +	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height,
> > sysconf(_SC_PAGESIZE));
> > +	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ |
> > PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> > +	igt_assert(blit->rgb24.map != MAP_FAILED);
> > +
> > +	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> > +	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
> > +		setup_linear_mapping(fd, fb, &blit->linear);
> > +	} else {
> > +		blit->linear.handle = 0;
> > +		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, 
> > fb->size,
> > +					      PROT_READ |
> > PROT_WRITE);
> > +		igt_assert(blit->linear.map);
> > +		blit->linear.stride = fb->stride;
> > +		blit->linear.size = fb->size;
> > +		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);
> > +
> > +	fb->cairo_surface =
> > +		cairo_image_surface_create_for_data(blit->rgb24.map,
> > +						    CAIRO_FORMAT_RGB
> > 24,
> > +						    fb->width, fb-
> > >height,
> > +						    blit-
> > >rgb24.stride);
> > +
> > +	cairo_surface_set_user_data(fb->cairo_surface,
> > +				    (cairo_user_data_key_t
> > *)create_cairo_surface__convert,
> > +				    blit,
> > destroy_cairo_surface__convert);
> > +}
> > +
> >  /**
> >   * igt_get_cairo_surface:
> >   * @fd: open drm file descriptor
> > @@ -1297,11 +1544,10 @@ static void create_cairo_surface__gtt(int fd,
> > struct igt_fb *fb)
> >   */
> >  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
> >  {
> > -	/* This doesn't work for planar formats for now, but we will
> > convert them to RGB24 in the future. */
> > -	igt_assert(fb->num_planes < 2);
> > -
> >  	if (fb->cairo_surface == NULL) {
> > -		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> > +		if (fb->num_planes > 1)
> > +			create_cairo_surface__convert(fd, fb);
> > +		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED
> > ||
> >  		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
> >  			create_cairo_surface__blit(fd, fb);
> >  		else
> -- 
> Mika Kahola - Intel OTC
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

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

* Re: [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion
  2018-01-31 14:32     ` Ville Syrjälä
@ 2018-01-31 15:09       ` Maarten Lankhorst
  2018-01-31 16:52       ` [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2 Maarten Lankhorst
  1 sibling, 0 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-31 15:09 UTC (permalink / raw)
  To: Ville Syrjälä, Mika Kahola; +Cc: igt-dev

Op 31-01-18 om 15:32 schreef Ville Syrjälä:
> On Wed, Jan 31, 2018 at 03:45:37PM +0200, Mika Kahola wrote:
>> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
>>> For NV12 a format conversion is needed. Because YUV formats are not
>>> fully defined with just a fourcc, I've chosen BT.709 limited range.
>>> This puts the pixel center of the CbCr components between the top
>>> left Y and bottom left Y:
>>>
>>> Y   Y   Y   Y
>>> UV      UV
>>> Y   Y   Y   Y
>>>
>>> Some work is put into optimising the conversion routines in order to
>>> make it fast enough. Before converting nv12 to rgb24, it is copied to
>>> a temporary buffer to take advantage of memory caching. This is
>>> approximately 20x faster than directly reading the BO.
>>>
>>> When testing on my KBL with a 1080p buffer, it takes approximately
>>> .1s to convert either way, this is fast enough not to bother
>>> optimising
>>> even further for me.
>>>
>>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>>> ---
>>>  lib/igt_fb.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++-
>>> ----------
>>>  1 file changed, 318 insertions(+), 72 deletions(-)
>>>
>>> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
>>> index 4d6b62a64ded..43b71e643586 100644
>>> --- a/lib/igt_fb.c
>>> +++ b/lib/igt_fb.c
>>> @@ -70,6 +70,7 @@ static struct format_desc_struct {
>>>  	DF(XRGB8888,	RGB24,		32, 24),
>>>  	DF(XRGB2101010,	RGB30,		32, 30),
>>>  	DF(ARGB8888,	ARGB32,		32, 32),
>>> +	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
>>>  };
>>>  #undef DF
>>>  
>>> @@ -363,14 +364,20 @@ static int create_bo_for_fb(int fd, int width,
>>> int height,
>>>  			*is_dumb = false;
>>>  
>>>  		if (is_i915_device(fd)) {
>>> -			uint32_t *ptr;
>>> +			uint8_t *ptr;
>>>  
>>>  			bo = gem_create(fd, size);
>>>  			gem_set_tiling(fd, bo,
>>> igt_fb_mod_to_tiling(tiling), stride);
>>>  
>>>  			/* Ensure the framebuffer is preallocated */
>>> -			ptr = gem_mmap__gtt(fd, bo, size,
>>> PROT_READ);
>>> -			igt_assert(*ptr == 0);
>>> +			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);
>>> +			}
>>>  			gem_munmap(ptr, size);
>>>  
>>>  			if (size_ret)
>>> @@ -1126,103 +1133,117 @@ static cairo_format_t
>>> drm_format_to_cairo(uint32_t drm_format)
>>>  		     drm_format, igt_format_str(drm_format));
>>>  }
>>>  
>>> +struct fb_blit_linear {
>>> +	uint32_t handle;
>>> +	unsigned size, stride;
>>> +	uint8_t *map;
>>> +	bool is_dumb;
>>> +	uint32_t offsets[4];
>>> +};
>>> +
>>>  struct fb_blit_upload {
>>>  	int fd;
>>>  	struct igt_fb *fb;
>>> -	struct {
>>> -		uint32_t handle;
>>> -		unsigned size, stride;
>>> -		uint8_t *map;
>>> -		bool is_dumb;
>>> -	} linear;
>>> +	struct fb_blit_linear linear;
>>>  };
>>>  
>>> -static void destroy_cairo_surface__blit(void *arg)
>>> +static void free_linear_mapping(int fd, struct igt_fb *fb, struct
>>> fb_blit_linear *linear)
>>>  {
>>> -	struct fb_blit_upload *blit = arg;
>>> -	struct igt_fb *fb = blit->fb;
>>>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
>>> +	int i;
>>>  
>>> -	gem_munmap(blit->linear.map, blit->linear.size);
>>> -	fb->cairo_surface = NULL;
>>> +	gem_munmap(linear->map, linear->size);
>>> +	gem_set_domain(fd, linear->handle,
>>> +		       I915_GEM_DOMAIN_GTT, 0);
>>> +
>>> +	for (i = 0; i < fb->num_planes; i++)
>>> +		igt_blitter_fast_copy__raw(fd,
>>> +					   linear->handle,
>>> +					   linear->offsets[i],
>>> +					   linear->stride,
>>> +					   I915_TILING_NONE,
>>> +					   0, 0, /* src_x, src_y */
>>> +					   fb->plane_width[i], fb-
>>>> plane_height[i],
>>> +					   fb->plane_bpp[i],
>>> +					   fb->gem_handle,
>>> +					   fb->offsets[i],
>>> +					   fb->stride,
>>> +					   obj_tiling,
>>> +					   0, 0 /* dst_x, dst_y */);
>>> +
>>> +	gem_sync(fd, linear->handle);
>>> +	gem_close(fd, linear->handle);
>>> +}
>>>  
>>> -	gem_set_domain(blit->fd, blit->linear.handle,
>>> -			I915_GEM_DOMAIN_GTT, 0);
>>> +static void destroy_cairo_surface__blit(void *arg)
>>> +{
>>> +	struct fb_blit_upload *blit = arg;
>>>  
>>> -	igt_blitter_fast_copy__raw(blit->fd,
>>> -				   blit->linear.handle, 0,
>>> -				   blit->linear.stride,
>>> -				   I915_TILING_NONE,
>>> -				   0, 0, /* src_x, src_y */
>>> -				   fb->width, fb->height,
>>> -				   igt_drm_format_to_bpp(fb-
>>>> drm_format),
>>> -				   fb->gem_handle,
>>> -				   fb->offsets[0],
>>> -				   fb->stride,
>>> -				   obj_tiling,
>>> -				   0, 0 /* dst_x, dst_y */);
>>> -
>>> -	gem_sync(blit->fd, blit->linear.handle);
>>> -	gem_close(blit->fd, blit->linear.handle);
>>> +	blit->fb->cairo_surface = NULL;
>>> +
>>> +	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
>>>  
>>>  	free(blit);
>>>  }
>>>  
>>> -static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
>>> +static void setup_linear_mapping(int fd, struct igt_fb *fb, struct
>>> fb_blit_linear *linear)
>>>  {
>>> -	struct fb_blit_upload *blit;
>>> -	cairo_format_t cairo_format;
>>>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
>>> -	uint32_t offsets[4];
>>> -
>>> -	blit = malloc(sizeof(*blit));
>>> -	igt_assert(blit);
>>> +	int i;
>>>  
>>>  	/*
>>>  	 * We create a linear BO that we'll map for the CPU to write
>>> to (using
>>>  	 * cairo). This linear bo will be then blitted to its final
>>>  	 * destination, tiling it at the same time.
>>>  	 */
>>> -	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb-
>>>> height,
>>> +	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
>>>  					       lookup_drm_format(fb-
>>>> drm_format),
>>>  					       LOCAL_DRM_FORMAT_MOD_
>>> NONE, 0,
>>> -					       0, &blit-
>>>> linear.size,
>>> -					       &blit->linear.stride,
>>> -					       offsets, &blit-
>>>> linear.is_dumb);
>>> -
>>> -	igt_assert(blit->linear.handle > 0);
>>> +					       0, &linear->size,
>>> +					       &linear->stride,
>>> +					       linear->offsets,
>>> &linear->is_dumb);
>>>  
>>> -	blit->fd = fd;
>>> -	blit->fb = fb;
>>> +	igt_assert(linear->handle > 0);
>>>  
>>>  	/* Copy fb content to linear BO */
>>> -	gem_set_domain(fd, blit->linear.handle,
>>> +	gem_set_domain(fd, linear->handle,
>>>  			I915_GEM_DOMAIN_GTT, 0);
>>>  
>>> -	igt_blitter_fast_copy__raw(fd,
>>> -				   fb->gem_handle,
>>> -				   fb->offsets[0],
>>> -				   fb->stride,
>>> -				   obj_tiling,
>>> -				   0, 0, /* src_x, src_y */
>>> -				   fb->width, fb->height,
>>> -				   igt_drm_format_to_bpp(fb-
>>>> drm_format),
>>> -				   blit->linear.handle, 0,
>>> -				   blit->linear.stride,
>>> -				   I915_TILING_NONE,
>>> -				   0, 0 /* dst_x, dst_y */);
>>> -
>>> -	gem_sync(fd, blit->linear.handle);
>>> -
>>> -	gem_set_domain(fd, blit->linear.handle,
>>> +	for (i = 0; i < fb->num_planes; i++)
>>> +		igt_blitter_fast_copy__raw(fd,
>>> +					  fb->gem_handle,
>>> +					  fb->offsets[i],
>>> +					  fb->stride,
>>> +					  obj_tiling,
>>> +					  0, 0, /* src_x, src_y */
>>> +					  fb->plane_width[i], fb-
>>>> plane_height[i],
>>> +					  fb->plane_bpp[i],
>>> +					  linear->handle, linear-
>>>> offsets[i],
>>> +					  linear->stride,
>>> +					  I915_TILING_NONE,
>>> +					  0, 0 /* dst_x, dst_y */);
>>> +
>>> +	gem_sync(fd, linear->handle);
>>> +
>>> +	gem_set_domain(fd, linear->handle,
>>>  		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
>>>  
>>>  	/* Setup cairo context */
>>> -	blit->linear.map = gem_mmap__cpu(fd,
>>> -					 blit->linear.handle,
>>> -					 0,
>>> -					 blit->linear.size,
>>> -					 PROT_READ | PROT_WRITE);
>>> +	linear->map = gem_mmap__cpu(fd, linear->handle,
>>> +				    0, linear->size, PROT_READ |
>>> PROT_WRITE);
>>> +}
>>> +
>>> +static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
>>> +{
>>> +	struct fb_blit_upload *blit;
>>> +	cairo_format_t cairo_format;
>>> +
>>> +	blit = malloc(sizeof(*blit));
>>> +	igt_assert(blit);
>>> +
>>> +	blit->fd = fd;
>>> +	blit->fb = fb;
>>> +	setup_linear_mapping(fd, fb, &blit->linear);
>>>  
>>>  	cairo_format = drm_format_to_cairo(fb->drm_format);
>>>  	fb->cairo_surface =
>>> @@ -1284,6 +1305,232 @@ static void create_cairo_surface__gtt(int fd,
>>> struct igt_fb *fb)
>>>  				    fb, destroy_cairo_surface__gtt);
>>>  }
>>>  
>>> +struct fb_convert_blit_upload {
>>> +	int fd;
>>> +	struct igt_fb *fb;
>>> +
>>> +	struct {
>>> +		uint8_t *map;
>>> +		unsigned stride, size;
>>> +	} rgb24;
>>> +
>>> +	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;
>> I'm thinking of this rounding issue. Should we use rounding to the
>> nearest integer here, instead of floor? Does the way we do rounding
>> have an effect on test results if we first grab the reference CRC and
>> then run a test in NV12 format?
>>
>>> +}
>>> +
>>> +static void convert_nv12_to_rgb24(struct igt_fb *fb, struct
>>> fb_convert_blit_upload *blit)
>>> +{
>>> +	int i, j;
>>> +	const uint8_t *y, *uv;
>>> +	uint8_t *rgb24 = blit->rgb24.map;
>>> +	unsigned rgb24_stride = blit->rgb24.stride, planar_stride =
>>> blit->linear.stride;
>>> +	uint8_t *buf = malloc(blit->linear.size);
>>> +
>>> +	/*
>>> +	 * 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.
>>> +	 */
>>> +	memcpy(buf, blit->linear.map, blit->linear.size);
>>> +	y = &buf[blit->linear.offsets[0]];
>>> +	uv = &buf[blit->linear.offsets[1]];
>>> +
>>> +	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);
>>> +
>>> +			cb = uv[j & ~1] - 128.f;
>>> +			cr = uv[j | 1] - 128.f;
>>> +
>>> +			r_ = 0.000f * cb +  1.793f * cr;
>>> +			g_ = -0.213f * cb + -0.533f * cr;
>>> +			b_ = 2.112f * cb +  0.000f * cr;
>>> +
>>> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
>>> +			rgb24[j * 4 + 2 + rgb24_stride] =
>>> clamprgb(y1 + r_);
>>> +
>>> +			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 += 2 * rgb24_stride;
>>> +		y += 2 * planar_stride;
>>> +		uv += planar_stride;
>>> +	}
>>> +
>>> +	if (fb->height & 1) {
>>> +		/* Convert last row */
>>> +		for (j = 0; j < fb->width; j++) {
>>> +			float r_, g_, b_, y0, cb, cr;
>>> +			/* Convert single pixel */
>>> +
>>> +			cb = uv[j & ~1] - 128.f;
>>> +			cr = uv[j | 1] - 128.f;
>>> +
>>> +			y0 = 1.164f * (y[j] - 16.f);
>>> +			r_ =  0.000f * cb +  1.793f * cr;
>>> +			g_ = -0.213f * cb + -0.533f * cr;
>>> +			b_ =  2.112f * cb +  0.000f * cr;
>>> +
>> Do you have a reference for these conversion coefficients? According
>> to https://www.fourcc.org/fccyvrgb.php there are a few opinions how
>> this conversion should be handled?
> We probably don't want to hardcode these in the code since we'll want to
> test other encodings besides limited range BT.601. I think the cleanest
> approach is to derive the coefficients from the Kr/Kb values, but that
> might not lend itself well to tweaking the coefficients to match the
> hardware output (if that's necessary).
This is limited range BT.709. If we ever add support for encodings we can worry about it. :)

I think being 100% color accurate is not necessary for NV12, just as long as we are consistent.
>>> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
>>> +			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
>>> +			rgb24[j * 4] = clamprgb(y0 + b_);
>>> +		}
>>> +	}
>>> +
>>> +	free(buf);
>>> +}
>>> +
>>> +static void convert_rgb24_to_nv12(struct igt_fb *fb, struct
>>> fb_convert_blit_upload *blit)
>>> +{
>>> +	int i, j;
>>> +	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
>>> +	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
>>> +	const uint8_t *rgb24 = blit->rgb24.map;
>>> +	unsigned rgb24_stride = blit->rgb24.stride;
>>> +	unsigned planar_stride = blit->linear.stride;
>>> +
>>> +	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.709 */
>>> +
>>> +		for (j = 0; j < fb->plane_width[0]; j++) {
>>> +			float yf = 0.183f * rgb24[j * 4 + 2] +
>>> +				   0.614f * rgb24[j * 4 + 1] +
>>> +				   0.062f * rgb24[j * 4] + 16;
>>> +
>>> +			y[j] = (uint8_t)yf;
>> We could use clamprgb() here too. Just in case.
Since it's limited range, I don't think we'll hit it in practice..

>>> 0.183 * 255 + .614 * 255 + .062 * 255 + 16
235.045

>>> 0.183 * 0 + .614 * 0 + .062 * 0 + 16
16.0

u min/max:
>>> -.101 * 255 - .339 * 255 + 128
15.799999999999983

>>> .439 * 255 + 128
239.945

v min/max:
>>> -.339 * 255 + -.040 * 255 + 128
31.35499999999999

>>> .439 * 255 + 128
239.945

So it's pretty much contained between 15 and 240, no need to clamp..

>>> +		}
>>> +
>>> +		rgb24 += rgb24_stride;
>>> +		y += planar_stride;
>>> +	}
>>> +
>>> +	rgb24 = blit->rgb24.map;
>>> +
>>> +	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.101f/2 * rgb24[j * 8 + 2] +
>>> +				   -0.101f/2 * rgb24[j * 8 + 2 +
>>> rgb24_stride] +
>>> +				   -0.339f/2 * rgb24[j * 8 + 1] +
>>> +				   -0.339f/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.339f/2 * rgb24[j * 8 + 1] +
>>> +				   -0.339f/2 * rgb24[j * 8 + 1 +
>>> rgb24_stride] +
>>> +				   -0.040f/2 * rgb24[j * 8] +
>>> +				   -0.040f/2 * rgb24[j * 8 +
>>> rgb24_stride] + 128;
>>> +			uv[j * 2] = (uint8_t)uf;
>>> +			uv[j * 2 + 1] = (uint8_t)vf;
>>>
>> Maybe add rounding & clamping here too?
>>>  
>>> +		}
>>> +
>>> +		rgb24 += 2 * rgb24_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.101f * rgb24[j * 8 + 2] +
>>> +				   -0.339f * rgb24[j * 8 + 1] +
>>> +				    0.439f * rgb24[j * 8] + 128;
>>> +			float vf =  0.439f * rgb24[j * 8 + 2] +
>>> +				   -0.339f * rgb24[j * 8 + 1] +
>>> +				   -0.040f * rgb24[j * 8] + 128;
>>> +
>>> +			uv[j * 2] = (uint8_t)uf;
>>> +			uv[j * 2 + 1] = (uint8_t)vf;
>> rounding & clamping?
I left out the clamping for Y and UV because we can overflow/undeflow by 16. If necessary I can re-add it. :)

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

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

* [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2.
  2018-01-31 14:32     ` Ville Syrjälä
  2018-01-31 15:09       ` Maarten Lankhorst
@ 2018-01-31 16:52       ` Maarten Lankhorst
  2018-02-01 14:23         ` Ville Syrjälä
  1 sibling, 1 reply; 47+ messages in thread
From: Maarten Lankhorst @ 2018-01-31 16:52 UTC (permalink / raw)
  To: igt-dev

For NV12 a format conversion is needed. Because YUV formats are not
fully defined with just a fourcc, I've chosen BT.601 limited range.
This puts the pixel center of the CbCr components between the top
left Y and bottom left Y:

Y   Y   Y   Y
UV      UV
Y   Y   Y   Y

Some work is put into optimising the conversion routines in order to
make it fast enough. Before converting nv12 to rgb24, it is copied to
a temporary buffer to take advantage of memory caching. This is
approximately 20x faster than directly reading the BO.

When testing on my KBL with a 1080p buffer, it takes approximately
.1s to convert either way, this is fast enough not to bother optimising
even further for me.

Changes since v1:
- Use BT.601 instead of BT.709 coefficients. (Ville)

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 lib/igt_fb.c | 391 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 319 insertions(+), 72 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 9d60280f198e..6f57ab69a822 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -70,6 +70,7 @@ static struct format_desc_struct {
 	DF(XRGB8888,	RGB24,		32, 24),
 	DF(XRGB2101010,	RGB30,		32, 30),
 	DF(ARGB8888,	ARGB32,		32, 32),
+	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
 };
 #undef DF
 
@@ -364,14 +365,20 @@ static int create_bo_for_fb(int fd, int width, int height,
 			*is_dumb = false;
 
 		if (is_i915_device(fd)) {
-			uint32_t *ptr;
+			uint8_t *ptr;
 
 			bo = gem_create(fd, size);
 			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
 
 			/* Ensure the framebuffer is preallocated */
-			ptr = gem_mmap__gtt(fd, bo, size, PROT_READ);
-			igt_assert(*ptr == 0);
+			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);
+			}
 			gem_munmap(ptr, size);
 
 			if (size_ret)
@@ -1127,103 +1134,117 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 		     drm_format, igt_format_str(drm_format));
 }
 
+struct fb_blit_linear {
+	uint32_t handle;
+	unsigned size, stride;
+	uint8_t *map;
+	bool is_dumb;
+	uint32_t offsets[4];
+};
+
 struct fb_blit_upload {
 	int fd;
 	struct igt_fb *fb;
-	struct {
-		uint32_t handle;
-		unsigned size, stride;
-		uint8_t *map;
-		bool is_dumb;
-	} linear;
+	struct fb_blit_linear linear;
 };
 
-static void destroy_cairo_surface__blit(void *arg)
+static void free_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
 {
-	struct fb_blit_upload *blit = arg;
-	struct igt_fb *fb = blit->fb;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
+	int i;
 
-	gem_munmap(blit->linear.map, blit->linear.size);
-	fb->cairo_surface = NULL;
+	gem_munmap(linear->map, linear->size);
+	gem_set_domain(fd, linear->handle,
+		       I915_GEM_DOMAIN_GTT, 0);
+
+	for (i = 0; i < fb->num_planes; i++)
+		igt_blitter_fast_copy__raw(fd,
+					   linear->handle,
+					   linear->offsets[i],
+					   linear->stride,
+					   I915_TILING_NONE,
+					   0, 0, /* src_x, src_y */
+					   fb->plane_width[i], fb->plane_height[i],
+					   fb->plane_bpp[i],
+					   fb->gem_handle,
+					   fb->offsets[i],
+					   fb->stride,
+					   obj_tiling,
+					   0, 0 /* dst_x, dst_y */);
+
+	gem_sync(fd, linear->handle);
+	gem_close(fd, linear->handle);
+}
 
-	gem_set_domain(blit->fd, blit->linear.handle,
-			I915_GEM_DOMAIN_GTT, 0);
+static void destroy_cairo_surface__blit(void *arg)
+{
+	struct fb_blit_upload *blit = arg;
 
-	igt_blitter_fast_copy__raw(blit->fd,
-				   blit->linear.handle, 0,
-				   blit->linear.stride,
-				   I915_TILING_NONE,
-				   0, 0, /* src_x, src_y */
-				   fb->width, fb->height,
-				   igt_drm_format_to_bpp(fb->drm_format),
-				   fb->gem_handle,
-				   fb->offsets[0],
-				   fb->stride,
-				   obj_tiling,
-				   0, 0 /* dst_x, dst_y */);
-
-	gem_sync(blit->fd, blit->linear.handle);
-	gem_close(blit->fd, blit->linear.handle);
+	blit->fb->cairo_surface = NULL;
+
+	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
 
 	free(blit);
 }
 
-static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
+static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
 {
-	struct fb_blit_upload *blit;
-	cairo_format_t cairo_format;
 	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
-	uint32_t offsets[4];
-
-	blit = malloc(sizeof(*blit));
-	igt_assert(blit);
+	int i;
 
 	/*
 	 * We create a linear BO that we'll map for the CPU to write to (using
 	 * cairo). This linear bo will be then blitted to its final
 	 * destination, tiling it at the same time.
 	 */
-	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
+	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
 					       lookup_drm_format(fb->drm_format),
 					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
-					       0, &blit->linear.size,
-					       &blit->linear.stride,
-					       offsets, &blit->linear.is_dumb);
-
-	igt_assert(blit->linear.handle > 0);
+					       0, &linear->size,
+					       &linear->stride,
+					       linear->offsets, &linear->is_dumb);
 
-	blit->fd = fd;
-	blit->fb = fb;
+	igt_assert(linear->handle > 0);
 
 	/* Copy fb content to linear BO */
-	gem_set_domain(fd, blit->linear.handle,
+	gem_set_domain(fd, linear->handle,
 			I915_GEM_DOMAIN_GTT, 0);
 
-	igt_blitter_fast_copy__raw(fd,
-				   fb->gem_handle,
-				   fb->offsets[0],
-				   fb->stride,
-				   obj_tiling,
-				   0, 0, /* src_x, src_y */
-				   fb->width, fb->height,
-				   igt_drm_format_to_bpp(fb->drm_format),
-				   blit->linear.handle, 0,
-				   blit->linear.stride,
-				   I915_TILING_NONE,
-				   0, 0 /* dst_x, dst_y */);
-
-	gem_sync(fd, blit->linear.handle);
-
-	gem_set_domain(fd, blit->linear.handle,
+	for (i = 0; i < fb->num_planes; i++)
+		igt_blitter_fast_copy__raw(fd,
+					  fb->gem_handle,
+					  fb->offsets[i],
+					  fb->stride,
+					  obj_tiling,
+					  0, 0, /* src_x, src_y */
+					  fb->plane_width[i], fb->plane_height[i],
+					  fb->plane_bpp[i],
+					  linear->handle, linear->offsets[i],
+					  linear->stride,
+					  I915_TILING_NONE,
+					  0, 0 /* dst_x, dst_y */);
+
+	gem_sync(fd, linear->handle);
+
+	gem_set_domain(fd, linear->handle,
 		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 
 	/* Setup cairo context */
-	blit->linear.map = gem_mmap__cpu(fd,
-					 blit->linear.handle,
-					 0,
-					 blit->linear.size,
-					 PROT_READ | PROT_WRITE);
+	linear->map = gem_mmap__cpu(fd, linear->handle,
+				    0, linear->size, PROT_READ | PROT_WRITE);
+}
+
+static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
+{
+	struct fb_blit_upload *blit;
+	cairo_format_t cairo_format;
+
+	blit = malloc(sizeof(*blit));
+	igt_assert(blit);
+
+	blit->fd = fd;
+	blit->fb = fb;
+	setup_linear_mapping(fd, fb, &blit->linear);
 
 	cairo_format = drm_format_to_cairo(fb->drm_format);
 	fb->cairo_surface =
@@ -1285,6 +1306,233 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
 				    fb, destroy_cairo_surface__gtt);
 }
 
+struct fb_convert_blit_upload {
+	int fd;
+	struct igt_fb *fb;
+
+	struct {
+		uint8_t *map;
+		unsigned stride, size;
+	} rgb24;
+
+	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 void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
+{
+	int i, j;
+	const uint8_t *y, *uv;
+	uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
+	uint8_t *buf = malloc(blit->linear.size);
+
+	/*
+	 * 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.
+	 */
+	memcpy(buf, blit->linear.map, blit->linear.size);
+	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);
+
+			cb = uv[j & ~1] - 128.f;
+			cr = uv[j | 1] - 128.f;
+
+			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(y0 + r_);
+			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
+
+			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 += 2 * rgb24_stride;
+		y += 2 * planar_stride;
+		uv += planar_stride;
+	}
+
+	if (fb->height & 1) {
+		/* Convert last row */
+		for (j = 0; j < fb->width; j++) {
+			float r_, g_, b_, y0, cb, cr;
+			/* Convert single pixel */
+
+			cb = uv[j & ~1] - 128.f;
+			cr = uv[j | 1] - 128.f;
+
+			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;
+
+			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
+			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
+			rgb24[j * 4] = clamprgb(y0 + b_);
+		}
+	}
+
+	free(buf);
+}
+
+static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
+{
+	int i, j;
+	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
+	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
+	const uint8_t *rgb24 = blit->rgb24.map;
+	unsigned rgb24_stride = blit->rgb24.stride;
+	unsigned planar_stride = blit->linear.stride;
+
+	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;
+
+			y[j] = (uint8_t)yf;
+		}
+
+		rgb24 += rgb24_stride;
+		y += planar_stride;
+	}
+
+	rgb24 = blit->rgb24.map;
+
+	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;
+		}
+
+		rgb24 += 2 * rgb24_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;
+		}
+	}
+}
+
+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);
+
+	munmap(blit->rgb24.map, blit->rgb24.size);
+
+	if (blit->linear.handle)
+		free_linear_mapping(blit->fd, blit->fb, &blit->linear);
+	else
+		gem_munmap(blit->linear.map, fb->size);
+
+	free(blit);
+
+	fb->cairo_surface = NULL;
+}
+
+static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
+{
+	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
+	igt_assert(blit);
+
+	blit->fd = fd;
+	blit->fb = fb;
+	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
+	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height, sysconf(_SC_PAGESIZE));
+	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	igt_assert(blit->rgb24.map != MAP_FAILED);
+
+	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
+		setup_linear_mapping(fd, fb, &blit->linear);
+	} else {
+		blit->linear.handle = 0;
+		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
+					      PROT_READ | PROT_WRITE);
+		igt_assert(blit->linear.map);
+		blit->linear.stride = fb->stride;
+		blit->linear.size = fb->size;
+		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);
+
+	fb->cairo_surface =
+		cairo_image_surface_create_for_data(blit->rgb24.map,
+						    CAIRO_FORMAT_RGB24,
+						    fb->width, fb->height,
+						    blit->rgb24.stride);
+
+	cairo_surface_set_user_data(fb->cairo_surface,
+				    (cairo_user_data_key_t *)create_cairo_surface__convert,
+				    blit, destroy_cairo_surface__convert);
+}
+
 /**
  * igt_get_cairo_surface:
  * @fd: open drm file descriptor
@@ -1298,11 +1546,10 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
  */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
 {
-	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
-	igt_assert(fb->num_planes < 2);
-
 	if (fb->cairo_surface == NULL) {
-		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
+		if (fb->num_planes > 1)
+			create_cairo_surface__convert(fd, fb);
+		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
 		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
 			create_cairo_surface__blit(fd, fb);
 		else
-- 
2.15.1

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

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

* Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
  2018-01-23 15:50   ` Ville Syrjälä
@ 2018-01-31 17:03   ` Ville Syrjälä
  1 sibling, 0 replies; 47+ messages in thread
From: Ville Syrjälä @ 2018-01-31 17:03 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

On Tue, Jan 23, 2018 at 01:56:35PM +0100, Maarten Lankhorst wrote:
> This will allow support for NV12 in the future, where igt_get_cairo_ctx
> will return a RGB image to draw with, which will be converted in
> igt_put_cairo_ctx so tests don't have to add special support for NV12.
> 
> This is the same as cairo_destroy + checking for errors, but not all
> tests use this correctly so it's better to have a single handler for it.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c                      | 34 ++++++++++++++++++++++++----------
>  lib/igt_fb.h                      |  1 +
>  tests/kms_chv_cursor_fail.c       |  3 +--
>  tests/kms_color.c                 |  4 ++--
>  tests/kms_concurrent.c            |  3 +--
>  tests/kms_crtc_background_color.c |  2 +-
>  tests/kms_cursor_crc.c            | 23 +++++++++++++++++++----
>  tests/kms_flip.c                  |  3 +--
>  tests/kms_mmap_write_crc.c        |  4 ++--
>  tests/kms_plane.c                 |  9 +++------
>  tests/kms_plane_multiple.c        |  3 +--
>  tests/kms_plane_scaling.c         |  3 +--
>  tests/kms_psr_sink_crc.c          |  2 +-
>  tests/kms_render.c                |  2 +-
>  tests/kms_rotation_crc.c          |  2 +-
>  tests/kms_setmode.c               |  2 +-
>  tests/testdisplay.c               |  8 ++------
>  17 files changed, 63 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index ded639e833f1..39a83bae178a 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -771,8 +771,7 @@ unsigned int igt_create_color_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_color(cr, 0, 0, width, height, r, g, b);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -809,8 +808,7 @@ unsigned int igt_create_pattern_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_test_pattern(cr, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -853,8 +851,7 @@ unsigned int igt_create_color_pattern_fb(int fd, int width, int height,
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_color(cr, 0, 0, width, height, r, g, b);
>  	igt_paint_test_pattern(cr, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -897,8 +894,7 @@ unsigned int igt_create_image_fb(int fd, int width, int height,
>  
>  	cr = igt_get_cairo_ctx(fd, fb);
>  	igt_paint_image(cr, filename, 0, 0, width, height);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(fd, fb, cr);
>  
>  	return fb_id;
>  }
> @@ -998,7 +994,7 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
>  			layout.right.x, layout.right.y,
>  			layout.right.width, layout.right.height);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, &fb, cr);
>  
>  	return fb_id;
>  }
> @@ -1206,7 +1202,7 @@ cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>   *
>   * This initializes a cairo surface for @fb and then allocates a drawing context
>   * for it. The return cairo drawing context should be released by calling
> - * cairo_destroy(). This also sets a default font for drawing text on
> + * igt_put_cairo_ctx(). This also sets a default font for drawing text on
>   * framebuffers.
>   *
>   * Returns:
> @@ -1229,6 +1225,24 @@ cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb)
>  	return cr;
>  }
>  
> +/**
> + * igt_put_cairo_ctx:
> + * @fd: open i915 drm file descriptor
> + * @fb: pointer to an #igt_fb structure
> + * @cr: the cairo context returned by igt_get_cairo_ctx.
> + *
> + * This releases the cairo surface @cr returned by igt_get_cairo_ctx()
> + * for @fb, and writes the changes out to the framebuffer if cairo doesn't
> + * have native support for the format.
> + */
> +void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr)
> +{
> +	cairo_status_t ret = cairo_status(cr);
> +	igt_assert_f(ret == CAIRO_STATUS_SUCCESS, "Cairo failed to draw with %s\n", cairo_status_to_string(ret));
> +
> +	cairo_destroy(cr);

I was looking at the whole cairo surface stuff, and it looks to me like
igt_get_cairo_surface() is missing a cairo_surface_reference() for the
case where already have fb->cairo_surface.

Maybe we should also add some asserts into eg. igt_plane_set_fb() to
make sure there is no fb->cairo_surface around anymore, to guarantee
that we've actually copied the contents from the temp surface back
to the real bo?

Anyway, this patch seems fine to me so
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +}
> +
>  /**
>   * igt_remove_fb:
>   * @fd: open i915 drm file descriptor
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index d30a7340c76e..3004f0656029 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -131,6 +131,7 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
>  cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
>  cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
> +void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr);
>  void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
>  			 double r, double g, double b);
>  void igt_paint_color_alpha(cairo_t *cr, int x, int y, int w, int h,
> diff --git a/tests/kms_chv_cursor_fail.c b/tests/kms_chv_cursor_fail.c
> index 3e74df1142da..1bcf8469088e 100644
> --- a/tests/kms_chv_cursor_fail.c
> +++ b/tests/kms_chv_cursor_fail.c
> @@ -87,8 +87,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
>  	else
>  		igt_paint_color_alpha(cr, 0, 0, data->fb.width, data->fb.height,
>  				      0.0, 0.0, 0.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  }
>  
>  static void cursor_move(data_t *data, int x, int y, int i)
> diff --git a/tests/kms_color.c b/tests/kms_color.c
> index 3b0a88802c93..dc4fcce241be 100644
> --- a/tests/kms_color.c
> +++ b/tests/kms_color.c
> @@ -86,7 +86,7 @@ static void paint_gradient_rectangles(data_t *data,
>  					       colors[i].b);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  static void paint_rectangles(data_t *data,
> @@ -103,7 +103,7 @@ static void paint_rectangles(data_t *data,
>  				colors[i].r, colors[i].g, colors[i].b);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  static double *generate_table(uint32_t lut_size, double exp)
> diff --git a/tests/kms_concurrent.c b/tests/kms_concurrent.c
> index 3b2e601505c4..283acf8c8a7e 100644
> --- a/tests/kms_concurrent.c
> +++ b/tests/kms_concurrent.c
> @@ -148,8 +148,7 @@ create_fb_for_mode_position(data_t *data, drmModeModeInfo *mode,
>  				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
>  	}
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
>  }
>  
>  static void
> diff --git a/tests/kms_crtc_background_color.c b/tests/kms_crtc_background_color.c
> index e99c67bd185e..6407e19bafce 100644
> --- a/tests/kms_crtc_background_color.c
> +++ b/tests/kms_crtc_background_color.c
> @@ -69,7 +69,7 @@ paint_background(data_t *data, struct igt_fb *fb, drmModeModeInfo *mode,
>  	b = (double) ((background & 0xFF0000) >> 16) / 255.0;
>  	igt_paint_color_alpha(cr, 0, 0, w, h, r, g, b, alpha);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->gfx_fd, &data->fb, cr);
>  }
>  
>  static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
> diff --git a/tests/kms_cursor_crc.c b/tests/kms_cursor_crc.c
> index 4c5e00c074a5..a164839ee2cc 100644
> --- a/tests/kms_cursor_crc.c
> +++ b/tests/kms_cursor_crc.c
> @@ -141,13 +141,16 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_pipe_crc_t *pipe_crc = data->pipe_crc;
>  	igt_crc_t crc, ref_crc;
>  	igt_plane_t *cursor;
> -	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
> +	cairo_t *cr;
>  	int ret = 0;
>  
>  	igt_print_activity();
>  
>  	/* Hardware test */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_test_pattern(cr, data->screenw, data->screenh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  	cursor_enable(data);
>  	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
>  	igt_plane_set_position(cursor, x, y);
> @@ -190,7 +193,9 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_display_commit(display);
>  
>  	/* Now render the same in software and collect crc */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	draw_cursor(cr, x, y, data->curw, data->curh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  	igt_display_commit(display);
>  
>  	igt_wait_for_vblank(data->drm_fd, data->pipe);
> @@ -198,20 +203,25 @@ static void do_single_test(data_t *data, int x, int y)
>  	igt_assert_crc_equal(&crc, &ref_crc);
>  
>  	/* Clear screen afterwards */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_color(cr, 0, 0, data->screenw, data->screenh, 0.0, 0.0, 0.0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  }
>  
>  static void do_fail_test(data_t *data, int x, int y, int expect)
>  {
>  	igt_display_t *display = &data->display;
>  	igt_plane_t *cursor;
> -	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
> +	cairo_t *cr;
>  	int ret;
>  
>  	igt_print_activity();
>  
>  	/* Hardware test */
> +	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	igt_paint_test_pattern(cr, data->screenw, data->screenh);
> +	igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  	cursor_enable(data);
>  	cursor = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_CURSOR);
>  	igt_plane_set_position(cursor, x, y);
> @@ -446,7 +456,7 @@ static void create_cursor_fb(data_t *data, int cur_w, int cur_h)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
>  	draw_cursor(cr, 0, 0, cur_w, cur_h);
> -	igt_assert(cairo_status(cr) == 0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  }
>  
>  static bool has_nonsquare_cursors(uint32_t devid)
> @@ -486,6 +496,7 @@ static void test_cursor_size(data_t *data)
>  	/* Use a solid white rectangle as the cursor */
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
>  	igt_paint_color_alpha(cr, 0, 0, cursor_max_size, cursor_max_size, 1.0, 1.0, 1.0, 1.0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb, cr);
>  
>  	/* Hardware test loop */
>  	cursor_enable(data);
> @@ -501,16 +512,20 @@ static void test_cursor_size(data_t *data)
>  	}
>  	cursor_disable(data);
>  	/* Software test loop */
> -	cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  	for (i = 0, size = cursor_max_size; size >= 64; size /= 2, i++) {
>  		/* Now render the same in software and collect crc */
> +		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  		igt_paint_color_alpha(cr, 0, 0, size, size, 1.0, 1.0, 1.0, 1.0);
> +		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
> +
>  		igt_display_commit(display);
>  		igt_wait_for_vblank(data->drm_fd, data->pipe);
>  		igt_pipe_crc_collect_crc(pipe_crc, &ref_crc);
>  		/* Clear screen afterwards */
> +		cr = igt_get_cairo_ctx(data->drm_fd, &data->primary_fb);
>  		igt_paint_color(cr, 0, 0, data->screenw, data->screenh,
>  				0.0, 0.0, 0.0);
> +		igt_put_cairo_ctx(data->drm_fd, &data->primary_fb, cr);
>  		igt_assert_crc_equal(&crc[i], &ref_crc);
>  	}
>  }
> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> index 710ea52b4a8a..b43e77123e7f 100644
> --- a/tests/kms_flip.c
> +++ b/tests/kms_flip.c
> @@ -976,8 +976,7 @@ static void paint_flip_mode(struct igt_fb *fb, bool odd_frame)
>  	cairo_set_source_rgb(cr, 1, 1, 1);
>  	cairo_fill(cr);
>  
> -	igt_assert(!cairo_status(cr));
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  }
>  
>  static int
> diff --git a/tests/kms_mmap_write_crc.c b/tests/kms_mmap_write_crc.c
> index dd44ce97238a..279d0f67dd53 100644
> --- a/tests/kms_mmap_write_crc.c
> +++ b/tests/kms_mmap_write_crc.c
> @@ -92,7 +92,7 @@ static void test(data_t *data)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, fb);
>  	igt_paint_test_pattern(cr, fb->width, fb->height);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  
>  	/* flip to it to make it UC/WC and fully flushed */
>  	igt_plane_set_fb(data->primary, fb);
> @@ -135,7 +135,7 @@ static void test(data_t *data)
>  	 * fully flushed */
>  	cr = igt_get_cairo_ctx(data->drm_fd, fb);
>  	igt_paint_test_pattern(cr, fb->width, fb->height);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  
>  	igt_plane_set_fb(data->primary, fb);
>  	igt_display_commit(display);
> diff --git a/tests/kms_plane.c b/tests/kms_plane.c
> index 9672763fe619..54bcffc16f4f 100644
> --- a/tests/kms_plane.c
> +++ b/tests/kms_plane.c
> @@ -138,8 +138,7 @@ create_fb_for_mode__position(data_t *data, drmModeModeInfo *mode,
>  	igt_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
>  			    0.0, 1.0, 0.0);
>  	igt_paint_color(cr, rect_x, rect_y, rect_w, rect_h, 0.0, 0.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  enum {
> @@ -279,8 +278,7 @@ create_fb_for_mode__panning(data_t *data, drmModeModeInfo *mode,
>  			mode->hdisplay, mode->vdisplay,
>  			0.0, 0.0, 1.0);
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, fb, cr);
>  }
>  
>  enum {
> @@ -436,8 +434,7 @@ static void test_format_plane(data_t *data, enum pipe pipe,
>  				0.0, 1.0, 0.0);
>  		if (width >= 164 && height >= 164)
>  			igt_paint_color(cr, 100, 100, 64, 64, 0.0, 0.0, 0.0);
> -		igt_assert(cairo_status(cr) == 0);
> -		cairo_destroy(cr);
> +		igt_put_cairo_ctx(data->drm_fd, &fb, cr);
>  
>  		igt_plane_set_fb(plane, &fb);
>  		igt_display_commit2(&data->display, COMMIT_UNIVERSAL);
> diff --git a/tests/kms_plane_multiple.c b/tests/kms_plane_multiple.c
> index aea59df84d76..95b713858edc 100644
> --- a/tests/kms_plane_multiple.c
> +++ b/tests/kms_plane_multiple.c
> @@ -173,8 +173,7 @@ create_fb_for_mode_position(data_t *data, igt_output_t *output, drmModeModeInfo
>  				rect_w[i], rect_h[i], 0.0, 0.0, 0.0);
>  		}
>  
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb[primary->index], cr);
>  }
>  
>  
> diff --git a/tests/kms_plane_scaling.c b/tests/kms_plane_scaling.c
> index c8283a3b23d1..d32f3441e8c9 100644
> --- a/tests/kms_plane_scaling.c
> +++ b/tests/kms_plane_scaling.c
> @@ -120,8 +120,7 @@ static void paint_fb(data_t *d, struct igt_fb *fb)
>  
>  	cr = igt_get_cairo_ctx(d->drm_fd, fb);
>  	igt_paint_color(cr, 0, 0, fb->width, fb->height, 0.0, 1.0, 0.0);
> -	igt_assert(cairo_status(cr) == 0);
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(d->drm_fd, fb, cr);
>  }
>  
>  static void check_scaling_pipe_plane_rot(data_t *d, igt_plane_t *plane,
> diff --git a/tests/kms_psr_sink_crc.c b/tests/kms_psr_sink_crc.c
> index 26cf434af64a..2b60acf34e77 100644
> --- a/tests/kms_psr_sink_crc.c
> +++ b/tests/kms_psr_sink_crc.c
> @@ -91,7 +91,7 @@ static void create_cursor_fb(data_t *data)
>  
>  	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb_white);
>  	igt_paint_color_alpha(cr, 0, 0, 64, 64, 1.0, 1.0, 1.0, 1.0);
> -	igt_assert(cairo_status(cr) == 0);
> +	igt_put_cairo_ctx(data->drm_fd, &data->fb_white, cr);
>  }
>  
>  
> diff --git a/tests/kms_render.c b/tests/kms_render.c
> index d2208e38f84e..25a0c05b547c 100644
> --- a/tests/kms_render.c
> +++ b/tests/kms_render.c
> @@ -55,7 +55,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
>  	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
>  	igt_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  
>  	return 0;
>  }
> diff --git a/tests/kms_rotation_crc.c b/tests/kms_rotation_crc.c
> index 799cf1142579..5b190a0d03cb 100644
> --- a/tests/kms_rotation_crc.c
> +++ b/tests/kms_rotation_crc.c
> @@ -120,7 +120,7 @@ paint_squares(data_t *data, igt_rotation_t rotation,
>  	igt_paint_color(cr, 0, h / 2, w / 2, h / 2, RGB_COLOR(bl));
>  	igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, RGB_COLOR(br));
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(data->gfx_fd, fb, cr);
>  }
>  
>  static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
> diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c
> index 206d360607bb..06241b191a0f 100644
> --- a/tests/kms_setmode.c
> +++ b/tests/kms_setmode.c
> @@ -161,7 +161,7 @@ static int paint_fb(struct igt_fb *fb, const char *test_name,
>  					  crtc_str[i]);
>  	}
>  
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  
>  	return 0;
>  }
> diff --git a/tests/testdisplay.c b/tests/testdisplay.c
> index b0156c5cf0e1..0ff98a2b705e 100644
> --- a/tests/testdisplay.c
> +++ b/tests/testdisplay.c
> @@ -227,9 +227,7 @@ paint_color_key(struct igt_fb *fb_info)
>  	cairo_set_source_rgb(cr, .8, .8, .8);
>  	cairo_fill(cr);
>  
> -	igt_assert(!cairo_status(cr));
> -
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb_info, cr);
>  }
>  
>  static void paint_image(cairo_t *cr, const char *file)
> @@ -294,9 +292,7 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb)
>  	if (qr_code)
>  		paint_image(cr, "pass.png");
>  
> -	igt_assert(!cairo_status(cr));
> -
> -	cairo_destroy(cr);
> +	igt_put_cairo_ctx(drm_fd, fb, cr);
>  }
>  
>  static void sighandler(int signo)
> -- 
> 2.15.1
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

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

* [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev5)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (15 preceding siblings ...)
  2018-01-29 17:29 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
@ 2018-01-31 17:15 ` Patchwork
  2018-01-31 18:55 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-31 17:15 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev5)
URL   : https://patchwork.freedesktop.org/series/36965/
State : success

== Summary ==

IGT patchset tested on top of latest successful build
7f0be0e7d9becb79630093bf0e6daeadcd937062 tools/intel_reg: Add reading and writing registers through engine

with latest DRM-Tip kernel build CI_DRM_3708
ae93f9b9acf3 drm-tip: 2018y-01m-31d-16h-31m-38s UTC integration manifest

No testlist changes.

Test kms_chamelium:
        Subgroup common-hpd-after-suspend:
                dmesg-warn -> PASS       (fi-skl-6700k2) fdo#104108
Test kms_pipe_crc_basic:
        Subgroup suspend-read-crc-pipe-b:
                incomplete -> PASS       (fi-snb-2520m) fdo#103713

fdo#104108 https://bugs.freedesktop.org/show_bug.cgi?id=104108
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713

fi-bdw-5557u     total:288  pass:267  dwarn:0   dfail:0   fail:0   skip:21  time:418s
fi-bdw-gvtdvm    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:425s
fi-blb-e6850     total:288  pass:223  dwarn:1   dfail:0   fail:0   skip:64  time:372s
fi-bsw-n3050     total:288  pass:242  dwarn:0   dfail:0   fail:0   skip:46  time:488s
fi-bwr-2160      total:288  pass:183  dwarn:0   dfail:0   fail:0   skip:105 time:282s
fi-bxt-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:483s
fi-bxt-j4205     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:486s
fi-byt-j1900     total:288  pass:253  dwarn:0   dfail:0   fail:0   skip:35  time:468s
fi-byt-n2820     total:288  pass:249  dwarn:0   dfail:0   fail:0   skip:39  time:454s
fi-cfl-s2        total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:578s
fi-elk-e7500     total:224  pass:168  dwarn:10  dfail:0   fail:0   skip:45 
fi-gdg-551       total:288  pass:179  dwarn:0   dfail:0   fail:1   skip:108 time:281s
fi-glk-1         total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:512s
fi-hsw-4770      total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:390s
fi-hsw-4770r     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:403s
fi-ilk-650       total:288  pass:228  dwarn:0   dfail:0   fail:0   skip:60  time:419s
fi-ivb-3520m     total:288  pass:259  dwarn:0   dfail:0   fail:0   skip:29  time:452s
fi-ivb-3770      total:288  pass:255  dwarn:0   dfail:0   fail:0   skip:33  time:413s
fi-kbl-7500u     total:288  pass:263  dwarn:1   dfail:0   fail:0   skip:24  time:457s
fi-kbl-7560u     total:288  pass:269  dwarn:0   dfail:0   fail:0   skip:19  time:497s
fi-kbl-7567u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:456s
fi-kbl-r         total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:498s
fi-pnv-d510      total:288  pass:222  dwarn:1   dfail:0   fail:0   skip:65  time:579s
fi-skl-6260u     total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:436s
fi-skl-6600u     total:288  pass:261  dwarn:0   dfail:0   fail:0   skip:27  time:505s
fi-skl-6700hq    total:288  pass:262  dwarn:0   dfail:0   fail:0   skip:26  time:528s
fi-skl-6700k2    total:288  pass:264  dwarn:0   dfail:0   fail:0   skip:24  time:493s
fi-skl-6770hq    total:288  pass:268  dwarn:0   dfail:0   fail:0   skip:20  time:472s
fi-skl-guc       total:288  pass:260  dwarn:0   dfail:0   fail:0   skip:28  time:418s
fi-skl-gvtdvm    total:288  pass:265  dwarn:0   dfail:0   fail:0   skip:23  time:432s
fi-snb-2520m     total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:530s
fi-snb-2600      total:288  pass:248  dwarn:0   dfail:0   fail:0   skip:40  time:405s
Blacklisted hosts:
fi-glk-dsi       total:288  pass:258  dwarn:0   dfail:0   fail:0   skip:30  time:469s

== Logs ==

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

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

* [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev5)
  2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
                   ` (16 preceding siblings ...)
  2018-01-31 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev5) Patchwork
@ 2018-01-31 18:55 ` Patchwork
  17 siblings, 0 replies; 47+ messages in thread
From: Patchwork @ 2018-01-31 18:55 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

== Series Details ==

Series: lib/igt_fb: Add support for the NV12 format. (rev5)
URL   : https://patchwork.freedesktop.org/series/36965/
State : failure

== Summary ==

Test kms_flip:
        Subgroup blocking-wf_vblank:
                pass       -> FAIL       (shard-hsw) fdo#103928
        Subgroup wf_vblank-ts-check-interruptible:
                fail       -> PASS       (shard-apl) fdo#100368
        Subgroup modeset-vs-vblank-race-interruptible:
                fail       -> PASS       (shard-apl) fdo#103060
        Subgroup basic-plain-flip:
                skip       -> PASS       (shard-apl)
        Subgroup flip-vs-modeset-vs-hang-interruptible:
                pass       -> DMESG-WARN (shard-snb) fdo#104311
        Subgroup flip-vs-expired-vblank:
                pass       -> FAIL       (shard-snb)
Test kms_frontbuffer_tracking:
        Subgroup fbc-1p-primscrn-shrfb-pgflip-blt:
                fail       -> PASS       (shard-apl) fdo#101623 +2
        Subgroup fbc-shrfb-scaledprimary:
                skip       -> PASS       (shard-apl) fdo#103167 +1
        Subgroup fbc-rgb101010-draw-mmap-gtt:
                skip       -> PASS       (shard-apl)
Test kms_rmfb:
        Subgroup rmfb-ioctl:
                skip       -> PASS       (shard-apl)
Test perf_pmu:
        Subgroup frequency:
                pass       -> FAIL       (shard-apl) fdo#104829
Test kms_cursor_legacy:
        Subgroup cursor-vs-flip-legacy:
                pass       -> FAIL       (shard-apl) fdo#103355
        Subgroup cursora-vs-flipa-atomic:
                skip       -> PASS       (shard-apl)
        Subgroup basic-flip-after-cursor-varying-size:
                skip       -> PASS       (shard-apl) fdo#102670
Test kms_vblank:
        Subgroup crtc-id:
                skip       -> PASS       (shard-apl)
        Subgroup pipe-b-accuracy-idle:
                skip       -> FAIL       (shard-apl)
        Subgroup pipe-c-wait-forked-busy:
                skip       -> PASS       (shard-apl)
        Subgroup pipe-a-ts-continuation-dpms-suspend:
                pass       -> FAIL       (shard-snb)
        Subgroup pipe-c-ts-continuation-suspend:
                dmesg-warn -> PASS       (shard-apl)
        Subgroup pipe-a-query-busy:
                skip       -> PASS       (shard-apl)
Test kms_draw_crc:
        Subgroup draw-method-xrgb8888-render-untiled:
                skip       -> PASS       (shard-apl)
        Subgroup draw-method-xrgb2101010-render-xtiled:
                skip       -> PASS       (shard-apl)
Test kms_cursor_crc:
        Subgroup cursor-256x256-dpms:
                skip       -> PASS       (shard-apl)
        Subgroup cursor-128x42-random:
                skip       -> PASS       (shard-apl)
        Subgroup cursor-256x256-rapid-movement:
                skip       -> PASS       (shard-apl) fdo#103326
Test gem_eio:
        Subgroup in-flight:
                fail       -> PASS       (shard-hsw) fdo#104676 +1
        Subgroup in-flight-contexts:
                pass       -> DMESG-WARN (shard-snb) fdo#104058
Test kms_ccs:
        Subgroup pipe-b-bad-pixel-format:
                skip       -> PASS       (shard-apl)
Test kms_plane_multiple:
        Subgroup atomic-pipe-b-tiling-yf:
                fail       -> PASS       (shard-apl)
        Subgroup legacy-pipe-a-tiling-x:
                skip       -> PASS       (shard-apl)
Test kms_pipe_crc_basic:
        Subgroup read-crc-pipe-c:
                skip       -> PASS       (shard-apl) fdo#103191
        Subgroup nonblocking-crc-pipe-c-frame-sequence:
                skip       -> PASS       (shard-apl) fdo#103481
        Subgroup read-crc-pipe-a:
                skip       -> PASS       (shard-apl)
Test kms_chv_cursor_fail:
        Subgroup pipe-a-128x128-bottom-edge:
                skip       -> PASS       (shard-apl)
Test kms_busy:
        Subgroup extended-modeset-hang-oldfb-with-reset-render-c:
                skip       -> PASS       (shard-apl) fdo#103336
        Subgroup extended-modeset-hang-newfb-with-reset-render-c:
                skip       -> PASS       (shard-apl)
Test kms_render:
        Subgroup gpu-blit:
                pass       -> FAIL       (shard-snb)
                pass       -> FAIL       (shard-hsw)
                pass       -> FAIL       (shard-apl)
        Subgroup direct-render:
                pass       -> FAIL       (shard-snb) fdo#104312
                pass       -> FAIL       (shard-hsw) fdo#102614
                pass       -> FAIL       (shard-apl)
Test perf:
        Subgroup oa-exponents:
                fail       -> PASS       (shard-apl) fdo#102254
        Subgroup oa-formats:
                pass       -> SKIP       (shard-hsw) fdo#104151
Test kms_sysfs_edid_timing:
                warn       -> PASS       (shard-apl) fdo#100047
Test kms_color:
        Subgroup pipe-a-ctm-0-75:
                skip       -> PASS       (shard-apl)
Test kms_rotation_crc:
        Subgroup primary-rotation-90-y-tiled:
                skip       -> PASS       (shard-apl)
Test kms_plane_scaling:
        Subgroup pipe-c-plane-scaling:
                skip       -> PASS       (shard-apl)

fdo#103928 https://bugs.freedesktop.org/show_bug.cgi?id=103928
fdo#100368 https://bugs.freedesktop.org/show_bug.cgi?id=100368
fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
fdo#104311 https://bugs.freedesktop.org/show_bug.cgi?id=104311
fdo#101623 https://bugs.freedesktop.org/show_bug.cgi?id=101623
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#104829 https://bugs.freedesktop.org/show_bug.cgi?id=104829
fdo#103355 https://bugs.freedesktop.org/show_bug.cgi?id=103355
fdo#102670 https://bugs.freedesktop.org/show_bug.cgi?id=102670
fdo#103326 https://bugs.freedesktop.org/show_bug.cgi?id=103326
fdo#104676 https://bugs.freedesktop.org/show_bug.cgi?id=104676
fdo#104058 https://bugs.freedesktop.org/show_bug.cgi?id=104058
fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
fdo#103481 https://bugs.freedesktop.org/show_bug.cgi?id=103481
fdo#103336 https://bugs.freedesktop.org/show_bug.cgi?id=103336
fdo#104312 https://bugs.freedesktop.org/show_bug.cgi?id=104312
fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614
fdo#102254 https://bugs.freedesktop.org/show_bug.cgi?id=102254
fdo#104151 https://bugs.freedesktop.org/show_bug.cgi?id=104151
fdo#100047 https://bugs.freedesktop.org/show_bug.cgi?id=100047

shard-apl        total:2838 pass:1747 dwarn:1   dfail:0   fail:26  skip:1064 time:12376s
shard-hsw        total:2838 pass:1732 dwarn:1   dfail:0   fail:13  skip:1091 time:11550s
shard-snb        total:2838 pass:1324 dwarn:3   dfail:0   fail:14  skip:1497 time:6552s

== Logs ==

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

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

* Re: [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2.
  2018-01-31 16:52       ` [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2 Maarten Lankhorst
@ 2018-02-01 14:23         ` Ville Syrjälä
  2018-02-01 14:43           ` Maarten Lankhorst
  0 siblings, 1 reply; 47+ messages in thread
From: Ville Syrjälä @ 2018-02-01 14:23 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

On Wed, Jan 31, 2018 at 05:52:00PM +0100, Maarten Lankhorst wrote:
> For NV12 a format conversion is needed. Because YUV formats are not
> fully defined with just a fourcc, I've chosen BT.601 limited range.
> This puts the pixel center of the CbCr components between the top
> left Y and bottom left Y:
> 
> Y   Y   Y   Y
> UV      UV
> Y   Y   Y   Y
> 
> Some work is put into optimising the conversion routines in order to
> make it fast enough. Before converting nv12 to rgb24, it is copied to
> a temporary buffer to take advantage of memory caching. This is
> approximately 20x faster than directly reading the BO.
> 
> When testing on my KBL with a 1080p buffer, it takes approximately
> .1s to convert either way, this is fast enough not to bother optimising
> even further for me.
> 
> Changes since v1:
> - Use BT.601 instead of BT.709 coefficients. (Ville)
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c | 391 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 319 insertions(+), 72 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 9d60280f198e..6f57ab69a822 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -70,6 +70,7 @@ static struct format_desc_struct {
>  	DF(XRGB8888,	RGB24,		32, 24),
>  	DF(XRGB2101010,	RGB30,		32, 30),
>  	DF(ARGB8888,	ARGB32,		32, 32),
> +	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),

This is getting pretty much unredable. Switching to named
initializers as a followup might seem prudent.

>  };
>  #undef DF
>  
> @@ -364,14 +365,20 @@ static int create_bo_for_fb(int fd, int width, int height,
>  			*is_dumb = false;
>  
>  		if (is_i915_device(fd)) {
> -			uint32_t *ptr;
> +			uint8_t *ptr;
>  
>  			bo = gem_create(fd, size);
>  			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
>  
>  			/* Ensure the framebuffer is preallocated */
> -			ptr = gem_mmap__gtt(fd, bo, size, PROT_READ);
> -			igt_assert(*ptr == 0);
> +			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);
> +			}
>  			gem_munmap(ptr, size);
>  
>  			if (size_ret)
> @@ -1127,103 +1134,117 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
>  		     drm_format, igt_format_str(drm_format));
>  }
>  
> +struct fb_blit_linear {
> +	uint32_t handle;
> +	unsigned size, stride;
> +	uint8_t *map;
> +	bool is_dumb;
> +	uint32_t offsets[4];
> +};
> +
>  struct fb_blit_upload {
>  	int fd;
>  	struct igt_fb *fb;
> -	struct {
> -		uint32_t handle;
> -		unsigned size, stride;
> -		uint8_t *map;
> -		bool is_dumb;
> -	} linear;
> +	struct fb_blit_linear linear;
>  };
>  
> -static void destroy_cairo_surface__blit(void *arg)
> +static void free_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
>  {
> -	struct fb_blit_upload *blit = arg;
> -	struct igt_fb *fb = blit->fb;
>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> +	int i;
>  
> -	gem_munmap(blit->linear.map, blit->linear.size);
> -	fb->cairo_surface = NULL;
> +	gem_munmap(linear->map, linear->size);
> +	gem_set_domain(fd, linear->handle,
> +		       I915_GEM_DOMAIN_GTT, 0);
> +
> +	for (i = 0; i < fb->num_planes; i++)
> +		igt_blitter_fast_copy__raw(fd,
> +					   linear->handle,
> +					   linear->offsets[i],
> +					   linear->stride,
> +					   I915_TILING_NONE,
> +					   0, 0, /* src_x, src_y */
> +					   fb->plane_width[i], fb->plane_height[i],
> +					   fb->plane_bpp[i],
> +					   fb->gem_handle,
> +					   fb->offsets[i],
> +					   fb->stride,
> +					   obj_tiling,
> +					   0, 0 /* dst_x, dst_y */);
> +
> +	gem_sync(fd, linear->handle);
> +	gem_close(fd, linear->handle);
> +}
>  
> -	gem_set_domain(blit->fd, blit->linear.handle,
> -			I915_GEM_DOMAIN_GTT, 0);
> +static void destroy_cairo_surface__blit(void *arg)
> +{
> +	struct fb_blit_upload *blit = arg;
>  
> -	igt_blitter_fast_copy__raw(blit->fd,
> -				   blit->linear.handle, 0,
> -				   blit->linear.stride,
> -				   I915_TILING_NONE,
> -				   0, 0, /* src_x, src_y */
> -				   fb->width, fb->height,
> -				   igt_drm_format_to_bpp(fb->drm_format),
> -				   fb->gem_handle,
> -				   fb->offsets[0],
> -				   fb->stride,
> -				   obj_tiling,
> -				   0, 0 /* dst_x, dst_y */);
> -
> -	gem_sync(blit->fd, blit->linear.handle);
> -	gem_close(blit->fd, blit->linear.handle);
> +	blit->fb->cairo_surface = NULL;
> +
> +	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
>  
>  	free(blit);
>  }
>  
> -static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> +static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
>  {
> -	struct fb_blit_upload *blit;
> -	cairo_format_t cairo_format;
>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
> -	uint32_t offsets[4];
> -
> -	blit = malloc(sizeof(*blit));
> -	igt_assert(blit);
> +	int i;
>  
>  	/*
>  	 * We create a linear BO that we'll map for the CPU to write to (using
>  	 * cairo). This linear bo will be then blitted to its final
>  	 * destination, tiling it at the same time.
>  	 */
> -	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
> +	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
>  					       lookup_drm_format(fb->drm_format),
>  					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
> -					       0, &blit->linear.size,
> -					       &blit->linear.stride,
> -					       offsets, &blit->linear.is_dumb);
> -
> -	igt_assert(blit->linear.handle > 0);
> +					       0, &linear->size,
> +					       &linear->stride,
> +					       linear->offsets, &linear->is_dumb);
>  
> -	blit->fd = fd;
> -	blit->fb = fb;
> +	igt_assert(linear->handle > 0);
>  
>  	/* Copy fb content to linear BO */
> -	gem_set_domain(fd, blit->linear.handle,
> +	gem_set_domain(fd, linear->handle,
>  			I915_GEM_DOMAIN_GTT, 0);
>  
> -	igt_blitter_fast_copy__raw(fd,
> -				   fb->gem_handle,
> -				   fb->offsets[0],
> -				   fb->stride,
> -				   obj_tiling,
> -				   0, 0, /* src_x, src_y */
> -				   fb->width, fb->height,
> -				   igt_drm_format_to_bpp(fb->drm_format),
> -				   blit->linear.handle, 0,
> -				   blit->linear.stride,
> -				   I915_TILING_NONE,
> -				   0, 0 /* dst_x, dst_y */);
> -
> -	gem_sync(fd, blit->linear.handle);
> -
> -	gem_set_domain(fd, blit->linear.handle,
> +	for (i = 0; i < fb->num_planes; i++)
> +		igt_blitter_fast_copy__raw(fd,
> +					  fb->gem_handle,
> +					  fb->offsets[i],
> +					  fb->stride,
> +					  obj_tiling,
> +					  0, 0, /* src_x, src_y */
> +					  fb->plane_width[i], fb->plane_height[i],
> +					  fb->plane_bpp[i],
> +					  linear->handle, linear->offsets[i],
> +					  linear->stride,
> +					  I915_TILING_NONE,
> +					  0, 0 /* dst_x, dst_y */);
> +
> +	gem_sync(fd, linear->handle);
> +
> +	gem_set_domain(fd, linear->handle,
>  		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
>  
>  	/* Setup cairo context */
> -	blit->linear.map = gem_mmap__cpu(fd,
> -					 blit->linear.handle,
> -					 0,
> -					 blit->linear.size,
> -					 PROT_READ | PROT_WRITE);
> +	linear->map = gem_mmap__cpu(fd, linear->handle,
> +				    0, linear->size, PROT_READ | PROT_WRITE);
> +}
> +
> +static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
> +{
> +	struct fb_blit_upload *blit;
> +	cairo_format_t cairo_format;
> +
> +	blit = malloc(sizeof(*blit));
> +	igt_assert(blit);
> +
> +	blit->fd = fd;
> +	blit->fb = fb;
> +	setup_linear_mapping(fd, fb, &blit->linear);
>  
>  	cairo_format = drm_format_to_cairo(fb->drm_format);
>  	fb->cairo_surface =
> @@ -1285,6 +1306,233 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
>  				    fb, destroy_cairo_surface__gtt);
>  }
>  
> +struct fb_convert_blit_upload {
> +	int fd;
> +	struct igt_fb *fb;
> +
> +	struct {
> +		uint8_t *map;
> +		unsigned stride, size;
> +	} rgb24;
> +
> +	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 void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
> +{
> +	int i, j;
> +	const uint8_t *y, *uv;
> +	uint8_t *rgb24 = blit->rgb24.map;
> +	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
> +	uint8_t *buf = malloc(blit->linear.size);
> +
> +	/*
> +	 * 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.
> +	 */
> +	memcpy(buf, blit->linear.map, blit->linear.size);
> +	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);
> +
> +			cb = uv[j & ~1] - 128.f;
> +			cr = uv[j | 1] - 128.f;
> +
> +			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(y0 + r_);
> +			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
> +
> +			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_);

Just replicating the same chroma for four pixels is pretty crude, but
since this is for testing I guess we don't really care. Given that I
guess we could even process in 2x2 blocks instead.

The coefficients looks correct enough to me.

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +		}
> +
> +		rgb24 += 2 * rgb24_stride;
> +		y += 2 * planar_stride;
> +		uv += planar_stride;
> +	}
> +
> +	if (fb->height & 1) {
> +		/* Convert last row */
> +		for (j = 0; j < fb->width; j++) {
> +			float r_, g_, b_, y0, cb, cr;
> +			/* Convert single pixel */
> +
> +			cb = uv[j & ~1] - 128.f;
> +			cr = uv[j | 1] - 128.f;
> +
> +			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;
> +
> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
> +			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
> +			rgb24[j * 4] = clamprgb(y0 + b_);
> +		}
> +	}
> +
> +	free(buf);
> +}
> +
> +static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
> +{
> +	int i, j;
> +	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
> +	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
> +	const uint8_t *rgb24 = blit->rgb24.map;
> +	unsigned rgb24_stride = blit->rgb24.stride;
> +	unsigned planar_stride = blit->linear.stride;
> +
> +	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;
> +
> +			y[j] = (uint8_t)yf;
> +		}
> +
> +		rgb24 += rgb24_stride;
> +		y += planar_stride;
> +	}
> +
> +	rgb24 = blit->rgb24.map;
> +
> +	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;
> +		}
> +
> +		rgb24 += 2 * rgb24_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;
> +		}
> +	}
> +}
> +
> +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);
> +
> +	munmap(blit->rgb24.map, blit->rgb24.size);
> +
> +	if (blit->linear.handle)
> +		free_linear_mapping(blit->fd, blit->fb, &blit->linear);
> +	else
> +		gem_munmap(blit->linear.map, fb->size);
> +
> +	free(blit);
> +
> +	fb->cairo_surface = NULL;
> +}
> +
> +static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
> +{
> +	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
> +	igt_assert(blit);
> +
> +	blit->fd = fd;
> +	blit->fb = fb;
> +	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
> +	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height, sysconf(_SC_PAGESIZE));
> +	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +	igt_assert(blit->rgb24.map != MAP_FAILED);
> +
> +	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> +	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
> +		setup_linear_mapping(fd, fb, &blit->linear);
> +	} else {
> +		blit->linear.handle = 0;
> +		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
> +					      PROT_READ | PROT_WRITE);
> +		igt_assert(blit->linear.map);
> +		blit->linear.stride = fb->stride;
> +		blit->linear.size = fb->size;
> +		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);
> +
> +	fb->cairo_surface =
> +		cairo_image_surface_create_for_data(blit->rgb24.map,
> +						    CAIRO_FORMAT_RGB24,
> +						    fb->width, fb->height,
> +						    blit->rgb24.stride);
> +
> +	cairo_surface_set_user_data(fb->cairo_surface,
> +				    (cairo_user_data_key_t *)create_cairo_surface__convert,
> +				    blit, destroy_cairo_surface__convert);
> +}
> +
>  /**
>   * igt_get_cairo_surface:
>   * @fd: open drm file descriptor
> @@ -1298,11 +1546,10 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
>   */
>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>  {
> -	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
> -	igt_assert(fb->num_planes < 2);
> -
>  	if (fb->cairo_surface == NULL) {
> -		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
> +		if (fb->num_planes > 1)
> +			create_cairo_surface__convert(fd, fb);
> +		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
>  		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
>  			create_cairo_surface__blit(fd, fb);
>  		else
> -- 
> 2.15.1
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

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

* Re: [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb
  2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb Maarten Lankhorst
  2018-01-26  9:00   ` Mika Kahola
@ 2018-02-01 14:39   ` Ville Syrjälä
  1 sibling, 0 replies; 47+ messages in thread
From: Ville Syrjälä @ 2018-02-01 14:39 UTC (permalink / raw)
  To: Maarten Lankhorst; +Cc: igt-dev

On Tue, Jan 23, 2018 at 01:56:37PM +0100, Maarten Lankhorst wrote:
> By adding support for planar formats to igt_calc_fb_size and create_bo_for_fb,
> we can calculate dimensions and create backing storage for planar framebuffers.
> 
> This is required for adding support to create planar framebuffers in the next patch.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  lib/igt_fb.c | 168 +++++++++++++++++++++++++++++++++++++++++++----------------
>  1 file changed, 123 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index da07d1a9e21f..6a331f06724b 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -54,14 +54,16 @@
>   */
>  
>  /* drm fourcc/cairo format maps */
> -#define DF(did, cid, _bpp, _depth)	\
> -	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
> +#define DF(did, cid, ...)	\
> +	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }

I don't think this macro is providing any benefit to us since it can't
even protect against did vs. cid typoes. IMO just kill it and switch to
named initializers.

>  static struct format_desc_struct {
>  	uint32_t drm_id;
>  	cairo_format_t cairo_id;
>  	const char *name;
>  	int bpp;
>  	int depth;
> +	int planes;
> +	int plane_bpp[4];
>  } format_desc[] = {
>  	DF(RGB565,	RGB16_565,	16, 16),
>  	//DF(RGB888,	INVALID,	24, 24),
> @@ -74,6 +76,20 @@ static struct format_desc_struct {
>  #define for_each_format(f)	\
>  	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
>  
> +static struct format_desc_struct *lookup_drm_format(uint32_t drm_format)

The function name feels a bit misleading. Makes me thing it returns a
drm fourcc.

> +{
> +	struct format_desc_struct *format;
> +
> +	for_each_format(format) {
> +		if (format->drm_id != drm_format)
> +			continue;

Or just 
if (a == b)
	return whatever;

Anyway apart from those things look pretty reasonable to me, so with the
misleading function name made better this is

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +
> +		return format;
> +	}
> +
> +	return NULL;
> +}
> +
>  /**
>   * igt_get_fb_tile_size:
>   * @fd: the DRM file descriptor
> @@ -142,27 +158,68 @@ void igt_get_fb_tile_size(int fd, uint64_t tiling, int fb_bpp,
>  	}
>  }
>  
> -/**
> - * igt_calc_fb_size:
> - * @fd: the DRM file descriptor
> - * @width: width of the framebuffer in pixels
> - * @height: height of the framebuffer in pixels
> - * @format: drm fourcc pixel format code
> - * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
> - * @size_ret: returned size for the framebuffer
> - * @stride_ret: returned stride for the framebuffer
> - *
> - * This function returns valid stride and size values for a framebuffer with the
> - * specified parameters.
> - */
> -void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t tiling,
> -		      unsigned *size_ret, unsigned *stride_ret)
> +static unsigned planar_stride(struct format_desc_struct *format, unsigned width, int plane)
> +{
> +	unsigned cpp = format->plane_bpp[plane] / 8;
> +
> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> +		return (width + 1) / 2 * cpp;
> +
> +	return width * cpp;
> +}
> +
> +static unsigned planar_height(struct format_desc_struct *format, unsigned height, int plane)
> +{
> +	if (format->drm_id == DRM_FORMAT_NV12 && plane == 1)
> +		return (height + 1) / 2;
> +
> +	return height;
> +}
> +
> +static void calc_fb_size_planar(int fd, int width, int height,
> +				struct format_desc_struct *format,
> +				uint64_t tiling, unsigned *size_ret,
> +				unsigned *stride_ret, unsigned *offsets)
> +{
> +	int plane;
> +	unsigned stride = 0, tile_width, tile_height;
> +
> +	*size_ret = 0;
> +
> +	for (plane = 0; plane < format->planes; plane++) {
> +		unsigned plane_stride;
> +
> +		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
> +
> +		plane_stride = ALIGN(planar_stride(format, width, plane), tile_width);
> +		if (stride < plane_stride)
> +			stride = plane_stride;
> +	}
> +
> +	for (plane = 0; plane < format->planes; plane++) {
> +		if (offsets)
> +			offsets[plane] = *size_ret;
> +
> +		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
> +
> +		*size_ret += stride * ALIGN(planar_height(format, height, plane), tile_height);
> +	}
> +
> +	if (offsets)
> +		for (; plane < 4; plane++)
> +			offsets[plane] = 0;
> +
> +	*stride_ret = stride;
> +}
> +
> +static void calc_fb_size_packed(int fd, int width, int height,
> +				struct format_desc_struct *format, uint64_t tiling,
> +				unsigned *size_ret, unsigned *stride_ret)
>  {
>  	unsigned int tile_width, tile_height, stride, size;
> -	int bpp = igt_drm_format_to_bpp(format);
> -	int byte_width = width * (bpp / 8);
> +	int byte_width = width * (format->bpp / 8);
>  
> -	igt_get_fb_tile_size(fd, tiling, bpp, &tile_width, &tile_height);
> +	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width, &tile_height);
>  
>  	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
>  	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
> @@ -176,7 +233,7 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t t
>  		 * tiled. But then that failure is expected.
>  		 */
>  
> -		v = width * bpp / 8;
> +		v = byte_width;
>  		for (stride = 512; stride < v; stride *= 2)
>  			;
>  
> @@ -192,6 +249,31 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t format, uint64_t t
>  	*size_ret = size;
>  }
>  
> +/**
> + * igt_calc_fb_size:
> + * @fd: the DRM file descriptor
> + * @width: width of the framebuffer in pixels
> + * @height: height of the framebuffer in pixels
> + * @format: drm fourcc pixel format code
> + * @tiling: tiling layout of the framebuffer (as framebuffer modifier)
> + * @size_ret: returned size for the framebuffer
> + * @stride_ret: returned stride for the framebuffer
> + *
> + * This function returns valid stride and size values for a framebuffer with the
> + * specified parameters.
> + */
> +void igt_calc_fb_size(int fd, int width, int height, uint32_t drm_format, uint64_t tiling,
> +		      unsigned *size_ret, unsigned *stride_ret)
> +{
> +	struct format_desc_struct *format = lookup_drm_format(drm_format);
> +	igt_assert(format);
> +
> +	if (format->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);
> +}
> +
>  /**
>   * igt_fb_mod_to_tiling:
>   * @modifier: DRM framebuffer modifier
> @@ -245,17 +327,20 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling)
>  }
>  
>  /* helpers to create nice-looking framebuffers */
> -static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
> +static int create_bo_for_fb(int fd, int width, int height,
> +			    struct format_desc_struct *format,
>  			    uint64_t tiling, unsigned size, unsigned stride,
>  			    unsigned *size_ret, unsigned *stride_ret,
>  			    bool *is_dumb)
>  {
>  	int bo;
>  
> -	if (tiling || size || stride) {
> +	igt_assert(format);
> +
> +	if (tiling || size || stride || format->planes > 1) {
>  		unsigned calculated_size, calculated_stride;
>  
> -		igt_calc_fb_size(fd, width, height, format, tiling,
> +		igt_calc_fb_size(fd, width, height, format->drm_id, tiling,
>  				 &calculated_size, &calculated_stride);
>  		if (stride == 0)
>  			stride = calculated_stride;
> @@ -290,12 +375,10 @@ static int create_bo_for_fb(int fd, int width, int height, uint32_t format,
>  			return -EINVAL;
>  		}
>  	} else {
> -		int bpp = igt_drm_format_to_bpp(format);
> -
>  		if (is_dumb)
>  			*is_dumb = true;
>  
> -		return kmstest_dumb_create(fd, width, height, bpp, stride_ret,
> +		return kmstest_dumb_create(fd, width, height, format->bpp, stride_ret,
>  					   size_ret);
>  	}
>  }
> @@ -323,8 +406,8 @@ 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, format, modifier, 0, stride,
> -			     size_ret, stride_ret, is_dumb);
> +	return create_bo_for_fb(fd, width, height, lookup_drm_format(format),
> +				modifier, 0, stride, size_ret, stride_ret, is_dumb);
>  }
>  
>  /**
> @@ -671,9 +754,10 @@ 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, format, tiling,
> -					  bo_size, bo_stride, &fb->size,
> -					  &fb->stride, &fb->is_dumb);
> +	fb->gem_handle = create_bo_for_fb(fd, width, height,
> +					  lookup_drm_format(format),
> +					  tiling, bo_size, bo_stride,
> +					  &fb->size, &fb->stride, &fb->is_dumb);
>  	igt_assert(fb->gem_handle > 0);
>  
>  	igt_debug("%s(handle=%d, pitch=%d)\n",
> @@ -1069,7 +1153,7 @@ static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
>  	 * destination, tiling it at the same time.
>  	 */
>  	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
> -					       fb->drm_format,
> +					       lookup_drm_format(fb->drm_format),
>  					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
>  					       0, &blit->linear.size,
>  					       &blit->linear.stride,
> @@ -1293,14 +1377,12 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth)
>   */
>  uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
>  {
> -	struct format_desc_struct *f;
> +	struct format_desc_struct *f = lookup_drm_format(drm_format);
>  
> -	for_each_format(f)
> -		if (f->drm_id == drm_format)
> -			return f->bpp;
> -
> -	igt_assert_f(0, "can't find a bpp format for %08x (%s)\n",
> +	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
>  		     drm_format, igt_format_str(drm_format));
> +
> +	return f->bpp;
>  }
>  
>  /**
> @@ -1313,13 +1395,9 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
>   */
>  const char *igt_format_str(uint32_t drm_format)
>  {
> -	struct format_desc_struct *f;
> -
> -	for_each_format(f)
> -		if (f->drm_id == drm_format)
> -			return f->name;
> +	struct format_desc_struct *f = lookup_drm_format(drm_format);
>  
> -	return "invalid";
> +	return f ? f->name : "invalid";
>  }
>  
>  /**
> -- 
> 2.15.1
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

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

* Re: [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2.
  2018-02-01 14:23         ` Ville Syrjälä
@ 2018-02-01 14:43           ` Maarten Lankhorst
  0 siblings, 0 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-02-01 14:43 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: igt-dev

Op 01-02-18 om 15:23 schreef Ville Syrjälä:
> On Wed, Jan 31, 2018 at 05:52:00PM +0100, Maarten Lankhorst wrote:
>> For NV12 a format conversion is needed. Because YUV formats are not
>> fully defined with just a fourcc, I've chosen BT.601 limited range.
>> This puts the pixel center of the CbCr components between the top
>> left Y and bottom left Y:
>>
>> Y   Y   Y   Y
>> UV      UV
>> Y   Y   Y   Y
>>
>> Some work is put into optimising the conversion routines in order to
>> make it fast enough. Before converting nv12 to rgb24, it is copied to
>> a temporary buffer to take advantage of memory caching. This is
>> approximately 20x faster than directly reading the BO.
>>
>> When testing on my KBL with a 1080p buffer, it takes approximately
>> .1s to convert either way, this is fast enough not to bother optimising
>> even further for me.
>>
>> Changes since v1:
>> - Use BT.601 instead of BT.709 coefficients. (Ville)
>>
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> ---
>>  lib/igt_fb.c | 391 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
>>  1 file changed, 319 insertions(+), 72 deletions(-)
>>
>> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
>> index 9d60280f198e..6f57ab69a822 100644
>> --- a/lib/igt_fb.c
>> +++ b/lib/igt_fb.c
>> @@ -70,6 +70,7 @@ static struct format_desc_struct {
>>  	DF(XRGB8888,	RGB24,		32, 24),
>>  	DF(XRGB2101010,	RGB30,		32, 30),
>>  	DF(ARGB8888,	ARGB32,		32, 32),
>> +	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
> This is getting pretty much unredable. Switching to named
> initializers as a followup might seem prudent.
>
>>  };
>>  #undef DF
>>  
>> @@ -364,14 +365,20 @@ static int create_bo_for_fb(int fd, int width, int height,
>>  			*is_dumb = false;
>>  
>>  		if (is_i915_device(fd)) {
>> -			uint32_t *ptr;
>> +			uint8_t *ptr;
>>  
>>  			bo = gem_create(fd, size);
>>  			gem_set_tiling(fd, bo, igt_fb_mod_to_tiling(tiling), stride);
>>  
>>  			/* Ensure the framebuffer is preallocated */
>> -			ptr = gem_mmap__gtt(fd, bo, size, PROT_READ);
>> -			igt_assert(*ptr == 0);
>> +			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);
>> +			}
>>  			gem_munmap(ptr, size);
>>  
>>  			if (size_ret)
>> @@ -1127,103 +1134,117 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
>>  		     drm_format, igt_format_str(drm_format));
>>  }
>>  
>> +struct fb_blit_linear {
>> +	uint32_t handle;
>> +	unsigned size, stride;
>> +	uint8_t *map;
>> +	bool is_dumb;
>> +	uint32_t offsets[4];
>> +};
>> +
>>  struct fb_blit_upload {
>>  	int fd;
>>  	struct igt_fb *fb;
>> -	struct {
>> -		uint32_t handle;
>> -		unsigned size, stride;
>> -		uint8_t *map;
>> -		bool is_dumb;
>> -	} linear;
>> +	struct fb_blit_linear linear;
>>  };
>>  
>> -static void destroy_cairo_surface__blit(void *arg)
>> +static void free_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
>>  {
>> -	struct fb_blit_upload *blit = arg;
>> -	struct igt_fb *fb = blit->fb;
>>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
>> +	int i;
>>  
>> -	gem_munmap(blit->linear.map, blit->linear.size);
>> -	fb->cairo_surface = NULL;
>> +	gem_munmap(linear->map, linear->size);
>> +	gem_set_domain(fd, linear->handle,
>> +		       I915_GEM_DOMAIN_GTT, 0);
>> +
>> +	for (i = 0; i < fb->num_planes; i++)
>> +		igt_blitter_fast_copy__raw(fd,
>> +					   linear->handle,
>> +					   linear->offsets[i],
>> +					   linear->stride,
>> +					   I915_TILING_NONE,
>> +					   0, 0, /* src_x, src_y */
>> +					   fb->plane_width[i], fb->plane_height[i],
>> +					   fb->plane_bpp[i],
>> +					   fb->gem_handle,
>> +					   fb->offsets[i],
>> +					   fb->stride,
>> +					   obj_tiling,
>> +					   0, 0 /* dst_x, dst_y */);
>> +
>> +	gem_sync(fd, linear->handle);
>> +	gem_close(fd, linear->handle);
>> +}
>>  
>> -	gem_set_domain(blit->fd, blit->linear.handle,
>> -			I915_GEM_DOMAIN_GTT, 0);
>> +static void destroy_cairo_surface__blit(void *arg)
>> +{
>> +	struct fb_blit_upload *blit = arg;
>>  
>> -	igt_blitter_fast_copy__raw(blit->fd,
>> -				   blit->linear.handle, 0,
>> -				   blit->linear.stride,
>> -				   I915_TILING_NONE,
>> -				   0, 0, /* src_x, src_y */
>> -				   fb->width, fb->height,
>> -				   igt_drm_format_to_bpp(fb->drm_format),
>> -				   fb->gem_handle,
>> -				   fb->offsets[0],
>> -				   fb->stride,
>> -				   obj_tiling,
>> -				   0, 0 /* dst_x, dst_y */);
>> -
>> -	gem_sync(blit->fd, blit->linear.handle);
>> -	gem_close(blit->fd, blit->linear.handle);
>> +	blit->fb->cairo_surface = NULL;
>> +
>> +	free_linear_mapping(blit->fd, blit->fb, &blit->linear);
>>  
>>  	free(blit);
>>  }
>>  
>> -static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
>> +static void setup_linear_mapping(int fd, struct igt_fb *fb, struct fb_blit_linear *linear)
>>  {
>> -	struct fb_blit_upload *blit;
>> -	cairo_format_t cairo_format;
>>  	unsigned int obj_tiling = igt_fb_mod_to_tiling(fb->tiling);
>> -	uint32_t offsets[4];
>> -
>> -	blit = malloc(sizeof(*blit));
>> -	igt_assert(blit);
>> +	int i;
>>  
>>  	/*
>>  	 * We create a linear BO that we'll map for the CPU to write to (using
>>  	 * cairo). This linear bo will be then blitted to its final
>>  	 * destination, tiling it at the same time.
>>  	 */
>> -	blit->linear.handle = create_bo_for_fb(fd, fb->width, fb->height,
>> +	linear->handle = create_bo_for_fb(fd, fb->width, fb->height,
>>  					       lookup_drm_format(fb->drm_format),
>>  					       LOCAL_DRM_FORMAT_MOD_NONE, 0,
>> -					       0, &blit->linear.size,
>> -					       &blit->linear.stride,
>> -					       offsets, &blit->linear.is_dumb);
>> -
>> -	igt_assert(blit->linear.handle > 0);
>> +					       0, &linear->size,
>> +					       &linear->stride,
>> +					       linear->offsets, &linear->is_dumb);
>>  
>> -	blit->fd = fd;
>> -	blit->fb = fb;
>> +	igt_assert(linear->handle > 0);
>>  
>>  	/* Copy fb content to linear BO */
>> -	gem_set_domain(fd, blit->linear.handle,
>> +	gem_set_domain(fd, linear->handle,
>>  			I915_GEM_DOMAIN_GTT, 0);
>>  
>> -	igt_blitter_fast_copy__raw(fd,
>> -				   fb->gem_handle,
>> -				   fb->offsets[0],
>> -				   fb->stride,
>> -				   obj_tiling,
>> -				   0, 0, /* src_x, src_y */
>> -				   fb->width, fb->height,
>> -				   igt_drm_format_to_bpp(fb->drm_format),
>> -				   blit->linear.handle, 0,
>> -				   blit->linear.stride,
>> -				   I915_TILING_NONE,
>> -				   0, 0 /* dst_x, dst_y */);
>> -
>> -	gem_sync(fd, blit->linear.handle);
>> -
>> -	gem_set_domain(fd, blit->linear.handle,
>> +	for (i = 0; i < fb->num_planes; i++)
>> +		igt_blitter_fast_copy__raw(fd,
>> +					  fb->gem_handle,
>> +					  fb->offsets[i],
>> +					  fb->stride,
>> +					  obj_tiling,
>> +					  0, 0, /* src_x, src_y */
>> +					  fb->plane_width[i], fb->plane_height[i],
>> +					  fb->plane_bpp[i],
>> +					  linear->handle, linear->offsets[i],
>> +					  linear->stride,
>> +					  I915_TILING_NONE,
>> +					  0, 0 /* dst_x, dst_y */);
>> +
>> +	gem_sync(fd, linear->handle);
>> +
>> +	gem_set_domain(fd, linear->handle,
>>  		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
>>  
>>  	/* Setup cairo context */
>> -	blit->linear.map = gem_mmap__cpu(fd,
>> -					 blit->linear.handle,
>> -					 0,
>> -					 blit->linear.size,
>> -					 PROT_READ | PROT_WRITE);
>> +	linear->map = gem_mmap__cpu(fd, linear->handle,
>> +				    0, linear->size, PROT_READ | PROT_WRITE);
>> +}
>> +
>> +static void create_cairo_surface__blit(int fd, struct igt_fb *fb)
>> +{
>> +	struct fb_blit_upload *blit;
>> +	cairo_format_t cairo_format;
>> +
>> +	blit = malloc(sizeof(*blit));
>> +	igt_assert(blit);
>> +
>> +	blit->fd = fd;
>> +	blit->fb = fb;
>> +	setup_linear_mapping(fd, fb, &blit->linear);
>>  
>>  	cairo_format = drm_format_to_cairo(fb->drm_format);
>>  	fb->cairo_surface =
>> @@ -1285,6 +1306,233 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
>>  				    fb, destroy_cairo_surface__gtt);
>>  }
>>  
>> +struct fb_convert_blit_upload {
>> +	int fd;
>> +	struct igt_fb *fb;
>> +
>> +	struct {
>> +		uint8_t *map;
>> +		unsigned stride, size;
>> +	} rgb24;
>> +
>> +	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 void convert_nv12_to_rgb24(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
>> +{
>> +	int i, j;
>> +	const uint8_t *y, *uv;
>> +	uint8_t *rgb24 = blit->rgb24.map;
>> +	unsigned rgb24_stride = blit->rgb24.stride, planar_stride = blit->linear.stride;
>> +	uint8_t *buf = malloc(blit->linear.size);
>> +
>> +	/*
>> +	 * 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.
>> +	 */
>> +	memcpy(buf, blit->linear.map, blit->linear.size);
>> +	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);
>> +
>> +			cb = uv[j & ~1] - 128.f;
>> +			cr = uv[j | 1] - 128.f;
>> +
>> +			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(y0 + r_);
>> +			rgb24[j * 4 + 2 + rgb24_stride] = clamprgb(y1 + r_);
>> +
>> +			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_);
> Just replicating the same chroma for four pixels is pretty crude, but
> since this is for testing I guess we don't really care. Given that I
> guess we could even process in 2x2 blocks instead.
>
> The coefficients looks correct enough to me.
>
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
>> +		}
>> +
>> +		rgb24 += 2 * rgb24_stride;
>> +		y += 2 * planar_stride;
>> +		uv += planar_stride;
>> +	}
>> +
>> +	if (fb->height & 1) {
>> +		/* Convert last row */
>> +		for (j = 0; j < fb->width; j++) {
>> +			float r_, g_, b_, y0, cb, cr;
>> +			/* Convert single pixel */
>> +
>> +			cb = uv[j & ~1] - 128.f;
>> +			cr = uv[j | 1] - 128.f;
>> +
>> +			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;
>> +
>> +			rgb24[j * 4 + 2] = clamprgb(y0 + r_);
>> +			rgb24[j * 4 + 1] = clamprgb(y0 + g_);
>> +			rgb24[j * 4] = clamprgb(y0 + b_);
>> +		}
>> +	}
>> +
>> +	free(buf);
>> +}
>> +
>> +static void convert_rgb24_to_nv12(struct igt_fb *fb, struct fb_convert_blit_upload *blit)
>> +{
>> +	int i, j;
>> +	uint8_t *y = &blit->linear.map[blit->linear.offsets[0]];
>> +	uint8_t *uv = &blit->linear.map[blit->linear.offsets[1]];
>> +	const uint8_t *rgb24 = blit->rgb24.map;
>> +	unsigned rgb24_stride = blit->rgb24.stride;
>> +	unsigned planar_stride = blit->linear.stride;
>> +
>> +	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;
>> +
>> +			y[j] = (uint8_t)yf;
>> +		}
>> +
>> +		rgb24 += rgb24_stride;
>> +		y += planar_stride;
>> +	}
>> +
>> +	rgb24 = blit->rgb24.map;
>> +
>> +	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;
>> +		}
>> +
>> +		rgb24 += 2 * rgb24_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;
>> +		}
>> +	}
>> +}
>> +
>> +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);
>> +
>> +	munmap(blit->rgb24.map, blit->rgb24.size);
>> +
>> +	if (blit->linear.handle)
>> +		free_linear_mapping(blit->fd, blit->fb, &blit->linear);
>> +	else
>> +		gem_munmap(blit->linear.map, fb->size);
>> +
>> +	free(blit);
>> +
>> +	fb->cairo_surface = NULL;
>> +}
>> +
>> +static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
>> +{
>> +	struct fb_convert_blit_upload *blit = malloc(sizeof(*blit));
>> +	igt_assert(blit);
>> +
>> +	blit->fd = fd;
>> +	blit->fb = fb;
>> +	blit->rgb24.stride = ALIGN(fb->width * 4, 16);
>> +	blit->rgb24.size = ALIGN(blit->rgb24.stride * fb->height, sysconf(_SC_PAGESIZE));
>> +	blit->rgb24.map = mmap(NULL, blit->rgb24.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>> +	igt_assert(blit->rgb24.map != MAP_FAILED);
>> +
>> +	if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
>> +	    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED) {
>> +		setup_linear_mapping(fd, fb, &blit->linear);
>> +	} else {
>> +		blit->linear.handle = 0;
>> +		blit->linear.map = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
>> +					      PROT_READ | PROT_WRITE);
>> +		igt_assert(blit->linear.map);
>> +		blit->linear.stride = fb->stride;
>> +		blit->linear.size = fb->size;
>> +		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);
>> +
>> +	fb->cairo_surface =
>> +		cairo_image_surface_create_for_data(blit->rgb24.map,
>> +						    CAIRO_FORMAT_RGB24,
>> +						    fb->width, fb->height,
>> +						    blit->rgb24.stride);
>> +
>> +	cairo_surface_set_user_data(fb->cairo_surface,
>> +				    (cairo_user_data_key_t *)create_cairo_surface__convert,
>> +				    blit, destroy_cairo_surface__convert);
>> +}
>> +
>>  /**
>>   * igt_get_cairo_surface:
>>   * @fd: open drm file descriptor
>> @@ -1298,11 +1546,10 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
>>   */
>>  cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>>  {
>> -	/* This doesn't work for planar formats for now, but we will convert them to RGB24 in the future. */
>> -	igt_assert(fb->num_planes < 2);
>> -
>>  	if (fb->cairo_surface == NULL) {
>> -		if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
>> +		if (fb->num_planes > 1)
>> +			create_cairo_surface__convert(fd, fb);
>> +		else if (fb->tiling == LOCAL_I915_FORMAT_MOD_Y_TILED ||
>>  		    fb->tiling == LOCAL_I915_FORMAT_MOD_Yf_TILED)
>>  			create_cairo_surface__blit(fd, fb);
>>  		else
>> -- 
>> 2.15.1
>>
>> _______________________________________________
>> igt-dev mailing list
>> igt-dev@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/igt-dev

Thanks, pushed!

~Maarten

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

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

* Re: [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb
  2018-01-26 13:56   ` Mika Kahola
@ 2018-02-28 15:40     ` Arkadiusz Hiler
  2018-02-28 15:43       ` Maarten Lankhorst
  2018-02-28 15:43       ` Arkadiusz Hiler
  0 siblings, 2 replies; 47+ messages in thread
From: Arkadiusz Hiler @ 2018-02-28 15:40 UTC (permalink / raw)
  To: Mika Kahola; +Cc: igt-dev

On Fri, Jan 26, 2018 at 03:56:03PM +0200, Mika Kahola wrote:
> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> > This is required to make the test pass when we start enabling
> > planar formats in the future.
> > 
> 
> Reviewed-by: Mika Kahola <mika.kahola@intel.com>

Seems like the whole series have been merged but this patch.
Any reason for it?
- Arek
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

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

* Re: [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb
  2018-02-28 15:40     ` Arkadiusz Hiler
@ 2018-02-28 15:43       ` Maarten Lankhorst
  2018-02-28 15:43       ` Arkadiusz Hiler
  1 sibling, 0 replies; 47+ messages in thread
From: Maarten Lankhorst @ 2018-02-28 15:43 UTC (permalink / raw)
  To: Arkadiusz Hiler, Mika Kahola; +Cc: igt-dev

Op 28-02-18 om 16:40 schreef Arkadiusz Hiler:
> On Fri, Jan 26, 2018 at 03:56:03PM +0200, Mika Kahola wrote:
>> On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
>>> This is required to make the test pass when we start enabling
>>> planar formats in the future.
>>>
>> Reviewed-by: Mika Kahola <mika.kahola@intel.com>
> Seems like the whole series have been merged but this patch.
> Any reason for it?
> - Arek

kms_render has been removed by another patch. :)

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

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

* Re: [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb
  2018-02-28 15:40     ` Arkadiusz Hiler
  2018-02-28 15:43       ` Maarten Lankhorst
@ 2018-02-28 15:43       ` Arkadiusz Hiler
  1 sibling, 0 replies; 47+ messages in thread
From: Arkadiusz Hiler @ 2018-02-28 15:43 UTC (permalink / raw)
  To: Mika Kahola; +Cc: igt-dev

On Wed, Feb 28, 2018 at 05:40:08PM +0200, Arkadiusz Hiler wrote:
> On Fri, Jan 26, 2018 at 03:56:03PM +0200, Mika Kahola wrote:
> > On Tue, 2018-01-23 at 13:56 +0100, Maarten Lankhorst wrote:
> > > This is required to make the test pass when we start enabling
> > > planar formats in the future.
> > > 
> > 
> > Reviewed-by: Mika Kahola <mika.kahola@intel.com>
> 
> Seems like the whole series have been merged but this patch.
> Any reason for it?
> - Arek

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

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

end of thread, other threads:[~2018-02-28 15:44 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-23 12:56 [igt-dev] [PATCH i-g-t 0/8] lib/igt_fb: Add support for the NV12 format Maarten Lankhorst
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx Maarten Lankhorst
2018-01-23 15:50   ` Ville Syrjälä
2018-01-24 12:26     ` Maarten Lankhorst
2018-01-25 11:43       ` Mika Kahola
2018-01-29 17:01         ` Maarten Lankhorst
2018-01-31 17:03   ` Ville Syrjälä
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 2/8] lib/igt_fb: Pass format to igt_calc_fb_size Maarten Lankhorst
2018-01-25 11:51   ` Mika Kahola
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 3/8] lib/fb: Handle planar formats in igt_calc_fb_size and create_bo_for_fb Maarten Lankhorst
2018-01-26  9:00   ` Mika Kahola
2018-01-26 10:20     ` Maarten Lankhorst
2018-01-26 10:24       ` Mika Kahola
2018-01-26 12:01         ` Maarten Lankhorst
2018-01-26 13:10           ` Mika Kahola
2018-02-01 14:39   ` Ville Syrjälä
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 4/8] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw Maarten Lankhorst
2018-01-26  9:02   ` Mika Kahola
2018-01-29 12:10   ` [igt-dev] [PATCH i-g-t] lib/intel_batchbuffer: Add delta argument to igt_blitter_fast_copy__raw, v2 Maarten Lankhorst
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 5/8] lib/intel_batchbuffer: Add src/dst delta arguments to igt_blitter_fast_copy too Maarten Lankhorst
2018-01-26  9:04   ` Mika Kahola
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add support for creating planar framebuffers Maarten Lankhorst
2018-01-23 14:50   ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v2 Maarten Lankhorst
2018-01-24 10:53     ` [igt-dev] [PATCH i-g-t] lib/fb: Add support for creating planar framebuffers, v3 Maarten Lankhorst
2018-01-29  8:44       ` Mika Kahola
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 7/8] tests/kms_render: Copy all planes when copying fb Maarten Lankhorst
2018-01-26 13:56   ` Mika Kahola
2018-02-28 15:40     ` Arkadiusz Hiler
2018-02-28 15:43       ` Maarten Lankhorst
2018-02-28 15:43       ` Arkadiusz Hiler
2018-01-23 12:56 ` [igt-dev] [PATCH i-g-t 8/8] lib/igt_fb: Add support for NV12 format through conversion Maarten Lankhorst
2018-01-31 13:45   ` Mika Kahola
2018-01-31 14:32     ` Ville Syrjälä
2018-01-31 15:09       ` Maarten Lankhorst
2018-01-31 16:52       ` [igt-dev] [PATCH i-g-t] lib/igt_fb: Add support for NV12 format through conversion, v2 Maarten Lankhorst
2018-02-01 14:23         ` Ville Syrjälä
2018-02-01 14:43           ` Maarten Lankhorst
2018-01-23 14:28 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
2018-01-23 15:41 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
2018-01-23 19:47 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format Patchwork
2018-01-23 22:30 ` [igt-dev] ✗ Fi.CI.IGT: failure for lib/igt_fb: Add support for the NV12 format. (rev2) Patchwork
2018-01-24 12:16 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev3) Patchwork
2018-01-24 15:57 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-01-29 12:37 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev4) Patchwork
2018-01-29 17:29 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-01-31 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Add support for the NV12 format. (rev5) Patchwork
2018-01-31 18:55 ` [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.