2 * Copyright © 2011 Intel Corporation
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:
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
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
24 * Chris Wilson <chris@chris-wilson.co.uk>
28 /** @file gem_linear_render_blits.c
30 * This is a test of doing many blits, with a working set
31 * larger than the aperture size.
33 * The goal is to simply ensure the basics work.
37 #include <sys/ioctl.h>
48 #include "ioctl_wrappers.h"
50 #include "intel_bufmgr.h"
51 #include "intel_batchbuffer.h"
53 #include "intel_chipset.h"
57 #define STRIDE (WIDTH*4)
59 #define SIZE (HEIGHT*STRIDE)
61 static igt_render_copyfunc_t render_copy;
62 static drm_intel_bo *linear;
63 static uint32_t data[WIDTH*HEIGHT];
67 check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
75 tmp.tiling = I915_TILING_NONE;
78 render_copy(batch, NULL, buf, 0, 0, WIDTH, HEIGHT, &tmp, 0, 0);
80 do_or_die(dri_bo_map(linear, 0));
81 ptr = linear->virtual;
83 do_or_die(drm_intel_bo_get_subdata(linear, 0, sizeof(data), data));
86 for (i = 0; i < WIDTH*HEIGHT; i++) {
87 igt_assert_f(ptr[i] == val,
88 "Expected 0x%08x, found 0x%08x "
97 int main(int argc, char **argv)
99 drm_intel_bufmgr *bufmgr;
100 struct intel_batchbuffer *batch;
107 igt_simple_init(argc, argv);
109 igt_skip_on_simulation();
112 devid = intel_get_drm_devid(fd);
114 render_copy = igt_get_render_copyfunc(devid);
115 igt_require(render_copy);
118 if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */
120 if (IS_BROADWATER(devid) || IS_CRESTLINE(devid)) /* snafu */
123 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
124 drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
125 batch = intel_batchbuffer_alloc(bufmgr, devid);
129 count = atoi(argv[1]);
131 count = 3 * gem_aperture_size(fd) / SIZE / 2;
132 else if (count < 2) {
133 igt_warn("count must be >= 2\n");
137 if (count > intel_get_total_ram_mb() * 9 / 10) {
138 count = intel_get_total_ram_mb() * 9 / 10;
139 igt_info("not enough RAM to run test, reducing buffer count\n");
142 igt_info("Using %d 1MiB buffers\n", count);
144 linear = drm_intel_bo_alloc(bufmgr, "linear", WIDTH*HEIGHT*4, 0);
146 gem_set_caching(fd, linear->handle, 1);
147 igt_info("Using a snoop linear buffer for comparisons\n");
150 buf = malloc(sizeof(*buf)*count);
151 start_val = malloc(sizeof(*start_val)*count);
153 for (i = 0; i < count; i++) {
154 uint32_t tiling = I915_TILING_X + (random() & 1);
155 unsigned long pitch = STRIDE;
158 buf[i].bo = drm_intel_bo_alloc_tiled(bufmgr, "",
161 buf[i].stride = pitch;
162 buf[i].tiling = tiling;
165 start_val[i] = start;
167 do_or_die(drm_intel_gem_bo_map_gtt(buf[i].bo));
168 ptr = buf[i].bo->virtual;
169 for (j = 0; j < WIDTH*HEIGHT; j++)
171 drm_intel_gem_bo_unmap_gtt(buf[i].bo);
174 igt_info("Verifying initialisation...\n");
175 for (i = 0; i < count; i++)
176 check_bo(batch, &buf[i], start_val[i]);
178 igt_info("Cyclic blits, forward...\n");
179 for (i = 0; i < count * 4; i++) {
181 int dst = (i + 1) % count;
183 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
184 start_val[dst] = start_val[src];
186 for (i = 0; i < count; i++)
187 check_bo(batch, &buf[i], start_val[i]);
189 igt_info("Cyclic blits, backward...\n");
190 for (i = 0; i < count * 4; i++) {
191 int src = (i + 1) % count;
194 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
195 start_val[dst] = start_val[src];
197 for (i = 0; i < count; i++)
198 check_bo(batch, &buf[i], start_val[i]);
200 igt_info("Random blits...\n");
201 for (i = 0; i < count * 4; i++) {
202 int src = random() % count;
203 int dst = random() % count;
208 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
209 start_val[dst] = start_val[src];
211 for (i = 0; i < count; i++)
212 check_bo(batch, &buf[i], start_val[i]);