blob: 2a61980a0c3c8ca97bc90fcb4a3fdb05d680707d [file] [log] [blame]
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +00001/*
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#ifndef __PAN_JOB_H__
27#define __PAN_JOB_H__
28
Alyssa Rosenzweigf0854742019-06-19 11:27:59 -070029#include "util/u_dynarray.h"
30#include "pipe/p_state.h"
Alyssa Rosenzweigc8d848b2020-07-07 16:24:41 -040031#include "pan_pool.h"
Alyssa Rosenzweigf0854742019-06-19 11:27:59 -070032#include "pan_resource.h"
Alyssa Rosenzweig31197c22020-07-07 17:07:34 -040033#include "pan_scoreboard.h"
Alyssa Rosenzweigf0854742019-06-19 11:27:59 -070034
Boris Brezillon6936b7f2019-09-15 10:27:07 +020035/* panfrost_batch_fence is the out fence of a batch that users or other batches
36 * might want to wait on. The batch fence lifetime is different from the batch
37 * one as want will certainly want to wait upon the fence after the batch has
38 * been submitted (which is when panfrost_batch objects are freed).
39 */
40struct panfrost_batch_fence {
41 /* Refcounting object for the fence. */
42 struct pipe_reference reference;
43
44 /* Batch that created this fence object. Will become NULL at batch
45 * submission time. This field is mainly here to know whether the
46 * batch has been flushed or not.
47 */
48 struct panfrost_batch *batch;
Boris Brezillon6936b7f2019-09-15 10:27:07 +020049};
50
Alyssa Rosenzweig8c268902019-03-12 23:16:37 +000051#define PAN_REQ_MSAA (1 << 0)
52#define PAN_REQ_DEPTH_WRITE (1 << 1)
53
Boris Brezillon2c526992019-09-05 21:41:26 +020054/* A panfrost_batch corresponds to a bound FBO we're rendering to,
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +000055 * collecting over multiple draws. */
56
Boris Brezillon2c526992019-09-05 21:41:26 +020057struct panfrost_batch {
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +000058 struct panfrost_context *ctx;
Boris Brezillon1b5873b2019-09-01 10:24:30 +020059 struct pipe_framebuffer_state key;
Alyssa Rosenzweig40ffee42019-02-26 23:51:34 +000060
61 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
62 unsigned clear;
63
Alyssa Rosenzweig5d0d8fa2020-07-15 17:35:58 -040064 /* Buffers drawn */
65 unsigned draws;
66
Alyssa Rosenzweig8e4e4672019-07-01 11:49:06 -070067 /* Packed clear values, indexed by both render target as well as word.
68 * Essentially, a single pixel is packed, with some padding to bring it
69 * up to a 32-bit interval; that pixel is then duplicated over to fill
70 * all 16-bytes */
71
72 uint32_t clear_color[PIPE_MAX_COLOR_BUFS][4];
Alyssa Rosenzweig40ffee42019-02-26 23:51:34 +000073 float clear_depth;
74 unsigned clear_stencil;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +000075
Alyssa Rosenzweigbc887e82019-12-09 11:18:47 -050076 /* Amount of thread local storage required per thread */
77 unsigned stack_size;
78
Alyssa Rosenzweig96031262020-02-06 14:29:42 -050079 /* Amount of shared memory needed per workgroup (for compute) */
80 unsigned shared_size;
81
Alyssa Rosenzweig8c268902019-03-12 23:16:37 +000082 /* Whether this job uses the corresponding requirement (PAN_REQ_*
83 * bitmask) */
84 unsigned requirements;
85
Alyssa Rosenzweigc3788292019-06-18 12:30:55 -070086 /* The bounding box covered by this job, taking scissors into account.
87 * Basically, the bounding box we have to run fragment shaders for */
88
89 unsigned minx, miny;
90 unsigned maxx, maxy;
91
Alyssa Rosenzweig8882d6a2020-07-07 14:46:40 -040092 /* BOs referenced not in the pool */
Boris Brezillona8bd2652019-09-15 09:27:14 +020093 struct hash_table *bos;
Alyssa Rosenzweig0f5ad9e2019-07-12 12:53:36 -070094
Alyssa Rosenzweig8882d6a2020-07-07 14:46:40 -040095 /* Pool owned by this batch (released when the batch is released) used for temporary descriptors */
96 struct pan_pool pool;
Alyssa Rosenzweigcd98d942019-08-02 19:18:48 +020097
Alyssa Rosenzweig17c617c2020-08-17 10:31:02 -040098 /* Pool also owned by this batch that is not CPU mapped (created as
99 * INVISIBLE) used for private GPU-internal structures, particularly
100 * varyings */
101 struct pan_pool invisible_pool;
102
Alyssa Rosenzweig31197c22020-07-07 17:07:34 -0400103 /* Job scoreboarding state */
104 struct pan_scoreboard scoreboard;
105
Alyssa Rosenzweigcd98d942019-08-02 19:18:48 +0200106 /* Polygon list bound to the batch, or NULL if none bound yet */
107 struct panfrost_bo *polygon_list;
Boris Brezillon4166ca92019-09-05 19:07:12 +0200108
Alyssa Rosenzweig96031262020-02-06 14:29:42 -0500109 /* Scratchpad BO bound to the batch, or NULL if none bound yet */
Boris Brezillon1e483a82019-09-14 19:18:51 +0200110 struct panfrost_bo *scratchpad;
111
Alyssa Rosenzweig96031262020-02-06 14:29:42 -0500112 /* Shared memory BO bound to the batch, or NULL if none bound yet */
113 struct panfrost_bo *shared_memory;
114
Boris Brezillon1e483a82019-09-14 19:18:51 +0200115 /* Tiler heap BO bound to the batch, or NULL if none bound yet */
116 struct panfrost_bo *tiler_heap;
117
118 /* Dummy tiler BO bound to the batch, or NULL if none bound yet */
119 struct panfrost_bo *tiler_dummy;
120
Boris Brezillon4166ca92019-09-05 19:07:12 +0200121 /* Framebuffer descriptor. */
Alyssa Rosenzweigb0e915b2019-12-09 11:00:42 -0500122 struct panfrost_transfer framebuffer;
Boris Brezillon6936b7f2019-09-15 10:27:07 +0200123
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200124 /* Bifrost tiler meta descriptor. */
125 mali_ptr tiler_meta;
126
Boris Brezillon6936b7f2019-09-15 10:27:07 +0200127 /* Output sync object. Only valid when submitted is true. */
128 struct panfrost_batch_fence *out_sync;
Boris Brezillon2dad9fd2019-09-15 13:39:52 +0200129
130 /* Batch dependencies */
131 struct util_dynarray dependencies;
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +0000132};
133
134/* Functions for managing the above */
135
Boris Brezillon6936b7f2019-09-15 10:27:07 +0200136void
137panfrost_batch_fence_unreference(struct panfrost_batch_fence *fence);
138
139void
140panfrost_batch_fence_reference(struct panfrost_batch_fence *batch);
141
Boris Brezillon2c526992019-09-05 21:41:26 +0200142struct panfrost_batch *
Boris Brezillon2c526992019-09-05 21:41:26 +0200143panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +0000144
Boris Brezillonc138ca82019-09-19 15:52:02 +0200145struct panfrost_batch *
146panfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx);
147
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +0000148void
Boris Brezillon2c526992019-09-05 21:41:26 +0200149panfrost_batch_init(struct panfrost_context *ctx);
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +0000150
Alyssa Rosenzweige008d4f2019-04-14 22:42:44 +0000151void
Boris Brezillonada752a2019-09-15 09:21:13 +0200152panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
153 uint32_t flags);
Alyssa Rosenzweige008d4f2019-04-14 22:42:44 +0000154
Boris Brezillon5a4d0952019-09-14 17:57:06 +0200155struct panfrost_bo *
156panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
Boris Brezillonada752a2019-09-15 09:21:13 +0200157 uint32_t create_flags, uint32_t access_flags);
Boris Brezillon5a4d0952019-09-14 17:57:06 +0200158
Alyssa Rosenzweige008d4f2019-04-14 22:42:44 +0000159void
Alyssa Rosenzweig64d6f562020-07-20 13:34:42 -0400160panfrost_flush_all_batches(struct panfrost_context *ctx, uint32_t out_sync);
Rohan Gargbfca21b2019-06-05 17:49:14 +0200161
Boris Brezillon7fa5cd32019-10-10 15:12:30 +0200162bool
163panfrost_pending_batches_access_bo(struct panfrost_context *ctx,
164 const struct panfrost_bo *bo);
165
Rohan Gargbfca21b2019-06-05 17:49:14 +0200166void
Boris Brezillon82399b52019-09-15 20:17:14 +0200167panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
Alyssa Rosenzweigc6ebff32020-05-26 14:47:21 -0400168 struct panfrost_bo *bo, bool flush_readers);
Boris Brezillon82399b52019-09-15 20:17:14 +0200169
170void
Boris Brezillon12d8a172019-09-05 21:41:28 +0200171panfrost_batch_set_requirements(struct panfrost_batch *batch);
Rohan Gargad284f72019-06-05 19:04:04 +0200172
Boris Brezillon79f88502020-03-05 08:58:10 +0100173void
174panfrost_batch_adjust_stack_size(struct panfrost_batch *batch);
175
Alyssa Rosenzweig4f7fddb2019-12-09 11:02:15 -0500176struct panfrost_bo *
Alyssa Rosenzweigb41692c2020-08-17 12:30:49 -0400177panfrost_batch_get_scratchpad(struct panfrost_batch *batch, unsigned size, unsigned thread_tls_alloc, unsigned core_count);
Alyssa Rosenzweig4f7fddb2019-12-09 11:02:15 -0500178
Alyssa Rosenzweig96031262020-02-06 14:29:42 -0500179struct panfrost_bo *
180panfrost_batch_get_shared_memory(struct panfrost_batch *batch, unsigned size, unsigned workgroup_count);
181
Alyssa Rosenzweigcd98d942019-08-02 19:18:48 +0200182mali_ptr
Boris Brezillon2c526992019-09-05 21:41:26 +0200183panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size);
Alyssa Rosenzweigcd98d942019-08-02 19:18:48 +0200184
Boris Brezillon1e483a82019-09-14 19:18:51 +0200185struct panfrost_bo *
Boris Brezillon1e483a82019-09-14 19:18:51 +0200186panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch);
187
Rohan Gargad284f72019-06-05 19:04:04 +0200188void
Boris Brezillon12d8a172019-09-05 21:41:28 +0200189panfrost_batch_clear(struct panfrost_batch *batch,
Boris Brezillon2c526992019-09-05 21:41:26 +0200190 unsigned buffers,
191 const union pipe_color_union *color,
192 double depth, unsigned stencil);
Rohan Gargad284f72019-06-05 19:04:04 +0200193
Alyssa Rosenzweigc3788292019-06-18 12:30:55 -0700194void
Boris Brezillon2c526992019-09-05 21:41:26 +0200195panfrost_batch_union_scissor(struct panfrost_batch *batch,
196 unsigned minx, unsigned miny,
197 unsigned maxx, unsigned maxy);
Alyssa Rosenzweigc3788292019-06-18 12:30:55 -0700198
Boris Brezillon65ae86b2019-08-12 12:07:08 +0200199void
Boris Brezillon2c526992019-09-05 21:41:26 +0200200panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
201 unsigned minx, unsigned miny,
202 unsigned maxx, unsigned maxy);
Boris Brezillon65ae86b2019-08-12 12:07:08 +0200203
Boris Brezillone46d95d2019-09-01 10:54:38 +0200204bool
205panfrost_batch_is_scanout(struct panfrost_batch *batch);
206
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200207mali_ptr
Boris Brezillonefce73d2020-09-08 10:11:26 +0200208panfrost_batch_get_bifrost_tiler(struct panfrost_batch *batch, unsigned vertex_count);
Tomeu Vizoso46e42462020-04-08 15:58:42 +0200209
Alyssa Rosenzweig34a03102020-07-15 13:10:02 -0400210mali_ptr
211panfrost_batch_reserve_framebuffer(struct panfrost_batch *batch);
212
Alyssa Rosenzweig59c96232019-02-25 05:32:16 +0000213#endif