blob: 9f769e5d3a091eb1a527dc4ed896ff3fbd03b864 [file] [log] [blame]
Daniel Vetter3dba47e2013-08-06 22:27:37 +02001/*
2 * Copyright © 2009,2012,2013 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Chris Wilson <chris@chris-wilson.co.uk>
26 * Daniel Vetter <daniel.vetter@ffwll.ch>
27 *
28 */
29
Daniel Vetter43779e32013-08-14 14:50:50 +020030/** @file gem_concurrent_blit.c
Daniel Vetter3dba47e2013-08-06 22:27:37 +020031 *
32 * This is a test of pread/pwrite behavior when writing to active
33 * buffers.
34 *
35 * Based on gem_gtt_concurrent_blt.
36 */
37
38#include <stdlib.h>
39#include <stdio.h>
40#include <string.h>
Daniel Vetter3dba47e2013-08-06 22:27:37 +020041#include <fcntl.h>
42#include <inttypes.h>
43#include <errno.h>
44#include <sys/stat.h>
45#include <sys/time.h>
Chris Wilson99431a42013-08-14 11:03:34 +010046#include <sys/wait.h>
Daniel Vetterf5daeec2014-03-23 13:35:09 +010047
48#include <drm.h>
49
Daniel Vettere49ceb82014-03-22 21:07:37 +010050#include "ioctl_wrappers.h"
Daniel Vetter3dba47e2013-08-06 22:27:37 +020051#include "drmtest.h"
52#include "intel_bufmgr.h"
53#include "intel_batchbuffer.h"
Daniel Vetterc03c6ce2014-03-22 21:34:29 +010054#include "intel_io.h"
Daniel Vettere49ceb82014-03-22 21:07:37 +010055#include "intel_chipset.h"
Daniel Vetterf5daeec2014-03-23 13:35:09 +010056#include "igt_aux.h"
Daniel Vetter3dba47e2013-08-06 22:27:37 +020057
Chris Wilson6c428a62014-08-29 13:11:37 +010058int fd, devid, gen;
59struct intel_batchbuffer *batch;
60
Daniel Vetter3dba47e2013-08-06 22:27:37 +020061static void
Daniel Vetter43779e32013-08-14 14:50:50 +020062prw_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height)
Daniel Vetter3dba47e2013-08-06 22:27:37 +020063{
Chris Wilson0b4c33f2014-01-26 14:36:32 +000064 int size = width * height, i;
65 uint32_t *tmp;
Daniel Vetter3dba47e2013-08-06 22:27:37 +020066
Chris Wilson0b4c33f2014-01-26 14:36:32 +000067 tmp = malloc(4*size);
68 if (tmp) {
69 for (i = 0; i < size; i++)
70 tmp[i] = val;
71 drm_intel_bo_subdata(bo, 0, 4*size, tmp);
72 free(tmp);
73 } else {
74 for (i = 0; i < size; i++)
75 drm_intel_bo_subdata(bo, 4*i, 4, &val);
76 }
Daniel Vetter3dba47e2013-08-06 22:27:37 +020077}
78
79static void
Chris Wilsonc12f2922014-08-31 16:14:40 +010080prw_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp)
Daniel Vetter3dba47e2013-08-06 22:27:37 +020081{
Chris Wilson0b4c33f2014-01-26 14:36:32 +000082 int size = width * height, i;
Chris Wilsonc12f2922014-08-31 16:14:40 +010083 uint32_t *vaddr;
Daniel Vetter3dba47e2013-08-06 22:27:37 +020084
Chris Wilsonc12f2922014-08-31 16:14:40 +010085 do_or_die(drm_intel_bo_map(tmp, true));
86 do_or_die(drm_intel_bo_get_subdata(bo, 0, 4*size, tmp->virtual));
87 vaddr = tmp->virtual;
88 for (i = 0; i < size; i++)
89 igt_assert_eq_u32(vaddr[i], val);
90 drm_intel_bo_unmap(tmp);
Daniel Vetter3dba47e2013-08-06 22:27:37 +020091}
92
93static drm_intel_bo *
Chris Wilson86055df2014-08-29 17:36:29 +010094unmapped_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
Daniel Vetter3dba47e2013-08-06 22:27:37 +020095{
96 drm_intel_bo *bo;
97
98 bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0);
Daniel Vetter83440952013-08-13 12:35:58 +020099 igt_assert(bo);
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200100
101 return bo;
102}
103
Daniel Vetter43779e32013-08-14 14:50:50 +0200104static void
105gtt_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height)
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200106{
Daniel Vetter43779e32013-08-14 14:50:50 +0200107 int size = width * height;
108 uint32_t *vaddr;
109
110 drm_intel_gem_bo_start_gtt_access(bo, true);
111 vaddr = bo->virtual;
112 while (size--)
113 *vaddr++ = val;
114}
115
116static void
Chris Wilsonc12f2922014-08-31 16:14:40 +0100117gtt_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp)
Daniel Vetter43779e32013-08-14 14:50:50 +0200118{
119 int size = width * height;
120 uint32_t *vaddr;
121
122 drm_intel_gem_bo_start_gtt_access(bo, false);
123 vaddr = bo->virtual;
124 while (size--)
Chris Wilson6c428a62014-08-29 13:11:37 +0100125 igt_assert_eq_u32(*vaddr++, val);
Daniel Vetter43779e32013-08-14 14:50:50 +0200126}
127
128static drm_intel_bo *
Chris Wilson86055df2014-08-29 17:36:29 +0100129map_bo(drm_intel_bo *bo)
Daniel Vetter43779e32013-08-14 14:50:50 +0200130{
Daniel Vetter43779e32013-08-14 14:50:50 +0200131 /* gtt map doesn't have a write parameter, so just keep the mapping
132 * around (to avoid the set_domain with the gtt write domain set) and
133 * manually tell the kernel when we start access the gtt. */
134 do_or_die(drm_intel_gem_bo_map_gtt(bo));
135
136 return bo;
137}
138
Chris Wilson86055df2014-08-29 17:36:29 +0100139static drm_intel_bo *
140tile_bo(drm_intel_bo *bo, int width)
141{
142 uint32_t tiling = I915_TILING_X;
143 uint32_t stride = width * 4;
144
145 do_or_die(drm_intel_bo_set_tiling(bo, &tiling, stride));
146
147 return bo;
148}
149
150static drm_intel_bo *
151gtt_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
152{
153 return map_bo(unmapped_create_bo(bufmgr, width, height));
154}
155
156static drm_intel_bo *
157gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
158{
159 return tile_bo(gtt_create_bo(bufmgr, width, height), width);
160}
161
162static drm_intel_bo *
163gpu_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
164{
165 return unmapped_create_bo(bufmgr, width, height);
166}
167
168
169static drm_intel_bo *
170gpuX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height)
171{
172 return tile_bo(gpu_create_bo(bufmgr, width, height), width);
173}
174
Daniel Vetter43779e32013-08-14 14:50:50 +0200175static void
176cpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height)
177{
178 int size = width * height;
179 uint32_t *vaddr;
180
181 do_or_die(drm_intel_bo_map(bo, true));
182 vaddr = bo->virtual;
183 while (size--)
184 *vaddr++ = val;
185 drm_intel_bo_unmap(bo);
186}
187
188static void
Chris Wilsonc12f2922014-08-31 16:14:40 +0100189cpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp)
Daniel Vetter43779e32013-08-14 14:50:50 +0200190{
191 int size = width * height;
192 uint32_t *vaddr;
193
194 do_or_die(drm_intel_bo_map(bo, false));
195 vaddr = bo->virtual;
196 while (size--)
Chris Wilson6c428a62014-08-29 13:11:37 +0100197 igt_assert_eq_u32(*vaddr++, val);
Daniel Vetter43779e32013-08-14 14:50:50 +0200198 drm_intel_bo_unmap(bo);
199}
200
Chris Wilson6c428a62014-08-29 13:11:37 +0100201static void
202gpu_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height)
203{
204 struct drm_i915_gem_relocation_entry reloc[1];
205 struct drm_i915_gem_exec_object2 gem_exec[2];
206 struct drm_i915_gem_execbuffer2 execbuf;
207 struct drm_i915_gem_pwrite gem_pwrite;
208 struct drm_i915_gem_create create;
209 uint32_t buf[10], *b;
Chris Wilson86055df2014-08-29 17:36:29 +0100210 uint32_t tiling, swizzle;
211
212 drm_intel_bo_get_tiling(bo, &tiling, &swizzle);
Chris Wilson6c428a62014-08-29 13:11:37 +0100213
214 memset(reloc, 0, sizeof(reloc));
215 memset(gem_exec, 0, sizeof(gem_exec));
216 memset(&execbuf, 0, sizeof(execbuf));
217
218 b = buf;
219 *b++ = XY_COLOR_BLT_CMD_NOLEN |
220 ((gen >= 8) ? 5 : 4) |
221 COLOR_BLT_WRITE_ALPHA | XY_COLOR_BLT_WRITE_RGB;
Chris Wilson86055df2014-08-29 17:36:29 +0100222 if (gen >= 4 && tiling) {
223 b[-1] |= XY_COLOR_BLT_TILED;
224 *b = width;
225 } else
226 *b = width << 2;
227 *b++ |= 0xf0 << 16 | 1 << 25 | 1 << 24;
Chris Wilson6c428a62014-08-29 13:11:37 +0100228 *b++ = 0;
229 *b++ = height << 16 | width;
230 reloc[0].offset = (b - buf) * sizeof(uint32_t);
231 reloc[0].target_handle = bo->handle;
232 reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
233 reloc[0].write_domain = I915_GEM_DOMAIN_RENDER;
234 *b++ = 0;
235 if (gen >= 8)
236 *b++ = 0;
237 *b++ = val;
238 *b++ = MI_BATCH_BUFFER_END;
239 if ((b - buf) & 1)
240 *b++ = 0;
241
242 gem_exec[0].handle = bo->handle;
243 gem_exec[0].flags = EXEC_OBJECT_NEEDS_FENCE;
244
245 create.handle = 0;
246 create.size = 4096;
247 drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
248 gem_exec[1].handle = create.handle;
249 gem_exec[1].relocation_count = 1;
250 gem_exec[1].relocs_ptr = (uintptr_t)reloc;
251
252 execbuf.buffers_ptr = (uintptr_t)gem_exec;
253 execbuf.buffer_count = 2;
254 execbuf.batch_len = (b - buf) * sizeof(buf[0]);
Chris Wilson86055df2014-08-29 17:36:29 +0100255 if (gen >= 6)
256 execbuf.flags = I915_EXEC_BLT;
Chris Wilson6c428a62014-08-29 13:11:37 +0100257
258 gem_pwrite.handle = gem_exec[1].handle;
259 gem_pwrite.offset = 0;
260 gem_pwrite.size = execbuf.batch_len;
261 gem_pwrite.data_ptr = (uintptr_t)buf;
Chris Wilsonc12f2922014-08-31 16:14:40 +0100262 do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &gem_pwrite));
263 do_or_die(drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf));
Chris Wilson6c428a62014-08-29 13:11:37 +0100264
265 drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &create.handle);
266}
267
268static void
Chris Wilsonc12f2922014-08-31 16:14:40 +0100269gpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp)
Chris Wilson6c428a62014-08-29 13:11:37 +0100270{
Chris Wilson6c428a62014-08-29 13:11:37 +0100271 intel_copy_bo(batch, tmp, bo, width*height*4);
Chris Wilsonc12f2922014-08-31 16:14:40 +0100272 cpu_cmp_bo(tmp, val, width, height, NULL);
Chris Wilson6c428a62014-08-29 13:11:37 +0100273}
274
Daniel Vetter43779e32013-08-14 14:50:50 +0200275struct access_mode {
276 void (*set_bo)(drm_intel_bo *bo, uint32_t val, int w, int h);
Chris Wilsonc12f2922014-08-31 16:14:40 +0100277 void (*cmp_bo)(drm_intel_bo *bo, uint32_t val, int w, int h, drm_intel_bo *tmp);
Chris Wilson86055df2014-08-29 17:36:29 +0100278 drm_intel_bo *(*create_bo)(drm_intel_bufmgr *bufmgr, int width, int height);
Daniel Vetter43779e32013-08-14 14:50:50 +0200279 const char *name;
280};
281
282struct access_mode access_modes[] = {
283 { .set_bo = prw_set_bo, .cmp_bo = prw_cmp_bo,
284 .create_bo = unmapped_create_bo, .name = "prw" },
285 { .set_bo = cpu_set_bo, .cmp_bo = cpu_cmp_bo,
286 .create_bo = unmapped_create_bo, .name = "cpu" },
287 { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo,
288 .create_bo = gtt_create_bo, .name = "gtt" },
Chris Wilson86055df2014-08-29 17:36:29 +0100289 { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo,
290 .create_bo = gttX_create_bo, .name = "gttX" },
Chris Wilson6c428a62014-08-29 13:11:37 +0100291 { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo,
Chris Wilson86055df2014-08-29 17:36:29 +0100292 .create_bo = gpu_create_bo, .name = "gpu" },
293 { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo,
294 .create_bo = gpuX_create_bo, .name = "gpuX" },
Daniel Vetter43779e32013-08-14 14:50:50 +0200295};
296
Chris Wilson1ca607b2013-08-16 09:44:13 +0100297#define MAX_NUM_BUFFERS 1024
Chris Wilson6c428a62014-08-29 13:11:37 +0100298int num_buffers = MAX_NUM_BUFFERS;
Chris Wilson86055df2014-08-29 17:36:29 +0100299const int width = 512, height = 512;
Chris Wilson59c55622014-08-29 13:11:37 +0100300igt_render_copyfunc_t rendercopy;
301
302typedef void (*do_copy)(drm_intel_bo *dst, drm_intel_bo *src);
303
304static void render_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
305{
306 struct igt_buf d = {
307 .bo = dst,
308 .size = width * height * 4,
Chris Wilson59c55622014-08-29 13:11:37 +0100309 .num_tiles = width * height * 4,
310 .stride = width * 4,
311 }, s = {
312 .bo = src,
313 .size = width * height * 4,
Chris Wilson59c55622014-08-29 13:11:37 +0100314 .num_tiles = width * height * 4,
315 .stride = width * 4,
316 };
Chris Wilson86055df2014-08-29 17:36:29 +0100317 uint32_t swizzle;
318
319 drm_intel_bo_get_tiling(dst, &d.tiling, &swizzle);
320 drm_intel_bo_get_tiling(src, &s.tiling, &swizzle);
321
Chris Wilson59c55622014-08-29 13:11:37 +0100322 rendercopy(batch, NULL,
323 &s, 0, 0,
324 width, height,
325 &d, 0, 0);
326}
327
328static void blt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src)
329{
Chris Wilson86055df2014-08-29 17:36:29 +0100330 intel_blt_copy(batch,
331 src, 0, 0, 4*width,
332 dst, 0, 0, 4*width,
333 width, height, 32);
Chris Wilson59c55622014-08-29 13:11:37 +0100334}
Daniel Vetter5a598c92013-08-14 15:08:05 +0200335
336static void do_overwrite_source(struct access_mode *mode,
337 drm_intel_bo **src, drm_intel_bo **dst,
Chris Wilson59c55622014-08-29 13:11:37 +0100338 drm_intel_bo *dummy,
339 do_copy do_copy_func)
Daniel Vetter5a598c92013-08-14 15:08:05 +0200340{
341 int i;
342
343 gem_quiescent_gpu(fd);
344 for (i = 0; i < num_buffers; i++) {
345 mode->set_bo(src[i], i, width, height);
Chris Wilsonc12f2922014-08-31 16:14:40 +0100346 mode->set_bo(dst[i], ~i, width, height);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200347 }
348 for (i = 0; i < num_buffers; i++)
Chris Wilson59c55622014-08-29 13:11:37 +0100349 do_copy_func(dst[i], src[i]);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200350 for (i = num_buffers; i--; )
351 mode->set_bo(src[i], 0xdeadbeef, width, height);
352 for (i = 0; i < num_buffers; i++)
Chris Wilsonc12f2922014-08-31 16:14:40 +0100353 mode->cmp_bo(dst[i], i, width, height, dummy);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200354}
355
356static void do_early_read(struct access_mode *mode,
357 drm_intel_bo **src, drm_intel_bo **dst,
Chris Wilson59c55622014-08-29 13:11:37 +0100358 drm_intel_bo *dummy,
359 do_copy do_copy_func)
Daniel Vetter5a598c92013-08-14 15:08:05 +0200360{
361 int i;
362
363 gem_quiescent_gpu(fd);
364 for (i = num_buffers; i--; )
365 mode->set_bo(src[i], 0xdeadbeef, width, height);
366 for (i = 0; i < num_buffers; i++)
Chris Wilson59c55622014-08-29 13:11:37 +0100367 do_copy_func(dst[i], src[i]);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200368 for (i = num_buffers; i--; )
Chris Wilsonc12f2922014-08-31 16:14:40 +0100369 mode->cmp_bo(dst[i], 0xdeadbeef, width, height, dummy);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200370}
371
372static void do_gpu_read_after_write(struct access_mode *mode,
373 drm_intel_bo **src, drm_intel_bo **dst,
Chris Wilson59c55622014-08-29 13:11:37 +0100374 drm_intel_bo *dummy,
375 do_copy do_copy_func)
Daniel Vetter5a598c92013-08-14 15:08:05 +0200376{
377 int i;
378
379 gem_quiescent_gpu(fd);
380 for (i = num_buffers; i--; )
381 mode->set_bo(src[i], 0xabcdabcd, width, height);
382 for (i = 0; i < num_buffers; i++)
Chris Wilson59c55622014-08-29 13:11:37 +0100383 do_copy_func(dst[i], src[i]);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200384 for (i = num_buffers; i--; )
Chris Wilson59c55622014-08-29 13:11:37 +0100385 do_copy_func(dummy, dst[i]);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200386 for (i = num_buffers; i--; )
Chris Wilsonc12f2922014-08-31 16:14:40 +0100387 mode->cmp_bo(dst[i], 0xabcdabcd, width, height, dummy);
Daniel Vetter5a598c92013-08-14 15:08:05 +0200388}
389
Daniel Vetterec283d62013-08-14 15:18:37 +0200390typedef void (*do_test)(struct access_mode *mode,
391 drm_intel_bo **src, drm_intel_bo **dst,
Chris Wilson59c55622014-08-29 13:11:37 +0100392 drm_intel_bo *dummy,
393 do_copy do_copy_func);
Daniel Vetterec283d62013-08-14 15:18:37 +0200394
395typedef void (*run_wrap)(struct access_mode *mode,
396 drm_intel_bo **src, drm_intel_bo **dst,
397 drm_intel_bo *dummy,
Chris Wilson59c55622014-08-29 13:11:37 +0100398 do_test do_test_func,
399 do_copy do_copy_func);
Daniel Vetterec283d62013-08-14 15:18:37 +0200400
401static void run_single(struct access_mode *mode,
402 drm_intel_bo **src, drm_intel_bo **dst,
403 drm_intel_bo *dummy,
Chris Wilson59c55622014-08-29 13:11:37 +0100404 do_test do_test_func,
405 do_copy do_copy_func)
Daniel Vetterec283d62013-08-14 15:18:37 +0200406{
Chris Wilson59c55622014-08-29 13:11:37 +0100407 do_test_func(mode, src, dst, dummy, do_copy_func);
Daniel Vetterec283d62013-08-14 15:18:37 +0200408}
409
Chris Wilson1ca607b2013-08-16 09:44:13 +0100410static void run_interruptible(struct access_mode *mode,
411 drm_intel_bo **src, drm_intel_bo **dst,
412 drm_intel_bo *dummy,
Chris Wilson59c55622014-08-29 13:11:37 +0100413 do_test do_test_func,
414 do_copy do_copy_func)
Daniel Vetterec283d62013-08-14 15:18:37 +0200415{
416 int loop;
417
418 for (loop = 0; loop < 10; loop++)
Chris Wilson59c55622014-08-29 13:11:37 +0100419 do_test_func(mode, src, dst, dummy, do_copy_func);
Daniel Vetterec283d62013-08-14 15:18:37 +0200420}
421
422static void run_forked(struct access_mode *mode,
423 drm_intel_bo **src, drm_intel_bo **dst,
424 drm_intel_bo *dummy,
Chris Wilson59c55622014-08-29 13:11:37 +0100425 do_test do_test_func,
426 do_copy do_copy_func)
Daniel Vetterec283d62013-08-14 15:18:37 +0200427{
Chris Wilson1ca607b2013-08-16 09:44:13 +0100428 const int old_num_buffers = num_buffers;
Chris Wilson86055df2014-08-29 17:36:29 +0100429 drm_intel_bufmgr *bufmgr;
Daniel Vetterec283d62013-08-14 15:18:37 +0200430
Daniel Vettercd1f2202013-08-29 10:06:51 +0200431 num_buffers /= 16;
Chris Wilson1ca607b2013-08-16 09:44:13 +0100432 num_buffers += 2;
433
Daniel Vettercd1f2202013-08-29 10:06:51 +0200434 igt_fork(child, 16) {
Daniel Vettercd1f2202013-08-29 10:06:51 +0200435 /* recreate process local variables */
436 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
437 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
Chris Wilson86055df2014-08-29 17:36:29 +0100438 batch = intel_batchbuffer_alloc(bufmgr, devid);
Daniel Vettercd1f2202013-08-29 10:06:51 +0200439 for (int i = 0; i < num_buffers; i++) {
Chris Wilson86055df2014-08-29 17:36:29 +0100440 src[i] = mode->create_bo(bufmgr, width, height);
441 dst[i] = mode->create_bo(bufmgr, width, height);
Daniel Vetterec283d62013-08-14 15:18:37 +0200442 }
Chris Wilson86055df2014-08-29 17:36:29 +0100443 dummy = mode->create_bo(bufmgr, width, height);
Daniel Vettercd1f2202013-08-29 10:06:51 +0200444 for (int loop = 0; loop < 10; loop++)
Chris Wilson59c55622014-08-29 13:11:37 +0100445 do_test_func(mode, src, dst, dummy, do_copy_func);
Daniel Vettercd1f2202013-08-29 10:06:51 +0200446 /* as we borrow the fd, we need to reap our bo */
447 for (int i = 0; i < num_buffers; i++) {
448 drm_intel_bo_unreference(src[i]);
449 drm_intel_bo_unreference(dst[i]);
450 }
451 drm_intel_bo_unreference(dummy);
452 intel_batchbuffer_free(batch);
453 drm_intel_bufmgr_destroy(bufmgr);
Daniel Vetterec283d62013-08-14 15:18:37 +0200454 }
Daniel Vettercd1f2202013-08-29 10:06:51 +0200455
456 igt_waitchildren();
Chris Wilson1ca607b2013-08-16 09:44:13 +0100457
Chris Wilson1ca607b2013-08-16 09:44:13 +0100458 num_buffers = old_num_buffers;
Daniel Vetterec283d62013-08-14 15:18:37 +0200459}
Daniel Vetter5a598c92013-08-14 15:08:05 +0200460
Chris Wilson08188752014-09-03 13:38:30 +0100461static void bcs_require(void)
462{
463}
464
465static void rcs_require(void)
466{
467 igt_require(rendercopy);
468}
469
Daniel Vetter5a598c92013-08-14 15:08:05 +0200470static void
471run_basic_modes(struct access_mode *mode,
472 drm_intel_bo **src, drm_intel_bo **dst,
Daniel Vetterec283d62013-08-14 15:18:37 +0200473 drm_intel_bo *dummy, const char *suffix,
474 run_wrap run_wrap_func)
Daniel Vetter5a598c92013-08-14 15:08:05 +0200475{
Chris Wilson59c55622014-08-29 13:11:37 +0100476 struct {
477 const char *prefix;
478 do_copy copy;
Chris Wilson08188752014-09-03 13:38:30 +0100479 void (*require)(void);
Chris Wilson59c55622014-08-29 13:11:37 +0100480 } pipelines[] = {
Chris Wilson08188752014-09-03 13:38:30 +0100481 { "bcs", blt_copy_bo, bcs_require },
482 { "rcs", render_copy_bo, rcs_require },
Chris Wilson59c55622014-08-29 13:11:37 +0100483 { NULL, NULL }
484 }, *p;
Daniel Vetter5a598c92013-08-14 15:08:05 +0200485
Chris Wilson59c55622014-08-29 13:11:37 +0100486 for (p = pipelines; p->prefix; p++) {
487 /* try to overwrite the source values */
Chris Wilson08188752014-09-03 13:38:30 +0100488 igt_subtest_f("%s-%s-overwrite-source%s", mode->name, p->prefix, suffix) {
489 p->require();
Chris Wilson59c55622014-08-29 13:11:37 +0100490 run_wrap_func(mode, src, dst, dummy,
491 do_overwrite_source, p->copy);
Chris Wilson08188752014-09-03 13:38:30 +0100492 }
Daniel Vetter5a598c92013-08-14 15:08:05 +0200493
Chris Wilson59c55622014-08-29 13:11:37 +0100494 /* try to read the results before the copy completes */
Chris Wilson08188752014-09-03 13:38:30 +0100495 igt_subtest_f("%s-%s-early-read%s", mode->name, p->prefix, suffix) {
496 p->require();
Chris Wilson59c55622014-08-29 13:11:37 +0100497 run_wrap_func(mode, src, dst, dummy,
498 do_early_read, p->copy);
Chris Wilson08188752014-09-03 13:38:30 +0100499 }
Chris Wilson59c55622014-08-29 13:11:37 +0100500
501 /* and finally try to trick the kernel into loosing the pending write */
Chris Wilson08188752014-09-03 13:38:30 +0100502 igt_subtest_f("%s-%s-gpu-read-after-write%s", mode->name, p->prefix, suffix) {
503 p->require();
Chris Wilson59c55622014-08-29 13:11:37 +0100504 run_wrap_func(mode, src, dst, dummy,
505 do_gpu_read_after_write, p->copy);
Chris Wilson08188752014-09-03 13:38:30 +0100506 }
Chris Wilson59c55622014-08-29 13:11:37 +0100507 }
Daniel Vetter5a598c92013-08-14 15:08:05 +0200508}
Daniel Vetter43779e32013-08-14 14:50:50 +0200509
510static void
511run_modes(struct access_mode *mode)
512{
Daniel Vetterad0f0812013-08-26 20:41:00 +0200513 drm_intel_bo *src[MAX_NUM_BUFFERS], *dst[MAX_NUM_BUFFERS], *dummy = NULL;
Chris Wilson86055df2014-08-29 17:36:29 +0100514 drm_intel_bufmgr *bufmgr;
Daniel Vetterad0f0812013-08-26 20:41:00 +0200515
Daniel Vetter2dbd9982013-08-14 15:48:54 +0200516 igt_fixture {
Chris Wilson0d320fd2013-08-16 12:07:56 +0100517 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
518 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
Chris Wilson86055df2014-08-29 17:36:29 +0100519 batch = intel_batchbuffer_alloc(bufmgr, devid);
Chris Wilson0d320fd2013-08-16 12:07:56 +0100520
Chris Wilson1ca607b2013-08-16 09:44:13 +0100521 for (int i = 0; i < num_buffers; i++) {
Chris Wilson86055df2014-08-29 17:36:29 +0100522 src[i] = mode->create_bo(bufmgr, width, height);
523 dst[i] = mode->create_bo(bufmgr, width, height);
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200524 }
Chris Wilson86055df2014-08-29 17:36:29 +0100525 dummy = mode->create_bo(bufmgr, width, height);
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200526 }
527
Daniel Vetterec283d62013-08-14 15:18:37 +0200528 run_basic_modes(mode, src, dst, dummy, "", run_single);
Chris Wilson6c428a62014-08-29 13:11:37 +0100529
530 igt_fork_signal_helper();
Chris Wilson1ca607b2013-08-16 09:44:13 +0100531 run_basic_modes(mode, src, dst, dummy, "-interruptible", run_interruptible);
Chris Wilson6c428a62014-08-29 13:11:37 +0100532 igt_stop_signal_helper();
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200533
Daniel Vetter2dbd9982013-08-14 15:48:54 +0200534 igt_fixture {
Chris Wilson1ca607b2013-08-16 09:44:13 +0100535 for (int i = 0; i < num_buffers; i++) {
Daniel Vetter43779e32013-08-14 14:50:50 +0200536 drm_intel_bo_unreference(src[i]);
537 drm_intel_bo_unreference(dst[i]);
538 }
539 drm_intel_bo_unreference(dummy);
Chris Wilson0d320fd2013-08-16 12:07:56 +0100540 intel_batchbuffer_free(batch);
541 drm_intel_bufmgr_destroy(bufmgr);
Daniel Vetter43779e32013-08-14 14:50:50 +0200542 }
Chris Wilson1ca607b2013-08-16 09:44:13 +0100543
Chris Wilson6c428a62014-08-29 13:11:37 +0100544 igt_fork_signal_helper();
Chris Wilson1ca607b2013-08-16 09:44:13 +0100545 run_basic_modes(mode, src, dst, dummy, "-forked", run_forked);
Chris Wilson6c428a62014-08-29 13:11:37 +0100546 igt_stop_signal_helper();
Daniel Vetter43779e32013-08-14 14:50:50 +0200547}
548
Daniel Vetter071e9ca2013-10-31 16:23:26 +0100549igt_main
Daniel Vetter43779e32013-08-14 14:50:50 +0200550{
551 int max, i;
552
Daniel Vetter43779e32013-08-14 14:50:50 +0200553 igt_skip_on_simulation();
554
Daniel Vetter2dbd9982013-08-14 15:48:54 +0200555 igt_fixture {
556 fd = drm_open_any();
Chris Wilson6c428a62014-08-29 13:11:37 +0100557 devid = intel_get_drm_devid(fd);
558 gen = intel_gen(devid);
Chris Wilson59c55622014-08-29 13:11:37 +0100559 rendercopy = igt_get_render_copyfunc(devid);
Daniel Vetter43779e32013-08-14 14:50:50 +0200560
Daniel Vetter2dbd9982013-08-14 15:48:54 +0200561 max = gem_aperture_size (fd) / (1024 * 1024) / 2;
562 if (num_buffers > max)
563 num_buffers = max;
Daniel Vetteraee0dcb2013-12-03 16:32:52 +0100564
565 max = intel_get_total_ram_mb() * 3 / 4;
566 if (num_buffers > max)
567 num_buffers = max;
Chris Wilson0b4c33f2014-01-26 14:36:32 +0000568 num_buffers /= 2;
Daniel Vettere624fa82014-05-14 00:36:04 +0200569 igt_info("using 2x%d buffers, each 1MiB\n", num_buffers);
Daniel Vetter2dbd9982013-08-14 15:48:54 +0200570 }
Daniel Vetter43779e32013-08-14 14:50:50 +0200571
572 for (i = 0; i < ARRAY_SIZE(access_modes); i++)
573 run_modes(&access_modes[i]);
Daniel Vetter3dba47e2013-08-06 22:27:37 +0200574}