Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/lib/pan_scoreboard.c
4560 views
1
/*
2
* Copyright (C) 2019 Collabora, Ltd.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
*/
24
25
#include <string.h>
26
#include "pan_scoreboard.h"
27
#include "pan_device.h"
28
#include "panfrost-quirks.h"
29
30
/*
31
* There are various types of Mali jobs:
32
*
33
* - WRITE_VALUE: generic write primitive, used to zero tiler field
34
* - VERTEX: runs a vertex shader
35
* - TILER: runs tiling and sets up a fragment shader
36
* - FRAGMENT: runs fragment shaders and writes out
37
* - COMPUTE: runs a compute shader
38
* - FUSED: vertex+tiler fused together, implicit intradependency (Bifrost)
39
* - GEOMETRY: runs a geometry shader (unimplemented)
40
* - CACHE_FLUSH: unseen in the wild, theoretically cache flush
41
*
42
* In between a full batch and a single Mali job is the "job chain", a series
43
* of Mali jobs together forming a linked list. Within the job chain, each Mali
44
* job can set (up to) two dependencies on other earlier jobs in the chain.
45
* This dependency graph forms a scoreboard. The general idea of a scoreboard
46
* applies: when there is a data dependency of job B on job A, job B sets one
47
* of its dependency indices to job A, ensuring that job B won't start until
48
* job A finishes.
49
*
50
* More specifically, here are a set of rules:
51
*
52
* - A write value job must appear if and only if there is at least one tiler
53
* job, and tiler jobs must depend on it.
54
*
55
* - Vertex jobs and tiler jobs are independent.
56
*
57
* - A tiler job must have a dependency on its data source. If it's getting
58
* data from a vertex job, it depends on the vertex job. If it's getting data
59
* from software, this is null.
60
*
61
* - Tiler jobs must depend on the write value job (chained or otherwise).
62
*
63
* - Tiler jobs must be strictly ordered. So each tiler job must depend on the
64
* previous job in the chain.
65
*
66
* - Jobs linking via next_job has no bearing on order of execution, rather it
67
* just establishes the linked list of jobs, EXCEPT:
68
*
69
* - A job's dependencies must appear earlier in the linked list (job chain).
70
*
71
* Justification for each rule:
72
*
73
* - Write value jobs are used to write a zero into a magic tiling field, which
74
* enables tiling to work. If tiling occurs, they are needed; if it does not,
75
* we cannot emit them since then tiling partially occurs and it's bad.
76
*
77
* - The hardware has no notion of a "vertex/tiler job" (at least not our
78
* hardware -- other revs have fused jobs, but --- crap, this just got even
79
* more complicated). They are independent units that take in data, process
80
* it, and spit out data.
81
*
82
* - Any job must depend on its data source, in fact, or risk a
83
* read-before-write hazard. Tiler jobs get their data from vertex jobs, ergo
84
* tiler jobs depend on the corresponding vertex job (if it's there).
85
*
86
* - The tiler is not thread-safe; this dependency prevents race conditions
87
* between two different jobs trying to write to the tiler outputs at the
88
* same time.
89
*
90
* - Internally, jobs are scoreboarded; the next job fields just form a linked
91
* list to allow the jobs to be read in; the execution order is from
92
* resolving the dependency fields instead.
93
*
94
* - The hardware cannot set a dependency on a job it doesn't know about yet,
95
* and dependencies are processed in-order of the next job fields.
96
*
97
*/
98
99
/* Generates, uploads, and queues a a new job. All fields are written in order
100
* except for next_job accounting (TODO: Should we be clever and defer the
101
* upload of the header here until next job to keep the access pattern totally
102
* linear? Or is that just a micro op at this point?). Returns the generated
103
* index for dep management.
104
*
105
* Inject is used to inject a job at the front, for wallpapering. If you are
106
* not wallpapering and set this, dragons will eat you. */
107
108
unsigned
109
panfrost_add_job(
110
struct pan_pool *pool,
111
struct pan_scoreboard *scoreboard,
112
enum mali_job_type type,
113
bool barrier, bool suppress_prefetch,
114
unsigned local_dep, unsigned global_dep,
115
const struct panfrost_ptr *job,
116
bool inject)
117
{
118
if (type == MALI_JOB_TYPE_TILER) {
119
/* Tiler jobs must be chained, and on Midgard, the first tiler
120
* job must depend on the write value job, whose index we
121
* reserve now */
122
123
if (!pan_is_bifrost(pool->dev) && !scoreboard->write_value_index)
124
scoreboard->write_value_index = ++scoreboard->job_index;
125
126
if (scoreboard->tiler_dep && !inject)
127
global_dep = scoreboard->tiler_dep;
128
else if (!pan_is_bifrost(pool->dev))
129
global_dep = scoreboard->write_value_index;
130
}
131
132
/* Assign the index */
133
unsigned index = ++scoreboard->job_index;
134
135
pan_pack(job->cpu, JOB_HEADER, header) {
136
header.type = type;
137
header.barrier = barrier;
138
header.suppress_prefetch = suppress_prefetch;
139
header.index = index;
140
header.dependency_1 = local_dep;
141
header.dependency_2 = global_dep;
142
143
if (inject)
144
header.next = scoreboard->first_job;
145
}
146
147
if (inject) {
148
assert(type == MALI_JOB_TYPE_TILER && "only for blit shaders");
149
150
if (scoreboard->first_tiler) {
151
/* Manual update of the dep2 field. This is bad,
152
* don't copy this pattern.
153
*/
154
scoreboard->first_tiler->opaque[5] =
155
scoreboard->first_tiler_dep1 | (index << 16);
156
}
157
158
scoreboard->first_tiler = (void *)job->cpu;
159
scoreboard->first_tiler_dep1 = local_dep;
160
scoreboard->first_job = job->gpu;
161
return index;
162
}
163
164
/* Form a chain */
165
if (type == MALI_JOB_TYPE_TILER) {
166
if (!scoreboard->first_tiler) {
167
scoreboard->first_tiler = (void *)job->cpu;
168
scoreboard->first_tiler_dep1 = local_dep;
169
}
170
scoreboard->tiler_dep = index;
171
}
172
173
if (scoreboard->prev_job) {
174
/* Manual update of the next pointer. This is bad, don't copy
175
* this pattern.
176
* TODO: Find a way to defer last job header emission until we
177
* have a new job to queue or the batch is ready for execution.
178
*/
179
scoreboard->prev_job->opaque[6] = job->gpu;
180
scoreboard->prev_job->opaque[7] = job->gpu >> 32;
181
} else {
182
scoreboard->first_job = job->gpu;
183
}
184
185
scoreboard->prev_job = (struct mali_job_header_packed *)job->cpu;
186
return index;
187
}
188
189
/* Generates a write value job, used to initialize the tiler structures. Note
190
* this is called right before frame submission. */
191
192
struct panfrost_ptr
193
panfrost_scoreboard_initialize_tiler(struct pan_pool *pool,
194
struct pan_scoreboard *scoreboard,
195
mali_ptr polygon_list)
196
{
197
struct panfrost_ptr transfer = { 0 };
198
199
/* Check if we even need tiling */
200
if (pan_is_bifrost(pool->dev) || !scoreboard->first_tiler)
201
return transfer;
202
203
/* Okay, we do. Let's generate it. We'll need the job's polygon list
204
* regardless of size. */
205
206
transfer = pan_pool_alloc_desc(pool, WRITE_VALUE_JOB);
207
208
pan_section_pack(transfer.cpu, WRITE_VALUE_JOB, HEADER, header) {
209
header.type = MALI_JOB_TYPE_WRITE_VALUE;
210
header.index = scoreboard->write_value_index;
211
header.next = scoreboard->first_job;
212
}
213
214
pan_section_pack(transfer.cpu, WRITE_VALUE_JOB, PAYLOAD, payload) {
215
payload.address = polygon_list;
216
payload.type = MALI_WRITE_VALUE_TYPE_ZERO;
217
}
218
219
scoreboard->first_job = transfer.gpu;
220
return transfer;
221
}
222
223