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.
37 #include <sys/ioctl.h>
50 #include "intel_bufmgr.h"
51 #include "intel_batchbuffer.h"
52 #include "intel_gpu_tools.h"
55 #define STRIDE (WIDTH*4)
57 #define SIZE (HEIGHT*STRIDE)
59 #define SRC_COLOR 0xffff00ff
60 #define DST_COLOR 0xfff0ff00
65 drm_intel_bufmgr *bufmgr;
66 uint32_t linear[WIDTH * HEIGHT];
69 static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
71 cairo_surface_t *surface;
74 drm_intel_bo_map(buf->bo, 0);
75 surface = cairo_image_surface_create_for_data(buf->bo->virtual,
80 ret = cairo_surface_write_to_png(surface, filename);
81 if (ret != CAIRO_STATUS_SUCCESS) {
82 fprintf(stderr, "%s: %s\n", __func__,
83 cairo_status_to_string(ret));
85 cairo_surface_destroy(surface);
86 drm_intel_bo_unmap(buf->bo);
89 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
90 int width, int height, int stride, uint32_t color)
95 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
96 for (i = 0; i < width * height; i++)
97 data->linear[i] = color;
98 gem_write(data->drm_fd, bo->handle, 0, data->linear,
99 sizeof(data->linear));
102 buf->stride = stride;
103 buf->tiling = I915_TILING_NONE;
108 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
113 gem_read(data->drm_fd, buf->bo->handle, 0,
114 data->linear, sizeof(data->linear));
115 val = data->linear[y * WIDTH + x];
117 fprintf(stderr, "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
123 int main(int argc, char **argv)
126 struct intel_batchbuffer *batch = NULL;
127 struct igt_buf src, dst;
128 igt_render_copyfunc_t render_copy = NULL;
130 int opt_dump_png = false;
131 int opt_dump_aub = drmtest_dump_aub();
135 while ((opt = getopt(argc, argv, "d")) != -1) {
146 data.drm_fd = drm_open_any_render();
147 data.devid = intel_get_drm_devid(data.drm_fd);
149 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
150 igt_assert(data.bufmgr);
152 render_copy = igt_get_render_copyfunc(data.devid);
153 igt_require_f(render_copy,
154 "no render-copy function\n");
156 batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
160 scratch_buf_init(&data, &src, WIDTH, HEIGHT, STRIDE, SRC_COLOR);
161 scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR);
163 scratch_buf_check(&data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR);
164 scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
167 scratch_buf_write_to_png(&src, "source.png");
168 scratch_buf_write_to_png(&dst, "destination.png");
172 drm_intel_bufmgr_gem_set_aub_filename(data.bufmgr,
174 drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, true);
177 render_copy(batch, NULL,
178 &src, 0, 0, WIDTH, HEIGHT,
179 &dst, WIDTH / 2, HEIGHT / 2);
182 scratch_buf_write_to_png(&dst, "result.png");
185 drm_intel_gem_bo_aub_dump_bmp(dst.bo,
187 AUB_DUMP_BMP_FORMAT_ARGB_8888,
189 drm_intel_bufmgr_gem_set_aub_dump(data.bufmgr, false);
191 scratch_buf_check(&data, &dst, 10, 10, DST_COLOR);
192 scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);