diff mbox

i-g-t: Adding display NV12 testcase

Message ID 1431145969-921-1-git-send-email-chandra.konduru@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chandra Konduru May 9, 2015, 4:32 a.m. UTC
From: chandra konduru <chandra.konduru@intel.com>

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

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

Signed-off-by: chandra konduru <chandra.konduru@intel.com>
---
 tests/.gitignore       |   1 +
 tests/Android.mk       |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_nv12.c       | 619 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 622 insertions(+)
 create mode 100644 tests/kms_nv12.c

Comments

Tvrtko Ursulin May 11, 2015, 12:12 p.m. UTC | #1
Hi,

On 05/09/2015 05:32 AM, Chandra Konduru wrote:
> From: chandra konduru <chandra.konduru@intel.com>
>
> This patch adds kms_nv12 test case. It covers testing NV12 in
> all supported linear/tile-X/tile-Y/tile-Yf tile formats in
> 0 and 180 orientations. For each tiling format, it tests
> various combinations of planes and scaling.
>
> v2:
> -Added 90/270 tests (me)
> -took out crc test as it isn't adding much value due to chroma upsampling (me)
>
> Signed-off-by: chandra konduru <chandra.konduru@intel.com>
> ---
>   tests/.gitignore       |   1 +
>   tests/Android.mk       |   1 +
>   tests/Makefile.sources |   1 +
>   tests/kms_nv12.c       | 619 +++++++++++++++++++++++++++++++++++++++++++++++++
>   4 files changed, 622 insertions(+)
>   create mode 100644 tests/kms_nv12.c

[snip]

> +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;
> +
> +	igt_assert(intel_gen(devid) >= 9);

Not reviewing as such, but notice --list-subtest is broken unless you 
move the above three lines into the fixture.

After that I ran:

> +	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);
> +	}
> +	igt_subtest_f("nv12-plane-tile-yf-rot-90") {
> +		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_TILED;
> +		test_nv12_plane_rotation_90_or_270(&data);
> +	}

And both succeeded! :)

Your + mine patch series rebased on top of today's nightly.

Regards,

Tvrtko
Thomas Wood May 12, 2015, 3:55 p.m. UTC | #2
On 9 May 2015 at 05:32, Chandra Konduru <chandra.konduru@intel.com> wrote:
> From: chandra konduru <chandra.konduru@intel.com>
>
> This patch adds kms_nv12 test case. It covers testing NV12 in
> all supported linear/tile-X/tile-Y/tile-Yf tile formats in
> 0 and 180 orientations. For each tiling format, it tests
> various combinations of planes and scaling.
>
> v2:
> -Added 90/270 tests (me)
> -took out crc test as it isn't adding much value due to chroma upsampling (me)
>
> Signed-off-by: chandra konduru <chandra.konduru@intel.com>
> ---
>  tests/.gitignore       |   1 +
>  tests/Android.mk       |   1 +
>  tests/Makefile.sources |   1 +
>  tests/kms_nv12.c       | 619 +++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 622 insertions(+)
>  create mode 100644 tests/kms_nv12.c
>
> diff --git a/tests/.gitignore b/tests/.gitignore
> index 86795c0..b03647a 100644
> --- a/tests/.gitignore
> +++ b/tests/.gitignore
> @@ -149,6 +149,7 @@ kms_vblank
>  kms_crtc_background_color
>  kms_plane_scaling
>  kms_panel_fitting
> +kms_nv12
>  pm_lpsp
>  pm_rc6_residency
>  pm_rpm
> diff --git a/tests/Android.mk b/tests/Android.mk
> index fac9931..c0c6383 100644
> --- a/tests/Android.mk
> +++ b/tests/Android.mk
> @@ -81,6 +81,7 @@ else
>      kms_pwrite_crc \
>      kms_pipe_b_c_ivb \
>      kms_legacy_colorkey
> +       kms_nv12 \
>      IGT_LOCAL_CFLAGS += -DANDROID_HAS_CAIRO=0
>  endif
>
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index 12f27f9..32c1b25 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -79,6 +79,7 @@ TESTS_progs_M = \
>         kms_crtc_background_color \
>         kms_plane_scaling \
>         kms_panel_fitting \
> +       kms_nv12 \
>         pm_lpsp \
>         pm_rpm \
>         pm_rps \
> diff --git a/tests/kms_nv12.c b/tests/kms_nv12.c
> new file mode 100644
> index 0000000..616cf6e
> --- /dev/null
> +++ b/tests/kms_nv12.c
> @@ -0,0 +1,619 @@
> +/*
> + * Copyright © 2013,2014 Intel Corporation

and 2015?

> + *
> + * 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;
> +
> +       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);

This could be igt_assert_eq(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);
> +               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);
> +               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);

This only needs to be done once, so it can be moved out of the for loop.

> +
> +               /* 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

Mimicking?

> +                */
> +
> +               /* 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);
> +
> +               /* 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);
> +               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_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);
> +
> +                       /* 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);
> +
> +                       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);
> +
> +       for_each_connected_output(display, output) {
> +               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);
> +               prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
> +
> +               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->plane2 = 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);

This could also use igt_assert_eq.


> +
> +               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");
> +}
> +
> +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;
> +
> +       igt_assert(intel_gen(devid) >= 9);

As Tvrtko mentioned, these lines need to be moved into the igt_fixture block.


> +
> +       data.rotation = IGT_ROTATION_0;
> +       igt_subtest_f("nv12-plane-linear") {

There is no format string here, so igt_subtest would be sufficient.


> +               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);
> +       }
> +       igt_subtest_f("nv12-plane-tile-yf") {
> +               data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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);
> +       }
> +       igt_subtest_f("nv12-plane-tile-yf-rot-180") {
> +               data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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);
> +       }
> +       igt_subtest_f("nv12-plane-tile-yf-rot-90") {
> +               data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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-plane-tile-yf-rot-270") {
> +               data.tiled = LOCAL_I915_FORMAT_MOD_Yf_TILED;
> +               test_nv12_plane_rotation_90_or_270(&data);
> +       }
> +
> +       igt_subtest_f("nv12-on-unsupported-plane") {
> +               data.tiled = LOCAL_DRM_FORMAT_MOD_NONE;
> +               test_nv12_unsupported_plane(&data);
> +       }
> +
> +       igt_fixture {
> +               igt_display_fini(&data.display);
> +       }
> +}
> --
> 1.9.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/tests/.gitignore b/tests/.gitignore
index 86795c0..b03647a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -149,6 +149,7 @@  kms_vblank
 kms_crtc_background_color
 kms_plane_scaling
 kms_panel_fitting
+kms_nv12
 pm_lpsp
 pm_rc6_residency
 pm_rpm
diff --git a/tests/Android.mk b/tests/Android.mk
index fac9931..c0c6383 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -81,6 +81,7 @@  else
     kms_pwrite_crc \
     kms_pipe_b_c_ivb \
     kms_legacy_colorkey
+	kms_nv12 \
     IGT_LOCAL_CFLAGS += -DANDROID_HAS_CAIRO=0
 endif
 
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 12f27f9..32c1b25 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -79,6 +79,7 @@  TESTS_progs_M = \
 	kms_crtc_background_color \
 	kms_plane_scaling \
 	kms_panel_fitting \
+	kms_nv12 \
 	pm_lpsp \
 	pm_rpm \
 	pm_rps \
diff --git a/tests/kms_nv12.c b/tests/kms_nv12.c
new file mode 100644
index 0000000..616cf6e
--- /dev/null
+++ b/tests/kms_nv12.c
@@ -0,0 +1,619 @@ 
+/*
+ * 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;
+
+	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);
+		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);
+		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);
+
+		/* 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);
+		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_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);
+
+			/* 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);
+
+			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);
+
+	for_each_connected_output(display, output) {
+		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);
+		prepare_crtc(d, output, pipe, d->plane1, mode, COMMIT_LEGACY);
+
+		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->plane2 = 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");
+}
+
+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;
+
+	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);
+	}
+	igt_subtest_f("nv12-plane-tile-yf") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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);
+	}
+	igt_subtest_f("nv12-plane-tile-yf-rot-180") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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);
+	}
+	igt_subtest_f("nv12-plane-tile-yf-rot-90") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_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-plane-tile-yf-rot-270") {
+		data.tiled = LOCAL_I915_FORMAT_MOD_Yf_TILED;
+		test_nv12_plane_rotation_90_or_270(&data);
+	}
+
+	igt_subtest_f("nv12-on-unsupported-plane") {
+		data.tiled = LOCAL_DRM_FORMAT_MOD_NONE;
+		test_nv12_unsupported_plane(&data);
+	}
+
+	igt_fixture {
+		igt_display_fini(&data.display);
+	}
+}