[Intel-gfx] [PATCH i-g-t 2/2] Adding kms_nv12 to test display NV12 feature

Chandra Konduru chandra.konduru at intel.com
Fri Sep 4 19:58:33 PDT 2015


From: chandra konduru <chandra.konduru at intel.com>

This patch adds kms_nv12 test case. It covers testing NV12
in linear/tile-X/tile-Y tiling formats in 0/90/180/270
orientations. For each tiling format, it tests several
combinations of planes and its scaling.

v2:
-Added 90/270 tests (me)
-took out crc test as it isn't adding much value due to chroma upsampling (me)

v3:
-Make --list-subtests option work (Tvrtko)
-Make nv12 unsupported test run properly either as a sub test
 or along with all other tests (me)
-Added nv12 fb with invalid params (Daniel)

v4:
-Avoid modeset for invalid tests (Daniel)

Signed-off-by: chandra konduru <chandra.konduru at intel.com>
---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_nv12.c       | 753 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 755 insertions(+)
 create mode 100644 tests/kms_nv12.c

diff --git a/tests/.gitignore b/tests/.gitignore
index d6d05ff..2de4712 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -155,6 +155,7 @@ kms_setmode
 kms_sink_crc_basic
 kms_universal_plane
 kms_vblank
+kms_nv12
 pm_backlight
 pm_lpsp
 pm_rc6_residency
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index ef69299..a7804fa 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -85,6 +85,7 @@ TESTS_progs_M = \
 	kms_crtc_background_color \
 	kms_plane_scaling \
 	kms_panel_fitting \
+	kms_nv12 \
 	pm_backlight \
 	pm_lpsp \
 	pm_rpm \
diff --git a/tests/kms_nv12.c b/tests/kms_nv12.c
new file mode 100644
index 0000000..61f826a
--- /dev/null
+++ b/tests/kms_nv12.c
@@ -0,0 +1,753 @@
+/*
+ * Copyright © 2013,2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include <math.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#include "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "igt_core.h"
+#include "intel_chipset.h"
+#include "ioctl_wrappers.h"
+
+IGT_TEST_DESCRIPTION("Test display NV12 support");
+
+uint32_t devid;
+typedef struct {
+	int drm_fd;
+	igt_display_t display;
+	int num_scalers;
+	int num_planes;
+
+	struct igt_fb fb1;
+	struct igt_fb fb1_nv12;
+	struct igt_fb fb2;
+	struct igt_fb fb2_nv12;
+	struct igt_fb fb3;
+	struct igt_fb fb3_nv12;
+	int fb_id1;
+	int fb_id1_nv12;
+	int fb_id2;
+	int fb_id2_nv12;
+	int fb_id3;
+	int fb_id3_nv12;
+
+	igt_plane_t *plane1;
+	igt_plane_t *plane2;
+	igt_plane_t *plane3;
+
+	uint64_t tiled;
+	int rotation;
+} data_t;
+
+typedef struct {
+	int width;
+	int height;
+} res_t;
+
+#define IMG_FILE  "1080p-left.png"
+
+static void
+paint_pattern(data_t *d, struct igt_fb *fb, uint16_t w, uint16_t h)
+{
+	cairo_t *cr;
+
+	cr = igt_get_cairo_ctx(d->drm_fd, fb);
+	igt_paint_test_pattern(cr, w, h);
+	cairo_destroy(cr);
+}
+
+static void
+paint_image(data_t *d, struct igt_fb *fb, uint16_t w, uint16_t h)
+{
+	cairo_t *cr;
+
+	cr = igt_get_cairo_ctx(d->drm_fd, fb);
+	igt_paint_image(cr, IMG_FILE, 0, 0, w, h);
+	cairo_destroy(cr);
+}
+
+static void prepare_crtc(data_t *data, igt_output_t *output, enum pipe pipe,
+			igt_plane_t *plane, drmModeModeInfo *mode, enum igt_commit_style s)
+{
+	igt_display_t *display = &data->display;
+
+	igt_output_set_pipe(output, pipe);
+
+	/* before allocating, free if any older fb */
+	if (data->fb_id1) {
+		igt_remove_fb(data->drm_fd, &data->fb1);
+		data->fb_id1 = 0;
+	}
+
+	/* allocate fb for plane 1 */
+	data->fb_id1 = igt_create_fb(data->drm_fd,
+			mode->hdisplay, mode->vdisplay,
+			DRM_FORMAT_XRGB8888,
+			data->tiled, /* tiled */
+			&data->fb1);
+	igt_assert(data->fb_id1);
+
+	paint_pattern(data, &data->fb1, mode->hdisplay, mode->vdisplay);
+
+	/*
+	 * We always set the primary plane to actually enable the pipe as
+	 * there's no way (that works) to light up a pipe with only a sprite
+	 * plane enabled at the moment.
+	 */
+	if (!plane->is_primary) {
+		igt_plane_t *primary;
+
+		primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		igt_plane_set_fb(primary, &data->fb1);
+	}
+
+	igt_plane_set_fb(plane, &data->fb1);
+	if (s == COMMIT_LEGACY) {
+		int ret;
+		ret = drmModeSetCrtc(data->drm_fd,
+				output->config.crtc->crtc_id,
+				data->fb_id1,
+				plane->pan_x, plane->pan_y,
+				&output->id,
+				1,
+				mode);
+		igt_assert(ret == 0);
+	} else {
+		igt_display_commit2(display, s);
+	}
+}
+
+static void cleanup_crtc(data_t *data, igt_output_t *output, igt_plane_t *plane)
+{
+	igt_display_t *display = &data->display;
+
+	if (data->fb_id1) {
+		igt_remove_fb(data->drm_fd, &data->fb1);
+		data->fb_id1 = 0;
+	}
+	if (data->fb_id2) {
+		igt_remove_fb(data->drm_fd, &data->fb2);
+		data->fb_id2 = 0;
+	}
+	if (data->fb_id3) {
+		igt_remove_fb(data->drm_fd, &data->fb3);
+		data->fb_id3 = 0;
+	}
+
+	if (data->fb_id1_nv12) {
+		igt_remove_fb(data->drm_fd, &data->fb1_nv12);
+		data->fb_id1_nv12 = 0;
+	}
+
+	if (data->fb_id2_nv12) {
+		igt_remove_fb(data->drm_fd, &data->fb2_nv12);
+		data->fb_id2_nv12 = 0;
+	}
+
+	if (data->fb_id3_nv12) {
+		igt_remove_fb(data->drm_fd, &data->fb3_nv12);
+		data->fb_id3_nv12 = 0;
+	}
+
+	if (!plane->is_primary) {
+		igt_plane_t *primary;
+
+		primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		igt_plane_set_fb(primary, NULL);
+	}
+
+	igt_plane_set_fb(plane, NULL);
+	igt_output_set_pipe(output, PIPE_ANY);
+
+	igt_display_commit2(display, COMMIT_UNIVERSAL);
+}
+
+static void test_nv12_plane(data_t *d)
+{
+	igt_display_t *display = &d->display;
+	igt_output_t *output;
+	enum pipe pipe;
+	int valid_tests = 0;
+	int img_width;
+	int img_height;
+
+	igt_require(d->display.has_universal_planes);
+	igt_require(d->num_scalers);
+
+	for_each_connected_output(display, output) {
+		drmModeModeInfo *mode;
+		mode = igt_output_get_mode(output);
+		pipe = output->config.pipe;
+
+		igt_output_set_pipe(output, pipe);
+
+		/* get planes */
+		d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		d->plane2 = igt_output_get_plane(output, IGT_PLANE_2);
+		if (d->num_planes >= 3)
+			d->plane3 = igt_output_get_plane(output, IGT_PLANE_3);
+
+		/* set required rotation */
+		igt_plane_set_rotation(d->plane1, d->rotation);
+		igt_plane_set_rotation(d->plane2, d->rotation);
+		if (d->num_planes >= 3)
+			igt_plane_set_rotation(d->plane3, d->rotation);
+
+		/* Set up display with plane 1 */
+		prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
+
+		/* allocate fb2, fb2_nv12, fb1_nv12 with image size */
+		igt_get_image_size(IMG_FILE, &img_width, &img_height);
+
+		/* fb2 is in RGB format */
+		d->fb_id2 = igt_create_fb(d->drm_fd,
+				img_width, img_height,
+				DRM_FORMAT_XRGB8888,
+				d->tiled, /* tiled */
+				&d->fb2);
+		igt_assert(d->fb_id2);
+
+		/* fb1_nv12 is in NV12 format */
+		d->fb_id1_nv12 = igt_create_fb(d->drm_fd,
+				img_width, img_height,
+				DRM_FORMAT_NV12,
+				d->tiled, /* tiled */
+				&d->fb1_nv12);
+		igt_assert(d->fb_id1_nv12);
+
+		/* fb2_nv12 is in NV12 format */
+		d->fb_id2_nv12 = igt_create_fb(d->drm_fd,
+				img_width, img_height,
+				DRM_FORMAT_NV12,
+				d->tiled,
+				&d->fb2_nv12);
+		igt_assert(d->fb_id2_nv12);
+
+		/* fb3 is in RGB */
+		d->fb_id3 = igt_create_fb(d->drm_fd,
+				mode->hdisplay, mode->vdisplay,
+				DRM_FORMAT_ARGB8888,
+				d->tiled, /* tiled */
+				&d->fb3);
+		igt_assert(d->fb_id3);
+
+		/*
+		 * Mimicing some not exactly but closer to some real usage
+		 */
+
+		/* set up data for fb2: both fb1_nv12, fb2_nv12 uses this */
+		paint_image(d, &d->fb2, img_width, img_height);
+
+		/* set up data in fb1_nv12: fb2 RGB-> fb1_nv12 */
+		igt_fb_csc_xrgb_to_nv12(d->drm_fd, &d->fb1_nv12, &d->fb2);
+
+		/* set up data in fb2_nv12: fb2 RGB-> fb2_nv12 */
+		igt_fb_csc_xrgb_to_nv12(d->drm_fd, &d->fb2_nv12, &d->fb2);
+
+		/* set up data in fb3 */
+		paint_pattern(d, &d->fb3, d->fb3.width, d->fb3.height);
+
+		/* Set up fb2_nv12->plane2 mapping. */
+		igt_plane_set_fb(d->plane2, &d->fb2_nv12);
+		/* 2nd plane nv12 windowed - no scaling */
+		igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+		igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+			d->fb2_nv12.height);
+		igt_plane_set_position(d->plane2, 0, 0);
+		igt_plane_set_size(d->plane2, d->fb2_nv12.width, d->fb2_nv12.height);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		/* Change primary plane to nv12 full screen: scaling + NV12 */
+		igt_plane_set_fb(d->plane1, &d->fb1_nv12);
+		igt_fb_set_position(&d->fb1_nv12, d->plane1, 0, 0);
+		igt_fb_set_size(&d->fb1_nv12, d->plane1, d->fb1_nv12.width,
+			d->fb1_nv12.height);
+		igt_plane_set_position(d->plane1, 0, 0);
+		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		if (d->num_planes >= 3) {
+			/* Set up fb3->plane3 mapping. */
+			igt_plane_set_fb(d->plane3, &d->fb3);
+
+			/* 3rd plane full screen - no scaling. */
+			igt_fb_set_position(&d->fb3, d->plane3, 0, 0);
+			igt_fb_set_size(&d->fb3, d->plane3, d->fb3.width, d->fb3.height);
+			igt_plane_set_position(d->plane3, 0, 0);
+			igt_plane_set_size(d->plane3, d->fb3.width, d->fb3.height);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+		}
+
+		/* 2nd plane nv12 up scaling */
+		igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+		igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+			d->fb2_nv12.height);
+		igt_plane_set_position(d->plane2, 100, 100);
+		igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		/* 2nd plane nv12 down scaling */
+		igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+		igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+			d->fb2_nv12.height);
+		igt_plane_set_position(d->plane2, 1024, 0);
+		igt_plane_set_size(d->plane2, d->fb2_nv12.width * 2/3,
+			d->fb2_nv12.height * 2/3);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		/* Back to single plane mode  - rgb & no scaling */
+		igt_plane_set_fb(d->plane1, &d->fb1);
+		igt_plane_set_fb(d->plane2, NULL);
+		if (d->num_planes >= 3)
+			igt_plane_set_fb(d->plane3, NULL);
+		igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
+		igt_fb_set_size(&d->fb1, d->plane1, mode->hdisplay, mode->vdisplay);
+		igt_plane_set_position(d->plane1, 0, 0);
+		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		/* single plane mode  - rgb & scaling */
+		igt_plane_set_rotation(d->plane1, IGT_ROTATION_0);
+		igt_plane_set_fb(d->plane1, &d->fb1);
+		igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
+		igt_fb_set_size(&d->fb1, d->plane1, d->fb1.width/2, d->fb1.height/2);
+		igt_plane_set_position(d->plane1, 0, 0);
+		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		/* single plane mode  - nv12 & scaling */
+		igt_plane_set_fb(d->plane1, &d->fb1_nv12);
+		igt_fb_set_position(&d->fb1_nv12, d->plane1, 0, 0);
+		igt_fb_set_size(&d->fb1_nv12, d->plane1, d->fb1_nv12.width,
+			d->fb1_nv12.height);
+		igt_plane_set_position(d->plane1, 0, 0);
+		igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+		igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+		valid_tests++;
+
+		cleanup_crtc(d, output, d->plane1);
+	}
+	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+}
+
+static void test_nv12_plane_rotation_90_or_270(data_t *d)
+{
+	igt_display_t *display = &d->display;
+	igt_output_t *output;
+	enum pipe pipe;
+	int valid_tests = 0;
+	int i;
+
+	/*
+	 * There are two key scenarios:
+	 * 1) Flip landscape buffer onto portrait display
+	 * 2) Flip portrait buffer onto landscape display
+	 *
+	 * Due to availability of landscape display, going with #2.
+	 */
+	res_t nv12_res_list[] = {
+		{480, 720},
+		{720, 1280},
+		{1080, 1920},
+	};
+
+	igt_require(d->display.has_universal_planes);
+	igt_require(d->num_scalers);
+
+	for_each_connected_output(display, output) {
+		drmModeModeInfo *mode;
+		mode = igt_output_get_mode(output);
+		pipe = output->config.pipe;
+
+		igt_output_set_pipe(output, pipe);
+
+		/* get planes */
+		d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		d->plane2 = igt_output_get_plane(output, IGT_PLANE_2);
+
+		for (i = 0; i < sizeof(nv12_res_list)/sizeof(res_t); i++) {
+			/* Set up display with plane 1 */
+			igt_plane_set_rotation(d->plane1, IGT_ROTATION_0);
+			prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
+
+			/* fb2 is in RGB format */
+			d->fb_id2 = igt_create_fb(d->drm_fd,
+					nv12_res_list[i].width, nv12_res_list[i].height,
+					DRM_FORMAT_XRGB8888,
+					d->tiled,
+					&d->fb2);
+			igt_assert(d->fb_id2);
+
+			/* Change primary plane to fb2 RGB with rotation */
+			igt_plane_set_rotation(d->plane1, d->rotation);
+
+			igt_plane_set_fb(d->plane1, &d->fb2);
+			igt_fb_set_position(&d->fb2, d->plane1, 0, 0);
+			igt_fb_set_size(&d->fb2, d->plane1, d->fb2.width, d->fb2.height);
+			igt_plane_set_position(d->plane1, 0, 0);
+			igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* fb1_nv12 is in NV12 format */
+			d->fb_id1_nv12 = igt_create_fb(d->drm_fd,
+					nv12_res_list[i].width, nv12_res_list[i].height,
+					DRM_FORMAT_NV12,
+					d->tiled,
+					&d->fb1_nv12);
+			igt_assert(d->fb_id1_nv12);
+
+			/* fb2_nv12 is in NV12 format */
+			d->fb_id2_nv12 = igt_create_fb(d->drm_fd,
+					nv12_res_list[i].width, nv12_res_list[i].height,
+					DRM_FORMAT_NV12,
+					d->tiled,
+					&d->fb2_nv12);
+			igt_assert(d->fb_id2_nv12);
+
+			/* set up data in fb1_nv12: fb2 PATTERN RGB-> fb1_nv12 */
+			paint_pattern(d, &d->fb2, d->fb2.width, d->fb2.height);
+			igt_fb_csc_xrgb_to_nv12(d->drm_fd, &d->fb1_nv12, &d->fb2);
+
+			/* set up data in fb2_nv12: fb2 PATTERN RGB-> fb2_nv12 */
+			paint_pattern(d, &d->fb2, d->fb2.width, d->fb2.height);
+			igt_fb_csc_xrgb_to_nv12(d->drm_fd, &d->fb2_nv12, &d->fb2);
+
+			/* set required rotation */
+			igt_plane_set_rotation(d->plane1, d->rotation);
+			igt_plane_set_rotation(d->plane2, d->rotation);
+
+			/* Change primary plane to nv12 full screen: scaling + NV12 */
+			igt_plane_set_fb(d->plane1, &d->fb1_nv12);
+			igt_fb_set_position(&d->fb1_nv12, d->plane1, 0, 0);
+			igt_fb_set_size(&d->fb1_nv12, d->plane1, d->fb1_nv12.width,
+				d->fb1_nv12.height);
+			igt_plane_set_position(d->plane1, 0, 0);
+			igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* 2nd plane nv12 windowed */
+			igt_plane_set_fb(d->plane2, &d->fb2_nv12);
+			igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+			igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+				d->fb2_nv12.height);
+			igt_plane_set_position(d->plane2, 0, 0);
+			igt_plane_set_size(d->plane2, d->fb2_nv12.height,d->fb2_nv12.width);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* 2nd plane nv12 up scaling */
+			igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+			igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+				d->fb2_nv12.height);
+			igt_plane_set_position(d->plane2, 100, 100);
+			igt_plane_set_size(d->plane2, mode->hdisplay-200, mode->vdisplay-200);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* 2nd plane nv12 down scaling */
+			igt_fb_set_position(&d->fb2_nv12, d->plane2, 0, 0);
+			igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width,
+				d->fb2_nv12.height);
+			igt_plane_set_position(d->plane2, 100, 100);
+			igt_plane_set_size(d->plane2, d->fb2_nv12.height * 2/3,
+				d->fb2_nv12.width * 2/3);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* 2nd plane nv12 down scaling - pan into FB */
+			igt_fb_set_position(&d->fb2_nv12, d->plane2, 100, 100);
+			igt_fb_set_size(&d->fb2_nv12, d->plane2, d->fb2_nv12.width-100,
+				d->fb2_nv12.height-100);
+			igt_plane_set_position(d->plane2, 100, 100);
+			igt_plane_set_size(d->plane2, (d->fb2_nv12.height-100) * 2/3,
+				(d->fb2_nv12.width-100) * 2/3);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			/* Back to single plane mode  - rgb & no scaling */
+			igt_plane_set_rotation(d->plane1, IGT_ROTATION_0);
+			igt_plane_set_fb(d->plane1, &d->fb1);
+			igt_plane_set_fb(d->plane2, NULL);
+			igt_fb_set_position(&d->fb1, d->plane1, 0, 0);
+			igt_fb_set_size(&d->fb1, d->plane1, mode->hdisplay, mode->vdisplay);
+			igt_plane_set_position(d->plane1, 0, 0);
+			igt_plane_set_size(d->plane1, mode->hdisplay, mode->vdisplay);
+			igt_display_commit2(display, COMMIT_UNIVERSAL);
+
+			igt_remove_fb(d->drm_fd, &d->fb2);
+			igt_remove_fb(d->drm_fd, &d->fb2_nv12);
+			igt_remove_fb(d->drm_fd, &d->fb1_nv12);
+			d->fb_id2 = 0;
+			d->fb_id2_nv12 = 0;
+			d->fb_id1_nv12 = 0;
+		}
+
+		valid_tests++;
+
+		cleanup_crtc(d, output, d->plane1);
+	}
+	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+}
+
+static void test_nv12_unsupported_plane(data_t *d)
+{
+	igt_display_t *display = &d->display;
+	igt_output_t *output;
+	enum pipe pipe;
+	int valid_tests = 0;
+
+	igt_require(d->display.has_universal_planes);
+	igt_require(d->num_scalers);
+	igt_require(d->num_planes >= 3);
+
+	for_each_connected_output(display, output) {
+		drmModeModeInfo *mode;
+		mode = igt_output_get_mode(output);
+		pipe = output->config.pipe;
+
+		igt_output_set_pipe(output, pipe);
+
+		d->fb_id3_nv12 = igt_create_fb(d->drm_fd,
+				1920, 1080,
+				DRM_FORMAT_NV12,
+				d->tiled,
+				&d->fb3_nv12);
+		igt_assert(d->fb_id3_nv12);
+
+		/* Set up fb3_nv12->plane3 mapping. */
+		d->plane3 = igt_output_get_plane(output, IGT_PLANE_3);
+		igt_plane_set_fb(d->plane3, &d->fb3_nv12);
+
+		/* 3rd plane nv12 windowed - no scaling */
+		igt_fb_set_position(&d->fb3_nv12, d->plane3, 0, 0);
+		igt_fb_set_size(&d->fb3_nv12, d->plane3, d->fb3_nv12.width,
+			d->fb3_nv12.height);
+		igt_plane_set_position(d->plane3, 0, 0);
+		igt_plane_set_size(d->plane3, d->fb3_nv12.width, d->fb3_nv12.height);
+
+		/* Should fail because NV12 is not supported on plane 3 */
+		igt_assert(igt_display_try_commit2(display, COMMIT_UNIVERSAL)
+			== -EINVAL);
+
+		valid_tests++;
+
+		igt_plane_set_fb(d->plane3, NULL);
+		cleanup_crtc(d, output, d->plane1);
+	}
+	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+}
+
+static void test_nv12_invalid_fb_params(data_t *d)
+{
+	igt_display_t *display = &d->display;
+	igt_output_t *output;
+	enum pipe pipe;
+	int valid_tests = 0;
+
+	igt_require(d->display.has_universal_planes);
+	igt_require(d->num_scalers);
+
+	for_each_connected_output(display, output) {
+		struct local_drm_mode_fb_cmd2 f;
+		int fd = d->drm_fd;
+		drmModeModeInfo *mode;
+
+		mode = igt_output_get_mode(output);
+		pipe = output->config.pipe;
+
+		igt_output_set_pipe(output, pipe);
+
+		/* Set up display with plane 1 */
+		d->plane1 = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		igt_plane_set_rotation(d->plane1, IGT_ROTATION_0);
+
+		/* use igt helper to create bo and addfb tile-Yf, this should pass */
+		d->fb_id1_nv12 = igt_create_fb(d->drm_fd,
+				1920, 1080,
+				DRM_FORMAT_NV12,
+				LOCAL_I915_FORMAT_MOD_Yf_TILED,
+				&d->fb1_nv12);
+		igt_assert(d->fb_id1_nv12);
+
+		/* now remove fb but keep bo to redo addfb */
+		drmModeRmFB(d->drm_fd, d->fb_id1_nv12);
+
+		/* redo AddFB */
+		memset(&f, 0, sizeof(f));
+
+		f.width = d->fb1_nv12.width;
+		f.height = d->fb1_nv12.height;
+		f.pixel_format = d->fb1_nv12.drm_format;
+		f.flags = LOCAL_DRM_MODE_FB_MODIFIERS;
+		f.handles[0] = d->fb1_nv12.gem_handle;
+		f.pitches[0] = d->fb1_nv12.stride;
+		f.modifier[0] = LOCAL_I915_FORMAT_MOD_Yf_TILED;
+		f.modifier[1] = LOCAL_I915_FORMAT_MOD_Yf_TILED;
+
+		/* test invalid uv start */
+		f.handles[1] = d->fb1_nv12.gem_handle;
+		f.pitches[1] = d->fb1_nv12.stride;
+		f.offsets[1] = 0;  /* invalid uv start */
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) != 0);
+
+		/* test uv pitch != y pitch */
+		f.handles[1] = d->fb1_nv12.gem_handle;
+		f.pitches[1] = d->fb1_nv12.stride + 1; /* invalid pitch */
+		f.offsets[1] = d->fb1_nv12.uv_offset;
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) != 0);
+
+		/* test uv gem handle != y gem handle */
+		f.handles[1] = 0xFFFFFFFF;   /* invalid gem handle */
+		f.pitches[1] = d->fb1_nv12.stride;
+		f.offsets[1] = d->fb1_nv12.uv_offset;
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) != 0);
+
+		/* test uv offset not aligned to new tile-row */
+		f.handles[1] = d->fb1_nv12.gem_handle;
+		f.pitches[1] = d->fb1_nv12.stride;
+		f.offsets[1] = d->fb1_nv12.uv_offset + 0xFF;  /* not tile-row aligned */
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) != 0);
+
+		/* valid params */
+		f.handles[1] = d->fb1_nv12.gem_handle;
+		f.pitches[1] = d->fb1_nv12.stride;
+		f.offsets[1] = d->fb1_nv12.uv_offset;
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) == 0);
+
+		/* Free fb */
+		igt_remove_fb(d->drm_fd, &d->fb1_nv12);
+		d->fb_id1_nv12 = 0;
+
+		/* recreate bo and addfb in tile-Y, this should pass */
+		d->fb_id1_nv12 = igt_create_fb(d->drm_fd,
+				1920, 1080,
+				DRM_FORMAT_NV12,
+				LOCAL_I915_FORMAT_MOD_Y_TILED,
+				&d->fb1_nv12);
+		igt_assert(d->fb_id1_nv12);
+
+		/* now remove fb but keep bo to redo addfb */
+		drmModeRmFB(d->drm_fd, d->fb_id1_nv12);
+
+		/* redo AddFB */
+		memset(&f, 0, sizeof(f));
+
+		f.width = d->fb1_nv12.width;
+		f.height = d->fb1_nv12.height;
+		f.pixel_format = d->fb1_nv12.drm_format;
+		f.flags = LOCAL_DRM_MODE_FB_MODIFIERS;
+		f.handles[0] = d->fb1_nv12.gem_handle;
+		f.pitches[0] = d->fb1_nv12.stride;
+		f.modifier[0] = LOCAL_I915_FORMAT_MOD_Y_TILED;
+		f.handles[1] = d->fb1_nv12.gem_handle;
+		f.pitches[1] = d->fb1_nv12.stride;
+		f.modifier[1] = LOCAL_I915_FORMAT_MOD_Y_TILED;
+
+		/* test uv offset not 4-line aligned */
+		f.offsets[1] = d->fb1_nv12.uv_offset + f.pitches[1]; /* not 4-ln align*/
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) != 0);
+
+		/* valid params */
+		f.offsets[1] = d->fb1_nv12.uv_offset;
+		igt_assert(drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f) == 0);
+
+		valid_tests++;
+
+		cleanup_crtc(d, output, d->plane1);
+	}
+	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+}
+
+igt_main
+{
+	data_t data = {};
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		data.drm_fd = drm_open_any();
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_display_init(&data.display, data.drm_fd);
+
+		devid = intel_get_drm_devid(data.drm_fd);
+		data.num_scalers = intel_gen(devid) >= 9 ? 2 : 0;
+		data.num_planes = 2;
+		igt_assert(intel_gen(devid) >= 9);
+	}
+
+	data.rotation = IGT_ROTATION_0;
+	igt_subtest_f("nv12-plane-linear") {
+		data.tiled = LOCAL_DRM_FORMAT_MOD_NONE;
+		test_nv12_plane(&data);
+	}
+	igt_subtest_f("nv12-plane-tile-x") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_X_TILED;
+		test_nv12_plane(&data);
+	}
+	igt_subtest_f("nv12-plane-tile-y") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Y_TILED;
+		test_nv12_plane(&data);
+	}
+
+	data.rotation = IGT_ROTATION_180;
+	igt_subtest_f("nv12-plane-linear-rot-180") {
+		data.tiled = LOCAL_DRM_FORMAT_MOD_NONE;
+		test_nv12_plane(&data);
+	}
+	igt_subtest_f("nv12-plane-tile-x-rot-180") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_X_TILED;
+		test_nv12_plane(&data);
+	}
+	igt_subtest_f("nv12-plane-tile-y-rot-180") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Y_TILED;
+		test_nv12_plane(&data);
+	}
+
+	data.rotation = IGT_ROTATION_90;
+	igt_subtest_f("nv12-plane-tile-y-rot-90") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Y_TILED;
+		test_nv12_plane_rotation_90_or_270(&data);
+	}
+
+	data.rotation = IGT_ROTATION_270;
+	igt_subtest_f("nv12-plane-tile-y-rot-270") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Y_TILED;
+		test_nv12_plane_rotation_90_or_270(&data);
+	}
+
+	igt_subtest_f("nv12-on-unsupported-plane") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_TILED;
+		test_nv12_unsupported_plane(&data);
+	}
+
+	igt_subtest_f("nv12-invalid-fb-params") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_TILED;
+		test_nv12_invalid_fb_params(&data);
+	}
+
+	igt_fixture {
+		igt_display_fini(&data.display);
+	}
+}
-- 
1.9.1



More information about the Intel-gfx mailing list