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