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