Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 1 | /* |
| 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 Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 30 | /** @file gem_concurrent_blit.c |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 31 | * |
| 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 Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 41 | #include <fcntl.h> |
| 42 | #include <inttypes.h> |
| 43 | #include <errno.h> |
| 44 | #include <sys/stat.h> |
| 45 | #include <sys/time.h> |
Chris Wilson | 99431a4 | 2013-08-14 11:03:34 +0100 | [diff] [blame] | 46 | #include <sys/wait.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 47 | |
| 48 | #include <drm.h> |
| 49 | |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 50 | #include "ioctl_wrappers.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 51 | #include "drmtest.h" |
| 52 | #include "intel_bufmgr.h" |
| 53 | #include "intel_batchbuffer.h" |
Daniel Vetter | c03c6ce | 2014-03-22 21:34:29 +0100 | [diff] [blame] | 54 | #include "intel_io.h" |
Daniel Vetter | e49ceb8 | 2014-03-22 21:07:37 +0100 | [diff] [blame] | 55 | #include "intel_chipset.h" |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 56 | #include "igt_aux.h" |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 57 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 58 | int fd, devid, gen; |
| 59 | struct intel_batchbuffer *batch; |
| 60 | |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 61 | static void |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 62 | prw_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 63 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 64 | int size = width * height, i; |
| 65 | uint32_t *tmp; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 66 | |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 67 | 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 Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 80 | prw_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 81 | { |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 82 | int size = width * height, i; |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 83 | uint32_t *vaddr; |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 84 | |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 85 | 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 Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 94 | unmapped_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 95 | { |
| 96 | drm_intel_bo *bo; |
| 97 | |
| 98 | bo = drm_intel_bo_alloc(bufmgr, "bo", 4*width*height, 0); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 99 | igt_assert(bo); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 100 | |
| 101 | return bo; |
| 102 | } |
| 103 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 104 | static void |
| 105 | gtt_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 106 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 107 | 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 | |
| 116 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 117 | gtt_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 118 | { |
| 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 Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 125 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static drm_intel_bo * |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 129 | map_bo(drm_intel_bo *bo) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 130 | { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 131 | /* 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 Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 139 | static drm_intel_bo * |
| 140 | tile_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 | |
| 150 | static drm_intel_bo * |
| 151 | gtt_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 152 | { |
| 153 | return map_bo(unmapped_create_bo(bufmgr, width, height)); |
| 154 | } |
| 155 | |
| 156 | static drm_intel_bo * |
| 157 | gttX_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 158 | { |
| 159 | return tile_bo(gtt_create_bo(bufmgr, width, height), width); |
| 160 | } |
| 161 | |
| 162 | static drm_intel_bo * |
| 163 | gpu_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) |
| 164 | { |
| 165 | return unmapped_create_bo(bufmgr, width, height); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | static drm_intel_bo * |
| 170 | gpuX_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 Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 175 | static void |
| 176 | cpu_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 | |
| 188 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 189 | cpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 190 | { |
| 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 Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 197 | igt_assert_eq_u32(*vaddr++, val); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 198 | drm_intel_bo_unmap(bo); |
| 199 | } |
| 200 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 201 | static void |
| 202 | gpu_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 Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 210 | uint32_t tiling, swizzle; |
| 211 | |
| 212 | drm_intel_bo_get_tiling(bo, &tiling, &swizzle); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 213 | |
| 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 Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 222 | 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 Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 228 | *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 Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 255 | if (gen >= 6) |
| 256 | execbuf.flags = I915_EXEC_BLT; |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 257 | |
| 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 Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 262 | 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 Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 264 | |
| 265 | drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &create.handle); |
| 266 | } |
| 267 | |
| 268 | static void |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 269 | gpu_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 270 | { |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 271 | intel_copy_bo(batch, tmp, bo, width*height*4); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 272 | cpu_cmp_bo(tmp, val, width, height, NULL); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 275 | struct access_mode { |
| 276 | void (*set_bo)(drm_intel_bo *bo, uint32_t val, int w, int h); |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 277 | void (*cmp_bo)(drm_intel_bo *bo, uint32_t val, int w, int h, drm_intel_bo *tmp); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 278 | drm_intel_bo *(*create_bo)(drm_intel_bufmgr *bufmgr, int width, int height); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 279 | const char *name; |
| 280 | }; |
| 281 | |
| 282 | struct 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 Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 289 | { .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo, |
| 290 | .create_bo = gttX_create_bo, .name = "gttX" }, |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 291 | { .set_bo = gpu_set_bo, .cmp_bo = gpu_cmp_bo, |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 292 | .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 Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 295 | }; |
| 296 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 297 | #define MAX_NUM_BUFFERS 1024 |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 298 | int num_buffers = MAX_NUM_BUFFERS; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 299 | const int width = 512, height = 512; |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 300 | igt_render_copyfunc_t rendercopy; |
| 301 | |
| 302 | typedef void (*do_copy)(drm_intel_bo *dst, drm_intel_bo *src); |
| 303 | |
| 304 | static 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 Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 309 | .num_tiles = width * height * 4, |
| 310 | .stride = width * 4, |
| 311 | }, s = { |
| 312 | .bo = src, |
| 313 | .size = width * height * 4, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 314 | .num_tiles = width * height * 4, |
| 315 | .stride = width * 4, |
| 316 | }; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 317 | 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 Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 322 | rendercopy(batch, NULL, |
| 323 | &s, 0, 0, |
| 324 | width, height, |
| 325 | &d, 0, 0); |
| 326 | } |
| 327 | |
| 328 | static void blt_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) |
| 329 | { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 330 | intel_blt_copy(batch, |
| 331 | src, 0, 0, 4*width, |
| 332 | dst, 0, 0, 4*width, |
| 333 | width, height, 32); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 334 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 335 | |
| 336 | static void do_overwrite_source(struct access_mode *mode, |
| 337 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 338 | drm_intel_bo *dummy, |
| 339 | do_copy do_copy_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 340 | { |
| 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 Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 346 | mode->set_bo(dst[i], ~i, width, height); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 347 | } |
| 348 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 349 | do_copy_func(dst[i], src[i]); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 350 | for (i = num_buffers; i--; ) |
| 351 | mode->set_bo(src[i], 0xdeadbeef, width, height); |
| 352 | for (i = 0; i < num_buffers; i++) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 353 | mode->cmp_bo(dst[i], i, width, height, dummy); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static void do_early_read(struct access_mode *mode, |
| 357 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 358 | drm_intel_bo *dummy, |
| 359 | do_copy do_copy_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 360 | { |
| 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 Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 367 | do_copy_func(dst[i], src[i]); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 368 | for (i = num_buffers; i--; ) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 369 | mode->cmp_bo(dst[i], 0xdeadbeef, width, height, dummy); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static void do_gpu_read_after_write(struct access_mode *mode, |
| 373 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 374 | drm_intel_bo *dummy, |
| 375 | do_copy do_copy_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 376 | { |
| 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 Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 383 | do_copy_func(dst[i], src[i]); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 384 | for (i = num_buffers; i--; ) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 385 | do_copy_func(dummy, dst[i]); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 386 | for (i = num_buffers; i--; ) |
Chris Wilson | c12f292 | 2014-08-31 16:14:40 +0100 | [diff] [blame] | 387 | mode->cmp_bo(dst[i], 0xabcdabcd, width, height, dummy); |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 388 | } |
| 389 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 390 | typedef void (*do_test)(struct access_mode *mode, |
| 391 | drm_intel_bo **src, drm_intel_bo **dst, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 392 | drm_intel_bo *dummy, |
| 393 | do_copy do_copy_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 394 | |
| 395 | typedef void (*run_wrap)(struct access_mode *mode, |
| 396 | drm_intel_bo **src, drm_intel_bo **dst, |
| 397 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 398 | do_test do_test_func, |
| 399 | do_copy do_copy_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 400 | |
| 401 | static void run_single(struct access_mode *mode, |
| 402 | drm_intel_bo **src, drm_intel_bo **dst, |
| 403 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 404 | do_test do_test_func, |
| 405 | do_copy do_copy_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 406 | { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 407 | do_test_func(mode, src, dst, dummy, do_copy_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 408 | } |
| 409 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 410 | static void run_interruptible(struct access_mode *mode, |
| 411 | drm_intel_bo **src, drm_intel_bo **dst, |
| 412 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 413 | do_test do_test_func, |
| 414 | do_copy do_copy_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 415 | { |
| 416 | int loop; |
| 417 | |
| 418 | for (loop = 0; loop < 10; loop++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 419 | do_test_func(mode, src, dst, dummy, do_copy_func); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void run_forked(struct access_mode *mode, |
| 423 | drm_intel_bo **src, drm_intel_bo **dst, |
| 424 | drm_intel_bo *dummy, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 425 | do_test do_test_func, |
| 426 | do_copy do_copy_func) |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 427 | { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 428 | const int old_num_buffers = num_buffers; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 429 | drm_intel_bufmgr *bufmgr; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 430 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 431 | num_buffers /= 16; |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 432 | num_buffers += 2; |
| 433 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 434 | igt_fork(child, 16) { |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 435 | /* recreate process local variables */ |
| 436 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 437 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 438 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 439 | for (int i = 0; i < num_buffers; i++) { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 440 | src[i] = mode->create_bo(bufmgr, width, height); |
| 441 | dst[i] = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 442 | } |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 443 | dummy = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 444 | for (int loop = 0; loop < 10; loop++) |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 445 | do_test_func(mode, src, dst, dummy, do_copy_func); |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 446 | /* 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 Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 454 | } |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 455 | |
| 456 | igt_waitchildren(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 457 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 458 | num_buffers = old_num_buffers; |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 459 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 460 | |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 461 | static void bcs_require(void) |
| 462 | { |
| 463 | } |
| 464 | |
| 465 | static void rcs_require(void) |
| 466 | { |
| 467 | igt_require(rendercopy); |
| 468 | } |
| 469 | |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 470 | static void |
| 471 | run_basic_modes(struct access_mode *mode, |
| 472 | drm_intel_bo **src, drm_intel_bo **dst, |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 473 | drm_intel_bo *dummy, const char *suffix, |
| 474 | run_wrap run_wrap_func) |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 475 | { |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 476 | struct { |
| 477 | const char *prefix; |
| 478 | do_copy copy; |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 479 | void (*require)(void); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 480 | } pipelines[] = { |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 481 | { "bcs", blt_copy_bo, bcs_require }, |
| 482 | { "rcs", render_copy_bo, rcs_require }, |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 483 | { NULL, NULL } |
| 484 | }, *p; |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 485 | |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 486 | for (p = pipelines; p->prefix; p++) { |
| 487 | /* try to overwrite the source values */ |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 488 | igt_subtest_f("%s-%s-overwrite-source%s", mode->name, p->prefix, suffix) { |
| 489 | p->require(); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 490 | run_wrap_func(mode, src, dst, dummy, |
| 491 | do_overwrite_source, p->copy); |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 492 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 493 | |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 494 | /* try to read the results before the copy completes */ |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 495 | igt_subtest_f("%s-%s-early-read%s", mode->name, p->prefix, suffix) { |
| 496 | p->require(); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 497 | run_wrap_func(mode, src, dst, dummy, |
| 498 | do_early_read, p->copy); |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 499 | } |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 500 | |
| 501 | /* and finally try to trick the kernel into loosing the pending write */ |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 502 | igt_subtest_f("%s-%s-gpu-read-after-write%s", mode->name, p->prefix, suffix) { |
| 503 | p->require(); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 504 | run_wrap_func(mode, src, dst, dummy, |
| 505 | do_gpu_read_after_write, p->copy); |
Chris Wilson | 0818875 | 2014-09-03 13:38:30 +0100 | [diff] [blame^] | 506 | } |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 507 | } |
Daniel Vetter | 5a598c9 | 2013-08-14 15:08:05 +0200 | [diff] [blame] | 508 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 509 | |
| 510 | static void |
| 511 | run_modes(struct access_mode *mode) |
| 512 | { |
Daniel Vetter | ad0f081 | 2013-08-26 20:41:00 +0200 | [diff] [blame] | 513 | drm_intel_bo *src[MAX_NUM_BUFFERS], *dst[MAX_NUM_BUFFERS], *dummy = NULL; |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 514 | drm_intel_bufmgr *bufmgr; |
Daniel Vetter | ad0f081 | 2013-08-26 20:41:00 +0200 | [diff] [blame] | 515 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 516 | igt_fixture { |
Chris Wilson | 0d320fd | 2013-08-16 12:07:56 +0100 | [diff] [blame] | 517 | bufmgr = drm_intel_bufmgr_gem_init(fd, 4096); |
| 518 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 519 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Chris Wilson | 0d320fd | 2013-08-16 12:07:56 +0100 | [diff] [blame] | 520 | |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 521 | for (int i = 0; i < num_buffers; i++) { |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 522 | src[i] = mode->create_bo(bufmgr, width, height); |
| 523 | dst[i] = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 524 | } |
Chris Wilson | 86055df | 2014-08-29 17:36:29 +0100 | [diff] [blame] | 525 | dummy = mode->create_bo(bufmgr, width, height); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Daniel Vetter | ec283d6 | 2013-08-14 15:18:37 +0200 | [diff] [blame] | 528 | run_basic_modes(mode, src, dst, dummy, "", run_single); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 529 | |
| 530 | igt_fork_signal_helper(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 531 | run_basic_modes(mode, src, dst, dummy, "-interruptible", run_interruptible); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 532 | igt_stop_signal_helper(); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 533 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 534 | igt_fixture { |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 535 | for (int i = 0; i < num_buffers; i++) { |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 536 | drm_intel_bo_unreference(src[i]); |
| 537 | drm_intel_bo_unreference(dst[i]); |
| 538 | } |
| 539 | drm_intel_bo_unreference(dummy); |
Chris Wilson | 0d320fd | 2013-08-16 12:07:56 +0100 | [diff] [blame] | 540 | intel_batchbuffer_free(batch); |
| 541 | drm_intel_bufmgr_destroy(bufmgr); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 542 | } |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 543 | |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 544 | igt_fork_signal_helper(); |
Chris Wilson | 1ca607b | 2013-08-16 09:44:13 +0100 | [diff] [blame] | 545 | run_basic_modes(mode, src, dst, dummy, "-forked", run_forked); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 546 | igt_stop_signal_helper(); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Daniel Vetter | 071e9ca | 2013-10-31 16:23:26 +0100 | [diff] [blame] | 549 | igt_main |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 550 | { |
| 551 | int max, i; |
| 552 | |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 553 | igt_skip_on_simulation(); |
| 554 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 555 | igt_fixture { |
| 556 | fd = drm_open_any(); |
Chris Wilson | 6c428a6 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 557 | devid = intel_get_drm_devid(fd); |
| 558 | gen = intel_gen(devid); |
Chris Wilson | 59c5562 | 2014-08-29 13:11:37 +0100 | [diff] [blame] | 559 | rendercopy = igt_get_render_copyfunc(devid); |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 560 | |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 561 | max = gem_aperture_size (fd) / (1024 * 1024) / 2; |
| 562 | if (num_buffers > max) |
| 563 | num_buffers = max; |
Daniel Vetter | aee0dcb | 2013-12-03 16:32:52 +0100 | [diff] [blame] | 564 | |
| 565 | max = intel_get_total_ram_mb() * 3 / 4; |
| 566 | if (num_buffers > max) |
| 567 | num_buffers = max; |
Chris Wilson | 0b4c33f | 2014-01-26 14:36:32 +0000 | [diff] [blame] | 568 | num_buffers /= 2; |
Daniel Vetter | e624fa8 | 2014-05-14 00:36:04 +0200 | [diff] [blame] | 569 | igt_info("using 2x%d buffers, each 1MiB\n", num_buffers); |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 570 | } |
Daniel Vetter | 43779e3 | 2013-08-14 14:50:50 +0200 | [diff] [blame] | 571 | |
| 572 | for (i = 0; i < ARRAY_SIZE(access_modes); i++) |
| 573 | run_modes(&access_modes[i]); |
Daniel Vetter | 3dba47e | 2013-08-06 22:27:37 +0200 | [diff] [blame] | 574 | } |