| 1 |
/* |
| 2 |
* Copyright (C) 2019-2020 Collabora Ltd. |
| 3 |
* Copyright (C) 2019 Alyssa Rosenzweig |
| 4 |
* Copyright (C) 2014-2017 Broadcom |
| 5 |
* SPDX-License-Identifier: MIT |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef __PAN_JC_H__ |
| 9 |
#define __PAN_JC_H__ |
| 10 |
|
| 11 |
#include "genxml/gen_macros.h" |
| 12 |
#include "pan_pool.h" |
| 13 |
|
| 14 |
/* Job chain */ |
| 15 |
struct pan_jc { |
| 16 |
/* The first job in the chain */ |
| 17 |
uint64_t first_job; |
| 18 |
|
| 19 |
/* The number of jobs in the chain, essentially */ |
| 20 |
unsigned job_index; |
| 21 |
|
| 22 |
/* A CPU-side pointer to the previous job for next_job linking */ |
| 23 |
struct mali_job_header_packed *prev_job; |
| 24 |
|
| 25 |
/* A CPU-side pointer to the first tiler job for dep updates when |
| 26 |
* injecting a reload tiler job. |
| 27 |
*/ |
| 28 |
struct mali_job_header_packed *first_tiler; |
| 29 |
uint32_t first_tiler_dep1; |
| 30 |
|
| 31 |
/* The dependency for tiler jobs (i.e. the index of the last emitted |
| 32 |
* tiler job, or zero if none have been emitted) */ |
| 33 |
unsigned tiler_dep; |
| 34 |
|
| 35 |
/* The job index of the WRITE_VALUE job (before it has been created) */ |
| 36 |
unsigned write_value_index; |
| 37 |
}; |
| 38 |
|
| 39 |
#if defined(PAN_ARCH) && PAN_ARCH <= 9 |
| 40 |
/* |
| 41 |
* There are various types of Mali jobs: |
| 42 |
* |
| 43 |
* - WRITE_VALUE: generic write primitive, used to zero tiler field |
| 44 |
* - VERTEX: runs a vertex shader |
| 45 |
* - TILER: runs tiling and sets up a fragment shader |
| 46 |
* - FRAGMENT: runs fragment shaders and writes out |
| 47 |
* - COMPUTE: runs a compute shader |
| 48 |
* - FUSED: vertex+tiler fused together, implicit intradependency (Bifrost) |
| 49 |
* - GEOMETRY: runs a geometry shader (unimplemented) |
| 50 |
* - CACHE_FLUSH: unseen in the wild, theoretically cache flush |
| 51 |
* |
| 52 |
* In between a full batch and a single Mali job is the "job chain", a series |
| 53 |
* of Mali jobs together forming a linked list. Within the job chain, each Mali |
| 54 |
* job can set (up to) two dependencies on other earlier jobs in the chain. |
| 55 |
* This dependency graph forms a scoreboard. The general idea of a scoreboard |
| 56 |
* applies: when there is a data dependency of job B on job A, job B sets one |
| 57 |
* of its dependency indices to job A, ensuring that job B won't start until |
| 58 |
* job A finishes. |
| 59 |
* |
| 60 |
* More specifically, here are a set of rules: |
| 61 |
* |
| 62 |
* - A write value job must appear if and only if there is at least one tiler |
| 63 |
* job, and tiler jobs must depend on it. |
| 64 |
* |
| 65 |
* - Vertex jobs and tiler jobs are independent. |
| 66 |
* |
| 67 |
* - A tiler job must have a dependency on its data source. If it's getting |
| 68 |
* data from a vertex job, it depends on the vertex job. If it's getting data |
| 69 |
* from software, this is null. |
| 70 |
* |
| 71 |
* - Tiler jobs must depend on the write value job (chained or otherwise). |
| 72 |
* |
| 73 |
* - Tiler jobs must be strictly ordered. So each tiler job must depend on the |
| 74 |
* previous job in the chain. |
| 75 |
* |
| 76 |
* - Jobs linking via next_job has no bearing on order of execution, rather it |
| 77 |
* just establishes the linked list of jobs, EXCEPT: |
| 78 |
* |
| 79 |
* - A job's dependencies must appear earlier in the linked list (job chain). |
| 80 |
* |
| 81 |
* Justification for each rule: |
| 82 |
* |
| 83 |
* - Write value jobs are used to write a zero into a magic tiling field, which |
| 84 |
* enables tiling to work. If tiling occurs, they are needed; if it does not, |
| 85 |
* we cannot emit them since then tiling partially occurs and it's bad. |
| 86 |
* |
| 87 |
* - The hardware has no notion of a "vertex/tiler job" (at least not our |
| 88 |
* hardware -- other revs have fused jobs, but --- crap, this just got even |
| 89 |
* more complicated). They are independent units that take in data, process |
| 90 |
* it, and spit out data. |
| 91 |
* |
| 92 |
* - Any job must depend on its data source, in fact, or risk a |
| 93 |
* read-before-write hazard. Tiler jobs get their data from vertex jobs, ergo |
| 94 |
* tiler jobs depend on the corresponding vertex job (if it's there). |
| 95 |
* |
| 96 |
* - The tiler is not thread-safe; this dependency prevents race conditions |
| 97 |
* between two different jobs trying to write to the tiler outputs at the |
| 98 |
* same time. |
| 99 |
* |
| 100 |
* - Internally, jobs are scoreboarded; the next job fields just form a linked |
| 101 |
* list to allow the jobs to be read in; the execution order is from |
| 102 |
* resolving the dependency fields instead. |
| 103 |
* |
| 104 |
* - The hardware cannot set a dependency on a job it doesn't know about yet, |
| 105 |
* and dependencies are processed in-order of the next job fields. |
| 106 |
* |
| 107 |
*/ |
| 108 |
|
| 109 |
/** |
| 110 |
* Does this job use the tiler? Beyond tiler jobs, index-driven vertex shading |
| 111 |
* jobs also do. |
| 112 |
*/ |
| 113 |
static inline bool |
| 114 |
job_uses_tiling(enum mali_job_type type) |
| 115 |
{ |
| 116 |
#if PAN_ARCH >= 9 |
| 117 |
if (type == MALI_JOB_TYPE_MALLOC_VERTEX) |
| 118 |
return true; |
| 119 |
#endif |
| 120 |
|
| 121 |
#if PAN_ARCH >= 6 |
| 122 |
if (type == MALI_JOB_TYPE_INDEXED_VERTEX) |
| 123 |
return true; |
| 124 |
#endif |
| 125 |
|
| 126 |
return (type == MALI_JOB_TYPE_TILER); |
| 127 |
} |
| 128 |
|
| 129 |
/* Generates, uploads, and queues a a new job. All fields are written in order |
| 130 |
* except for next_job accounting (TODO: Should we be clever and defer the |
| 131 |
* upload of the header here until next job to keep the access pattern totally |
| 132 |
* linear? Or is that just a micro op at this point?). Returns the generated |
| 133 |
* index for dep management. |
| 134 |
* |
| 135 |
* Inject is used to inject a job at the front, for wallpapering. If you are |
| 136 |
* not wallpapering and set this, dragons will eat you. */ |
| 137 |
|
| 138 |
static inline unsigned |
| 139 |
pan_jc_add_job(struct pan_jc *jc, enum mali_job_type type, bool barrier, |
| 140 |
bool suppress_prefetch, unsigned local_dep, unsigned global_dep, |
| 141 |
const struct pan_ptr *job, bool inject) |
| 142 |
{ |
| 143 |
if (job_uses_tiling(type)) { |
| 144 |
/* Tiler jobs must be chained, and on Midgard, the first tiler |
| 145 |
* job must depend on the write value job, whose index we |
| 146 |
* reserve now */ |
| 147 |
|
| 148 |
if (PAN_ARCH <= 5 && !jc->write_value_index) |
| 149 |
jc->write_value_index = ++jc->job_index; |
| 150 |
|
| 151 |
if (jc->tiler_dep && !inject) |
| 152 |
global_dep = jc->tiler_dep; |
| 153 |
else if (PAN_ARCH <= 5) |
| 154 |
global_dep = jc->write_value_index; |
| 155 |
} |
| 156 |
|
| 157 |
/* Assign the index */ |
| 158 |
unsigned index = ++jc->job_index; |
| 159 |
|
| 160 |
pan_cast_and_pack(job->cpu, JOB_HEADER, header) { |
| 161 |
header.type = type; |
| 162 |
header.barrier = barrier; |
| 163 |
header.suppress_prefetch = suppress_prefetch; |
| 164 |
header.index = index; |
| 165 |
header.dependency_1 = local_dep; |
| 166 |
header.dependency_2 = global_dep; |
| 167 |
|
| 168 |
if (inject) |
| 169 |
header.next = jc->first_job; |
| 170 |
} |
| 171 |
|
| 172 |
if (inject) { |
| 173 |
assert(type == MALI_JOB_TYPE_TILER && "only for blit shaders"); |
| 174 |
|
| 175 |
if (jc->first_tiler) { |
| 176 |
/* Manual update of the dep2 field. This is bad, |
| 177 |
* don't copy this pattern. |
| 178 |
*/ |
| 179 |
jc->first_tiler->opaque[5] = |
| 180 |
jc->first_tiler_dep1 | (index << 16); |
| 181 |
} |
| 182 |
|
| 183 |
jc->first_tiler = (void *)job->cpu; |
| 184 |
jc->first_tiler_dep1 = local_dep; |
| 185 |
jc->first_job = job->gpu; |
| 186 |
return index; |
| 187 |
} |
| 188 |
|
| 189 |
/* Form a chain */ |
| 190 |
if (job_uses_tiling(type)) { |
| 191 |
if (!jc->first_tiler) { |
| 192 |
jc->first_tiler = (void *)job->cpu; |
| 193 |
jc->first_tiler_dep1 = local_dep; |
| 194 |
} |
| 195 |
jc->tiler_dep = index; |
| 196 |
} |
| 197 |
|
| 198 |
if (jc->prev_job) { |
| 199 |
/* Manual update of the next pointer. This is bad, don't copy |
| 200 |
* this pattern. |
| 201 |
* TODO: Find a way to defer last job header emission until we |
| 202 |
* have a new job to queue or the batch is ready for execution. |
| 203 |
*/ |
| 204 |
jc->prev_job->opaque[6] = job->gpu; |
| 205 |
jc->prev_job->opaque[7] = job->gpu >> 32; |
| 206 |
} else { |
| 207 |
jc->first_job = job->gpu; |
| 208 |
} |
| 209 |
|
| 210 |
jc->prev_job = (struct mali_job_header_packed *)job->cpu; |
| 211 |
return index; |
| 212 |
} |
| 213 |
|
| 214 |
/* Generates a write value job, used to initialize the tiler structures. Note |
| 215 |
* this is called right before frame submission. */ |
| 216 |
|
| 217 |
static inline struct pan_ptr |
| 218 |
pan_jc_initialize_tiler(struct pan_pool *pool, struct pan_jc *jc, |
| 219 |
uint64_t polygon_list) |
| 220 |
{ |
| 221 |
struct pan_ptr transfer = {0}; |
| 222 |
|
| 223 |
/* Check if we even need tiling */ |
| 224 |
if (PAN_ARCH >= 6 || !jc->first_tiler) |
| 225 |
return transfer; |
| 226 |
|
| 227 |
/* Okay, we do. Let's generate it. We'll need the job's polygon list |
| 228 |
* regardless of size. */ |
| 229 |
|
| 230 |
transfer = pan_pool_alloc_desc(pool, WRITE_VALUE_JOB); |
| 231 |
|
| 232 |
pan_section_pack(transfer.cpu, WRITE_VALUE_JOB, HEADER, header) { |
| 233 |
header.type = MALI_JOB_TYPE_WRITE_VALUE; |
| 234 |
header.index = jc->write_value_index; |
| 235 |
header.next = jc->first_job; |
| 236 |
} |
| 237 |
|
| 238 |
pan_section_pack(transfer.cpu, WRITE_VALUE_JOB, PAYLOAD, payload) { |
| 239 |
payload.address = polygon_list; |
| 240 |
payload.type = MALI_WRITE_VALUE_TYPE_ZERO; |
| 241 |
} |
| 242 |
|
| 243 |
jc->first_job = transfer.gpu; |
| 244 |
return transfer; |
| 245 |
} |
| 246 |
#endif /* PAN_ARCH */ |
| 247 |
|
| 248 |
#endif |