[igt-dev] [PATCH i-g-t 6/7] tests/gem_render_copy: Add subtests for different tiling modes
Ville Syrjala
ville.syrjala at linux.intel.com
Wed Jul 4 16:16:45 UTC 2018
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
Make sure our rendercopy implementations do the right thing with
tiled buffers.
For now we'll just do linear->linear, x-tiled->x-tiled, and
y-tiled->y-tiled. Not sure there's much point in adding tests
for different src vs. dst tiling modes?
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
tests/gem_render_copy.c | 175 +++++++++++++++++++++++++++++-------------------
1 file changed, 105 insertions(+), 70 deletions(-)
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index 956f83f4b3a5..13198dfcb3fd 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -58,25 +58,19 @@ typedef struct {
int drm_fd;
uint32_t devid;
drm_intel_bufmgr *bufmgr;
+ struct intel_batchbuffer *batch;
+ igt_render_copyfunc_t render_copy;
} data_t;
static int opt_dump_png = false;
static int check_all_pixels = false;
-static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
+static const char *make_filename(const char *filename)
{
- cairo_surface_t *surface;
- cairo_status_t ret;
+ static char buf[64];
- drm_intel_bo_map(buf->bo, 0);
- surface = cairo_image_surface_create_for_data(buf->bo->virtual,
- CAIRO_FORMAT_RGB24,
- igt_buf_width(buf),
- igt_buf_height(buf),
- buf->stride);
- ret = cairo_surface_write_to_png(surface, filename);
- igt_assert(ret == CAIRO_STATUS_SUCCESS);
- cairo_surface_destroy(surface);
- drm_intel_bo_unmap(buf->bo);
+ snprintf(buf, sizeof(buf), "%s_%s", igt_subtest_name(), filename);
+
+ return buf;
}
static void *linear_copy(data_t *data, struct igt_buf *buf)
@@ -98,6 +92,27 @@ static void *linear_copy(data_t *data, struct igt_buf *buf)
return linear;
}
+static void scratch_buf_write_to_png(data_t *data, struct igt_buf *buf,
+ const char *filename)
+{
+ cairo_surface_t *surface;
+ cairo_status_t ret;
+ void *linear;
+
+ linear = linear_copy(data, buf);
+
+ surface = cairo_image_surface_create_for_data(linear,
+ CAIRO_FORMAT_RGB24,
+ igt_buf_width(buf),
+ igt_buf_height(buf),
+ buf->stride);
+ ret = cairo_surface_write_to_png(surface, make_filename(filename));
+ igt_assert(ret == CAIRO_STATUS_SUCCESS);
+ cairo_surface_destroy(surface);
+
+ free(linear);
+}
+
static void scratch_buf_draw_pattern(data_t *data, struct igt_buf *buf,
int x, int y, int w, int h,
int cx, int cy, int cw, int ch,
@@ -199,7 +214,8 @@ scratch_buf_copy(data_t *data,
}
static void scratch_buf_init(data_t *data, struct igt_buf *buf,
- int width, int height, int stride)
+ int width, int height, int stride,
+ uint32_t tiling)
{
drm_intel_bo *bo;
int size = height * stride;
@@ -210,9 +226,12 @@ static void scratch_buf_init(data_t *data, struct igt_buf *buf,
buf->bo = bo;
buf->stride = stride;
- buf->tiling = I915_TILING_NONE;
+ buf->tiling = tiling;
buf->size = size;
+ drm_intel_bo_set_tiling(buf->bo, &tiling, buf->stride);
+ igt_assert_eq(tiling, buf->tiling);
+
igt_assert(igt_buf_width(buf) == width);
igt_assert(igt_buf_height(buf) == height);
}
@@ -275,73 +294,39 @@ scratch_buf_check_all(data_t *data,
free(linear_buf);
}
-static int opt_handler(int opt, int opt_index, void *data)
-{
- if (opt == 'd') {
- opt_dump_png = true;
- }
-
- if (opt == 'a') {
- check_all_pixels = true;
- }
-
- return 0;
-}
-
-int main(int argc, char **argv)
+static void test_basic(data_t *data, uint32_t tiling)
{
- data_t data = {0, };
- struct intel_batchbuffer *batch = NULL;
struct igt_buf src, dst, ref;
- igt_render_copyfunc_t render_copy = NULL;
int opt_dump_aub = igt_aub_dump_enabled();
- igt_simple_init_parse_opts(&argc, argv, "da", NULL, NULL,
- opt_handler, NULL);
-
- igt_fixture {
- data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
- 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 = igt_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);
- scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE);
- scratch_buf_init(&data, &ref, WIDTH, HEIGHT, STRIDE);
+ scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, tiling);
+ scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, tiling);
+ scratch_buf_init(data, &ref, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE);
- scratch_buf_draw_pattern(&data, &src,
+ scratch_buf_draw_pattern(data, &src,
0, 0, WIDTH, HEIGHT,
0, 0, WIDTH, HEIGHT, true);
- scratch_buf_draw_pattern(&data, &dst,
+ scratch_buf_draw_pattern(data, &dst,
0, 0, WIDTH, HEIGHT,
0, 0, WIDTH, HEIGHT, false);
- scratch_buf_copy(&data,
+ scratch_buf_copy(data,
&dst, 0, 0, WIDTH, HEIGHT,
&ref, 0, 0);
- scratch_buf_copy(&data,
+ scratch_buf_copy(data,
&src, WIDTH/4, WIDTH/4, WIDTH/2, HEIGHT/2,
&ref, WIDTH/2-1, WIDTH/2-1);
if (opt_dump_png) {
- scratch_buf_write_to_png(&src, "source.png");
- scratch_buf_write_to_png(&dst, "destination.png");
- scratch_buf_write_to_png(&ref, "reference.png");
+ scratch_buf_write_to_png(data, &src, "source.png");
+ scratch_buf_write_to_png(data, &dst, "destination.png");
+ scratch_buf_write_to_png(data, &ref, "reference.png");
}
if (opt_dump_aub) {
- drm_intel_bufmgr_gem_set_aub_filename(data.bufmgr,
+ drm_intel_bufmgr_gem_set_aub_filename(data->bufmgr,
"rendercopy.aub");
- drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, true);
+ drm_intel_bufmgr_gem_set_aub_dump(data->bufmgr, true);
}
/* This will copy the src to the mid point of the dst buffer. Presumably
@@ -352,24 +337,74 @@ int main(int argc, char **argv)
* |dst|src|
* -------
*/
- render_copy(batch, NULL,
- &src, WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2,
- &dst, WIDTH/2-1, HEIGHT/2-1);
+ data->render_copy(data->batch, NULL,
+ &src, WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2,
+ &dst, WIDTH/2-1, HEIGHT/2-1);
if (opt_dump_png)
- scratch_buf_write_to_png(&dst, "result.png");
+ scratch_buf_write_to_png(data, &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);
+ drm_intel_bufmgr_gem_set_aub_dump(data->bufmgr, false);
} else if (check_all_pixels) {
- scratch_buf_check_all(&data, &dst, &ref);
+ scratch_buf_check_all(data, &dst, &ref);
} else {
- scratch_buf_check(&data, &dst, &ref, 10, 10);
- scratch_buf_check(&data, &dst, &ref, WIDTH - 10, HEIGHT - 10);
+ scratch_buf_check(data, &dst, &ref, 10, 10);
+ scratch_buf_check(data, &dst, &ref, WIDTH - 10, HEIGHT - 10);
+ }
+}
+
+static int opt_handler(int opt, int opt_index, void *data)
+{
+ if (opt == 'd') {
+ opt_dump_png = true;
+ }
+
+ if (opt == 'a') {
+ check_all_pixels = true;
+ }
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ data_t data = {0, };
+
+ igt_subtest_init_parse_opts(&argc, argv, "da", NULL, NULL,
+ opt_handler, NULL);
+
+ igt_fixture {
+ data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
+ data.devid = intel_get_drm_devid(data.drm_fd);
+
+ data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+ igt_assert(data.bufmgr);
+
+ data.render_copy = igt_get_render_copyfunc(data.devid);
+ igt_require_f(data.render_copy,
+ "no render-copy function\n");
+
+ data.batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
+ igt_assert(data.batch);
+ }
+
+ igt_subtest("linear")
+ test_basic(&data, I915_TILING_NONE);
+
+ igt_subtest("x-tiled")
+ test_basic(&data, I915_TILING_X);
+
+ igt_subtest("y-tiled")
+ test_basic(&data, I915_TILING_Y);
+
+ igt_fixture {
+ intel_batchbuffer_free(data.batch);
+ drm_intel_bufmgr_destroy(data.bufmgr);
}
igt_exit();
--
2.16.4
More information about the igt-dev
mailing list