7854e0a0f994f37b65e6489b40cf4c703e6a7bf1
[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
113 /* Functions for managing the above */
114
115 struct panfrost_batch *
116 panfrost_create_batch(struct panfrost_context *ctx,
117 const struct pipe_framebuffer_state *key);
118
119 void
120 panfrost_free_batch(struct panfrost_batch *batch);
121
122 struct panfrost_batch *
123 panfrost_get_batch(struct panfrost_context *ctx,
124 const struct pipe_framebuffer_state *key);
125
126 struct panfrost_batch *
127 panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
128
129 void
130 panfrost_batch_init(struct panfrost_context *ctx);
131
132 void
133 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo);
134
135 void
136 panfrost_flush_jobs_writing_resource(struct panfrost_context *panfrost,
137 struct pipe_resource *prsc);
138
139 void
140 panfrost_flush_jobs_reading_resource(struct panfrost_context *panfrost,
141 struct pipe_resource *prsc);
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 void
153 panfrost_batch_clear(struct panfrost_batch *batch,
154 unsigned buffers,
155 const union pipe_color_union *color,
156 double depth, unsigned stencil);
157
158 void
159 panfrost_batch_union_scissor(struct panfrost_batch *batch,
160 unsigned minx, unsigned miny,
161 unsigned maxx, unsigned maxy);
162
163 void
164 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
165 unsigned minx, unsigned miny,
166 unsigned maxx, unsigned maxy);
167
168 /* Scoreboarding */
169
170 void
171 panfrost_scoreboard_queue_compute_job(
172 struct panfrost_batch *batch,
173 struct panfrost_transfer job);
174
175 void
176 panfrost_scoreboard_queue_vertex_job(
177 struct panfrost_batch *batch,
178 struct panfrost_transfer vertex,
179 bool requires_tiling);
180
181 void
182 panfrost_scoreboard_queue_tiler_job(
183 struct panfrost_batch *batch,
184 struct panfrost_transfer tiler);
185
186 void
187 panfrost_scoreboard_queue_fused_job(
188 struct panfrost_batch *batch,
189 struct panfrost_transfer vertex,
190 struct panfrost_transfer tiler);
191 void
192 panfrost_scoreboard_queue_fused_job_prepend(
193 struct panfrost_batch *batch,
194 struct panfrost_transfer vertex,
195 struct panfrost_transfer tiler);
196
197 void
198 panfrost_scoreboard_link_batch(struct panfrost_batch *batch);
199
200 #endif