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