[igt-dev] [PATCH i-g-t v5 1/9] tests/i915/gem_render_copy.c: Do detiling on the CPU side

Antonio Argenziano antonio.argenziano at intel.com
Wed Jun 12 22:57:26 UTC 2019


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 at 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



More information about the igt-dev mailing list