kms_rotation_crc: Allow the sprite test to run even without universal planes
[platform/upstream/intel-gpu-tools.git] / tests / gem_render_linear_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 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 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 #include <stdlib.h>
41 #include <sys/ioctl.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <fcntl.h>
45 #include <inttypes.h>
46 #include <errno.h>
47 #include <sys/stat.h>
48 #include <sys/time.h>
49 #include <getopt.h>
50
51 #include <drm.h>
52
53 #include "ioctl_wrappers.h"
54 #include "drmtest.h"
55 #include "intel_bufmgr.h"
56 #include "intel_batchbuffer.h"
57 #include "intel_io.h"
58 #include "intel_chipset.h"
59 #include "igt_aux.h"
60
61 #define WIDTH 512
62 #define STRIDE (WIDTH*4)
63 #define HEIGHT 512
64 #define SIZE (HEIGHT*STRIDE)
65
66 static uint32_t linear[WIDTH*HEIGHT];
67 static igt_render_copyfunc_t render_copy;
68
69 static void
70 check_bo(int fd, uint32_t handle, uint32_t val)
71 {
72         int i;
73
74         gem_read(fd, handle, 0, linear, sizeof(linear));
75         for (i = 0; i < WIDTH*HEIGHT; i++) {
76                 igt_assert_f(linear[i] == val,
77                              "Expected 0x%08x, found 0x%08x "
78                              "at offset 0x%08x\n",
79                              val, linear[i], i * 4);
80                 val++;
81         }
82 }
83
84 int main(int argc, char **argv)
85 {
86         drm_intel_bufmgr *bufmgr;
87         struct intel_batchbuffer *batch;
88         uint32_t *start_val;
89         drm_intel_bo **bo;
90         uint32_t start = 0;
91         int i, j, fd, count;
92
93         igt_simple_init();
94
95         fd = drm_open_any();
96
97         render_copy = igt_get_render_copyfunc(intel_get_drm_devid(fd));
98         igt_require(render_copy);
99
100         bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
101         batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
102
103         count = 0;
104         if (igt_run_in_simulation())
105                 count = 2;
106         if (argc > 1)
107                 count = atoi(argv[1]);
108
109         if (count == 0)
110                 count = 3 * gem_aperture_size(fd) / SIZE / 2;
111         else if (count < 2) {
112                 igt_warn("count must be >= 2\n");
113                 return 1;
114         }
115
116         if (count > intel_get_total_ram_mb() * 9 / 10) {
117                 count = intel_get_total_ram_mb() * 9 / 10;
118                 igt_info("not enough RAM to run test, reducing buffer count\n");
119         }
120
121         bo = malloc(sizeof(*bo)*count);
122         start_val = malloc(sizeof(*start_val)*count);
123
124         for (i = 0; i < count; i++) {
125                 bo[i] = drm_intel_bo_alloc(bufmgr, "", SIZE, 4096);
126                 start_val[i] = start;
127                 for (j = 0; j < WIDTH*HEIGHT; j++)
128                         linear[j] = start++;
129                 gem_write(fd, bo[i]->handle, 0, linear, sizeof(linear));
130         }
131
132         igt_info("Verifying initialisation...\n");
133         for (i = 0; i < count; i++)
134                 check_bo(fd, bo[i]->handle, start_val[i]);
135
136         igt_info("Cyclic blits, forward...\n");
137         for (i = 0; i < count * 4; i++) {
138                 struct igt_buf src, dst;
139
140                 src.bo = bo[i % count];
141                 src.stride = STRIDE;
142                 src.tiling = I915_TILING_NONE;
143                 src.size = SIZE;
144
145                 dst.bo = bo[(i + 1) % count];
146                 dst.stride = STRIDE;
147                 dst.tiling = I915_TILING_NONE;
148                 dst.size = SIZE;
149
150                 render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
151                 start_val[(i + 1) % count] = start_val[i % count];
152         }
153         for (i = 0; i < count; i++)
154                 check_bo(fd, bo[i]->handle, start_val[i]);
155
156         if (igt_run_in_simulation())
157                 return 0;
158
159         igt_info("Cyclic blits, backward...\n");
160         for (i = 0; i < count * 4; i++) {
161                 struct igt_buf src, dst;
162
163                 src.bo = bo[(i + 1) % count];
164                 src.stride = STRIDE;
165                 src.tiling = I915_TILING_NONE;
166                 src.size = SIZE;
167
168                 dst.bo = bo[i % count];
169                 dst.stride = STRIDE;
170                 dst.tiling = I915_TILING_NONE;
171                 dst.size = SIZE;
172
173                 render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
174                 start_val[i % count] = start_val[(i + 1) % count];
175         }
176         for (i = 0; i < count; i++)
177                 check_bo(fd, bo[i]->handle, start_val[i]);
178
179         igt_info("Random blits...\n");
180         for (i = 0; i < count * 4; i++) {
181                 struct igt_buf src, dst;
182                 int s = random() % count;
183                 int d = random() % count;
184
185                 if (s == d)
186                         continue;
187
188                 src.bo = bo[s];
189                 src.stride = STRIDE;
190                 src.tiling = I915_TILING_NONE;
191                 src.size = SIZE;
192
193                 dst.bo = bo[d];
194                 dst.stride = STRIDE;
195                 dst.tiling = I915_TILING_NONE;
196                 dst.size = SIZE;
197
198                 render_copy(batch, NULL, &src, 0, 0, WIDTH, HEIGHT, &dst, 0, 0);
199                 start_val[d] = start_val[s];
200         }
201         for (i = 0; i < count; i++)
202                 check_bo(fd, bo[i]->handle, start_val[i]);
203
204         return 0;
205 }