Lines Matching refs:batch
46 panfrost_batch_idx(struct panfrost_batch *batch)
48 return batch - batch->ctx->batches.slots;
51 /* Adds the BO backing surface to a batch if the surface is non-null */
54 panfrost_batch_add_surface(struct panfrost_batch *batch, struct pipe_surface *surf)
58 panfrost_batch_write_rsrc(batch, rsrc, PIPE_SHADER_FRAGMENT);
65 struct panfrost_batch *batch)
71 batch->ctx = ctx;
73 batch->seqnum = ++ctx->batches.seqnum;
75 util_dynarray_init(&batch->bos, NULL);
77 batch->minx = batch->miny = ~0;
78 batch->maxx = batch->maxy = 0;
80 util_copy_framebuffer_state(&batch->key, key);
81 batch->resources =_mesa_set_create(NULL, _mesa_hash_pointer,
84 /* Preallocate the main pool, since every batch has at least one job
86 panfrost_pool_init(&batch->pool, NULL, dev, 0, 65536, "Batch pool", true, true);
88 /* Don't preallocate the invisible pool, since not every batch will use
91 panfrost_pool_init(&batch->invisible_pool, NULL, dev,
94 for (unsigned i = 0; i < batch->key.nr_cbufs; ++i)
95 panfrost_batch_add_surface(batch, batch->key.cbufs[i]);
97 panfrost_batch_add_surface(batch, batch->key.zsbuf);
99 screen->vtbl.init_batch(batch);
103 panfrost_batch_cleanup(struct panfrost_context *ctx, struct panfrost_batch *batch)
107 assert(batch->seqnum);
109 if (ctx->batch == batch)
110 ctx->batch = NULL;
112 unsigned batch_idx = panfrost_batch_idx(batch);
114 pan_bo_access *flags = util_dynarray_begin(&batch->bos);
115 unsigned end_bo = util_dynarray_num_elements(&batch->bos, pan_bo_access);
125 set_foreach(batch->resources, entry) {
138 _mesa_set_destroy(batch->resources, NULL);
139 panfrost_pool_cleanup(&batch->pool);
140 panfrost_pool_cleanup(&batch->invisible_pool);
142 util_unreference_framebuffer_state(&batch->key);
144 util_dynarray_fini(&batch->bos);
146 memset(batch, 0, sizeof(*batch));
152 struct panfrost_batch *batch);
158 struct panfrost_batch *batch = NULL;
170 if (!batch || batch->seqnum > ctx->batches.slots[i].seqnum)
171 batch = &ctx->batches.slots[i];
174 assert(batch);
176 /* The selected slot is used, we need to flush the batch */
177 if (batch->seqnum)
178 panfrost_batch_submit(ctx, batch);
180 panfrost_batch_init(ctx, key, batch);
182 unsigned batch_idx = panfrost_batch_idx(batch);
185 return batch;
195 if (ctx->batch) {
196 assert(util_framebuffer_state_equal(&ctx->batch->key,
198 return ctx->batch;
202 struct panfrost_batch *batch = panfrost_get_batch(ctx,
208 ctx->batch = batch;
210 return batch;
216 struct panfrost_batch *batch;
218 batch = panfrost_get_batch(ctx, &ctx->pipe_framebuffer);
221 /* We only need to submit and get a fresh batch if there is no
222 * draw/clear queued. Otherwise we may reuse the batch. */
224 if (batch->scoreboard.first_job) {
226 panfrost_batch_submit(ctx, batch);
227 batch = panfrost_get_batch(ctx, &ctx->pipe_framebuffer);
230 ctx->batch = batch;
231 return batch;
235 panfrost_batch_update_access(struct panfrost_batch *batch,
238 struct panfrost_context *ctx = batch->ctx;
239 uint32_t batch_idx = panfrost_batch_idx(batch);
244 _mesa_set_search_or_add(batch->resources, rsrc, &found);
250 /* Reference the resource on the batch */
255 if (writes || ((writer != NULL) && (writer != batch))) {
258 struct panfrost_batch *batch = &ctx->batches.slots[i];
260 /* Skip the entry if this our batch. */
265 if (_mesa_set_search(batch->resources, rsrc))
266 panfrost_batch_submit(ctx, batch);
271 _mesa_hash_table_insert(ctx->writers, rsrc, batch);
277 panfrost_batch_get_bo_access(struct panfrost_batch *batch, unsigned handle)
279 unsigned size = util_dynarray_num_elements(&batch->bos, pan_bo_access);
284 memset(util_dynarray_grow(&batch->bos, pan_bo_access, grow),
288 return util_dynarray_element(&batch->bos, pan_bo_access, handle);
292 panfrost_batch_add_bo_old(struct panfrost_batch *batch,
299 panfrost_batch_get_bo_access(batch, bo->gem_handle);
303 batch->num_bos++;
322 panfrost_batch_add_bo(struct panfrost_batch *batch,
325 panfrost_batch_add_bo_old(batch, bo, PAN_BO_ACCESS_READ |
330 panfrost_batch_read_rsrc(struct panfrost_batch *batch,
337 panfrost_batch_add_bo_old(batch, rsrc->image.data.bo, access);
340 panfrost_batch_add_bo_old(batch, rsrc->image.crc.bo, access);
343 panfrost_batch_add_bo_old(batch, rsrc->separate_stencil->image.data.bo, access);
345 panfrost_batch_update_access(batch, rsrc, false);
349 panfrost_batch_write_rsrc(struct panfrost_batch *batch,
356 panfrost_batch_add_bo_old(batch, rsrc->image.data.bo, access);
359 panfrost_batch_add_bo_old(batch, rsrc->image.crc.bo, access);
362 panfrost_batch_add_bo_old(batch, rsrc->separate_stencil->image.data.bo, access);
364 panfrost_batch_update_access(batch, rsrc, true);
372 /* Any batch writing this resource is writing to the old BO, not the
383 /* Likewise, any batch reading this resource is reading the old BO, and
388 struct panfrost_batch *batch = &ctx->batches.slots[i];
389 struct set_entry *ent = _mesa_set_search(batch->resources, rsrc);
394 _mesa_set_remove(batch->resources, ent);
406 panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
412 bo = panfrost_bo_create(pan_device(batch->ctx->base.screen), size,
414 panfrost_batch_add_bo(batch, bo, stage);
418 * unreference the BO here so it gets released when the batch is
426 panfrost_batch_get_scratchpad(struct panfrost_batch *batch,
435 if (batch->scratchpad) {
436 assert(batch->scratchpad->size >= size);
438 batch->scratchpad = panfrost_batch_create_bo(batch, size,
443 panfrost_batch_add_bo(batch, batch->scratchpad,
447 return batch->scratchpad;
451 panfrost_batch_get_shared_memory(struct panfrost_batch *batch,
455 if (batch->shared_memory) {
456 assert(batch->shared_memory->size >= size);
458 batch->shared_memory = panfrost_batch_create_bo(batch, size,
464 return batch->shared_memory;
468 panfrost_batch_to_fb_info(const struct panfrost_batch *batch,
480 fb->width = batch->key.width;
481 fb->height = batch->key.height;
482 fb->extent.minx = batch->minx;
483 fb->extent.miny = batch->miny;
484 fb->extent.maxx = batch->maxx - 1;
485 fb->extent.maxy = batch->maxy - 1;
486 fb->nr_samples = util_framebuffer_get_num_samples(&batch->key);
487 fb->rt_count = batch->key.nr_cbufs;
488 fb->sprite_coord_origin = pan_tristate_get(batch->sprite_coord_origin);
489 fb->first_provoking_vertex = pan_tristate_get(batch->first_provoking_vertex);
496 struct pipe_surface *surf = batch->key.cbufs[i];
504 if (batch->clear & mask) {
506 memcpy(fb->rts[i].clear_value, batch->clear_color[i],
510 fb->rts[i].discard = !reserve && !(batch->resolve & mask);
524 if (!(batch->clear & mask) &&
525 ((batch->read & mask) ||
526 ((batch->draws & mask) &&
535 if (batch->key.zsbuf) {
536 struct pipe_surface *surf = batch->key.zsbuf;
570 if (batch->clear & PIPE_CLEAR_DEPTH) {
572 fb->zs.clear_value.depth = batch->clear_depth;
575 if (batch->clear & PIPE_CLEAR_STENCIL) {
577 fb->zs.clear_value.stencil = batch->clear_stencil;
580 fb->zs.discard.z = !reserve && !(batch->resolve & PIPE_CLEAR_DEPTH);
581 fb->zs.discard.s = !reserve && !(batch->resolve & PIPE_CLEAR_STENCIL);
584 ((batch->read & PIPE_CLEAR_DEPTH) ||
585 ((batch->draws & PIPE_CLEAR_DEPTH) &&
590 ((batch->read & PIPE_CLEAR_STENCIL) ||
591 ((batch->draws & PIPE_CLEAR_STENCIL) &&
609 panfrost_batch_submit_ioctl(struct panfrost_batch *batch,
615 struct panfrost_context *ctx = batch->ctx;
638 bo_handles = calloc(panfrost_pool_num_bos(&batch->pool) +
639 panfrost_pool_num_bos(&batch->invisible_pool) +
640 batch->num_bos + 2,
644 pan_bo_access *flags = util_dynarray_begin(&batch->bos);
645 unsigned end_bo = util_dynarray_num_elements(&batch->bos, pan_bo_access);
651 assert(submit.bo_handle_count < batch->num_bos);
658 * We also preserve existing flags as this batch might not
666 panfrost_pool_get_bo_handles(&batch->pool, bo_handles + submit.bo_handle_count);
667 submit.bo_handle_count += panfrost_pool_num_bos(&batch->pool);
668 panfrost_pool_get_bo_handles(&batch->invisible_pool, bo_handles + submit.bo_handle_count);
669 submit.bo_handle_count += panfrost_pool_num_bos(&batch->invisible_pool);
671 /* Add the tiler heap to the list of accessed BOs if the batch has at
675 if (batch->scoreboard.first_tiler)
712 panfrost_has_fragment_job(struct panfrost_batch *batch)
714 return batch->scoreboard.first_tiler || batch->clear;
717 /* Submit both vertex/tiler and fragment jobs for a batch, possibly with an
722 panfrost_batch_submit_jobs(struct panfrost_batch *batch,
726 struct pipe_screen *pscreen = batch->ctx->base.screen;
729 bool has_draws = batch->scoreboard.first_job;
730 bool has_tiler = batch->scoreboard.first_tiler;
731 bool has_frag = panfrost_has_fragment_job(batch);
742 ret = panfrost_batch_submit_ioctl(batch, batch->scoreboard.first_job,
750 mali_ptr fragjob = screen->vtbl.emit_fragment_job(batch, fb);
751 ret = panfrost_batch_submit_ioctl(batch, fragjob,
766 panfrost_emit_tile_map(struct panfrost_batch *batch, struct pan_fb_info *fb)
768 if (batch->key.nr_cbufs < 1 || !batch->key.cbufs[0])
771 struct pipe_surface *surf = batch->key.cbufs[0];
776 pan_pool_upload_aligned(&batch->pool.base,
786 struct panfrost_batch *batch)
793 if (!batch->scoreboard.first_job && !batch->clear)
796 if (batch->key.zsbuf && panfrost_has_fragment_job(batch)) {
797 struct pipe_surface *surf = batch->key.zsbuf;
804 if (batch->clear & PIPE_CLEAR_STENCIL) {
805 z_rsrc->stencil_value = batch->clear_stencil;
808 batch->clear_stencil = z_rsrc->stencil_value;
809 batch->clear |= PIPE_CLEAR_STENCIL;
812 if (batch->draws & PIPE_CLEAR_STENCIL)
819 panfrost_batch_to_fb_info(batch, &fb, rts, &zs, &s, false);
821 screen->vtbl.preload(batch, &fb);
822 screen->vtbl.init_polygon_list(batch);
825 * FBD for the batch (if there is one). */
827 screen->vtbl.emit_tls(batch);
828 panfrost_emit_tile_map(batch, &fb);
830 if (batch->scoreboard.first_tiler || batch->clear)
831 screen->vtbl.emit_fbd(batch, &fb);
833 ret = panfrost_batch_submit_jobs(batch, &fb, 0, ctx->syncobj);
847 for (unsigned i = 0; i < batch->key.nr_cbufs; i++) {
848 if (!batch->key.cbufs[i])
852 batch->key.cbufs[i]->texture,
857 panfrost_batch_cleanup(ctx, batch);
865 struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
866 panfrost_batch_submit(ctx, batch);
898 struct panfrost_batch *batch = &ctx->batches.slots[i];
900 if (!_mesa_set_search(batch->resources, rsrc))
904 panfrost_batch_submit(ctx, batch);
909 panfrost_batch_adjust_stack_size(struct panfrost_batch *batch)
911 struct panfrost_context *ctx = batch->ctx;
920 batch->stack_size = MAX2(batch->stack_size, ss->info.tls_size);
925 panfrost_batch_clear(struct panfrost_batch *batch,
930 struct panfrost_context *ctx = batch->ctx;
938 pan_pack_color(batch->clear_color[i], color, format, false);
943 batch->clear_depth = depth;
947 batch->clear_stencil = stencil;
950 batch->clear |= buffers;
951 batch->resolve |= buffers;
958 panfrost_batch_union_scissor(batch, 0, 0,
967 panfrost_batch_union_scissor(struct panfrost_batch *batch,
971 batch->minx = MIN2(batch->minx, minx);
972 batch->miny = MIN2(batch->miny, miny);
973 batch->maxx = MAX2(batch->maxx, maxx);
974 batch->maxy = MAX2(batch->maxy, maxy);
985 panfrost_batch_skip_rasterization(struct panfrost_batch *batch)
987 struct panfrost_context *ctx = batch->ctx;
991 batch->scissor_culls_everything ||
992 !batch->rsd[PIPE_SHADER_VERTEX]);