Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Daniel Vetter |
| 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 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 25 | * |
| 26 | * Partially based upon gem_tiled_fence_blits.c |
| 27 | */ |
| 28 | |
| 29 | /** @file gem_stress.c |
| 30 | * |
| 31 | * This is a general gem coherency test. It's designed to eventually replicate |
| 32 | * any possible sequence of access patterns. It works by copying a set of tiles |
| 33 | * between two sets of backing buffer objects, randomly permutating the assinged |
| 34 | * position on each copy operations. |
| 35 | * |
| 36 | * The copy operation are done in tiny portions (to reduce any race windows |
| 37 | * for corruptions, hence increasing the chances for observing one) and are |
| 38 | * constantly switched between all means to copy stuff (fenced blitter, unfenced |
| 39 | * render, mmap, pwrite/read). |
| 40 | * |
| 41 | * After every complete move of a set tiling parameters of a buffer are randomly |
| 42 | * changed to simulate the effects of libdrm caching. |
| 43 | * |
| 44 | * Buffers are 1mb big to nicely fit into fences on gen2/3. A few are further |
| 45 | * split up to test relaxed fencing. Using this to push the average working set |
| 46 | * size over the available gtt space forces objects to be mapped as unfenceable |
| 47 | * (and as a side-effect tests gtt map/unmap coherency). |
| 48 | * |
| 49 | * In short: designed for maximum evilness. |
| 50 | */ |
| 51 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 52 | #include "igt.h" |
Daniel Vetter | 7dc0001 | 2014-03-22 15:31:15 +0100 | [diff] [blame] | 53 | #include <stdlib.h> |
| 54 | #include <sys/ioctl.h> |
| 55 | #include <stdio.h> |
| 56 | #include <string.h> |
Daniel Vetter | 7dc0001 | 2014-03-22 15:31:15 +0100 | [diff] [blame] | 57 | #include <fcntl.h> |
| 58 | #include <inttypes.h> |
| 59 | #include <errno.h> |
| 60 | #include <sys/stat.h> |
| 61 | #include <sys/time.h> |
Daniel Vetter | f5daeec | 2014-03-23 13:35:09 +0100 | [diff] [blame] | 62 | |
| 63 | #include <drm.h> |
| 64 | |
Daniel Vetter | 7dc0001 | 2014-03-22 15:31:15 +0100 | [diff] [blame] | 65 | #include "intel_bufmgr.h" |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 66 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 67 | IGT_TEST_DESCRIPTION("General gem coherency test."); |
| 68 | |
Daniel Vetter | 2aac223 | 2011-03-25 21:53:07 +0100 | [diff] [blame] | 69 | #define CMD_POLY_STIPPLE_OFFSET 0x7906 |
| 70 | |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 71 | #define DUCTAPE 0xdead0001 |
| 72 | #define TILESZ 0xdead0002 |
| 73 | #define CHCK_RENDER 0xdead0003 |
| 74 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 75 | /** TODO: |
| 76 | * - beat on relaxed fencing (i.e. mappable/fenceable tracking in the kernel) |
| 77 | * - render copy (to check fence tracking and cache coherency management by the |
| 78 | * kernel) |
| 79 | * - multi-threading: probably just a wrapper script to launch multiple |
| 80 | * instances + an option to accordingly reduce the working set |
| 81 | * - gen6 inter-ring coherency (needs render copy, first) |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 82 | * - variable buffer size |
| 83 | * - add an option to fork a second process that randomly sends signals to the |
| 84 | * first one (to check consistency of the kernel recovery paths) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 85 | */ |
| 86 | |
Daniel Vetter | a6751ba | 2011-03-31 23:29:25 +0200 | [diff] [blame] | 87 | drm_intel_bufmgr *bufmgr; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 88 | struct intel_batchbuffer *batch; |
Daniel Vetter | a6751ba | 2011-03-31 23:29:25 +0200 | [diff] [blame] | 89 | int drm_fd; |
| 90 | int devid; |
| 91 | int num_fences; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 92 | |
| 93 | drm_intel_bo *busy_bo; |
| 94 | |
Daniel Vetter | b9fe673 | 2012-01-18 17:47:33 +0100 | [diff] [blame] | 95 | struct option_struct { |
| 96 | unsigned scratch_buf_size; |
| 97 | unsigned max_dimension; |
| 98 | unsigned num_buffers; |
| 99 | int trace_tile; |
| 100 | int no_hw; |
| 101 | int gpu_busy_load; |
| 102 | int use_render; |
| 103 | int use_blt; |
| 104 | int forced_tiling; |
| 105 | int use_cpu_maps; |
| 106 | int total_rounds; |
| 107 | int fail; |
| 108 | int tiles_per_buf; |
| 109 | int ducttape; |
| 110 | int tile_size; |
| 111 | int check_render_cpyfn; |
| 112 | int use_signal_helper; |
| 113 | }; |
| 114 | |
Daniel Vetter | a6751ba | 2011-03-31 23:29:25 +0200 | [diff] [blame] | 115 | struct option_struct options; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 116 | |
Daniel Vetter | 699d309 | 2012-01-18 01:03:20 +0100 | [diff] [blame] | 117 | #define MAX_BUFS 4096 |
| 118 | #define SCRATCH_BUF_SIZE 1024*1024 |
| 119 | #define BUSY_BUF_SIZE (256*4096) |
| 120 | #define TILE_BYTES(size) ((size)*(size)*sizeof(uint32_t)) |
| 121 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 122 | static struct igt_buf buffers[2][MAX_BUFS]; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 123 | /* tile i is at logical position tile_permutation[i] */ |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 124 | static unsigned *tile_permutation; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 125 | static unsigned num_buffers = 0; |
| 126 | static unsigned current_set = 0; |
| 127 | static unsigned target_set = 0; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 128 | static unsigned num_total_tiles = 0; |
| 129 | |
Daniel Vetter | a6751ba | 2011-03-31 23:29:25 +0200 | [diff] [blame] | 130 | int fence_storm = 0; |
Daniel Vetter | 294c78f | 2011-03-27 15:25:12 +0200 | [diff] [blame] | 131 | static int gpu_busy_load = 10; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 132 | |
Daniel Vetter | 336f85d | 2011-06-13 22:02:52 +0200 | [diff] [blame] | 133 | struct { |
| 134 | unsigned num_failed; |
| 135 | unsigned max_failed_reads; |
| 136 | } stats; |
| 137 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 138 | static void tile2xy(struct igt_buf *buf, unsigned tile, unsigned *x, unsigned *y) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 139 | { |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 140 | igt_assert(tile < buf->num_tiles); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 141 | *x = (tile*options.tile_size) % (buf->stride/sizeof(uint32_t)); |
| 142 | *y = ((tile*options.tile_size) / (buf->stride/sizeof(uint32_t))) * options.tile_size; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 143 | } |
| 144 | |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 145 | static void emit_blt(drm_intel_bo *src_bo, uint32_t src_tiling, unsigned src_pitch, |
| 146 | unsigned src_x, unsigned src_y, unsigned w, unsigned h, |
| 147 | drm_intel_bo *dst_bo, uint32_t dst_tiling, unsigned dst_pitch, |
| 148 | unsigned dst_x, unsigned dst_y) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 149 | { |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 150 | uint32_t cmd_bits = 0; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 151 | |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 152 | if (IS_965(devid) && src_tiling) { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 153 | src_pitch /= 4; |
| 154 | cmd_bits |= XY_SRC_COPY_BLT_SRC_TILED; |
| 155 | } |
| 156 | |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 157 | if (IS_965(devid) && dst_tiling) { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 158 | dst_pitch /= 4; |
| 159 | cmd_bits |= XY_SRC_COPY_BLT_DST_TILED; |
| 160 | } |
| 161 | |
| 162 | /* copy lower half to upper half */ |
Chris Wilson | 10552b5 | 2014-08-30 11:44:51 +0100 | [diff] [blame] | 163 | BLIT_COPY_BATCH_START(cmd_bits); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 164 | OUT_BATCH((3 << 24) | /* 32 bits */ |
| 165 | (0xcc << 16) | /* copy ROP */ |
| 166 | dst_pitch); |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 167 | OUT_BATCH(dst_y << 16 | dst_x); |
| 168 | OUT_BATCH((dst_y+h) << 16 | (dst_x+w)); |
| 169 | OUT_RELOC_FENCED(dst_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0); |
| 170 | OUT_BATCH(src_y << 16 | src_x); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 171 | OUT_BATCH(src_pitch); |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 172 | OUT_RELOC_FENCED(src_bo, I915_GEM_DOMAIN_RENDER, 0, 0); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 173 | ADVANCE_BATCH(); |
Daniel Vetter | 7af82bb | 2011-11-27 02:39:14 +0100 | [diff] [blame] | 174 | |
Chris Wilson | 10552b5 | 2014-08-30 11:44:51 +0100 | [diff] [blame] | 175 | if (batch->gen >= 6) { |
| 176 | BEGIN_BATCH(3, 0); |
Daniel Vetter | 7af82bb | 2011-11-27 02:39:14 +0100 | [diff] [blame] | 177 | OUT_BATCH(XY_SETUP_CLIP_BLT_CMD); |
| 178 | OUT_BATCH(0); |
| 179 | OUT_BATCH(0); |
| 180 | ADVANCE_BATCH(); |
| 181 | } |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 184 | /* All this gem trashing wastes too much cpu time, so give the gpu something to |
| 185 | * do to increase changes for races. */ |
Daniel Vetter | f7c2dab | 2012-01-18 17:51:48 +0100 | [diff] [blame] | 186 | static void keep_gpu_busy(void) |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 187 | { |
| 188 | int tmp; |
| 189 | |
| 190 | tmp = 1 << gpu_busy_load; |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 191 | igt_assert_lte(tmp, 1024); |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 192 | |
| 193 | emit_blt(busy_bo, 0, 4096, 0, 0, tmp, 128, |
| 194 | busy_bo, 0, 4096, 0, 128); |
| 195 | } |
| 196 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 197 | static void set_to_cpu_domain(struct igt_buf *buf, int writing) |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 198 | { |
Daniel Vetter | 673e6b2 | 2012-01-10 16:05:34 +0100 | [diff] [blame] | 199 | gem_set_domain(drm_fd, buf->bo->handle, I915_GEM_DOMAIN_CPU, |
| 200 | writing ? I915_GEM_DOMAIN_CPU : 0); |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 203 | static unsigned int copyfunc_seq = 0; |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 204 | static void (*copyfunc)(struct igt_buf *src, unsigned src_x, unsigned src_y, |
| 205 | struct igt_buf *dst, unsigned dst_x, unsigned dst_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 206 | unsigned logical_tile_no); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 207 | |
| 208 | /* stride, x, y in units of uint32_t! */ |
| 209 | static void cpucpy2d(uint32_t *src, unsigned src_stride, unsigned src_x, unsigned src_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 210 | uint32_t *dst, unsigned dst_stride, unsigned dst_x, unsigned dst_y, |
| 211 | unsigned logical_tile_no) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 212 | { |
| 213 | int i, j; |
Daniel Vetter | 874163d | 2011-03-27 14:02:49 +0200 | [diff] [blame] | 214 | int failed = 0; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 215 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 216 | for (i = 0; i < options.tile_size; i++) { |
| 217 | for (j = 0; j < options.tile_size; j++) { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 218 | unsigned dst_ofs = dst_x + j + dst_stride * (dst_y + i); |
| 219 | unsigned src_ofs = src_x + j + src_stride * (src_y + i); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 220 | unsigned expect = logical_tile_no*options.tile_size*options.tile_size |
| 221 | + i*options.tile_size + j; |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 222 | uint32_t tmp = src[src_ofs]; |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 223 | if (tmp != expect) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 224 | igt_info("mismatch at tile %i pos %i, read %i, expected %i, diff %i\n", logical_tile_no, i * options.tile_size + j, tmp, expect, (int)tmp - expect); |
| 225 | igt_fail_on(options.trace_tile >= 0 && options.fail); |
Daniel Vetter | 336f85d | 2011-06-13 22:02:52 +0200 | [diff] [blame] | 226 | failed++; |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 227 | } |
Daniel Vetter | 6daa883 | 2011-06-13 00:22:01 +0200 | [diff] [blame] | 228 | /* when not aborting, correct any errors */ |
| 229 | dst[dst_ofs] = expect; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 230 | } |
| 231 | } |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 232 | igt_fail_on(failed && options.fail); |
Daniel Vetter | 336f85d | 2011-06-13 22:02:52 +0200 | [diff] [blame] | 233 | |
| 234 | if (failed > stats.max_failed_reads) |
| 235 | stats.max_failed_reads = failed; |
| 236 | if (failed) |
| 237 | stats.num_failed++; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 240 | static void cpu_copyfunc(struct igt_buf *src, unsigned src_x, unsigned src_y, |
| 241 | struct igt_buf *dst, unsigned dst_x, unsigned dst_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 242 | unsigned logical_tile_no) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 243 | { |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 244 | igt_assert(batch->ptr == batch->buffer); |
Chris Wilson | 75f7e81 | 2011-05-25 14:49:40 +0100 | [diff] [blame] | 245 | |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 246 | if (options.ducttape) |
| 247 | drm_intel_bo_wait_rendering(dst->bo); |
| 248 | |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 249 | if (options.use_cpu_maps) { |
| 250 | set_to_cpu_domain(src, 0); |
| 251 | set_to_cpu_domain(dst, 1); |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 254 | cpucpy2d(src->data, src->stride/sizeof(uint32_t), src_x, src_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 255 | dst->data, dst->stride/sizeof(uint32_t), dst_x, dst_y, |
| 256 | logical_tile_no); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 259 | static void prw_copyfunc(struct igt_buf *src, unsigned src_x, unsigned src_y, |
| 260 | struct igt_buf *dst, unsigned dst_x, unsigned dst_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 261 | unsigned logical_tile_no) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 262 | { |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 263 | uint32_t tmp_tile[options.tile_size*options.tile_size]; |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 264 | int i; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 265 | |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 266 | igt_assert(batch->ptr == batch->buffer); |
Chris Wilson | 75f7e81 | 2011-05-25 14:49:40 +0100 | [diff] [blame] | 267 | |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 268 | if (options.ducttape) |
| 269 | drm_intel_bo_wait_rendering(dst->bo); |
| 270 | |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 271 | if (src->tiling == I915_TILING_NONE) { |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 272 | for (i = 0; i < options.tile_size; i++) { |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 273 | unsigned ofs = src_x*sizeof(uint32_t) + src->stride*(src_y + i); |
| 274 | drm_intel_bo_get_subdata(src->bo, ofs, |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 275 | options.tile_size*sizeof(uint32_t), |
| 276 | tmp_tile + options.tile_size*i); |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 277 | } |
| 278 | } else { |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 279 | if (options.use_cpu_maps) |
| 280 | set_to_cpu_domain(src, 0); |
| 281 | |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 282 | cpucpy2d(src->data, src->stride/sizeof(uint32_t), src_x, src_y, |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 283 | tmp_tile, options.tile_size, 0, 0, logical_tile_no); |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if (dst->tiling == I915_TILING_NONE) { |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 287 | for (i = 0; i < options.tile_size; i++) { |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 288 | unsigned ofs = dst_x*sizeof(uint32_t) + dst->stride*(dst_y + i); |
| 289 | drm_intel_bo_subdata(dst->bo, ofs, |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 290 | options.tile_size*sizeof(uint32_t), |
| 291 | tmp_tile + options.tile_size*i); |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 292 | } |
| 293 | } else { |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 294 | if (options.use_cpu_maps) |
| 295 | set_to_cpu_domain(dst, 1); |
| 296 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 297 | cpucpy2d(tmp_tile, options.tile_size, 0, 0, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 298 | dst->data, dst->stride/sizeof(uint32_t), dst_x, dst_y, |
| 299 | logical_tile_no); |
| 300 | } |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 303 | static void blitter_copyfunc(struct igt_buf *src, unsigned src_x, unsigned src_y, |
| 304 | struct igt_buf *dst, unsigned dst_x, unsigned dst_y, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 305 | unsigned logical_tile_no) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 306 | { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 307 | static unsigned keep_gpu_busy_counter = 0; |
| 308 | |
| 309 | /* check both edges of the fence usage */ |
| 310 | if (keep_gpu_busy_counter & 1 && !fence_storm) |
| 311 | keep_gpu_busy(); |
| 312 | |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 313 | emit_blt(src->bo, src->tiling, src->stride, src_x, src_y, |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 314 | options.tile_size, options.tile_size, |
Daniel Vetter | aeb0b6f | 2011-04-03 13:10:07 +0200 | [diff] [blame] | 315 | dst->bo, dst->tiling, dst->stride, dst_x, dst_y); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 316 | |
| 317 | if (!(keep_gpu_busy_counter & 1) && !fence_storm) |
| 318 | keep_gpu_busy(); |
| 319 | |
| 320 | keep_gpu_busy_counter++; |
| 321 | |
| 322 | if (src->tiling) |
| 323 | fence_storm--; |
| 324 | if (dst->tiling) |
| 325 | fence_storm--; |
| 326 | |
Daniel Vetter | 3f10ff8 | 2011-03-21 22:13:18 +0100 | [diff] [blame] | 327 | if (fence_storm <= 1) { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 328 | fence_storm = 0; |
| 329 | intel_batchbuffer_flush(batch); |
| 330 | } |
| 331 | } |
| 332 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 333 | static void render_copyfunc(struct igt_buf *src, unsigned src_x, unsigned src_y, |
| 334 | struct igt_buf *dst, unsigned dst_x, unsigned dst_y, |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 335 | unsigned logical_tile_no) |
| 336 | { |
Daniel Vetter | f7c2dab | 2012-01-18 17:51:48 +0100 | [diff] [blame] | 337 | static unsigned keep_gpu_busy_counter = 0; |
Daniel Vetter | 53a4d9e | 2014-03-22 15:49:02 +0100 | [diff] [blame] | 338 | igt_render_copyfunc_t rendercopy = igt_get_render_copyfunc(devid); |
Daniel Vetter | f7c2dab | 2012-01-18 17:51:48 +0100 | [diff] [blame] | 339 | |
| 340 | /* check both edges of the fence usage */ |
| 341 | if (keep_gpu_busy_counter & 1) |
| 342 | keep_gpu_busy(); |
| 343 | |
Ville Syrjälä | fa86e33 | 2014-04-28 17:58:45 +0300 | [diff] [blame] | 344 | if (rendercopy) { |
| 345 | /* |
| 346 | * Flush outstanding blts so that they don't end up on |
| 347 | * the render ring when that's not allowed (gen6+). |
| 348 | */ |
| 349 | intel_batchbuffer_flush(batch); |
Ville Syrjälä | 725da6e | 2013-11-21 19:05:17 +0200 | [diff] [blame] | 350 | rendercopy(batch, NULL, src, src_x, src_y, |
Daniel Vetter | 64f669f | 2012-11-29 14:59:57 +0100 | [diff] [blame] | 351 | options.tile_size, options.tile_size, |
| 352 | dst, dst_x, dst_y); |
Ville Syrjälä | fa86e33 | 2014-04-28 17:58:45 +0300 | [diff] [blame] | 353 | } else |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 354 | blitter_copyfunc(src, src_x, src_y, |
| 355 | dst, dst_x, dst_y, |
| 356 | logical_tile_no); |
Daniel Vetter | f7c2dab | 2012-01-18 17:51:48 +0100 | [diff] [blame] | 357 | if (!(keep_gpu_busy_counter & 1)) |
| 358 | keep_gpu_busy(); |
| 359 | |
| 360 | keep_gpu_busy_counter++; |
| 361 | intel_batchbuffer_flush(batch); |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 362 | } |
| 363 | |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 364 | static void next_copyfunc(int tile) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 365 | { |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 366 | if (fence_storm) { |
| 367 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 368 | igt_info(" using fence storm\n"); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 369 | return; |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 370 | } |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 371 | |
Daniel Vetter | fde66f9 | 2011-06-06 20:15:44 +0200 | [diff] [blame] | 372 | if (copyfunc_seq % 61 == 0 |
| 373 | && options.forced_tiling != I915_TILING_NONE) { |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 374 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 375 | igt_info(" using fence storm\n"); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 376 | fence_storm = num_fences; |
| 377 | copyfunc = blitter_copyfunc; |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 378 | } else if (copyfunc_seq % 17 == 0) { |
| 379 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 380 | igt_info(" using cpu\n"); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 381 | copyfunc = cpu_copyfunc; |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 382 | } else if (copyfunc_seq % 19 == 0) { |
| 383 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 384 | igt_info(" using prw\n"); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 385 | copyfunc = prw_copyfunc; |
Daniel Vetter | 1baab2e | 2011-03-30 21:46:04 +0200 | [diff] [blame] | 386 | } else if (copyfunc_seq % 3 == 0 && options.use_render) { |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 387 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 388 | igt_info(" using render\n"); |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 389 | copyfunc = render_copyfunc; |
Chris Wilson | 4e1f2f5 | 2011-05-25 13:41:28 +0100 | [diff] [blame] | 390 | } else if (options.use_blt){ |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 391 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 392 | igt_info(" using blitter\n"); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 393 | copyfunc = blitter_copyfunc; |
Chris Wilson | 4e1f2f5 | 2011-05-25 13:41:28 +0100 | [diff] [blame] | 394 | } else if (options.use_render){ |
| 395 | if (tile == options.trace_tile) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 396 | igt_info(" using render\n"); |
Chris Wilson | 4e1f2f5 | 2011-05-25 13:41:28 +0100 | [diff] [blame] | 397 | copyfunc = render_copyfunc; |
| 398 | } else { |
| 399 | copyfunc = cpu_copyfunc; |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 400 | } |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 401 | |
| 402 | copyfunc_seq++; |
| 403 | } |
| 404 | |
| 405 | static void fan_out(void) |
| 406 | { |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 407 | uint32_t tmp_tile[options.tile_size*options.tile_size]; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 408 | uint32_t seq = 0; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 409 | int i, k; |
| 410 | unsigned tile, buf_idx, x, y; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 411 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 412 | for (i = 0; i < num_total_tiles; i++) { |
| 413 | tile = i; |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 414 | buf_idx = tile / options.tiles_per_buf; |
| 415 | tile %= options.tiles_per_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 416 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 417 | tile2xy(&buffers[current_set][buf_idx], tile, &x, &y); |
| 418 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 419 | for (k = 0; k < options.tile_size*options.tile_size; k++) |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 420 | tmp_tile[k] = seq++; |
| 421 | |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 422 | if (options.use_cpu_maps) |
| 423 | set_to_cpu_domain(&buffers[current_set][buf_idx], 1); |
| 424 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 425 | cpucpy2d(tmp_tile, options.tile_size, 0, 0, |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 426 | buffers[current_set][buf_idx].data, |
| 427 | buffers[current_set][buf_idx].stride / sizeof(uint32_t), |
| 428 | x, y, i); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 431 | for (i = 0; i < num_total_tiles; i++) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 432 | tile_permutation[i] = i; |
| 433 | } |
| 434 | |
| 435 | static void fan_in_and_check(void) |
| 436 | { |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 437 | uint32_t tmp_tile[options.tile_size*options.tile_size]; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 438 | unsigned tile, buf_idx, x, y; |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 439 | int i; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 440 | for (i = 0; i < num_total_tiles; i++) { |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 441 | tile = tile_permutation[i]; |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 442 | buf_idx = tile / options.tiles_per_buf; |
| 443 | tile %= options.tiles_per_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 444 | |
| 445 | tile2xy(&buffers[current_set][buf_idx], tile, &x, &y); |
| 446 | |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 447 | if (options.use_cpu_maps) |
| 448 | set_to_cpu_domain(&buffers[current_set][buf_idx], 0); |
| 449 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 450 | cpucpy2d(buffers[current_set][buf_idx].data, |
| 451 | buffers[current_set][buf_idx].stride / sizeof(uint32_t), |
| 452 | x, y, |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 453 | tmp_tile, options.tile_size, 0, 0, |
Daniel Vetter | 80aae9b | 2011-03-20 21:12:20 +0100 | [diff] [blame] | 454 | i); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 458 | static void sanitize_stride(struct igt_buf *buf) |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 459 | { |
| 460 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 461 | if (igt_buf_height(buf) > options.max_dimension) |
Daniel Vetter | 205510b | 2012-01-18 00:34:15 +0100 | [diff] [blame] | 462 | buf->stride = buf->size / options.max_dimension; |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 463 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 464 | if (igt_buf_height(buf) < options.tile_size) |
Daniel Vetter | 205510b | 2012-01-18 00:34:15 +0100 | [diff] [blame] | 465 | buf->stride = buf->size / options.tile_size; |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 466 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 467 | if (igt_buf_width(buf) < options.tile_size) |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 468 | buf->stride = options.tile_size * sizeof(uint32_t); |
| 469 | |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 470 | igt_assert(buf->stride <= 8192); |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 471 | igt_assert(igt_buf_width(buf) <= options.max_dimension); |
| 472 | igt_assert(igt_buf_height(buf) <= options.max_dimension); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 473 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 474 | igt_assert(igt_buf_width(buf) >= options.tile_size); |
| 475 | igt_assert(igt_buf_height(buf) >= options.tile_size); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 476 | |
| 477 | } |
| 478 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 479 | static void init_buffer(struct igt_buf *buf, unsigned size) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 480 | { |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 481 | buf->bo = drm_intel_bo_alloc(bufmgr, "tiled bo", size, 4096); |
Daniel Vetter | 205510b | 2012-01-18 00:34:15 +0100 | [diff] [blame] | 482 | buf->size = size; |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 483 | igt_assert(buf->bo); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 484 | buf->tiling = I915_TILING_NONE; |
Daniel Vetter | 1095a82 | 2011-06-06 20:16:35 +0200 | [diff] [blame] | 485 | buf->stride = 4096; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 486 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 487 | sanitize_stride(buf); |
| 488 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 489 | if (options.no_hw) |
| 490 | buf->data = malloc(size); |
| 491 | else { |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 492 | if (options.use_cpu_maps) |
| 493 | drm_intel_bo_map(buf->bo, 1); |
| 494 | else |
| 495 | drm_intel_gem_bo_map_gtt(buf->bo); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 496 | buf->data = buf->bo->virtual; |
| 497 | } |
| 498 | |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 499 | buf->num_tiles = options.tiles_per_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 500 | } |
| 501 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 502 | static void exchange_buf(void *array, unsigned i, unsigned j) |
| 503 | { |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 504 | struct igt_buf *buf_arr, tmp; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 505 | buf_arr = array; |
| 506 | |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 507 | memcpy(&tmp, &buf_arr[i], sizeof(struct igt_buf)); |
| 508 | memcpy(&buf_arr[i], &buf_arr[j], sizeof(struct igt_buf)); |
| 509 | memcpy(&buf_arr[j], &tmp, sizeof(struct igt_buf)); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 510 | } |
| 511 | |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 512 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 513 | static void init_set(unsigned set) |
| 514 | { |
| 515 | long int r; |
| 516 | int i; |
| 517 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 518 | igt_permute_array(buffers[set], num_buffers, exchange_buf); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 519 | |
Daniel Vetter | 294c78f | 2011-03-27 15:25:12 +0200 | [diff] [blame] | 520 | if (current_set == 1 && options.gpu_busy_load == 0) { |
| 521 | gpu_busy_load++; |
| 522 | if (gpu_busy_load > 10) |
| 523 | gpu_busy_load = 6; |
| 524 | } |
| 525 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 526 | for (i = 0; i < num_buffers; i++) { |
| 527 | r = random(); |
| 528 | if ((r & 3) != 0) |
| 529 | continue; |
| 530 | r >>= 2; |
| 531 | |
| 532 | if ((r & 3) != 0) |
| 533 | buffers[set][i].tiling = I915_TILING_X; |
| 534 | else |
| 535 | buffers[set][i].tiling = I915_TILING_NONE; |
| 536 | r >>= 2; |
Daniel Vetter | a67091b | 2011-04-12 22:26:42 +0200 | [diff] [blame] | 537 | if (options.forced_tiling >= 0) |
| 538 | buffers[set][i].tiling = options.forced_tiling; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 539 | |
| 540 | if (buffers[set][i].tiling == I915_TILING_NONE) { |
| 541 | /* min 64 byte stride */ |
| 542 | r %= 8; |
| 543 | buffers[set][i].stride = 64 * (1 << r); |
| 544 | } else if (IS_GEN2(devid)) { |
| 545 | /* min 128 byte stride */ |
| 546 | r %= 7; |
| 547 | buffers[set][i].stride = 128 * (1 << r); |
| 548 | } else { |
| 549 | /* min 512 byte stride */ |
| 550 | r %= 5; |
| 551 | buffers[set][i].stride = 512 * (1 << r); |
| 552 | } |
Chris Wilson | 3d66d91 | 2011-06-05 21:53:49 +0100 | [diff] [blame] | 553 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 554 | sanitize_stride(&buffers[set][i]); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 555 | |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 556 | gem_set_tiling(drm_fd, buffers[set][i].bo->handle, |
| 557 | buffers[set][i].tiling, |
| 558 | buffers[set][i].stride); |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 559 | |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 560 | if (options.trace_tile != -1 && i == options.trace_tile/options.tiles_per_buf) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 561 | igt_info("changing buffer %i containing tile %i: tiling %i, stride %i\n", i, options.trace_tile, buffers[set][i].tiling, buffers[set][i].stride); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
| 565 | static void exchange_uint(void *array, unsigned i, unsigned j) |
| 566 | { |
| 567 | unsigned *i_arr = array; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 568 | |
Daniel Vetter | 2eca38e | 2015-02-07 12:37:48 +0100 | [diff] [blame] | 569 | igt_swap(i_arr[i], i_arr[j]); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void copy_tiles(unsigned *permutation) |
| 573 | { |
| 574 | unsigned src_tile, src_buf_idx, src_x, src_y; |
| 575 | unsigned dst_tile, dst_buf_idx, dst_x, dst_y; |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 576 | struct igt_buf *src_buf, *dst_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 577 | int i, idx; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 578 | for (i = 0; i < num_total_tiles; i++) { |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 579 | /* tile_permutation is independent of current_permutation, so |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 580 | * abuse it to randomize the order of the src bos */ |
| 581 | idx = tile_permutation[i]; |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 582 | src_buf_idx = idx / options.tiles_per_buf; |
| 583 | src_tile = idx % options.tiles_per_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 584 | src_buf = &buffers[current_set][src_buf_idx]; |
| 585 | |
| 586 | tile2xy(src_buf, src_tile, &src_x, &src_y); |
| 587 | |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 588 | dst_buf_idx = permutation[idx] / options.tiles_per_buf; |
| 589 | dst_tile = permutation[idx] % options.tiles_per_buf; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 590 | dst_buf = &buffers[target_set][dst_buf_idx]; |
| 591 | |
| 592 | tile2xy(dst_buf, dst_tile, &dst_x, &dst_y); |
| 593 | |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 594 | if (options.trace_tile == i) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 595 | igt_info("copying tile %i from %i (%i, %i) to %i (%i, %i)", i, tile_permutation[i], src_buf_idx, src_tile, permutation[idx], dst_buf_idx, dst_tile); |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 596 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 597 | if (options.no_hw) { |
| 598 | cpucpy2d(src_buf->data, |
| 599 | src_buf->stride / sizeof(uint32_t), |
| 600 | src_x, src_y, |
| 601 | dst_buf->data, |
| 602 | dst_buf->stride / sizeof(uint32_t), |
| 603 | dst_x, dst_y, |
| 604 | i); |
| 605 | } else { |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 606 | next_copyfunc(i); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 607 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 608 | copyfunc(src_buf, src_x, src_y, dst_buf, dst_x, dst_y, |
| 609 | i); |
| 610 | } |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | intel_batchbuffer_flush(batch); |
| 614 | } |
| 615 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 616 | static void sanitize_tiles_per_buf(void) |
| 617 | { |
| 618 | if (options.tiles_per_buf > options.scratch_buf_size / TILE_BYTES(options.tile_size)) |
| 619 | options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size); |
| 620 | } |
| 621 | |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 622 | static int parse_options(int opt, int opt_index, void *data) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 623 | { |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 624 | int tmp; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 625 | |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 626 | switch(opt) { |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 627 | case 'd': |
| 628 | options.no_hw = 1; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 629 | igt_info("no-hw debug mode\n"); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 630 | break; |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 631 | case 'S': |
| 632 | options.use_signal_helper = 0; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 633 | igt_info("disabling that pesky nuisance who keeps interrupting us\n"); |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 634 | break; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 635 | case 's': |
| 636 | tmp = atoi(optarg); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 637 | if (tmp < options.tile_size*8192) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 638 | igt_info("scratch buffer size needs to be at least %i\n", options.tile_size * 8192); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 639 | else if (tmp & (tmp - 1)) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 640 | igt_info("scratch buffer size needs to be a power-of-two\n"); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 641 | } else { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 642 | igt_info("fixed scratch buffer size to %u\n", tmp); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 643 | options.scratch_buf_size = tmp; |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 644 | sanitize_tiles_per_buf(); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 645 | } |
| 646 | break; |
Daniel Vetter | 294c78f | 2011-03-27 15:25:12 +0200 | [diff] [blame] | 647 | case 'g': |
| 648 | tmp = atoi(optarg); |
| 649 | if (tmp < 0 || tmp > 10) |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 650 | igt_info("gpu busy load needs to be bigger than 0 and smaller than 10\n"); |
Daniel Vetter | 294c78f | 2011-03-27 15:25:12 +0200 | [diff] [blame] | 651 | else { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 652 | igt_info("gpu busy load factor set to %i\n", tmp); |
Daniel Vetter | 294c78f | 2011-03-27 15:25:12 +0200 | [diff] [blame] | 653 | gpu_busy_load = options.gpu_busy_load = tmp; |
| 654 | } |
| 655 | break; |
Daniel Vetter | 130daf9 | 2011-03-27 15:37:26 +0200 | [diff] [blame] | 656 | case 'c': |
| 657 | options.num_buffers = atoi(optarg); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 658 | igt_info("buffer count set to %i\n", options.num_buffers); |
Daniel Vetter | 130daf9 | 2011-03-27 15:37:26 +0200 | [diff] [blame] | 659 | break; |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 660 | case 't': |
| 661 | options.trace_tile = atoi(optarg); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 662 | igt_info("tracing tile %i\n", options.trace_tile); |
Daniel Vetter | 6a860b7 | 2011-03-29 19:23:35 +0200 | [diff] [blame] | 663 | break; |
Daniel Vetter | 1baab2e | 2011-03-30 21:46:04 +0200 | [diff] [blame] | 664 | case 'r': |
| 665 | options.use_render = 0; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 666 | igt_info("disabling render copy\n"); |
Daniel Vetter | e68652c | 2011-04-04 22:10:21 +0200 | [diff] [blame] | 667 | break; |
Chris Wilson | 4e1f2f5 | 2011-05-25 13:41:28 +0100 | [diff] [blame] | 668 | case 'b': |
| 669 | options.use_blt = 0; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 670 | igt_info("disabling blt copy\n"); |
Chris Wilson | 4e1f2f5 | 2011-05-25 13:41:28 +0100 | [diff] [blame] | 671 | break; |
Daniel Vetter | e68652c | 2011-04-04 22:10:21 +0200 | [diff] [blame] | 672 | case 'u': |
Daniel Vetter | a67091b | 2011-04-12 22:26:42 +0200 | [diff] [blame] | 673 | options.forced_tiling = I915_TILING_NONE; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 674 | igt_info("disabling tiling\n"); |
Daniel Vetter | e68652c | 2011-04-04 22:10:21 +0200 | [diff] [blame] | 675 | break; |
Daniel Vetter | a67091b | 2011-04-12 22:26:42 +0200 | [diff] [blame] | 676 | case 'x': |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 677 | if (options.use_cpu_maps) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 678 | igt_info("tiling not possible with cpu maps\n"); |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 679 | } else { |
| 680 | options.forced_tiling = I915_TILING_X; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 681 | igt_info("using only X-tiling\n"); |
Daniel Vetter | b11d67a | 2011-04-27 22:13:29 +0200 | [diff] [blame] | 682 | } |
| 683 | break; |
| 684 | case 'm': |
| 685 | options.use_cpu_maps = 1; |
| 686 | options.forced_tiling = I915_TILING_NONE; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 687 | igt_info("disabling tiling\n"); |
Daniel Vetter | a67091b | 2011-04-12 22:26:42 +0200 | [diff] [blame] | 688 | break; |
Daniel Vetter | 9649dd7 | 2011-06-07 22:30:03 +0200 | [diff] [blame] | 689 | case 'o': |
| 690 | options.total_rounds = atoi(optarg); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 691 | igt_info("total rounds %i\n", options.total_rounds); |
Daniel Vetter | 9649dd7 | 2011-06-07 22:30:03 +0200 | [diff] [blame] | 692 | break; |
Daniel Vetter | 6daa883 | 2011-06-13 00:22:01 +0200 | [diff] [blame] | 693 | case 'f': |
| 694 | options.fail = 0; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 695 | igt_info("not failing when detecting errors\n"); |
Daniel Vetter | 6daa883 | 2011-06-13 00:22:01 +0200 | [diff] [blame] | 696 | break; |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 697 | case 'p': |
| 698 | options.tiles_per_buf = atoi(optarg); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 699 | igt_info("tiles per buffer %i\n", options.tiles_per_buf); |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 700 | break; |
| 701 | case DUCTAPE: |
Daniel Vetter | 74670c7 | 2011-07-17 23:33:27 +0200 | [diff] [blame] | 702 | options.ducttape = 0; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 703 | igt_info("applying duct-tape\n"); |
Daniel Vetter | c0f3433 | 2011-06-13 13:18:35 +0200 | [diff] [blame] | 704 | break; |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 705 | case TILESZ: |
| 706 | options.tile_size = atoi(optarg); |
| 707 | sanitize_tiles_per_buf(); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 708 | igt_info("til size %i\n", options.tile_size); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 709 | break; |
Daniel Vetter | 1007956 | 2011-06-13 20:14:53 +0200 | [diff] [blame] | 710 | case CHCK_RENDER: |
| 711 | options.check_render_cpyfn = 1; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 712 | igt_info("checking render copy function\n"); |
Daniel Vetter | 1007956 | 2011-06-13 20:14:53 +0200 | [diff] [blame] | 713 | break; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Daniel Vetter | 7250328 | 2011-06-06 18:59:54 +0200 | [diff] [blame] | 716 | /* actually 32767, according to docs, but that kills our nice pot calculations. */ |
| 717 | options.max_dimension = 16*1024; |
Chris Wilson | 3d66d91 | 2011-06-05 21:53:49 +0100 | [diff] [blame] | 718 | if (options.use_render) { |
| 719 | if (IS_GEN2(devid) || IS_GEN3(devid)) |
| 720 | options.max_dimension = 2048; |
| 721 | else |
| 722 | options.max_dimension = 8192; |
| 723 | } |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 724 | igt_info("Limiting buffer to %dx%d\n", options.max_dimension, options.max_dimension); |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 725 | |
| 726 | return 0; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | static void init(void) |
| 730 | { |
| 731 | int i; |
Daniel Vetter | bfa6f5d | 2011-03-25 21:54:02 +0100 | [diff] [blame] | 732 | unsigned tmp; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 733 | |
Daniel Vetter | 130daf9 | 2011-03-27 15:37:26 +0200 | [diff] [blame] | 734 | if (options.num_buffers == 0) { |
| 735 | tmp = gem_aperture_size(drm_fd); |
Ville Syrjälä | 8032f52 | 2014-12-03 14:51:16 +0200 | [diff] [blame] | 736 | tmp = min(256 * (1024 * 1024), tmp); |
Daniel Vetter | 130daf9 | 2011-03-27 15:37:26 +0200 | [diff] [blame] | 737 | num_buffers = 2 * tmp / options.scratch_buf_size / 3; |
| 738 | num_buffers /= 2; |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 739 | igt_info("using %u buffers\n", num_buffers); |
Daniel Vetter | 130daf9 | 2011-03-27 15:37:26 +0200 | [diff] [blame] | 740 | } else |
| 741 | num_buffers = options.num_buffers; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 742 | |
| 743 | bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096); |
| 744 | drm_intel_bufmgr_gem_enable_reuse(bufmgr); |
Daniel Vetter | cd640cc | 2011-03-27 21:33:29 +0200 | [diff] [blame] | 745 | drm_intel_bufmgr_gem_enable_fenced_relocs(bufmgr); |
Daniel Vetter | 14e12b8 | 2013-09-12 14:21:56 +0200 | [diff] [blame] | 746 | num_fences = gem_available_fences(drm_fd); |
Matt Roper | 07be8fe | 2015-03-05 15:01:00 -0800 | [diff] [blame] | 747 | igt_assert_lt(4, num_fences); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 748 | batch = intel_batchbuffer_alloc(bufmgr, devid); |
Daniel Vetter | a67091b | 2011-04-12 22:26:42 +0200 | [diff] [blame] | 749 | |
Chris Wilson | 652d9eb | 2011-03-21 07:58:51 +0000 | [diff] [blame] | 750 | busy_bo = drm_intel_bo_alloc(bufmgr, "tiled bo", BUSY_BUF_SIZE, 4096); |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 751 | if (options.forced_tiling >= 0) |
| 752 | gem_set_tiling(drm_fd, busy_bo->handle, options.forced_tiling, 4096); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 753 | |
| 754 | for (i = 0; i < num_buffers; i++) { |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 755 | init_buffer(&buffers[0][i], options.scratch_buf_size); |
| 756 | init_buffer(&buffers[1][i], options.scratch_buf_size); |
| 757 | |
| 758 | num_total_tiles += buffers[0][i].num_tiles; |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 759 | } |
| 760 | current_set = 0; |
| 761 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 762 | /* just in case it helps reproducability */ |
| 763 | srandom(0xdeadbeef); |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 764 | } |
| 765 | |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 766 | static void check_render_copyfunc(void) |
| 767 | { |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 768 | struct igt_buf src, dst; |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 769 | uint32_t *ptr; |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 770 | int i, j, pass; |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 771 | |
Daniel Vetter | 1007956 | 2011-06-13 20:14:53 +0200 | [diff] [blame] | 772 | if (!options.check_render_cpyfn) |
| 773 | return; |
| 774 | |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 775 | init_buffer(&src, options.scratch_buf_size); |
| 776 | init_buffer(&dst, options.scratch_buf_size); |
| 777 | |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 778 | for (pass = 0; pass < 16; pass++) { |
Daniel Vetter | 83a4c7d | 2014-03-22 15:44:48 +0100 | [diff] [blame] | 779 | int sx = random() % (igt_buf_width(&src)-options.tile_size); |
| 780 | int sy = random() % (igt_buf_height(&src)-options.tile_size); |
| 781 | int dx = random() % (igt_buf_width(&dst)-options.tile_size); |
| 782 | int dy = random() % (igt_buf_height(&dst)-options.tile_size); |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 783 | |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 784 | if (options.use_cpu_maps) |
| 785 | set_to_cpu_domain(&src, 1); |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 786 | |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 787 | memset(src.data, 0xff, options.scratch_buf_size); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 788 | for (j = 0; j < options.tile_size; j++) { |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 789 | ptr = (uint32_t*)((char *)src.data + sx*4 + (sy+j) * src.stride); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 790 | for (i = 0; i < options.tile_size; i++) |
| 791 | ptr[i] = j * options.tile_size + i; |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | render_copyfunc(&src, sx, sy, &dst, dx, dy, 0); |
| 795 | |
| 796 | if (options.use_cpu_maps) |
| 797 | set_to_cpu_domain(&dst, 0); |
| 798 | |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 799 | for (j = 0; j < options.tile_size; j++) { |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 800 | ptr = (uint32_t*)((char *)dst.data + dx*4 + (dy+j) * dst.stride); |
Daniel Vetter | 5b253ce | 2011-06-13 20:09:38 +0200 | [diff] [blame] | 801 | for (i = 0; i < options.tile_size; i++) |
| 802 | if (ptr[i] != j * options.tile_size + i) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 803 | igt_info("render copyfunc mismatch at (%d, %d): found %d, expected %d\n", i, j, ptr[i], j * options.tile_size + i); |
Chris Wilson | bfa23b4 | 2011-06-05 21:34:07 +0100 | [diff] [blame] | 804 | } |
| 805 | } |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
| 809 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 810 | int main(int argc, char **argv) |
| 811 | { |
| 812 | int i, j; |
| 813 | unsigned *current_permutation, *tmp_permutation; |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 814 | static struct option long_options[] = { |
| 815 | {"no-hw", 0, 0, 'd'}, |
| 816 | {"buf-size", 1, 0, 's'}, |
| 817 | {"gpu-busy-load", 1, 0, 'g'}, |
| 818 | {"no-signals", 0, 0, 'S'}, |
| 819 | {"buffer-count", 1, 0, 'c'}, |
| 820 | {"trace-tile", 1, 0, 't'}, |
| 821 | {"disable-blt", 0, 0, 'b'}, |
| 822 | {"disable-render", 0, 0, 'r'}, |
| 823 | {"untiled", 0, 0, 'u'}, |
| 824 | {"x-tiled", 0, 0, 'x'}, |
| 825 | {"use-cpu-maps", 0, 0, 'm'}, |
| 826 | {"rounds", 1, 0, 'o'}, |
| 827 | {"no-fail", 0, 0, 'f'}, |
| 828 | {"tiles-per-buf", 0, 0, 'p'}, |
| 829 | {"remove-duct-tape", 0, 0, DUCTAPE}, |
| 830 | {"tile-size", 1, 0, TILESZ}, |
| 831 | {"check-render-cpyfn", 0, 0, CHCK_RENDER}, |
| 832 | {NULL, 0, 0, 0}, |
| 833 | }; |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 834 | |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 835 | options.scratch_buf_size = 256*4096; |
| 836 | options.no_hw = 0; |
| 837 | options.use_signal_helper = 1; |
| 838 | options.gpu_busy_load = 0; |
| 839 | options.num_buffers = 0; |
| 840 | options.trace_tile = -1; |
| 841 | options.use_render = 1; |
| 842 | options.use_blt = 1; |
| 843 | options.forced_tiling = -1; |
| 844 | options.use_cpu_maps = 0; |
| 845 | options.total_rounds = 512; |
| 846 | options.fail = 1; |
| 847 | options.ducttape = 1; |
| 848 | options.tile_size = 16; |
| 849 | options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size); |
| 850 | options.check_render_cpyfn = 0; |
| 851 | |
Thomas Wood | 8fb1978 | 2015-02-18 16:19:59 +0000 | [diff] [blame] | 852 | igt_simple_init_parse_opts(&argc, argv,"ds:g:c:t:rbuxmo:fp:", |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 853 | long_options, NULL, parse_options, NULL); |
Tim Gore | 8abca6f | 2014-06-20 11:28:12 +0100 | [diff] [blame] | 854 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 855 | drm_fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | 3d66d91 | 2011-06-05 21:53:49 +0100 | [diff] [blame] | 856 | devid = intel_get_drm_devid(drm_fd); |
| 857 | |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 858 | /* start our little helper early before too may allocations occur */ |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 859 | if (options.use_signal_helper) |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 860 | igt_fork_signal_helper(); |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 861 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 862 | init(); |
| 863 | |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 864 | check_render_copyfunc(); |
| 865 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 866 | tile_permutation = malloc(num_total_tiles*sizeof(uint32_t)); |
| 867 | current_permutation = malloc(num_total_tiles*sizeof(uint32_t)); |
| 868 | tmp_permutation = malloc(num_total_tiles*sizeof(uint32_t)); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 869 | igt_assert(tile_permutation); |
| 870 | igt_assert(current_permutation); |
| 871 | igt_assert(tmp_permutation); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 872 | |
| 873 | fan_out(); |
| 874 | |
Daniel Vetter | 9649dd7 | 2011-06-07 22:30:03 +0200 | [diff] [blame] | 875 | for (i = 0; i < options.total_rounds; i++) { |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 876 | igt_info("round %i\n", i); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 877 | if (i % 64 == 63) { |
| 878 | fan_in_and_check(); |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 879 | igt_info("everything correct after %i rounds\n", i + 1); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | target_set = (current_set + 1) & 1; |
| 883 | init_set(target_set); |
| 884 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 885 | for (j = 0; j < num_total_tiles; j++) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 886 | current_permutation[j] = j; |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 887 | igt_permute_array(current_permutation, num_total_tiles, exchange_uint); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 888 | |
| 889 | copy_tiles(current_permutation); |
| 890 | |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 891 | memcpy(tmp_permutation, tile_permutation, sizeof(unsigned)*num_total_tiles); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 892 | |
| 893 | /* accumulate the permutations */ |
Daniel Vetter | 22fe098 | 2011-03-27 14:26:43 +0200 | [diff] [blame] | 894 | for (j = 0; j < num_total_tiles; j++) |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 895 | tile_permutation[j] = current_permutation[tmp_permutation[j]]; |
| 896 | |
| 897 | current_set = target_set; |
| 898 | } |
| 899 | |
| 900 | fan_in_and_check(); |
| 901 | |
Daniel Vetter | c9c5545 | 2014-06-13 18:27:59 +0200 | [diff] [blame] | 902 | igt_info("num failed tiles %u, max incoherent bytes %zd\n", stats.num_failed, stats.max_failed_reads * sizeof(uint32_t)); |
Daniel Vetter | 336f85d | 2011-06-13 22:02:52 +0200 | [diff] [blame] | 903 | |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 904 | intel_batchbuffer_free(batch); |
| 905 | drm_intel_bufmgr_destroy(bufmgr); |
| 906 | |
| 907 | close(drm_fd); |
| 908 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 909 | igt_stop_signal_helper(); |
Chris Wilson | 4227da8 | 2011-07-02 08:59:32 +0100 | [diff] [blame] | 910 | |
Daniel Vetter | 4306538 | 2014-10-02 11:18:20 +0200 | [diff] [blame] | 911 | igt_exit(); |
Daniel Vetter | 08cf537 | 2011-03-19 21:34:55 +0100 | [diff] [blame] | 912 | } |