panfrost: Move the batch stack size adjustment out of panfrost_queue_draw()
[mesa.git] / src / gallium / drivers / panfrost / pan_job.c
1 /*
2 * Copyright (C) 2019 Alyssa Rosenzweig
3 * Copyright (C) 2014-2017 Broadcom
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #include <assert.h>
27
28 #include "drm-uapi/panfrost_drm.h"
29
30 #include "pan_bo.h"
31 #include "pan_context.h"
32 #include "util/hash_table.h"
33 #include "util/ralloc.h"
34 #include "util/format/u_format.h"
35 #include "util/u_pack_color.h"
36 #include "pan_util.h"
37 #include "pandecode/decode.h"
38 #include "panfrost-quirks.h"
39
40 /* panfrost_bo_access is here to help us keep track of batch accesses to BOs
41 * and build a proper dependency graph such that batches can be pipelined for
42 * better GPU utilization.
43 *
44 * Each accessed BO has a corresponding entry in the ->accessed_bos hash table.
45 * A BO is either being written or read at any time, that's what the type field
46 * encodes.
47 * When the last access is a write, the batch writing the BO might have read
48 * dependencies (readers that have not been executed yet and want to read the
49 * previous BO content), and when the last access is a read, all readers might
50 * depend on another batch to push its results to memory. That's what the
51 * readers/writers keep track off.
52 * There can only be one writer at any given time, if a new batch wants to
53 * write to the same BO, a dependency will be added between the new writer and
54 * the old writer (at the batch level), and panfrost_bo_access->writer will be
55 * updated to point to the new writer.
56 */
57 struct panfrost_bo_access {
58 uint32_t type;
59 struct util_dynarray readers;
60 struct panfrost_batch_fence *writer;
61 };
62
63 static struct panfrost_batch_fence *
64 panfrost_create_batch_fence(struct panfrost_batch *batch)
65 {
66 struct panfrost_batch_fence *fence;
67 ASSERTED int ret;
68
69 fence = rzalloc(NULL, struct panfrost_batch_fence);
70 assert(fence);
71 pipe_reference_init(&fence->reference, 1);
72 fence->ctx = batch->ctx;
73 fence->batch = batch;
74 ret = drmSyncobjCreate(pan_screen(batch->ctx->base.screen)->fd, 0,
75 &fence->syncobj);
76 assert(!ret);
77
78 return fence;
79 }
80
81 static void
82 panfrost_free_batch_fence(struct panfrost_batch_fence *fence)
83 {
84 drmSyncobjDestroy(pan_screen(fence->ctx->base.screen)->fd,
85 fence->syncobj);
86 ralloc_free(fence);
87 }
88
89 void
90 panfrost_batch_fence_unreference(struct panfrost_batch_fence *fence)
91 {
92 if (pipe_reference(&fence->reference, NULL))
93 panfrost_free_batch_fence(fence);
94 }
95
96 void
97 panfrost_batch_fence_reference(struct panfrost_batch_fence *fence)
98 {
99 pipe_reference(NULL, &fence->reference);
100 }
101
102 static struct panfrost_batch *
103 panfrost_create_batch(struct panfrost_context *ctx,
104 const struct pipe_framebuffer_state *key)
105 {
106 struct panfrost_batch *batch = rzalloc(ctx, struct panfrost_batch);
107
108 batch->ctx = ctx;
109
110 batch->bos = _mesa_hash_table_create(batch, _mesa_hash_pointer,
111 _mesa_key_pointer_equal);
112
113 batch->minx = batch->miny = ~0;
114 batch->maxx = batch->maxy = 0;
115 batch->transient_offset = 0;
116
117 batch->out_sync = panfrost_create_batch_fence(batch);
118 util_copy_framebuffer_state(&batch->key, key);
119
120 return batch;
121 }
122
123 static void
124 panfrost_freeze_batch(struct panfrost_batch *batch)
125 {
126 struct panfrost_context *ctx = batch->ctx;
127 struct hash_entry *entry;
128
129 /* Remove the entry in the FBO -> batch hash table if the batch
130 * matches. This way, next draws/clears targeting this FBO will trigger
131 * the creation of a new batch.
132 */
133 entry = _mesa_hash_table_search(ctx->batches, &batch->key);
134 if (entry && entry->data == batch)
135 _mesa_hash_table_remove(ctx->batches, entry);
136
137 /* If this is the bound batch, the panfrost_context parameters are
138 * relevant so submitting it invalidates those parameters, but if it's
139 * not bound, the context parameters are for some other batch so we
140 * can't invalidate them.
141 */
142 if (ctx->batch == batch) {
143 panfrost_invalidate_frame(ctx);
144 ctx->batch = NULL;
145 }
146 }
147
148 #ifndef NDEBUG
149 static bool panfrost_batch_is_frozen(struct panfrost_batch *batch)
150 {
151 struct panfrost_context *ctx = batch->ctx;
152 struct hash_entry *entry;
153
154 entry = _mesa_hash_table_search(ctx->batches, &batch->key);
155 if (entry && entry->data == batch)
156 return false;
157
158 if (ctx->batch == batch)
159 return false;
160
161 return true;
162 }
163 #endif
164
165 static void
166 panfrost_free_batch(struct panfrost_batch *batch)
167 {
168 if (!batch)
169 return;
170
171 assert(panfrost_batch_is_frozen(batch));
172
173 hash_table_foreach(batch->bos, entry)
174 panfrost_bo_unreference((struct panfrost_bo *)entry->key);
175
176 util_dynarray_foreach(&batch->dependencies,
177 struct panfrost_batch_fence *, dep) {
178 panfrost_batch_fence_unreference(*dep);
179 }
180
181 /* The out_sync fence lifetime is different from the the batch one
182 * since other batches might want to wait on a fence of already
183 * submitted/signaled batch. All we need to do here is make sure the
184 * fence does not point to an invalid batch, which the core will
185 * interpret as 'batch is already submitted'.
186 */
187 batch->out_sync->batch = NULL;
188 panfrost_batch_fence_unreference(batch->out_sync);
189
190 util_unreference_framebuffer_state(&batch->key);
191 ralloc_free(batch);
192 }
193
194 #ifndef NDEBUG
195 static bool
196 panfrost_dep_graph_contains_batch(struct panfrost_batch *root,
197 struct panfrost_batch *batch)
198 {
199 if (!root)
200 return false;
201
202 util_dynarray_foreach(&root->dependencies,
203 struct panfrost_batch_fence *, dep) {
204 if ((*dep)->batch == batch ||
205 panfrost_dep_graph_contains_batch((*dep)->batch, batch))
206 return true;
207 }
208
209 return false;
210 }
211 #endif
212
213 static void
214 panfrost_batch_add_dep(struct panfrost_batch *batch,
215 struct panfrost_batch_fence *newdep)
216 {
217 if (batch == newdep->batch)
218 return;
219
220 /* We might want to turn ->dependencies into a set if the number of
221 * deps turns out to be big enough to make this 'is dep already there'
222 * search inefficient.
223 */
224 util_dynarray_foreach(&batch->dependencies,
225 struct panfrost_batch_fence *, dep) {
226 if (*dep == newdep)
227 return;
228 }
229
230 /* Make sure the dependency graph is acyclic. */
231 assert(!panfrost_dep_graph_contains_batch(newdep->batch, batch));
232
233 panfrost_batch_fence_reference(newdep);
234 util_dynarray_append(&batch->dependencies,
235 struct panfrost_batch_fence *, newdep);
236
237 /* We now have a batch depending on us, let's make sure new draw/clear
238 * calls targeting the same FBO use a new batch object.
239 */
240 if (newdep->batch)
241 panfrost_freeze_batch(newdep->batch);
242 }
243
244 static struct panfrost_batch *
245 panfrost_get_batch(struct panfrost_context *ctx,
246 const struct pipe_framebuffer_state *key)
247 {
248 /* Lookup the job first */
249 struct hash_entry *entry = _mesa_hash_table_search(ctx->batches, key);
250
251 if (entry)
252 return entry->data;
253
254 /* Otherwise, let's create a job */
255
256 struct panfrost_batch *batch = panfrost_create_batch(ctx, key);
257
258 /* Save the created job */
259 _mesa_hash_table_insert(ctx->batches, &batch->key, batch);
260
261 return batch;
262 }
263
264 /* Get the job corresponding to the FBO we're currently rendering into */
265
266 struct panfrost_batch *
267 panfrost_get_batch_for_fbo(struct panfrost_context *ctx)
268 {
269 /* If we're wallpapering, we special case to workaround
270 * u_blitter abuse */
271
272 if (ctx->wallpaper_batch)
273 return ctx->wallpaper_batch;
274
275 /* If we already began rendering, use that */
276
277 if (ctx->batch) {
278 assert(util_framebuffer_state_equal(&ctx->batch->key,
279 &ctx->pipe_framebuffer));
280 return ctx->batch;
281 }
282
283 /* If not, look up the job */
284 struct panfrost_batch *batch = panfrost_get_batch(ctx,
285 &ctx->pipe_framebuffer);
286
287 /* Set this job as the current FBO job. Will be reset when updating the
288 * FB state and when submitting or releasing a job.
289 */
290 ctx->batch = batch;
291 return batch;
292 }
293
294 struct panfrost_batch *
295 panfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx)
296 {
297 struct panfrost_batch *batch;
298
299 batch = panfrost_get_batch(ctx, &ctx->pipe_framebuffer);
300
301 /* The batch has no draw/clear queued, let's return it directly.
302 * Note that it's perfectly fine to re-use a batch with an
303 * existing clear, we'll just update it with the new clear request.
304 */
305 if (!batch->first_job)
306 return batch;
307
308 /* Otherwise, we need to freeze the existing one and instantiate a new
309 * one.
310 */
311 panfrost_freeze_batch(batch);
312 return panfrost_get_batch(ctx, &ctx->pipe_framebuffer);
313 }
314
315 static bool
316 panfrost_batch_fence_is_signaled(struct panfrost_batch_fence *fence)
317 {
318 if (fence->signaled)
319 return true;
320
321 /* Batch has not been submitted yet. */
322 if (fence->batch)
323 return false;
324
325 int ret = drmSyncobjWait(pan_screen(fence->ctx->base.screen)->fd,
326 &fence->syncobj, 1, 0, 0, NULL);
327
328 /* Cache whether the fence was signaled */
329 fence->signaled = ret >= 0;
330 return fence->signaled;
331 }
332
333 static void
334 panfrost_bo_access_gc_fences(struct panfrost_context *ctx,
335 struct panfrost_bo_access *access,
336 const struct panfrost_bo *bo)
337 {
338 if (access->writer && panfrost_batch_fence_is_signaled(access->writer)) {
339 panfrost_batch_fence_unreference(access->writer);
340 access->writer = NULL;
341 }
342
343 struct panfrost_batch_fence **readers_array = util_dynarray_begin(&access->readers);
344 struct panfrost_batch_fence **new_readers = readers_array;
345
346 util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,
347 reader) {
348 if (!(*reader))
349 continue;
350
351 if (panfrost_batch_fence_is_signaled(*reader)) {
352 panfrost_batch_fence_unreference(*reader);
353 *reader = NULL;
354 } else {
355 /* Build a new array of only unsignaled fences in-place */
356 *(new_readers++) = *reader;
357 }
358 }
359
360 if (!util_dynarray_resize(&access->readers, struct panfrost_batch_fence *,
361 new_readers - readers_array) &&
362 new_readers != readers_array)
363 unreachable("Invalid dynarray access->readers");
364 }
365
366 /* Collect signaled fences to keep the kernel-side syncobj-map small. The
367 * idea is to collect those signaled fences at the end of each flush_all
368 * call. This function is likely to collect only fences from previous
369 * batch flushes not the one that have just have just been submitted and
370 * are probably still in flight when we trigger the garbage collection.
371 * Anyway, we need to do this garbage collection at some point if we don't
372 * want the BO access map to keep invalid entries around and retain
373 * syncobjs forever.
374 */
375 static void
376 panfrost_gc_fences(struct panfrost_context *ctx)
377 {
378 hash_table_foreach(ctx->accessed_bos, entry) {
379 struct panfrost_bo_access *access = entry->data;
380
381 assert(access);
382 panfrost_bo_access_gc_fences(ctx, access, entry->key);
383 if (!util_dynarray_num_elements(&access->readers,
384 struct panfrost_batch_fence *) &&
385 !access->writer) {
386 ralloc_free(access);
387 _mesa_hash_table_remove(ctx->accessed_bos, entry);
388 }
389 }
390 }
391
392 #ifndef NDEBUG
393 static bool
394 panfrost_batch_in_readers(struct panfrost_batch *batch,
395 struct panfrost_bo_access *access)
396 {
397 util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,
398 reader) {
399 if (*reader && (*reader)->batch == batch)
400 return true;
401 }
402
403 return false;
404 }
405 #endif
406
407 static void
408 panfrost_batch_update_bo_access(struct panfrost_batch *batch,
409 struct panfrost_bo *bo, uint32_t access_type,
410 bool already_accessed)
411 {
412 struct panfrost_context *ctx = batch->ctx;
413 struct panfrost_bo_access *access;
414 uint32_t old_access_type;
415 struct hash_entry *entry;
416
417 assert(access_type == PAN_BO_ACCESS_WRITE ||
418 access_type == PAN_BO_ACCESS_READ);
419
420 entry = _mesa_hash_table_search(ctx->accessed_bos, bo);
421 access = entry ? entry->data : NULL;
422 if (access) {
423 old_access_type = access->type;
424 } else {
425 access = rzalloc(ctx, struct panfrost_bo_access);
426 util_dynarray_init(&access->readers, access);
427 _mesa_hash_table_insert(ctx->accessed_bos, bo, access);
428 /* We are the first to access this BO, let's initialize
429 * old_access_type to our own access type in that case.
430 */
431 old_access_type = access_type;
432 access->type = access_type;
433 }
434
435 assert(access);
436
437 if (access_type == PAN_BO_ACCESS_WRITE &&
438 old_access_type == PAN_BO_ACCESS_READ) {
439 /* Previous access was a read and we want to write this BO.
440 * We first need to add explicit deps between our batch and
441 * the previous readers.
442 */
443 util_dynarray_foreach(&access->readers,
444 struct panfrost_batch_fence *, reader) {
445 /* We were already reading the BO, no need to add a dep
446 * on ourself (the acyclic check would complain about
447 * that).
448 */
449 if (!(*reader) || (*reader)->batch == batch)
450 continue;
451
452 panfrost_batch_add_dep(batch, *reader);
453 }
454 panfrost_batch_fence_reference(batch->out_sync);
455
456 /* We now are the new writer. */
457 access->writer = batch->out_sync;
458 access->type = access_type;
459
460 /* Release the previous readers and reset the readers array. */
461 util_dynarray_foreach(&access->readers,
462 struct panfrost_batch_fence *,
463 reader) {
464 if (!*reader)
465 continue;
466 panfrost_batch_fence_unreference(*reader);
467 }
468
469 util_dynarray_clear(&access->readers);
470 } else if (access_type == PAN_BO_ACCESS_WRITE &&
471 old_access_type == PAN_BO_ACCESS_WRITE) {
472 /* Previous access was a write and we want to write this BO.
473 * First check if we were the previous writer, in that case
474 * there's nothing to do. Otherwise we need to add a
475 * dependency between the new writer and the old one.
476 */
477 if (access->writer != batch->out_sync) {
478 if (access->writer) {
479 panfrost_batch_add_dep(batch, access->writer);
480 panfrost_batch_fence_unreference(access->writer);
481 }
482 panfrost_batch_fence_reference(batch->out_sync);
483 access->writer = batch->out_sync;
484 }
485 } else if (access_type == PAN_BO_ACCESS_READ &&
486 old_access_type == PAN_BO_ACCESS_WRITE) {
487 /* Previous access was a write and we want to read this BO.
488 * First check if we were the previous writer, in that case
489 * we want to keep the access type unchanged, as a write is
490 * more constraining than a read.
491 */
492 if (access->writer != batch->out_sync) {
493 /* Add a dependency on the previous writer. */
494 panfrost_batch_add_dep(batch, access->writer);
495
496 /* The previous access was a write, there's no reason
497 * to have entries in the readers array.
498 */
499 assert(!util_dynarray_num_elements(&access->readers,
500 struct panfrost_batch_fence *));
501
502 /* Add ourselves to the readers array. */
503 panfrost_batch_fence_reference(batch->out_sync);
504 util_dynarray_append(&access->readers,
505 struct panfrost_batch_fence *,
506 batch->out_sync);
507 access->type = PAN_BO_ACCESS_READ;
508 }
509 } else {
510 /* We already accessed this BO before, so we should already be
511 * in the reader array.
512 */
513 if (already_accessed) {
514 assert(panfrost_batch_in_readers(batch, access));
515 return;
516 }
517
518 /* Previous access was a read and we want to read this BO.
519 * Add ourselves to the readers array and add a dependency on
520 * the previous writer if any.
521 */
522 panfrost_batch_fence_reference(batch->out_sync);
523 util_dynarray_append(&access->readers,
524 struct panfrost_batch_fence *,
525 batch->out_sync);
526
527 if (access->writer)
528 panfrost_batch_add_dep(batch, access->writer);
529 }
530 }
531
532 void
533 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
534 uint32_t flags)
535 {
536 if (!bo)
537 return;
538
539 struct hash_entry *entry;
540 uint32_t old_flags = 0;
541
542 entry = _mesa_hash_table_search(batch->bos, bo);
543 if (!entry) {
544 entry = _mesa_hash_table_insert(batch->bos, bo,
545 (void *)(uintptr_t)flags);
546 panfrost_bo_reference(bo);
547 } else {
548 old_flags = (uintptr_t)entry->data;
549
550 /* All batches have to agree on the shared flag. */
551 assert((old_flags & PAN_BO_ACCESS_SHARED) ==
552 (flags & PAN_BO_ACCESS_SHARED));
553 }
554
555 assert(entry);
556
557 if (old_flags == flags)
558 return;
559
560 flags |= old_flags;
561 entry->data = (void *)(uintptr_t)flags;
562
563 /* If this is not a shared BO, we don't really care about dependency
564 * tracking.
565 */
566 if (!(flags & PAN_BO_ACCESS_SHARED))
567 return;
568
569 /* All dependencies should have been flushed before we execute the
570 * wallpaper draw, so it should be harmless to skip the
571 * update_bo_access() call.
572 */
573 if (batch == batch->ctx->wallpaper_batch)
574 return;
575
576 /* Only pass R/W flags to the dep tracking logic. */
577 assert(flags & PAN_BO_ACCESS_RW);
578 flags = (flags & PAN_BO_ACCESS_WRITE) ?
579 PAN_BO_ACCESS_WRITE : PAN_BO_ACCESS_READ;
580 panfrost_batch_update_bo_access(batch, bo, flags, old_flags != 0);
581 }
582
583 void panfrost_batch_add_fbo_bos(struct panfrost_batch *batch)
584 {
585 uint32_t flags = PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_WRITE |
586 PAN_BO_ACCESS_VERTEX_TILER |
587 PAN_BO_ACCESS_FRAGMENT;
588
589 for (unsigned i = 0; i < batch->key.nr_cbufs; ++i) {
590 struct panfrost_resource *rsrc = pan_resource(batch->key.cbufs[i]->texture);
591 panfrost_batch_add_bo(batch, rsrc->bo, flags);
592 }
593
594 if (batch->key.zsbuf) {
595 struct panfrost_resource *rsrc = pan_resource(batch->key.zsbuf->texture);
596 panfrost_batch_add_bo(batch, rsrc->bo, flags);
597 }
598 }
599
600 struct panfrost_bo *
601 panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
602 uint32_t create_flags, uint32_t access_flags)
603 {
604 struct panfrost_bo *bo;
605
606 bo = panfrost_bo_create(pan_screen(batch->ctx->base.screen), size,
607 create_flags);
608 panfrost_batch_add_bo(batch, bo, access_flags);
609
610 /* panfrost_batch_add_bo() has retained a reference and
611 * panfrost_bo_create() initialize the refcnt to 1, so let's
612 * unreference the BO here so it gets released when the batch is
613 * destroyed (unless it's retained by someone else in the meantime).
614 */
615 panfrost_bo_unreference(bo);
616 return bo;
617 }
618
619 /* Returns the polygon list's GPU address if available, or otherwise allocates
620 * the polygon list. It's perfectly fast to use allocate/free BO directly,
621 * since we'll hit the BO cache and this is one-per-batch anyway. */
622
623 mali_ptr
624 panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size)
625 {
626 if (batch->polygon_list) {
627 assert(batch->polygon_list->size >= size);
628 } else {
629 /* Create the BO as invisible, as there's no reason to map */
630 size = util_next_power_of_two(size);
631
632 batch->polygon_list = panfrost_batch_create_bo(batch, size,
633 PAN_BO_INVISIBLE,
634 PAN_BO_ACCESS_PRIVATE |
635 PAN_BO_ACCESS_RW |
636 PAN_BO_ACCESS_VERTEX_TILER |
637 PAN_BO_ACCESS_FRAGMENT);
638 }
639
640 return batch->polygon_list->gpu;
641 }
642
643 struct panfrost_bo *
644 panfrost_batch_get_scratchpad(struct panfrost_batch *batch,
645 unsigned shift,
646 unsigned thread_tls_alloc,
647 unsigned core_count)
648 {
649 unsigned size = panfrost_get_total_stack_size(shift,
650 thread_tls_alloc,
651 core_count);
652
653 if (batch->scratchpad) {
654 assert(batch->scratchpad->size >= size);
655 } else {
656 batch->scratchpad = panfrost_batch_create_bo(batch, size,
657 PAN_BO_INVISIBLE,
658 PAN_BO_ACCESS_PRIVATE |
659 PAN_BO_ACCESS_RW |
660 PAN_BO_ACCESS_VERTEX_TILER |
661 PAN_BO_ACCESS_FRAGMENT);
662 }
663
664 return batch->scratchpad;
665 }
666
667 struct panfrost_bo *
668 panfrost_batch_get_shared_memory(struct panfrost_batch *batch,
669 unsigned size,
670 unsigned workgroup_count)
671 {
672 if (batch->shared_memory) {
673 assert(batch->shared_memory->size >= size);
674 } else {
675 batch->shared_memory = panfrost_batch_create_bo(batch, size,
676 PAN_BO_INVISIBLE,
677 PAN_BO_ACCESS_PRIVATE |
678 PAN_BO_ACCESS_RW |
679 PAN_BO_ACCESS_VERTEX_TILER);
680 }
681
682 return batch->shared_memory;
683 }
684
685 struct panfrost_bo *
686 panfrost_batch_get_tiler_heap(struct panfrost_batch *batch)
687 {
688 if (batch->tiler_heap)
689 return batch->tiler_heap;
690
691 batch->tiler_heap = panfrost_batch_create_bo(batch, 4096 * 4096,
692 PAN_BO_INVISIBLE |
693 PAN_BO_GROWABLE,
694 PAN_BO_ACCESS_PRIVATE |
695 PAN_BO_ACCESS_RW |
696 PAN_BO_ACCESS_VERTEX_TILER |
697 PAN_BO_ACCESS_FRAGMENT);
698 assert(batch->tiler_heap);
699 return batch->tiler_heap;
700 }
701
702 struct panfrost_bo *
703 panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch)
704 {
705 struct panfrost_screen *screen = pan_screen(batch->ctx->base.screen);
706
707 uint32_t create_flags = 0;
708
709 if (batch->tiler_dummy)
710 return batch->tiler_dummy;
711
712 if (!(screen->quirks & MIDGARD_NO_HIER_TILING))
713 create_flags = PAN_BO_INVISIBLE;
714
715 batch->tiler_dummy = panfrost_batch_create_bo(batch, 4096,
716 create_flags,
717 PAN_BO_ACCESS_PRIVATE |
718 PAN_BO_ACCESS_RW |
719 PAN_BO_ACCESS_VERTEX_TILER |
720 PAN_BO_ACCESS_FRAGMENT);
721 assert(batch->tiler_dummy);
722 return batch->tiler_dummy;
723 }
724
725 static void
726 panfrost_batch_draw_wallpaper(struct panfrost_batch *batch)
727 {
728 /* Color 0 is cleared, no need to draw the wallpaper.
729 * TODO: MRT wallpapers.
730 */
731 if (batch->clear & PIPE_CLEAR_COLOR0)
732 return;
733
734 /* Nothing to reload? TODO: MRT wallpapers */
735 if (batch->key.cbufs[0] == NULL)
736 return;
737
738 /* No draw calls, and no clear on the depth/stencil bufs.
739 * Drawing the wallpaper would be useless.
740 */
741 if (!batch->tiler_dep &&
742 !(batch->clear & PIPE_CLEAR_DEPTHSTENCIL))
743 return;
744
745 /* Check if the buffer has any content on it worth preserving */
746
747 struct pipe_surface *surf = batch->key.cbufs[0];
748 struct panfrost_resource *rsrc = pan_resource(surf->texture);
749 unsigned level = surf->u.tex.level;
750
751 if (!rsrc->slices[level].initialized)
752 return;
753
754 batch->ctx->wallpaper_batch = batch;
755
756 /* Clamp the rendering area to the damage extent. The
757 * KHR_partial_update() spec states that trying to render outside of
758 * the damage region is "undefined behavior", so we should be safe.
759 */
760 unsigned damage_width = (rsrc->damage.extent.maxx - rsrc->damage.extent.minx);
761 unsigned damage_height = (rsrc->damage.extent.maxy - rsrc->damage.extent.miny);
762
763 if (damage_width && damage_height) {
764 panfrost_batch_intersection_scissor(batch,
765 rsrc->damage.extent.minx,
766 rsrc->damage.extent.miny,
767 rsrc->damage.extent.maxx,
768 rsrc->damage.extent.maxy);
769 }
770
771 /* FIXME: Looks like aligning on a tile is not enough, but
772 * aligning on twice the tile size seems to works. We don't
773 * know exactly what happens here but this deserves extra
774 * investigation to figure it out.
775 */
776 batch->minx = batch->minx & ~((MALI_TILE_LENGTH * 2) - 1);
777 batch->miny = batch->miny & ~((MALI_TILE_LENGTH * 2) - 1);
778 batch->maxx = MIN2(ALIGN_POT(batch->maxx, MALI_TILE_LENGTH * 2),
779 rsrc->base.width0);
780 batch->maxy = MIN2(ALIGN_POT(batch->maxy, MALI_TILE_LENGTH * 2),
781 rsrc->base.height0);
782
783 struct pipe_scissor_state damage;
784 struct pipe_box rects[4];
785
786 /* Clamp the damage box to the rendering area. */
787 damage.minx = MAX2(batch->minx, rsrc->damage.biggest_rect.x);
788 damage.miny = MAX2(batch->miny, rsrc->damage.biggest_rect.y);
789 damage.maxx = MIN2(batch->maxx,
790 rsrc->damage.biggest_rect.x +
791 rsrc->damage.biggest_rect.width);
792 damage.maxx = MAX2(damage.maxx, damage.minx);
793 damage.maxy = MIN2(batch->maxy,
794 rsrc->damage.biggest_rect.y +
795 rsrc->damage.biggest_rect.height);
796 damage.maxy = MAX2(damage.maxy, damage.miny);
797
798 /* One damage rectangle means we can end up with at most 4 reload
799 * regions:
800 * 1: left region, only exists if damage.x > 0
801 * 2: right region, only exists if damage.x + damage.width < fb->width
802 * 3: top region, only exists if damage.y > 0. The intersection with
803 * the left and right regions are dropped
804 * 4: bottom region, only exists if damage.y + damage.height < fb->height.
805 * The intersection with the left and right regions are dropped
806 *
807 * ____________________________
808 * | | 3 | |
809 * | |___________| |
810 * | | damage | |
811 * | 1 | rect | 2 |
812 * | |___________| |
813 * | | 4 | |
814 * |_______|___________|______|
815 */
816 u_box_2d(batch->minx, batch->miny, damage.minx - batch->minx,
817 batch->maxy - batch->miny, &rects[0]);
818 u_box_2d(damage.maxx, batch->miny, batch->maxx - damage.maxx,
819 batch->maxy - batch->miny, &rects[1]);
820 u_box_2d(damage.minx, batch->miny, damage.maxx - damage.minx,
821 damage.miny - batch->miny, &rects[2]);
822 u_box_2d(damage.minx, damage.maxy, damage.maxx - damage.minx,
823 batch->maxy - damage.maxy, &rects[3]);
824
825 for (unsigned i = 0; i < 4; i++) {
826 /* Width and height are always >= 0 even if width is declared as a
827 * signed integer: u_box_2d() helper takes unsigned args and
828 * panfrost_set_damage_region() is taking care of clamping
829 * negative values.
830 */
831 if (!rects[i].width || !rects[i].height)
832 continue;
833
834 /* Blit the wallpaper in */
835 panfrost_blit_wallpaper(batch->ctx, &rects[i]);
836 }
837 batch->ctx->wallpaper_batch = NULL;
838 }
839
840 static int
841 panfrost_batch_submit_ioctl(struct panfrost_batch *batch,
842 mali_ptr first_job_desc,
843 uint32_t reqs)
844 {
845 struct panfrost_context *ctx = batch->ctx;
846 struct pipe_context *gallium = (struct pipe_context *) ctx;
847 struct panfrost_screen *screen = pan_screen(gallium->screen);
848 struct drm_panfrost_submit submit = {0,};
849 uint32_t *bo_handles, *in_syncs = NULL;
850 bool is_fragment_shader;
851 int ret;
852
853 is_fragment_shader = (reqs & PANFROST_JD_REQ_FS) && batch->first_job;
854 if (is_fragment_shader)
855 submit.in_sync_count = 1;
856 else
857 submit.in_sync_count = util_dynarray_num_elements(&batch->dependencies,
858 struct panfrost_batch_fence *);
859
860 if (submit.in_sync_count) {
861 in_syncs = calloc(submit.in_sync_count, sizeof(*in_syncs));
862 assert(in_syncs);
863 }
864
865 /* The fragment job always depends on the vertex/tiler job if there's
866 * one
867 */
868 if (is_fragment_shader) {
869 in_syncs[0] = batch->out_sync->syncobj;
870 } else {
871 unsigned int i = 0;
872
873 util_dynarray_foreach(&batch->dependencies,
874 struct panfrost_batch_fence *, dep)
875 in_syncs[i++] = (*dep)->syncobj;
876 }
877
878 submit.in_syncs = (uintptr_t)in_syncs;
879 submit.out_sync = batch->out_sync->syncobj;
880 submit.jc = first_job_desc;
881 submit.requirements = reqs;
882
883 bo_handles = calloc(batch->bos->entries, sizeof(*bo_handles));
884 assert(bo_handles);
885
886 hash_table_foreach(batch->bos, entry) {
887 struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
888 uint32_t flags = (uintptr_t)entry->data;
889
890 assert(bo->gem_handle > 0);
891 bo_handles[submit.bo_handle_count++] = bo->gem_handle;
892
893 /* Update the BO access flags so that panfrost_bo_wait() knows
894 * about all pending accesses.
895 * We only keep the READ/WRITE info since this is all the BO
896 * wait logic cares about.
897 * We also preserve existing flags as this batch might not
898 * be the first one to access the BO.
899 */
900 bo->gpu_access |= flags & (PAN_BO_ACCESS_RW);
901 }
902
903 submit.bo_handles = (u64) (uintptr_t) bo_handles;
904 ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_SUBMIT, &submit);
905 free(bo_handles);
906 free(in_syncs);
907
908 if (ret) {
909 DBG("Error submitting: %m\n");
910 return errno;
911 }
912
913 /* Trace the job if we're doing that */
914 if (pan_debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) {
915 /* Wait so we can get errors reported back */
916 drmSyncobjWait(screen->fd, &batch->out_sync->syncobj, 1,
917 INT64_MAX, 0, NULL);
918
919 /* Trace gets priority over sync */
920 bool minimal = !(pan_debug & PAN_DBG_TRACE);
921 pandecode_jc(submit.jc, FALSE, screen->gpu_id, minimal);
922 }
923
924 return 0;
925 }
926
927 static int
928 panfrost_batch_submit_jobs(struct panfrost_batch *batch)
929 {
930 bool has_draws = batch->first_job;
931 int ret = 0;
932
933 if (has_draws) {
934 ret = panfrost_batch_submit_ioctl(batch, batch->first_job, 0);
935 assert(!ret);
936 }
937
938 if (batch->tiler_dep || batch->clear) {
939 mali_ptr fragjob = panfrost_fragment_job(batch, has_draws);
940 ret = panfrost_batch_submit_ioctl(batch, fragjob, PANFROST_JD_REQ_FS);
941 assert(!ret);
942 }
943
944 return ret;
945 }
946
947 static void
948 panfrost_batch_submit(struct panfrost_batch *batch)
949 {
950 assert(batch);
951
952 /* Submit the dependencies first. */
953 util_dynarray_foreach(&batch->dependencies,
954 struct panfrost_batch_fence *, dep) {
955 if ((*dep)->batch)
956 panfrost_batch_submit((*dep)->batch);
957 }
958
959 int ret;
960
961 /* Nothing to do! */
962 if (!batch->first_job && !batch->clear) {
963 /* Mark the fence as signaled so the fence logic does not try
964 * to wait on it.
965 */
966 batch->out_sync->signaled = true;
967 goto out;
968 }
969
970 panfrost_batch_draw_wallpaper(batch);
971
972 /* Now that all draws are in, we can finally prepare the
973 * FBD for the batch */
974
975 if (batch->framebuffer.gpu && batch->first_job) {
976 struct panfrost_context *ctx = batch->ctx;
977 struct pipe_context *gallium = (struct pipe_context *) ctx;
978 struct panfrost_screen *screen = pan_screen(gallium->screen);
979
980 if (screen->quirks & MIDGARD_SFBD)
981 panfrost_attach_sfbd(batch, ~0);
982 else
983 panfrost_attach_mfbd(batch, ~0);
984 }
985
986 panfrost_scoreboard_initialize_tiler(batch);
987
988 ret = panfrost_batch_submit_jobs(batch);
989
990 if (ret)
991 DBG("panfrost_batch_submit failed: %d\n", ret);
992
993 /* We must reset the damage info of our render targets here even
994 * though a damage reset normally happens when the DRI layer swaps
995 * buffers. That's because there can be implicit flushes the GL
996 * app is not aware of, and those might impact the damage region: if
997 * part of the damaged portion is drawn during those implicit flushes,
998 * you have to reload those areas before next draws are pushed, and
999 * since the driver can't easily know what's been modified by the draws
1000 * it flushed, the easiest solution is to reload everything.
1001 */
1002 for (unsigned i = 0; i < batch->key.nr_cbufs; i++) {
1003 struct panfrost_resource *res;
1004
1005 if (!batch->key.cbufs[i])
1006 continue;
1007
1008 res = pan_resource(batch->key.cbufs[i]->texture);
1009 panfrost_resource_reset_damage(res);
1010 }
1011
1012 out:
1013 panfrost_freeze_batch(batch);
1014 panfrost_free_batch(batch);
1015 }
1016
1017 void
1018 panfrost_flush_all_batches(struct panfrost_context *ctx, bool wait)
1019 {
1020 struct util_dynarray fences, syncobjs;
1021
1022 if (wait) {
1023 util_dynarray_init(&fences, NULL);
1024 util_dynarray_init(&syncobjs, NULL);
1025 }
1026
1027 hash_table_foreach(ctx->batches, hentry) {
1028 struct panfrost_batch *batch = hentry->data;
1029
1030 assert(batch);
1031
1032 if (wait) {
1033 panfrost_batch_fence_reference(batch->out_sync);
1034 util_dynarray_append(&fences, struct panfrost_batch_fence *,
1035 batch->out_sync);
1036 util_dynarray_append(&syncobjs, uint32_t,
1037 batch->out_sync->syncobj);
1038 }
1039
1040 panfrost_batch_submit(batch);
1041 }
1042
1043 assert(!ctx->batches->entries);
1044
1045 /* Collect batch fences before returning */
1046 panfrost_gc_fences(ctx);
1047
1048 if (!wait)
1049 return;
1050
1051 drmSyncobjWait(pan_screen(ctx->base.screen)->fd,
1052 util_dynarray_begin(&syncobjs),
1053 util_dynarray_num_elements(&syncobjs, uint32_t),
1054 INT64_MAX, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, NULL);
1055
1056 util_dynarray_foreach(&fences, struct panfrost_batch_fence *, fence)
1057 panfrost_batch_fence_unreference(*fence);
1058
1059 util_dynarray_fini(&fences);
1060 util_dynarray_fini(&syncobjs);
1061 }
1062
1063 bool
1064 panfrost_pending_batches_access_bo(struct panfrost_context *ctx,
1065 const struct panfrost_bo *bo)
1066 {
1067 struct panfrost_bo_access *access;
1068 struct hash_entry *hentry;
1069
1070 hentry = _mesa_hash_table_search(ctx->accessed_bos, bo);
1071 access = hentry ? hentry->data : NULL;
1072 if (!access)
1073 return false;
1074
1075 if (access->writer && access->writer->batch)
1076 return true;
1077
1078 util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,
1079 reader) {
1080 if (*reader && (*reader)->batch)
1081 return true;
1082 }
1083
1084 return false;
1085 }
1086
1087 void
1088 panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
1089 struct panfrost_bo *bo,
1090 uint32_t access_type)
1091 {
1092 struct panfrost_bo_access *access;
1093 struct hash_entry *hentry;
1094
1095 /* It doesn't make any to flush only the readers. */
1096 assert(access_type == PAN_BO_ACCESS_WRITE ||
1097 access_type == PAN_BO_ACCESS_RW);
1098
1099 hentry = _mesa_hash_table_search(ctx->accessed_bos, bo);
1100 access = hentry ? hentry->data : NULL;
1101 if (!access)
1102 return;
1103
1104 if (access_type & PAN_BO_ACCESS_WRITE && access->writer &&
1105 access->writer->batch)
1106 panfrost_batch_submit(access->writer->batch);
1107
1108 if (!(access_type & PAN_BO_ACCESS_READ))
1109 return;
1110
1111 util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *,
1112 reader) {
1113 if (*reader && (*reader)->batch)
1114 panfrost_batch_submit((*reader)->batch);
1115 }
1116 }
1117
1118 void
1119 panfrost_batch_set_requirements(struct panfrost_batch *batch)
1120 {
1121 struct panfrost_context *ctx = batch->ctx;
1122
1123 if (ctx->rasterizer && ctx->rasterizer->base.multisample)
1124 batch->requirements |= PAN_REQ_MSAA;
1125
1126 if (ctx->depth_stencil && ctx->depth_stencil->depth.writemask)
1127 batch->requirements |= PAN_REQ_DEPTH_WRITE;
1128 }
1129
1130 void
1131 panfrost_batch_adjust_stack_size(struct panfrost_batch *batch)
1132 {
1133 struct panfrost_context *ctx = batch->ctx;
1134
1135 for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) {
1136 struct panfrost_shader_state *ss;
1137
1138 ss = panfrost_get_shader_state(ctx, i);
1139 if (!ss)
1140 continue;
1141
1142 batch->stack_size = MAX2(batch->stack_size, ss->stack_size);
1143 }
1144 }
1145
1146 /* Helper to smear a 32-bit color across 128-bit components */
1147
1148 static void
1149 pan_pack_color_32(uint32_t *packed, uint32_t v)
1150 {
1151 for (unsigned i = 0; i < 4; ++i)
1152 packed[i] = v;
1153 }
1154
1155 static void
1156 pan_pack_color_64(uint32_t *packed, uint32_t lo, uint32_t hi)
1157 {
1158 for (unsigned i = 0; i < 4; i += 2) {
1159 packed[i + 0] = lo;
1160 packed[i + 1] = hi;
1161 }
1162 }
1163
1164 static void
1165 pan_pack_color(uint32_t *packed, const union pipe_color_union *color, enum pipe_format format)
1166 {
1167 /* Alpha magicked to 1.0 if there is no alpha */
1168
1169 bool has_alpha = util_format_has_alpha(format);
1170 float clear_alpha = has_alpha ? color->f[3] : 1.0f;
1171
1172 /* Packed color depends on the framebuffer format */
1173
1174 const struct util_format_description *desc =
1175 util_format_description(format);
1176
1177 if (util_format_is_rgba8_variant(desc)) {
1178 pan_pack_color_32(packed,
1179 ((uint32_t) float_to_ubyte(clear_alpha) << 24) |
1180 ((uint32_t) float_to_ubyte(color->f[2]) << 16) |
1181 ((uint32_t) float_to_ubyte(color->f[1]) << 8) |
1182 ((uint32_t) float_to_ubyte(color->f[0]) << 0));
1183 } else if (format == PIPE_FORMAT_B5G6R5_UNORM) {
1184 /* First, we convert the components to R5, G6, B5 separately */
1185 unsigned r5 = CLAMP(color->f[0], 0.0, 1.0) * 31.0;
1186 unsigned g6 = CLAMP(color->f[1], 0.0, 1.0) * 63.0;
1187 unsigned b5 = CLAMP(color->f[2], 0.0, 1.0) * 31.0;
1188
1189 /* Then we pack into a sparse u32. TODO: Why these shifts? */
1190 pan_pack_color_32(packed, (b5 << 25) | (g6 << 14) | (r5 << 5));
1191 } else if (format == PIPE_FORMAT_B4G4R4A4_UNORM) {
1192 /* We scale the components against 0xF0 (=240.0), rather than 0xFF */
1193 unsigned r4 = CLAMP(color->f[0], 0.0, 1.0) * 240.0;
1194 unsigned g4 = CLAMP(color->f[1], 0.0, 1.0) * 240.0;
1195 unsigned b4 = CLAMP(color->f[2], 0.0, 1.0) * 240.0;
1196 unsigned a4 = CLAMP(clear_alpha, 0.0, 1.0) * 240.0;
1197
1198 /* Pack on *byte* intervals */
1199 pan_pack_color_32(packed, (a4 << 24) | (b4 << 16) | (g4 << 8) | r4);
1200 } else if (format == PIPE_FORMAT_B5G5R5A1_UNORM) {
1201 /* Scale as expected but shift oddly */
1202 unsigned r5 = round(CLAMP(color->f[0], 0.0, 1.0)) * 31.0;
1203 unsigned g5 = round(CLAMP(color->f[1], 0.0, 1.0)) * 31.0;
1204 unsigned b5 = round(CLAMP(color->f[2], 0.0, 1.0)) * 31.0;
1205 unsigned a1 = round(CLAMP(clear_alpha, 0.0, 1.0)) * 1.0;
1206
1207 pan_pack_color_32(packed, (a1 << 31) | (b5 << 25) | (g5 << 15) | (r5 << 5));
1208 } else {
1209 /* Try Gallium's generic default path. Doesn't work for all
1210 * formats but it's a good guess. */
1211
1212 union util_color out;
1213
1214 if (util_format_is_pure_integer(format)) {
1215 memcpy(out.ui, color->ui, 16);
1216 } else {
1217 util_pack_color(color->f, format, &out);
1218 }
1219
1220 unsigned size = util_format_get_blocksize(format);
1221
1222 if (size == 1) {
1223 unsigned b = out.ui[0];
1224 unsigned s = b | (b << 8);
1225 pan_pack_color_32(packed, s | (s << 16));
1226 } else if (size == 2)
1227 pan_pack_color_32(packed, out.ui[0] | (out.ui[0] << 16));
1228 else if (size == 3 || size == 4)
1229 pan_pack_color_32(packed, out.ui[0]);
1230 else if (size == 6)
1231 pan_pack_color_64(packed, out.ui[0], out.ui[1] | (out.ui[1] << 16)); /* RGB16F -- RGBB */
1232 else if (size == 8)
1233 pan_pack_color_64(packed, out.ui[0], out.ui[1]);
1234 else if (size == 16)
1235 memcpy(packed, out.ui, 16);
1236 else
1237 unreachable("Unknown generic format size packing clear colour");
1238 }
1239 }
1240
1241 void
1242 panfrost_batch_clear(struct panfrost_batch *batch,
1243 unsigned buffers,
1244 const union pipe_color_union *color,
1245 double depth, unsigned stencil)
1246 {
1247 struct panfrost_context *ctx = batch->ctx;
1248
1249 if (buffers & PIPE_CLEAR_COLOR) {
1250 for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
1251 if (!(buffers & (PIPE_CLEAR_COLOR0 << i)))
1252 continue;
1253
1254 enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format;
1255 pan_pack_color(batch->clear_color[i], color, format);
1256 }
1257 }
1258
1259 if (buffers & PIPE_CLEAR_DEPTH) {
1260 batch->clear_depth = depth;
1261 }
1262
1263 if (buffers & PIPE_CLEAR_STENCIL) {
1264 batch->clear_stencil = stencil;
1265 }
1266
1267 batch->clear |= buffers;
1268
1269 /* Clearing affects the entire framebuffer (by definition -- this is
1270 * the Gallium clear callback, which clears the whole framebuffer. If
1271 * the scissor test were enabled from the GL side, the state tracker
1272 * would emit a quad instead and we wouldn't go down this code path) */
1273
1274 panfrost_batch_union_scissor(batch, 0, 0,
1275 ctx->pipe_framebuffer.width,
1276 ctx->pipe_framebuffer.height);
1277 }
1278
1279 static bool
1280 panfrost_batch_compare(const void *a, const void *b)
1281 {
1282 return util_framebuffer_state_equal(a, b);
1283 }
1284
1285 static uint32_t
1286 panfrost_batch_hash(const void *key)
1287 {
1288 return _mesa_hash_data(key, sizeof(struct pipe_framebuffer_state));
1289 }
1290
1291 /* Given a new bounding rectangle (scissor), let the job cover the union of the
1292 * new and old bounding rectangles */
1293
1294 void
1295 panfrost_batch_union_scissor(struct panfrost_batch *batch,
1296 unsigned minx, unsigned miny,
1297 unsigned maxx, unsigned maxy)
1298 {
1299 batch->minx = MIN2(batch->minx, minx);
1300 batch->miny = MIN2(batch->miny, miny);
1301 batch->maxx = MAX2(batch->maxx, maxx);
1302 batch->maxy = MAX2(batch->maxy, maxy);
1303 }
1304
1305 void
1306 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
1307 unsigned minx, unsigned miny,
1308 unsigned maxx, unsigned maxy)
1309 {
1310 batch->minx = MAX2(batch->minx, minx);
1311 batch->miny = MAX2(batch->miny, miny);
1312 batch->maxx = MIN2(batch->maxx, maxx);
1313 batch->maxy = MIN2(batch->maxy, maxy);
1314 }
1315
1316 /* Are we currently rendering to the screen (rather than an FBO)? */
1317
1318 bool
1319 panfrost_batch_is_scanout(struct panfrost_batch *batch)
1320 {
1321 /* If there is no color buffer, it's an FBO */
1322 if (batch->key.nr_cbufs != 1)
1323 return false;
1324
1325 /* If we're too early that no framebuffer was sent, it's scanout */
1326 if (!batch->key.cbufs[0])
1327 return true;
1328
1329 return batch->key.cbufs[0]->texture->bind & PIPE_BIND_DISPLAY_TARGET ||
1330 batch->key.cbufs[0]->texture->bind & PIPE_BIND_SCANOUT ||
1331 batch->key.cbufs[0]->texture->bind & PIPE_BIND_SHARED;
1332 }
1333
1334 void
1335 panfrost_batch_init(struct panfrost_context *ctx)
1336 {
1337 ctx->batches = _mesa_hash_table_create(ctx,
1338 panfrost_batch_hash,
1339 panfrost_batch_compare);
1340 ctx->accessed_bos = _mesa_hash_table_create(ctx, _mesa_hash_pointer,
1341 _mesa_key_pointer_equal);
1342 }