Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 1 | /* |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 2 | * Copyright © 2012,2013 Intel Corporation |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 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 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 28 | /* Exercises the basic execbuffer using the handle LUT interface */ |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 29 | |
Thomas Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 30 | #include "igt.h" |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 34 | #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 Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 40 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 41 | IGT_TEST_DESCRIPTION("Exercises the basic execbuffer using the handle LUT" |
| 42 | " interface."); |
| 43 | |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 44 | #define BATCH_SIZE (1024*1024) |
| 45 | |
| 46 | #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12) |
| 47 | |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 48 | #define NORMAL 0 |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 49 | #define USE_LUT 0x1 |
| 50 | #define BROKEN 0x2 |
| 51 | |
| 52 | static 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 Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 68 | gem_exec[0].relocs_ptr = to_user_pointer(gem_reloc); |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 69 | 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 Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 75 | execbuf.buffers_ptr = to_user_pointer(gem_exec); |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 76 | 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 Wilson | e46ff3f | 2014-05-08 10:04:35 +0100 | [diff] [blame] | 87 | if (drmIoctl(fd, |
| 88 | DRM_IOCTL_I915_GEM_EXECBUFFER2, |
| 89 | &execbuf)) |
| 90 | return -errno; |
| 91 | |
| 92 | return 0; |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 95 | static 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 Wilson | 9d8fc19 | 2013-06-07 11:44:40 +0100 | [diff] [blame] | 100 | unsigned max_handle = batch; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 101 | int ret, n; |
| 102 | |
| 103 | gem_exec = calloc(num_exec+1, sizeof(*gem_exec)); |
| 104 | gem_reloc = calloc(num_reloc, sizeof(*gem_reloc)); |
Daniel Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 105 | igt_assert(gem_exec && gem_reloc); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 106 | |
| 107 | for (n = 0; n < num_exec; n++) { |
| 108 | gem_exec[n].handle = gem_create(fd, 4096); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 109 | 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 Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 122 | gem_exec[n].relocs_ptr = to_user_pointer(gem_reloc); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 123 | |
Chris Wilson | 9d8fc19 | 2013-06-07 11:44:40 +0100 | [diff] [blame] | 124 | if (flags & USE_LUT) |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 125 | max_handle = num_exec + 1; |
Chris Wilson | 9d8fc19 | 2013-06-07 11:44:40 +0100 | [diff] [blame] | 126 | max_handle++; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 127 | |
| 128 | for (n = 0; n < num_reloc; n++) { |
Chris Wilson | 60e3930 | 2013-06-24 13:53:44 +0100 | [diff] [blame] | 129 | uint32_t target; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 130 | |
| 131 | if (flags & BROKEN) { |
Chris Wilson | ebfd019 | 2013-06-27 19:58:57 +0100 | [diff] [blame] | 132 | target = -(rand() % 4096) - 1; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 133 | } 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 Wilson | 4de67b2 | 2017-01-02 11:05:21 +0000 | [diff] [blame] | 147 | execbuf.buffers_ptr = to_user_pointer(gem_exec); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 148 | 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 Wilson | c1404e0 | 2014-04-29 07:14:33 +0100 | [diff] [blame] | 162 | if (ret < 0) |
| 163 | ret = -errno; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 164 | |
| 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 Vetter | 0b7ce4a | 2014-05-14 09:56:53 +0200 | [diff] [blame] | 174 | #define fail(x) igt_assert((x) == -ENOENT) |
| 175 | #define pass(x) igt_assert((x) == 0) |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 176 | |
Daniel Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 177 | igt_simple_main |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 178 | { |
| 179 | uint32_t batch[2] = {MI_BATCH_BUFFER_END}; |
| 180 | uint32_t handle; |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 181 | int fd, i; |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 182 | |
Micah Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 183 | fd = drm_open_driver(DRIVER_INTEL); |
Chris Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 184 | |
| 185 | handle = gem_create(fd, 4096); |
| 186 | gem_write(fd, handle, 0, batch, sizeof(batch)); |
| 187 | |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 188 | do_or_die(exec(fd, handle, NORMAL)); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 189 | fail(exec(fd, handle, BROKEN)); |
Chris Wilson | fb7bc2e | 2013-01-17 15:07:50 +0000 | [diff] [blame] | 190 | |
Daniel Vetter | cb9e837 | 2014-01-10 09:21:15 +0100 | [diff] [blame] | 191 | igt_skip_on(exec(fd, handle, USE_LUT)); |
Chris Wilson | fb7bc2e | 2013-01-17 15:07:50 +0000 | [diff] [blame] | 192 | |
| 193 | do_or_die(exec(fd, handle, USE_LUT)); |
Chris Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 194 | fail(exec(fd, handle, USE_LUT | BROKEN)); |
| 195 | |
Damien Lespiau | 204df66 | 2013-07-18 11:36:56 +0100 | [diff] [blame] | 196 | for (i = 2; i <= SLOW_QUICK(65536, 8); i *= 2) { |
Chris Wilson | c1404e0 | 2014-04-29 07:14:33 +0100 | [diff] [blame] | 197 | if (many_exec(fd, handle, i+1, i+1, NORMAL) == -ENOSPC) |
Chris Wilson | ebfd019 | 2013-06-27 19:58:57 +0100 | [diff] [blame] | 198 | break; |
| 199 | |
Chris Wilson | f1e9e30 | 2013-06-05 11:10:04 +0100 | [diff] [blame] | 200 | 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 Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 209 | |
| 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 Wilson | f1e9e30 | 2013-06-05 11:10:04 +0100 | [diff] [blame] | 220 | 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 Wilson | d5517a1 | 2013-01-17 15:05:20 +0000 | [diff] [blame] | 229 | |
| 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 Wilson | ec2eac6 | 2012-11-14 12:15:01 +0000 | [diff] [blame] | 240 | } |