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
29 #include "util/u_dynarray.h"
30 #include "pipe/p_state.h"
31 #include "pan_allocate.h"
32 #include "pan_resource.h"
34 /* panfrost_batch_fence is the out fence of a batch that users or other batches
35 * might want to wait on. The batch fence lifetime is different from the batch
36 * one as want will certainly want to wait upon the fence after the batch has
37 * been submitted (which is when panfrost_batch objects are freed).
39 struct panfrost_batch_fence
{
40 /* Refcounting object for the fence. */
41 struct pipe_reference reference
;
43 /* Batch that created this fence object. Will become NULL at batch
44 * submission time. This field is mainly here to know whether the
45 * batch has been flushed or not.
47 struct panfrost_batch
*batch
;
49 /* Context this fence is attached to. We need both ctx and batch, as
50 * the batch will go away after it's been submitted, but the fence
51 * will stay a bit longer.
53 struct panfrost_context
*ctx
;
55 /* Sync object backing this fence. */
58 /* Cached value of the signaled state to avoid calling WAIT_SYNCOBJs
59 * when we know the fence has already been signaled.
64 #define PAN_REQ_MSAA (1 << 0)
65 #define PAN_REQ_DEPTH_WRITE (1 << 1)
67 /* A panfrost_batch corresponds to a bound FBO we're rendering to,
68 * collecting over multiple draws. */
70 struct panfrost_batch
{
71 struct panfrost_context
*ctx
;
72 struct pipe_framebuffer_state key
;
74 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
77 /* Packed clear values, indexed by both render target as well as word.
78 * Essentially, a single pixel is packed, with some padding to bring it
79 * up to a 32-bit interval; that pixel is then duplicated over to fill
82 uint32_t clear_color
[PIPE_MAX_COLOR_BUFS
][4];
84 unsigned clear_stencil
;
86 /* Whether this job uses the corresponding requirement (PAN_REQ_*
88 unsigned requirements
;
90 /* The bounding box covered by this job, taking scissors into account.
91 * Basically, the bounding box we have to run fragment shaders for */
96 /* CPU pointers to the job descriptor headers. next_job is only
97 * set at submit time (since only then are all the dependencies
98 * known). The upshot is that this is append-only.
100 * These arrays contain the headers for the "primary batch", our jargon
101 * referring to the part of the panfrost_job that actually contains
102 * meaningful work. In an OpenGL ES setting, that means the
103 * SET_VALUE/VERTEX/TILER jobs. Excluded is specifically the FRAGMENT
104 * job, which is sent on as a secondary batch containing only a single
105 * hardware job. Since there's one and only one FRAGMENT job issued per
106 * panfrost_job, there is no need to do any scoreboarding / management;
107 * it's easy enough to open-code it and it's not like we can get any
109 struct util_dynarray headers
;
111 /* (And the GPU versions; TODO maybe combine) */
112 struct util_dynarray gpu_headers
;
114 /* The last job in the primary batch */
115 struct panfrost_transfer last_job
;
117 /* The first/last tiler job */
118 struct panfrost_transfer first_tiler
;
119 struct panfrost_transfer last_tiler
;
121 /* The first vertex job used as the input to a tiler job */
122 struct panfrost_transfer first_vertex_for_tiler
;
124 /* The first job. Notice we've created a linked list */
125 struct panfrost_transfer first_job
;
127 /* The number of jobs in the primary batch, essentially */
130 /* BOs referenced -- will be used for flushing logic */
131 struct hash_table
*bos
;
133 /* Current transient BO */
134 struct panfrost_bo
*transient_bo
;
136 /* Within the topmost transient BO, how much has been used? */
137 unsigned transient_offset
;
139 /* Polygon list bound to the batch, or NULL if none bound yet */
140 struct panfrost_bo
*polygon_list
;
142 /* Scratchpath BO bound to the batch, or NULL if none bound yet */
143 struct panfrost_bo
*scratchpad
;
145 /* Tiler heap BO bound to the batch, or NULL if none bound yet */
146 struct panfrost_bo
*tiler_heap
;
148 /* Dummy tiler BO bound to the batch, or NULL if none bound yet */
149 struct panfrost_bo
*tiler_dummy
;
151 /* Framebuffer descriptor. */
152 mali_ptr framebuffer
;
154 /* Output sync object. Only valid when submitted is true. */
155 struct panfrost_batch_fence
*out_sync
;
157 /* Batch dependencies */
158 struct util_dynarray dependencies
;
161 /* Functions for managing the above */
164 panfrost_batch_fence_unreference(struct panfrost_batch_fence
*fence
);
167 panfrost_batch_fence_reference(struct panfrost_batch_fence
*batch
);
169 struct panfrost_batch
*
170 panfrost_get_batch_for_fbo(struct panfrost_context
*ctx
);
173 panfrost_batch_init(struct panfrost_context
*ctx
);
176 panfrost_batch_add_bo(struct panfrost_batch
*batch
, struct panfrost_bo
*bo
,
179 void panfrost_batch_add_fbo_bos(struct panfrost_batch
*batch
);
182 panfrost_batch_create_bo(struct panfrost_batch
*batch
, size_t size
,
183 uint32_t create_flags
, uint32_t access_flags
);
186 panfrost_batch_submit(struct panfrost_batch
*batch
);
189 panfrost_batch_set_requirements(struct panfrost_batch
*batch
);
192 panfrost_batch_get_polygon_list(struct panfrost_batch
*batch
, unsigned size
);
195 panfrost_batch_get_scratchpad(struct panfrost_batch
*batch
);
198 panfrost_batch_get_tiler_heap(struct panfrost_batch
*batch
);
201 panfrost_batch_get_tiler_dummy(struct panfrost_batch
*batch
);
204 panfrost_batch_clear(struct panfrost_batch
*batch
,
206 const union pipe_color_union
*color
,
207 double depth
, unsigned stencil
);
210 panfrost_batch_union_scissor(struct panfrost_batch
*batch
,
211 unsigned minx
, unsigned miny
,
212 unsigned maxx
, unsigned maxy
);
215 panfrost_batch_intersection_scissor(struct panfrost_batch
*batch
,
216 unsigned minx
, unsigned miny
,
217 unsigned maxx
, unsigned maxy
);
222 panfrost_scoreboard_queue_compute_job(
223 struct panfrost_batch
*batch
,
224 struct panfrost_transfer job
);
227 panfrost_scoreboard_queue_vertex_job(
228 struct panfrost_batch
*batch
,
229 struct panfrost_transfer vertex
,
230 bool requires_tiling
);
233 panfrost_scoreboard_queue_tiler_job(
234 struct panfrost_batch
*batch
,
235 struct panfrost_transfer tiler
);
238 panfrost_scoreboard_queue_fused_job(
239 struct panfrost_batch
*batch
,
240 struct panfrost_transfer vertex
,
241 struct panfrost_transfer tiler
);
243 panfrost_scoreboard_queue_fused_job_prepend(
244 struct panfrost_batch
*batch
,
245 struct panfrost_transfer vertex
,
246 struct panfrost_transfer tiler
);
249 panfrost_scoreboard_link_batch(struct panfrost_batch
*batch
);
252 panfrost_batch_is_scanout(struct panfrost_batch
*batch
);