panfrost: Extend the panfrost_batch_add_bo() API to pass access flags
[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/u_format.h"
35 #include "util/u_pack_color.h"
36 #include "pan_util.h"
37 #include "pandecode/decode.h"
38
39 static struct panfrost_batch *
40 panfrost_create_batch(struct panfrost_context *ctx,
41 const struct pipe_framebuffer_state *key)
42 {
43 struct panfrost_batch *batch = rzalloc(ctx, struct panfrost_batch);
44
45 batch->ctx = ctx;
46
47 batch->bos = _mesa_set_create(batch,
48 _mesa_hash_pointer,
49 _mesa_key_pointer_equal);
50
51 batch->minx = batch->miny = ~0;
52 batch->maxx = batch->maxy = 0;
53 batch->transient_offset = 0;
54
55 util_dynarray_init(&batch->headers, batch);
56 util_dynarray_init(&batch->gpu_headers, batch);
57 util_copy_framebuffer_state(&batch->key, key);
58
59 return batch;
60 }
61
62 static void
63 panfrost_free_batch(struct panfrost_batch *batch)
64 {
65 if (!batch)
66 return;
67
68 struct panfrost_context *ctx = batch->ctx;
69
70 set_foreach(batch->bos, entry) {
71 struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
72 panfrost_bo_unreference(bo);
73 }
74
75 _mesa_hash_table_remove_key(ctx->batches, &batch->key);
76
77 if (ctx->batch == batch)
78 ctx->batch = NULL;
79
80 util_unreference_framebuffer_state(&batch->key);
81 ralloc_free(batch);
82 }
83
84 static struct panfrost_batch *
85 panfrost_get_batch(struct panfrost_context *ctx,
86 const struct pipe_framebuffer_state *key)
87 {
88 /* Lookup the job first */
89 struct hash_entry *entry = _mesa_hash_table_search(ctx->batches, key);
90
91 if (entry)
92 return entry->data;
93
94 /* Otherwise, let's create a job */
95
96 struct panfrost_batch *batch = panfrost_create_batch(ctx, key);
97
98 /* Save the created job */
99 _mesa_hash_table_insert(ctx->batches, &batch->key, batch);
100
101 return batch;
102 }
103
104 /* Get the job corresponding to the FBO we're currently rendering into */
105
106 struct panfrost_batch *
107 panfrost_get_batch_for_fbo(struct panfrost_context *ctx)
108 {
109 /* If we're wallpapering, we special case to workaround
110 * u_blitter abuse */
111
112 if (ctx->wallpaper_batch)
113 return ctx->wallpaper_batch;
114
115 /* If we already began rendering, use that */
116
117 if (ctx->batch) {
118 assert(util_framebuffer_state_equal(&ctx->batch->key,
119 &ctx->pipe_framebuffer));
120 return ctx->batch;
121 }
122
123 /* If not, look up the job */
124 struct panfrost_batch *batch = panfrost_get_batch(ctx,
125 &ctx->pipe_framebuffer);
126
127 /* Set this job as the current FBO job. Will be reset when updating the
128 * FB state and when submitting or releasing a job.
129 */
130 ctx->batch = batch;
131 return batch;
132 }
133
134 void
135 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
136 uint32_t flags)
137 {
138 if (!bo)
139 return;
140
141 if (_mesa_set_search(batch->bos, bo))
142 return;
143
144 panfrost_bo_reference(bo);
145 _mesa_set_add(batch->bos, bo);
146 }
147
148 void panfrost_batch_add_fbo_bos(struct panfrost_batch *batch)
149 {
150 uint32_t flags = PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_WRITE |
151 PAN_BO_ACCESS_VERTEX_TILER |
152 PAN_BO_ACCESS_FRAGMENT;
153
154 for (unsigned i = 0; i < batch->key.nr_cbufs; ++i) {
155 struct panfrost_resource *rsrc = pan_resource(batch->key.cbufs[i]->texture);
156 panfrost_batch_add_bo(batch, rsrc->bo, flags);
157 }
158
159 if (batch->key.zsbuf) {
160 struct panfrost_resource *rsrc = pan_resource(batch->key.zsbuf->texture);
161 panfrost_batch_add_bo(batch, rsrc->bo, flags);
162 }
163 }
164
165 struct panfrost_bo *
166 panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
167 uint32_t create_flags, uint32_t access_flags)
168 {
169 struct panfrost_bo *bo;
170
171 bo = panfrost_bo_create(pan_screen(batch->ctx->base.screen), size,
172 create_flags);
173 panfrost_batch_add_bo(batch, bo, access_flags);
174
175 /* panfrost_batch_add_bo() has retained a reference and
176 * panfrost_bo_create() initialize the refcnt to 1, so let's
177 * unreference the BO here so it gets released when the batch is
178 * destroyed (unless it's retained by someone else in the meantime).
179 */
180 panfrost_bo_unreference(bo);
181 return bo;
182 }
183
184 /* Returns the polygon list's GPU address if available, or otherwise allocates
185 * the polygon list. It's perfectly fast to use allocate/free BO directly,
186 * since we'll hit the BO cache and this is one-per-batch anyway. */
187
188 mali_ptr
189 panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size)
190 {
191 if (batch->polygon_list) {
192 assert(batch->polygon_list->size >= size);
193 } else {
194 /* Create the BO as invisible, as there's no reason to map */
195
196 batch->polygon_list = panfrost_batch_create_bo(batch, size,
197 PAN_BO_INVISIBLE,
198 PAN_BO_ACCESS_PRIVATE |
199 PAN_BO_ACCESS_RW |
200 PAN_BO_ACCESS_VERTEX_TILER |
201 PAN_BO_ACCESS_FRAGMENT);
202 }
203
204 return batch->polygon_list->gpu;
205 }
206
207 struct panfrost_bo *
208 panfrost_batch_get_scratchpad(struct panfrost_batch *batch)
209 {
210 if (batch->scratchpad)
211 return batch->scratchpad;
212
213 batch->scratchpad = panfrost_batch_create_bo(batch, 64 * 4 * 4096,
214 PAN_BO_INVISIBLE,
215 PAN_BO_ACCESS_PRIVATE |
216 PAN_BO_ACCESS_RW |
217 PAN_BO_ACCESS_VERTEX_TILER |
218 PAN_BO_ACCESS_FRAGMENT);
219 assert(batch->scratchpad);
220 return batch->scratchpad;
221 }
222
223 struct panfrost_bo *
224 panfrost_batch_get_tiler_heap(struct panfrost_batch *batch)
225 {
226 if (batch->tiler_heap)
227 return batch->tiler_heap;
228
229 batch->tiler_heap = panfrost_batch_create_bo(batch, 4096 * 4096,
230 PAN_BO_INVISIBLE |
231 PAN_BO_GROWABLE,
232 PAN_BO_ACCESS_PRIVATE |
233 PAN_BO_ACCESS_RW |
234 PAN_BO_ACCESS_VERTEX_TILER |
235 PAN_BO_ACCESS_FRAGMENT);
236 assert(batch->tiler_heap);
237 return batch->tiler_heap;
238 }
239
240 struct panfrost_bo *
241 panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch)
242 {
243 if (batch->tiler_dummy)
244 return batch->tiler_dummy;
245
246 batch->tiler_dummy = panfrost_batch_create_bo(batch, 4096,
247 PAN_BO_INVISIBLE,
248 PAN_BO_ACCESS_PRIVATE |
249 PAN_BO_ACCESS_RW |
250 PAN_BO_ACCESS_VERTEX_TILER |
251 PAN_BO_ACCESS_FRAGMENT);
252 assert(batch->tiler_dummy);
253 return batch->tiler_dummy;
254 }
255
256 static void
257 panfrost_batch_draw_wallpaper(struct panfrost_batch *batch)
258 {
259 /* Nothing to reload? TODO: MRT wallpapers */
260 if (batch->key.cbufs[0] == NULL)
261 return;
262
263 /* Check if the buffer has any content on it worth preserving */
264
265 struct pipe_surface *surf = batch->key.cbufs[0];
266 struct panfrost_resource *rsrc = pan_resource(surf->texture);
267 unsigned level = surf->u.tex.level;
268
269 if (!rsrc->slices[level].initialized)
270 return;
271
272 batch->ctx->wallpaper_batch = batch;
273
274 /* Clamp the rendering area to the damage extent. The
275 * KHR_partial_update() spec states that trying to render outside of
276 * the damage region is "undefined behavior", so we should be safe.
277 */
278 unsigned damage_width = (rsrc->damage.extent.maxx - rsrc->damage.extent.minx);
279 unsigned damage_height = (rsrc->damage.extent.maxy - rsrc->damage.extent.miny);
280
281 if (damage_width && damage_height) {
282 panfrost_batch_intersection_scissor(batch,
283 rsrc->damage.extent.minx,
284 rsrc->damage.extent.miny,
285 rsrc->damage.extent.maxx,
286 rsrc->damage.extent.maxy);
287 }
288
289 /* FIXME: Looks like aligning on a tile is not enough, but
290 * aligning on twice the tile size seems to works. We don't
291 * know exactly what happens here but this deserves extra
292 * investigation to figure it out.
293 */
294 batch->minx = batch->minx & ~((MALI_TILE_LENGTH * 2) - 1);
295 batch->miny = batch->miny & ~((MALI_TILE_LENGTH * 2) - 1);
296 batch->maxx = MIN2(ALIGN_POT(batch->maxx, MALI_TILE_LENGTH * 2),
297 rsrc->base.width0);
298 batch->maxy = MIN2(ALIGN_POT(batch->maxy, MALI_TILE_LENGTH * 2),
299 rsrc->base.height0);
300
301 struct pipe_scissor_state damage;
302 struct pipe_box rects[4];
303
304 /* Clamp the damage box to the rendering area. */
305 damage.minx = MAX2(batch->minx, rsrc->damage.biggest_rect.x);
306 damage.miny = MAX2(batch->miny, rsrc->damage.biggest_rect.y);
307 damage.maxx = MIN2(batch->maxx,
308 rsrc->damage.biggest_rect.x +
309 rsrc->damage.biggest_rect.width);
310 damage.maxy = MIN2(batch->maxy,
311 rsrc->damage.biggest_rect.y +
312 rsrc->damage.biggest_rect.height);
313
314 /* One damage rectangle means we can end up with at most 4 reload
315 * regions:
316 * 1: left region, only exists if damage.x > 0
317 * 2: right region, only exists if damage.x + damage.width < fb->width
318 * 3: top region, only exists if damage.y > 0. The intersection with
319 * the left and right regions are dropped
320 * 4: bottom region, only exists if damage.y + damage.height < fb->height.
321 * The intersection with the left and right regions are dropped
322 *
323 * ____________________________
324 * | | 3 | |
325 * | |___________| |
326 * | | damage | |
327 * | 1 | rect | 2 |
328 * | |___________| |
329 * | | 4 | |
330 * |_______|___________|______|
331 */
332 u_box_2d(batch->minx, batch->miny, damage.minx - batch->minx,
333 batch->maxy - batch->miny, &rects[0]);
334 u_box_2d(damage.maxx, batch->miny, batch->maxx - damage.maxx,
335 batch->maxy - batch->miny, &rects[1]);
336 u_box_2d(damage.minx, batch->miny, damage.maxx - damage.minx,
337 damage.miny - batch->miny, &rects[2]);
338 u_box_2d(damage.minx, damage.maxy, damage.maxx - damage.minx,
339 batch->maxy - damage.maxy, &rects[3]);
340
341 for (unsigned i = 0; i < 4; i++) {
342 /* Width and height are always >= 0 even if width is declared as a
343 * signed integer: u_box_2d() helper takes unsigned args and
344 * panfrost_set_damage_region() is taking care of clamping
345 * negative values.
346 */
347 if (!rects[i].width || !rects[i].height)
348 continue;
349
350 /* Blit the wallpaper in */
351 panfrost_blit_wallpaper(batch->ctx, &rects[i]);
352 }
353 batch->ctx->wallpaper_batch = NULL;
354 }
355
356 static int
357 panfrost_batch_submit_ioctl(struct panfrost_batch *batch,
358 mali_ptr first_job_desc,
359 uint32_t reqs)
360 {
361 struct panfrost_context *ctx = batch->ctx;
362 struct pipe_context *gallium = (struct pipe_context *) ctx;
363 struct panfrost_screen *screen = pan_screen(gallium->screen);
364 struct drm_panfrost_submit submit = {0,};
365 uint32_t *bo_handles;
366 int ret;
367
368 submit.in_syncs = (u64) (uintptr_t) &ctx->out_sync;
369 submit.in_sync_count = 1;
370
371 submit.out_sync = ctx->out_sync;
372
373 submit.jc = first_job_desc;
374 submit.requirements = reqs;
375
376 bo_handles = calloc(batch->bos->entries, sizeof(*bo_handles));
377 assert(bo_handles);
378
379 set_foreach(batch->bos, entry) {
380 struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
381 assert(bo->gem_handle > 0);
382 bo_handles[submit.bo_handle_count++] = bo->gem_handle;
383 }
384
385 submit.bo_handles = (u64) (uintptr_t) bo_handles;
386 ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_SUBMIT, &submit);
387 free(bo_handles);
388 if (ret) {
389 fprintf(stderr, "Error submitting: %m\n");
390 return errno;
391 }
392
393 /* Trace the job if we're doing that */
394 if (pan_debug & PAN_DBG_TRACE) {
395 /* Wait so we can get errors reported back */
396 drmSyncobjWait(screen->fd, &ctx->out_sync, 1, INT64_MAX, 0, NULL);
397 pandecode_jc(submit.jc, FALSE);
398 }
399
400 return 0;
401 }
402
403 static int
404 panfrost_batch_submit_jobs(struct panfrost_batch *batch)
405 {
406 bool has_draws = batch->first_job.gpu;
407 int ret = 0;
408
409 if (has_draws) {
410 ret = panfrost_batch_submit_ioctl(batch, batch->first_job.gpu, 0);
411 assert(!ret);
412 }
413
414 if (batch->first_tiler.gpu || batch->clear) {
415 mali_ptr fragjob = panfrost_fragment_job(batch, has_draws);
416
417 ret = panfrost_batch_submit_ioctl(batch, fragjob, PANFROST_JD_REQ_FS);
418 assert(!ret);
419 }
420
421 return ret;
422 }
423
424 void
425 panfrost_batch_submit(struct panfrost_batch *batch)
426 {
427 assert(batch);
428
429 struct panfrost_context *ctx = batch->ctx;
430 int ret;
431
432 /* Nothing to do! */
433 if (!batch->last_job.gpu && !batch->clear)
434 goto out;
435
436 if (!batch->clear && batch->last_tiler.gpu)
437 panfrost_batch_draw_wallpaper(batch);
438
439 panfrost_scoreboard_link_batch(batch);
440
441 ret = panfrost_batch_submit_jobs(batch);
442
443 if (ret)
444 fprintf(stderr, "panfrost_batch_submit failed: %d\n", ret);
445
446 out:
447 /* If this is the bound batch, the panfrost_context parameters are
448 * relevant so submitting it invalidates those paramaters, but if it's
449 * not bound, the context parameters are for some other batch so we
450 * can't invalidate them.
451 */
452 if (ctx->batch == batch)
453 panfrost_invalidate_frame(ctx);
454
455 /* The job has been submitted, let's invalidate the current FBO job
456 * cache.
457 */
458 assert(!ctx->batch || batch == ctx->batch);
459 ctx->batch = NULL;
460
461 /* We always stall the pipeline for correct results since pipelined
462 * rendering is quite broken right now (to be fixed by the panfrost_job
463 * refactor, just take the perf hit for correctness)
464 */
465 drmSyncobjWait(pan_screen(ctx->base.screen)->fd, &ctx->out_sync, 1,
466 INT64_MAX, 0, NULL);
467 panfrost_free_batch(batch);
468 }
469
470 void
471 panfrost_batch_set_requirements(struct panfrost_batch *batch)
472 {
473 struct panfrost_context *ctx = batch->ctx;
474
475 if (ctx->rasterizer && ctx->rasterizer->base.multisample)
476 batch->requirements |= PAN_REQ_MSAA;
477
478 if (ctx->depth_stencil && ctx->depth_stencil->depth.writemask)
479 batch->requirements |= PAN_REQ_DEPTH_WRITE;
480 }
481
482 /* Helper to smear a 32-bit color across 128-bit components */
483
484 static void
485 pan_pack_color_32(uint32_t *packed, uint32_t v)
486 {
487 for (unsigned i = 0; i < 4; ++i)
488 packed[i] = v;
489 }
490
491 static void
492 pan_pack_color_64(uint32_t *packed, uint32_t lo, uint32_t hi)
493 {
494 for (unsigned i = 0; i < 4; i += 2) {
495 packed[i + 0] = lo;
496 packed[i + 1] = hi;
497 }
498 }
499
500 static void
501 pan_pack_color(uint32_t *packed, const union pipe_color_union *color, enum pipe_format format)
502 {
503 /* Alpha magicked to 1.0 if there is no alpha */
504
505 bool has_alpha = util_format_has_alpha(format);
506 float clear_alpha = has_alpha ? color->f[3] : 1.0f;
507
508 /* Packed color depends on the framebuffer format */
509
510 const struct util_format_description *desc =
511 util_format_description(format);
512
513 if (util_format_is_rgba8_variant(desc)) {
514 pan_pack_color_32(packed,
515 (float_to_ubyte(clear_alpha) << 24) |
516 (float_to_ubyte(color->f[2]) << 16) |
517 (float_to_ubyte(color->f[1]) << 8) |
518 (float_to_ubyte(color->f[0]) << 0));
519 } else if (format == PIPE_FORMAT_B5G6R5_UNORM) {
520 /* First, we convert the components to R5, G6, B5 separately */
521 unsigned r5 = CLAMP(color->f[0], 0.0, 1.0) * 31.0;
522 unsigned g6 = CLAMP(color->f[1], 0.0, 1.0) * 63.0;
523 unsigned b5 = CLAMP(color->f[2], 0.0, 1.0) * 31.0;
524
525 /* Then we pack into a sparse u32. TODO: Why these shifts? */
526 pan_pack_color_32(packed, (b5 << 25) | (g6 << 14) | (r5 << 5));
527 } else if (format == PIPE_FORMAT_B4G4R4A4_UNORM) {
528 /* We scale the components against 0xF0 (=240.0), rather than 0xFF */
529 unsigned r4 = CLAMP(color->f[0], 0.0, 1.0) * 240.0;
530 unsigned g4 = CLAMP(color->f[1], 0.0, 1.0) * 240.0;
531 unsigned b4 = CLAMP(color->f[2], 0.0, 1.0) * 240.0;
532 unsigned a4 = CLAMP(clear_alpha, 0.0, 1.0) * 240.0;
533
534 /* Pack on *byte* intervals */
535 pan_pack_color_32(packed, (a4 << 24) | (b4 << 16) | (g4 << 8) | r4);
536 } else if (format == PIPE_FORMAT_B5G5R5A1_UNORM) {
537 /* Scale as expected but shift oddly */
538 unsigned r5 = round(CLAMP(color->f[0], 0.0, 1.0)) * 31.0;
539 unsigned g5 = round(CLAMP(color->f[1], 0.0, 1.0)) * 31.0;
540 unsigned b5 = round(CLAMP(color->f[2], 0.0, 1.0)) * 31.0;
541 unsigned a1 = round(CLAMP(clear_alpha, 0.0, 1.0)) * 1.0;
542
543 pan_pack_color_32(packed, (a1 << 31) | (b5 << 25) | (g5 << 15) | (r5 << 5));
544 } else {
545 /* Try Gallium's generic default path. Doesn't work for all
546 * formats but it's a good guess. */
547
548 union util_color out;
549
550 if (util_format_is_pure_integer(format)) {
551 memcpy(out.ui, color->ui, 16);
552 } else {
553 util_pack_color(color->f, format, &out);
554 }
555
556 unsigned size = util_format_get_blocksize(format);
557
558 if (size == 1) {
559 unsigned b = out.ui[0];
560 unsigned s = b | (b << 8);
561 pan_pack_color_32(packed, s | (s << 16));
562 } else if (size == 2)
563 pan_pack_color_32(packed, out.ui[0] | (out.ui[0] << 16));
564 else if (size == 4)
565 pan_pack_color_32(packed, out.ui[0]);
566 else if (size == 8)
567 pan_pack_color_64(packed, out.ui[0], out.ui[1]);
568 else if (size == 16)
569 memcpy(packed, out.ui, 16);
570 else
571 unreachable("Unknown generic format size packing clear colour");
572 }
573 }
574
575 void
576 panfrost_batch_clear(struct panfrost_batch *batch,
577 unsigned buffers,
578 const union pipe_color_union *color,
579 double depth, unsigned stencil)
580 {
581 struct panfrost_context *ctx = batch->ctx;
582
583 if (buffers & PIPE_CLEAR_COLOR) {
584 for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) {
585 if (!(buffers & (PIPE_CLEAR_COLOR0 << i)))
586 continue;
587
588 enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format;
589 pan_pack_color(batch->clear_color[i], color, format);
590 }
591 }
592
593 if (buffers & PIPE_CLEAR_DEPTH) {
594 batch->clear_depth = depth;
595 }
596
597 if (buffers & PIPE_CLEAR_STENCIL) {
598 batch->clear_stencil = stencil;
599 }
600
601 batch->clear |= buffers;
602
603 /* Clearing affects the entire framebuffer (by definition -- this is
604 * the Gallium clear callback, which clears the whole framebuffer. If
605 * the scissor test were enabled from the GL side, the state tracker
606 * would emit a quad instead and we wouldn't go down this code path) */
607
608 panfrost_batch_union_scissor(batch, 0, 0,
609 ctx->pipe_framebuffer.width,
610 ctx->pipe_framebuffer.height);
611 }
612
613 static bool
614 panfrost_batch_compare(const void *a, const void *b)
615 {
616 return util_framebuffer_state_equal(a, b);
617 }
618
619 static uint32_t
620 panfrost_batch_hash(const void *key)
621 {
622 return _mesa_hash_data(key, sizeof(struct pipe_framebuffer_state));
623 }
624
625 /* Given a new bounding rectangle (scissor), let the job cover the union of the
626 * new and old bounding rectangles */
627
628 void
629 panfrost_batch_union_scissor(struct panfrost_batch *batch,
630 unsigned minx, unsigned miny,
631 unsigned maxx, unsigned maxy)
632 {
633 batch->minx = MIN2(batch->minx, minx);
634 batch->miny = MIN2(batch->miny, miny);
635 batch->maxx = MAX2(batch->maxx, maxx);
636 batch->maxy = MAX2(batch->maxy, maxy);
637 }
638
639 void
640 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
641 unsigned minx, unsigned miny,
642 unsigned maxx, unsigned maxy)
643 {
644 batch->minx = MAX2(batch->minx, minx);
645 batch->miny = MAX2(batch->miny, miny);
646 batch->maxx = MIN2(batch->maxx, maxx);
647 batch->maxy = MIN2(batch->maxy, maxy);
648 }
649
650 /* Are we currently rendering to the screen (rather than an FBO)? */
651
652 bool
653 panfrost_batch_is_scanout(struct panfrost_batch *batch)
654 {
655 /* If there is no color buffer, it's an FBO */
656 if (batch->key.nr_cbufs != 1)
657 return false;
658
659 /* If we're too early that no framebuffer was sent, it's scanout */
660 if (!batch->key.cbufs[0])
661 return true;
662
663 return batch->key.cbufs[0]->texture->bind & PIPE_BIND_DISPLAY_TARGET ||
664 batch->key.cbufs[0]->texture->bind & PIPE_BIND_SCANOUT ||
665 batch->key.cbufs[0]->texture->bind & PIPE_BIND_SHARED;
666 }
667
668 void
669 panfrost_batch_init(struct panfrost_context *ctx)
670 {
671 ctx->batches = _mesa_hash_table_create(ctx,
672 panfrost_batch_hash,
673 panfrost_batch_compare);
674 }