panfrost: Prepare things to avoid flushes on FB switch
[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 /* Framebuffer descriptor. */
113 mali_ptr framebuffer;
114 };
115
116 /* Functions for managing the above */
117
118 struct panfrost_batch *
119 panfrost_create_batch(struct panfrost_context *ctx,
120 const struct pipe_framebuffer_state *key);
121
122 void
123 panfrost_free_batch(struct panfrost_batch *batch);
124
125 struct panfrost_batch *
126 panfrost_get_batch(struct panfrost_context *ctx,
127 const struct pipe_framebuffer_state *key);
128
129 struct panfrost_batch *
130 panfrost_get_batch_for_fbo(struct panfrost_context *ctx);
131
132 void
133 panfrost_batch_init(struct panfrost_context *ctx);
134
135 void
136 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo);
137
138 void
139 panfrost_batch_submit(struct panfrost_batch *batch);
140
141 void
142 panfrost_batch_set_requirements(struct panfrost_batch *batch);
143
144 mali_ptr
145 panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size);
146
147 void
148 panfrost_batch_clear(struct panfrost_batch *batch,
149 unsigned buffers,
150 const union pipe_color_union *color,
151 double depth, unsigned stencil);
152
153 void
154 panfrost_batch_union_scissor(struct panfrost_batch *batch,
155 unsigned minx, unsigned miny,
156 unsigned maxx, unsigned maxy);
157
158 void
159 panfrost_batch_intersection_scissor(struct panfrost_batch *batch,
160 unsigned minx, unsigned miny,
161 unsigned maxx, unsigned maxy);
162
163 /* Scoreboarding */
164
165 void
166 panfrost_scoreboard_queue_compute_job(
167 struct panfrost_batch *batch,
168 struct panfrost_transfer job);
169
170 void
171 panfrost_scoreboard_queue_vertex_job(
172 struct panfrost_batch *batch,
173 struct panfrost_transfer vertex,
174 bool requires_tiling);
175
176 void
177 panfrost_scoreboard_queue_tiler_job(
178 struct panfrost_batch *batch,
179 struct panfrost_transfer tiler);
180
181 void
182 panfrost_scoreboard_queue_fused_job(
183 struct panfrost_batch *batch,
184 struct panfrost_transfer vertex,
185 struct panfrost_transfer tiler);
186 void
187 panfrost_scoreboard_queue_fused_job_prepend(
188 struct panfrost_batch *batch,
189 struct panfrost_transfer vertex,
190 struct panfrost_transfer tiler);
191
192 void
193 panfrost_scoreboard_link_batch(struct panfrost_batch *batch);
194
195 bool
196 panfrost_batch_is_scanout(struct panfrost_batch *batch);
197
198 #endif