public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* gem_render_copy
@ 2013-10-23 15:05 Damien Lespiau
  2013-10-23 15:05 ` [PATCH 1/5] lib: Add a function to dump a scratch buf into a png Damien Lespiau
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

A few moons ago, Chris suggested to create a small, standalone, render copy
test to add aub file support and help enabling new platforms instead of
hijacking gem_render_linear_blits.

So here it is.

-- 
Damien

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

* [PATCH 1/5] lib: Add a function to dump a scratch buf into a png
  2013-10-23 15:05 gem_render_copy Damien Lespiau
@ 2013-10-23 15:05 ` Damien Lespiau
  2013-10-23 15:05 ` [PATCH 2/5] tests/gem_render_copy: Add a simple render copy test Damien Lespiau
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3113 bytes --]

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 lib/Makefile.am  |  1 +
 lib/rendercopy.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/rendercopy.h |  2 ++
 3 files changed, 52 insertions(+)
 create mode 100644 lib/rendercopy.c

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 431fd93..d7f4275 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -32,6 +32,7 @@ libintel_tools_la_SOURCES = 	\
 	rendercopy_gen6.c	\
 	rendercopy_gen7.c	\
 	rendercopy.h		\
+	rendercopy.c		\
 	intel_reg_map.c		\
 	intel_dpio.c		\
 	intel_iosf.c		\
diff --git a/lib/rendercopy.c b/lib/rendercopy.c
new file mode 100644
index 0000000..2c1684d
--- /dev/null
+++ b/lib/rendercopy.c
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ *
+ * Authors:
+ *    Damien Lespiau <damien.lespiau@intel.com>
+ */
+
+#include <cairo.h>
+
+#include "rendercopy.h"
+
+void scratch_buf_write_to_png(struct scratch_buf *buf, const char *filename)
+{
+	cairo_surface_t *surface;
+	cairo_status_t ret;
+
+	drm_intel_bo_map(buf->bo, 0);
+	surface = cairo_image_surface_create_for_data(buf->bo->virtual,
+						      CAIRO_FORMAT_RGB24,
+						      buf_width(buf),
+						      buf_height(buf),
+						      buf->stride);
+	ret = cairo_surface_write_to_png(surface, filename);
+	if (ret != CAIRO_STATUS_SUCCESS) {
+		fprintf(stderr, "%s: %s\n", __func__,
+			cairo_status_to_string(ret));
+	}
+	cairo_surface_destroy(surface);
+	drm_intel_bo_unmap(buf->bo);
+}
diff --git a/lib/rendercopy.h b/lib/rendercopy.h
index 8fd9222..ace4392 100644
--- a/lib/rendercopy.h
+++ b/lib/rendercopy.h
@@ -85,4 +85,6 @@ void gen2_render_copyfunc(struct intel_batchbuffer *batch,
 			  unsigned width, unsigned height,
 			  struct scratch_buf *dst, unsigned dst_x, unsigned dst_y);
 
+void scratch_buf_write_to_png(struct scratch_buf *buf, const char *filename);
+
 #endif /* RENDERCOPY_H */
-- 
1.8.3.1


[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

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

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

* [PATCH 2/5] tests/gem_render_copy: Add a simple render copy test
  2013-10-23 15:05 gem_render_copy Damien Lespiau
  2013-10-23 15:05 ` [PATCH 1/5] lib: Add a function to dump a scratch buf into a png Damien Lespiau
@ 2013-10-23 15:05 ` Damien Lespiau
  2013-10-23 15:05 ` [PATCH 3/5] tests/gem_render_copy: Only dump pngs when the -d option is given Damien Lespiau
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 5289 bytes --]

The goal is here to both: demonstrate a simple usage of render copy with
the possibility to write pngs to visualize what it's doing and to
provide a test bed to port the render copy function to new
architectures.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 tests/.gitignore        |   1 +
 tests/Makefile.am       |   1 +
 tests/gem_render_copy.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 129 insertions(+)
 create mode 100644 tests/gem_render_copy.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 1c97a04..eded4a7 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -58,6 +58,7 @@ gem_readwrite
 gem_reg_read
 gem_reloc_overflow
 gem_reloc_vs_gpu
+gem_render_copy
 gem_render_linear_blits
 gem_render_tiled_blits
 gem_ringfill
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 843c7d2..7be2bc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,6 +87,7 @@ TESTS_progs = \
 	gem_pin \
 	gem_pipe_control_store_loop \
 	gem_reg_read \
+	gem_render_copy \
 	gem_render_linear_blits \
 	gem_render_tiled_blits \
 	gem_ring_sync_loop \
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
new file mode 100644
index 0000000..a693cee
--- /dev/null
+++ b/tests/gem_render_copy.c
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ *
+ * Authors:
+ *    Damien Lespiau <damien.lespiau@intel.com>
+ */
+
+/*
+ * This file is a basic test for the render_copy() function, a very simple
+ * workload for the 3D engine.
+ */
+
+#include <stdbool.h>
+
+#include "rendercopy.h"
+
+#define WIDTH 512
+#define STRIDE (WIDTH*4)
+#define HEIGHT 512
+#define SIZE (HEIGHT*STRIDE)
+
+#define SRC_COLOR	0xffff00ff
+#define DST_COLOR	0xfff0ff00
+
+typedef struct {
+	int drm_fd;
+	uint32_t devid;
+	drm_intel_bufmgr *bufmgr;
+	uint32_t linear[WIDTH * HEIGHT];
+} data_t;
+
+static void scratch_buf_init(data_t *data, struct scratch_buf *buf,
+			     int width, int height, int stride, uint32_t color)
+{
+	drm_intel_bo *bo;
+	int i;
+
+	bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
+	for (i = 0; i < width * height; i++)
+		data->linear[i] = color;
+	gem_write(data->drm_fd, bo->handle, 0, data->linear,
+		  sizeof(data->linear));
+
+	buf->bo = bo;
+	buf->stride = stride;
+	buf->tiling = I915_TILING_NONE;
+	buf->size = SIZE;
+}
+
+static void
+scratch_buf_check(data_t *data, struct scratch_buf *buf, int x, int y,
+		  uint32_t color)
+{
+	uint32_t val;
+
+	gem_read(data->drm_fd, buf->bo->handle, 0,
+		 data->linear, sizeof(data->linear));
+	val = data->linear[y * WIDTH + x];
+	if (val != color) {
+		fprintf(stderr, "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
+			color, val, x, y);
+		abort();
+	}
+}
+
+int main(int argc, char **argv)
+{
+	data_t data = {0, };
+	struct intel_batchbuffer *batch = NULL;
+	struct scratch_buf src, dst;
+	render_copyfunc_t render_copy = NULL;
+	int opt_dump_png = false;
+
+	igt_fixture {
+		data.drm_fd = drm_open_any();
+		data.devid = intel_get_drm_devid(data.drm_fd);
+
+		data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+		igt_assert(data.bufmgr);
+
+		render_copy = get_render_copyfunc(data.devid);
+		igt_require_f(render_copy,
+			      "no render-copy function\n");
+
+		batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
+		igt_assert(batch);
+	}
+
+	scratch_buf_init(&data, &src, WIDTH, HEIGHT, STRIDE, SRC_COLOR);
+	scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR);
+
+	scratch_buf_check(&data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR);
+	scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
+
+	scratch_buf_write_to_png(&src, "source.png");
+	scratch_buf_write_to_png(&dst, "destination.png");
+
+	render_copy(batch,
+		    &src, 0, 0, WIDTH, HEIGHT,
+		    &dst, WIDTH / 2, HEIGHT / 2);
+
+	scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
+	scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
+
+	scratch_buf_write_to_png(&dst, "result.png");
+
+	return 0;
+}
-- 
1.8.3.1


[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

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

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

* [PATCH 3/5] tests/gem_render_copy: Only dump pngs when the -d option is given
  2013-10-23 15:05 gem_render_copy Damien Lespiau
  2013-10-23 15:05 ` [PATCH 1/5] lib: Add a function to dump a scratch buf into a png Damien Lespiau
  2013-10-23 15:05 ` [PATCH 2/5] tests/gem_render_copy: Add a simple render copy test Damien Lespiau
@ 2013-10-23 15:05 ` Damien Lespiau
  2013-10-23 15:05 ` [PATCH 4/5] tests/gem_render_copy: Add aub dump support Damien Lespiau
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 tests/gem_render_copy.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index a693cee..b844fbb 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -30,6 +30,7 @@
  */
 
 #include <stdbool.h>
+#include <unistd.h>
 
 #include "rendercopy.h"
 
@@ -88,8 +89,19 @@ int main(int argc, char **argv)
 	struct intel_batchbuffer *batch = NULL;
 	struct scratch_buf src, dst;
 	render_copyfunc_t render_copy = NULL;
+	int opt;
 	int opt_dump_png = false;
 
+	while ((opt = getopt(argc, argv, "d")) != -1) {
+		switch (opt) {
+		case 'd':
+			opt_dump_png = true;
+			break;
+		default:
+			break;
+		}
+	}
+
 	igt_fixture {
 		data.drm_fd = drm_open_any();
 		data.devid = intel_get_drm_devid(data.drm_fd);
@@ -111,8 +123,10 @@ int main(int argc, char **argv)
 	scratch_buf_check(&data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR);
 	scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
 
-	scratch_buf_write_to_png(&src, "source.png");
-	scratch_buf_write_to_png(&dst, "destination.png");
+	if (opt_dump_png) {
+		scratch_buf_write_to_png(&src, "source.png");
+		scratch_buf_write_to_png(&dst, "destination.png");
+	}
 
 	render_copy(batch,
 		    &src, 0, 0, WIDTH, HEIGHT,
@@ -121,7 +135,8 @@ int main(int argc, char **argv)
 	scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
 	scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
 
-	scratch_buf_write_to_png(&dst, "result.png");
+	if (opt_dump_png)
+		scratch_buf_write_to_png(&dst, "result.png");
 
 	return 0;
 }
-- 
1.8.3.1

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

* [PATCH 4/5] tests/gem_render_copy: Add aub dump support
  2013-10-23 15:05 gem_render_copy Damien Lespiau
                   ` (2 preceding siblings ...)
  2013-10-23 15:05 ` [PATCH 3/5] tests/gem_render_copy: Only dump pngs when the -d option is given Damien Lespiau
@ 2013-10-23 15:05 ` Damien Lespiau
  2013-10-23 15:05 ` [PATCH 5/5] gem_render_linear_blits: Remove " Damien Lespiau
  2013-10-24 12:47 ` gem_render_copy Damien Lespiau
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 tests/gem_render_copy.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index b844fbb..40c37f4 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -91,6 +91,7 @@ int main(int argc, char **argv)
 	render_copyfunc_t render_copy = NULL;
 	int opt;
 	int opt_dump_png = false;
+	int opt_dump_aub = drmtest_dump_aub();
 
 	while ((opt = getopt(argc, argv, "d")) != -1) {
 		switch (opt) {
@@ -128,15 +129,29 @@ int main(int argc, char **argv)
 		scratch_buf_write_to_png(&dst, "destination.png");
 	}
 
+	if (opt_dump_aub) {
+		drm_intel_bufmgr_gem_set_aub_filename(data.bufmgr,
+						      "rendercopy.aub");
+		drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, true);
+	}
+
 	render_copy(batch,
 		    &src, 0, 0, WIDTH, HEIGHT,
 		    &dst, WIDTH / 2, HEIGHT / 2);
 
-	scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
-	scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
-
 	if (opt_dump_png)
 		scratch_buf_write_to_png(&dst, "result.png");
 
+	if (opt_dump_aub) {
+		drm_intel_gem_bo_aub_dump_bmp(dst.bo,
+			0, 0, WIDTH, HEIGHT,
+			AUB_DUMP_BMP_FORMAT_ARGB_8888,
+			STRIDE, 0);
+		drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, false);
+	} else {
+		scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
+		scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
+	}
+
 	return 0;
 }
-- 
1.8.3.1

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

* [PATCH 5/5] gem_render_linear_blits: Remove aub dump support
  2013-10-23 15:05 gem_render_copy Damien Lespiau
                   ` (3 preceding siblings ...)
  2013-10-23 15:05 ` [PATCH 4/5] tests/gem_render_copy: Add aub dump support Damien Lespiau
@ 2013-10-23 15:05 ` Damien Lespiau
  2013-10-24 12:47 ` gem_render_copy Damien Lespiau
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-23 15:05 UTC (permalink / raw)
  To: intel-gfx

It's much easier to follow the new gem_render_copy test and acquire a
aub dump from it.

Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 tests/gem_render_linear_blits.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/tests/gem_render_linear_blits.c b/tests/gem_render_linear_blits.c
index 1cc50b9..f110753 100644
--- a/tests/gem_render_linear_blits.c
+++ b/tests/gem_render_linear_blits.c
@@ -90,11 +90,6 @@ int main(int argc, char **argv)
 	if (argc > 1)
 		count = atoi(argv[1]);
 
-	if (drmtest_dump_aub()) {
-		count = 2;
-		drm_intel_bufmgr_gem_set_aub_filename(bufmgr, "rendercopy.aub");
-		drm_intel_bufmgr_gem_set_aub_dump(bufmgr, true);
-	}
 	if (count == 0)
 		count = 3 * gem_aperture_size(fd) / SIZE / 2;
 	else if (count < 2) {
@@ -135,17 +130,6 @@ int main(int argc, char **argv)
 
 		render_copy(batch, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
 		start_val[(i + 1) % count] = start_val[i % count];
-
-		/* We're not really here for the test, we just want to dump a
-		 * trace of a call to render_copy() */
-		if (drmtest_dump_aub()) {
-			drm_intel_gem_bo_aub_dump_bmp(dst.bo,
-				0, 0, WIDTH, HEIGHT,
-				AUB_DUMP_BMP_FORMAT_ARGB_8888,
-				STRIDE, 0);
-			drm_intel_bufmgr_gem_set_aub_dump(bufmgr, false);
-			return 0;
-		}
 	}
 	for (i = 0; i < count; i++)
 		check_bo(fd, bo[i]->handle, start_val[i]);
-- 
1.8.3.1

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

* Re: gem_render_copy
  2013-10-23 15:05 gem_render_copy Damien Lespiau
                   ` (4 preceding siblings ...)
  2013-10-23 15:05 ` [PATCH 5/5] gem_render_linear_blits: Remove " Damien Lespiau
@ 2013-10-24 12:47 ` Damien Lespiau
  5 siblings, 0 replies; 7+ messages in thread
From: Damien Lespiau @ 2013-10-24 12:47 UTC (permalink / raw)
  To: intel-gfx

On Wed, Oct 23, 2013 at 04:05:11PM +0100, Damien Lespiau wrote:
> A few moons ago, Chris suggested to create a small, standalone, render copy
> test to add aub file support and help enabling new platforms instead of
> hijacking gem_render_linear_blits.
> 
> So here it is.

A whole day without comment, pushed :)

As always, shout if needed.

-- 
Damien

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

end of thread, other threads:[~2013-10-24 12:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 15:05 gem_render_copy Damien Lespiau
2013-10-23 15:05 ` [PATCH 1/5] lib: Add a function to dump a scratch buf into a png Damien Lespiau
2013-10-23 15:05 ` [PATCH 2/5] tests/gem_render_copy: Add a simple render copy test Damien Lespiau
2013-10-23 15:05 ` [PATCH 3/5] tests/gem_render_copy: Only dump pngs when the -d option is given Damien Lespiau
2013-10-23 15:05 ` [PATCH 4/5] tests/gem_render_copy: Add aub dump support Damien Lespiau
2013-10-23 15:05 ` [PATCH 5/5] gem_render_linear_blits: Remove " Damien Lespiau
2013-10-24 12:47 ` gem_render_copy Damien Lespiau

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