2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Damien Lespiau <damien.lespiau@intel.com>
28 * This file is a basic test for the render_copy() function, a very simple
29 * workload for the 3D engine.
36 #include <sys/ioctl.h>
48 #include "ioctl_wrappers.h"
50 #include "intel_bufmgr.h"
51 #include "intel_batchbuffer.h"
53 #include "intel_chipset.h"
57 #define STRIDE (WIDTH*4)
59 #define SIZE (HEIGHT*STRIDE)
61 #define SRC_COLOR 0xffff00ff
62 #define DST_COLOR 0xfff0ff00
67 drm_intel_bufmgr *bufmgr;
68 uint32_t linear[WIDTH * HEIGHT];
71 static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
73 cairo_surface_t *surface;
76 drm_intel_bo_map(buf->bo, 0);
77 surface = cairo_image_surface_create_for_data(buf->bo->virtual,
82 ret = cairo_surface_write_to_png(surface, filename);
83 igt_assert(ret == CAIRO_STATUS_SUCCESS);
84 cairo_surface_destroy(surface);
85 drm_intel_bo_unmap(buf->bo);
88 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
89 int width, int height, int stride, uint32_t color)
94 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
95 for (i = 0; i < width * height; i++)
96 data->linear[i] = color;
97 gem_write(data->drm_fd, bo->handle, 0, data->linear,
98 sizeof(data->linear));
101 buf->stride = stride;
102 buf->tiling = I915_TILING_NONE;
107 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
112 gem_read(data->drm_fd, buf->bo->handle, 0,
113 data->linear, sizeof(data->linear));
114 val = data->linear[y * WIDTH + x];
115 igt_assert_f(val == color,
116 "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
120 int main(int argc, char **argv)
123 struct intel_batchbuffer *batch = NULL;
124 struct igt_buf src, dst;
125 igt_render_copyfunc_t render_copy = NULL;
127 int opt_dump_png = false;
128 int opt_dump_aub = igt_aub_dump_enabled();
132 while ((opt = getopt(argc, argv, "d")) != -1) {
143 data.drm_fd = drm_open_any_render();
144 data.devid = intel_get_drm_devid(data.drm_fd);
146 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
147 igt_assert(data.bufmgr);
149 render_copy = igt_get_render_copyfunc(data.devid);
150 igt_require_f(render_copy,
151 "no render-copy function\n");
153 batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
157 scratch_buf_init(&data, &src, WIDTH, HEIGHT, STRIDE, SRC_COLOR);
158 scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR);
160 scratch_buf_check(&data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR);
161 scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
164 scratch_buf_write_to_png(&src, "source.png");
165 scratch_buf_write_to_png(&dst, "destination.png");
169 drm_intel_bufmgr_gem_set_aub_filename(data.bufmgr,
171 drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, true);
174 render_copy(batch, NULL,
175 &src, 0, 0, WIDTH, HEIGHT,
176 &dst, WIDTH / 2, HEIGHT / 2);
179 scratch_buf_write_to_png(&dst, "result.png");
182 drm_intel_gem_bo_aub_dump_bmp(dst.bo,
184 AUB_DUMP_BMP_FORMAT_ARGB_8888,
186 drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, false);
188 scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
189 scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);