panfrost: Extend the panfrost_batch_add_bo() API to pass access flags
[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_allocate.h"
32 #include "pan_resource.h"
33
34 #define PAN_REQ_MSAA (1 << 0)
35 #define PAN_REQ_DEPTH_WRITE (1 << 1)
36
37 /* A panfrost_batch corresponds to a bound FBO we're rendering to,
38 * collecting over multiple draws. */
39
40 struct panfrost_batch {
41 struct panfrost_context *ctx;
42 struct pipe_framebuffer_state key;
43
44 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
45 unsigned clear;
46
47 /* Packed clear values, indexed by both render target as well as word.
48 * Essentially, a single pixel is packed, with some padding to bring it
49 * up to a 32-bit interval; that pixel is then duplicated over to fill
50 * all 16-bytes */
51
52 uint32_t clear_color[PIPE_MAX_COLOR_BUFS][4];
53 float clear_depth;
54 unsigned clear_stencil;
55
56 /* Whether this job uses the corresponding requirement (PAN_REQ_*
57 * bitmask) */
58 unsigned requirements;
59
60 /* The bounding box covered by this job, taking scissors into account.
61 * Basically, the bounding box we have to run fragment shaders for */
62
63 unsigned minx, miny;
64 unsigned maxx, maxy;
65
66 /* CPU pointers to the job descriptor headers. next_job is only
67 * set at submit time (since only then are all the dependencies
68 * known). The upshot is that this is append-only.
69 *
70 * These arrays contain the headers for the "primary batch", our jargon
71 * referring to the part of the panfrost_job that actually contains
72 * meaningful work. In an OpenGL ES setting, that means the
73 * SET_VALUE/VERTEX/TILER jobs. Excluded is specifically the FRAGMENT
74 * job, which is sent on as a secondary batch containing only a single
75 * hardware job. Since there's one and only one FRAGMENT job issued per
76 * panfrost_job, there is no need to do any scoreboarding / management;
77 * it's easy enough to open-code it and it's not like we can get any
78 * better anyway. */
79 struct util_dynarray headers;
80
81 /* (And the GPU versions; TODO maybe combine) */
82 struct util_dynarray gpu_headers;
83
84 /* The last job in the primary batch */
85 struct panfrost_transfer last_job;
86
87 /* The first/last tiler job */
88 struct panfrost_transfer first_tiler;
89 struct panfrost_transfer last_tiler;
90
91 /* The first vertex job used as the input to a tiler job */
92 struct panfrost_transfer first_vertex_for_tiler;
93
94 /* The first job. Notice we've created a linked list */
95 struct panfrost_transfer first_job;
96
97 /* The number of jobs in the primary batch, essentially */
98 unsigned job_index;
99
100 /* BOs referenced -- will be used for flushing logic */
101 struct set *bos;
102
103 /* Current transient BO */
104 struct panfrost_bo *transient_bo;
105
106 /* Within the topmost transient BO, how much has been used? */
107 unsigned transient_offset;
108
109 /* Polygon list bound to the batch, or NULL if none bound yet */
110 struct panfrost_bo *polygon_list;
111
112 /* Scratchpath BO bound to the batch, or NULL if none bound yet */
113 struct panfrost_bo *scratchpad;
114
115 /* 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
121 /* Framebuffer descriptor. */
122 mali_ptr framebuffer;
123 };
124
125 /* Functions for managing the above */
126
127 struct panfrost_batch *
128 panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
129
130 void
131 panfrost_batch_init(struct panfrost_context *ctx);
132
133 void
134 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo,
135 uint32_t flags);
136
137 void panfrost_batch_add_fbo_bos(struct panfrost_batch *batch);
138
139 struct panfrost_bo *
140 panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
141 uint32_t create_flags, uint32_t access_flags);
142
143 void
144 panfrost_batch_submit(struct panfrost_batch *batch);
145
146 void
147 panfrost_batch_set_requirements(struct panfrost_batch *batch);
148
149 mali_ptr
150 panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size);
151
152 struct panfrost_bo *
153 panfrost_batch_get_scratchpad(struct panfrost_batch *batch);
154
155 struct panfrost_bo *
156 panfrost_batch_get_tiler_heap(struct panfrost_batch *batch);
157
158 struct panfrost_bo *
159 panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch);
160
161 void
162 panfrost_batch_clear(struct panfrost_batch *batch,
163 unsigned buffers,
164 const union pipe_color_union *color,
165 double depth, unsigned stencil);
166
167 void
168 panfrost_batch_union_scissor(struct panfrost_batch *batch,
169 unsigned minx, unsigned miny,
170 unsigned maxx, unsigned maxy);
171
172 void
173 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
174 unsigned minx, unsigned miny,
175 unsigned maxx, unsigned maxy);
176
177 /* Scoreboarding */
178
179 void
180 panfrost_scoreboard_queue_compute_job(
181 struct panfrost_batch *batch,
182 struct panfrost_transfer job);
183
184 void
185 panfrost_scoreboard_queue_vertex_job(
186 struct panfrost_batch *batch,
187 struct panfrost_transfer vertex,
188 bool requires_tiling);
189
190 void
191 panfrost_scoreboard_queue_tiler_job(
192 struct panfrost_batch *batch,
193 struct panfrost_transfer tiler);
194
195 void
196 panfrost_scoreboard_queue_fused_job(
197 struct panfrost_batch *batch,
198 struct panfrost_transfer vertex,
199 struct panfrost_transfer tiler);
200 void
201 panfrost_scoreboard_queue_fused_job_prepend(
202 struct panfrost_batch *batch,
203 struct panfrost_transfer vertex,
204 struct panfrost_transfer tiler);
205
206 void
207 panfrost_scoreboard_link_batch(struct panfrost_batch *batch);
208
209 bool
210 panfrost_batch_is_scanout(struct panfrost_batch *batch);
211
212 #endif