2 * Copyright © 2013-2014 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 an "advanced" test for the render_copy() function, a very simple
29 * workload for the 3D engine. The basic test in gem_render_copy.c is intentionally
30 * kept extremely simple to allow for aub instrumentation and to ease debugging of
31 * the render copy functions themselves. This test on the overhand aims to stress
32 * the execbuffer interface with a simple render workload.
38 #include <sys/ioctl.h>
49 #include "ioctl_wrappers.h"
51 #include "intel_bufmgr.h"
52 #include "intel_batchbuffer.h"
54 #include "intel_chipset.h"
58 #define STRIDE (WIDTH*4)
60 #define SIZE (HEIGHT*STRIDE)
62 #define SRC_COLOR 0xffff00ff
63 #define DST_COLOR 0xfff0ff00
68 drm_intel_bufmgr *bufmgr;
69 struct intel_batchbuffer *batch;
70 igt_render_copyfunc_t render_copy;
71 uint32_t linear[WIDTH * HEIGHT];
74 static void data_init(data_t *data)
76 data->fd = drm_open_any();
77 data->devid = intel_get_drm_devid(data->fd);
79 data->bufmgr = drm_intel_bufmgr_gem_init(data->fd, 4096);
80 igt_assert(data->bufmgr);
82 data->render_copy = igt_get_render_copyfunc(data->devid);
83 igt_require_f(data->render_copy,
84 "no render-copy function\n");
86 data->batch = intel_batchbuffer_alloc(data->bufmgr, data->devid);
87 igt_assert(data->batch);
90 static void data_fini(data_t *data)
92 intel_batchbuffer_free(data->batch);
93 drm_intel_bufmgr_destroy(data->bufmgr);
97 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
98 int width, int height, int stride, uint32_t color)
103 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
104 for (i = 0; i < width * height; i++)
105 data->linear[i] = color;
106 gem_write(data->fd, bo->handle, 0, data->linear,
107 sizeof(data->linear));
110 buf->stride = stride;
111 buf->tiling = I915_TILING_NONE;
115 static void scratch_buf_fini(data_t *data, struct igt_buf *buf)
117 dri_bo_unreference(buf->bo);
118 memset(buf, 0, sizeof(*buf));
122 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
127 gem_read(data->fd, buf->bo->handle, 0,
128 data->linear, sizeof(data->linear));
129 val = data->linear[y * WIDTH + x];
130 igt_assert_f(val == color,
131 "Expected 0x%08x, found 0x%08x at (%d,%d)\n",
135 static void copy(data_t *data)
137 struct igt_buf src, dst;
139 scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, SRC_COLOR);
140 scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR);
142 scratch_buf_check(data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR);
143 scratch_buf_check(data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
145 data->render_copy(data->batch, NULL,
146 &src, 0, 0, WIDTH, HEIGHT,
147 &dst, WIDTH / 2, HEIGHT / 2);
149 scratch_buf_check(data, &dst, 10, 10, DST_COLOR);
150 scratch_buf_check(data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
152 scratch_buf_fini(data, &src);
153 scratch_buf_fini(data, &dst);
156 static void copy_flink(data_t *data)
159 struct igt_buf src, dst;
160 struct igt_buf local_src, local_dst;
161 struct igt_buf flink;
166 scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, 0);
167 scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR);
169 data->render_copy(data->batch, NULL,
170 &src, 0, 0, WIDTH, HEIGHT,
171 &dst, WIDTH, HEIGHT);
173 scratch_buf_init(&local, &local_src, WIDTH, HEIGHT, STRIDE, 0);
174 scratch_buf_init(&local, &local_dst, WIDTH, HEIGHT, STRIDE, SRC_COLOR);
176 local.render_copy(local.batch, NULL,
177 &local_src, 0, 0, WIDTH, HEIGHT,
178 &local_dst, WIDTH, HEIGHT);
181 drm_intel_bo_flink(local_dst.bo, &name);
183 flink.bo = drm_intel_bo_gem_create_from_name(data->bufmgr, "flink", name);
185 data->render_copy(data->batch, NULL,
186 &flink, 0, 0, WIDTH, HEIGHT,
187 &dst, WIDTH / 2, HEIGHT / 2);
189 scratch_buf_check(data, &dst, 10, 10, DST_COLOR);
190 scratch_buf_check(data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
192 scratch_buf_check(data, &dst, 10, 10, DST_COLOR);
193 scratch_buf_check(data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR);
195 scratch_buf_fini(data, &src);
196 scratch_buf_fini(data, &flink);
197 scratch_buf_fini(data, &dst);
199 scratch_buf_fini(&local, &local_src);
200 scratch_buf_fini(&local, &local_dst);
205 int main(int argc, char **argv)
209 igt_subtest_init(argc, argv);
215 igt_subtest("normal") {
221 igt_subtest("interruptible") {
223 igt_fork_signal_helper();
226 igt_stop_signal_helper();
229 igt_subtest("flink") {
235 igt_subtest("flink-interruptible") {
237 igt_fork_signal_helper();
240 igt_stop_signal_helper();