2 * Copyright (C) 2019 Alyssa Rosenzweig
3 * Copyright (C) 2014-2017 Broadcom
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:
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
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
28 #include "drm-uapi/panfrost_drm.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 "util/rounding.h"
38 #include "pan_blending.h"
39 #include "pandecode/decode.h"
40 #include "panfrost-quirks.h"
42 /* panfrost_bo_access is here to help us keep track of batch accesses to BOs
43 * and build a proper dependency graph such that batches can be pipelined for
44 * better GPU utilization.
46 * Each accessed BO has a corresponding entry in the ->accessed_bos hash table.
47 * A BO is either being written or read at any time (see if writer != NULL).
48 * When the last access is a write, the batch writing the BO might have read
49 * dependencies (readers that have not been executed yet and want to read the
50 * previous BO content), and when the last access is a read, all readers might
51 * depend on another batch to push its results to memory. That's what the
52 * readers/writers keep track off.
53 * There can only be one writer at any given time, if a new batch wants to
54 * write to the same BO, a dependency will be added between the new writer and
55 * the old writer (at the batch level), and panfrost_bo_access->writer will be
56 * updated to point to the new writer.
58 struct panfrost_bo_access
{
59 struct util_dynarray readers
;
60 struct panfrost_batch_fence
*writer
;
63 static struct panfrost_batch_fence
*
64 panfrost_create_batch_fence(struct panfrost_batch
*batch
)
66 struct panfrost_batch_fence
*fence
;
68 fence
= rzalloc(NULL
, struct panfrost_batch_fence
);
70 pipe_reference_init(&fence
->reference
, 1);
71 fence
->ctx
= batch
->ctx
;
78 panfrost_free_batch_fence(struct panfrost_batch_fence
*fence
)
84 panfrost_batch_fence_unreference(struct panfrost_batch_fence
*fence
)
86 if (pipe_reference(&fence
->reference
, NULL
))
87 panfrost_free_batch_fence(fence
);
91 panfrost_batch_fence_reference(struct panfrost_batch_fence
*fence
)
93 pipe_reference(NULL
, &fence
->reference
);
96 static struct panfrost_batch
*
97 panfrost_create_batch(struct panfrost_context
*ctx
,
98 const struct pipe_framebuffer_state
*key
)
100 struct panfrost_batch
*batch
= rzalloc(ctx
, struct panfrost_batch
);
104 batch
->bos
= _mesa_hash_table_create(batch
, _mesa_hash_pointer
,
105 _mesa_key_pointer_equal
);
107 batch
->minx
= batch
->miny
= ~0;
108 batch
->maxx
= batch
->maxy
= 0;
110 batch
->out_sync
= panfrost_create_batch_fence(batch
);
111 util_copy_framebuffer_state(&batch
->key
, key
);
113 batch
->pool
= panfrost_create_pool(batch
, pan_device(ctx
->base
.screen
));
119 panfrost_freeze_batch(struct panfrost_batch
*batch
)
121 struct panfrost_context
*ctx
= batch
->ctx
;
122 struct hash_entry
*entry
;
124 /* Remove the entry in the FBO -> batch hash table if the batch
125 * matches. This way, next draws/clears targeting this FBO will trigger
126 * the creation of a new batch.
128 entry
= _mesa_hash_table_search(ctx
->batches
, &batch
->key
);
129 if (entry
&& entry
->data
== batch
)
130 _mesa_hash_table_remove(ctx
->batches
, entry
);
132 /* If this is the bound batch, the panfrost_context parameters are
133 * relevant so submitting it invalidates those parameters, but if it's
134 * not bound, the context parameters are for some other batch so we
135 * can't invalidate them.
137 if (ctx
->batch
== batch
) {
138 panfrost_invalidate_frame(ctx
);
143 #ifdef PAN_BATCH_DEBUG
144 static bool panfrost_batch_is_frozen(struct panfrost_batch
*batch
)
146 struct panfrost_context
*ctx
= batch
->ctx
;
147 struct hash_entry
*entry
;
149 entry
= _mesa_hash_table_search(ctx
->batches
, &batch
->key
);
150 if (entry
&& entry
->data
== batch
)
153 if (ctx
->batch
== batch
)
161 panfrost_free_batch(struct panfrost_batch
*batch
)
166 #ifdef PAN_BATCH_DEBUG
167 assert(panfrost_batch_is_frozen(batch
));
170 hash_table_foreach(batch
->bos
, entry
)
171 panfrost_bo_unreference((struct panfrost_bo
*)entry
->key
);
173 hash_table_foreach(batch
->pool
.bos
, entry
)
174 panfrost_bo_unreference((struct panfrost_bo
*)entry
->key
);
176 util_dynarray_foreach(&batch
->dependencies
,
177 struct panfrost_batch_fence
*, dep
) {
178 panfrost_batch_fence_unreference(*dep
);
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'.
187 batch
->out_sync
->batch
= NULL
;
188 panfrost_batch_fence_unreference(batch
->out_sync
);
190 util_unreference_framebuffer_state(&batch
->key
);
194 #ifdef PAN_BATCH_DEBUG
196 panfrost_dep_graph_contains_batch(struct panfrost_batch
*root
,
197 struct panfrost_batch
*batch
)
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
))
214 panfrost_batch_add_dep(struct panfrost_batch
*batch
,
215 struct panfrost_batch_fence
*newdep
)
217 if (batch
== newdep
->batch
)
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.
224 util_dynarray_foreach(&batch
->dependencies
,
225 struct panfrost_batch_fence
*, dep
) {
230 #ifdef PAN_BATCH_DEBUG
231 /* Make sure the dependency graph is acyclic. */
232 assert(!panfrost_dep_graph_contains_batch(newdep
->batch
, batch
));
235 panfrost_batch_fence_reference(newdep
);
236 util_dynarray_append(&batch
->dependencies
,
237 struct panfrost_batch_fence
*, newdep
);
239 /* We now have a batch depending on us, let's make sure new draw/clear
240 * calls targeting the same FBO use a new batch object.
243 panfrost_freeze_batch(newdep
->batch
);
246 static struct panfrost_batch
*
247 panfrost_get_batch(struct panfrost_context
*ctx
,
248 const struct pipe_framebuffer_state
*key
)
250 /* Lookup the job first */
251 struct hash_entry
*entry
= _mesa_hash_table_search(ctx
->batches
, key
);
256 /* Otherwise, let's create a job */
258 struct panfrost_batch
*batch
= panfrost_create_batch(ctx
, key
);
260 /* Save the created job */
261 _mesa_hash_table_insert(ctx
->batches
, &batch
->key
, batch
);
266 /* Get the job corresponding to the FBO we're currently rendering into */
268 struct panfrost_batch
*
269 panfrost_get_batch_for_fbo(struct panfrost_context
*ctx
)
271 /* If we're wallpapering, we special case to workaround
274 if (ctx
->wallpaper_batch
)
275 return ctx
->wallpaper_batch
;
277 /* If we already began rendering, use that */
280 assert(util_framebuffer_state_equal(&ctx
->batch
->key
,
281 &ctx
->pipe_framebuffer
));
285 /* If not, look up the job */
286 struct panfrost_batch
*batch
= panfrost_get_batch(ctx
,
287 &ctx
->pipe_framebuffer
);
289 /* Set this job as the current FBO job. Will be reset when updating the
290 * FB state and when submitting or releasing a job.
296 struct panfrost_batch
*
297 panfrost_get_fresh_batch_for_fbo(struct panfrost_context
*ctx
)
299 struct panfrost_batch
*batch
;
301 batch
= panfrost_get_batch(ctx
, &ctx
->pipe_framebuffer
);
303 /* The batch has no draw/clear queued, let's return it directly.
304 * Note that it's perfectly fine to re-use a batch with an
305 * existing clear, we'll just update it with the new clear request.
307 if (!batch
->scoreboard
.first_job
)
310 /* Otherwise, we need to freeze the existing one and instantiate a new
313 panfrost_freeze_batch(batch
);
314 return panfrost_get_batch(ctx
, &ctx
->pipe_framebuffer
);
318 panfrost_bo_access_gc_fences(struct panfrost_context
*ctx
,
319 struct panfrost_bo_access
*access
,
320 const struct panfrost_bo
*bo
)
322 if (access
->writer
) {
323 panfrost_batch_fence_unreference(access
->writer
);
324 access
->writer
= NULL
;
327 struct panfrost_batch_fence
**readers_array
= util_dynarray_begin(&access
->readers
);
328 struct panfrost_batch_fence
**new_readers
= readers_array
;
330 util_dynarray_foreach(&access
->readers
, struct panfrost_batch_fence
*,
335 panfrost_batch_fence_unreference(*reader
);
339 if (!util_dynarray_resize(&access
->readers
, struct panfrost_batch_fence
*,
340 new_readers
- readers_array
) &&
341 new_readers
!= readers_array
)
342 unreachable("Invalid dynarray access->readers");
345 /* Collect signaled fences to keep the kernel-side syncobj-map small. The
346 * idea is to collect those signaled fences at the end of each flush_all
347 * call. This function is likely to collect only fences from previous
348 * batch flushes not the one that have just have just been submitted and
349 * are probably still in flight when we trigger the garbage collection.
350 * Anyway, we need to do this garbage collection at some point if we don't
351 * want the BO access map to keep invalid entries around and retain
355 panfrost_gc_fences(struct panfrost_context
*ctx
)
357 hash_table_foreach(ctx
->accessed_bos
, entry
) {
358 struct panfrost_bo_access
*access
= entry
->data
;
361 panfrost_bo_access_gc_fences(ctx
, access
, entry
->key
);
362 if (!util_dynarray_num_elements(&access
->readers
,
363 struct panfrost_batch_fence
*) &&
366 _mesa_hash_table_remove(ctx
->accessed_bos
, entry
);
371 #ifdef PAN_BATCH_DEBUG
373 panfrost_batch_in_readers(struct panfrost_batch
*batch
,
374 struct panfrost_bo_access
*access
)
376 util_dynarray_foreach(&access
->readers
, struct panfrost_batch_fence
*,
378 if (*reader
&& (*reader
)->batch
== batch
)
387 panfrost_batch_update_bo_access(struct panfrost_batch
*batch
,
388 struct panfrost_bo
*bo
, bool writes
,
389 bool already_accessed
)
391 struct panfrost_context
*ctx
= batch
->ctx
;
392 struct panfrost_bo_access
*access
;
393 bool old_writes
= false;
394 struct hash_entry
*entry
;
396 entry
= _mesa_hash_table_search(ctx
->accessed_bos
, bo
);
397 access
= entry
? entry
->data
: NULL
;
399 old_writes
= access
->writer
!= NULL
;
401 access
= rzalloc(ctx
, struct panfrost_bo_access
);
402 util_dynarray_init(&access
->readers
, access
);
403 _mesa_hash_table_insert(ctx
->accessed_bos
, bo
, access
);
404 /* We are the first to access this BO, let's initialize
405 * old_writes to our own access type in that case.
412 if (writes
&& !old_writes
) {
413 /* Previous access was a read and we want to write this BO.
414 * We first need to add explicit deps between our batch and
415 * the previous readers.
417 util_dynarray_foreach(&access
->readers
,
418 struct panfrost_batch_fence
*, reader
) {
419 /* We were already reading the BO, no need to add a dep
420 * on ourself (the acyclic check would complain about
423 if (!(*reader
) || (*reader
)->batch
== batch
)
426 panfrost_batch_add_dep(batch
, *reader
);
428 panfrost_batch_fence_reference(batch
->out_sync
);
431 panfrost_batch_fence_unreference(access
->writer
);
433 /* We now are the new writer. */
434 access
->writer
= batch
->out_sync
;
436 /* Release the previous readers and reset the readers array. */
437 util_dynarray_foreach(&access
->readers
,
438 struct panfrost_batch_fence
*,
442 panfrost_batch_fence_unreference(*reader
);
445 util_dynarray_clear(&access
->readers
);
446 } else if (writes
&& old_writes
) {
447 /* First check if we were the previous writer, in that case
448 * there's nothing to do. Otherwise we need to add a
449 * dependency between the new writer and the old one.
451 if (access
->writer
!= batch
->out_sync
) {
452 if (access
->writer
) {
453 panfrost_batch_add_dep(batch
, access
->writer
);
454 panfrost_batch_fence_unreference(access
->writer
);
456 panfrost_batch_fence_reference(batch
->out_sync
);
457 access
->writer
= batch
->out_sync
;
459 } else if (!writes
&& old_writes
) {
460 /* First check if we were the previous writer, in that case
461 * we want to keep the access type unchanged, as a write is
462 * more constraining than a read.
464 if (access
->writer
!= batch
->out_sync
) {
465 /* Add a dependency on the previous writer. */
466 panfrost_batch_add_dep(batch
, access
->writer
);
468 /* The previous access was a write, there's no reason
469 * to have entries in the readers array.
471 assert(!util_dynarray_num_elements(&access
->readers
,
472 struct panfrost_batch_fence
*));
474 /* Add ourselves to the readers array. */
475 panfrost_batch_fence_reference(batch
->out_sync
);
476 util_dynarray_append(&access
->readers
,
477 struct panfrost_batch_fence
*,
479 access
->writer
= NULL
;
482 /* We already accessed this BO before, so we should already be
483 * in the reader array.
485 #ifdef PAN_BATCH_DEBUG
486 if (already_accessed
) {
487 assert(panfrost_batch_in_readers(batch
, access
));
492 /* Previous access was a read and we want to read this BO.
493 * Add ourselves to the readers array and add a dependency on
494 * the previous writer if any.
496 panfrost_batch_fence_reference(batch
->out_sync
);
497 util_dynarray_append(&access
->readers
,
498 struct panfrost_batch_fence
*,
502 panfrost_batch_add_dep(batch
, access
->writer
);
507 panfrost_batch_add_bo(struct panfrost_batch
*batch
, struct panfrost_bo
*bo
,
513 struct hash_entry
*entry
;
514 uint32_t old_flags
= 0;
516 entry
= _mesa_hash_table_search(batch
->bos
, bo
);
518 entry
= _mesa_hash_table_insert(batch
->bos
, bo
,
519 (void *)(uintptr_t)flags
);
520 panfrost_bo_reference(bo
);
522 old_flags
= (uintptr_t)entry
->data
;
524 /* All batches have to agree on the shared flag. */
525 assert((old_flags
& PAN_BO_ACCESS_SHARED
) ==
526 (flags
& PAN_BO_ACCESS_SHARED
));
531 if (old_flags
== flags
)
535 entry
->data
= (void *)(uintptr_t)flags
;
537 /* If this is not a shared BO, we don't really care about dependency
540 if (!(flags
& PAN_BO_ACCESS_SHARED
))
543 /* All dependencies should have been flushed before we execute the
544 * wallpaper draw, so it should be harmless to skip the
545 * update_bo_access() call.
547 if (batch
== batch
->ctx
->wallpaper_batch
)
550 assert(flags
& PAN_BO_ACCESS_RW
);
551 panfrost_batch_update_bo_access(batch
, bo
, flags
& PAN_BO_ACCESS_WRITE
,
556 panfrost_batch_add_resource_bos(struct panfrost_batch
*batch
,
557 struct panfrost_resource
*rsrc
,
560 panfrost_batch_add_bo(batch
, rsrc
->bo
, flags
);
562 for (unsigned i
= 0; i
< MAX_MIP_LEVELS
; i
++)
563 if (rsrc
->slices
[i
].checksum_bo
)
564 panfrost_batch_add_bo(batch
, rsrc
->slices
[i
].checksum_bo
, flags
);
566 if (rsrc
->separate_stencil
)
567 panfrost_batch_add_bo(batch
, rsrc
->separate_stencil
->bo
, flags
);
570 void panfrost_batch_add_fbo_bos(struct panfrost_batch
*batch
)
572 uint32_t flags
= PAN_BO_ACCESS_SHARED
| PAN_BO_ACCESS_WRITE
|
573 PAN_BO_ACCESS_VERTEX_TILER
|
574 PAN_BO_ACCESS_FRAGMENT
;
576 for (unsigned i
= 0; i
< batch
->key
.nr_cbufs
; ++i
) {
577 struct panfrost_resource
*rsrc
= pan_resource(batch
->key
.cbufs
[i
]->texture
);
578 panfrost_batch_add_resource_bos(batch
, rsrc
, flags
);
581 if (batch
->key
.zsbuf
) {
582 struct panfrost_resource
*rsrc
= pan_resource(batch
->key
.zsbuf
->texture
);
583 panfrost_batch_add_resource_bos(batch
, rsrc
, flags
);
588 panfrost_batch_create_bo(struct panfrost_batch
*batch
, size_t size
,
589 uint32_t create_flags
, uint32_t access_flags
)
591 struct panfrost_bo
*bo
;
593 bo
= panfrost_bo_create(pan_device(batch
->ctx
->base
.screen
), size
,
595 panfrost_batch_add_bo(batch
, bo
, access_flags
);
597 /* panfrost_batch_add_bo() has retained a reference and
598 * panfrost_bo_create() initialize the refcnt to 1, so let's
599 * unreference the BO here so it gets released when the batch is
600 * destroyed (unless it's retained by someone else in the meantime).
602 panfrost_bo_unreference(bo
);
606 /* Returns the polygon list's GPU address if available, or otherwise allocates
607 * the polygon list. It's perfectly fast to use allocate/free BO directly,
608 * since we'll hit the BO cache and this is one-per-batch anyway. */
611 panfrost_batch_get_polygon_list(struct panfrost_batch
*batch
, unsigned size
)
613 if (batch
->polygon_list
) {
614 assert(batch
->polygon_list
->size
>= size
);
616 /* Create the BO as invisible, as there's no reason to map */
617 size
= util_next_power_of_two(size
);
619 batch
->polygon_list
= panfrost_batch_create_bo(batch
, size
,
621 PAN_BO_ACCESS_PRIVATE
|
623 PAN_BO_ACCESS_VERTEX_TILER
|
624 PAN_BO_ACCESS_FRAGMENT
);
627 return batch
->polygon_list
->gpu
;
631 panfrost_batch_get_scratchpad(struct panfrost_batch
*batch
,
633 unsigned thread_tls_alloc
,
636 unsigned size
= panfrost_get_total_stack_size(shift
,
640 if (batch
->scratchpad
) {
641 assert(batch
->scratchpad
->size
>= size
);
643 batch
->scratchpad
= panfrost_batch_create_bo(batch
, size
,
645 PAN_BO_ACCESS_PRIVATE
|
647 PAN_BO_ACCESS_VERTEX_TILER
|
648 PAN_BO_ACCESS_FRAGMENT
);
651 return batch
->scratchpad
;
655 panfrost_batch_get_shared_memory(struct panfrost_batch
*batch
,
657 unsigned workgroup_count
)
659 if (batch
->shared_memory
) {
660 assert(batch
->shared_memory
->size
>= size
);
662 batch
->shared_memory
= panfrost_batch_create_bo(batch
, size
,
664 PAN_BO_ACCESS_PRIVATE
|
666 PAN_BO_ACCESS_VERTEX_TILER
);
669 return batch
->shared_memory
;
673 panfrost_batch_get_tiler_heap(struct panfrost_batch
*batch
)
675 if (batch
->tiler_heap
)
676 return batch
->tiler_heap
;
678 batch
->tiler_heap
= panfrost_batch_create_bo(batch
, 4096 * 4096,
681 PAN_BO_ACCESS_PRIVATE
|
683 PAN_BO_ACCESS_VERTEX_TILER
|
684 PAN_BO_ACCESS_FRAGMENT
);
685 assert(batch
->tiler_heap
);
686 return batch
->tiler_heap
;
690 panfrost_batch_get_tiler_meta(struct panfrost_batch
*batch
, unsigned vertex_count
)
695 if (batch
->tiler_meta
)
696 return batch
->tiler_meta
;
698 struct panfrost_bo
*tiler_heap
;
699 tiler_heap
= panfrost_batch_get_tiler_heap(batch
);
701 struct bifrost_tiler_heap_meta tiler_heap_meta
= {
702 .heap_size
= tiler_heap
->size
,
703 .tiler_heap_start
= tiler_heap
->gpu
,
704 .tiler_heap_free
= tiler_heap
->gpu
,
705 .tiler_heap_end
= tiler_heap
->gpu
+ tiler_heap
->size
,
707 .unk7e007e
= 0x7e007e,
710 struct bifrost_tiler_meta tiler_meta
= {
711 .hierarchy_mask
= 0x28,
713 .width
= MALI_POSITIVE(batch
->key
.width
),
714 .height
= MALI_POSITIVE(batch
->key
.height
),
715 .tiler_heap_meta
= panfrost_pool_upload(&batch
->pool
, &tiler_heap_meta
, sizeof(tiler_heap_meta
)),
718 batch
->tiler_meta
= panfrost_pool_upload(&batch
->pool
, &tiler_meta
, sizeof(tiler_meta
));
719 return batch
->tiler_meta
;
723 panfrost_batch_get_tiler_dummy(struct panfrost_batch
*batch
)
725 struct panfrost_device
*dev
= pan_device(batch
->ctx
->base
.screen
);
727 uint32_t create_flags
= 0;
729 if (batch
->tiler_dummy
)
730 return batch
->tiler_dummy
;
732 if (!(dev
->quirks
& MIDGARD_NO_HIER_TILING
))
733 create_flags
= PAN_BO_INVISIBLE
;
735 batch
->tiler_dummy
= panfrost_batch_create_bo(batch
, 4096,
737 PAN_BO_ACCESS_PRIVATE
|
739 PAN_BO_ACCESS_VERTEX_TILER
|
740 PAN_BO_ACCESS_FRAGMENT
);
741 assert(batch
->tiler_dummy
);
742 return batch
->tiler_dummy
;
746 panfrost_batch_reserve_framebuffer(struct panfrost_batch
*batch
)
748 struct panfrost_device
*dev
= pan_device(batch
->ctx
->base
.screen
);
750 /* If we haven't, reserve space for the framebuffer */
752 if (!batch
->framebuffer
.gpu
) {
753 unsigned size
= (dev
->quirks
& MIDGARD_SFBD
) ?
754 sizeof(struct mali_single_framebuffer
) :
755 sizeof(struct mali_framebuffer
);
757 batch
->framebuffer
= panfrost_pool_alloc(&batch
->pool
, size
);
759 /* Tag the pointer */
760 if (!(dev
->quirks
& MIDGARD_SFBD
))
761 batch
->framebuffer
.gpu
|= MALI_MFBD
;
764 return batch
->framebuffer
.gpu
;
770 panfrost_load_surface(struct panfrost_batch
*batch
, struct pipe_surface
*surf
, unsigned loc
)
775 struct panfrost_resource
*rsrc
= pan_resource(surf
->texture
);
776 unsigned level
= surf
->u
.tex
.level
;
778 if (!rsrc
->slices
[level
].initialized
)
781 if (!rsrc
->damage
.inverted_len
)
784 /* Clamp the rendering area to the damage extent. The
785 * KHR_partial_update() spec states that trying to render outside of
786 * the damage region is "undefined behavior", so we should be safe.
788 unsigned damage_width
= (rsrc
->damage
.extent
.maxx
- rsrc
->damage
.extent
.minx
);
789 unsigned damage_height
= (rsrc
->damage
.extent
.maxy
- rsrc
->damage
.extent
.miny
);
791 if (damage_width
&& damage_height
) {
792 panfrost_batch_intersection_scissor(batch
,
793 rsrc
->damage
.extent
.minx
,
794 rsrc
->damage
.extent
.miny
,
795 rsrc
->damage
.extent
.maxx
,
796 rsrc
->damage
.extent
.maxy
);
799 /* XXX: Native blits on Bifrost */
800 if (batch
->pool
.dev
->quirks
& IS_BIFROST
) {
801 if (loc
!= FRAG_RESULT_DATA0
)
804 /* XXX: why align on *twice* the tile length? */
805 batch
->minx
= batch
->minx
& ~((MALI_TILE_LENGTH
* 2) - 1);
806 batch
->miny
= batch
->miny
& ~((MALI_TILE_LENGTH
* 2) - 1);
807 batch
->maxx
= MIN2(ALIGN_POT(batch
->maxx
, MALI_TILE_LENGTH
* 2),
809 batch
->maxy
= MIN2(ALIGN_POT(batch
->maxy
, MALI_TILE_LENGTH
* 2),
812 struct pipe_box rect
;
813 batch
->ctx
->wallpaper_batch
= batch
;
814 u_box_2d(batch
->minx
, batch
->miny
, batch
->maxx
- batch
->minx
,
815 batch
->maxy
- batch
->miny
, &rect
);
816 panfrost_blit_wallpaper(batch
->ctx
, &rect
);
817 batch
->ctx
->wallpaper_batch
= NULL
;
821 enum pipe_format format
= rsrc
->base
.format
;
823 if (loc
== FRAG_RESULT_DEPTH
) {
824 if (!util_format_has_depth(util_format_description(format
)))
827 format
= util_format_get_depth_only(format
);
828 } else if (loc
== FRAG_RESULT_STENCIL
) {
829 if (!util_format_has_stencil(util_format_description(format
)))
832 if (rsrc
->separate_stencil
) {
833 rsrc
= rsrc
->separate_stencil
;
834 format
= rsrc
->base
.format
;
837 format
= util_format_stencil_only(format
);
840 enum mali_texture_type type
=
841 panfrost_translate_texture_type(rsrc
->base
.target
);
843 unsigned nr_samples
= surf
->nr_samples
;
846 nr_samples
= surf
->texture
->nr_samples
;
848 struct pan_image img
= {
849 .width0
= rsrc
->base
.width0
,
850 .height0
= rsrc
->base
.height0
,
851 .depth0
= rsrc
->base
.depth0
,
854 .layout
= rsrc
->layout
,
855 .array_size
= rsrc
->base
.array_size
,
856 .first_level
= level
,
858 .first_layer
= surf
->u
.tex
.first_layer
,
859 .last_layer
= surf
->u
.tex
.last_layer
,
860 .nr_samples
= nr_samples
,
861 .cubemap_stride
= rsrc
->cubemap_stride
,
863 .slices
= rsrc
->slices
866 mali_ptr blend_shader
= 0;
868 if (loc
>= FRAG_RESULT_DATA0
&& !panfrost_can_fixed_blend(rsrc
->base
.format
)) {
869 struct panfrost_blend_shader
*b
=
870 panfrost_get_blend_shader(batch
->ctx
, &batch
->ctx
->blit_blend
, rsrc
->base
.format
, loc
- FRAG_RESULT_DATA0
);
872 struct panfrost_bo
*bo
= panfrost_batch_create_bo(batch
, b
->size
,
874 PAN_BO_ACCESS_PRIVATE
|
876 PAN_BO_ACCESS_FRAGMENT
);
878 memcpy(bo
->cpu
, b
->buffer
, b
->size
);
879 assert(b
->work_count
<= 4);
881 blend_shader
= bo
->gpu
| b
->first_tag
;
884 struct panfrost_transfer transfer
= panfrost_pool_alloc(&batch
->pool
,
885 4 * 4 * 6 * rsrc
->damage
.inverted_len
);
887 for (unsigned i
= 0; i
< rsrc
->damage
.inverted_len
; ++i
) {
888 float *o
= (float *) (transfer
.cpu
+ (4 * 4 * 6 * i
));
889 struct pan_rect r
= rsrc
->damage
.inverted_rects
[i
];
892 r
.minx
, rsrc
->base
.height0
- r
.miny
, 0.0, 1.0,
893 r
.maxx
, rsrc
->base
.height0
- r
.miny
, 0.0, 1.0,
894 r
.minx
, rsrc
->base
.height0
- r
.maxy
, 0.0, 1.0,
896 r
.maxx
, rsrc
->base
.height0
- r
.miny
, 0.0, 1.0,
897 r
.minx
, rsrc
->base
.height0
- r
.maxy
, 0.0, 1.0,
898 r
.maxx
, rsrc
->base
.height0
- r
.maxy
, 0.0, 1.0,
901 assert(sizeof(rect
) == 4 * 4 * 6);
902 memcpy(o
, rect
, sizeof(rect
));
905 panfrost_load_midg(&batch
->pool
, &batch
->scoreboard
,
907 batch
->framebuffer
.gpu
, transfer
.gpu
,
908 rsrc
->damage
.inverted_len
* 6,
911 panfrost_batch_add_bo(batch
, batch
->pool
.dev
->blit_shaders
.bo
,
912 PAN_BO_ACCESS_SHARED
| PAN_BO_ACCESS_READ
| PAN_BO_ACCESS_FRAGMENT
);
916 panfrost_batch_draw_wallpaper(struct panfrost_batch
*batch
)
918 panfrost_batch_reserve_framebuffer(batch
);
920 /* Assume combined. If either depth or stencil is written, they will
921 * both be written so we need to be careful for reloading */
923 unsigned draws
= batch
->draws
;
925 if (draws
& PIPE_CLEAR_DEPTHSTENCIL
)
926 draws
|= PIPE_CLEAR_DEPTHSTENCIL
;
928 /* Mask of buffers which need reload since they are not cleared and
929 * they are drawn. (If they are cleared, reload is useless; if they are
930 * not drawn and also not cleared, we can generally omit the attachment
931 * at the framebuffer descriptor level */
933 unsigned reload
= ~batch
->clear
& draws
;
935 for (unsigned i
= 0; i
< batch
->key
.nr_cbufs
; ++i
) {
936 if (reload
& (PIPE_CLEAR_COLOR0
<< i
))
937 panfrost_load_surface(batch
, batch
->key
.cbufs
[i
], FRAG_RESULT_DATA0
+ i
);
940 if (reload
& PIPE_CLEAR_DEPTH
)
941 panfrost_load_surface(batch
, batch
->key
.zsbuf
, FRAG_RESULT_DEPTH
);
943 if (reload
& PIPE_CLEAR_STENCIL
)
944 panfrost_load_surface(batch
, batch
->key
.zsbuf
, FRAG_RESULT_STENCIL
);
948 panfrost_batch_record_bo(struct hash_entry
*entry
, unsigned *bo_handles
, unsigned idx
)
950 struct panfrost_bo
*bo
= (struct panfrost_bo
*)entry
->key
;
951 uint32_t flags
= (uintptr_t)entry
->data
;
953 assert(bo
->gem_handle
> 0);
954 bo_handles
[idx
] = bo
->gem_handle
;
956 /* Update the BO access flags so that panfrost_bo_wait() knows
957 * about all pending accesses.
958 * We only keep the READ/WRITE info since this is all the BO
959 * wait logic cares about.
960 * We also preserve existing flags as this batch might not
961 * be the first one to access the BO.
963 bo
->gpu_access
|= flags
& (PAN_BO_ACCESS_RW
);
967 panfrost_batch_submit_ioctl(struct panfrost_batch
*batch
,
968 mali_ptr first_job_desc
,
972 struct panfrost_context
*ctx
= batch
->ctx
;
973 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
974 struct panfrost_device
*dev
= pan_device(gallium
->screen
);
975 struct drm_panfrost_submit submit
= {0,};
976 uint32_t *bo_handles
;
979 /* If we trace, we always need a syncobj, so make one of our own if we
980 * weren't given one to use. Remember that we did so, so we can free it
981 * after we're done but preventing double-frees if we were given a
984 bool our_sync
= false;
986 if (!out_sync
&& dev
->debug
& (PAN_DBG_TRACE
| PAN_DBG_SYNC
)) {
987 drmSyncobjCreate(dev
->fd
, 0, &out_sync
);
991 submit
.out_sync
= out_sync
;
992 submit
.jc
= first_job_desc
;
993 submit
.requirements
= reqs
;
995 bo_handles
= calloc(batch
->pool
.bos
->entries
+ batch
->bos
->entries
, sizeof(*bo_handles
));
998 hash_table_foreach(batch
->bos
, entry
)
999 panfrost_batch_record_bo(entry
, bo_handles
, submit
.bo_handle_count
++);
1001 hash_table_foreach(batch
->pool
.bos
, entry
)
1002 panfrost_batch_record_bo(entry
, bo_handles
, submit
.bo_handle_count
++);
1004 submit
.bo_handles
= (u64
) (uintptr_t) bo_handles
;
1005 ret
= drmIoctl(dev
->fd
, DRM_IOCTL_PANFROST_SUBMIT
, &submit
);
1009 if (dev
->debug
& PAN_DBG_MSGS
)
1010 fprintf(stderr
, "Error submitting: %m\n");
1015 /* Trace the job if we're doing that */
1016 if (dev
->debug
& (PAN_DBG_TRACE
| PAN_DBG_SYNC
)) {
1017 /* Wait so we can get errors reported back */
1018 drmSyncobjWait(dev
->fd
, &out_sync
, 1,
1019 INT64_MAX
, 0, NULL
);
1021 /* Trace gets priority over sync */
1022 bool minimal
= !(dev
->debug
& PAN_DBG_TRACE
);
1023 pandecode_jc(submit
.jc
, dev
->quirks
& IS_BIFROST
, dev
->gpu_id
, minimal
);
1026 /* Cleanup if we created the syncobj */
1028 drmSyncobjDestroy(dev
->fd
, out_sync
);
1033 /* Submit both vertex/tiler and fragment jobs for a batch, possibly with an
1034 * outsync corresponding to the later of the two (since there will be an
1035 * implicit dep between them) */
1038 panfrost_batch_submit_jobs(struct panfrost_batch
*batch
, uint32_t out_sync
)
1040 bool has_draws
= batch
->scoreboard
.first_job
;
1041 bool has_frag
= batch
->scoreboard
.tiler_dep
|| batch
->clear
;
1045 ret
= panfrost_batch_submit_ioctl(batch
, batch
->scoreboard
.first_job
,
1046 0, has_frag
? 0 : out_sync
);
1051 /* Whether we program the fragment job for draws or not depends
1052 * on whether there is any *tiler* activity (so fragment
1053 * shaders). If there are draws but entirely RASTERIZER_DISCARD
1054 * (say, for transform feedback), we want a fragment job that
1055 * *only* clears, since otherwise the tiler structures will be
1056 * uninitialized leading to faults (or state leaks) */
1058 mali_ptr fragjob
= panfrost_fragment_job(batch
,
1059 batch
->scoreboard
.tiler_dep
!= 0);
1060 ret
= panfrost_batch_submit_ioctl(batch
, fragjob
,
1061 PANFROST_JD_REQ_FS
, out_sync
);
1069 panfrost_batch_submit(struct panfrost_batch
*batch
, uint32_t out_sync
)
1072 struct panfrost_device
*dev
= pan_device(batch
->ctx
->base
.screen
);
1074 /* Submit the dependencies first. Don't pass along the out_sync since
1075 * they are guaranteed to terminate sooner */
1076 util_dynarray_foreach(&batch
->dependencies
,
1077 struct panfrost_batch_fence
*, dep
) {
1079 panfrost_batch_submit((*dep
)->batch
, 0);
1084 /* Nothing to do! */
1085 if (!batch
->scoreboard
.first_job
&& !batch
->clear
)
1088 panfrost_batch_draw_wallpaper(batch
);
1090 /* Now that all draws are in, we can finally prepare the
1091 * FBD for the batch */
1093 if (batch
->framebuffer
.gpu
&& batch
->scoreboard
.first_job
) {
1094 struct panfrost_context
*ctx
= batch
->ctx
;
1095 struct pipe_context
*gallium
= (struct pipe_context
*) ctx
;
1096 struct panfrost_device
*dev
= pan_device(gallium
->screen
);
1098 if (dev
->quirks
& MIDGARD_SFBD
)
1099 panfrost_attach_sfbd(batch
, ~0);
1101 panfrost_attach_mfbd(batch
, ~0);
1104 mali_ptr polygon_list
= panfrost_batch_get_polygon_list(batch
,
1105 MALI_TILER_MINIMUM_HEADER_SIZE
);
1107 panfrost_scoreboard_initialize_tiler(&batch
->pool
, &batch
->scoreboard
, polygon_list
);
1109 ret
= panfrost_batch_submit_jobs(batch
, out_sync
);
1111 if (ret
&& dev
->debug
& PAN_DBG_MSGS
)
1112 fprintf(stderr
, "panfrost_batch_submit failed: %d\n", ret
);
1114 /* We must reset the damage info of our render targets here even
1115 * though a damage reset normally happens when the DRI layer swaps
1116 * buffers. That's because there can be implicit flushes the GL
1117 * app is not aware of, and those might impact the damage region: if
1118 * part of the damaged portion is drawn during those implicit flushes,
1119 * you have to reload those areas before next draws are pushed, and
1120 * since the driver can't easily know what's been modified by the draws
1121 * it flushed, the easiest solution is to reload everything.
1123 for (unsigned i
= 0; i
< batch
->key
.nr_cbufs
; i
++) {
1124 if (!batch
->key
.cbufs
[i
])
1127 panfrost_resource_set_damage_region(NULL
,
1128 batch
->key
.cbufs
[i
]->texture
, 0, NULL
);
1132 panfrost_freeze_batch(batch
);
1133 panfrost_free_batch(batch
);
1136 /* Submit all batches, applying the out_sync to the currently bound batch */
1139 panfrost_flush_all_batches(struct panfrost_context
*ctx
, uint32_t out_sync
)
1141 struct panfrost_batch
*batch
= panfrost_get_batch_for_fbo(ctx
);
1142 panfrost_batch_submit(batch
, out_sync
);
1144 hash_table_foreach(ctx
->batches
, hentry
) {
1145 struct panfrost_batch
*batch
= hentry
->data
;
1148 panfrost_batch_submit(batch
, 0);
1151 assert(!ctx
->batches
->entries
);
1153 /* Collect batch fences before returning */
1154 panfrost_gc_fences(ctx
);
1158 panfrost_pending_batches_access_bo(struct panfrost_context
*ctx
,
1159 const struct panfrost_bo
*bo
)
1161 struct panfrost_bo_access
*access
;
1162 struct hash_entry
*hentry
;
1164 hentry
= _mesa_hash_table_search(ctx
->accessed_bos
, bo
);
1165 access
= hentry
? hentry
->data
: NULL
;
1169 if (access
->writer
&& access
->writer
->batch
)
1172 util_dynarray_foreach(&access
->readers
, struct panfrost_batch_fence
*,
1174 if (*reader
&& (*reader
)->batch
)
1181 /* We always flush writers. We might also need to flush readers */
1184 panfrost_flush_batches_accessing_bo(struct panfrost_context
*ctx
,
1185 struct panfrost_bo
*bo
,
1188 struct panfrost_bo_access
*access
;
1189 struct hash_entry
*hentry
;
1191 hentry
= _mesa_hash_table_search(ctx
->accessed_bos
, bo
);
1192 access
= hentry
? hentry
->data
: NULL
;
1196 if (access
->writer
&& access
->writer
->batch
)
1197 panfrost_batch_submit(access
->writer
->batch
, 0);
1202 util_dynarray_foreach(&access
->readers
, struct panfrost_batch_fence
*,
1204 if (*reader
&& (*reader
)->batch
)
1205 panfrost_batch_submit((*reader
)->batch
, 0);
1210 panfrost_batch_set_requirements(struct panfrost_batch
*batch
)
1212 struct panfrost_context
*ctx
= batch
->ctx
;
1214 if (ctx
->rasterizer
&& ctx
->rasterizer
->base
.multisample
)
1215 batch
->requirements
|= PAN_REQ_MSAA
;
1217 if (ctx
->depth_stencil
&& ctx
->depth_stencil
->depth
.writemask
) {
1218 batch
->requirements
|= PAN_REQ_DEPTH_WRITE
;
1219 batch
->draws
|= PIPE_CLEAR_DEPTH
;
1222 if (ctx
->depth_stencil
&& ctx
->depth_stencil
->stencil
[0].enabled
)
1223 batch
->draws
|= PIPE_CLEAR_STENCIL
;
1227 panfrost_batch_adjust_stack_size(struct panfrost_batch
*batch
)
1229 struct panfrost_context
*ctx
= batch
->ctx
;
1231 for (unsigned i
= 0; i
< PIPE_SHADER_TYPES
; ++i
) {
1232 struct panfrost_shader_state
*ss
;
1234 ss
= panfrost_get_shader_state(ctx
, i
);
1238 batch
->stack_size
= MAX2(batch
->stack_size
, ss
->stack_size
);
1242 /* Helper to smear a 32-bit color across 128-bit components */
1245 pan_pack_color_32(uint32_t *packed
, uint32_t v
)
1247 for (unsigned i
= 0; i
< 4; ++i
)
1252 pan_pack_color_64(uint32_t *packed
, uint32_t lo
, uint32_t hi
)
1254 for (unsigned i
= 0; i
< 4; i
+= 2) {
1261 pan_pack_color(uint32_t *packed
, const union pipe_color_union
*color
, enum pipe_format format
)
1263 /* Alpha magicked to 1.0 if there is no alpha */
1265 bool has_alpha
= util_format_has_alpha(format
);
1266 float clear_alpha
= has_alpha
? color
->f
[3] : 1.0f
;
1268 /* Packed color depends on the framebuffer format */
1270 const struct util_format_description
*desc
=
1271 util_format_description(format
);
1273 if (util_format_is_rgba8_variant(desc
) && desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_SRGB
) {
1274 pan_pack_color_32(packed
,
1275 ((uint32_t) float_to_ubyte(clear_alpha
) << 24) |
1276 ((uint32_t) float_to_ubyte(color
->f
[2]) << 16) |
1277 ((uint32_t) float_to_ubyte(color
->f
[1]) << 8) |
1278 ((uint32_t) float_to_ubyte(color
->f
[0]) << 0));
1279 } else if (format
== PIPE_FORMAT_B5G6R5_UNORM
) {
1280 /* First, we convert the components to R5, G6, B5 separately */
1281 unsigned r5
= _mesa_roundevenf(SATURATE(color
->f
[0]) * 31.0);
1282 unsigned g6
= _mesa_roundevenf(SATURATE(color
->f
[1]) * 63.0);
1283 unsigned b5
= _mesa_roundevenf(SATURATE(color
->f
[2]) * 31.0);
1285 /* Then we pack into a sparse u32. TODO: Why these shifts? */
1286 pan_pack_color_32(packed
, (b5
<< 25) | (g6
<< 14) | (r5
<< 5));
1287 } else if (format
== PIPE_FORMAT_B4G4R4A4_UNORM
) {
1288 /* Convert to 4-bits */
1289 unsigned r4
= _mesa_roundevenf(SATURATE(color
->f
[0]) * 15.0);
1290 unsigned g4
= _mesa_roundevenf(SATURATE(color
->f
[1]) * 15.0);
1291 unsigned b4
= _mesa_roundevenf(SATURATE(color
->f
[2]) * 15.0);
1292 unsigned a4
= _mesa_roundevenf(SATURATE(clear_alpha
) * 15.0);
1294 /* Pack on *byte* intervals */
1295 pan_pack_color_32(packed
, (a4
<< 28) | (b4
<< 20) | (g4
<< 12) | (r4
<< 4));
1296 } else if (format
== PIPE_FORMAT_B5G5R5A1_UNORM
) {
1297 /* Scale as expected but shift oddly */
1298 unsigned r5
= _mesa_roundevenf(SATURATE(color
->f
[0]) * 31.0);
1299 unsigned g5
= _mesa_roundevenf(SATURATE(color
->f
[1]) * 31.0);
1300 unsigned b5
= _mesa_roundevenf(SATURATE(color
->f
[2]) * 31.0);
1301 unsigned a1
= _mesa_roundevenf(SATURATE(clear_alpha
) * 1.0);
1303 pan_pack_color_32(packed
, (a1
<< 31) | (b5
<< 25) | (g5
<< 15) | (r5
<< 5));
1305 /* Otherwise, it's generic subject to replication */
1307 union util_color out
= { 0 };
1308 unsigned size
= util_format_get_blocksize(format
);
1310 util_pack_color(color
->f
, format
, &out
);
1313 unsigned b
= out
.ui
[0];
1314 unsigned s
= b
| (b
<< 8);
1315 pan_pack_color_32(packed
, s
| (s
<< 16));
1316 } else if (size
== 2)
1317 pan_pack_color_32(packed
, out
.ui
[0] | (out
.ui
[0] << 16));
1318 else if (size
== 3 || size
== 4)
1319 pan_pack_color_32(packed
, out
.ui
[0]);
1321 pan_pack_color_64(packed
, out
.ui
[0], out
.ui
[1] | (out
.ui
[1] << 16)); /* RGB16F -- RGBB */
1323 pan_pack_color_64(packed
, out
.ui
[0], out
.ui
[1]);
1324 else if (size
== 16)
1325 memcpy(packed
, out
.ui
, 16);
1327 unreachable("Unknown generic format size packing clear colour");
1332 panfrost_batch_clear(struct panfrost_batch
*batch
,
1334 const union pipe_color_union
*color
,
1335 double depth
, unsigned stencil
)
1337 struct panfrost_context
*ctx
= batch
->ctx
;
1339 if (buffers
& PIPE_CLEAR_COLOR
) {
1340 for (unsigned i
= 0; i
< PIPE_MAX_COLOR_BUFS
; ++i
) {
1341 if (!(buffers
& (PIPE_CLEAR_COLOR0
<< i
)))
1344 enum pipe_format format
= ctx
->pipe_framebuffer
.cbufs
[i
]->format
;
1345 pan_pack_color(batch
->clear_color
[i
], color
, format
);
1349 if (buffers
& PIPE_CLEAR_DEPTH
) {
1350 batch
->clear_depth
= depth
;
1353 if (buffers
& PIPE_CLEAR_STENCIL
) {
1354 batch
->clear_stencil
= stencil
;
1357 batch
->clear
|= buffers
;
1359 /* Clearing affects the entire framebuffer (by definition -- this is
1360 * the Gallium clear callback, which clears the whole framebuffer. If
1361 * the scissor test were enabled from the GL side, the gallium frontend
1362 * would emit a quad instead and we wouldn't go down this code path) */
1364 panfrost_batch_union_scissor(batch
, 0, 0,
1365 ctx
->pipe_framebuffer
.width
,
1366 ctx
->pipe_framebuffer
.height
);
1370 panfrost_batch_compare(const void *a
, const void *b
)
1372 return util_framebuffer_state_equal(a
, b
);
1376 panfrost_batch_hash(const void *key
)
1378 return _mesa_hash_data(key
, sizeof(struct pipe_framebuffer_state
));
1381 /* Given a new bounding rectangle (scissor), let the job cover the union of the
1382 * new and old bounding rectangles */
1385 panfrost_batch_union_scissor(struct panfrost_batch
*batch
,
1386 unsigned minx
, unsigned miny
,
1387 unsigned maxx
, unsigned maxy
)
1389 batch
->minx
= MIN2(batch
->minx
, minx
);
1390 batch
->miny
= MIN2(batch
->miny
, miny
);
1391 batch
->maxx
= MAX2(batch
->maxx
, maxx
);
1392 batch
->maxy
= MAX2(batch
->maxy
, maxy
);
1396 panfrost_batch_intersection_scissor(struct panfrost_batch
*batch
,
1397 unsigned minx
, unsigned miny
,
1398 unsigned maxx
, unsigned maxy
)
1400 batch
->minx
= MAX2(batch
->minx
, minx
);
1401 batch
->miny
= MAX2(batch
->miny
, miny
);
1402 batch
->maxx
= MIN2(batch
->maxx
, maxx
);
1403 batch
->maxy
= MIN2(batch
->maxy
, maxy
);
1406 /* Are we currently rendering to the dev (rather than an FBO)? */
1409 panfrost_batch_is_scanout(struct panfrost_batch
*batch
)
1411 /* If there is no color buffer, it's an FBO */
1412 if (batch
->key
.nr_cbufs
!= 1)
1415 /* If we're too early that no framebuffer was sent, it's scanout */
1416 if (!batch
->key
.cbufs
[0])
1419 return batch
->key
.cbufs
[0]->texture
->bind
& PIPE_BIND_DISPLAY_TARGET
||
1420 batch
->key
.cbufs
[0]->texture
->bind
& PIPE_BIND_SCANOUT
||
1421 batch
->key
.cbufs
[0]->texture
->bind
& PIPE_BIND_SHARED
;
1425 panfrost_batch_init(struct panfrost_context
*ctx
)
1427 ctx
->batches
= _mesa_hash_table_create(ctx
,
1428 panfrost_batch_hash
,
1429 panfrost_batch_compare
);
1430 ctx
->accessed_bos
= _mesa_hash_table_create(ctx
, _mesa_hash_pointer
,
1431 _mesa_key_pointer_equal
);