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