meson: add missing idep_nir_headers in iris_gen_libs
[mesa.git] / src / gallium / drivers / iris / iris_batch.c
1 /*
2 * Copyright © 2017 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 shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 /**
24 * @file iris_batch.c
25 *
26 * Batchbuffer and command submission module.
27 *
28 * Every API draw call results in a number of GPU commands, which we
29 * collect into a "batch buffer". Typically, many draw calls are grouped
30 * into a single batch to amortize command submission overhead.
31 *
32 * We submit batches to the kernel using the I915_GEM_EXECBUFFER2 ioctl.
33 * One critical piece of data is the "validation list", which contains a
34 * list of the buffer objects (BOs) which the commands in the GPU need.
35 * The kernel will make sure these are resident and pinned at the correct
36 * virtual memory address before executing our batch. If a BO is not in
37 * the validation list, it effectively does not exist, so take care.
38 */
39
40 #include "iris_batch.h"
41 #include "iris_bufmgr.h"
42 #include "iris_context.h"
43 #include "iris_fence.h"
44
45 #include "drm-uapi/i915_drm.h"
46
47 #include "intel/common/gen_gem.h"
48 #include "util/hash_table.h"
49 #include "util/set.h"
50 #include "main/macros.h"
51
52 #include <errno.h>
53 #include <xf86drm.h>
54
55 #if HAVE_VALGRIND
56 #include <valgrind.h>
57 #include <memcheck.h>
58 #define VG(x) x
59 #else
60 #define VG(x)
61 #endif
62
63 #define FILE_DEBUG_FLAG DEBUG_BUFMGR
64
65 /* Terminating the batch takes either 4 bytes for MI_BATCH_BUFFER_END
66 * or 12 bytes for MI_BATCH_BUFFER_START (when chaining). Plus, we may
67 * need an extra 4 bytes to pad out to the nearest QWord. So reserve 16.
68 */
69 #define BATCH_RESERVED 16
70
71 static void
72 iris_batch_reset(struct iris_batch *batch);
73
74 static unsigned
75 num_fences(struct iris_batch *batch)
76 {
77 return util_dynarray_num_elements(&batch->exec_fences,
78 struct drm_i915_gem_exec_fence);
79 }
80
81 /**
82 * Debugging code to dump the fence list, used by INTEL_DEBUG=submit.
83 */
84 static void
85 dump_fence_list(struct iris_batch *batch)
86 {
87 fprintf(stderr, "Fence list (length %u): ", num_fences(batch));
88
89 util_dynarray_foreach(&batch->exec_fences,
90 struct drm_i915_gem_exec_fence, f) {
91 fprintf(stderr, "%s%u%s ",
92 (f->flags & I915_EXEC_FENCE_WAIT) ? "..." : "",
93 f->handle,
94 (f->flags & I915_EXEC_FENCE_SIGNAL) ? "!" : "");
95 }
96
97 fprintf(stderr, "\n");
98 }
99
100 /**
101 * Debugging code to dump the validation list, used by INTEL_DEBUG=submit.
102 */
103 static void
104 dump_validation_list(struct iris_batch *batch)
105 {
106 fprintf(stderr, "Validation list (length %d):\n", batch->exec_count);
107
108 for (int i = 0; i < batch->exec_count; i++) {
109 uint64_t flags = batch->validation_list[i].flags;
110 assert(batch->validation_list[i].handle ==
111 batch->exec_bos[i]->gem_handle);
112 fprintf(stderr, "[%2d]: %2d %-14s @ 0x%016llx (%"PRIu64"B)\t %2d refs %s\n",
113 i,
114 batch->validation_list[i].handle,
115 batch->exec_bos[i]->name,
116 batch->validation_list[i].offset,
117 batch->exec_bos[i]->size,
118 batch->exec_bos[i]->refcount,
119 (flags & EXEC_OBJECT_WRITE) ? " (write)" : "");
120 }
121 }
122
123 /**
124 * Return BO information to the batch decoder (for debugging).
125 */
126 static struct gen_batch_decode_bo
127 decode_get_bo(void *v_batch, bool ppgtt, uint64_t address)
128 {
129 struct iris_batch *batch = v_batch;
130
131 assert(ppgtt);
132
133 for (int i = 0; i < batch->exec_count; i++) {
134 struct iris_bo *bo = batch->exec_bos[i];
135 /* The decoder zeroes out the top 16 bits, so we need to as well */
136 uint64_t bo_address = bo->gtt_offset & (~0ull >> 16);
137
138 if (address >= bo_address && address < bo_address + bo->size) {
139 return (struct gen_batch_decode_bo) {
140 .addr = address,
141 .size = bo->size,
142 .map = iris_bo_map(batch->dbg, bo, MAP_READ) +
143 (address - bo_address),
144 };
145 }
146 }
147
148 return (struct gen_batch_decode_bo) { };
149 }
150
151 static unsigned
152 decode_get_state_size(void *v_batch, uint32_t offset_from_base)
153 {
154 struct iris_batch *batch = v_batch;
155
156 /* The decoder gives us offsets from a base address, which is not great.
157 * Binding tables are relative to surface state base address, and other
158 * state is relative to dynamic state base address. These could alias,
159 * but in practice it's unlikely because surface offsets are always in
160 * the [0, 64K) range, and we assign dynamic state addresses starting at
161 * the top of the 4GB range. We should fix this but it's likely good
162 * enough for now.
163 */
164 unsigned size = (uintptr_t)
165 _mesa_hash_table_u64_search(batch->state_sizes, offset_from_base);
166
167 return size;
168 }
169
170 /**
171 * Decode the current batch.
172 */
173 static void
174 decode_batch(struct iris_batch *batch)
175 {
176 void *map = iris_bo_map(batch->dbg, batch->exec_bos[0], MAP_READ);
177 gen_print_batch(&batch->decoder, map, batch->primary_batch_size,
178 batch->exec_bos[0]->gtt_offset, false);
179 }
180
181 void
182 iris_init_batch(struct iris_batch *batch,
183 struct iris_screen *screen,
184 struct iris_vtable *vtbl,
185 struct pipe_debug_callback *dbg,
186 struct pipe_device_reset_callback *reset,
187 struct hash_table_u64 *state_sizes,
188 struct iris_batch *all_batches,
189 enum iris_batch_name name,
190 uint8_t engine,
191 int priority)
192 {
193 batch->screen = screen;
194 batch->vtbl = vtbl;
195 batch->dbg = dbg;
196 batch->reset = reset;
197 batch->state_sizes = state_sizes;
198 batch->name = name;
199
200 /* engine should be one of I915_EXEC_RENDER, I915_EXEC_BLT, etc. */
201 assert((engine & ~I915_EXEC_RING_MASK) == 0);
202 assert(util_bitcount(engine) == 1);
203 batch->engine = engine;
204
205 batch->hw_ctx_id = iris_create_hw_context(screen->bufmgr);
206 assert(batch->hw_ctx_id);
207
208 iris_hw_context_set_priority(screen->bufmgr, batch->hw_ctx_id, priority);
209
210 util_dynarray_init(&batch->exec_fences, ralloc_context(NULL));
211 util_dynarray_init(&batch->syncpts, ralloc_context(NULL));
212
213 batch->exec_count = 0;
214 batch->exec_array_size = 100;
215 batch->exec_bos =
216 malloc(batch->exec_array_size * sizeof(batch->exec_bos[0]));
217 batch->validation_list =
218 malloc(batch->exec_array_size * sizeof(batch->validation_list[0]));
219
220 batch->cache.render = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
221 _mesa_key_pointer_equal);
222 batch->cache.depth = _mesa_set_create(NULL, _mesa_hash_pointer,
223 _mesa_key_pointer_equal);
224
225 memset(batch->other_batches, 0, sizeof(batch->other_batches));
226
227 for (int i = 0, j = 0; i < IRIS_BATCH_COUNT; i++) {
228 if (&all_batches[i] != batch)
229 batch->other_batches[j++] = &all_batches[i];
230 }
231
232 if (unlikely(INTEL_DEBUG)) {
233 const unsigned decode_flags =
234 GEN_BATCH_DECODE_FULL |
235 ((INTEL_DEBUG & DEBUG_COLOR) ? GEN_BATCH_DECODE_IN_COLOR : 0) |
236 GEN_BATCH_DECODE_OFFSETS |
237 GEN_BATCH_DECODE_FLOATS;
238
239 gen_batch_decode_ctx_init(&batch->decoder, &screen->devinfo,
240 stderr, decode_flags, NULL,
241 decode_get_bo, decode_get_state_size, batch);
242 batch->decoder.dynamic_base = IRIS_MEMZONE_DYNAMIC_START;
243 batch->decoder.instruction_base = IRIS_MEMZONE_SHADER_START;
244 batch->decoder.max_vbo_decoded_lines = 32;
245 }
246
247 iris_batch_reset(batch);
248 }
249
250 static struct drm_i915_gem_exec_object2 *
251 find_validation_entry(struct iris_batch *batch, struct iris_bo *bo)
252 {
253 unsigned index = READ_ONCE(bo->index);
254
255 if (index < batch->exec_count && batch->exec_bos[index] == bo)
256 return &batch->validation_list[index];
257
258 /* May have been shared between multiple active batches */
259 for (index = 0; index < batch->exec_count; index++) {
260 if (batch->exec_bos[index] == bo)
261 return &batch->validation_list[index];
262 }
263
264 return NULL;
265 }
266
267 /**
268 * Add a buffer to the current batch's validation list.
269 *
270 * You must call this on any BO you wish to use in this batch, to ensure
271 * that it's resident when the GPU commands execute.
272 */
273 void
274 iris_use_pinned_bo(struct iris_batch *batch,
275 struct iris_bo *bo,
276 bool writable)
277 {
278 assert(bo->kflags & EXEC_OBJECT_PINNED);
279
280 /* Never mark the workaround BO with EXEC_OBJECT_WRITE. We don't care
281 * about the order of any writes to that buffer, and marking it writable
282 * would introduce data dependencies between multiple batches which share
283 * the buffer.
284 */
285 if (bo == batch->screen->workaround_bo)
286 writable = false;
287
288 struct drm_i915_gem_exec_object2 *existing_entry =
289 find_validation_entry(batch, bo);
290
291 if (existing_entry) {
292 /* The BO is already in the validation list; mark it writable */
293 if (writable)
294 existing_entry->flags |= EXEC_OBJECT_WRITE;
295
296 return;
297 }
298
299 if (bo != batch->bo) {
300 /* This is the first time our batch has seen this BO. Before we use it,
301 * we may need to flush and synchronize with other batches.
302 */
303 for (int b = 0; b < ARRAY_SIZE(batch->other_batches); b++) {
304 struct drm_i915_gem_exec_object2 *other_entry =
305 find_validation_entry(batch->other_batches[b], bo);
306
307 /* If the buffer is referenced by another batch, and either batch
308 * intends to write it, then flush the other batch and synchronize.
309 *
310 * Consider these cases:
311 *
312 * 1. They read, we read => No synchronization required.
313 * 2. They read, we write => Synchronize (they need the old value)
314 * 3. They write, we read => Synchronize (we need their new value)
315 * 4. They write, we write => Synchronize (order writes)
316 *
317 * The read/read case is very common, as multiple batches usually
318 * share a streaming state buffer or shader assembly buffer, and
319 * we want to avoid synchronizing in this case.
320 */
321 if (other_entry &&
322 ((other_entry->flags & EXEC_OBJECT_WRITE) || writable)) {
323 iris_batch_flush(batch->other_batches[b]);
324 iris_batch_add_syncpt(batch, batch->other_batches[b]->last_syncpt,
325 I915_EXEC_FENCE_WAIT);
326 }
327 }
328 }
329
330 /* Now, take a reference and add it to the validation list. */
331 iris_bo_reference(bo);
332
333 if (batch->exec_count == batch->exec_array_size) {
334 batch->exec_array_size *= 2;
335 batch->exec_bos =
336 realloc(batch->exec_bos,
337 batch->exec_array_size * sizeof(batch->exec_bos[0]));
338 batch->validation_list =
339 realloc(batch->validation_list,
340 batch->exec_array_size * sizeof(batch->validation_list[0]));
341 }
342
343 batch->validation_list[batch->exec_count] =
344 (struct drm_i915_gem_exec_object2) {
345 .handle = bo->gem_handle,
346 .offset = bo->gtt_offset,
347 .flags = bo->kflags | (writable ? EXEC_OBJECT_WRITE : 0),
348 };
349
350 bo->index = batch->exec_count;
351 batch->exec_bos[batch->exec_count] = bo;
352 batch->aperture_space += bo->size;
353
354 batch->exec_count++;
355 }
356
357 static void
358 create_batch(struct iris_batch *batch)
359 {
360 struct iris_screen *screen = batch->screen;
361 struct iris_bufmgr *bufmgr = screen->bufmgr;
362
363 batch->bo = iris_bo_alloc(bufmgr, "command buffer",
364 BATCH_SZ + BATCH_RESERVED, IRIS_MEMZONE_OTHER);
365 batch->bo->kflags |= EXEC_OBJECT_CAPTURE;
366 batch->map = iris_bo_map(NULL, batch->bo, MAP_READ | MAP_WRITE);
367 batch->map_next = batch->map;
368
369 iris_use_pinned_bo(batch, batch->bo, false);
370 }
371
372 static void
373 iris_batch_reset(struct iris_batch *batch)
374 {
375 struct iris_screen *screen = batch->screen;
376
377 iris_bo_unreference(batch->bo);
378 batch->primary_batch_size = 0;
379 batch->contains_draw = false;
380 batch->decoder.surface_base = batch->last_surface_base_address;
381
382 create_batch(batch);
383 assert(batch->bo->index == 0);
384
385 struct iris_syncpt *syncpt = iris_create_syncpt(screen);
386 iris_batch_add_syncpt(batch, syncpt, I915_EXEC_FENCE_SIGNAL);
387 iris_syncpt_reference(screen, &syncpt, NULL);
388
389 iris_cache_sets_clear(batch);
390 }
391
392 void
393 iris_batch_free(struct iris_batch *batch)
394 {
395 struct iris_screen *screen = batch->screen;
396 struct iris_bufmgr *bufmgr = screen->bufmgr;
397
398 for (int i = 0; i < batch->exec_count; i++) {
399 iris_bo_unreference(batch->exec_bos[i]);
400 }
401 free(batch->exec_bos);
402 free(batch->validation_list);
403
404 ralloc_free(batch->exec_fences.mem_ctx);
405
406 util_dynarray_foreach(&batch->syncpts, struct iris_syncpt *, s)
407 iris_syncpt_reference(screen, s, NULL);
408 ralloc_free(batch->syncpts.mem_ctx);
409
410 iris_syncpt_reference(screen, &batch->last_syncpt, NULL);
411
412 iris_bo_unreference(batch->bo);
413 batch->bo = NULL;
414 batch->map = NULL;
415 batch->map_next = NULL;
416
417 iris_destroy_hw_context(bufmgr, batch->hw_ctx_id);
418
419 _mesa_hash_table_destroy(batch->cache.render, NULL);
420 _mesa_set_destroy(batch->cache.depth, NULL);
421
422 if (unlikely(INTEL_DEBUG))
423 gen_batch_decode_ctx_finish(&batch->decoder);
424 }
425
426 /**
427 * If we've chained to a secondary batch, or are getting near to the end,
428 * then flush. This should only be called between draws.
429 */
430 void
431 iris_batch_maybe_flush(struct iris_batch *batch, unsigned estimate)
432 {
433 if (batch->bo != batch->exec_bos[0] ||
434 iris_batch_bytes_used(batch) + estimate >= BATCH_SZ) {
435 iris_batch_flush(batch);
436 }
437 }
438
439 void
440 iris_chain_to_new_batch(struct iris_batch *batch)
441 {
442 /* We only support chaining a single time. */
443 assert(batch->bo == batch->exec_bos[0]);
444
445 VG(void *map = batch->map);
446 uint32_t *cmd = batch->map_next;
447 uint64_t *addr = batch->map_next + 4;
448 batch->map_next += 12;
449
450 /* No longer held by batch->bo, still held by validation list */
451 iris_bo_unreference(batch->bo);
452 batch->primary_batch_size = iris_batch_bytes_used(batch);
453 create_batch(batch);
454
455 /* Emit MI_BATCH_BUFFER_START to chain to another batch. */
456 *cmd = (0x31 << 23) | (1 << 8) | (3 - 2);
457 *addr = batch->bo->gtt_offset;
458
459 VG(VALGRIND_CHECK_MEM_IS_DEFINED(map, batch->primary_batch_size));
460 }
461
462 /**
463 * Terminate a batch with MI_BATCH_BUFFER_END.
464 */
465 static void
466 iris_finish_batch(struct iris_batch *batch)
467 {
468 /* Emit MI_BATCH_BUFFER_END to finish our batch. */
469 uint32_t *map = batch->map_next;
470
471 map[0] = (0xA << 23);
472
473 batch->map_next += 4;
474 VG(VALGRIND_CHECK_MEM_IS_DEFINED(batch->map, iris_batch_bytes_used(batch)));
475
476 if (batch->bo == batch->exec_bos[0])
477 batch->primary_batch_size = iris_batch_bytes_used(batch);
478 }
479
480 /**
481 * Replace our current GEM context with a new one (in case it got banned).
482 */
483 static bool
484 replace_hw_ctx(struct iris_batch *batch)
485 {
486 struct iris_screen *screen = batch->screen;
487 struct iris_bufmgr *bufmgr = screen->bufmgr;
488
489 uint32_t new_ctx = iris_clone_hw_context(bufmgr, batch->hw_ctx_id);
490 if (!new_ctx)
491 return false;
492
493 iris_destroy_hw_context(bufmgr, batch->hw_ctx_id);
494 batch->hw_ctx_id = new_ctx;
495
496 /* Notify the context that state must be re-initialized. */
497 iris_lost_context_state(batch);
498
499 return true;
500 }
501
502 enum pipe_reset_status
503 iris_batch_check_for_reset(struct iris_batch *batch)
504 {
505 struct iris_screen *screen = batch->screen;
506 enum pipe_reset_status status = PIPE_NO_RESET;
507 struct drm_i915_reset_stats stats = { .ctx_id = batch->hw_ctx_id };
508
509 if (drmIoctl(screen->fd, DRM_IOCTL_I915_GET_RESET_STATS, &stats))
510 DBG("DRM_IOCTL_I915_GET_RESET_STATS failed: %s\n", strerror(errno));
511
512 if (stats.batch_active != 0) {
513 /* A reset was observed while a batch from this hardware context was
514 * executing. Assume that this context was at fault.
515 */
516 status = PIPE_GUILTY_CONTEXT_RESET;
517 } else if (stats.batch_pending != 0) {
518 /* A reset was observed while a batch from this context was in progress,
519 * but the batch was not executing. In this case, assume that the
520 * context was not at fault.
521 */
522 status = PIPE_INNOCENT_CONTEXT_RESET;
523 }
524
525 if (status != PIPE_NO_RESET) {
526 /* Our context is likely banned, or at least in an unknown state.
527 * Throw it away and start with a fresh context. Ideally this may
528 * catch the problem before our next execbuf fails with -EIO.
529 */
530 replace_hw_ctx(batch);
531 }
532
533 return status;
534 }
535
536 /**
537 * Submit the batch to the GPU via execbuffer2.
538 */
539 static int
540 submit_batch(struct iris_batch *batch)
541 {
542 iris_bo_unmap(batch->bo);
543
544 /* The requirement for using I915_EXEC_NO_RELOC are:
545 *
546 * The addresses written in the objects must match the corresponding
547 * reloc.gtt_offset which in turn must match the corresponding
548 * execobject.offset.
549 *
550 * Any render targets written to in the batch must be flagged with
551 * EXEC_OBJECT_WRITE.
552 *
553 * To avoid stalling, execobject.offset should match the current
554 * address of that object within the active context.
555 */
556 struct drm_i915_gem_execbuffer2 execbuf = {
557 .buffers_ptr = (uintptr_t) batch->validation_list,
558 .buffer_count = batch->exec_count,
559 .batch_start_offset = 0,
560 /* This must be QWord aligned. */
561 .batch_len = ALIGN(batch->primary_batch_size, 8),
562 .flags = batch->engine |
563 I915_EXEC_NO_RELOC |
564 I915_EXEC_BATCH_FIRST |
565 I915_EXEC_HANDLE_LUT,
566 .rsvd1 = batch->hw_ctx_id, /* rsvd1 is actually the context ID */
567 };
568
569 if (num_fences(batch)) {
570 execbuf.flags |= I915_EXEC_FENCE_ARRAY;
571 execbuf.num_cliprects = num_fences(batch);
572 execbuf.cliprects_ptr =
573 (uintptr_t)util_dynarray_begin(&batch->exec_fences);
574 }
575
576 int ret = 0;
577 if (!batch->screen->no_hw &&
578 gen_ioctl(batch->screen->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf))
579 ret = -errno;
580
581 for (int i = 0; i < batch->exec_count; i++) {
582 struct iris_bo *bo = batch->exec_bos[i];
583
584 bo->idle = false;
585 bo->index = -1;
586
587 iris_bo_unreference(bo);
588 }
589
590 return ret;
591 }
592
593 static const char *
594 batch_name_to_string(enum iris_batch_name name)
595 {
596 const char *names[IRIS_BATCH_COUNT] = {
597 [IRIS_BATCH_RENDER] = "render",
598 [IRIS_BATCH_COMPUTE] = "compute",
599 };
600 return names[name];
601 }
602
603 /**
604 * Flush the batch buffer, submitting it to the GPU and resetting it so
605 * we're ready to emit the next batch.
606 *
607 * \param in_fence_fd is ignored if -1. Otherwise, this function takes
608 * ownership of the fd.
609 *
610 * \param out_fence_fd is ignored if NULL. Otherwise, the caller must
611 * take ownership of the returned fd.
612 */
613 void
614 _iris_batch_flush(struct iris_batch *batch, const char *file, int line)
615 {
616 struct iris_screen *screen = batch->screen;
617
618 if (iris_batch_bytes_used(batch) == 0)
619 return;
620
621 iris_finish_batch(batch);
622
623 if (unlikely(INTEL_DEBUG &
624 (DEBUG_BATCH | DEBUG_SUBMIT | DEBUG_PIPE_CONTROL))) {
625 int bytes_for_commands = iris_batch_bytes_used(batch);
626 int second_bytes = 0;
627 if (batch->bo != batch->exec_bos[0]) {
628 second_bytes = bytes_for_commands;
629 bytes_for_commands += batch->primary_batch_size;
630 }
631 fprintf(stderr, "%19s:%-3d: %s batch [%u] flush with %5d+%5db (%0.1f%%) "
632 "(cmds), %4d BOs (%0.1fMb aperture)\n",
633 file, line, batch_name_to_string(batch->name), batch->hw_ctx_id,
634 batch->primary_batch_size, second_bytes,
635 100.0f * bytes_for_commands / BATCH_SZ,
636 batch->exec_count,
637 (float) batch->aperture_space / (1024 * 1024));
638
639 if (INTEL_DEBUG & (DEBUG_BATCH | DEBUG_SUBMIT)) {
640 dump_fence_list(batch);
641 dump_validation_list(batch);
642 }
643
644 if (INTEL_DEBUG & DEBUG_BATCH) {
645 decode_batch(batch);
646 }
647 }
648
649 int ret = submit_batch(batch);
650
651 batch->exec_count = 0;
652 batch->aperture_space = 0;
653
654 struct iris_syncpt *syncpt =
655 ((struct iris_syncpt **) util_dynarray_begin(&batch->syncpts))[0];
656 iris_syncpt_reference(screen, &batch->last_syncpt, syncpt);
657
658 util_dynarray_foreach(&batch->syncpts, struct iris_syncpt *, s)
659 iris_syncpt_reference(screen, s, NULL);
660 util_dynarray_clear(&batch->syncpts);
661
662 util_dynarray_clear(&batch->exec_fences);
663
664 if (unlikely(INTEL_DEBUG & DEBUG_SYNC)) {
665 dbg_printf("waiting for idle\n");
666 iris_bo_wait_rendering(batch->bo); /* if execbuf failed; this is a nop */
667 }
668
669 /* Start a new batch buffer. */
670 iris_batch_reset(batch);
671
672 /* EIO means our context is banned. In this case, try and replace it
673 * with a new logical context, and inform iris_context that all state
674 * has been lost and needs to be re-initialized. If this succeeds,
675 * dubiously claim success...
676 */
677 if (ret == -EIO && replace_hw_ctx(batch)) {
678 if (batch->reset->reset) {
679 /* Tell the state tracker the device is lost and it was our fault. */
680 batch->reset->reset(batch->reset->data, PIPE_GUILTY_CONTEXT_RESET);
681 }
682
683 ret = 0;
684 }
685
686 if (ret < 0) {
687 #ifdef DEBUG
688 const bool color = INTEL_DEBUG & DEBUG_COLOR;
689 fprintf(stderr, "%siris: Failed to submit batchbuffer: %-80s%s\n",
690 color ? "\e[1;41m" : "", strerror(-ret), color ? "\e[0m" : "");
691 #endif
692 abort();
693 }
694 }
695
696 /**
697 * Does the current batch refer to the given BO?
698 *
699 * (In other words, is the BO in the current batch's validation list?)
700 */
701 bool
702 iris_batch_references(struct iris_batch *batch, struct iris_bo *bo)
703 {
704 return find_validation_entry(batch, bo) != NULL;
705 }