blob: 10516b4f17ce301aec529db0a343919d97a792e9 [file] [log] [blame]
Chris Wilsonec2eac62012-11-14 12:15:01 +00001/*
Chris Wilsond5517a12013-01-17 15:05:20 +00002 * Copyright © 2012,2013 Intel Corporation
Chris Wilsonec2eac62012-11-14 12:15:01 +00003 *
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
Thomas Woodb2ac2642014-11-28 11:02:44 +000028/* Exercises the basic execbuffer using the handle LUT interface */
Chris Wilsonec2eac62012-11-14 12:15:01 +000029
Thomas Wood804e11f2015-08-17 17:57:43 +010030#include "igt.h"
Chris Wilsonec2eac62012-11-14 12:15:01 +000031#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
Chris Wilsonec2eac62012-11-14 12:15:01 +000034#include <fcntl.h>
35#include <inttypes.h>
36#include <errno.h>
37#include <sys/stat.h>
38#include <sys/time.h>
39#include "drm.h"
Chris Wilsonec2eac62012-11-14 12:15:01 +000040
Thomas Woodb2ac2642014-11-28 11:02:44 +000041IGT_TEST_DESCRIPTION("Exercises the basic execbuffer using the handle LUT"
42 " interface.");
43
Chris Wilsonec2eac62012-11-14 12:15:01 +000044#define BATCH_SIZE (1024*1024)
45
46#define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
47
Chris Wilsond5517a12013-01-17 15:05:20 +000048#define NORMAL 0
Chris Wilsonec2eac62012-11-14 12:15:01 +000049#define USE_LUT 0x1
50#define BROKEN 0x2
51
52static int exec(int fd, uint32_t handle, unsigned int flags)
53{
54 struct drm_i915_gem_execbuffer2 execbuf;
55 struct drm_i915_gem_exec_object2 gem_exec[1];
56 struct drm_i915_gem_relocation_entry gem_reloc[1];
57
58 gem_reloc[0].offset = 1024;
59 gem_reloc[0].delta = 0;
60 gem_reloc[0].target_handle =
61 !!(flags & USE_LUT) ^ !!(flags & BROKEN) ? 0 : handle;
62 gem_reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
63 gem_reloc[0].write_domain = 0;
64 gem_reloc[0].presumed_offset = 0;
65
66 gem_exec[0].handle = handle;
67 gem_exec[0].relocation_count = 1;
Chris Wilson4de67b22017-01-02 11:05:21 +000068 gem_exec[0].relocs_ptr = to_user_pointer(gem_reloc);
Chris Wilsonec2eac62012-11-14 12:15:01 +000069 gem_exec[0].alignment = 0;
70 gem_exec[0].offset = 0;
71 gem_exec[0].flags = 0;
72 gem_exec[0].rsvd1 = 0;
73 gem_exec[0].rsvd2 = 0;
74
Chris Wilson4de67b22017-01-02 11:05:21 +000075 execbuf.buffers_ptr = to_user_pointer(gem_exec);
Chris Wilsonec2eac62012-11-14 12:15:01 +000076 execbuf.buffer_count = 1;
77 execbuf.batch_start_offset = 0;
78 execbuf.batch_len = 8;
79 execbuf.cliprects_ptr = 0;
80 execbuf.num_cliprects = 0;
81 execbuf.DR1 = 0;
82 execbuf.DR4 = 0;
83 execbuf.flags = flags & USE_LUT ? LOCAL_I915_EXEC_HANDLE_LUT : 0;
84 i915_execbuffer2_set_context_id(execbuf, 0);
85 execbuf.rsvd2 = 0;
86
Chris Wilsone46ff3f2014-05-08 10:04:35 +010087 if (drmIoctl(fd,
88 DRM_IOCTL_I915_GEM_EXECBUFFER2,
89 &execbuf))
90 return -errno;
91
92 return 0;
Chris Wilsonec2eac62012-11-14 12:15:01 +000093}
94
Chris Wilsond5517a12013-01-17 15:05:20 +000095static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsigned flags)
96{
97 struct drm_i915_gem_execbuffer2 execbuf;
98 struct drm_i915_gem_exec_object2 *gem_exec;
99 struct drm_i915_gem_relocation_entry *gem_reloc;
Chris Wilson9d8fc192013-06-07 11:44:40 +0100100 unsigned max_handle = batch;
Chris Wilsond5517a12013-01-17 15:05:20 +0000101 int ret, n;
102
103 gem_exec = calloc(num_exec+1, sizeof(*gem_exec));
104 gem_reloc = calloc(num_reloc, sizeof(*gem_reloc));
Daniel Vetter83440952013-08-13 12:35:58 +0200105 igt_assert(gem_exec && gem_reloc);
Chris Wilsond5517a12013-01-17 15:05:20 +0000106
107 for (n = 0; n < num_exec; n++) {
108 gem_exec[n].handle = gem_create(fd, 4096);
Chris Wilsond5517a12013-01-17 15:05:20 +0000109 if (gem_exec[n].handle > max_handle)
110 max_handle = gem_exec[n].handle;
111 gem_exec[n].relocation_count = 0;
112 gem_exec[n].relocs_ptr = 0;
113 gem_exec[n].alignment = 0;
114 gem_exec[n].offset = 0;
115 gem_exec[n].flags = 0;
116 gem_exec[n].rsvd1 = 0;
117 gem_exec[n].rsvd2 = 0;
118 }
119
120 gem_exec[n].handle = batch;
121 gem_exec[n].relocation_count = num_reloc;
Chris Wilson4de67b22017-01-02 11:05:21 +0000122 gem_exec[n].relocs_ptr = to_user_pointer(gem_reloc);
Chris Wilsond5517a12013-01-17 15:05:20 +0000123
Chris Wilson9d8fc192013-06-07 11:44:40 +0100124 if (flags & USE_LUT)
Chris Wilsond5517a12013-01-17 15:05:20 +0000125 max_handle = num_exec + 1;
Chris Wilson9d8fc192013-06-07 11:44:40 +0100126 max_handle++;
Chris Wilsond5517a12013-01-17 15:05:20 +0000127
128 for (n = 0; n < num_reloc; n++) {
Chris Wilson60e39302013-06-24 13:53:44 +0100129 uint32_t target;
Chris Wilsond5517a12013-01-17 15:05:20 +0000130
131 if (flags & BROKEN) {
Chris Wilsonebfd0192013-06-27 19:58:57 +0100132 target = -(rand() % 4096) - 1;
Chris Wilsond5517a12013-01-17 15:05:20 +0000133 } else {
134 target = rand() % (num_exec + 1);
135 if ((flags & USE_LUT) == 0)
136 target = gem_exec[target].handle;
137 }
138
139 gem_reloc[n].offset = 1024;
140 gem_reloc[n].delta = 0;
141 gem_reloc[n].target_handle = target;
142 gem_reloc[n].read_domains = I915_GEM_DOMAIN_RENDER;
143 gem_reloc[n].write_domain = 0;
144 gem_reloc[n].presumed_offset = 0;
145 }
146
Chris Wilson4de67b22017-01-02 11:05:21 +0000147 execbuf.buffers_ptr = to_user_pointer(gem_exec);
Chris Wilsond5517a12013-01-17 15:05:20 +0000148 execbuf.buffer_count = num_exec + 1;
149 execbuf.batch_start_offset = 0;
150 execbuf.batch_len = 8;
151 execbuf.cliprects_ptr = 0;
152 execbuf.num_cliprects = 0;
153 execbuf.DR1 = 0;
154 execbuf.DR4 = 0;
155 execbuf.flags = flags & USE_LUT ? LOCAL_I915_EXEC_HANDLE_LUT : 0;
156 i915_execbuffer2_set_context_id(execbuf, 0);
157 execbuf.rsvd2 = 0;
158
159 ret = drmIoctl(fd,
160 DRM_IOCTL_I915_GEM_EXECBUFFER2,
161 &execbuf);
Chris Wilsonc1404e02014-04-29 07:14:33 +0100162 if (ret < 0)
163 ret = -errno;
Chris Wilsond5517a12013-01-17 15:05:20 +0000164
165 for (n = 0; n < num_exec; n++)
166 gem_close(fd, gem_exec[n].handle);
167
168 free(gem_exec);
169 free(gem_reloc);
170
171 return ret;
172}
173
Daniel Vetter0b7ce4a2014-05-14 09:56:53 +0200174#define fail(x) igt_assert((x) == -ENOENT)
175#define pass(x) igt_assert((x) == 0)
Chris Wilsond5517a12013-01-17 15:05:20 +0000176
Daniel Vetterdda85fb2013-12-10 10:18:32 +0100177igt_simple_main
Chris Wilsonec2eac62012-11-14 12:15:01 +0000178{
179 uint32_t batch[2] = {MI_BATCH_BUFFER_END};
180 uint32_t handle;
Chris Wilsond5517a12013-01-17 15:05:20 +0000181 int fd, i;
Chris Wilsonec2eac62012-11-14 12:15:01 +0000182
Micah Fedkec81d2932015-07-22 21:54:02 +0000183 fd = drm_open_driver(DRIVER_INTEL);
Chris Wilsonec2eac62012-11-14 12:15:01 +0000184
185 handle = gem_create(fd, 4096);
186 gem_write(fd, handle, 0, batch, sizeof(batch));
187
Chris Wilsond5517a12013-01-17 15:05:20 +0000188 do_or_die(exec(fd, handle, NORMAL));
Chris Wilsond5517a12013-01-17 15:05:20 +0000189 fail(exec(fd, handle, BROKEN));
Chris Wilsonfb7bc2e2013-01-17 15:07:50 +0000190
Daniel Vettercb9e8372014-01-10 09:21:15 +0100191 igt_skip_on(exec(fd, handle, USE_LUT));
Chris Wilsonfb7bc2e2013-01-17 15:07:50 +0000192
193 do_or_die(exec(fd, handle, USE_LUT));
Chris Wilsond5517a12013-01-17 15:05:20 +0000194 fail(exec(fd, handle, USE_LUT | BROKEN));
195
Damien Lespiau204df662013-07-18 11:36:56 +0100196 for (i = 2; i <= SLOW_QUICK(65536, 8); i *= 2) {
Chris Wilsonc1404e02014-04-29 07:14:33 +0100197 if (many_exec(fd, handle, i+1, i+1, NORMAL) == -ENOSPC)
Chris Wilsonebfd0192013-06-27 19:58:57 +0100198 break;
199
Chris Wilsonf1e9e302013-06-05 11:10:04 +0100200 pass(many_exec(fd, handle, i-1, i-1, NORMAL));
201 pass(many_exec(fd, handle, i-1, i, NORMAL));
202 pass(many_exec(fd, handle, i-1, i+1, NORMAL));
203 pass(many_exec(fd, handle, i, i-1, NORMAL));
204 pass(many_exec(fd, handle, i, i, NORMAL));
205 pass(many_exec(fd, handle, i, i+1, NORMAL));
206 pass(many_exec(fd, handle, i+1, i-1, NORMAL));
207 pass(many_exec(fd, handle, i+1, i, NORMAL));
208 pass(many_exec(fd, handle, i+1, i+1, NORMAL));
Chris Wilsond5517a12013-01-17 15:05:20 +0000209
210 fail(many_exec(fd, handle, i-1, i-1, NORMAL | BROKEN));
211 fail(many_exec(fd, handle, i-1, i, NORMAL | BROKEN));
212 fail(many_exec(fd, handle, i-1, i+1, NORMAL | BROKEN));
213 fail(many_exec(fd, handle, i, i-1, NORMAL | BROKEN));
214 fail(many_exec(fd, handle, i, i, NORMAL | BROKEN));
215 fail(many_exec(fd, handle, i, i+1, NORMAL | BROKEN));
216 fail(many_exec(fd, handle, i+1, i-1, NORMAL | BROKEN));
217 fail(many_exec(fd, handle, i+1, i, NORMAL | BROKEN));
218 fail(many_exec(fd, handle, i+1, i+1, NORMAL | BROKEN));
219
Chris Wilsonf1e9e302013-06-05 11:10:04 +0100220 pass(many_exec(fd, handle, i-1, i-1, USE_LUT));
221 pass(many_exec(fd, handle, i-1, i, USE_LUT));
222 pass(many_exec(fd, handle, i-1, i+1, USE_LUT));
223 pass(many_exec(fd, handle, i, i-1, USE_LUT));
224 pass(many_exec(fd, handle, i, i, USE_LUT));
225 pass(many_exec(fd, handle, i, i+1, USE_LUT));
226 pass(many_exec(fd, handle, i+1, i-1, USE_LUT));
227 pass(many_exec(fd, handle, i+1, i, USE_LUT));
228 pass(many_exec(fd, handle, i+1, i+1, USE_LUT));
Chris Wilsond5517a12013-01-17 15:05:20 +0000229
230 fail(many_exec(fd, handle, i-1, i-1, USE_LUT | BROKEN));
231 fail(many_exec(fd, handle, i-1, i, USE_LUT | BROKEN));
232 fail(many_exec(fd, handle, i-1, i+1, USE_LUT | BROKEN));
233 fail(many_exec(fd, handle, i, i-1, USE_LUT | BROKEN));
234 fail(many_exec(fd, handle, i, i, USE_LUT | BROKEN));
235 fail(many_exec(fd, handle, i, i+1, USE_LUT | BROKEN));
236 fail(many_exec(fd, handle, i+1, i-1, USE_LUT | BROKEN));
237 fail(many_exec(fd, handle, i+1, i, USE_LUT | BROKEN));
238 fail(many_exec(fd, handle, i+1, i+1, USE_LUT | BROKEN));
239 }
Chris Wilsonec2eac62012-11-14 12:15:01 +0000240}