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 #ifndef __PAN_JOB_H__
27 #define __PAN_JOB_H__
28
29 #include "pipe/p_state.h"
30 #include "util/u_dynarray.h"
31 #include "util/u_tristate.h"
32 #include "pan_csf.h"
33 #include "pan_desc.h"
34 #include "pan_jm.h"
35 #include "pan_mempool.h"
36 #include "pan_resource.h"
37
38 /* A panfrost_batch corresponds to a bound FBO we're rendering to,
39 * collecting over multiple draws. */
40
41 struct panfrost_batch {
42 struct panfrost_context *ctx;
43 struct pipe_framebuffer_state key;
44
45 /* Sequence number used to implement LRU eviction when all batch slots are
46 * used */
47 uint64_t seqnum;
48
49 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
50 unsigned clear;
51
52 /* Buffers drawn */
53 unsigned draws;
54
55 /* Buffers read */
56 unsigned read;
57
58 /* Buffers needing resolve to memory */
59 unsigned resolve;
60
61 /* Packed clear values, indexed by both render target as well as word.
62 * Essentially, a single pixel is packed, with some padding to bring it
63 * up to a 32-bit interval; that pixel is then duplicated over to fill
64 * all 16-bytes */
65
66 uint32_t clear_color[PIPE_MAX_COLOR_BUFS][4];
67 float clear_depth;
68 unsigned clear_stencil;
69
70 /* Amount of thread local storage required per thread */
71 unsigned stack_size;
72
73 /* Amount of shared memory needed per workgroup (for compute) */
74 unsigned shared_size;
75
76 /* The bounding box covered by this job, taking scissors into account.
77 * Basically, the bounding box we have to run fragment shaders for */
78
79 unsigned minx, miny;
80 unsigned maxx, maxy;
81
82 /* Acts as a rasterizer discard */
83 bool scissor_culls_everything;
84
85 /* BOs referenced not in the pool */
86 unsigned num_bos;
87 struct util_dynarray bos;
88
89 /* Pool owned by this batch (released when the batch is released) used for
90 * temporary descriptors */
91 struct panfrost_pool pool;
92
93 /* Pool also owned by this batch that is not CPU mapped (created as
94 * INVISIBLE) used for private GPU-internal structures, particularly
95 * varyings */
96 struct panfrost_pool invisible_pool;
97
98 /* Scratchpad BO bound to the batch, or NULL if none bound yet */
99 struct panfrost_bo *scratchpad;
100
101 /* Shared memory BO bound to the batch, or NULL if none bound yet */
102 struct panfrost_bo *shared_memory;
103
104 /* Framebuffer descriptor. */
105 struct panfrost_ptr framebuffer;
106
107 /* Thread local storage descriptor. */
108 struct panfrost_ptr tls;
109
110 /* Vertex count */
111 uint32_t vertex_count;
112
113 /* Tiler context */
114 struct pan_tiler_context tiler_ctx;
115
116 /* Only used on midgard. */
117 struct panfrost_bo *polygon_list_bo;
118
119 /* Keep the num_work_groups sysval around for indirect dispatch */
120 uint64_t num_wg_sysval[3];
121
122 /* Cached descriptors */
123 uint64_t viewport;
124 uint64_t rsd[PIPE_SHADER_TYPES];
125 uint64_t textures[PIPE_SHADER_TYPES];
126 uint64_t samplers[PIPE_SHADER_TYPES];
127 uint64_t attribs[PIPE_SHADER_TYPES];
128 uint64_t attrib_bufs[PIPE_SHADER_TYPES];
129 uint64_t uniform_buffers[PIPE_SHADER_TYPES];
130 uint64_t push_uniforms[PIPE_SHADER_TYPES];
131 uint64_t depth_stencil;
132 uint64_t blend;
133
134 unsigned nr_push_uniforms[PIPE_SHADER_TYPES];
135 unsigned nr_uniform_buffers[PIPE_SHADER_TYPES];
136
137 /* Varying related pointers */
138 struct {
139 uint64_t bufs;
140 unsigned nr_bufs;
141 uint64_t vs;
142 uint64_t fs;
143 uint64_t pos;
144 uint64_t psiz;
145 } varyings;
146
147 /* Index array */
148 uint64_t indices;
149
150 /* Valhall: struct mali_scissor_packed */
151 unsigned scissor[2];
152 float minimum_z, maximum_z;
153
154 /* Used on Valhall only. Midgard includes attributes in-band with
155 * attributes, wildly enough.
156 */
157 uint64_t images[PIPE_SHADER_TYPES];
158
159 /* SSBOs. */
160 uint64_t ssbos[PIPE_SHADER_TYPES];
161
162 /* On Valhall, these are properties of the batch. On Bifrost, they are
163 * per draw.
164 */
165 enum u_tristate sprite_coord_origin;
166 enum u_tristate first_provoking_vertex;
167
168 /** This one is always on the batch */
169 enum u_tristate line_smoothing;
170
171 /* Number of effective draws in the batch. Draws with rasterization disabled
172 * don't count as effective draws. It's basically the number of IDVS or
173 * <vertex,tiler> jobs present in the batch.
174 */
175 uint32_t draw_count;
176
177 /* Number of compute jobs in the batch. */
178 uint32_t compute_count;
179
180 /* Set when cycle count is required for this batch. */
181 bool need_job_req_cycle_count;
182
183 /* The batch contains a time query. */
184 bool has_time_query;
185
186 /* Job frontend specific fields. */
187 union {
188 struct panfrost_jm_batch jm;
189 struct panfrost_csf_batch csf;
190 };
191 };
192
193 /* Functions for managing the above */
194
195 struct panfrost_batch *panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
196
197 struct panfrost_batch *
198 panfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx,
199 const char *reason);
200
201 void panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
202 enum pipe_shader_type stage);
203
204 void panfrost_batch_write_bo(struct panfrost_batch *batch,
205 struct panfrost_bo *bo,
206 enum pipe_shader_type stage);
207
208 void panfrost_batch_read_rsrc(struct panfrost_batch *batch,
209 struct panfrost_resource *rsrc,
210 enum pipe_shader_type stage);
211
212 void panfrost_batch_write_rsrc(struct panfrost_batch *batch,
213 struct panfrost_resource *rsrc,
214 enum pipe_shader_type stage);
215
216 bool panfrost_any_batch_reads_rsrc(struct panfrost_context *ctx,
217 struct panfrost_resource *rsrc);
218
219 bool panfrost_any_batch_writes_rsrc(struct panfrost_context *ctx,
220 struct panfrost_resource *rsrc);
221
222 struct panfrost_bo *panfrost_batch_create_bo(struct panfrost_batch *batch,
223 size_t size, uint32_t create_flags,
224 enum pipe_shader_type stage,
225 const char *label);
226
227 void panfrost_flush_all_batches(struct panfrost_context *ctx,
228 const char *reason);
229
230 void panfrost_flush_batches_accessing_rsrc(struct panfrost_context *ctx,
231 struct panfrost_resource *rsrc,
232 const char *reason);
233
234 void panfrost_flush_writer(struct panfrost_context *ctx,
235 struct panfrost_resource *rsrc, const char *reason);
236
237 void panfrost_batch_adjust_stack_size(struct panfrost_batch *batch);
238
239 struct panfrost_bo *panfrost_batch_get_scratchpad(struct panfrost_batch *batch,
240 unsigned size,
241 unsigned thread_tls_alloc,
242 unsigned core_id_range);
243
244 struct panfrost_bo *
245 panfrost_batch_get_shared_memory(struct panfrost_batch *batch, unsigned size,
246 unsigned workgroup_count);
247
248 void panfrost_batch_clear(struct panfrost_batch *batch, unsigned buffers,
249 const union pipe_color_union *color, double depth,
250 unsigned stencil);
251
252 void panfrost_batch_union_scissor(struct panfrost_batch *batch, unsigned minx,
253 unsigned miny, unsigned maxx, unsigned maxy);
254
255 bool panfrost_batch_skip_rasterization(struct panfrost_batch *batch);
256
257 static inline bool
panfrost_has_fragment_job(struct panfrost_batch * batch)258 panfrost_has_fragment_job(struct panfrost_batch *batch)
259 {
260 return batch->draw_count > 0 || batch->clear;
261 }
262
263 #endif
264