Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH igt 1/2] rendercopy: Pass context to rendercopy functions
@ 2013-11-21 19:33 ville.syrjala
  2013-11-21 19:33 ` [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
  0 siblings, 1 reply; 8+ messages in thread
From: ville.syrjala @ 2013-11-21 19:33 UTC (permalink / raw)
  To: intel-gfx

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

rendercopy does the batch buffer flush internally, so if we want
to use it with multiple contexts, we need to pass the context
in from caller.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/rendercopy.h                |  5 +++++
 lib/rendercopy_gen6.c           | 12 +++++++-----
 lib/rendercopy_gen7.c           | 12 +++++++-----
 lib/rendercopy_i830.c           |  1 +
 lib/rendercopy_i915.c           |  1 +
 tests/gem_ctx_basic.c           |  2 +-
 tests/gem_render_copy.c         |  2 +-
 tests/gem_render_linear_blits.c |  6 +++---
 tests/gem_render_tiled_blits.c  |  6 +++---
 tests/gem_ringfill.c            |  5 +++--
 tests/gem_seqno_wrap.c          |  2 +-
 tests/gem_stress.c              |  2 +-
 tests/kms_flip.c                |  2 +-
 13 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/lib/rendercopy.h b/lib/rendercopy.h
index f726df6..5586b1c 100644
--- a/lib/rendercopy.h
+++ b/lib/rendercopy.h
@@ -62,6 +62,7 @@ static inline unsigned buf_height(struct scratch_buf *buf)
 }
 
 typedef void (*render_copyfunc_t)(struct intel_batchbuffer *batch,
+				  drm_intel_context *context,
 				  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 				  unsigned width, unsigned height,
 				  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
@@ -73,18 +74,22 @@ void gen8_render_copyfunc(struct intel_batchbuffer *batch,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
 void gen7_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
 void gen6_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
 void gen3_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
 void gen2_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
diff --git a/lib/rendercopy_gen6.c b/lib/rendercopy_gen6.c
index dafee88..457cb35 100644
--- a/lib/rendercopy_gen6.c
+++ b/lib/rendercopy_gen6.c
@@ -78,14 +78,15 @@ batch_copy(struct intel_batchbuffer *batch, const void *ptr, uint32_t size, uint
 }
 
 static void
-gen6_render_flush(struct intel_batchbuffer *batch, uint32_t batch_end)
+gen6_render_flush(struct intel_batchbuffer *batch,
+		  drm_intel_context *context, uint32_t batch_end)
 {
 	int ret;
 
 	ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
 	if (ret == 0)
-		ret = drm_intel_bo_mrb_exec(batch->bo, batch_end,
-					    NULL, 0, 0, 0);
+		ret = drm_intel_gem_bo_context_exec(batch->bo, context,
+						    batch_end, 0);
 	assert(ret == 0);
 }
 
@@ -529,6 +530,7 @@ static uint32_t gen6_emit_primitive(struct intel_batchbuffer *batch)
 }
 
 void gen6_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
@@ -537,7 +539,7 @@ void gen6_render_copyfunc(struct intel_batchbuffer *batch,
 	uint32_t cc_vp, cc_blend, offset;
 	uint32_t batch_end;
 
-	intel_batchbuffer_flush(batch);
+	intel_batchbuffer_flush_with_context(batch, context);
 
 	batch->ptr = batch->buffer + 1024;
 	batch_alloc(batch, 64, 64);
@@ -594,6 +596,6 @@ void gen6_render_copyfunc(struct intel_batchbuffer *batch,
 	emit_vertex_normalized(batch, src_x, buf_width(src));
 	emit_vertex_normalized(batch, src_y, buf_height(src));
 
-	gen6_render_flush(batch, batch_end);
+	gen6_render_flush(batch, context, batch_end);
 	intel_batchbuffer_reset(batch);
 }
diff --git a/lib/rendercopy_gen7.c b/lib/rendercopy_gen7.c
index fdf741f..f6981c7 100644
--- a/lib/rendercopy_gen7.c
+++ b/lib/rendercopy_gen7.c
@@ -52,14 +52,15 @@ batch_copy(struct intel_batchbuffer *batch, const void *ptr, uint32_t size, uint
 }
 
 static void
-gen7_render_flush(struct intel_batchbuffer *batch, uint32_t batch_end)
+gen7_render_flush(struct intel_batchbuffer *batch,
+		  drm_intel_context *context, uint32_t batch_end)
 {
 	int ret;
 
 	ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
 	if (ret == 0)
-		ret = drm_intel_bo_mrb_exec(batch->bo, batch_end,
-					    NULL, 0, 0, 0);
+		ret = drm_intel_gem_bo_context_exec(batch->bo, context,
+						    batch_end, 0);
 	assert(ret == 0);
 }
 
@@ -513,13 +514,14 @@ gen7_emit_null_depth_buffer(struct intel_batchbuffer *batch)
 
 #define BATCH_STATE_SPLIT 2048
 void gen7_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
 {
 	uint32_t batch_end;
 
-	intel_batchbuffer_flush(batch);
+	intel_batchbuffer_flush_with_context(batch, context);
 
 	batch->state = &batch->buffer[BATCH_STATE_SPLIT];
 
@@ -563,6 +565,6 @@ void gen7_render_copyfunc(struct intel_batchbuffer *batch,
 	batch_end = ALIGN(batch_end, 8);
 	assert(batch_end < BATCH_STATE_SPLIT);
 
-	gen7_render_flush(batch, batch_end);
+	gen7_render_flush(batch, context, batch_end);
 	intel_batchbuffer_reset(batch);
 }
diff --git a/lib/rendercopy_i830.c b/lib/rendercopy_i830.c
index 0347597..73edcfa 100644
--- a/lib/rendercopy_i830.c
+++ b/lib/rendercopy_i830.c
@@ -191,6 +191,7 @@ static void gen2_emit_copy_pipeline(struct intel_batchbuffer *batch)
 }
 
 void gen2_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
diff --git a/lib/rendercopy_i915.c b/lib/rendercopy_i915.c
index 4b15dfe..33e027e 100644
--- a/lib/rendercopy_i915.c
+++ b/lib/rendercopy_i915.c
@@ -3,6 +3,7 @@
 #include "rendercopy.h"
 
 void gen3_render_copyfunc(struct intel_batchbuffer *batch,
+			  drm_intel_context *context,
 			  struct scratch_buf *src, unsigned src_x, unsigned src_y,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
diff --git a/tests/gem_ctx_basic.c b/tests/gem_ctx_basic.c
index bc21a8a..a2b83df 100644
--- a/tests/gem_ctx_basic.c
+++ b/tests/gem_ctx_basic.c
@@ -84,7 +84,7 @@ static void *work(void *arg)
 
 		if (uncontexted) {
 			igt_assert(rendercopy);
-			rendercopy(batch, &src, 0, 0, 0, 0, &dst, 0, 0);
+			rendercopy(batch, NULL, &src, 0, 0, 0, 0, &dst, 0, 0);
 		} else {
 			int ret;
 			ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index ed49622..6228595 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -156,7 +156,7 @@ int main(int argc, char **argv)
 		drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, true);
 	}
 
-	render_copy(batch,
+	render_copy(batch, NULL,
 		    &src, 0, 0, WIDTH, HEIGHT,
 		    &dst, WIDTH / 2, HEIGHT / 2);
 
diff --git a/tests/gem_render_linear_blits.c b/tests/gem_render_linear_blits.c
index f110753..4ae2103 100644
--- a/tests/gem_render_linear_blits.c
+++ b/tests/gem_render_linear_blits.c
@@ -128,7 +128,7 @@ int main(int argc, char **argv)
 		dst.tiling = I915_TILING_NONE;
 		dst.size = SIZE;
 
-		render_copy(batch, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
+		render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
 		start_val[(i + 1) % count] = start_val[i % count];
 	}
 	for (i = 0; i < count; i++)
@@ -151,7 +151,7 @@ int main(int argc, char **argv)
 		dst.tiling = I915_TILING_NONE;
 		dst.size = SIZE;
 
-		render_copy(batch, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
+		render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
 		start_val[i % count] = start_val[(i + 1) % count];
 	}
 	for (i = 0; i < count; i++)
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
 		dst.tiling = I915_TILING_NONE;
 		dst.size = SIZE;
 
-		render_copy(batch, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
+		render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
 		start_val[d] = start_val[s];
 	}
 	for (i = 0; i < count; i++)
diff --git a/tests/gem_render_tiled_blits.c b/tests/gem_render_tiled_blits.c
index d2af1e3..f8af236 100644
--- a/tests/gem_render_tiled_blits.c
+++ b/tests/gem_render_tiled_blits.c
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
 		int src = i % count;
 		int dst = (i + 1) % count;
 
-		render_copy(batch, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+		render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++)
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
 		int src = (i + 1) % count;
 		int dst = i % count;
 
-		render_copy(batch, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+		render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++)
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
 		if (src == dst)
 			continue;
 
-		render_copy(batch, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+		render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++)
diff --git a/tests/gem_ringfill.c b/tests/gem_ringfill.c
index ba91001..31a21cb 100644
--- a/tests/gem_ringfill.c
+++ b/tests/gem_ringfill.c
@@ -159,9 +159,9 @@ static int check_ring(drm_intel_bufmgr *bufmgr,
 		igt_assert(y < height);
 
 		/* Dummy load to fill the ring */
-		copy(batch, &src, 0, 0, width, height, &tmp, 0, 0);
+		copy(batch, NULL, &src, 0, 0, width, height, &tmp, 0, 0);
 		/* And copy the src into dst, pixel by pixel */
-		copy(batch, &src, x, y, 1, 1, &dst, x, y);
+		copy(batch, NULL, &src, x, y, 1, 1, &dst, x, y);
 	}
 
 	/* verify */
@@ -173,6 +173,7 @@ static int check_ring(drm_intel_bufmgr *bufmgr,
 }
 
 static void blt_copy(struct intel_batchbuffer *batch,
+		     drm_intel_context *context,
 		     struct scratch_buf *src, unsigned src_x, unsigned src_y,
 		     unsigned w, unsigned h,
 		     struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
diff --git a/tests/gem_seqno_wrap.c b/tests/gem_seqno_wrap.c
index 8417008..2c6ffbe 100644
--- a/tests/gem_seqno_wrap.c
+++ b/tests/gem_seqno_wrap.c
@@ -148,7 +148,7 @@ static void render_copyfunc(struct scratch_buf *src,
 	static int warned = 0;
 
 	if (rendercopy) {
-		rendercopy(batch_3d,
+		rendercopy(batch_3d, NULL,
 			   src, src_x, src_y,
 			   width, height,
 			   dst, dst_x, dst_y);
diff --git a/tests/gem_stress.c b/tests/gem_stress.c
index b7fd87e..c01e92e 100644
--- a/tests/gem_stress.c
+++ b/tests/gem_stress.c
@@ -328,7 +328,7 @@ static void render_copyfunc(struct scratch_buf *src, unsigned src_x, unsigned sr
 		keep_gpu_busy();
 
 	if (rendercopy)
-		rendercopy(batch, src, src_x, src_y,
+		rendercopy(batch, NULL, src, src_x, src_y,
 		     options.tile_size, options.tile_size,
 		     dst, dst_x, dst_y);
 	else
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index daaed8e..e1a2e93 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -234,7 +234,7 @@ static void emit_dummy_load__rcs(struct test_output *o)
 	for (i = 0; i < limit; i++) {
 		struct scratch_buf *tmp;
 
-		copyfunc(batch,
+		copyfunc(batch, NULL,
 			 src, 0, 0,
 			 o->fb_width, o->fb_height,
 			 dst, 0, 0);
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test
  2013-11-21 19:33 [PATCH igt 1/2] rendercopy: Pass context to rendercopy functions ville.syrjala
@ 2013-11-21 19:33 ` ville.syrjala
  2013-11-25  9:18   ` Daniel Vetter
  2013-11-25 15:08   ` [PATCH 1/2] lib: Add gem_sw_finish() ville.syrjala
  0 siblings, 2 replies; 8+ messages in thread
From: ville.syrjala @ 2013-11-21 19:33 UTC (permalink / raw)
  To: intel-gfx

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

kms_fbc_crc will perform various write operations to the scanout buffer
whilc FBC is enabled. CRC checks will be used to make sure the
modifcations to scanout buffer are detected.

The operations include:
 - page flip
 - pwrite
 - GTT mmap
 - CPU mmap
 - blit
 - rendercopy
 - context switch + rendercopy
 - combination of a page flip and each operation listed above

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 tests/Makefile.sources |   1 +
 tests/kms_fbc_crc.c    | 544 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 545 insertions(+)
 create mode 100644 tests/kms_fbc_crc.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index a02b93d..d201809 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -49,6 +49,7 @@ TESTS_progs_M = \
 	gem_write_read_ring_switch \
 	kms_addfb \
 	kms_cursor_crc \
+	kms_fbc_crc \
 	kms_flip \
 	kms_pipe_crc_basic \
 	kms_render \
diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c
new file mode 100644
index 0000000..355e33a
--- /dev/null
+++ b/tests/kms_fbc_crc.c
@@ -0,0 +1,544 @@
+/*
+ * Copyright © 2013 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 <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include "drm_fourcc.h"
+
+#include "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "rendercopy.h"
+
+enum test_mode {
+	TEST_PAGE_FLIP,
+	TEST_PWRITE,
+	TEST_MMAP_CPU,
+	TEST_MMAP_GTT,
+	TEST_BLT,
+	TEST_RENDER,
+	TEST_CONTEXT,
+	TEST_PAGE_FLIP_AND_PWRITE,
+	TEST_PAGE_FLIP_AND_MMAP_CPU,
+	TEST_PAGE_FLIP_AND_MMAP_GTT,
+	TEST_PAGE_FLIP_AND_BLT,
+	TEST_PAGE_FLIP_AND_RENDER,
+	TEST_PAGE_FLIP_AND_CONTEXT,
+};
+
+typedef struct {
+	struct kmstest_connector_config config;
+	drmModeModeInfo mode;
+	struct kmstest_fb fb[2];
+} connector_t;
+
+typedef struct {
+	int drm_fd;
+	igt_debugfs_t debugfs;
+	drmModeRes *resources;
+	FILE *ctl;
+	igt_crc_t ref_crc[2];
+	igt_pipe_crc_t **pipe_crc;
+	drm_intel_bufmgr *bufmgr;
+	drm_intel_context *ctx[2];
+	uint32_t devid;
+	uint32_t handle[2];
+	uint32_t crtc_id;
+	uint32_t crtc_idx;
+	uint32_t fb_id[2];
+} data_t;
+
+static const char *test_mode_str(enum test_mode mode)
+{
+	static const char * const test_modes[] = {
+		[TEST_PAGE_FLIP] = "page_flip",
+		[TEST_PWRITE] = "pwrite",
+		[TEST_MMAP_CPU] = "mmap_cpu",
+		[TEST_MMAP_GTT] = "mmap_gtt",
+		[TEST_BLT] = "blt",
+		[TEST_RENDER] = "render",
+		[TEST_CONTEXT] = "context",
+		[TEST_PAGE_FLIP_AND_PWRITE] = "page_flip_and_pwrite",
+		[TEST_PAGE_FLIP_AND_MMAP_CPU] = "page_flip_and_mmap_cpu",
+		[TEST_PAGE_FLIP_AND_MMAP_GTT] = "page_flip_and_mmap_gtt",
+		[TEST_PAGE_FLIP_AND_BLT] = "page_flip_and_blt",
+		[TEST_PAGE_FLIP_AND_RENDER] = "page_flip_and_render",
+		[TEST_PAGE_FLIP_AND_CONTEXT] = "page_flip_and_context",
+	};
+
+	return test_modes[mode];
+}
+
+static uint32_t create_fb(data_t *data,
+			  int w, int h,
+			  double r, double g, double b,
+			  struct kmstest_fb *fb)
+{
+	uint32_t fb_id;
+	cairo_t *cr;
+
+	fb_id = kmstest_create_fb2(data->drm_fd, w, h,
+				   DRM_FORMAT_XRGB8888, true, fb);
+	igt_assert(fb_id);
+
+	cr = kmstest_get_cairo_ctx(data->drm_fd, fb);
+	kmstest_paint_color(cr, 0, 0, w, h, r, g, b);
+	igt_assert(cairo_status(cr) == 0);
+
+	return fb_id;
+}
+
+static bool
+connector_set_mode(data_t *data, connector_t *connector,
+		   drmModeModeInfo *mode, uint32_t fb_id)
+{
+	struct kmstest_connector_config *config = &connector->config;
+	int ret;
+
+#if 0
+	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
+		mode->hdisplay, mode->vdisplay);
+#endif
+
+	ret = drmModeSetCrtc(data->drm_fd,
+			     config->crtc->crtc_id,
+			     fb_id,
+			     0, 0, /* x, y */
+			     &config->connector->connector_id,
+			     1,
+			     mode);
+	igt_assert(ret == 0);
+
+	return 0;
+}
+
+static void display_init(data_t *data)
+{
+	data->resources = drmModeGetResources(data->drm_fd);
+	igt_assert(data->resources);
+
+	data->pipe_crc = calloc(data->resources->count_crtcs, sizeof(data->pipe_crc[0]));
+}
+
+static void display_fini(data_t *data)
+{
+	free(data->pipe_crc);
+}
+
+static void fill_blt(data_t *data, uint32_t handle, unsigned char color)
+{
+	drm_intel_bo *dst = gem_handle_to_libdrm_bo(data->bufmgr,
+						    data->drm_fd,
+						    "", handle);
+	struct intel_batchbuffer *batch;
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	BEGIN_BATCH(5);
+	OUT_BATCH(COLOR_BLT_CMD);
+	OUT_BATCH((1 << 24) | (0xf0 << 16) | 0);
+	OUT_BATCH(1 << 16 | 4);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(color);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush(batch);
+	intel_batchbuffer_free(batch);
+}
+
+
+static void scratch_buf_init(struct scratch_buf *buf, drm_intel_bo *bo)
+{
+	buf->bo = bo;
+	buf->stride = 4096;
+	buf->tiling = I915_TILING_X;
+	buf->size = 4096;
+}
+
+static void exec_nop(data_t *data, uint32_t handle, drm_intel_context *context)
+{
+	drm_intel_bo *dst;
+	struct intel_batchbuffer *batch;
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	/* add the reloc to make sure the kernel will think we write to dst */
+	BEGIN_BATCH(4);
+	OUT_BATCH(MI_BATCH_BUFFER_END);
+	OUT_BATCH(MI_NOOP);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(MI_NOOP);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush_with_context(batch, context);
+	intel_batchbuffer_free(batch);
+}
+
+static void fill_render(data_t *data, uint32_t handle,
+			drm_intel_context *context, unsigned char color)
+{
+	drm_intel_bo *src, *dst;
+	struct intel_batchbuffer *batch;
+	struct scratch_buf src_buf, dst_buf;
+	const uint8_t buf[4] = { color, color, color, color };
+	render_copyfunc_t rendercopy = get_render_copyfunc(data->devid);
+
+	igt_skip_on(!rendercopy);
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	src = drm_intel_bo_alloc(data->bufmgr, "", 4096, 4096);
+	igt_assert(src);
+
+	gem_write(data->drm_fd, src->handle, 0, buf, 4);
+
+	scratch_buf_init(&src_buf, src);
+	scratch_buf_init(&dst_buf, dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	rendercopy(batch, context,
+		   &src_buf, 0, 0, 1, 1,
+		   &dst_buf, 0, 0);
+
+	intel_batchbuffer_free(batch);
+}
+
+static bool fbc_enabled(data_t *data)
+{
+	FILE *status;
+	char str[64] = {};
+
+	status = igt_debugfs_fopen(&data->debugfs, "i915_fbc_status", "r");
+	fread(str, sizeof(str) - 1, 1, status);
+	fclose(status);
+	return strstr(str, "FBC enabled") != NULL;
+}
+
+static void test_crc(data_t *data, enum test_mode mode)
+{
+	static const unsigned char buf[1] = { 0xcc };
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc[data->crtc_idx];
+	igt_crc_t *crcs = NULL;
+	uint32_t handle = data->handle[0];
+	uint32_t fb_id = data->fb_id[0];
+
+	igt_assert(fbc_enabled(data));
+
+	if (mode >= TEST_PAGE_FLIP_AND_PWRITE) {
+		handle = data->handle[1];
+		fb_id = data->fb_id[1];
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		usleep(300000);
+
+		igt_assert(fbc_enabled(data));
+	}
+
+	switch (mode) {
+		void *ptr;
+	case TEST_PAGE_FLIP:
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		break;
+	case TEST_PWRITE:
+	case TEST_PAGE_FLIP_AND_PWRITE:
+		gem_write(data->drm_fd, handle, 0, buf, 1);
+		igt_assert(drmModeDirtyFB(data->drm_fd, fb_id, NULL, 0) == 0);
+		break;
+	case TEST_MMAP_CPU:
+	case TEST_PAGE_FLIP_AND_MMAP_CPU:
+		ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+		memset(ptr, 0xff, 4);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
+		munmap(ptr, 4096);
+		igt_assert(drmModeDirtyFB(data->drm_fd, fb_id, NULL, 0) == 0);
+		break;
+	case TEST_MMAP_GTT:
+	case TEST_PAGE_FLIP_AND_MMAP_GTT:
+		ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+		memset(ptr, 0xff, 4);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
+		munmap(ptr, 4096);
+		break;
+	case TEST_BLT:
+	case TEST_PAGE_FLIP_AND_BLT:
+		fill_blt(data, handle, 0xff);
+		break;
+	case TEST_RENDER:
+	case TEST_CONTEXT:
+	case TEST_PAGE_FLIP_AND_RENDER:
+	case TEST_PAGE_FLIP_AND_CONTEXT:
+		fill_render(data, handle,
+			    (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) ?
+			    data->ctx[1] : NULL, 0xff);
+		break;
+	}
+
+	/* make sure we're looking at new data */
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+
+	/*
+	 * Allow time for FBC to kick in again if it
+	 * got disabled during dirtyfb or page flip.
+	 */
+	usleep(300000);
+
+	igt_assert(fbc_enabled(data));
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+}
+
+static bool prepare_crtc(data_t *data, uint32_t connector_id, enum test_mode mode)
+{
+	igt_pipe_crc_t *pipe_crc;
+	igt_crc_t *crcs = NULL;
+	connector_t connector;
+	int ret;
+
+	ret = kmstest_get_connector_config(data->drm_fd,
+					   connector_id,
+					   1 << data->crtc_idx,
+					   &connector.config);
+	if (ret)
+		return false;
+
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	pipe_crc = igt_pipe_crc_new(&data->debugfs,
+				    data->drm_fd, data->crtc_idx,
+				    INTEL_PIPE_CRC_SOURCE_AUTO);
+	if (!pipe_crc) {
+		printf("auto crc not supported on this connector with crtc %i\n",
+		       data->crtc_idx);
+		return false;
+	}
+
+	data->pipe_crc[data->crtc_idx] = pipe_crc;
+
+	data->fb_id[0] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.0, 0.0, 0.0, &connector.fb[0]);
+	igt_assert(data->fb_id[0]);
+
+	data->fb_id[1] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.1, 0.1, 0.1, &connector.fb[1]);
+	igt_assert(data->fb_id[1]);
+
+	data->handle[0] = connector.fb[0].gem_handle;
+	data->handle[1] = connector.fb[1].gem_handle;
+
+	/* scanout = fb[1] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[1]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[1] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[1] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		data->ctx[0] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[0]);
+		data->ctx[1] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[1]);
+
+		/*
+		 * Disable FBC RT address for both contexts
+		 * (by "rendering" to a non-scanout buffer).
+		 */
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+	}
+
+	/* scanout = fb[0] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[0]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		/*
+		 * make ctx[0] FBC RT address point to fb[0], ctx[1]
+		 * FBC RT address is left as disabled.
+		 */
+		exec_nop(data, connector.fb[0].gem_handle, data->ctx[0]);
+	}
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[0] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[0] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	kmstest_free_connector_config(&connector.config);
+
+	return true;
+}
+
+static void finish_crtc(data_t *data, enum test_mode mode)
+{
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		drm_intel_gem_context_destroy(data->ctx[0]);
+		drm_intel_gem_context_destroy(data->ctx[1]);
+	}
+}
+
+static void run_test(data_t *data, enum test_mode mode)
+{
+	int i, n;
+
+	for (i = 0; i < data->resources->count_connectors; i++) {
+		uint32_t connector_id = data->resources->connectors[i];
+
+		for (n = 0; n < data->resources->count_crtcs; n++) {
+			data->crtc_idx = n;
+			data->crtc_id = data->resources->crtcs[n];
+
+			if (!prepare_crtc(data, connector_id, mode))
+				continue;
+
+			fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+			test_crc(data, mode);
+
+			fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+
+			finish_crtc(data, mode);
+		}
+	}
+}
+
+igt_main
+{
+	data_t data = {};
+	enum test_mode mode;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		size_t written;
+		int ret;
+		const char *cmd = "pipe A none";
+		char buf[64];
+		FILE *status;
+
+		data.drm_fd = drm_open_any();
+		igt_require(data.drm_fd);
+		igt_set_vt_graphics_mode();
+
+		data.devid = intel_get_drm_devid(data.drm_fd);
+
+		igt_debugfs_init(&data.debugfs);
+		data.ctl = igt_debugfs_fopen(&data.debugfs,
+					     "i915_display_crc_ctl", "r+");
+		igt_require_f(data.ctl,
+			      "No display_crc_ctl found, kernel too old\n");
+		written = fwrite(cmd, 1, strlen(cmd), data.ctl);
+		ret = fflush(data.ctl);
+		igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
+			      "CRCs not supported on this platform\n");
+
+		status = igt_debugfs_fopen(&data.debugfs, "i915_fbc_status", "r");
+		igt_require_f(status, "No i915_fbc_status found\n");
+		fread(buf, sizeof(buf), 1, status);
+		fclose(status);
+		buf[sizeof(buf) - 1] = '\0';
+		igt_require_f(!strstr(buf, "unsupported by this chipset") &&
+			      !strstr(buf, "disabled per module param") &&
+			      !strstr(buf, "disabled per chip default"),
+			      "FBC not supported/enabled\n");
+
+		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+		igt_assert(data.bufmgr);
+		drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
+
+		display_init(&data);
+	}
+
+	for (mode = TEST_PAGE_FLIP; mode <= TEST_PAGE_FLIP_AND_CONTEXT; mode++) {
+		igt_subtest_f("%s", test_mode_str(mode)) {
+			run_test(&data, mode);
+		}
+	}
+
+	igt_fixture {
+		drm_intel_bufmgr_destroy(data.bufmgr);
+		display_fini(&data);
+		fclose(data.ctl);
+	}
+}
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test
  2013-11-21 19:33 ` [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
@ 2013-11-25  9:18   ` Daniel Vetter
  2013-11-25 15:08   ` [PATCH 1/2] lib: Add gem_sw_finish() ville.syrjala
  1 sibling, 0 replies; 8+ messages in thread
From: Daniel Vetter @ 2013-11-25  9:18 UTC (permalink / raw)
  To: ville.syrjala; +Cc: intel-gfx

On Thu, Nov 21, 2013 at 09:33:40PM +0200, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> kms_fbc_crc will perform various write operations to the scanout buffer
> whilc FBC is enabled. CRC checks will be used to make sure the
> modifcations to scanout buffer are detected.
> 
> The operations include:
>  - page flip
>  - pwrite
>  - GTT mmap
>  - CPU mmap
>  - blit
>  - rendercopy
>  - context switch + rendercopy
>  - combination of a page flip and each operation listed above
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

First things first: crc-based fbc testcase, you're my hero!

Two high-level comments:
- Imre somewhat started to dig in this direction with kms_render. Though
  it doesn't have crc checks obviously. Imo we should either merge yours
  with Imre's code or just rip the old stuff out.
- The next guy submitting psr patches will be volunteered to extend your
  testcase here to also tests cursors and sprites. If you can blow through
  some planning for this case (tbh I didn't read through the code too
  much) that'd be great.

Now for the actual approach (and this kinda goes as a review for your fbc
patches, too). Imo we shouldn't start to use drmModeDirtyFb if we still
have at least some of the hw tracking in place. The reason for that is
that I fear the hardware tracking will paper over userspace bugs in
communicating frontbuffer rendering to the kernel. Which will be a fun
problem once we don't have working frontbuffer rendering (baytrail psr
seeems to be of that kind).

So for now I'd like us to keep on using the legacy ioctls and dances for
communicating frontbuffer updates, and keep drmDirtyFb pristing for when
things clear up. I'll comment below with the exact rules.
-Daniel

> ---
>  tests/Makefile.sources |   1 +
>  tests/kms_fbc_crc.c    | 544 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 545 insertions(+)
>  create mode 100644 tests/kms_fbc_crc.c
> 
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index a02b93d..d201809 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -49,6 +49,7 @@ TESTS_progs_M = \
>  	gem_write_read_ring_switch \
>  	kms_addfb \
>  	kms_cursor_crc \
> +	kms_fbc_crc \
>  	kms_flip \
>  	kms_pipe_crc_basic \
>  	kms_render \
> diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c
> new file mode 100644
> index 0000000..355e33a
> --- /dev/null
> +++ b/tests/kms_fbc_crc.c
> @@ -0,0 +1,544 @@
> +/*
> + * Copyright © 2013 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 <errno.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +#include <glib.h>
> +
> +#include "drm_fourcc.h"
> +
> +#include "drmtest.h"
> +#include "igt_debugfs.h"
> +#include "igt_kms.h"
> +#include "rendercopy.h"
> +
> +enum test_mode {
> +	TEST_PAGE_FLIP,
> +	TEST_PWRITE,
> +	TEST_MMAP_CPU,
> +	TEST_MMAP_GTT,
> +	TEST_BLT,
> +	TEST_RENDER,
> +	TEST_CONTEXT,
> +	TEST_PAGE_FLIP_AND_PWRITE,
> +	TEST_PAGE_FLIP_AND_MMAP_CPU,
> +	TEST_PAGE_FLIP_AND_MMAP_GTT,
> +	TEST_PAGE_FLIP_AND_BLT,
> +	TEST_PAGE_FLIP_AND_RENDER,
> +	TEST_PAGE_FLIP_AND_CONTEXT,
> +};
> +
> +typedef struct {
> +	struct kmstest_connector_config config;
> +	drmModeModeInfo mode;
> +	struct kmstest_fb fb[2];
> +} connector_t;
> +
> +typedef struct {
> +	int drm_fd;
> +	igt_debugfs_t debugfs;
> +	drmModeRes *resources;
> +	FILE *ctl;
> +	igt_crc_t ref_crc[2];
> +	igt_pipe_crc_t **pipe_crc;
> +	drm_intel_bufmgr *bufmgr;
> +	drm_intel_context *ctx[2];
> +	uint32_t devid;
> +	uint32_t handle[2];
> +	uint32_t crtc_id;
> +	uint32_t crtc_idx;
> +	uint32_t fb_id[2];
> +} data_t;
> +
> +static const char *test_mode_str(enum test_mode mode)
> +{
> +	static const char * const test_modes[] = {
> +		[TEST_PAGE_FLIP] = "page_flip",
> +		[TEST_PWRITE] = "pwrite",
> +		[TEST_MMAP_CPU] = "mmap_cpu",
> +		[TEST_MMAP_GTT] = "mmap_gtt",
> +		[TEST_BLT] = "blt",
> +		[TEST_RENDER] = "render",
> +		[TEST_CONTEXT] = "context",
> +		[TEST_PAGE_FLIP_AND_PWRITE] = "page_flip_and_pwrite",
> +		[TEST_PAGE_FLIP_AND_MMAP_CPU] = "page_flip_and_mmap_cpu",
> +		[TEST_PAGE_FLIP_AND_MMAP_GTT] = "page_flip_and_mmap_gtt",
> +		[TEST_PAGE_FLIP_AND_BLT] = "page_flip_and_blt",
> +		[TEST_PAGE_FLIP_AND_RENDER] = "page_flip_and_render",
> +		[TEST_PAGE_FLIP_AND_CONTEXT] = "page_flip_and_context",
> +	};
> +
> +	return test_modes[mode];
> +}
> +
> +static uint32_t create_fb(data_t *data,
> +			  int w, int h,
> +			  double r, double g, double b,
> +			  struct kmstest_fb *fb)
> +{
> +	uint32_t fb_id;
> +	cairo_t *cr;
> +
> +	fb_id = kmstest_create_fb2(data->drm_fd, w, h,
> +				   DRM_FORMAT_XRGB8888, true, fb);
> +	igt_assert(fb_id);
> +
> +	cr = kmstest_get_cairo_ctx(data->drm_fd, fb);
> +	kmstest_paint_color(cr, 0, 0, w, h, r, g, b);
> +	igt_assert(cairo_status(cr) == 0);
> +
> +	return fb_id;
> +}
> +
> +static bool
> +connector_set_mode(data_t *data, connector_t *connector,
> +		   drmModeModeInfo *mode, uint32_t fb_id)
> +{
> +	struct kmstest_connector_config *config = &connector->config;
> +	int ret;
> +
> +#if 0
> +	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
> +		mode->hdisplay, mode->vdisplay);
> +#endif
> +
> +	ret = drmModeSetCrtc(data->drm_fd,
> +			     config->crtc->crtc_id,
> +			     fb_id,
> +			     0, 0, /* x, y */
> +			     &config->connector->connector_id,
> +			     1,
> +			     mode);
> +	igt_assert(ret == 0);
> +
> +	return 0;
> +}
> +
> +static void display_init(data_t *data)
> +{
> +	data->resources = drmModeGetResources(data->drm_fd);
> +	igt_assert(data->resources);
> +
> +	data->pipe_crc = calloc(data->resources->count_crtcs, sizeof(data->pipe_crc[0]));
> +}
> +
> +static void display_fini(data_t *data)
> +{
> +	free(data->pipe_crc);
> +}
> +
> +static void fill_blt(data_t *data, uint32_t handle, unsigned char color)
> +{
> +	drm_intel_bo *dst = gem_handle_to_libdrm_bo(data->bufmgr,
> +						    data->drm_fd,
> +						    "", handle);
> +	struct intel_batchbuffer *batch;
> +
> +	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
> +	igt_assert(batch);
> +
> +	BEGIN_BATCH(5);
> +	OUT_BATCH(COLOR_BLT_CMD);
> +	OUT_BATCH((1 << 24) | (0xf0 << 16) | 0);
> +	OUT_BATCH(1 << 16 | 4);
> +	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
> +	OUT_BATCH(color);
> +	ADVANCE_BATCH();
> +
> +	intel_batchbuffer_flush(batch);
> +	intel_batchbuffer_free(batch);
> +}
> +
> +
> +static void scratch_buf_init(struct scratch_buf *buf, drm_intel_bo *bo)
> +{
> +	buf->bo = bo;
> +	buf->stride = 4096;
> +	buf->tiling = I915_TILING_X;
> +	buf->size = 4096;
> +}
> +
> +static void exec_nop(data_t *data, uint32_t handle, drm_intel_context *context)
> +{
> +	drm_intel_bo *dst;
> +	struct intel_batchbuffer *batch;
> +
> +	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
> +	igt_assert(dst);
> +
> +	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
> +	igt_assert(batch);
> +
> +	/* add the reloc to make sure the kernel will think we write to dst */
> +	BEGIN_BATCH(4);
> +	OUT_BATCH(MI_BATCH_BUFFER_END);
> +	OUT_BATCH(MI_NOOP);
> +	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
> +	OUT_BATCH(MI_NOOP);
> +	ADVANCE_BATCH();
> +
> +	intel_batchbuffer_flush_with_context(batch, context);
> +	intel_batchbuffer_free(batch);
> +}
> +
> +static void fill_render(data_t *data, uint32_t handle,
> +			drm_intel_context *context, unsigned char color)
> +{
> +	drm_intel_bo *src, *dst;
> +	struct intel_batchbuffer *batch;
> +	struct scratch_buf src_buf, dst_buf;
> +	const uint8_t buf[4] = { color, color, color, color };
> +	render_copyfunc_t rendercopy = get_render_copyfunc(data->devid);
> +
> +	igt_skip_on(!rendercopy);
> +
> +	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
> +	igt_assert(dst);
> +
> +	src = drm_intel_bo_alloc(data->bufmgr, "", 4096, 4096);
> +	igt_assert(src);
> +
> +	gem_write(data->drm_fd, src->handle, 0, buf, 4);
> +
> +	scratch_buf_init(&src_buf, src);
> +	scratch_buf_init(&dst_buf, dst);
> +
> +	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
> +	igt_assert(batch);
> +
> +	rendercopy(batch, context,
> +		   &src_buf, 0, 0, 1, 1,
> +		   &dst_buf, 0, 0);
> +
> +	intel_batchbuffer_free(batch);
> +}
> +
> +static bool fbc_enabled(data_t *data)
> +{
> +	FILE *status;
> +	char str[64] = {};
> +
> +	status = igt_debugfs_fopen(&data->debugfs, "i915_fbc_status", "r");
> +	fread(str, sizeof(str) - 1, 1, status);
> +	fclose(status);
> +	return strstr(str, "FBC enabled") != NULL;
> +}
> +
> +static void test_crc(data_t *data, enum test_mode mode)
> +{
> +	static const unsigned char buf[1] = { 0xcc };
> +	igt_pipe_crc_t *pipe_crc = data->pipe_crc[data->crtc_idx];
> +	igt_crc_t *crcs = NULL;
> +	uint32_t handle = data->handle[0];
> +	uint32_t fb_id = data->fb_id[0];
> +
> +	igt_assert(fbc_enabled(data));
> +
> +	if (mode >= TEST_PAGE_FLIP_AND_PWRITE) {
> +		handle = data->handle[1];
> +		fb_id = data->fb_id[1];
> +		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
> +					   data->fb_id[1], 0, NULL) == 0);
> +		usleep(300000);
> +
> +		igt_assert(fbc_enabled(data));
> +	}
> +

In general please ditch all drmDirtyFB calls. Even if we eventually decide
to use it we need to keep legacy userspace working. Maybe give the current
tests a "-legacy" suffix to make this clear, then we can add "-dirtyfb"
tests later on.
> +	switch (mode) {
> +		void *ptr;
> +	case TEST_PAGE_FLIP:
> +		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
> +					   data->fb_id[1], 0, NULL) == 0);
> +		break;
> +	case TEST_PWRITE:

pwrite isn't really supported for frontbuffer rendering. Only exception
are cursor updates, where a simple pwrite is all that's needed. So this is
only relevant for psr (but definitely something psr gets wrong).

> +	case TEST_PAGE_FLIP_AND_PWRITE:
> +		gem_write(data->drm_fd, handle, 0, buf, 1);
> +		igt_assert(drmModeDirtyFB(data->drm_fd, fb_id, NULL, 0) == 0);
> +		break;
> +	case TEST_MMAP_CPU:

cpu mmaps must use the set_to_cpu_domain before and sw_finish ioctl calls
afterwards.

> +	case TEST_PAGE_FLIP_AND_MMAP_CPU:
> +		ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
> +		memset(ptr, 0xff, 4);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
> +		munmap(ptr, 4096);
> +		igt_assert(drmModeDirtyFB(data->drm_fd, fb_id, NULL, 0) == 0);
> +		break;
> +	case TEST_MMAP_GTT:

gtt mmap writes must do a set_to_gtt_domain before the write (the raw
helpers in drmtest.c don't do that for you). There is _no_ operation/ioctl
done after the writes. Which means if we don't have hardware tracking for
screen updates then we either need to disable fbc/psr in the kernel in the
set_domain ioctl or we need to set up a timer to tear down the gtt mmap
ptes after a bit of time and then force a screen update.


> +	case TEST_PAGE_FLIP_AND_MMAP_GTT:
> +		ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
> +		memset(ptr, 0xff, 4);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
> +		munmap(ptr, 4096);
> +		break;
> +	case TEST_BLT:
> +	case TEST_PAGE_FLIP_AND_BLT:
> +		fill_blt(data, handle, 0xff);
> +		break;
> +	case TEST_RENDER:
> +	case TEST_CONTEXT:

Legacy rules say that you must do a busy ioctl call on the frontbuffer to
flush out rendering. If you don't do that screen updates may get stuck
(and on older kernels they actually will be stuck in the render cache).
Imo we should exploit this for tracking gpu writes (at least it would
allow us to ditch the hw tracking without too much fuzz to get back the
performance penalty currently incurred due to fbc).

> +	case TEST_PAGE_FLIP_AND_RENDER:
> +	case TEST_PAGE_FLIP_AND_CONTEXT:
> +		fill_render(data, handle,
> +			    (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) ?
> +			    data->ctx[1] : NULL, 0xff);
> +		break;
> +	}
> +
> +	/* make sure we're looking at new data */
> +	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);

Given that we should allow the kernel some leeway in how quickly it
updates the screen I think we want 2 vblanks here. Otoh the pipe crc also
has it's own vblank wait in _start, so we should be good. But it might
help for documentation.

> +
> +	igt_pipe_crc_start(pipe_crc);
> +	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
> +	igt_pipe_crc_stop(pipe_crc);
> +	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
> +	if (mode == TEST_PAGE_FLIP)
> +		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
> +	else
> +		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
> +	free(crcs);
> +
> +	/*
> +	 * Allow time for FBC to kick in again if it
> +	 * got disabled during dirtyfb or page flip.
> +	 */
> +	usleep(300000);
> +
> +	igt_assert(fbc_enabled(data));
> +
> +	igt_pipe_crc_start(pipe_crc);
> +	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
> +	igt_pipe_crc_stop(pipe_crc);
> +	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
> +	if (mode == TEST_PAGE_FLIP)
> +		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
> +	else
> +		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
> +	free(crcs);
> +}
> +
> +static bool prepare_crtc(data_t *data, uint32_t connector_id, enum test_mode mode)
> +{
> +	igt_pipe_crc_t *pipe_crc;
> +	igt_crc_t *crcs = NULL;
> +	connector_t connector;
> +	int ret;
> +
> +	ret = kmstest_get_connector_config(data->drm_fd,
> +					   connector_id,
> +					   1 << data->crtc_idx,
> +					   &connector.config);
> +	if (ret)
> +		return false;
> +
> +	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
> +	data->pipe_crc[data->crtc_idx] = NULL;
> +
> +	pipe_crc = igt_pipe_crc_new(&data->debugfs,
> +				    data->drm_fd, data->crtc_idx,
> +				    INTEL_PIPE_CRC_SOURCE_AUTO);
> +	if (!pipe_crc) {
> +		printf("auto crc not supported on this connector with crtc %i\n",
> +		       data->crtc_idx);
> +		return false;
> +	}
> +
> +	data->pipe_crc[data->crtc_idx] = pipe_crc;
> +
> +	data->fb_id[0] = create_fb(data,
> +				   connector.config.default_mode.hdisplay,
> +				   connector.config.default_mode.vdisplay,
> +				   0.0, 0.0, 0.0, &connector.fb[0]);
> +	igt_assert(data->fb_id[0]);
> +
> +	data->fb_id[1] = create_fb(data,
> +				   connector.config.default_mode.hdisplay,
> +				   connector.config.default_mode.vdisplay,
> +				   0.1, 0.1, 0.1, &connector.fb[1]);
> +	igt_assert(data->fb_id[1]);
> +
> +	data->handle[0] = connector.fb[0].gem_handle;
> +	data->handle[1] = connector.fb[1].gem_handle;
> +
> +	/* scanout = fb[1] */
> +	connector_set_mode(data, &connector, &connector.config.default_mode,
> +			   data->fb_id[1]);
> +	usleep(300000);
> +
> +	igt_skip_on(!fbc_enabled(data));
> +
> +	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
> +
> +	/* get reference crc for fb[1] */
> +	igt_pipe_crc_start(pipe_crc);
> +	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
> +	data->ref_crc[1] = crcs[0];
> +	igt_pipe_crc_stop(pipe_crc);
> +	free(crcs);
> +
> +	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
> +		data->ctx[0] = drm_intel_gem_context_create(data->bufmgr);
> +		igt_require(data->ctx[0]);
> +		data->ctx[1] = drm_intel_gem_context_create(data->bufmgr);
> +		igt_require(data->ctx[1]);
> +
> +		/*
> +		 * Disable FBC RT address for both contexts
> +		 * (by "rendering" to a non-scanout buffer).
> +		 */
> +		exec_nop(data, data->handle[0], data->ctx[1]);
> +		exec_nop(data, data->handle[0], data->ctx[0]);
> +		exec_nop(data, data->handle[0], data->ctx[1]);
> +		exec_nop(data, data->handle[0], data->ctx[0]);
> +	}
> +
> +	/* scanout = fb[0] */
> +	connector_set_mode(data, &connector, &connector.config.default_mode,
> +			   data->fb_id[0]);
> +	usleep(300000);
> +
> +	igt_skip_on(!fbc_enabled(data));
> +
> +	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
> +		/*
> +		 * make ctx[0] FBC RT address point to fb[0], ctx[1]
> +		 * FBC RT address is left as disabled.
> +		 */
> +		exec_nop(data, connector.fb[0].gem_handle, data->ctx[0]);
> +	}
> +
> +	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
> +
> +	/* get reference crc for fb[0] */
> +	igt_pipe_crc_start(pipe_crc);
> +	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
> +	data->ref_crc[0] = crcs[0];
> +	igt_pipe_crc_stop(pipe_crc);
> +	free(crcs);
> +
> +	kmstest_free_connector_config(&connector.config);
> +
> +	return true;
> +}
> +
> +static void finish_crtc(data_t *data, enum test_mode mode)
> +{
> +	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
> +	data->pipe_crc[data->crtc_idx] = NULL;
> +
> +	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
> +		drm_intel_gem_context_destroy(data->ctx[0]);
> +		drm_intel_gem_context_destroy(data->ctx[1]);
> +	}
> +}
> +
> +static void run_test(data_t *data, enum test_mode mode)
> +{
> +	int i, n;
> +
> +	for (i = 0; i < data->resources->count_connectors; i++) {
> +		uint32_t connector_id = data->resources->connectors[i];
> +
> +		for (n = 0; n < data->resources->count_crtcs; n++) {
> +			data->crtc_idx = n;
> +			data->crtc_id = data->resources->crtcs[n];
> +
> +			if (!prepare_crtc(data, connector_id, mode))
> +				continue;
> +
> +			fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
> +				igt_subtest_name(), data->crtc_id, connector_id);
> +			test_crc(data, mode);
> +
> +			fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
> +				igt_subtest_name(), data->crtc_id, connector_id);
> +
> +			finish_crtc(data, mode);
> +		}
> +	}
> +}
> +
> +igt_main
> +{
> +	data_t data = {};
> +	enum test_mode mode;
> +
> +	igt_skip_on_simulation();
> +
> +	igt_fixture {
> +		size_t written;
> +		int ret;
> +		const char *cmd = "pipe A none";
> +		char buf[64];
> +		FILE *status;
> +
> +		data.drm_fd = drm_open_any();
> +		igt_require(data.drm_fd);
> +		igt_set_vt_graphics_mode();
> +
> +		data.devid = intel_get_drm_devid(data.drm_fd);
> +
> +		igt_debugfs_init(&data.debugfs);
> +		data.ctl = igt_debugfs_fopen(&data.debugfs,
> +					     "i915_display_crc_ctl", "r+");
> +		igt_require_f(data.ctl,
> +			      "No display_crc_ctl found, kernel too old\n");
> +		written = fwrite(cmd, 1, strlen(cmd), data.ctl);
> +		ret = fflush(data.ctl);
> +		igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
> +			      "CRCs not supported on this platform\n");
> +
> +		status = igt_debugfs_fopen(&data.debugfs, "i915_fbc_status", "r");
> +		igt_require_f(status, "No i915_fbc_status found\n");
> +		fread(buf, sizeof(buf), 1, status);
> +		fclose(status);
> +		buf[sizeof(buf) - 1] = '\0';
> +		igt_require_f(!strstr(buf, "unsupported by this chipset") &&
> +			      !strstr(buf, "disabled per module param") &&
> +			      !strstr(buf, "disabled per chip default"),
> +			      "FBC not supported/enabled\n");
> +
> +		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
> +		igt_assert(data.bufmgr);
> +		drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
> +
> +		display_init(&data);
> +	}
> +
> +	for (mode = TEST_PAGE_FLIP; mode <= TEST_PAGE_FLIP_AND_CONTEXT; mode++) {
> +		igt_subtest_f("%s", test_mode_str(mode)) {
> +			run_test(&data, mode);
> +		}
> +	}
> +
> +	igt_fixture {
> +		drm_intel_bufmgr_destroy(data.bufmgr);
> +		display_fini(&data);
> +		fclose(data.ctl);
> +	}
> +}
> -- 
> 1.8.3.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* [PATCH 1/2] lib: Add gem_sw_finish()
  2013-11-21 19:33 ` [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
  2013-11-25  9:18   ` Daniel Vetter
@ 2013-11-25 15:08   ` ville.syrjala
  2013-11-25 15:08     ` [PATCH v2 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
  1 sibling, 1 reply; 8+ messages in thread
From: ville.syrjala @ 2013-11-25 15:08 UTC (permalink / raw)
  To: intel-gfx

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

Wrap DRM_IOCTL_I915_GEM_SW_FINISH into gem_sw_finish()

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

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 15ed847..6544128 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -632,6 +632,16 @@ uint32_t gem_context_create(int fd)
 	return create.ctx_id;
 }
 
+void gem_sw_finish(int fd, uint32_t handle)
+{
+	struct drm_i915_gem_sw_finish finish;
+
+	finish.handle = handle;
+
+	do_ioctl(fd, DRM_IOCTL_I915_GEM_SW_FINISH, &finish);
+}
+
+
 /* prime */
 int prime_handle_to_fd(int fd, uint32_t handle)
 {
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 5295a7b..1a243b1 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -85,6 +85,8 @@ int gem_madvise(int fd, uint32_t handle, int state);
 
 uint32_t gem_context_create(int fd);
 
+void gem_sw_finish(int fd, uint32_t handle);
+
 /* feature test helpers */
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH v2 2/2] kms_fbc_crc: Add a CRC based FBC test
  2013-11-25 15:08   ` [PATCH 1/2] lib: Add gem_sw_finish() ville.syrjala
@ 2013-11-25 15:08     ` ville.syrjala
  2013-11-25 15:19       ` Daniel Vetter
  0 siblings, 1 reply; 8+ messages in thread
From: ville.syrjala @ 2013-11-25 15:08 UTC (permalink / raw)
  To: intel-gfx

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

kms_fbc_crc will perform various write operations to the scanout buffer
whilc FBC is enabled. CRC checks will be used to make sure the
modifcations to scanout buffer are detected.

The operations include:
 - page flip
 - pwrite
 - GTT mmap
 - CPU mmap
 - blit
 - rendercopy
 - context switch + rendercopy
 - combination of a page flip and each operation listed above

v2: Use gem_sw_finish instead of drmModeDirtyFB after CPU access

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 tests/Makefile.sources |   1 +
 tests/kms_fbc_crc.c    | 542 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 543 insertions(+)
 create mode 100644 tests/kms_fbc_crc.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index a02b93d..d201809 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -49,6 +49,7 @@ TESTS_progs_M = \
 	gem_write_read_ring_switch \
 	kms_addfb \
 	kms_cursor_crc \
+	kms_fbc_crc \
 	kms_flip \
 	kms_pipe_crc_basic \
 	kms_render \
diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c
new file mode 100644
index 0000000..bde4d8b
--- /dev/null
+++ b/tests/kms_fbc_crc.c
@@ -0,0 +1,542 @@
+/*
+ * Copyright © 2013 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 <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include "drm_fourcc.h"
+
+#include "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "rendercopy.h"
+
+enum test_mode {
+	TEST_PAGE_FLIP,
+	TEST_PWRITE,
+	TEST_MMAP_CPU,
+	TEST_MMAP_GTT,
+	TEST_BLT,
+	TEST_RENDER,
+	TEST_CONTEXT,
+	TEST_PAGE_FLIP_AND_PWRITE,
+	TEST_PAGE_FLIP_AND_MMAP_CPU,
+	TEST_PAGE_FLIP_AND_MMAP_GTT,
+	TEST_PAGE_FLIP_AND_BLT,
+	TEST_PAGE_FLIP_AND_RENDER,
+	TEST_PAGE_FLIP_AND_CONTEXT,
+};
+
+typedef struct {
+	struct kmstest_connector_config config;
+	drmModeModeInfo mode;
+	struct kmstest_fb fb[2];
+} connector_t;
+
+typedef struct {
+	int drm_fd;
+	igt_debugfs_t debugfs;
+	drmModeRes *resources;
+	FILE *ctl;
+	igt_crc_t ref_crc[2];
+	igt_pipe_crc_t **pipe_crc;
+	drm_intel_bufmgr *bufmgr;
+	drm_intel_context *ctx[2];
+	uint32_t devid;
+	uint32_t handle[2];
+	uint32_t crtc_id;
+	uint32_t crtc_idx;
+	uint32_t fb_id[2];
+} data_t;
+
+static const char *test_mode_str(enum test_mode mode)
+{
+	static const char * const test_modes[] = {
+		[TEST_PAGE_FLIP] = "page_flip",
+		[TEST_PWRITE] = "pwrite",
+		[TEST_MMAP_CPU] = "mmap_cpu",
+		[TEST_MMAP_GTT] = "mmap_gtt",
+		[TEST_BLT] = "blt",
+		[TEST_RENDER] = "render",
+		[TEST_CONTEXT] = "context",
+		[TEST_PAGE_FLIP_AND_PWRITE] = "page_flip_and_pwrite",
+		[TEST_PAGE_FLIP_AND_MMAP_CPU] = "page_flip_and_mmap_cpu",
+		[TEST_PAGE_FLIP_AND_MMAP_GTT] = "page_flip_and_mmap_gtt",
+		[TEST_PAGE_FLIP_AND_BLT] = "page_flip_and_blt",
+		[TEST_PAGE_FLIP_AND_RENDER] = "page_flip_and_render",
+		[TEST_PAGE_FLIP_AND_CONTEXT] = "page_flip_and_context",
+	};
+
+	return test_modes[mode];
+}
+
+static uint32_t create_fb(data_t *data,
+			  int w, int h,
+			  double r, double g, double b,
+			  struct kmstest_fb *fb)
+{
+	uint32_t fb_id;
+	cairo_t *cr;
+
+	fb_id = kmstest_create_fb2(data->drm_fd, w, h,
+				   DRM_FORMAT_XRGB8888, true, fb);
+	igt_assert(fb_id);
+
+	cr = kmstest_get_cairo_ctx(data->drm_fd, fb);
+	kmstest_paint_color(cr, 0, 0, w, h, r, g, b);
+	igt_assert(cairo_status(cr) == 0);
+
+	return fb_id;
+}
+
+static bool
+connector_set_mode(data_t *data, connector_t *connector,
+		   drmModeModeInfo *mode, uint32_t fb_id)
+{
+	struct kmstest_connector_config *config = &connector->config;
+	int ret;
+
+#if 0
+	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
+		mode->hdisplay, mode->vdisplay);
+#endif
+
+	ret = drmModeSetCrtc(data->drm_fd,
+			     config->crtc->crtc_id,
+			     fb_id,
+			     0, 0, /* x, y */
+			     &config->connector->connector_id,
+			     1,
+			     mode);
+	igt_assert(ret == 0);
+
+	return 0;
+}
+
+static void display_init(data_t *data)
+{
+	data->resources = drmModeGetResources(data->drm_fd);
+	igt_assert(data->resources);
+
+	data->pipe_crc = calloc(data->resources->count_crtcs, sizeof(data->pipe_crc[0]));
+}
+
+static void display_fini(data_t *data)
+{
+	free(data->pipe_crc);
+}
+
+static void fill_blt(data_t *data, uint32_t handle, unsigned char color)
+{
+	drm_intel_bo *dst = gem_handle_to_libdrm_bo(data->bufmgr,
+						    data->drm_fd,
+						    "", handle);
+	struct intel_batchbuffer *batch;
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	BEGIN_BATCH(5);
+	OUT_BATCH(COLOR_BLT_CMD);
+	OUT_BATCH((1 << 24) | (0xf0 << 16) | 0);
+	OUT_BATCH(1 << 16 | 4);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(color);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush(batch);
+	intel_batchbuffer_free(batch);
+}
+
+
+static void scratch_buf_init(struct scratch_buf *buf, drm_intel_bo *bo)
+{
+	buf->bo = bo;
+	buf->stride = 4096;
+	buf->tiling = I915_TILING_X;
+	buf->size = 4096;
+}
+
+static void exec_nop(data_t *data, uint32_t handle, drm_intel_context *context)
+{
+	drm_intel_bo *dst;
+	struct intel_batchbuffer *batch;
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	/* add the reloc to make sure the kernel will think we write to dst */
+	BEGIN_BATCH(4);
+	OUT_BATCH(MI_BATCH_BUFFER_END);
+	OUT_BATCH(MI_NOOP);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(MI_NOOP);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush_with_context(batch, context);
+	intel_batchbuffer_free(batch);
+}
+
+static void fill_render(data_t *data, uint32_t handle,
+			drm_intel_context *context, unsigned char color)
+{
+	drm_intel_bo *src, *dst;
+	struct intel_batchbuffer *batch;
+	struct scratch_buf src_buf, dst_buf;
+	const uint8_t buf[4] = { color, color, color, color };
+	render_copyfunc_t rendercopy = get_render_copyfunc(data->devid);
+
+	igt_skip_on(!rendercopy);
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	src = drm_intel_bo_alloc(data->bufmgr, "", 4096, 4096);
+	igt_assert(src);
+
+	gem_write(data->drm_fd, src->handle, 0, buf, 4);
+
+	scratch_buf_init(&src_buf, src);
+	scratch_buf_init(&dst_buf, dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	rendercopy(batch, context,
+		   &src_buf, 0, 0, 1, 1,
+		   &dst_buf, 0, 0);
+
+	intel_batchbuffer_free(batch);
+}
+
+static bool fbc_enabled(data_t *data)
+{
+	FILE *status;
+	char str[64] = {};
+
+	status = igt_debugfs_fopen(&data->debugfs, "i915_fbc_status", "r");
+	fread(str, sizeof(str) - 1, 1, status);
+	fclose(status);
+	return strstr(str, "FBC enabled") != NULL;
+}
+
+static void test_crc(data_t *data, enum test_mode mode)
+{
+	static const unsigned char buf[1] = { 0xcc };
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc[data->crtc_idx];
+	igt_crc_t *crcs = NULL;
+	uint32_t handle = data->handle[0];
+
+	igt_assert(fbc_enabled(data));
+
+	if (mode >= TEST_PAGE_FLIP_AND_PWRITE) {
+		handle = data->handle[1];
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		usleep(300000);
+
+		igt_assert(fbc_enabled(data));
+	}
+
+	switch (mode) {
+		void *ptr;
+	case TEST_PAGE_FLIP:
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		break;
+	case TEST_PWRITE:
+	case TEST_PAGE_FLIP_AND_PWRITE:
+		gem_write(data->drm_fd, handle, 0, buf, 1);
+		gem_sw_finish(data->drm_fd, handle);
+		break;
+	case TEST_MMAP_CPU:
+	case TEST_PAGE_FLIP_AND_MMAP_CPU:
+		ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+		memset(ptr, 0xff, 4);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
+		munmap(ptr, 4096);
+		gem_sw_finish(data->drm_fd, handle);
+		break;
+	case TEST_MMAP_GTT:
+	case TEST_PAGE_FLIP_AND_MMAP_GTT:
+		ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+		memset(ptr, 0xff, 4);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);
+		munmap(ptr, 4096);
+		break;
+	case TEST_BLT:
+	case TEST_PAGE_FLIP_AND_BLT:
+		fill_blt(data, handle, 0xff);
+		break;
+	case TEST_RENDER:
+	case TEST_CONTEXT:
+	case TEST_PAGE_FLIP_AND_RENDER:
+	case TEST_PAGE_FLIP_AND_CONTEXT:
+		fill_render(data, handle,
+			    (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) ?
+			    data->ctx[1] : NULL, 0xff);
+		break;
+	}
+
+	/* make sure we're looking at new data */
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+
+	/*
+	 * Allow time for FBC to kick in again if it
+	 * got disabled during dirtyfb or page flip.
+	 */
+	usleep(300000);
+
+	igt_assert(fbc_enabled(data));
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+}
+
+static bool prepare_crtc(data_t *data, uint32_t connector_id, enum test_mode mode)
+{
+	igt_pipe_crc_t *pipe_crc;
+	igt_crc_t *crcs = NULL;
+	connector_t connector;
+	int ret;
+
+	ret = kmstest_get_connector_config(data->drm_fd,
+					   connector_id,
+					   1 << data->crtc_idx,
+					   &connector.config);
+	if (ret)
+		return false;
+
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	pipe_crc = igt_pipe_crc_new(&data->debugfs,
+				    data->drm_fd, data->crtc_idx,
+				    INTEL_PIPE_CRC_SOURCE_AUTO);
+	if (!pipe_crc) {
+		printf("auto crc not supported on this connector with crtc %i\n",
+		       data->crtc_idx);
+		return false;
+	}
+
+	data->pipe_crc[data->crtc_idx] = pipe_crc;
+
+	data->fb_id[0] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.0, 0.0, 0.0, &connector.fb[0]);
+	igt_assert(data->fb_id[0]);
+
+	data->fb_id[1] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.1, 0.1, 0.1, &connector.fb[1]);
+	igt_assert(data->fb_id[1]);
+
+	data->handle[0] = connector.fb[0].gem_handle;
+	data->handle[1] = connector.fb[1].gem_handle;
+
+	/* scanout = fb[1] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[1]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[1] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[1] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		data->ctx[0] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[0]);
+		data->ctx[1] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[1]);
+
+		/*
+		 * Disable FBC RT address for both contexts
+		 * (by "rendering" to a non-scanout buffer).
+		 */
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+	}
+
+	/* scanout = fb[0] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[0]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		/*
+		 * make ctx[0] FBC RT address point to fb[0], ctx[1]
+		 * FBC RT address is left as disabled.
+		 */
+		exec_nop(data, connector.fb[0].gem_handle, data->ctx[0]);
+	}
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[0] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[0] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	kmstest_free_connector_config(&connector.config);
+
+	return true;
+}
+
+static void finish_crtc(data_t *data, enum test_mode mode)
+{
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		drm_intel_gem_context_destroy(data->ctx[0]);
+		drm_intel_gem_context_destroy(data->ctx[1]);
+	}
+}
+
+static void run_test(data_t *data, enum test_mode mode)
+{
+	int i, n;
+
+	for (i = 0; i < data->resources->count_connectors; i++) {
+		uint32_t connector_id = data->resources->connectors[i];
+
+		for (n = 0; n < data->resources->count_crtcs; n++) {
+			data->crtc_idx = n;
+			data->crtc_id = data->resources->crtcs[n];
+
+			if (!prepare_crtc(data, connector_id, mode))
+				continue;
+
+			fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+			test_crc(data, mode);
+
+			fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+
+			finish_crtc(data, mode);
+		}
+	}
+}
+
+igt_main
+{
+	data_t data = {};
+	enum test_mode mode;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		size_t written;
+		int ret;
+		const char *cmd = "pipe A none";
+		char buf[64];
+		FILE *status;
+
+		data.drm_fd = drm_open_any();
+		igt_require(data.drm_fd);
+		igt_set_vt_graphics_mode();
+
+		data.devid = intel_get_drm_devid(data.drm_fd);
+
+		igt_debugfs_init(&data.debugfs);
+		data.ctl = igt_debugfs_fopen(&data.debugfs,
+					     "i915_display_crc_ctl", "r+");
+		igt_require_f(data.ctl,
+			      "No display_crc_ctl found, kernel too old\n");
+		written = fwrite(cmd, 1, strlen(cmd), data.ctl);
+		ret = fflush(data.ctl);
+		igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
+			      "CRCs not supported on this platform\n");
+
+		status = igt_debugfs_fopen(&data.debugfs, "i915_fbc_status", "r");
+		igt_require_f(status, "No i915_fbc_status found\n");
+		fread(buf, sizeof(buf), 1, status);
+		fclose(status);
+		buf[sizeof(buf) - 1] = '\0';
+		igt_require_f(!strstr(buf, "unsupported by this chipset") &&
+			      !strstr(buf, "disabled per module param") &&
+			      !strstr(buf, "disabled per chip default"),
+			      "FBC not supported/enabled\n");
+
+		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+		igt_assert(data.bufmgr);
+		drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
+
+		display_init(&data);
+	}
+
+	for (mode = TEST_PAGE_FLIP; mode <= TEST_PAGE_FLIP_AND_CONTEXT; mode++) {
+		igt_subtest_f("%s", test_mode_str(mode)) {
+			run_test(&data, mode);
+		}
+	}
+
+	igt_fixture {
+		drm_intel_bufmgr_destroy(data.bufmgr);
+		display_fini(&data);
+		fclose(data.ctl);
+	}
+}
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* Re: [PATCH v2 2/2] kms_fbc_crc: Add a CRC based FBC test
  2013-11-25 15:08     ` [PATCH v2 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
@ 2013-11-25 15:19       ` Daniel Vetter
  2013-11-25 16:51         ` [PATCH igt 1/2] lib: Add gem_bo_busy ville.syrjala
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2013-11-25 15:19 UTC (permalink / raw)
  To: ville.syrjala; +Cc: intel-gfx

On Mon, Nov 25, 2013 at 05:08:41PM +0200, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> kms_fbc_crc will perform various write operations to the scanout buffer
> whilc FBC is enabled. CRC checks will be used to make sure the
> modifcations to scanout buffer are detected.
> 
> The operations include:
>  - page flip
>  - pwrite
>  - GTT mmap
>  - CPU mmap
>  - blit
>  - rendercopy
>  - context switch + rendercopy
>  - combination of a page flip and each operation listed above
> 
> v2: Use gem_sw_finish instead of drmModeDirtyFB after CPU access
> 
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

[snip]

> +	switch (mode) {
> +		void *ptr;
> +	case TEST_PAGE_FLIP:
> +		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
> +					   data->fb_id[1], 0, NULL) == 0);
> +		break;
> +	case TEST_PWRITE:
> +	case TEST_PAGE_FLIP_AND_PWRITE:
> +		gem_write(data->drm_fd, handle, 0, buf, 1);
> +		gem_sw_finish(data->drm_fd, handle);

This one's too much. Like I've said current rules for pwrite is that
a) it's only used for cursors
b) no explicit flushing afterwards.
So the sw_finish here could potentially paper over kernel bugs (but only
for psr since fbc doesn't care about cursors).

> +		break;
> +	case TEST_MMAP_CPU:
> +	case TEST_PAGE_FLIP_AND_MMAP_CPU:
> +		ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
> +		memset(ptr, 0xff, 4);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);

Nope, that's a bug. There's not set_domain(GTT, 0) after a cpu mmap
operation, just the sw_finish ioctl call. set_domain is only done _before_
mmap access (yeah, a bit a design but in the original gem interface to no
have a begin/end pair).

> +		munmap(ptr, 4096);
> +		gem_sw_finish(data->drm_fd, handle);
> +		break;
> +	case TEST_MMAP_GTT:
> +	case TEST_PAGE_FLIP_AND_MMAP_GTT:
> +		ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
> +		memset(ptr, 0xff, 4);
> +		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, 0);

Again no set_domain after the writes have landed.

> +		munmap(ptr, 4096);
> +		break;
> +	case TEST_BLT:
> +	case TEST_PAGE_FLIP_AND_BLT:
> +		fill_blt(data, handle, 0xff);
> +		break;
> +	case TEST_RENDER:
> +	case TEST_CONTEXT:
> +	case TEST_PAGE_FLIP_AND_RENDER:
> +	case TEST_PAGE_FLIP_AND_CONTEXT:
> +		fill_render(data, handle,
> +			    (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) ?
> +			    data->ctx[1] : NULL, 0xff);

busy ioctl call on the render target/frontbuffer still seems to be
missing.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

* [PATCH igt 1/2] lib: Add gem_bo_busy
  2013-11-25 15:19       ` Daniel Vetter
@ 2013-11-25 16:51         ` ville.syrjala
  2013-11-25 16:51           ` [PATCH igt v3 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
  0 siblings, 1 reply; 8+ messages in thread
From: ville.syrjala @ 2013-11-25 16:51 UTC (permalink / raw)
  To: intel-gfx

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

Move gem_bo_busy() from gem_wait_render_timeout.c to lib.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/drmtest.c                   | 10 ++++++++++
 lib/drmtest.h                   |  2 ++
 tests/gem_wait_render_timeout.c | 11 -----------
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 6544128..8f6c74e 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -641,6 +641,16 @@ void gem_sw_finish(int fd, uint32_t handle)
 	do_ioctl(fd, DRM_IOCTL_I915_GEM_SW_FINISH, &finish);
 }
 
+bool gem_bo_busy(int fd, uint32_t handle)
+{
+	struct drm_i915_gem_busy busy;
+
+	busy.handle = handle;
+
+	do_ioctl(fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
+
+	return !!busy.busy;
+}
 
 /* prime */
 int prime_handle_to_fd(int fd, uint32_t handle)
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 1a243b1..5e831e5 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -87,6 +87,8 @@ uint32_t gem_context_create(int fd);
 
 void gem_sw_finish(int fd, uint32_t handle);
 
+bool gem_bo_busy(int fd, uint32_t handle);
+
 /* feature test helpers */
 bool gem_uses_aliasing_ppgtt(int fd);
 int gem_available_fences(int fd);
diff --git a/tests/gem_wait_render_timeout.c b/tests/gem_wait_render_timeout.c
index ae31729..3253d7f 100644
--- a/tests/gem_wait_render_timeout.c
+++ b/tests/gem_wait_render_timeout.c
@@ -80,17 +80,6 @@ gem_bo_wait_timeout(int fd, uint32_t handle, uint64_t *timeout_ns)
 	return ret ? -errno : 0;
 }
 
-static bool
-gem_bo_busy(int fd, uint32_t handle)
-{
-	struct drm_i915_gem_busy busy;
-
-	busy.handle = handle;
-	do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_BUSY, &busy));
-
-	return !!busy.busy;
-}
-
 static void blt_color_fill(struct intel_batchbuffer *batch,
 			   drm_intel_bo *buf,
 			   const unsigned int pages)
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

* [PATCH igt v3 2/2] kms_fbc_crc: Add a CRC based FBC test
  2013-11-25 16:51         ` [PATCH igt 1/2] lib: Add gem_bo_busy ville.syrjala
@ 2013-11-25 16:51           ` ville.syrjala
  0 siblings, 0 replies; 8+ messages in thread
From: ville.syrjala @ 2013-11-25 16:51 UTC (permalink / raw)
  To: intel-gfx

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

kms_fbc_crc will perform various write operations to the scanout buffer
whilc FBC is enabled. CRC checks will be used to make sure the
modifcations to scanout buffer are detected.

The operations include:
 - page flip
 - GTT mmap
 - CPU mmap
 - blit
 - rendercopy
 - context switch + rendercopy
 - combination of a page flip and each operation listed above

v2: Use gem_sw_finish instead of drmModeDirtyFB after CPU access
v3: Drop pwrite tests, call gem_bo_busy() after rendering, drop
    set_domain() calls after mmap access, wait for 2 vblanks

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 tests/Makefile.sources |   1 +
 tests/kms_fbc_crc.c    | 539 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 540 insertions(+)
 create mode 100644 tests/kms_fbc_crc.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index a02b93d..d201809 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -49,6 +49,7 @@ TESTS_progs_M = \
 	gem_write_read_ring_switch \
 	kms_addfb \
 	kms_cursor_crc \
+	kms_fbc_crc \
 	kms_flip \
 	kms_pipe_crc_basic \
 	kms_render \
diff --git a/tests/kms_fbc_crc.c b/tests/kms_fbc_crc.c
new file mode 100644
index 0000000..189988e
--- /dev/null
+++ b/tests/kms_fbc_crc.c
@@ -0,0 +1,539 @@
+/*
+ * Copyright © 2013 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 <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+#include "drm_fourcc.h"
+
+#include "drmtest.h"
+#include "igt_debugfs.h"
+#include "igt_kms.h"
+#include "rendercopy.h"
+
+enum test_mode {
+	TEST_PAGE_FLIP,
+	TEST_MMAP_CPU,
+	TEST_MMAP_GTT,
+	TEST_BLT,
+	TEST_RENDER,
+	TEST_CONTEXT,
+	TEST_PAGE_FLIP_AND_MMAP_CPU,
+	TEST_PAGE_FLIP_AND_MMAP_GTT,
+	TEST_PAGE_FLIP_AND_BLT,
+	TEST_PAGE_FLIP_AND_RENDER,
+	TEST_PAGE_FLIP_AND_CONTEXT,
+};
+
+typedef struct {
+	struct kmstest_connector_config config;
+	drmModeModeInfo mode;
+	struct kmstest_fb fb[2];
+} connector_t;
+
+typedef struct {
+	int drm_fd;
+	igt_debugfs_t debugfs;
+	drmModeRes *resources;
+	FILE *ctl;
+	igt_crc_t ref_crc[2];
+	igt_pipe_crc_t **pipe_crc;
+	drm_intel_bufmgr *bufmgr;
+	drm_intel_context *ctx[2];
+	uint32_t devid;
+	uint32_t handle[2];
+	uint32_t crtc_id;
+	uint32_t crtc_idx;
+	uint32_t fb_id[2];
+} data_t;
+
+static const char *test_mode_str(enum test_mode mode)
+{
+	static const char * const test_modes[] = {
+		[TEST_PAGE_FLIP] = "page_flip",
+		[TEST_MMAP_CPU] = "mmap_cpu",
+		[TEST_MMAP_GTT] = "mmap_gtt",
+		[TEST_BLT] = "blt",
+		[TEST_RENDER] = "render",
+		[TEST_CONTEXT] = "context",
+		[TEST_PAGE_FLIP_AND_MMAP_CPU] = "page_flip_and_mmap_cpu",
+		[TEST_PAGE_FLIP_AND_MMAP_GTT] = "page_flip_and_mmap_gtt",
+		[TEST_PAGE_FLIP_AND_BLT] = "page_flip_and_blt",
+		[TEST_PAGE_FLIP_AND_RENDER] = "page_flip_and_render",
+		[TEST_PAGE_FLIP_AND_CONTEXT] = "page_flip_and_context",
+	};
+
+	return test_modes[mode];
+}
+
+static uint32_t create_fb(data_t *data,
+			  int w, int h,
+			  double r, double g, double b,
+			  struct kmstest_fb *fb)
+{
+	uint32_t fb_id;
+	cairo_t *cr;
+
+	fb_id = kmstest_create_fb2(data->drm_fd, w, h,
+				   DRM_FORMAT_XRGB8888, true, fb);
+	igt_assert(fb_id);
+
+	cr = kmstest_get_cairo_ctx(data->drm_fd, fb);
+	kmstest_paint_color(cr, 0, 0, w, h, r, g, b);
+	igt_assert(cairo_status(cr) == 0);
+
+	return fb_id;
+}
+
+static bool
+connector_set_mode(data_t *data, connector_t *connector,
+		   drmModeModeInfo *mode, uint32_t fb_id)
+{
+	struct kmstest_connector_config *config = &connector->config;
+	int ret;
+
+#if 0
+	fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
+		mode->hdisplay, mode->vdisplay);
+#endif
+
+	ret = drmModeSetCrtc(data->drm_fd,
+			     config->crtc->crtc_id,
+			     fb_id,
+			     0, 0, /* x, y */
+			     &config->connector->connector_id,
+			     1,
+			     mode);
+	igt_assert(ret == 0);
+
+	return 0;
+}
+
+static void display_init(data_t *data)
+{
+	data->resources = drmModeGetResources(data->drm_fd);
+	igt_assert(data->resources);
+
+	data->pipe_crc = calloc(data->resources->count_crtcs, sizeof(data->pipe_crc[0]));
+}
+
+static void display_fini(data_t *data)
+{
+	free(data->pipe_crc);
+}
+
+static void fill_blt(data_t *data, uint32_t handle, unsigned char color)
+{
+	drm_intel_bo *dst = gem_handle_to_libdrm_bo(data->bufmgr,
+						    data->drm_fd,
+						    "", handle);
+	struct intel_batchbuffer *batch;
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	BEGIN_BATCH(5);
+	OUT_BATCH(COLOR_BLT_CMD);
+	OUT_BATCH((1 << 24) | (0xf0 << 16) | 0);
+	OUT_BATCH(1 << 16 | 4);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(color);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush(batch);
+	intel_batchbuffer_free(batch);
+
+	gem_bo_busy(data->drm_fd, handle);
+}
+
+static void scratch_buf_init(struct scratch_buf *buf, drm_intel_bo *bo)
+{
+	buf->bo = bo;
+	buf->stride = 4096;
+	buf->tiling = I915_TILING_X;
+	buf->size = 4096;
+}
+
+static void exec_nop(data_t *data, uint32_t handle, drm_intel_context *context)
+{
+	drm_intel_bo *dst;
+	struct intel_batchbuffer *batch;
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	/* add the reloc to make sure the kernel will think we write to dst */
+	BEGIN_BATCH(4);
+	OUT_BATCH(MI_BATCH_BUFFER_END);
+	OUT_BATCH(MI_NOOP);
+	OUT_RELOC(dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+	OUT_BATCH(MI_NOOP);
+	ADVANCE_BATCH();
+
+	intel_batchbuffer_flush_with_context(batch, context);
+	intel_batchbuffer_free(batch);
+}
+
+static void fill_render(data_t *data, uint32_t handle,
+			drm_intel_context *context, unsigned char color)
+{
+	drm_intel_bo *src, *dst;
+	struct intel_batchbuffer *batch;
+	struct scratch_buf src_buf, dst_buf;
+	const uint8_t buf[4] = { color, color, color, color };
+	render_copyfunc_t rendercopy = get_render_copyfunc(data->devid);
+
+	igt_skip_on(!rendercopy);
+
+	dst = gem_handle_to_libdrm_bo(data->bufmgr, data->drm_fd, "", handle);
+	igt_assert(dst);
+
+	src = drm_intel_bo_alloc(data->bufmgr, "", 4096, 4096);
+	igt_assert(src);
+
+	gem_write(data->drm_fd, src->handle, 0, buf, 4);
+
+	scratch_buf_init(&src_buf, src);
+	scratch_buf_init(&dst_buf, dst);
+
+	batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
+	igt_assert(batch);
+
+	rendercopy(batch, context,
+		   &src_buf, 0, 0, 1, 1,
+		   &dst_buf, 0, 0);
+
+	intel_batchbuffer_free(batch);
+
+	gem_bo_busy(data->drm_fd, handle);
+}
+
+static bool fbc_enabled(data_t *data)
+{
+	FILE *status;
+	char str[64] = {};
+
+	status = igt_debugfs_fopen(&data->debugfs, "i915_fbc_status", "r");
+	fread(str, sizeof(str) - 1, 1, status);
+	fclose(status);
+	return strstr(str, "FBC enabled") != NULL;
+}
+
+static void test_crc(data_t *data, enum test_mode mode)
+{
+	static const unsigned char buf[1] = { 0xcc };
+	igt_pipe_crc_t *pipe_crc = data->pipe_crc[data->crtc_idx];
+	igt_crc_t *crcs = NULL;
+	uint32_t handle = data->handle[0];
+
+	igt_assert(fbc_enabled(data));
+
+	if (mode >= TEST_PAGE_FLIP_AND_MMAP_CPU) {
+		handle = data->handle[1];
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		usleep(300000);
+
+		igt_assert(fbc_enabled(data));
+	}
+
+	switch (mode) {
+		void *ptr;
+	case TEST_PAGE_FLIP:
+		igt_assert(drmModePageFlip(data->drm_fd, data->crtc_id,
+					   data->fb_id[1], 0, NULL) == 0);
+		break;
+	case TEST_MMAP_CPU:
+	case TEST_PAGE_FLIP_AND_MMAP_CPU:
+		ptr = gem_mmap__cpu(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+		memset(ptr, 0xff, 4);
+		munmap(ptr, 4096);
+		gem_sw_finish(data->drm_fd, handle);
+		break;
+	case TEST_MMAP_GTT:
+	case TEST_PAGE_FLIP_AND_MMAP_GTT:
+		ptr = gem_mmap__gtt(data->drm_fd, handle, 4096, PROT_WRITE);
+		gem_set_domain(data->drm_fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+		memset(ptr, 0xff, 4);
+		munmap(ptr, 4096);
+		break;
+	case TEST_BLT:
+	case TEST_PAGE_FLIP_AND_BLT:
+		fill_blt(data, handle, 0xff);
+		break;
+	case TEST_RENDER:
+	case TEST_CONTEXT:
+	case TEST_PAGE_FLIP_AND_RENDER:
+	case TEST_PAGE_FLIP_AND_CONTEXT:
+		fill_render(data, handle,
+			    (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) ?
+			    data->ctx[1] : NULL, 0xff);
+		break;
+	}
+
+	/*
+	 * Make sure we're looking at new data (two vblanks
+	 * to leave some leeway for the kernel if we ever do
+	 * some kind of delayed FBC disable for GTT mmaps.
+	 */
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+
+	/*
+	 * Allow time for FBC to kick in again if it
+	 * got disabled during dirtyfb or page flip.
+	 */
+	usleep(300000);
+
+	igt_assert(fbc_enabled(data));
+
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	igt_pipe_crc_stop(pipe_crc);
+	igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[0]));
+	if (mode == TEST_PAGE_FLIP)
+		igt_assert(igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	else
+		igt_assert(!igt_crc_equal(&crcs[0], &data->ref_crc[1]));
+	free(crcs);
+}
+
+static bool prepare_crtc(data_t *data, uint32_t connector_id, enum test_mode mode)
+{
+	igt_pipe_crc_t *pipe_crc;
+	igt_crc_t *crcs = NULL;
+	connector_t connector;
+	int ret;
+
+	ret = kmstest_get_connector_config(data->drm_fd,
+					   connector_id,
+					   1 << data->crtc_idx,
+					   &connector.config);
+	if (ret)
+		return false;
+
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	pipe_crc = igt_pipe_crc_new(&data->debugfs,
+				    data->drm_fd, data->crtc_idx,
+				    INTEL_PIPE_CRC_SOURCE_AUTO);
+	if (!pipe_crc) {
+		printf("auto crc not supported on this connector with crtc %i\n",
+		       data->crtc_idx);
+		return false;
+	}
+
+	data->pipe_crc[data->crtc_idx] = pipe_crc;
+
+	data->fb_id[0] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.0, 0.0, 0.0, &connector.fb[0]);
+	igt_assert(data->fb_id[0]);
+
+	data->fb_id[1] = create_fb(data,
+				   connector.config.default_mode.hdisplay,
+				   connector.config.default_mode.vdisplay,
+				   0.1, 0.1, 0.1, &connector.fb[1]);
+	igt_assert(data->fb_id[1]);
+
+	data->handle[0] = connector.fb[0].gem_handle;
+	data->handle[1] = connector.fb[1].gem_handle;
+
+	/* scanout = fb[1] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[1]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[1] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[1] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		data->ctx[0] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[0]);
+		data->ctx[1] = drm_intel_gem_context_create(data->bufmgr);
+		igt_require(data->ctx[1]);
+
+		/*
+		 * Disable FBC RT address for both contexts
+		 * (by "rendering" to a non-scanout buffer).
+		 */
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+		exec_nop(data, data->handle[0], data->ctx[1]);
+		exec_nop(data, data->handle[0], data->ctx[0]);
+	}
+
+	/* scanout = fb[0] */
+	connector_set_mode(data, &connector, &connector.config.default_mode,
+			   data->fb_id[0]);
+	usleep(300000);
+
+	igt_skip_on(!fbc_enabled(data));
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		/*
+		 * make ctx[0] FBC RT address point to fb[0], ctx[1]
+		 * FBC RT address is left as disabled.
+		 */
+		exec_nop(data, connector.fb[0].gem_handle, data->ctx[0]);
+	}
+
+	igt_wait_for_vblank(data->drm_fd, data->crtc_idx);
+
+	/* get reference crc for fb[0] */
+	igt_pipe_crc_start(pipe_crc);
+	igt_pipe_crc_get_crcs(pipe_crc, 1, &crcs);
+	data->ref_crc[0] = crcs[0];
+	igt_pipe_crc_stop(pipe_crc);
+	free(crcs);
+
+	kmstest_free_connector_config(&connector.config);
+
+	return true;
+}
+
+static void finish_crtc(data_t *data, enum test_mode mode)
+{
+	igt_pipe_crc_free(data->pipe_crc[data->crtc_idx]);
+	data->pipe_crc[data->crtc_idx] = NULL;
+
+	if (mode == TEST_CONTEXT || mode == TEST_PAGE_FLIP_AND_CONTEXT) {
+		drm_intel_gem_context_destroy(data->ctx[0]);
+		drm_intel_gem_context_destroy(data->ctx[1]);
+	}
+}
+
+static void run_test(data_t *data, enum test_mode mode)
+{
+	int i, n;
+
+	for (i = 0; i < data->resources->count_connectors; i++) {
+		uint32_t connector_id = data->resources->connectors[i];
+
+		for (n = 0; n < data->resources->count_crtcs; n++) {
+			data->crtc_idx = n;
+			data->crtc_id = data->resources->crtcs[n];
+
+			if (!prepare_crtc(data, connector_id, mode))
+				continue;
+
+			fprintf(stdout, "Beginning %s on crtc %d, connector %d\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+			test_crc(data, mode);
+
+			fprintf(stdout, "\n%s on crtc %d, connector %d: PASSED\n\n",
+				igt_subtest_name(), data->crtc_id, connector_id);
+
+			finish_crtc(data, mode);
+		}
+	}
+}
+
+igt_main
+{
+	data_t data = {};
+	enum test_mode mode;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		size_t written;
+		int ret;
+		const char *cmd = "pipe A none";
+		char buf[64];
+		FILE *status;
+
+		data.drm_fd = drm_open_any();
+		igt_require(data.drm_fd);
+		igt_set_vt_graphics_mode();
+
+		data.devid = intel_get_drm_devid(data.drm_fd);
+
+		igt_debugfs_init(&data.debugfs);
+		data.ctl = igt_debugfs_fopen(&data.debugfs,
+					     "i915_display_crc_ctl", "r+");
+		igt_require_f(data.ctl,
+			      "No display_crc_ctl found, kernel too old\n");
+		written = fwrite(cmd, 1, strlen(cmd), data.ctl);
+		ret = fflush(data.ctl);
+		igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
+			      "CRCs not supported on this platform\n");
+
+		status = igt_debugfs_fopen(&data.debugfs, "i915_fbc_status", "r");
+		igt_require_f(status, "No i915_fbc_status found\n");
+		fread(buf, sizeof(buf), 1, status);
+		fclose(status);
+		buf[sizeof(buf) - 1] = '\0';
+		igt_require_f(!strstr(buf, "unsupported by this chipset") &&
+			      !strstr(buf, "disabled per module param") &&
+			      !strstr(buf, "disabled per chip default"),
+			      "FBC not supported/enabled\n");
+
+		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+		igt_assert(data.bufmgr);
+		drm_intel_bufmgr_gem_enable_reuse(data.bufmgr);
+
+		display_init(&data);
+	}
+
+	for (mode = TEST_PAGE_FLIP; mode <= TEST_PAGE_FLIP_AND_CONTEXT; mode++) {
+		igt_subtest_f("%s", test_mode_str(mode)) {
+			run_test(&data, mode);
+		}
+	}
+
+	igt_fixture {
+		drm_intel_bufmgr_destroy(data.bufmgr);
+		display_fini(&data);
+		fclose(data.ctl);
+	}
+}
-- 
1.8.3.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

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

end of thread, other threads:[~2013-11-25 16:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-21 19:33 [PATCH igt 1/2] rendercopy: Pass context to rendercopy functions ville.syrjala
2013-11-21 19:33 ` [PATCH igt 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
2013-11-25  9:18   ` Daniel Vetter
2013-11-25 15:08   ` [PATCH 1/2] lib: Add gem_sw_finish() ville.syrjala
2013-11-25 15:08     ` [PATCH v2 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala
2013-11-25 15:19       ` Daniel Vetter
2013-11-25 16:51         ` [PATCH igt 1/2] lib: Add gem_bo_busy ville.syrjala
2013-11-25 16:51           ` [PATCH igt v3 2/2] kms_fbc_crc: Add a CRC based FBC test ville.syrjala

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox