panfrost: Implement command stream scoreboarding
[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_job_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_job corresponds to a bound FBO we're rendering to,
45 * collecting over multiple draws. */
46
47 struct panfrost_job {
48 struct panfrost_context *ctx;
49 struct panfrost_job_key key;
50
51 /* Buffers cleared (PIPE_CLEAR_* bitmask) */
52 unsigned clear;
53
54 /* Packed clear values */
55 uint32_t clear_color;
56 float clear_depth;
57 unsigned clear_stencil;
58
59 /* Whether this job uses the corresponding requirement (PAN_REQ_*
60 * bitmask) */
61 unsigned requirements;
62
63 /* The bounding box covered by this job, taking scissors into account.
64 * Basically, the bounding box we have to run fragment shaders for */
65
66 unsigned minx, miny;
67 unsigned maxx, maxy;
68
69 /* CPU pointers to the job descriptor headers. next_job is only
70 * set at submit time (since only then are all the dependencies
71 * known). The upshot is that this is append-only.
72 *
73 * These arrays contain the headers for the "primary batch", our jargon
74 * referring to the part of the panfrost_job that actually contains
75 * meaningful work. In an OpenGL ES setting, that means the
76 * SET_VALUE/VERTEX/TILER jobs. Excluded is specifically the FRAGMENT
77 * job, which is sent on as a secondary batch containing only a single
78 * hardware job. Since there's one and only one FRAGMENT job issued per
79 * panfrost_job, there is no need to do any scoreboarding / management;
80 * it's easy enough to open-code it and it's not like we can get any
81 * better anyway. */
82 struct util_dynarray headers;
83
84 /* (And the GPU versions; TODO maybe combine) */
85 struct util_dynarray gpu_headers;
86
87 /* The last job in the primary batch */
88 struct panfrost_transfer last_job;
89
90 /* The first/last tiler job */
91 struct panfrost_transfer first_tiler;
92 struct panfrost_transfer last_tiler;
93
94 /* The first vertex job used as the input to a tiler job */
95 struct panfrost_transfer first_vertex_for_tiler;
96
97 /* The first job. Notice we've created a linked list */
98 struct panfrost_transfer first_job;
99
100 /* The number of jobs in the primary batch, essentially */
101 unsigned job_index;
102
103 /* BOs referenced -- will be used for flushing logic */
104 struct set *bos;
105 };
106
107 /* Functions for managing the above */
108
109 struct panfrost_job *
110 panfrost_create_job(struct panfrost_context *ctx);
111
112 void
113 panfrost_free_job(struct panfrost_context *ctx, struct panfrost_job *job);
114
115 struct panfrost_job *
116 panfrost_get_job(struct panfrost_context *ctx,
117 struct pipe_surface **cbufs, struct pipe_surface *zsbuf);
118
119 struct panfrost_job *
120 panfrost_get_job_for_fbo(struct panfrost_context *ctx);
121
122 void
123 panfrost_job_init(struct panfrost_context *ctx);
124
125 void
126 panfrost_job_add_bo(struct panfrost_job *job, struct panfrost_bo *bo);
127
128 void
129 panfrost_flush_jobs_writing_resource(struct panfrost_context *panfrost,
130 struct pipe_resource *prsc);
131
132 void
133 panfrost_flush_jobs_reading_resource(struct panfrost_context *panfrost,
134 struct pipe_resource *prsc);
135
136 void
137 panfrost_job_submit(struct panfrost_context *ctx, struct panfrost_job *job);
138
139 void
140 panfrost_job_set_requirements(struct panfrost_context *ctx,
141 struct panfrost_job *job);
142
143 void
144 panfrost_job_clear(struct panfrost_context *ctx,
145 struct panfrost_job *job,
146 unsigned buffers,
147 const union pipe_color_union *color,
148 double depth, unsigned stencil);
149
150 void
151 panfrost_job_union_scissor(struct panfrost_job *job,
152 unsigned minx, unsigned miny,
153 unsigned maxx, unsigned maxy);
154
155 /* Scoreboarding */
156
157 void
158 panfrost_scoreboard_queue_compute_job(
159 struct panfrost_job *batch,
160 struct panfrost_transfer job);
161
162 void
163 panfrost_scoreboard_queue_vertex_job(
164 struct panfrost_job *batch,
165 struct panfrost_transfer vertex,
166 bool requires_tiling);
167
168 void
169 panfrost_scoreboard_queue_tiler_job(
170 struct panfrost_job *batch,
171 struct panfrost_transfer tiler);
172
173 void
174 panfrost_scoreboard_queue_fused_job(
175 struct panfrost_job *batch,
176 struct panfrost_transfer vertex,
177 struct panfrost_transfer tiler);
178 void
179 panfrost_scoreboard_queue_fused_job_prepend(
180 struct panfrost_job *batch,
181 struct panfrost_transfer vertex,
182 struct panfrost_transfer tiler);
183
184 void
185 panfrost_scoreboard_link_batch(struct panfrost_job *batch);
186
187 #endif