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