test/gen3_mixed_blits: Acutally use fences for BLT
[platform/upstream/intel-gpu-tools.git] / tests / gen3_mixed_blits.c
1 /*
2  * Copyright © 2011 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  *    Chris Wilson <chris@chris-wilson.co.uk>
25  *
26  */
27
28 /** @file gen3_linear_render_blits.c
29  *
30  * This is a test of doing many blits, with a working set
31  * larger than the aperture size.
32  *
33  * The goal is to simply ensure the basics work.
34  */
35
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <assert.h>
40 #include <fcntl.h>
41 #include <inttypes.h>
42 #include <errno.h>
43 #include <sys/stat.h>
44 #include <sys/time.h>
45 #include <sys/mman.h>
46 #include <sys/ioctl.h>
47 #include "drm.h"
48 #include "i915_drm.h"
49 #include "drmtest.h"
50 #include "intel_gpu_tools.h"
51
52 #include "i915_reg.h"
53 #include "i915_3d.h"
54
55 #define WIDTH (512)
56 #define HEIGHT (512)
57
58 static inline uint32_t pack_float(float f)
59 {
60         union {
61                 uint32_t dw;
62                 float f;
63         } u;
64         u.f = f;
65         return u.dw;
66 }
67
68 static uint32_t gem_create(int fd, int size)
69 {
70         struct drm_i915_gem_create create;
71
72         create.handle = 0;
73         create.size = size;
74         (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
75         assert(create.handle);
76
77         return create.handle;
78 }
79
80 static void gem_close(int fd, uint32_t handle)
81 {
82         struct drm_gem_close close;
83         int ret;
84
85         close.handle = handle;
86         ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
87         assert(ret == 0);
88 }
89
90 static uint64_t
91 gem_aperture_size(int fd)
92 {
93         struct drm_i915_gem_get_aperture aperture;
94
95         aperture.aper_size = 512*1024*1024;
96         (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
97         return aperture.aper_size;
98 }
99
100 static void
101 gem_write(int fd, uint32_t handle, int offset, int size, const void *buf)
102 {
103         struct drm_i915_gem_pwrite pwrite;
104         int ret;
105
106         pwrite.handle = handle;
107         pwrite.offset = offset;
108         pwrite.size = size;
109         pwrite.data_ptr = (uintptr_t)buf;
110         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite);
111         assert(ret == 0);
112 }
113
114 static uint32_t fill_reloc(struct drm_i915_gem_relocation_entry *reloc,
115                            uint32_t offset,
116                            uint32_t handle,
117                            uint32_t read_domain,
118                            uint32_t write_domain)
119 {
120         reloc->target_handle = handle;
121         reloc->delta = 0;
122         reloc->offset = offset * sizeof(uint32_t);
123         reloc->presumed_offset = 0;
124         reloc->read_domains = read_domain;
125         reloc->write_domain = write_domain;
126
127         return reloc->presumed_offset + reloc->delta;
128 }
129
130 static void
131 render_copy(int fd,
132      uint32_t dst, int dst_tiling,
133      uint32_t src, int src_tiling)
134 {
135         uint32_t batch[1024], *b = batch;
136         struct drm_i915_gem_relocation_entry reloc[2], *r = reloc;
137         struct drm_i915_gem_exec_object2 obj[3];
138         struct drm_i915_gem_execbuffer2 exec;
139         uint32_t handle;
140         uint32_t tiling_bits;
141         int ret;
142
143         /* invariant state */
144         *b++ = (_3DSTATE_AA_CMD |
145                 AA_LINE_ECAAR_WIDTH_ENABLE |
146                 AA_LINE_ECAAR_WIDTH_1_0 |
147                 AA_LINE_REGION_WIDTH_ENABLE | AA_LINE_REGION_WIDTH_1_0);
148         *b++ = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD |
149                 IAB_MODIFY_ENABLE |
150                 IAB_MODIFY_FUNC | (BLENDFUNC_ADD << IAB_FUNC_SHIFT) |
151                 IAB_MODIFY_SRC_FACTOR |
152                 (BLENDFACT_ONE << IAB_SRC_FACTOR_SHIFT) |
153                 IAB_MODIFY_DST_FACTOR |
154                 (BLENDFACT_ZERO << IAB_DST_FACTOR_SHIFT));
155         *b++ = (_3DSTATE_DFLT_DIFFUSE_CMD);
156         *b++ = (0);
157         *b++ = (_3DSTATE_DFLT_SPEC_CMD);
158         *b++ = (0);
159         *b++ = (_3DSTATE_DFLT_Z_CMD);
160         *b++ = (0);
161         *b++ = (_3DSTATE_COORD_SET_BINDINGS |
162                 CSB_TCB(0, 0) |
163                 CSB_TCB(1, 1) |
164                 CSB_TCB(2, 2) |
165                 CSB_TCB(3, 3) |
166                 CSB_TCB(4, 4) |
167                 CSB_TCB(5, 5) |
168                 CSB_TCB(6, 6) |
169                 CSB_TCB(7, 7));
170         *b++ = (_3DSTATE_RASTER_RULES_CMD |
171                 ENABLE_POINT_RASTER_RULE |
172                 OGL_POINT_RASTER_RULE |
173                 ENABLE_LINE_STRIP_PROVOKE_VRTX |
174                 ENABLE_TRI_FAN_PROVOKE_VRTX |
175                 LINE_STRIP_PROVOKE_VRTX(1) |
176                 TRI_FAN_PROVOKE_VRTX(2) |
177                 ENABLE_TEXKILL_3D_4D |
178                 TEXKILL_4D);
179         *b++ = (_3DSTATE_MODES_4_CMD |
180                 ENABLE_LOGIC_OP_FUNC | LOGIC_OP_FUNC(LOGICOP_COPY) |
181                 ENABLE_STENCIL_WRITE_MASK | STENCIL_WRITE_MASK(0xff) |
182                 ENABLE_STENCIL_TEST_MASK | STENCIL_TEST_MASK(0xff));
183         *b++ = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | I1_LOAD_S(4) | I1_LOAD_S(5) | 2);
184         *b++ = (0x00000000);    /* Disable texture coordinate wrap-shortest */
185         *b++ = ((1 << S4_POINT_WIDTH_SHIFT) |
186                 S4_LINE_WIDTH_ONE |
187                 S4_CULLMODE_NONE |
188                 S4_VFMT_XY);
189         *b++ = (0x00000000);    /* Stencil. */
190         *b++ = (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
191         *b++ = (_3DSTATE_SCISSOR_RECT_0_CMD);
192         *b++ = (0);
193         *b++ = (0);
194         *b++ = (_3DSTATE_DEPTH_SUBRECT_DISABLE);
195         *b++ = (_3DSTATE_LOAD_INDIRECT | 0);    /* disable indirect state */
196         *b++ = (0);
197         *b++ = (_3DSTATE_STIPPLE);
198         *b++ = (0x00000000);
199         *b++ = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_TWO_SIDE | 0);
200
201         /* samler state */
202         tiling_bits = 0;
203         if (src_tiling != I915_TILING_NONE)
204                 tiling_bits = MS3_TILED_SURFACE;
205         if (src_tiling == I915_TILING_Y)
206                 tiling_bits |= MS3_TILE_WALK;
207
208 #define TEX_COUNT 1
209         *b++ = (_3DSTATE_MAP_STATE | (3 * TEX_COUNT));
210         *b++ = ((1 << TEX_COUNT) - 1);
211         *b = fill_reloc(r++, b-batch, src, I915_GEM_DOMAIN_SAMPLER, 0); b++;
212         *b++ = (MAPSURF_32BIT | MT_32BIT_ARGB8888 | tiling_bits |
213                 (HEIGHT - 1) << MS3_HEIGHT_SHIFT |
214                 (WIDTH - 1) << MS3_WIDTH_SHIFT);
215         *b++ = ((WIDTH-1) << MS4_PITCH_SHIFT);
216
217         *b++ = (_3DSTATE_SAMPLER_STATE | (3 * TEX_COUNT));
218         *b++ = ((1 << TEX_COUNT) - 1);
219         *b++ = (MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT |
220                 FILTER_NEAREST << SS2_MAG_FILTER_SHIFT |
221                 FILTER_NEAREST << SS2_MIN_FILTER_SHIFT);
222         *b++ = (TEXCOORDMODE_WRAP << SS3_TCX_ADDR_MODE_SHIFT |
223                 TEXCOORDMODE_WRAP << SS3_TCY_ADDR_MODE_SHIFT |
224                 0 << SS3_TEXTUREMAP_INDEX_SHIFT);
225         *b++ = (0x00000000);
226
227         /* render target state */
228         tiling_bits = 0;
229         if (dst_tiling != I915_TILING_NONE)
230                 tiling_bits = BUF_3D_TILED_SURFACE;
231         if (dst_tiling == I915_TILING_Y)
232                 tiling_bits |= BUF_3D_TILE_WALK_Y;
233         *b++ = (_3DSTATE_BUF_INFO_CMD);
234         *b++ = (BUF_3D_ID_COLOR_BACK | tiling_bits | WIDTH*4);
235         *b = fill_reloc(r++, b-batch, dst,
236                         I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
237         b++;
238
239         *b++ = (_3DSTATE_DST_BUF_VARS_CMD);
240         *b++ = (COLR_BUF_ARGB8888 |
241                 DSTORG_HORT_BIAS(0x8) |
242                 DSTORG_VERT_BIAS(0x8));
243
244         /* draw rect is unconditional */
245         *b++ = (_3DSTATE_DRAW_RECT_CMD);
246         *b++ = (0x00000000);
247         *b++ = (0x00000000);    /* ymin, xmin */
248         *b++ = (DRAW_YMAX(HEIGHT - 1) |
249                 DRAW_XMAX(WIDTH - 1));
250         /* yorig, xorig (relate to color buffer?) */
251         *b++ = (0x00000000);
252
253         /* texfmt */
254         *b++ = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(1) | I1_LOAD_S(2) | I1_LOAD_S(6) | 2);
255         *b++ = ((4 << S1_VERTEX_WIDTH_SHIFT) | (4 << S1_VERTEX_PITCH_SHIFT));
256         *b++ = (~S2_TEXCOORD_FMT(0, TEXCOORDFMT_NOT_PRESENT) |
257                 S2_TEXCOORD_FMT(0, TEXCOORDFMT_2D));
258         *b++ = (S6_CBUF_BLEND_ENABLE | S6_COLOR_WRITE_ENABLE |
259                 BLENDFUNC_ADD << S6_CBUF_BLEND_FUNC_SHIFT |
260                 BLENDFACT_ONE << S6_CBUF_SRC_BLEND_FACT_SHIFT |
261                 BLENDFACT_ZERO << S6_CBUF_DST_BLEND_FACT_SHIFT);
262
263         /* pixel shader */
264         *b++ = (_3DSTATE_PIXEL_SHADER_PROGRAM | (1 + 3*3 - 2));
265         /* decl FS_T0 */
266         *b++ = (D0_DCL |
267                 REG_TYPE(FS_T0) << D0_TYPE_SHIFT |
268                 REG_NR(FS_T0) << D0_NR_SHIFT |
269                 ((REG_TYPE(FS_T0) != REG_TYPE_S) ? D0_CHANNEL_ALL : 0));
270         *b++ = (0);
271         *b++ = (0);
272         /* decl FS_S0 */
273         *b++ = (D0_DCL |
274                 (REG_TYPE(FS_S0) << D0_TYPE_SHIFT) |
275                 (REG_NR(FS_S0) << D0_NR_SHIFT) |
276                 ((REG_TYPE(FS_S0) != REG_TYPE_S) ? D0_CHANNEL_ALL : 0));
277         *b++ = (0);
278         *b++ = (0);
279         /* texld(FS_OC, FS_S0, FS_T0 */
280         *b++ = (T0_TEXLD |
281                 (REG_TYPE(FS_OC) << T0_DEST_TYPE_SHIFT) |
282                 (REG_NR(FS_OC) << T0_DEST_NR_SHIFT) |
283                 (REG_NR(FS_S0) << T0_SAMPLER_NR_SHIFT));
284         *b++ = ((REG_TYPE(FS_T0) << T1_ADDRESS_REG_TYPE_SHIFT) |
285                 (REG_NR(FS_T0) << T1_ADDRESS_REG_NR_SHIFT));
286         *b++ = (0);
287
288         *b++ = (PRIM3D_RECTLIST | (3*4 - 1));
289         *b++ = pack_float(WIDTH);
290         *b++ = pack_float(HEIGHT);
291         *b++ = pack_float(WIDTH);
292         *b++ = pack_float(HEIGHT);
293
294         *b++ = pack_float(0);
295         *b++ = pack_float(HEIGHT);
296         *b++ = pack_float(0);
297         *b++ = pack_float(HEIGHT);
298
299         *b++ = pack_float(0);
300         *b++ = pack_float(0);
301         *b++ = pack_float(0);
302         *b++ = pack_float(0);
303
304         *b++ = MI_BATCH_BUFFER_END;
305         if ((b - batch) & 1)
306                 *b++ = 0;
307
308         assert(b - batch <= 1024);
309         handle = gem_create(fd, 4096);
310         gem_write(fd, handle, 0, (b-batch)*sizeof(batch[0]), batch);
311
312         assert(r-reloc == 2);
313
314         obj[0].handle = dst;
315         obj[0].relocation_count = 0;
316         obj[0].relocs_ptr = 0;
317         obj[0].alignment = 0;
318         obj[0].offset = 0;
319         obj[0].flags = 0;
320         obj[0].rsvd1 = 0;
321         obj[0].rsvd2 = 0;
322
323         obj[1].handle = src;
324         obj[1].relocation_count = 0;
325         obj[1].relocs_ptr = 0;
326         obj[1].alignment = 0;
327         obj[1].offset = 0;
328         obj[1].flags = 0;
329         obj[1].rsvd1 = 0;
330         obj[1].rsvd2 = 0;
331
332         obj[2].handle = handle;
333         obj[2].relocation_count = 2;
334         obj[2].relocs_ptr = (uintptr_t)reloc;
335         obj[2].alignment = 0;
336         obj[2].offset = 0;
337         obj[2].flags = 0;
338         obj[2].rsvd1 = obj[2].rsvd2 = 0;
339
340         exec.buffers_ptr = (uintptr_t)obj;
341         exec.buffer_count = 3;
342         exec.batch_start_offset = 0;
343         exec.batch_len = (b-batch)*sizeof(batch[0]);
344         exec.DR1 = exec.DR4 = 0;
345         exec.num_cliprects = 0;
346         exec.cliprects_ptr = 0;
347         exec.flags = 0;
348         exec.rsvd1 = exec.rsvd2 = 0;
349
350         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
351         while (ret && errno == EBUSY) {
352                 drmCommandNone(fd, DRM_I915_GEM_THROTTLE);
353                 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
354         }
355         assert(ret == 0);
356
357         gem_close(fd, handle);
358 }
359
360 static void blt_copy(int fd, uint32_t dst, uint32_t src)
361 {
362         uint32_t batch[1024], *b = batch;
363         struct drm_i915_gem_relocation_entry reloc[2], *r = reloc;
364         struct drm_i915_gem_exec_object2 obj[3];
365         struct drm_i915_gem_execbuffer2 exec;
366         uint32_t handle;
367         int ret;
368
369         *b++ = (XY_SRC_COPY_BLT_CMD |
370                 XY_SRC_COPY_BLT_WRITE_ALPHA |
371                 XY_SRC_COPY_BLT_WRITE_RGB);
372         *b++ = 3 << 24 | 0xcc << 16 | WIDTH * 4;
373         *b++ = 0;
374         *b++ = HEIGHT << 16 | WIDTH;
375         *b = fill_reloc(r++, b-batch, dst,
376                         I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER); b++;
377         *b++ = 0;
378         *b++ = WIDTH*4;
379         *b = fill_reloc(r++, b-batch, src, I915_GEM_DOMAIN_RENDER, 0); b++;
380
381         *b++ = MI_BATCH_BUFFER_END;
382         if ((b - batch) & 1)
383                 *b++ = 0;
384
385         assert(b - batch <= 1024);
386         handle = gem_create(fd, 4096);
387         gem_write(fd, handle, 0, (b-batch)*sizeof(batch[0]), batch);
388
389         assert(r-reloc == 2);
390
391         obj[0].handle = dst;
392         obj[0].relocation_count = 0;
393         obj[0].relocs_ptr = 0;
394         obj[0].alignment = 0;
395         obj[0].offset = 0;
396         obj[0].flags = EXEC_OBJECT_NEEDS_FENCE;
397         obj[0].rsvd1 = 0;
398         obj[0].rsvd2 = 0;
399
400         obj[1].handle = src;
401         obj[1].relocation_count = 0;
402         obj[1].relocs_ptr = 0;
403         obj[1].alignment = 0;
404         obj[1].offset = 0;
405         obj[1].flags = EXEC_OBJECT_NEEDS_FENCE;
406         obj[1].rsvd1 = 0;
407         obj[1].rsvd2 = 0;
408
409         obj[2].handle = handle;
410         obj[2].relocation_count = 2;
411         obj[2].relocs_ptr = (uintptr_t)reloc;
412         obj[2].alignment = 0;
413         obj[2].offset = 0;
414         obj[2].flags = 0;
415         obj[2].rsvd1 = obj[2].rsvd2 = 0;
416
417         exec.buffers_ptr = (uintptr_t)obj;
418         exec.buffer_count = 3;
419         exec.batch_start_offset = 0;
420         exec.batch_len = (b-batch)*sizeof(batch[0]);
421         exec.DR1 = exec.DR4 = 0;
422         exec.num_cliprects = 0;
423         exec.cliprects_ptr = 0;
424         exec.flags = 0;
425         exec.rsvd1 = exec.rsvd2 = 0;
426
427         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
428         while (ret && errno == EBUSY) {
429                 drmCommandNone(fd, DRM_I915_GEM_THROTTLE);
430                 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
431         }
432         assert(ret == 0);
433
434         gem_close(fd, handle);
435 }
436
437 static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
438 {
439         struct drm_i915_gem_mmap_gtt mmap_arg;
440         void *ptr;
441
442         mmap_arg.handle = handle;
443         if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
444                 assert(0);
445                 return NULL;
446         }
447
448         ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
449         if (ptr == MAP_FAILED) {
450                 assert(0);
451                 ptr = NULL;
452         }
453
454         return ptr;
455 }
456
457 static void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
458 {
459         struct drm_i915_gem_set_tiling set_tiling;
460         int ret;
461
462         do {
463                 set_tiling.handle = handle;
464                 set_tiling.tiling_mode = tiling;
465                 set_tiling.stride = stride;
466
467                 ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
468         } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
469         assert(ret == 0);
470         assert(set_tiling.tiling_mode == tiling);
471 }
472
473 static uint32_t
474 create_bo(int fd, uint32_t val, int tiling)
475 {
476         uint32_t handle;
477         uint32_t *v;
478         int i;
479
480         handle = gem_create(fd, WIDTH*HEIGHT*4);
481         gem_set_tiling(fd, handle, tiling, WIDTH*4);
482
483         /* Fill the BO with dwords starting at val */
484         v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
485         for (i = 0; i < WIDTH*HEIGHT; i++)
486                 v[i] = val++;
487         munmap(v, WIDTH*HEIGHT*4);
488
489         return handle;
490 }
491
492 static void
493 check_bo(int fd, uint32_t handle, uint32_t val)
494 {
495         uint32_t *v;
496         int i;
497
498         v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
499         for (i = 0; i < WIDTH*HEIGHT; i++) {
500                 if (v[i] != val) {
501                         fprintf(stderr, "Expected 0x%08x, found 0x%08x "
502                                 "at offset 0x%08x\n",
503                                 val, v[i], i * 4);
504                         abort();
505                 }
506                 val++;
507         }
508         munmap(v, WIDTH*HEIGHT*4);
509 }
510
511 int main(int argc, char **argv)
512 {
513         uint32_t *handle, *tiling, *start_val;
514         uint32_t start = 0;
515         int i, fd, count;
516
517         fd = drm_open_any();
518
519         count = 0;
520         if (argc > 1)
521                 count = atoi(argv[1]);
522         if (count == 0)
523                 count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
524         printf("Using %d 1MiB buffers\n", count);
525
526         handle = malloc(sizeof(uint32_t)*count*3);
527         tiling = handle + count;
528         start_val = tiling + count;
529
530         for (i = 0; i < count; i++) {
531                 handle[i] = create_bo(fd, start, tiling[i] = i % 3);
532                 start_val[i] = start;
533                 start += 1024 * 1024 / 4;
534         }
535
536         printf("Verifying initialisation..."); fflush(stdout);
537         for (i = 0; i < count; i++)
538                 check_bo(fd, handle[i], start_val[i]);
539         printf("done\n");
540
541         printf("Cyclic blits, forward..."); fflush(stdout);
542         for (i = 0; i < count * 32; i++) {
543                 int src = i % count;
544                 int dst = (i + 1) % count;
545
546                 if (random() & 1)
547                         render_copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
548                 else
549                         blt_copy(fd, handle[dst], handle[src]);
550                 start_val[dst] = start_val[src];
551         }
552         printf("verifying..."); fflush(stdout);
553         for (i = 0; i < count; i++)
554                 check_bo(fd, handle[i], start_val[i]);
555         printf("done\n");
556
557         printf("Cyclic blits, backward..."); fflush(stdout);
558         for (i = 0; i < count * 32; i++) {
559                 int src = (i + 1) % count;
560                 int dst = i % count;
561
562                 if (random() & 1)
563                         render_copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
564                 else
565                         blt_copy(fd, handle[dst], handle[src]);
566                 start_val[dst] = start_val[src];
567         }
568         printf("verifying..."); fflush(stdout);
569         for (i = 0; i < count; i++)
570                 check_bo(fd, handle[i], start_val[i]);
571         printf("done\n");
572
573         printf("Random blits..."); fflush(stdout);
574         for (i = 0; i < count * 32; i++) {
575                 int src = random() % count;
576                 int dst = random() % count;
577
578                 while (src == dst)
579                         dst = random() % count;
580
581                 if (random() & 1)
582                         render_copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
583                 else
584                         blt_copy(fd, handle[dst], handle[src]);
585                 start_val[dst] = start_val[src];
586         }
587         printf("verifying..."); fflush(stdout);
588         for (i = 0; i < count; i++)
589                 check_bo(fd, handle[i], start_val[i]);
590         printf("done\n");
591
592         return 0;
593 }