public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Antonio Argenziano <antonio.argenziano@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v6 1/9] tests/i915/gem_render_copy.c: Do detiling on the CPU side
Date: Thu, 13 Jun 2019 14:54:40 -0700	[thread overview]
Message-ID: <20190613215448.17994-2-antonio.argenziano@intel.com> (raw)
In-Reply-To: <20190613215448.17994-1-antonio.argenziano@intel.com>

Try to step away from using gtt mapping for accessing tiled patterns by
linearizing the buffers on the CPU side.

Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
---
 tests/i915/gem_render_copy.c | 252 ++++++++++++++++++++++++++++++++++-
 1 file changed, 248 insertions(+), 4 deletions(-)

diff --git a/tests/i915/gem_render_copy.c b/tests/i915/gem_render_copy.c
index b8149483..cc1529fd 100644
--- a/tests/i915/gem_render_copy.c
+++ b/tests/i915/gem_render_copy.c
@@ -102,6 +102,42 @@ static void *yf_ptr(void *ptr,
 		(((y & ~0x1f) >> 5) * row_size);
 }
 
+bool dump = false;
+
+static void *x_ptr(void *ptr,
+		    unsigned int x, unsigned int y,
+		    unsigned int stride, unsigned int cpp)
+{
+	const int tile_width = 512;
+	int row_size = 8;
+	const int tile_size = tile_width * row_size;
+
+	x *= cpp; /* convert to Byte offset */
+
+	return ptr +
+		((x / tile_width) * tile_width) +
+		(x % tile_width) +
+		((y / row_size) * tile_size * (stride / tile_width)) +
+		((y % row_size) * stride);
+}
+
+static void *y_ptr(void *ptr,
+		    unsigned int x, unsigned int y,
+		    unsigned int stride, unsigned int cpp)
+{
+	const int tile_width = 128;
+	int row_size = 32;
+	const int tile_size = tile_width * row_size;
+
+	x *= cpp; /* convert to Byte offset */
+
+	return ptr +
+		((x / tile_width) * tile_width) +
+		(x % tile_width) +
+		((y / row_size) * tile_size * (stride / tile_width)) +
+		((y % row_size) * stride);
+}
+
 static void copy_linear_to_yf(data_t *data, struct igt_buf *buf,
 			      const uint32_t *linear)
 {
@@ -126,6 +162,54 @@ static void copy_linear_to_yf(data_t *data, struct igt_buf *buf,
 	munmap(map, buf->bo->size);
 }
 
+static void copy_linear_to_x(data_t *data, struct igt_buf *buf,
+			      const uint32_t *linear)
+{
+	int height = igt_buf_height(buf);
+	int width = igt_buf_width(buf);
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	map = gem_mmap__cpu(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ | PROT_WRITE);
+
+	for (int y = 0; y < height; y++) {
+		for (int x = 0; x < width; x++) {
+			uint32_t *ptr = x_ptr(map, x, y,
+					       buf->stride, buf->bpp / 8);
+
+			*ptr = linear[y * width + x];
+		}
+	}
+
+	munmap(map, buf->bo->size);
+}
+
+static void copy_linear_to_y(data_t *data, struct igt_buf *buf,
+			      const uint32_t *linear)
+{
+	int height = igt_buf_height(buf);
+	int width = igt_buf_width(buf);
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
+	map = gem_mmap__cpu(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ | PROT_WRITE);
+
+	for (int y = 0; y < height; y++) {
+		for (int x = 0; x < width; x++) {
+			uint32_t *ptr = y_ptr(map, x, y,
+					       buf->stride, buf->bpp / 8);
+
+			*ptr = linear[y * width + x];
+		}
+	}
+
+	munmap(map, buf->bo->size);
+}
+
 static void copy_yf_to_linear(data_t *data, struct igt_buf *buf,
 			      uint32_t *linear)
 {
@@ -150,6 +234,54 @@ static void copy_yf_to_linear(data_t *data, struct igt_buf *buf,
 	munmap(map, buf->bo->size);
 }
 
+static void copy_x_to_linear(data_t *data, struct igt_buf *buf,
+			      uint32_t *linear)
+{
+	int height = igt_buf_height(buf);
+	int width = igt_buf_width(buf);
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_CPU, 0);
+	map = gem_mmap__cpu(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ);
+
+	for (int y = 0; y < height; y++) {
+		for (int x = 0; x < width; x++) {
+			uint32_t *ptr = x_ptr(map, x, y,
+					       buf->stride, buf->bpp / 8);
+
+			linear[y * width + x] = *ptr;
+		}
+	}
+
+	munmap(map, buf->bo->size);
+}
+
+static void copy_y_to_linear(data_t *data, struct igt_buf *buf,
+			      uint32_t *linear)
+{
+	int height = igt_buf_height(buf);
+	int width = igt_buf_width(buf);
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_CPU, 0);
+	map = gem_mmap__cpu(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ);
+
+	for (int y = 0; y < height; y++) {
+		for (int x = 0; x < width; x++) {
+			uint32_t *ptr = y_ptr(map, x, y,
+					       buf->stride, buf->bpp / 8);
+
+			linear[y * width + x] = *ptr;
+		}
+	}
+
+	munmap(map, buf->bo->size);
+}
+
 static void copy_linear_to_gtt(data_t *data, struct igt_buf *buf,
 			       const uint32_t *linear)
 {
@@ -166,6 +298,22 @@ static void copy_linear_to_gtt(data_t *data, struct igt_buf *buf,
 	munmap(map, buf->bo->size);
 }
 
+static void copy_linear_to_wc(data_t *data, struct igt_buf *buf,
+			       const uint32_t *linear)
+{
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+
+	map = gem_mmap__wc(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ | PROT_WRITE);
+
+	memcpy(map, linear, buf->bo->size);
+
+	munmap(map, buf->bo->size);
+}
+
 static void copy_gtt_to_linear(data_t *data, struct igt_buf *buf,
 			       uint32_t *linear)
 {
@@ -182,6 +330,22 @@ static void copy_gtt_to_linear(data_t *data, struct igt_buf *buf,
 	munmap(map, buf->bo->size);
 }
 
+static void copy_wc_to_linear(data_t *data, struct igt_buf *buf,
+			       uint32_t *linear)
+{
+	void *map;
+
+	gem_set_domain(data->drm_fd, buf->bo->handle,
+		       I915_GEM_DOMAIN_GTT, 0);
+
+	map = gem_mmap__wc(data->drm_fd, buf->bo->handle, 0,
+			    buf->bo->size, PROT_READ);
+
+	igt_memcpy_from_wc(linear, map, buf->bo->size);
+
+	munmap(map, buf->bo->size);
+}
+
 static void *linear_copy(data_t *data, struct igt_buf *buf)
 {
 	void *linear;
@@ -191,12 +355,32 @@ static void *linear_copy(data_t *data, struct igt_buf *buf)
 
 	if (buf->tiling == I915_TILING_Yf)
 		copy_yf_to_linear(data, buf, linear);
+	else if (buf->tiling == I915_TILING_NONE)
+		copy_wc_to_linear(data, buf, linear);
+	else if (buf->tiling == I915_TILING_X)
+		copy_x_to_linear(data, buf, linear);
+	else if (buf->tiling == I915_TILING_Y)
+		copy_y_to_linear(data, buf, linear);
 	else
 		copy_gtt_to_linear(data, buf, linear);
 
 	return linear;
 }
 
+static void copy_linear_to_tiled(data_t *data, struct igt_buf *buf, const uint32_t *linear)
+{
+	if (buf->tiling == I915_TILING_Yf)
+		copy_linear_to_yf(data, buf, linear);
+	else if (buf->tiling == I915_TILING_X)
+		copy_linear_to_x(data, buf, linear);
+	else if (buf->tiling == I915_TILING_Y)
+		copy_linear_to_y(data, buf, linear);
+	else if (buf->tiling == I915_TILING_NONE)
+		copy_linear_to_wc(data, buf, linear);
+	else
+		igt_info("Unknown tiling!\n");
+}
+
 static void scratch_buf_write_to_png(data_t *data, struct igt_buf *buf,
 				     const char *filename)
 {
@@ -324,6 +508,12 @@ static void scratch_buf_draw_pattern(data_t *data, struct igt_buf *buf,
 
 	if (buf->tiling == I915_TILING_Yf)
 		copy_linear_to_yf(data, buf, linear);
+	else if (buf->tiling == I915_TILING_NONE)
+		copy_linear_to_wc(data, buf, linear);
+	else if (buf->tiling == I915_TILING_X)
+		copy_linear_to_x(data, buf, linear);
+	else if (buf->tiling == I915_TILING_Y)
+		copy_linear_to_y(data, buf, linear);
 	else
 		copy_linear_to_gtt(data, buf, linear);
 
@@ -338,6 +528,7 @@ scratch_buf_copy(data_t *data,
 	int width = igt_buf_width(dst);
 	int height  = igt_buf_height(dst);
 	uint32_t *linear_dst;
+	uint32_t *linear_tmp;
 
 	igt_assert_eq(igt_buf_width(dst), igt_buf_width(src));
 	igt_assert_eq(igt_buf_height(dst), igt_buf_height(src));
@@ -352,8 +543,8 @@ scratch_buf_copy(data_t *data,
 
 	gem_set_domain(data->drm_fd, dst->bo->handle,
 		       I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
-	linear_dst = gem_mmap__gtt(data->drm_fd, dst->bo->handle,
-				   dst->bo->size, PROT_WRITE);
+
+	linear_tmp = linear_copy(data, dst);
 
 	if (src->tiling == I915_TILING_Yf) {
 		void *map;
@@ -369,11 +560,62 @@ scratch_buf_copy(data_t *data,
 							     src->stride,
 							     src->bpp / 8);
 
-				linear_dst[(dy+y) * width + dx+x] = *ptr;
+				linear_tmp[(dy+y) * width + dx+x] = *ptr;
+			}
+		}
+
+		munmap(map, src->bo->size);
+	} else if (src->tiling == I915_TILING_Y) {
+		void *map;
+
+		gem_set_domain(data->drm_fd, src->bo->handle,
+			       I915_GEM_DOMAIN_CPU, 0);
+		map = gem_mmap__cpu(data->drm_fd, src->bo->handle, 0,
+				    src->bo->size, PROT_READ);
+
+		for (int y = 0; y < h; y++) {
+			for (int x = 0; x < w; x++) {
+				const uint32_t *ptr = y_ptr(map, sx+x, sy+y,
+							     src->stride,
+							     src->bpp / 8);
+
+				linear_tmp[(dy+y) * width + dx+x] = *ptr;
+			}
+		}
+
+		munmap(map, src->bo->size);
+	} else if (src->tiling == I915_TILING_X) {
+		void *map;
+
+		gem_set_domain(data->drm_fd, src->bo->handle,
+			       I915_GEM_DOMAIN_CPU, 0);
+		map = gem_mmap__cpu(data->drm_fd, src->bo->handle, 0,
+				    src->bo->size, PROT_READ);
+
+		for (int y = 0; y < h; y++) {
+			for (int x = 0; x < w; x++) {
+				const uint32_t *ptr = x_ptr(map, sx+x, sy+y,
+							     src->stride,
+							     src->bpp / 8);
+
+				linear_tmp[(dy+y) * width + dx+x] = *ptr;
 			}
 		}
 
 		munmap(map, src->bo->size);
+	} else if (src->tiling == I915_TILING_NONE) {
+		uint32_t *linear_src;
+
+		linear_src = gem_mmap__cpu(data->drm_fd, src->bo->handle, 0,
+					   src->bo->size, PROT_READ);
+
+		for (int y = 0; y < h; y++) {
+			igt_memcpy_from_wc(&linear_tmp[(dy+y) * width + dx],
+					   &linear_src[(sy+y) * width + sx],
+					   w * (src->bpp / 8));
+		}
+
+		munmap(linear_src, src->bo->size);
 	} else {
 		uint32_t *linear_src;
 
@@ -384,7 +626,7 @@ scratch_buf_copy(data_t *data,
 					   src->bo->size, PROT_READ);
 
 		for (int y = 0; y < h; y++) {
-			igt_memcpy_from_wc(&linear_dst[(dy+y) * width + dx],
+			igt_memcpy_from_wc(&linear_tmp[(dy+y) * width + dx],
 					   &linear_src[(sy+y) * width + sx],
 					   w * (src->bpp / 8));
 		}
@@ -392,6 +634,8 @@ scratch_buf_copy(data_t *data,
 		munmap(linear_src, src->bo->size);
 	}
 
+	copy_linear_to_tiled(data, dst, linear_tmp);
+
 	munmap(linear_dst, dst->bo->size);
 }
 
-- 
2.21.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-06-13 21:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 21:54 [igt-dev] [PATCH i-g-t v6 0/9] Aperture removal IGT changes Antonio Argenziano
2019-06-13 21:54 ` Antonio Argenziano [this message]
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 2/9] tests/i915/gem_madvise.c: Add more mappings Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 3/9] lib/i915/gem_mman: Remove static variables Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 4/9] lib/i915: Add mmap_offset support Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 5/9] tests/i915/gem_mmap_offset_exhaustion.c: Extend test to different mappings Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 6/9] igt/lib: Add wrapper to check if gtt mapping is available Antonio Argenziano
2019-06-14  9:47   ` Chris Wilson
2019-06-14 20:47     ` Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 7/9] igt/i915: Require GTT mapping to be available when needed Antonio Argenziano
2019-06-14  9:54   ` Chris Wilson
2019-06-14 21:16     ` Antonio Argenziano
2019-06-14 21:34       ` Chris Wilson
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 8/9] Remove static variables from mapping version function Antonio Argenziano
2019-06-13 21:54 ` [igt-dev] [PATCH i-g-t v6 9/9] igt/lib: If mappable aperture is missing return 0 size Antonio Argenziano
2019-06-14  9:56   ` Chris Wilson
2019-06-14 12:56 ` [igt-dev] ✓ Fi.CI.BAT: success for Aperture removal IGT changes (rev2) Patchwork
2019-06-15  9:07 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190613215448.17994-2-antonio.argenziano@intel.com \
    --to=antonio.argenziano@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox