[Intel-gfx] [PATCH] tests/kms_render_compression.c : Tests for Render Compression Feature

Mayuresh Gharpure mayuresh.s.gharpure at intel.com
Tue May 26 07:33:56 PDT 2015


Signed-off-by: Mayuresh Gharpure <mayuresh.s.gharpure at intel.com>
---
 tests/Makefile.sources         |   1 +
 tests/kms_render_compression.c | 359 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 360 insertions(+)
 create mode 100644 tests/kms_render_compression.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 994c31b..ae6635a 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -80,6 +80,7 @@ TESTS_progs_M = \
 	kms_crtc_background_color \
 	kms_plane_scaling \
 	kms_panel_fitting \
+	kms_render_compression \
 	pm_lpsp \
 	pm_rpm \
 	pm_rps \
diff --git a/tests/kms_render_compression.c b/tests/kms_render_compression.c
new file mode 100644
index 0000000..a0ab212
--- /dev/null
+++ b/tests/kms_render_compression.c
@@ -0,0 +1,359 @@
+/*
+ * 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 "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "igt_core.h"
+#include "intel_chipset.h"
+#include "igt_aux.h"
+
+IGT_TEST_DESCRIPTION("Test Render Compression");
+
+typedef struct {
+
+	int fb_initial;
+	int drm_fd;
+	int w, h;
+	bool bad_pixel_format, negative;
+	igt_display_t display;
+	igt_crc_t ref_crc;
+	igt_crc_t test_crc;
+	igt_pipe_crc_t *pipe_crc;
+	struct igt_fb fb_prep;
+	struct igt_fb fb;
+} data_t;
+
+
+	static void
+paint_color(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 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);
+
+	/* create the pipe_crc object for this pipe */
+	igt_pipe_crc_free(data->pipe_crc);
+	data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
+
+	/* before allocating, free if any older fb */
+	if (data->fb_initial) {
+		igt_remove_fb(data->drm_fd, &data->fb_prep);
+		data->fb_initial = 0;
+	}
+
+	/* allocate fb for plane 1 */
+	data->fb_initial = igt_create_fb(data->drm_fd,
+			mode->hdisplay, mode->vdisplay,
+			DRM_FORMAT_XRGB8888,
+			LOCAL_I915_FORMAT_MOD_X_TILED, /* tiled */
+			&data->fb_prep);
+	igt_assert(data->fb_initial);
+
+	paint_color(data, &data->fb_prep, mode->hdisplay, mode->vdisplay);
+	igt_plane_set_fb(plane, &data->fb_prep);
+	if (s == COMMIT_LEGACY) {
+		int ret;
+		ret = drmModeSetCrtc(data->drm_fd,
+				output->config.crtc->crtc_id,
+				data->fb_initial,
+				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;
+
+	igt_pipe_crc_free(data->pipe_crc);
+	data->pipe_crc = NULL;
+
+	if (data->fb_initial) {
+		igt_remove_fb(data->drm_fd, &data->fb_prep);
+		data->fb_initial = 0;
+	}
+	if (data->fb.fb_id)
+		igt_remove_fb(data->drm_fd, &data->fb);
+
+	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
+paint_squares(data_t *data, drmModeModeInfo *mode, igt_rotation_t rotation,
+		igt_plane_t *plane)
+{
+	cairo_t *cr;
+	unsigned int w = data->w;
+	unsigned int h = data->h;
+
+	cr = igt_get_cairo_ctx(data->drm_fd, &data->fb);
+
+	if (rotation == IGT_ROTATION_180) {
+		cairo_translate(cr, w, h);
+		cairo_rotate(cr, M_PI);
+	}
+
+	if (rotation == IGT_ROTATION_90) {
+		/* Paint 4 squares with width == height in Blue, Red,
+		   Green, White Clockwise order to look like 90 degree rotated*/
+		igt_paint_color(cr, 0, 0, w / 2, h / 2, 0.0, 0.0, 1.0);
+		igt_paint_color(cr, w / 2, 0, w / 2, h / 2, 1.0, 0.0, 0.0);
+		igt_paint_color(cr, 0, h / 2, w / 2, h / 2, 1.0, 1.0, 1.0);
+		igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, 0.0, 1.0, 0.0);
+
+	} else if (rotation == IGT_ROTATION_270) {
+		/* Paint 4 squares with width == height in Green, White,
+		   Blue, Red Clockwise order to look like 270 degree rotated*/
+		igt_paint_color(cr, 0, 0, w / 2, h / 2, 0.0, 1.0, 0.0);
+		igt_paint_color(cr, w / 2, 0, w / 2, h / 2, 1.0, 1.0, 1.0);
+		igt_paint_color(cr, 0, h / 2, w / 2, h / 2, 1.0, 0.0, 0.0);
+		igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, 0.0, 0.0, 1.0);
+
+	} else {
+		/* Paint with 4 squares of Red, Green, White, Blue Clockwise */
+		igt_paint_color(cr, 0, 0, w / 2, h / 2, 1.0, 0.0, 0.0);
+		igt_paint_color(cr, w / 2, 0, w / 2, h / 2, 0.0, 1.0, 0.0);
+		igt_paint_color(cr, 0, h / 2, w / 2, h / 2, 0.0, 0.0, 1.0);
+		igt_paint_color(cr, w / 2, h / 2, w / 2, h / 2, 1.0, 1.0, 1.0);
+	}
+
+	cairo_destroy(cr);
+}
+
+static void test_render_compression(data_t *data, enum igt_plane plane_type,
+		igt_rotation_t rotation, uint64_t tiling){
+
+	igt_display_t *display = &data->display;
+	igt_output_t *output;
+	igt_plane_t *plane;
+	enum pipe pipe;
+	int valid_tests = 0;
+	enum igt_commit_style commit = COMMIT_UNIVERSAL;
+	int res;
+	int fb_id;
+	int width, height;
+	uint32_t pixelformat = DRM_FORMAT_XRGB8888;
+	/*
+	* TODO: The algorithm to create compressed buffers is not available in
+	*	open source.So,this test only validates the code path with un-
+	*	compressed buffers and does some negative tests
+	*	Once the compression algorithm is available,buffer creation
+	*	logic will be changed
+	*/
+	for_each_connected_output(display, output) {
+		drmModeModeInfo *mode;
+		pipe = output->config.pipe;
+		/*
+		* Render compression is enabled only on first two pipes
+		*/
+		if (pipe != PIPE_A && pipe != PIPE_B)
+			continue;
+		igt_output_set_pipe(output, pipe);
+		mode = igt_output_get_mode(output);
+		/*Draw the initial primary plane*/
+		plane = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
+		prepare_crtc(data, output, pipe, plane, mode, commit);
+		/* create the pipe_crc object for this pipe */
+		igt_pipe_crc_free(data->pipe_crc);
+		data->pipe_crc = igt_pipe_crc_new(pipe,
+		INTEL_PIPE_CRC_SOURCE_AUTO);
+		width = (plane_type == IGT_PLANE_PRIMARY ?
+			mode->hdisplay : 200);
+		height = (plane_type == IGT_PLANE_PRIMARY ?
+			mode->vdisplay : 200);
+		plane = igt_output_get_plane(output, plane_type);
+		data->w = width;
+		data->h = height;
+		/*
+		* if test case is for bad_pixel_format set a 565 format
+		* as render compression only works for RGB8888 formats
+		*/
+		if (data->bad_pixel_format) {
+			pixelformat = DRM_FORMAT_RGB565;
+			data->negative = true;/* this is a negative test */
+		}
+		fb_id = igt_create_fb(data->drm_fd,
+				width, height,
+				pixelformat,
+				tiling,
+				&data->fb);
+		igt_assert(fb_id);
+		/* Step 1: create a reference CRC for a software-rotated fb */
+
+		/*
+		 * For Plane 1,we test with panel resolution only. So,using 90
+		 * or 270 degree rotation will need to recreate the buffer with
+		 * different resolution
+		 */
+		if (plane_type == IGT_PLANE_PRIMARY &&
+			rotation != IGT_ROTATION_0)
+			rotation = IGT_ROTATION_180;
+		paint_squares(data, mode, rotation, plane);
+		igt_plane_set_fb(plane, &data->fb);
+		igt_display_commit2(display, commit);
+		igt_pipe_crc_collect_crc(data->pipe_crc, &data->ref_crc);
+		/* Step 2: create a non rotated fb and let hw rotate it */
+		paint_squares(data, mode, IGT_ROTATION_0, plane);
+		igt_plane_set_fb(plane, &data->fb);
+		igt_plane_set_rotation(plane, rotation);
+		igt_plane_set_render_compression(plane, IGT_COMP_RENDER);
+		res = igt_display_try_commit2(display, commit);
+		/*
+		 *  If test is negative then return value should be nonzero
+		 *  i.e the commit should fail & vice-versa
+		 */
+		igt_assert((res == 0 && !data->negative) ||
+			(res != 0 && data->negative));
+		igt_pipe_crc_collect_crc(data->pipe_crc, &data->test_crc);
+		igt_assert_crc_equal(&data->ref_crc, &data->test_crc);
+		valid_tests++;
+		cleanup_crtc(data, output, plane);
+	}
+	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
+}
+
+static const char *get_rotation(igt_rotation_t rotation)
+{
+
+	switch (rotation) {
+	case IGT_ROTATION_0:
+		return "no-rotation";
+	case IGT_ROTATION_90:
+		return "rotation-90";
+	case IGT_ROTATION_180:
+		return "rotation-180";
+	case IGT_ROTATION_270:
+		return "rotation-270";
+	default:
+		return "no-rotation";
+	}
+}
+
+static const char *get_tiling(int tiling)
+{
+	switch (tiling) {
+	case 0:
+		return "tileY";
+	case 1:
+		return "tileYf";
+	default:
+		return "tileY";
+	}
+}
+
+igt_main
+{
+	data_t data = {};
+	int gen = 0;
+	int it_plane = 0, it_rotation = 0, it_tiling = 0;
+	int rotation_array[4] = {IGT_ROTATION_0, IGT_ROTATION_90,
+		IGT_ROTATION_180, IGT_ROTATION_270};
+	uint64_t tiling_array[2] = {LOCAL_I915_FORMAT_MOD_Y_TILED,
+		LOCAL_I915_FORMAT_MOD_Yf_TILED};
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		data.drm_fd = drm_open_any_master();
+
+		gen = intel_gen(intel_get_drm_devid(data.drm_fd));
+
+		igt_require(gen >= 9);
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_require_pipe_crc();
+		igt_display_init(&data.display, data.drm_fd);
+		igt_require(data.display.has_universal_planes);
+	}
+
+	for (it_plane = 0; it_plane < IGT_MAX_PLANES; it_plane++) {
+		for (it_rotation = 0; it_rotation < 4; it_rotation++) {
+			for (it_tiling = 0; it_tiling < 2; it_tiling++) {
+				igt_subtest_f("plane%d-%s-%s", it_plane+1,
+					get_rotation(rotation_array[it_rotation]),
+					get_tiling(it_tiling)) {
+				if (rotation_array[it_rotation] == IGT_ROTATION_90
+					|| rotation_array[it_rotation] == IGT_ROTATION_270
+					|| it_plane > IGT_PLANE_2)
+						data.negative = true;
+					test_render_compression(&data, it_plane,
+					rotation_array[it_rotation],
+					tiling_array[it_tiling]);
+					data.negative = false;
+				}
+			}
+		}
+	}
+
+	igt_subtest_f("bad-pixel-format") {
+		data.bad_pixel_format = true;
+		test_render_compression(&data, IGT_PLANE_1, IGT_ROTATION_0,
+			LOCAL_I915_FORMAT_MOD_Yf_TILED);
+		test_render_compression(&data, IGT_PLANE_2, IGT_ROTATION_0,
+			LOCAL_I915_FORMAT_MOD_Yf_TILED);
+		data.bad_pixel_format = false;
+	}
+
+	igt_subtest_f("bad-tiling") {
+		data.negative = true;
+		test_render_compression(&data, IGT_PLANE_1, IGT_ROTATION_0,
+			LOCAL_DRM_FORMAT_MOD_NONE);
+		test_render_compression(&data, IGT_PLANE_2, IGT_ROTATION_0,
+			LOCAL_I915_FORMAT_MOD_X_TILED);
+		data.negative = false;
+	}
+
+	igt_fixture {
+		igt_display_fini(&data.display);
+	}
+}
-- 
1.9.1



More information about the Intel-gfx mailing list