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