Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_batch.c
4565 views
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/intel_aux_map.h"
48
#include "intel/common/intel_gem.h"
49
#include "util/hash_table.h"
50
#include "util/set.h"
51
#include "util/u_upload_mgr.h"
52
#include "main/macros.h"
53
54
#include <errno.h>
55
#include <xf86drm.h>
56
57
#if HAVE_VALGRIND
58
#include <valgrind.h>
59
#include <memcheck.h>
60
#define VG(x) x
61
#else
62
#define VG(x)
63
#endif
64
65
#define FILE_DEBUG_FLAG DEBUG_BUFMGR
66
67
static void
68
iris_batch_reset(struct iris_batch *batch);
69
70
static unsigned
71
num_fences(struct iris_batch *batch)
72
{
73
return util_dynarray_num_elements(&batch->exec_fences,
74
struct drm_i915_gem_exec_fence);
75
}
76
77
/**
78
* Debugging code to dump the fence list, used by INTEL_DEBUG=submit.
79
*/
80
static void
81
dump_fence_list(struct iris_batch *batch)
82
{
83
fprintf(stderr, "Fence list (length %u): ", num_fences(batch));
84
85
util_dynarray_foreach(&batch->exec_fences,
86
struct drm_i915_gem_exec_fence, f) {
87
fprintf(stderr, "%s%u%s ",
88
(f->flags & I915_EXEC_FENCE_WAIT) ? "..." : "",
89
f->handle,
90
(f->flags & I915_EXEC_FENCE_SIGNAL) ? "!" : "");
91
}
92
93
fprintf(stderr, "\n");
94
}
95
96
/**
97
* Debugging code to dump the validation list, used by INTEL_DEBUG=submit.
98
*/
99
static void
100
dump_validation_list(struct iris_batch *batch)
101
{
102
fprintf(stderr, "Validation list (length %d):\n", batch->exec_count);
103
104
for (int i = 0; i < batch->exec_count; i++) {
105
uint64_t flags = batch->validation_list[i].flags;
106
assert(batch->validation_list[i].handle ==
107
batch->exec_bos[i]->gem_handle);
108
fprintf(stderr, "[%2d]: %2d %-14s @ 0x%"PRIx64" (%"PRIu64"B)\t %2d refs %s\n",
109
i,
110
batch->validation_list[i].handle,
111
batch->exec_bos[i]->name,
112
(uint64_t)batch->validation_list[i].offset,
113
batch->exec_bos[i]->size,
114
batch->exec_bos[i]->refcount,
115
(flags & EXEC_OBJECT_WRITE) ? " (write)" : "");
116
}
117
}
118
119
/**
120
* Return BO information to the batch decoder (for debugging).
121
*/
122
static struct intel_batch_decode_bo
123
decode_get_bo(void *v_batch, bool ppgtt, uint64_t address)
124
{
125
struct iris_batch *batch = v_batch;
126
127
assert(ppgtt);
128
129
for (int i = 0; i < batch->exec_count; i++) {
130
struct iris_bo *bo = batch->exec_bos[i];
131
/* The decoder zeroes out the top 16 bits, so we need to as well */
132
uint64_t bo_address = bo->gtt_offset & (~0ull >> 16);
133
134
if (address >= bo_address && address < bo_address + bo->size) {
135
return (struct intel_batch_decode_bo) {
136
.addr = bo_address,
137
.size = bo->size,
138
.map = iris_bo_map(batch->dbg, bo, MAP_READ),
139
};
140
}
141
}
142
143
return (struct intel_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
intel_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
batch->ice = ice;
183
batch->contains_fence_signal = false;
184
185
batch->fine_fences.uploader =
186
u_upload_create(&ice->ctx, 4096, PIPE_BIND_CUSTOM,
187
PIPE_USAGE_STAGING, 0);
188
iris_fine_fence_init(batch);
189
190
batch->hw_ctx_id = iris_create_hw_context(screen->bufmgr);
191
assert(batch->hw_ctx_id);
192
193
iris_hw_context_set_priority(screen->bufmgr, batch->hw_ctx_id, priority);
194
195
util_dynarray_init(&batch->exec_fences, ralloc_context(NULL));
196
util_dynarray_init(&batch->syncobjs, ralloc_context(NULL));
197
198
batch->exec_count = 0;
199
batch->exec_array_size = 100;
200
batch->exec_bos =
201
malloc(batch->exec_array_size * sizeof(batch->exec_bos[0]));
202
batch->validation_list =
203
malloc(batch->exec_array_size * sizeof(batch->validation_list[0]));
204
205
batch->cache.render = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
206
_mesa_key_pointer_equal);
207
208
memset(batch->other_batches, 0, sizeof(batch->other_batches));
209
210
for (int i = 0, j = 0; i < IRIS_BATCH_COUNT; i++) {
211
if (i != name)
212
batch->other_batches[j++] = &ice->batches[i];
213
}
214
215
if (INTEL_DEBUG) {
216
const unsigned decode_flags =
217
INTEL_BATCH_DECODE_FULL |
218
((INTEL_DEBUG & DEBUG_COLOR) ? INTEL_BATCH_DECODE_IN_COLOR : 0) |
219
INTEL_BATCH_DECODE_OFFSETS |
220
INTEL_BATCH_DECODE_FLOATS;
221
222
intel_batch_decode_ctx_init(&batch->decoder, &screen->devinfo,
223
stderr, decode_flags, NULL,
224
decode_get_bo, decode_get_state_size, batch);
225
batch->decoder.dynamic_base = IRIS_MEMZONE_DYNAMIC_START;
226
batch->decoder.instruction_base = IRIS_MEMZONE_SHADER_START;
227
batch->decoder.max_vbo_decoded_lines = 32;
228
}
229
230
iris_init_batch_measure(ice, batch);
231
232
iris_batch_reset(batch);
233
}
234
235
static struct drm_i915_gem_exec_object2 *
236
find_validation_entry(struct iris_batch *batch, struct iris_bo *bo)
237
{
238
unsigned index = READ_ONCE(bo->index);
239
240
if (index < batch->exec_count && batch->exec_bos[index] == bo)
241
return &batch->validation_list[index];
242
243
/* May have been shared between multiple active batches */
244
for (index = 0; index < batch->exec_count; index++) {
245
if (batch->exec_bos[index] == bo)
246
return &batch->validation_list[index];
247
}
248
249
return NULL;
250
}
251
252
static void
253
ensure_exec_obj_space(struct iris_batch *batch, uint32_t count)
254
{
255
while (batch->exec_count + count > batch->exec_array_size) {
256
batch->exec_array_size *= 2;
257
batch->exec_bos =
258
realloc(batch->exec_bos,
259
batch->exec_array_size * sizeof(batch->exec_bos[0]));
260
batch->validation_list =
261
realloc(batch->validation_list,
262
batch->exec_array_size * sizeof(batch->validation_list[0]));
263
}
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, enum iris_domain access)
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
if (access < NUM_IRIS_DOMAINS) {
288
assert(batch->sync_region_depth);
289
iris_bo_bump_seqno(bo, batch->next_seqno, access);
290
}
291
292
struct drm_i915_gem_exec_object2 *existing_entry =
293
find_validation_entry(batch, bo);
294
295
if (existing_entry) {
296
/* The BO is already in the validation list; mark it writable */
297
if (writable)
298
existing_entry->flags |= EXEC_OBJECT_WRITE;
299
300
return;
301
}
302
303
if (bo != batch->bo &&
304
(!batch->measure || bo != batch->measure->bo)) {
305
/* This is the first time our batch has seen this BO. Before we use it,
306
* we may need to flush and synchronize with other batches.
307
*/
308
for (int b = 0; b < ARRAY_SIZE(batch->other_batches); b++) {
309
struct drm_i915_gem_exec_object2 *other_entry =
310
find_validation_entry(batch->other_batches[b], bo);
311
312
/* If the buffer is referenced by another batch, and either batch
313
* intends to write it, then flush the other batch and synchronize.
314
*
315
* Consider these cases:
316
*
317
* 1. They read, we read => No synchronization required.
318
* 2. They read, we write => Synchronize (they need the old value)
319
* 3. They write, we read => Synchronize (we need their new value)
320
* 4. They write, we write => Synchronize (order writes)
321
*
322
* The read/read case is very common, as multiple batches usually
323
* share a streaming state buffer or shader assembly buffer, and
324
* we want to avoid synchronizing in this case.
325
*/
326
if (other_entry &&
327
((other_entry->flags & EXEC_OBJECT_WRITE) || writable)) {
328
iris_batch_flush(batch->other_batches[b]);
329
iris_batch_add_syncobj(batch,
330
batch->other_batches[b]->last_fence->syncobj,
331
I915_EXEC_FENCE_WAIT);
332
}
333
}
334
}
335
336
/* Now, take a reference and add it to the validation list. */
337
iris_bo_reference(bo);
338
339
ensure_exec_obj_space(batch, 1);
340
341
batch->validation_list[batch->exec_count] =
342
(struct drm_i915_gem_exec_object2) {
343
.handle = bo->gem_handle,
344
.offset = bo->gtt_offset,
345
.flags = bo->kflags | (writable ? EXEC_OBJECT_WRITE : 0),
346
};
347
348
bo->index = batch->exec_count;
349
batch->exec_bos[batch->exec_count] = bo;
350
batch->aperture_space += bo->size;
351
352
batch->exec_count++;
353
}
354
355
static void
356
create_batch(struct iris_batch *batch)
357
{
358
struct iris_screen *screen = batch->screen;
359
struct iris_bufmgr *bufmgr = screen->bufmgr;
360
361
batch->bo = iris_bo_alloc(bufmgr, "command buffer",
362
BATCH_SZ + BATCH_RESERVED, 1,
363
IRIS_MEMZONE_OTHER, 0);
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, IRIS_DOMAIN_NONE);
369
}
370
371
static void
372
iris_batch_maybe_noop(struct iris_batch *batch)
373
{
374
/* We only insert the NOOP at the beginning of the batch. */
375
assert(iris_batch_bytes_used(batch) == 0);
376
377
if (batch->noop_enabled) {
378
/* Emit MI_BATCH_BUFFER_END to prevent any further command to be
379
* executed.
380
*/
381
uint32_t *map = batch->map_next;
382
383
map[0] = (0xA << 23);
384
385
batch->map_next += 4;
386
}
387
}
388
389
static void
390
iris_batch_reset(struct iris_batch *batch)
391
{
392
struct iris_screen *screen = batch->screen;
393
394
iris_bo_unreference(batch->bo);
395
batch->primary_batch_size = 0;
396
batch->total_chained_batch_size = 0;
397
batch->contains_draw = false;
398
batch->contains_fence_signal = false;
399
batch->decoder.surface_base = batch->last_surface_base_address;
400
401
create_batch(batch);
402
assert(batch->bo->index == 0);
403
404
struct iris_syncobj *syncobj = iris_create_syncobj(screen);
405
iris_batch_add_syncobj(batch, syncobj, I915_EXEC_FENCE_SIGNAL);
406
iris_syncobj_reference(screen, &syncobj, NULL);
407
408
assert(!batch->sync_region_depth);
409
iris_batch_sync_boundary(batch);
410
iris_batch_mark_reset_sync(batch);
411
412
/* Always add the workaround BO, it contains a driver identifier at the
413
* beginning quite helpful to debug error states.
414
*/
415
iris_use_pinned_bo(batch, screen->workaround_bo, false, IRIS_DOMAIN_NONE);
416
417
iris_batch_maybe_noop(batch);
418
}
419
420
void
421
iris_batch_free(struct iris_batch *batch)
422
{
423
struct iris_screen *screen = batch->screen;
424
struct iris_bufmgr *bufmgr = screen->bufmgr;
425
426
for (int i = 0; i < batch->exec_count; i++) {
427
iris_bo_unreference(batch->exec_bos[i]);
428
}
429
free(batch->exec_bos);
430
free(batch->validation_list);
431
432
ralloc_free(batch->exec_fences.mem_ctx);
433
434
pipe_resource_reference(&batch->fine_fences.ref.res, NULL);
435
436
util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
437
iris_syncobj_reference(screen, s, NULL);
438
ralloc_free(batch->syncobjs.mem_ctx);
439
440
iris_fine_fence_reference(batch->screen, &batch->last_fence, NULL);
441
u_upload_destroy(batch->fine_fences.uploader);
442
443
iris_bo_unreference(batch->bo);
444
batch->bo = NULL;
445
batch->map = NULL;
446
batch->map_next = NULL;
447
448
iris_destroy_hw_context(bufmgr, batch->hw_ctx_id);
449
450
iris_destroy_batch_measure(batch->measure);
451
batch->measure = NULL;
452
453
_mesa_hash_table_destroy(batch->cache.render, NULL);
454
455
if (INTEL_DEBUG)
456
intel_batch_decode_ctx_finish(&batch->decoder);
457
}
458
459
/**
460
* If we've chained to a secondary batch, or are getting near to the end,
461
* then flush. This should only be called between draws.
462
*/
463
void
464
iris_batch_maybe_flush(struct iris_batch *batch, unsigned estimate)
465
{
466
if (batch->bo != batch->exec_bos[0] ||
467
iris_batch_bytes_used(batch) + estimate >= BATCH_SZ) {
468
iris_batch_flush(batch);
469
}
470
}
471
472
static void
473
record_batch_sizes(struct iris_batch *batch)
474
{
475
unsigned batch_size = iris_batch_bytes_used(batch);
476
477
VG(VALGRIND_CHECK_MEM_IS_DEFINED(batch->map, batch_size));
478
479
if (batch->bo == batch->exec_bos[0])
480
batch->primary_batch_size = batch_size;
481
482
batch->total_chained_batch_size += batch_size;
483
}
484
485
void
486
iris_chain_to_new_batch(struct iris_batch *batch)
487
{
488
uint32_t *cmd = batch->map_next;
489
uint64_t *addr = batch->map_next + 4;
490
batch->map_next += 12;
491
492
record_batch_sizes(batch);
493
494
/* No longer held by batch->bo, still held by validation list */
495
iris_bo_unreference(batch->bo);
496
create_batch(batch);
497
498
/* Emit MI_BATCH_BUFFER_START to chain to another batch. */
499
*cmd = (0x31 << 23) | (1 << 8) | (3 - 2);
500
*addr = batch->bo->gtt_offset;
501
}
502
503
static void
504
add_aux_map_bos_to_batch(struct iris_batch *batch)
505
{
506
void *aux_map_ctx = iris_bufmgr_get_aux_map_context(batch->screen->bufmgr);
507
if (!aux_map_ctx)
508
return;
509
510
uint32_t count = intel_aux_map_get_num_buffers(aux_map_ctx);
511
ensure_exec_obj_space(batch, count);
512
intel_aux_map_fill_bos(aux_map_ctx,
513
(void**)&batch->exec_bos[batch->exec_count], count);
514
for (uint32_t i = 0; i < count; i++) {
515
struct iris_bo *bo = batch->exec_bos[batch->exec_count];
516
iris_bo_reference(bo);
517
batch->validation_list[batch->exec_count] =
518
(struct drm_i915_gem_exec_object2) {
519
.handle = bo->gem_handle,
520
.offset = bo->gtt_offset,
521
.flags = bo->kflags,
522
};
523
batch->aperture_space += bo->size;
524
batch->exec_count++;
525
}
526
}
527
528
static void
529
finish_seqno(struct iris_batch *batch)
530
{
531
struct iris_fine_fence *sq = iris_fine_fence_new(batch, IRIS_FENCE_END);
532
if (!sq)
533
return;
534
535
iris_fine_fence_reference(batch->screen, &batch->last_fence, sq);
536
iris_fine_fence_reference(batch->screen, &sq, NULL);
537
}
538
539
/**
540
* Terminate a batch with MI_BATCH_BUFFER_END.
541
*/
542
static void
543
iris_finish_batch(struct iris_batch *batch)
544
{
545
const struct intel_device_info *devinfo = &batch->screen->devinfo;
546
547
if (devinfo->ver == 12 && batch->name == IRIS_BATCH_RENDER) {
548
/* We re-emit constants at the beginning of every batch as a hardware
549
* bug workaround, so invalidate indirect state pointers in order to
550
* save ourselves the overhead of restoring constants redundantly when
551
* the next render batch is executed.
552
*/
553
iris_emit_pipe_control_flush(batch, "ISP invalidate at batch end",
554
PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE |
555
PIPE_CONTROL_STALL_AT_SCOREBOARD |
556
PIPE_CONTROL_CS_STALL);
557
}
558
559
add_aux_map_bos_to_batch(batch);
560
561
finish_seqno(batch);
562
563
/* Emit MI_BATCH_BUFFER_END to finish our batch. */
564
uint32_t *map = batch->map_next;
565
566
map[0] = (0xA << 23);
567
568
batch->map_next += 4;
569
570
record_batch_sizes(batch);
571
}
572
573
/**
574
* Replace our current GEM context with a new one (in case it got banned).
575
*/
576
static bool
577
replace_hw_ctx(struct iris_batch *batch)
578
{
579
struct iris_screen *screen = batch->screen;
580
struct iris_bufmgr *bufmgr = screen->bufmgr;
581
582
uint32_t new_ctx = iris_clone_hw_context(bufmgr, batch->hw_ctx_id);
583
if (!new_ctx)
584
return false;
585
586
iris_destroy_hw_context(bufmgr, batch->hw_ctx_id);
587
batch->hw_ctx_id = new_ctx;
588
589
/* Notify the context that state must be re-initialized. */
590
iris_lost_context_state(batch);
591
592
return true;
593
}
594
595
enum pipe_reset_status
596
iris_batch_check_for_reset(struct iris_batch *batch)
597
{
598
struct iris_screen *screen = batch->screen;
599
enum pipe_reset_status status = PIPE_NO_RESET;
600
struct drm_i915_reset_stats stats = { .ctx_id = batch->hw_ctx_id };
601
602
if (intel_ioctl(screen->fd, DRM_IOCTL_I915_GET_RESET_STATS, &stats))
603
DBG("DRM_IOCTL_I915_GET_RESET_STATS failed: %s\n", strerror(errno));
604
605
if (stats.batch_active != 0) {
606
/* A reset was observed while a batch from this hardware context was
607
* executing. Assume that this context was at fault.
608
*/
609
status = PIPE_GUILTY_CONTEXT_RESET;
610
} else if (stats.batch_pending != 0) {
611
/* A reset was observed while a batch from this context was in progress,
612
* but the batch was not executing. In this case, assume that the
613
* context was not at fault.
614
*/
615
status = PIPE_INNOCENT_CONTEXT_RESET;
616
}
617
618
if (status != PIPE_NO_RESET) {
619
/* Our context is likely banned, or at least in an unknown state.
620
* Throw it away and start with a fresh context. Ideally this may
621
* catch the problem before our next execbuf fails with -EIO.
622
*/
623
replace_hw_ctx(batch);
624
}
625
626
return status;
627
}
628
629
/**
630
* Submit the batch to the GPU via execbuffer2.
631
*/
632
static int
633
submit_batch(struct iris_batch *batch)
634
{
635
iris_bo_unmap(batch->bo);
636
637
/* The requirement for using I915_EXEC_NO_RELOC are:
638
*
639
* The addresses written in the objects must match the corresponding
640
* reloc.gtt_offset which in turn must match the corresponding
641
* execobject.offset.
642
*
643
* Any render targets written to in the batch must be flagged with
644
* EXEC_OBJECT_WRITE.
645
*
646
* To avoid stalling, execobject.offset should match the current
647
* address of that object within the active context.
648
*/
649
struct drm_i915_gem_execbuffer2 execbuf = {
650
.buffers_ptr = (uintptr_t) batch->validation_list,
651
.buffer_count = batch->exec_count,
652
.batch_start_offset = 0,
653
/* This must be QWord aligned. */
654
.batch_len = ALIGN(batch->primary_batch_size, 8),
655
.flags = I915_EXEC_RENDER |
656
I915_EXEC_NO_RELOC |
657
I915_EXEC_BATCH_FIRST |
658
I915_EXEC_HANDLE_LUT,
659
.rsvd1 = batch->hw_ctx_id, /* rsvd1 is actually the context ID */
660
};
661
662
if (num_fences(batch)) {
663
execbuf.flags |= I915_EXEC_FENCE_ARRAY;
664
execbuf.num_cliprects = num_fences(batch);
665
execbuf.cliprects_ptr =
666
(uintptr_t)util_dynarray_begin(&batch->exec_fences);
667
}
668
669
int ret = 0;
670
if (!batch->screen->no_hw &&
671
intel_ioctl(batch->screen->fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf))
672
ret = -errno;
673
674
for (int i = 0; i < batch->exec_count; i++) {
675
struct iris_bo *bo = batch->exec_bos[i];
676
677
bo->idle = false;
678
bo->index = -1;
679
680
iris_bo_unreference(bo);
681
}
682
683
return ret;
684
}
685
686
static const char *
687
batch_name_to_string(enum iris_batch_name name)
688
{
689
const char *names[IRIS_BATCH_COUNT] = {
690
[IRIS_BATCH_RENDER] = "render",
691
[IRIS_BATCH_COMPUTE] = "compute",
692
};
693
return names[name];
694
}
695
696
/**
697
* Flush the batch buffer, submitting it to the GPU and resetting it so
698
* we're ready to emit the next batch.
699
*/
700
void
701
_iris_batch_flush(struct iris_batch *batch, const char *file, int line)
702
{
703
struct iris_screen *screen = batch->screen;
704
705
/* If a fence signals we need to flush it. */
706
if (iris_batch_bytes_used(batch) == 0 && !batch->contains_fence_signal)
707
return;
708
709
iris_measure_batch_end(batch->ice, batch);
710
711
iris_finish_batch(batch);
712
713
if (INTEL_DEBUG & (DEBUG_BATCH | DEBUG_SUBMIT | DEBUG_PIPE_CONTROL)) {
714
const char *basefile = strstr(file, "iris/");
715
if (basefile)
716
file = basefile + 5;
717
718
fprintf(stderr, "%19s:%-3d: %s batch [%u] flush with %5db (%0.1f%%) "
719
"(cmds), %4d BOs (%0.1fMb aperture)\n",
720
file, line, batch_name_to_string(batch->name), batch->hw_ctx_id,
721
batch->total_chained_batch_size,
722
100.0f * batch->total_chained_batch_size / BATCH_SZ,
723
batch->exec_count,
724
(float) batch->aperture_space / (1024 * 1024));
725
726
if (INTEL_DEBUG & (DEBUG_BATCH | DEBUG_SUBMIT)) {
727
dump_fence_list(batch);
728
dump_validation_list(batch);
729
}
730
731
if (INTEL_DEBUG & DEBUG_BATCH) {
732
decode_batch(batch);
733
}
734
}
735
736
int ret = submit_batch(batch);
737
738
batch->exec_count = 0;
739
batch->aperture_space = 0;
740
741
util_dynarray_foreach(&batch->syncobjs, struct iris_syncobj *, s)
742
iris_syncobj_reference(screen, s, NULL);
743
util_dynarray_clear(&batch->syncobjs);
744
745
util_dynarray_clear(&batch->exec_fences);
746
747
if (INTEL_DEBUG & DEBUG_SYNC) {
748
dbg_printf("waiting for idle\n");
749
iris_bo_wait_rendering(batch->bo); /* if execbuf failed; this is a nop */
750
}
751
752
/* Start a new batch buffer. */
753
iris_batch_reset(batch);
754
755
/* EIO means our context is banned. In this case, try and replace it
756
* with a new logical context, and inform iris_context that all state
757
* has been lost and needs to be re-initialized. If this succeeds,
758
* dubiously claim success...
759
* Also handle ENOMEM here.
760
*/
761
if ((ret == -EIO || ret == -ENOMEM) && replace_hw_ctx(batch)) {
762
if (batch->reset->reset) {
763
/* Tell gallium frontends the device is lost and it was our fault. */
764
batch->reset->reset(batch->reset->data, PIPE_GUILTY_CONTEXT_RESET);
765
}
766
767
ret = 0;
768
}
769
770
if (ret < 0) {
771
#ifdef DEBUG
772
const bool color = INTEL_DEBUG & DEBUG_COLOR;
773
fprintf(stderr, "%siris: Failed to submit batchbuffer: %-80s%s\n",
774
color ? "\e[1;41m" : "", strerror(-ret), color ? "\e[0m" : "");
775
#endif
776
abort();
777
}
778
}
779
780
/**
781
* Does the current batch refer to the given BO?
782
*
783
* (In other words, is the BO in the current batch's validation list?)
784
*/
785
bool
786
iris_batch_references(struct iris_batch *batch, struct iris_bo *bo)
787
{
788
return find_validation_entry(batch, bo) != NULL;
789
}
790
791
/**
792
* Updates the state of the noop feature. Returns true if there was a noop
793
* transition that led to state invalidation.
794
*/
795
bool
796
iris_batch_prepare_noop(struct iris_batch *batch, bool noop_enable)
797
{
798
if (batch->noop_enabled == noop_enable)
799
return 0;
800
801
batch->noop_enabled = noop_enable;
802
803
iris_batch_flush(batch);
804
805
/* If the batch was empty, flush had no effect, so insert our noop. */
806
if (iris_batch_bytes_used(batch) == 0)
807
iris_batch_maybe_noop(batch);
808
809
/* We only need to update the entire state if we transition from noop ->
810
* not-noop.
811
*/
812
return !batch->noop_enabled;
813
}
814
815