blob: 9f0e588434aef7968e60e9f808217ee516d8264e [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
Thomas Wood804e11f2015-08-17 17:57:43 +010036#include "igt.h"
Daniel Vetter7dc00012014-03-22 15:31:15 +010037#include <stdlib.h>
38#include <sys/ioctl.h>
39#include <stdio.h>
40#include <string.h>
Daniel Vetter7dc00012014-03-22 15:31:15 +010041#include <fcntl.h>
42#include <inttypes.h>
43#include <errno.h>
44#include <sys/stat.h>
45#include <sys/time.h>
Daniel Vetterf5daeec2014-03-23 13:35:09 +010046
47#include <drm.h>
48
Daniel Vetter7dc00012014-03-22 15:31:15 +010049#include "intel_bufmgr.h"
Chris Wilsonc0dbf042012-12-06 20:36:24 +000050
51#define WIDTH 512
52#define STRIDE (WIDTH*4)
53#define HEIGHT 512
54#define SIZE (HEIGHT*STRIDE)
55
Daniel Vetter53a4d9e2014-03-22 15:49:02 +010056static igt_render_copyfunc_t render_copy;
Chris Wilson66d5f092014-05-08 11:56:56 +010057static drm_intel_bo *linear;
58static uint32_t data[WIDTH*HEIGHT];
59static int snoop;
Chris Wilsonc0dbf042012-12-06 20:36:24 +000060
61static void
Chris Wilson66d5f092014-05-08 11:56:56 +010062check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
Chris Wilsonc0dbf042012-12-06 20:36:24 +000063{
Chris Wilson66d5f092014-05-08 11:56:56 +010064 struct igt_buf tmp;
Chris Wilsonc0dbf042012-12-06 20:36:24 +000065 uint32_t *ptr;
66 int i;
67
Chris Wilson66d5f092014-05-08 11:56:56 +010068 tmp.bo = linear;
69 tmp.stride = STRIDE;
70 tmp.tiling = I915_TILING_NONE;
71 tmp.size = SIZE;
72
73 render_copy(batch, NULL, buf, 0, 0, WIDTH, HEIGHT, &tmp, 0, 0);
74 if (snoop) {
Robert Fosse4e18dd2016-05-20 18:59:30 -040075 do_or_die(drm_intel_bo_map(linear, 0));
Chris Wilson66d5f092014-05-08 11:56:56 +010076 ptr = linear->virtual;
77 } else {
78 do_or_die(drm_intel_bo_get_subdata(linear, 0, sizeof(data), data));
79 ptr = data;
80 }
Chris Wilsonc0dbf042012-12-06 20:36:24 +000081 for (i = 0; i < WIDTH*HEIGHT; i++) {
Daniel Vetter0b7ce4a2014-05-14 09:56:53 +020082 igt_assert_f(ptr[i] == val,
Tim Goreee5c1192015-03-03 10:43:43 +000083 "Expected 0x%08x, found 0x%08x "
84 "at offset 0x%08x\n",
85 val, ptr[i], i * 4);
Chris Wilsonc0dbf042012-12-06 20:36:24 +000086 val++;
87 }
Chris Wilson66d5f092014-05-08 11:56:56 +010088 if (ptr != data)
Robert Fosse4e18dd2016-05-20 18:59:30 -040089 drm_intel_bo_unmap(linear);
Chris Wilsonc0dbf042012-12-06 20:36:24 +000090}
91
Tim Goreee5c1192015-03-03 10:43:43 +000092static void run_test (int fd, int count)
Chris Wilsonc0dbf042012-12-06 20:36:24 +000093{
94 drm_intel_bufmgr *bufmgr;
95 struct intel_batchbuffer *batch;
96 uint32_t *start_val;
Daniel Vetter83a4c7d2014-03-22 15:44:48 +010097 struct igt_buf *buf;
Chris Wilsonc0dbf042012-12-06 20:36:24 +000098 uint32_t start = 0;
Tim Goreee5c1192015-03-03 10:43:43 +000099 int i, j;
Chris Wilson66d5f092014-05-08 11:56:56 +0100100 uint32_t devid;
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000101
Chris Wilson66d5f092014-05-08 11:56:56 +0100102 devid = intel_get_drm_devid(fd);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000103
Chris Wilson66d5f092014-05-08 11:56:56 +0100104 render_copy = igt_get_render_copyfunc(devid);
Daniel Vetter0b7ce4a2014-05-14 09:56:53 +0200105 igt_require(render_copy);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000106
Chris Wilson66d5f092014-05-08 11:56:56 +0100107 snoop = 1;
108 if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */
109 snoop = 0;
110 if (IS_BROADWATER(devid) || IS_CRESTLINE(devid)) /* snafu */
111 snoop = 0;
112
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000113 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
Chris Wilsone0ce2312012-12-12 14:33:17 +0000114 drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
Chris Wilson66d5f092014-05-08 11:56:56 +0100115 batch = intel_batchbuffer_alloc(bufmgr, devid);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000116
Chris Wilson66d5f092014-05-08 11:56:56 +0100117 linear = drm_intel_bo_alloc(bufmgr, "linear", WIDTH*HEIGHT*4, 0);
118 if (snoop) {
119 gem_set_caching(fd, linear->handle, 1);
Daniel Vettere624fa82014-05-14 00:36:04 +0200120 igt_info("Using a snoop linear buffer for comparisons\n");
Chris Wilson66d5f092014-05-08 11:56:56 +0100121 }
122
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000123 buf = malloc(sizeof(*buf)*count);
124 start_val = malloc(sizeof(*start_val)*count);
125
126 for (i = 0; i < count; i++) {
127 uint32_t tiling = I915_TILING_X + (random() & 1);
128 unsigned long pitch = STRIDE;
129 uint32_t *ptr;
130
131 buf[i].bo = drm_intel_bo_alloc_tiled(bufmgr, "",
132 WIDTH, HEIGHT, 4,
133 &tiling, &pitch, 0);
134 buf[i].stride = pitch;
135 buf[i].tiling = tiling;
136 buf[i].size = SIZE;
137
138 start_val[i] = start;
139
140 do_or_die(drm_intel_gem_bo_map_gtt(buf[i].bo));
141 ptr = buf[i].bo->virtual;
142 for (j = 0; j < WIDTH*HEIGHT; j++)
143 ptr[j] = start++;
144 drm_intel_gem_bo_unmap_gtt(buf[i].bo);
145 }
146
Daniel Vettere624fa82014-05-14 00:36:04 +0200147 igt_info("Verifying initialisation...\n");
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000148 for (i = 0; i < count; i++)
Chris Wilson66d5f092014-05-08 11:56:56 +0100149 check_bo(batch, &buf[i], start_val[i]);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000150
Daniel Vettere624fa82014-05-14 00:36:04 +0200151 igt_info("Cyclic blits, forward...\n");
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000152 for (i = 0; i < count * 4; i++) {
153 int src = i % count;
154 int dst = (i + 1) % count;
155
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200156 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000157 start_val[dst] = start_val[src];
158 }
159 for (i = 0; i < count; i++)
Chris Wilson66d5f092014-05-08 11:56:56 +0100160 check_bo(batch, &buf[i], start_val[i]);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000161
Daniel Vettere624fa82014-05-14 00:36:04 +0200162 igt_info("Cyclic blits, backward...\n");
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000163 for (i = 0; i < count * 4; i++) {
164 int src = (i + 1) % count;
165 int dst = i % count;
166
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200167 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000168 start_val[dst] = start_val[src];
169 }
170 for (i = 0; i < count; i++)
Chris Wilson66d5f092014-05-08 11:56:56 +0100171 check_bo(batch, &buf[i], start_val[i]);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000172
Daniel Vettere624fa82014-05-14 00:36:04 +0200173 igt_info("Random blits...\n");
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000174 for (i = 0; i < count * 4; i++) {
175 int src = random() % count;
176 int dst = random() % count;
177
178 if (src == dst)
179 continue;
180
Ville Syrjälä725da6e2013-11-21 19:05:17 +0200181 render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000182 start_val[dst] = start_val[src];
183 }
184 for (i = 0; i < count; i++)
Chris Wilson66d5f092014-05-08 11:56:56 +0100185 check_bo(batch, &buf[i], start_val[i]);
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000186
Tim Goreee5c1192015-03-03 10:43:43 +0000187 /* release resources */
188 drm_intel_bo_unreference(linear);
189 for (i = 0; i < count; i++) {
190 drm_intel_bo_unreference(buf[i].bo);
191 }
192 intel_batchbuffer_free(batch);
193 drm_intel_bufmgr_destroy(bufmgr);
194}
195
196
197igt_main
198{
199 int fd = 0;
200 int count = 0;
201
202 igt_fixture {
Micah Fedkec81d2932015-07-22 21:54:02 +0000203 fd = drm_open_driver(DRIVER_INTEL);
Tim Goreee5c1192015-03-03 10:43:43 +0000204 }
205
Daniel Vetter6672da52015-12-10 12:29:14 +0100206 igt_subtest("basic") {
Tim Goreee5c1192015-03-03 10:43:43 +0000207 run_test(fd, 2);
208 }
209
210 /* the rest of the tests are too long for simulation */
211 igt_skip_on_simulation();
212
213 igt_subtest("apperture-thrash") {
214 count = 3 * gem_aperture_size(fd) / SIZE / 2;
215 intel_require_memory(count, SIZE, CHECK_RAM);
216 run_test(fd, count);
217 }
218
219 igt_subtest("swap-thrash") {
220 uint64_t swap_mb = intel_get_total_swap_mb();
221 igt_require(swap_mb > 0);
222 count = ((intel_get_avail_ram_mb() + (swap_mb / 2)) * 1024*1024) / SIZE;
223 intel_require_memory(count, SIZE, CHECK_RAM | CHECK_SWAP);
224 run_test(fd, count);
225 }
Chris Wilsonc0dbf042012-12-06 20:36:24 +0000226}