blob: f8af2368d4b6182cda88fe833e558c581c5720a4 [file] [log] [blame]
Chris Wilsonc0dbf042012-12-06 20:36:24 +00001/*
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 gem_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 "rendercopy.h"
37
38#define WIDTH 512
39#define STRIDE (WIDTH*4)
40#define HEIGHT 512
41#define SIZE (HEIGHT*STRIDE)
42
43static render_copyfunc_t render_copy;
44
45static void
46check_bo(drm_intel_bo *bo, uint32_t val)
47{
48 uint32_t *ptr;
49 int i;
50
51 do_or_die(drm_intel_gem_bo_map_gtt(bo));
52 ptr = bo->virtual;
53 for (i = 0; i < WIDTH*HEIGHT; i++) {
54 if (ptr[i] != val) {
55 fprintf(stderr, "Expected 0x%08x, found 0x%08x "
56 "at offset 0x%08x\n",
57 val, ptr[i], i * 4);
58 abort();
59 }
60 val++;
61 }
62 drm_intel_gem_bo_unmap_gtt(bo);
63}
64
65int main(int argc, char **argv)
66{
67 drm_intel_bufmgr *bufmgr;
68 struct intel_batchbuffer *batch;
69 uint32_t *start_val;
70 struct scratch_buf *buf;
71 uint32_t start = 0;
72 int i, j, fd, count;
73
Daniel Vetter1caaf0a2013-08-12 12:17:35 +020074 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +010075
Chris Wilsonc0dbf042012-12-06 20:36:24 +000076 fd = drm_open_any();
77
78 render_copy = get_render_copyfunc(intel_get_drm_devid(fd));
79 if (render_copy == NULL) {
80 printf("no render-copy function, doing nothing\n");
81 return 77;
82 }
83
84 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
Chris Wilsone0ce2312012-12-12 14:33:17 +000085 drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
Chris Wilsonc0dbf042012-12-06 20:36:24 +000086 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
87
88 count = 0;
89 if (argc > 1)
90 count = atoi(argv[1]);
91 if (count == 0)
92 count = 3 * gem_aperture_size(fd) / SIZE / 2;
Damien Lespiau6526d8c2013-02-12 14:24:40 +000093 else if (count < 2) {
94 fprintf(stderr, "count must be >= 2\n");
95 return 1;
96 }
97
Chris Wilsonc0dbf042012-12-06 20:36:24 +000098 printf("Using %d 1MiB buffers\n", count);
99
100 buf = malloc(sizeof(*buf)*count);
101 start_val = malloc(sizeof(*start_val)*count);
102
103 for (i = 0; i < count; i++) {
104 uint32_t tiling = I915_TILING_X + (random() & 1);
105 unsigned long pitch = STRIDE;
106 uint32_t *ptr;
107
108 buf[i].bo = drm_intel_bo_alloc_tiled(bufmgr, "",
109 WIDTH, HEIGHT, 4,
110 &tiling, &pitch, 0);
111 buf[i].stride = pitch;
112 buf[i].tiling = tiling;
113 buf[i].size = SIZE;
114
115 start_val[i] = start;
116
117 do_or_die(drm_intel_gem_bo_map_gtt(buf[i].bo));
118 ptr = buf[i].bo->virtual;
119 for (j = 0; j < WIDTH*HEIGHT; j++)
120 ptr[j] = start++;
121 drm_intel_gem_bo_unmap_gtt(buf[i].bo);
122 }
123
124 printf("Verifying initialisation...\n");
125 for (i = 0; i < count; i++)
126 check_bo(buf[i].bo, start_val[i]);
127
128 printf("Cyclic blits, forward...\n");
129 for (i = 0; i < count * 4; i++) {
130 int src = i % count;
131 int dst = (i + 1) % count;
132
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200133 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000134 start_val[dst] = start_val[src];
135 }
136 for (i = 0; i < count; i++)
137 check_bo(buf[i].bo, start_val[i]);
138
139 printf("Cyclic blits, backward...\n");
140 for (i = 0; i < count * 4; i++) {
141 int src = (i + 1) % count;
142 int dst = i % count;
143
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200144 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000145 start_val[dst] = start_val[src];
146 }
147 for (i = 0; i < count; i++)
148 check_bo(buf[i].bo, start_val[i]);
149
150 printf("Random blits...\n");
151 for (i = 0; i < count * 4; i++) {
152 int src = random() % count;
153 int dst = random() % count;
154
155 if (src == dst)
156 continue;
157
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200158 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000159 start_val[dst] = start_val[src];
160 }
161 for (i = 0; i < count; i++)
162 check_bo(buf[i].bo, start_val[i]);
163
164 return 0;
165}