[igt-dev] [PATCH] i915/gem_linear_blits: Use buffer with variable width and height

Vanshidhar Konda vanshidhar.r.konda at intel.com
Tue Nov 5 01:03:37 UTC 2019


Currently the test uses a hardcoded width and height of 512 each. The
test is being extended to take width and height as variables instead.
The function used to copy the buffer is also passed as an argument -
this allows us to extend the test with different copy functions.

Signed-off-by: Vanshidhar Konda <vanshidhar.r.konda at intel.com>
---
 tests/i915/gem_linear_blits.c | 74 ++++++++++++++++++++---------------
 1 file changed, 42 insertions(+), 32 deletions(-)

diff --git a/tests/i915/gem_linear_blits.c b/tests/i915/gem_linear_blits.c
index 07ca2f29..8010679b 100644
--- a/tests/i915/gem_linear_blits.c
+++ b/tests/i915/gem_linear_blits.c
@@ -49,13 +49,8 @@
 IGT_TEST_DESCRIPTION("Test doing many blits with a working set larger than the"
 		     " aperture size.");
 
-#define WIDTH 512
-#define HEIGHT 512
-
-static uint32_t linear[WIDTH*HEIGHT];
-
 static void
-copy(int fd, uint32_t dst, uint32_t src)
+copy(int fd, uint32_t dst, uint32_t src, uint32_t width, uint32_t height)
 {
 	uint32_t batch[12];
 	struct drm_i915_gem_relocation_entry reloc[2];
@@ -73,14 +68,14 @@ copy(int fd, uint32_t dst, uint32_t src)
 
 	batch[i++] = (3 << 24) | /* 32 bits */
 		  (0xcc << 16) | /* copy ROP */
-		  WIDTH*4;
+		  width*4;
 	batch[i++] = 0; /* dst x1,y1 */
-	batch[i++] = (HEIGHT << 16) | WIDTH; /* dst x2,y2 */
+	batch[i++] = (height << 16) | width; /* dst x2,y2 */
 	batch[i++] = 0; /* dst reloc */
 	if (intel_gen(intel_get_drm_devid(fd)) >= 8)
 		batch[i++] = 0;
 	batch[i++] = 0; /* src x1,y1 */
-	batch[i++] = WIDTH*4;
+	batch[i++] = width*4;
 	batch[i++] = 0; /* src reloc */
 	if (intel_gen(intel_get_drm_devid(fd)) >= 8)
 		batch[i++] = 0;
@@ -123,31 +118,33 @@ copy(int fd, uint32_t dst, uint32_t src)
 }
 
 static uint32_t
-create_bo(int fd, uint32_t val)
+create_bo(int fd, uint32_t val, uint32_t width, uint32_t height,
+	  uint32_t *linear)
 {
 	uint32_t handle;
 	int i;
 
-	handle = gem_create(fd, sizeof(linear));
+	handle = gem_create(fd, (sizeof(uint32_t)*width*height));
 
 	/* Fill the BO with dwords starting at val */
-	for (i = 0; i < WIDTH*HEIGHT; i++)
+	for (i = 0; i < width*height; i++)
 		linear[i] = val++;
-	gem_write(fd, handle, 0, linear, sizeof(linear));
+	gem_write(fd, handle, 0, linear, sizeof(uint32_t)*width*height);
 
 	return handle;
 }
 
 static void
-check_bo(int fd, uint32_t handle, uint32_t val)
+check_bo(int fd, uint32_t handle, uint32_t val, uint32_t width,
+	 uint32_t height, uint32_t *linear)
 {
 	int num_errors;
 	int i;
 
-	gem_read(fd, handle, 0, linear, sizeof(linear));
+	gem_read(fd, handle, 0, linear, sizeof(uint32_t)*width*height);
 
 	num_errors = 0;
-	for (i = 0; i < WIDTH*HEIGHT; i++) {
+	for (i = 0; i < width*height; i++) {
 		if (linear[i] != val && num_errors++ < 32)
 			igt_warn("[%08x] Expected 0x%08x, found 0x%08x (difference 0x%08x)\n",
 				 i * 4, val, linear[i], val ^ linear[i]);
@@ -156,7 +153,10 @@ check_bo(int fd, uint32_t handle, uint32_t val)
 	igt_assert_eq(num_errors, 0);
 }
 
-static void run_test(int fd, int count)
+static void run_test(int fd, int count, uint32_t width,
+		     uint32_t height, uint32_t *linear,
+		     void (*copy_func)(int, uint32_t, uint32_t,
+				       uint32_t, uint32_t))
 {
 	uint32_t *handle, *start_val;
 	uint32_t start = 0;
@@ -168,36 +168,36 @@ static void run_test(int fd, int count)
 	start_val = handle + count;
 
 	for (i = 0; i < count; i++) {
-		handle[i] = create_bo(fd, start);
+		handle[i] = create_bo(fd, start, width, height, linear);
 		start_val[i] = start;
 		start += 1024 * 1024 / 4;
 	}
 
 	igt_debug("Verifying initialisation...\n");
 	for (i = 0; i < count; i++)
-		check_bo(fd, handle[i], start_val[i]);
+		check_bo(fd, handle[i], start_val[i], width, height, linear);
 
 	igt_debug("Cyclic blits, forward...\n");
 	for (i = 0; i < count * 4; i++) {
 		int src = i % count;
 		int dst = (i + 1) % count;
 
-		copy(fd, handle[dst], handle[src]);
+		copy_func(fd, handle[dst], handle[src], width, height);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++)
-		check_bo(fd, handle[i], start_val[i]);
+		check_bo(fd, handle[i], start_val[i], width, height, linear);
 
 	igt_debug("Cyclic blits, backward...\n");
 	for (i = 0; i < count * 4; i++) {
 		int src = (i + 1) % count;
 		int dst = i % count;
 
-		copy(fd, handle[dst], handle[src]);
+		copy_func(fd, handle[dst], handle[src], width, height);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++)
-		check_bo(fd, handle[i], start_val[i]);
+		check_bo(fd, handle[i], start_val[i], width, height, linear);
 
 	igt_debug("Random blits...\n");
 	for (i = 0; i < count * 4; i++) {
@@ -207,11 +207,11 @@ static void run_test(int fd, int count)
 		if (src == dst)
 			continue;
 
-		copy(fd, handle[dst], handle[src]);
+		copy_func(fd, handle[dst], handle[src], width, height);
 		start_val[dst] = start_val[src];
 	}
 	for (i = 0; i < count; i++) {
-		check_bo(fd, handle[i], start_val[i]);
+		check_bo(fd, handle[i], start_val[i], width, height, linear);
 		gem_close(fd, handle[i]);
 	}
 
@@ -223,6 +223,8 @@ static void run_test(int fd, int count)
 igt_main
 {
 	int fd = 0;
+	uint32_t width, height;
+	uint32_t *linear;
 
 	igt_fixture {
 		fd = drm_open_driver(DRIVER_INTEL);
@@ -230,34 +232,42 @@ igt_main
 		gem_require_blitter(fd);
 	}
 
-	igt_subtest("basic")
-		run_test(fd, 2);
+	igt_subtest("basic") {
+		width = 1024;
+		height = 512;
+		linear = malloc(sizeof(uint32_t)*width*height);
+		run_test(fd, 2, width, height, linear, copy);
+	}
 
 	igt_subtest("normal") {
 		uint64_t count;
+		width = 512;
+		height = 512;
 
 		count = gem_aperture_size(fd);
 		if (count >> 32)
 			count = MAX_32b;
 		count = 3 * count / (1024*1024) / 2;
 		igt_require(count > 1);
-		intel_require_memory(count, sizeof(linear), CHECK_RAM);
+		intel_require_memory(count, sizeof(uint32_t), CHECK_RAM);
 
-		run_test(fd, count);
+		run_test(fd, count, width, height, linear, copy);
 	}
 
 	igt_subtest("interruptible") {
 		uint64_t count;
-
+		width = 512;
+		height = 512;
 		count = gem_aperture_size(fd);
 		if (count >> 32)
 			count = MAX_32b;
 		count = 3 * count / (1024*1024) / 2;
 		igt_require(count > 1);
-		intel_require_memory(count, sizeof(linear), CHECK_RAM);
+		intel_require_memory(count, sizeof(uint32_t), CHECK_RAM);
 
+		linear = malloc(sizeof(uint32_t)*width*height);
 		igt_fork_signal_helper();
-		run_test(fd, count);
+		run_test(fd, count, width, height, linear, copy);
 		igt_stop_signal_helper();
 	}
 }
-- 
2.23.0



More information about the igt-dev mailing list