746862e9c575e62df8005c087312c6272b61f42d
[mesa.git] / src / gallium / drivers / panfrost / pan_job.h
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 "util/u_dynarray.h"
30 #include "pipe/p_state.h"
31 #include "pan_pool.h"
32 #include "pan_resource.h"
33 #include "pan_scoreboard.h"
34
35 /* 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 */
40 struct 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;
49
50 /* Context this fence is attached to. We need both ctx and batch, as
51 * the batch will go away after it's been submitted, but the fence
52 * will stay a bit longer.
53 */
54 struct panfrost_context *ctx;
55
56 /* Cached value of the signaled state to avoid calling WAIT_SYNCOBJs
57 * when we know the fence has already been signaled.
58 */
59 bool signaled;
60 };
61
62 #define PAN_REQ_MSAA (1 << 0)
63 #define PAN_REQ_DEPTH_WRITE (1 << 1)
64
65 /* A panfrost_batch corresponds to a bound FBO we're rendering to,
66 * collecting over multiple draws. */
67
68 struct panfrost_batch {
69 struct panfrost_context *ctx;
70 struct pipe_framebuffer_state key;
71
72 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
73 unsigned clear;
74
75 /* Buffers drawn */
76 unsigned draws;
77
78 /* Packed clear values, indexed by both render target as well as word.
79 * Essentially, a single pixel is packed, with some padding to bring it
80 * up to a 32-bit interval; that pixel is then duplicated over to fill
81 * all 16-bytes */
82
83 uint32_t clear_color[PIPE_MAX_COLOR_BUFS][4];
84 float clear_depth;
85 unsigned clear_stencil;
86
87 /* Amount of thread local storage required per thread */
88 unsigned stack_size;
89
90 /* Amount of shared memory needed per workgroup (for compute) */
91 unsigned shared_size;
92
93 /* Whether this job uses the corresponding requirement (PAN_REQ_*
94 * bitmask) */
95 unsigned requirements;
96
97 /* The bounding box covered by this job, taking scissors into account.
98 * Basically, the bounding box we have to run fragment shaders for */
99
100 unsigned minx, miny;
101 unsigned maxx, maxy;
102
103 /* BOs referenced not in the pool */
104 struct hash_table *bos;
105
106 /* Pool owned by this batch (released when the batch is released) used for temporary descriptors */
107 struct pan_pool pool;
108
109 /* Job scoreboarding state */
110 struct pan_scoreboard scoreboard;
111
112 /* Polygon list bound to the batch, or NULL if none bound yet */
113 struct panfrost_bo *polygon_list;
114
115 /* Scratchpad BO bound to the batch, or NULL if none bound yet */
116 struct panfrost_bo *scratchpad;
117
118 /* Shared memory BO bound to the batch, or NULL if none bound yet */
119 struct panfrost_bo *shared_memory;
120
121 /* Tiler heap BO bound to the batch, or NULL if none bound yet */
122 struct panfrost_bo *tiler_heap;
123
124 /* Dummy tiler BO bound to the batch, or NULL if none bound yet */
125 struct panfrost_bo *tiler_dummy;
126
127 /* Framebuffer descriptor. */
128 struct panfrost_transfer framebuffer;
129
130 /* Bifrost tiler meta descriptor. */
131 mali_ptr tiler_meta;
132
133 /* Output sync object. Only valid when submitted is true. */
134 struct panfrost_batch_fence *out_sync;
135
136 /* Batch dependencies */
137 struct util_dynarray dependencies;
138 };
139
140 /* Functions for managing the above */
141
142 void
143 panfrost_batch_fence_unreference(struct panfrost_batch_fence *fence);
144
145 void
146 panfrost_batch_fence_reference(struct panfrost_batch_fence *batch);
147
148 struct panfrost_batch *
149 panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
150
151 struct panfrost_batch *
152 panfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx);
153
154 void
155 panfrost_batch_init(struct panfrost_context *ctx);
156
157 void
158 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
159 uint32_t flags);
160
161 void panfrost_batch_add_fbo_bos(struct panfrost_batch *batch);
162
163 struct panfrost_bo *
164 panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
165 uint32_t create_flags, uint32_t access_flags);
166
167 void
168 panfrost_flush_all_batches(struct panfrost_context *ctx, uint32_t out_sync);
169
170 bool
171 panfrost_pending_batches_access_bo(struct panfrost_context *ctx,
172 const struct panfrost_bo *bo);
173
174 void
175 panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx,
176 struct panfrost_bo *bo, bool flush_readers);
177
178 void
179 panfrost_batch_set_requirements(struct panfrost_batch *batch);
180
181 void
182 panfrost_batch_adjust_stack_size(struct panfrost_batch *batch);
183
184 struct panfrost_bo *
185 panfrost_batch_get_scratchpad(struct panfrost_batch *batch, unsigned shift, unsigned thread_tls_alloc, unsigned core_count);
186
187 struct panfrost_bo *
188 panfrost_batch_get_shared_memory(struct panfrost_batch *batch, unsigned size, unsigned workgroup_count);
189
190 mali_ptr
191 panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size);
192
193 struct panfrost_bo *
194 panfrost_batch_get_tiler_heap(struct panfrost_batch *batch);
195
196 struct panfrost_bo *
197 panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch);
198
199 void
200 panfrost_batch_clear(struct panfrost_batch *batch,
201 unsigned buffers,
202 const union pipe_color_union *color,
203 double depth, unsigned stencil);
204
205 void
206 panfrost_batch_union_scissor(struct panfrost_batch *batch,
207 unsigned minx, unsigned miny,
208 unsigned maxx, unsigned maxy);
209
210 void
211 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
212 unsigned minx, unsigned miny,
213 unsigned maxx, unsigned maxy);
214
215 bool
216 panfrost_batch_is_scanout(struct panfrost_batch *batch);
217
218 mali_ptr
219 panfrost_batch_get_tiler_meta(struct panfrost_batch *batch, unsigned vertex_count);
220
221 mali_ptr
222 panfrost_batch_reserve_framebuffer(struct panfrost_batch *batch);
223
224 #endif