blob: b7f5d49cb7a771d3e4d9e96f66c4029a71fbf8ed [file] [log] [blame]
Eric Anholt3b301df2009-04-03 14:23:06 -07001/*
2 * Copyright © 2009 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 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28/** @file gem_tiled_blits.c
29 *
30 * This is a test of doing many tiled blits, with a working set
31 * larger than the aperture size.
32 *
33 * The goal is to catch a couple types of failure;
34 * - Fence management problems on pre-965.
35 * - A17 or L-shaped memory tiling workaround problems in acceleration.
36 *
37 * The model is to fill a collection of 1MB objects in a way that can't trip
38 * over A6 swizzling -- upload data to a non-tiled object, blit to the tiled
39 * object. Then, copy the 1MB objects randomly between each other for a while.
40 * Finally, download their data through linear objects again and see what
41 * resulted.
42 */
43
44#include <stdlib.h>
45#include <stdio.h>
46#include <string.h>
47#include <assert.h>
48#include <fcntl.h>
49#include <inttypes.h>
50#include <errno.h>
51#include <sys/stat.h>
52#include <sys/time.h>
53#include "drm.h"
54#include "i915_drm.h"
55#include "drmtest.h"
56#include "intel_bufmgr.h"
57#include "intel_batchbuffer.h"
58#include "intel_gpu_tools.h"
59
60static drm_intel_bufmgr *bufmgr;
61struct intel_batchbuffer *batch;
62static int width = 512, height = 512;
Eric Anholt3b301df2009-04-03 14:23:06 -070063
64static drm_intel_bo *
65create_bo(uint32_t start_val)
66{
67 drm_intel_bo *bo, *linear_bo;
68 uint32_t *linear;
69 uint32_t tiling = I915_TILING_X;
70 int ret, i;
71
72 bo = drm_intel_bo_alloc(bufmgr, "tiled bo", 1024 * 1024, 4096);
73 ret = drm_intel_bo_set_tiling(bo, &tiling, width * 4);
74 assert(ret == 0);
75 assert(tiling == I915_TILING_X);
76
77 linear_bo = drm_intel_bo_alloc(bufmgr, "linear src", 1024 * 1024, 4096);
78
79 /* Fill the BO with dwords starting at start_val */
80 drm_intel_bo_map(linear_bo, 1);
81 linear = linear_bo->virtual;
82
83 for (i = 0; i < 1024 * 1024 / 4; i++) {
84 linear[i] = start_val++;
85 }
86 drm_intel_bo_unmap(linear_bo);
87
Chris Wilsond4d769a2010-10-26 10:59:18 +010088 intel_copy_bo (batch, bo, linear_bo, width, height);
Eric Anholt3b301df2009-04-03 14:23:06 -070089
90 drm_intel_bo_unreference(linear_bo);
91
92 return bo;
93}
94
95static void
96check_bo(drm_intel_bo *bo, uint32_t start_val)
97{
98 drm_intel_bo *linear_bo;
99 uint32_t *linear;
100 int i;
101
102 linear_bo = drm_intel_bo_alloc(bufmgr, "linear dst", 1024 * 1024, 4096);
103
Chris Wilsond4d769a2010-10-26 10:59:18 +0100104 intel_copy_bo(batch, linear_bo, bo, width, height);
Eric Anholt3b301df2009-04-03 14:23:06 -0700105
106 drm_intel_bo_map(linear_bo, 0);
107 linear = linear_bo->virtual;
108
109 for (i = 0; i < 1024 * 1024 / 4; i++) {
110 if (linear[i] != start_val) {
111 fprintf(stderr, "Expected 0x%08x, found 0x%08x "
112 "at offset 0x%08x\n",
113 start_val, linear[i], i * 4);
114 abort();
115 }
116 start_val++;
117 }
118 drm_intel_bo_unmap(linear_bo);
119
120 drm_intel_bo_unreference(linear_bo);
121}
122
123int main(int argc, char **argv)
124{
125 int fd;
126 int bo_count = 768; /* 768MB of objects */
127 drm_intel_bo *bo[bo_count];
128 uint32_t bo_start_val[bo_count];
129 uint32_t start = 0;
130 int i;
131
132 fd = drm_open_any();
Eric Anholt3b301df2009-04-03 14:23:06 -0700133
134 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
135 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
Chris Wilsond4d769a2010-10-26 10:59:18 +0100136 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
Eric Anholt3b301df2009-04-03 14:23:06 -0700137
138 for (i = 0; i < bo_count; i++) {
139 bo[i] = create_bo(start);
140 bo_start_val[i] = start;
141
142 /*
143 printf("Creating bo %d\n", i);
144 check_bo(bo[i], bo_start_val[i]);
145 */
146
147 start += 1024 * 1024 / 4;
148 }
149
150 for (i = 0; i < bo_count * 4; i++) {
151 int src = random() % bo_count;
152 int dst = random() % bo_count;
153
154 if (src == dst)
155 continue;
156
Chris Wilsond4d769a2010-10-26 10:59:18 +0100157 intel_copy_bo(batch, bo[dst], bo[src], width, height);
Eric Anholt3b301df2009-04-03 14:23:06 -0700158 bo_start_val[dst] = bo_start_val[src];
159
160 /*
161 check_bo(bo[dst], bo_start_val[dst]);
162 printf("%d: copy bo %d to %d\n", i, src, dst);
163 */
164 }
165
166 for (i = 0; i < bo_count; i++) {
167 /*
168 printf("check %d\n", i);
169 */
170 check_bo(bo[i], bo_start_val[i]);
171
172 drm_intel_bo_unreference(bo[i]);
173 bo[i] = NULL;
174 }
175
176 intel_batchbuffer_free(batch);
177 drm_intel_bufmgr_destroy(bufmgr);
178
179 close(fd);
180
181 return 0;
182}