Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 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 | |
Boris Brezillon | 20b00e1 | 2019-08-02 19:18:40 +0200 | [diff] [blame] | 26 | #include <assert.h> |
| 27 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 28 | #include "drm-uapi/panfrost_drm.h" |
| 29 | |
Boris Brezillon | 154cb72 | 2019-09-14 09:58:55 +0200 | [diff] [blame] | 30 | #include "pan_bo.h" |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 31 | #include "pan_context.h" |
| 32 | #include "util/hash_table.h" |
| 33 | #include "util/ralloc.h" |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 34 | #include "util/u_format.h" |
Alyssa Rosenzweig | 7692ad1 | 2019-06-28 18:46:43 -0700 | [diff] [blame] | 35 | #include "util/u_pack_color.h" |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 36 | #include "pan_util.h" |
| 37 | #include "pandecode/decode.h" |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 38 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 39 | /* panfrost_bo_access is here to help us keep track of batch accesses to BOs |
| 40 | * and build a proper dependency graph such that batches can be pipelined for |
| 41 | * better GPU utilization. |
| 42 | * |
| 43 | * Each accessed BO has a corresponding entry in the ->accessed_bos hash table. |
| 44 | * A BO is either being written or read at any time, that's what the type field |
| 45 | * encodes. |
| 46 | * When the last access is a write, the batch writing the BO might have read |
| 47 | * dependencies (readers that have not been executed yet and want to read the |
| 48 | * previous BO content), and when the last access is a read, all readers might |
| 49 | * depend on another batch to push its results to memory. That's what the |
| 50 | * readers/writers keep track off. |
| 51 | * There can only be one writer at any given time, if a new batch wants to |
| 52 | * write to the same BO, a dependency will be added between the new writer and |
| 53 | * the old writer (at the batch level), and panfrost_bo_access->writer will be |
| 54 | * updated to point to the new writer. |
| 55 | */ |
| 56 | struct panfrost_bo_access { |
| 57 | uint32_t type; |
| 58 | struct util_dynarray readers; |
| 59 | struct panfrost_batch_fence *writer; |
| 60 | }; |
| 61 | |
Boris Brezillon | 6936b7f | 2019-09-15 10:27:07 +0200 | [diff] [blame] | 62 | static struct panfrost_batch_fence * |
| 63 | panfrost_create_batch_fence(struct panfrost_batch *batch) |
| 64 | { |
| 65 | struct panfrost_batch_fence *fence; |
| 66 | ASSERTED int ret; |
| 67 | |
| 68 | fence = rzalloc(NULL, struct panfrost_batch_fence); |
| 69 | assert(fence); |
| 70 | pipe_reference_init(&fence->reference, 1); |
| 71 | fence->ctx = batch->ctx; |
| 72 | fence->batch = batch; |
| 73 | ret = drmSyncobjCreate(pan_screen(batch->ctx->base.screen)->fd, 0, |
| 74 | &fence->syncobj); |
| 75 | assert(!ret); |
| 76 | |
| 77 | return fence; |
| 78 | } |
| 79 | |
| 80 | static void |
| 81 | panfrost_free_batch_fence(struct panfrost_batch_fence *fence) |
| 82 | { |
| 83 | drmSyncobjDestroy(pan_screen(fence->ctx->base.screen)->fd, |
| 84 | fence->syncobj); |
| 85 | ralloc_free(fence); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | panfrost_batch_fence_unreference(struct panfrost_batch_fence *fence) |
| 90 | { |
| 91 | if (pipe_reference(&fence->reference, NULL)) |
| 92 | panfrost_free_batch_fence(fence); |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | panfrost_batch_fence_reference(struct panfrost_batch_fence *fence) |
| 97 | { |
| 98 | pipe_reference(NULL, &fence->reference); |
| 99 | } |
| 100 | |
Boris Brezillon | 2b771b8 | 2019-09-13 18:32:42 +0200 | [diff] [blame] | 101 | static struct panfrost_batch * |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 102 | panfrost_create_batch(struct panfrost_context *ctx, |
| 103 | const struct pipe_framebuffer_state *key) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 104 | { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 105 | struct panfrost_batch *batch = rzalloc(ctx, struct panfrost_batch); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 106 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 107 | batch->ctx = ctx; |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 108 | |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 109 | batch->bos = _mesa_hash_table_create(batch, _mesa_hash_pointer, |
| 110 | _mesa_key_pointer_equal); |
Alyssa Rosenzweig | c378829 | 2019-06-18 12:30:55 -0700 | [diff] [blame] | 111 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 112 | batch->minx = batch->miny = ~0; |
| 113 | batch->maxx = batch->maxy = 0; |
| 114 | batch->transient_offset = 0; |
Alyssa Rosenzweig | f085474 | 2019-06-19 11:27:59 -0700 | [diff] [blame] | 115 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 116 | util_dynarray_init(&batch->headers, batch); |
| 117 | util_dynarray_init(&batch->gpu_headers, batch); |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 118 | util_dynarray_init(&batch->dependencies, batch); |
Boris Brezillon | 6936b7f | 2019-09-15 10:27:07 +0200 | [diff] [blame] | 119 | batch->out_sync = panfrost_create_batch_fence(batch); |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 120 | util_copy_framebuffer_state(&batch->key, key); |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 121 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 122 | return batch; |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Boris Brezillon | 2b771b8 | 2019-09-13 18:32:42 +0200 | [diff] [blame] | 125 | static void |
Boris Brezillon | 40a07bf | 2019-09-15 12:14:22 +0200 | [diff] [blame] | 126 | panfrost_freeze_batch(struct panfrost_batch *batch) |
| 127 | { |
| 128 | struct panfrost_context *ctx = batch->ctx; |
| 129 | struct hash_entry *entry; |
| 130 | |
| 131 | /* Remove the entry in the FBO -> batch hash table if the batch |
| 132 | * matches. This way, next draws/clears targeting this FBO will trigger |
| 133 | * the creation of a new batch. |
| 134 | */ |
| 135 | entry = _mesa_hash_table_search(ctx->batches, &batch->key); |
| 136 | if (entry && entry->data == batch) |
| 137 | _mesa_hash_table_remove(ctx->batches, entry); |
| 138 | |
| 139 | /* If this is the bound batch, the panfrost_context parameters are |
| 140 | * relevant so submitting it invalidates those parameters, but if it's |
| 141 | * not bound, the context parameters are for some other batch so we |
| 142 | * can't invalidate them. |
| 143 | */ |
| 144 | if (ctx->batch == batch) { |
| 145 | panfrost_invalidate_frame(ctx); |
| 146 | ctx->batch = NULL; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | #ifndef NDEBUG |
| 151 | static bool panfrost_batch_is_frozen(struct panfrost_batch *batch) |
| 152 | { |
| 153 | struct panfrost_context *ctx = batch->ctx; |
| 154 | struct hash_entry *entry; |
| 155 | |
| 156 | entry = _mesa_hash_table_search(ctx->batches, &batch->key); |
| 157 | if (entry && entry->data == batch) |
| 158 | return false; |
| 159 | |
| 160 | if (ctx->batch == batch) |
| 161 | return false; |
| 162 | |
| 163 | return true; |
| 164 | } |
| 165 | #endif |
| 166 | |
| 167 | static void |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 168 | panfrost_free_batch(struct panfrost_batch *batch) |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 169 | { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 170 | if (!batch) |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 171 | return; |
| 172 | |
Boris Brezillon | 40a07bf | 2019-09-15 12:14:22 +0200 | [diff] [blame] | 173 | assert(panfrost_batch_is_frozen(batch)); |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 174 | |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 175 | hash_table_foreach(batch->bos, entry) |
| 176 | panfrost_bo_unreference((struct panfrost_bo *)entry->key); |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 177 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 178 | util_dynarray_foreach(&batch->dependencies, |
| 179 | struct panfrost_batch_fence *, dep) { |
| 180 | panfrost_batch_fence_unreference(*dep); |
| 181 | } |
| 182 | |
Boris Brezillon | 6936b7f | 2019-09-15 10:27:07 +0200 | [diff] [blame] | 183 | /* The out_sync fence lifetime is different from the the batch one |
| 184 | * since other batches might want to wait on a fence of already |
| 185 | * submitted/signaled batch. All we need to do here is make sure the |
| 186 | * fence does not point to an invalid batch, which the core will |
| 187 | * interpret as 'batch is already submitted'. |
| 188 | */ |
| 189 | batch->out_sync->batch = NULL; |
| 190 | panfrost_batch_fence_unreference(batch->out_sync); |
| 191 | |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 192 | util_unreference_framebuffer_state(&batch->key); |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 193 | ralloc_free(batch); |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 196 | #ifndef NDEBUG |
| 197 | static bool |
| 198 | panfrost_dep_graph_contains_batch(struct panfrost_batch *root, |
| 199 | struct panfrost_batch *batch) |
| 200 | { |
| 201 | if (!root) |
| 202 | return false; |
| 203 | |
| 204 | util_dynarray_foreach(&root->dependencies, |
| 205 | struct panfrost_batch_fence *, dep) { |
| 206 | if ((*dep)->batch == batch || |
| 207 | panfrost_dep_graph_contains_batch((*dep)->batch, batch)) |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | return false; |
| 212 | } |
| 213 | #endif |
| 214 | |
| 215 | static void |
| 216 | panfrost_batch_add_dep(struct panfrost_batch *batch, |
| 217 | struct panfrost_batch_fence *newdep) |
| 218 | { |
| 219 | if (batch == newdep->batch) |
| 220 | return; |
| 221 | |
| 222 | /* We might want to turn ->dependencies into a set if the number of |
| 223 | * deps turns out to be big enough to make this 'is dep already there' |
| 224 | * search inefficient. |
| 225 | */ |
| 226 | util_dynarray_foreach(&batch->dependencies, |
| 227 | struct panfrost_batch_fence *, dep) { |
| 228 | if (*dep == newdep) |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | /* Make sure the dependency graph is acyclic. */ |
| 233 | assert(!panfrost_dep_graph_contains_batch(newdep->batch, batch)); |
| 234 | |
| 235 | panfrost_batch_fence_reference(newdep); |
| 236 | util_dynarray_append(&batch->dependencies, |
| 237 | struct panfrost_batch_fence *, newdep); |
| 238 | |
| 239 | /* We now have a batch depending on us, let's make sure new draw/clear |
| 240 | * calls targeting the same FBO use a new batch object. |
| 241 | */ |
| 242 | if (newdep->batch) |
| 243 | panfrost_freeze_batch(newdep->batch); |
| 244 | } |
| 245 | |
Boris Brezillon | 2b771b8 | 2019-09-13 18:32:42 +0200 | [diff] [blame] | 246 | static struct panfrost_batch * |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 247 | panfrost_get_batch(struct panfrost_context *ctx, |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 248 | const struct pipe_framebuffer_state *key) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 249 | { |
| 250 | /* Lookup the job first */ |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 251 | struct hash_entry *entry = _mesa_hash_table_search(ctx->batches, key); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 252 | |
| 253 | if (entry) |
| 254 | return entry->data; |
| 255 | |
| 256 | /* Otherwise, let's create a job */ |
| 257 | |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 258 | struct panfrost_batch *batch = panfrost_create_batch(ctx, key); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 259 | |
| 260 | /* Save the created job */ |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 261 | _mesa_hash_table_insert(ctx->batches, &batch->key, batch); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 262 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 263 | return batch; |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* Get the job corresponding to the FBO we're currently rendering into */ |
| 267 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 268 | struct panfrost_batch * |
| 269 | panfrost_get_batch_for_fbo(struct panfrost_context *ctx) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 270 | { |
Alyssa Rosenzweig | f085474 | 2019-06-19 11:27:59 -0700 | [diff] [blame] | 271 | /* If we're wallpapering, we special case to workaround |
| 272 | * u_blitter abuse */ |
| 273 | |
| 274 | if (ctx->wallpaper_batch) |
| 275 | return ctx->wallpaper_batch; |
| 276 | |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 277 | /* If we already began rendering, use that */ |
| 278 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 279 | if (ctx->batch) { |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 280 | assert(util_framebuffer_state_equal(&ctx->batch->key, |
| 281 | &ctx->pipe_framebuffer)); |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 282 | return ctx->batch; |
Boris Brezillon | 20b00e1 | 2019-08-02 19:18:40 +0200 | [diff] [blame] | 283 | } |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 284 | |
| 285 | /* If not, look up the job */ |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 286 | struct panfrost_batch *batch = panfrost_get_batch(ctx, |
| 287 | &ctx->pipe_framebuffer); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 288 | |
Boris Brezillon | 20b00e1 | 2019-08-02 19:18:40 +0200 | [diff] [blame] | 289 | /* Set this job as the current FBO job. Will be reset when updating the |
| 290 | * FB state and when submitting or releasing a job. |
| 291 | */ |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 292 | ctx->batch = batch; |
| 293 | return batch; |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Boris Brezillon | c138ca8 | 2019-09-19 15:52:02 +0200 | [diff] [blame^] | 296 | struct panfrost_batch * |
| 297 | panfrost_get_fresh_batch_for_fbo(struct panfrost_context *ctx) |
| 298 | { |
| 299 | struct panfrost_batch *batch; |
| 300 | |
| 301 | batch = panfrost_get_batch(ctx, &ctx->pipe_framebuffer); |
| 302 | |
| 303 | /* The batch has no draw/clear queued, let's return it directly. |
| 304 | * Note that it's perfectly fine to re-use a batch with an |
| 305 | * existing clear, we'll just update it with the new clear request. |
| 306 | */ |
| 307 | if (!batch->last_job.gpu) |
| 308 | return batch; |
| 309 | |
| 310 | /* Otherwise, we need to freeze the existing one and instantiate a new |
| 311 | * one. |
| 312 | */ |
| 313 | panfrost_freeze_batch(batch); |
| 314 | return panfrost_get_batch(ctx, &ctx->pipe_framebuffer); |
| 315 | } |
| 316 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 317 | static bool |
| 318 | panfrost_batch_fence_is_signaled(struct panfrost_batch_fence *fence) |
| 319 | { |
| 320 | if (fence->signaled) |
| 321 | return true; |
| 322 | |
| 323 | /* Batch has not been submitted yet. */ |
| 324 | if (fence->batch) |
| 325 | return false; |
| 326 | |
| 327 | int ret = drmSyncobjWait(pan_screen(fence->ctx->base.screen)->fd, |
| 328 | &fence->syncobj, 1, 0, 0, NULL); |
| 329 | |
| 330 | /* Cache whether the fence was signaled */ |
| 331 | fence->signaled = ret >= 0; |
| 332 | return fence->signaled; |
| 333 | } |
| 334 | |
| 335 | static void |
| 336 | panfrost_bo_access_gc_fences(struct panfrost_context *ctx, |
| 337 | struct panfrost_bo_access *access, |
| 338 | const struct panfrost_bo *bo) |
| 339 | { |
| 340 | if (access->writer && panfrost_batch_fence_is_signaled(access->writer)) { |
| 341 | panfrost_batch_fence_unreference(access->writer); |
| 342 | access->writer = NULL; |
| 343 | } |
| 344 | |
| 345 | unsigned nreaders = 0; |
| 346 | util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *, |
| 347 | reader) { |
| 348 | if (!(*reader)) |
| 349 | continue; |
| 350 | |
| 351 | if (panfrost_batch_fence_is_signaled(*reader)) { |
| 352 | panfrost_batch_fence_unreference(*reader); |
| 353 | *reader = NULL; |
| 354 | } else { |
| 355 | nreaders++; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if (!nreaders) |
| 360 | util_dynarray_clear(&access->readers); |
| 361 | } |
| 362 | |
| 363 | /* Collect signaled fences to keep the kernel-side syncobj-map small. The |
| 364 | * idea is to collect those signaled fences at the end of each flush_all |
| 365 | * call. This function is likely to collect only fences from previous |
| 366 | * batch flushes not the one that have just have just been submitted and |
| 367 | * are probably still in flight when we trigger the garbage collection. |
| 368 | * Anyway, we need to do this garbage collection at some point if we don't |
| 369 | * want the BO access map to keep invalid entries around and retain |
| 370 | * syncobjs forever. |
| 371 | */ |
| 372 | static void |
| 373 | panfrost_gc_fences(struct panfrost_context *ctx) |
| 374 | { |
| 375 | hash_table_foreach(ctx->accessed_bos, entry) { |
| 376 | struct panfrost_bo_access *access = entry->data; |
| 377 | |
| 378 | assert(access); |
| 379 | panfrost_bo_access_gc_fences(ctx, access, entry->key); |
| 380 | if (!util_dynarray_num_elements(&access->readers, |
| 381 | struct panfrost_batch_fence *) && |
| 382 | !access->writer) |
| 383 | _mesa_hash_table_remove(ctx->accessed_bos, entry); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | #ifndef NDEBUG |
| 388 | static bool |
| 389 | panfrost_batch_in_readers(struct panfrost_batch *batch, |
| 390 | struct panfrost_bo_access *access) |
| 391 | { |
| 392 | util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *, |
| 393 | reader) { |
| 394 | if (*reader && (*reader)->batch == batch) |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | return false; |
| 399 | } |
| 400 | #endif |
| 401 | |
| 402 | static void |
| 403 | panfrost_batch_update_bo_access(struct panfrost_batch *batch, |
| 404 | struct panfrost_bo *bo, uint32_t access_type, |
| 405 | bool already_accessed) |
| 406 | { |
| 407 | struct panfrost_context *ctx = batch->ctx; |
| 408 | struct panfrost_bo_access *access; |
| 409 | uint32_t old_access_type; |
| 410 | struct hash_entry *entry; |
| 411 | |
| 412 | assert(access_type == PAN_BO_ACCESS_WRITE || |
| 413 | access_type == PAN_BO_ACCESS_READ); |
| 414 | |
| 415 | entry = _mesa_hash_table_search(ctx->accessed_bos, bo); |
| 416 | access = entry ? entry->data : NULL; |
| 417 | if (access) { |
| 418 | old_access_type = access->type; |
| 419 | } else { |
| 420 | access = rzalloc(ctx, struct panfrost_bo_access); |
| 421 | util_dynarray_init(&access->readers, access); |
| 422 | _mesa_hash_table_insert(ctx->accessed_bos, bo, access); |
| 423 | /* We are the first to access this BO, let's initialize |
| 424 | * old_access_type to our own access type in that case. |
| 425 | */ |
| 426 | old_access_type = access_type; |
| 427 | access->type = access_type; |
| 428 | } |
| 429 | |
| 430 | assert(access); |
| 431 | |
| 432 | if (access_type == PAN_BO_ACCESS_WRITE && |
| 433 | old_access_type == PAN_BO_ACCESS_READ) { |
| 434 | /* Previous access was a read and we want to write this BO. |
| 435 | * We first need to add explicit deps between our batch and |
| 436 | * the previous readers. |
| 437 | */ |
| 438 | util_dynarray_foreach(&access->readers, |
| 439 | struct panfrost_batch_fence *, reader) { |
| 440 | /* We were already reading the BO, no need to add a dep |
| 441 | * on ourself (the acyclic check would complain about |
| 442 | * that). |
| 443 | */ |
| 444 | if (!(*reader) || (*reader)->batch == batch) |
| 445 | continue; |
| 446 | |
| 447 | panfrost_batch_add_dep(batch, *reader); |
| 448 | } |
| 449 | panfrost_batch_fence_reference(batch->out_sync); |
| 450 | |
| 451 | /* We now are the new writer. */ |
| 452 | access->writer = batch->out_sync; |
| 453 | access->type = access_type; |
| 454 | |
| 455 | /* Release the previous readers and reset the readers array. */ |
| 456 | util_dynarray_foreach(&access->readers, |
| 457 | struct panfrost_batch_fence *, |
| 458 | reader) { |
| 459 | if (!*reader) |
| 460 | continue; |
| 461 | panfrost_batch_fence_unreference(*reader); |
| 462 | } |
| 463 | |
| 464 | util_dynarray_clear(&access->readers); |
| 465 | } else if (access_type == PAN_BO_ACCESS_WRITE && |
| 466 | old_access_type == PAN_BO_ACCESS_WRITE) { |
| 467 | /* Previous access was a write and we want to write this BO. |
| 468 | * First check if we were the previous writer, in that case |
| 469 | * there's nothing to do. Otherwise we need to add a |
| 470 | * dependency between the new writer and the old one. |
| 471 | */ |
| 472 | if (access->writer != batch->out_sync) { |
| 473 | if (access->writer) { |
| 474 | panfrost_batch_add_dep(batch, access->writer); |
| 475 | panfrost_batch_fence_unreference(access->writer); |
| 476 | } |
| 477 | panfrost_batch_fence_reference(batch->out_sync); |
| 478 | access->writer = batch->out_sync; |
| 479 | } |
| 480 | } else if (access_type == PAN_BO_ACCESS_READ && |
| 481 | old_access_type == PAN_BO_ACCESS_WRITE) { |
| 482 | /* Previous access was a write and we want to read this BO. |
| 483 | * First check if we were the previous writer, in that case |
| 484 | * we want to keep the access type unchanged, as a write is |
| 485 | * more constraining than a read. |
| 486 | */ |
| 487 | if (access->writer != batch->out_sync) { |
| 488 | /* Add a dependency on the previous writer. */ |
| 489 | panfrost_batch_add_dep(batch, access->writer); |
| 490 | |
| 491 | /* The previous access was a write, there's no reason |
| 492 | * to have entries in the readers array. |
| 493 | */ |
| 494 | assert(!util_dynarray_num_elements(&access->readers, |
| 495 | struct panfrost_batch_fence *)); |
| 496 | |
| 497 | /* Add ourselves to the readers array. */ |
| 498 | panfrost_batch_fence_reference(batch->out_sync); |
| 499 | util_dynarray_append(&access->readers, |
| 500 | struct panfrost_batch_fence *, |
| 501 | batch->out_sync); |
| 502 | access->type = PAN_BO_ACCESS_READ; |
| 503 | } |
| 504 | } else { |
| 505 | /* We already accessed this BO before, so we should already be |
| 506 | * in the reader array. |
| 507 | */ |
| 508 | if (already_accessed) { |
| 509 | assert(panfrost_batch_in_readers(batch, access)); |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | /* Previous access was a read and we want to read this BO. |
| 514 | * Add ourselves to the readers array and add a dependency on |
| 515 | * the previous writer if any. |
| 516 | */ |
| 517 | panfrost_batch_fence_reference(batch->out_sync); |
| 518 | util_dynarray_append(&access->readers, |
| 519 | struct panfrost_batch_fence *, |
| 520 | batch->out_sync); |
| 521 | |
| 522 | if (access->writer) |
| 523 | panfrost_batch_add_dep(batch, access->writer); |
| 524 | } |
| 525 | } |
| 526 | |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 527 | void |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 528 | panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo, |
| 529 | uint32_t flags) |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 530 | { |
| 531 | if (!bo) |
| 532 | return; |
| 533 | |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 534 | struct hash_entry *entry; |
| 535 | uint32_t old_flags = 0; |
| 536 | |
| 537 | entry = _mesa_hash_table_search(batch->bos, bo); |
| 538 | if (!entry) { |
| 539 | entry = _mesa_hash_table_insert(batch->bos, bo, |
| 540 | (void *)(uintptr_t)flags); |
| 541 | panfrost_bo_reference(bo); |
| 542 | } else { |
| 543 | old_flags = (uintptr_t)entry->data; |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 544 | |
| 545 | /* All batches have to agree on the shared flag. */ |
| 546 | assert((old_flags & PAN_BO_ACCESS_SHARED) == |
| 547 | (flags & PAN_BO_ACCESS_SHARED)); |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | assert(entry); |
| 551 | |
| 552 | if (old_flags == flags) |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 553 | return; |
| 554 | |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 555 | flags |= old_flags; |
| 556 | entry->data = (void *)(uintptr_t)flags; |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 557 | |
| 558 | /* If this is not a shared BO, we don't really care about dependency |
| 559 | * tracking. |
| 560 | */ |
| 561 | if (!(flags & PAN_BO_ACCESS_SHARED)) |
| 562 | return; |
| 563 | |
| 564 | /* All dependencies should have been flushed before we execute the |
| 565 | * wallpaper draw, so it should be harmless to skip the |
| 566 | * update_bo_access() call. |
| 567 | */ |
| 568 | if (batch == batch->ctx->wallpaper_batch) |
| 569 | return; |
| 570 | |
| 571 | /* Only pass R/W flags to the dep tracking logic. */ |
| 572 | assert(flags & PAN_BO_ACCESS_RW); |
| 573 | flags = (flags & PAN_BO_ACCESS_WRITE) ? |
| 574 | PAN_BO_ACCESS_WRITE : PAN_BO_ACCESS_READ; |
| 575 | panfrost_batch_update_bo_access(batch, bo, flags, old_flags != 0); |
Alyssa Rosenzweig | e008d4f | 2019-04-14 22:42:44 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Boris Brezillon | 0eec73a | 2019-09-14 18:40:23 +0200 | [diff] [blame] | 578 | void panfrost_batch_add_fbo_bos(struct panfrost_batch *batch) |
| 579 | { |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 580 | uint32_t flags = PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_WRITE | |
| 581 | PAN_BO_ACCESS_VERTEX_TILER | |
| 582 | PAN_BO_ACCESS_FRAGMENT; |
| 583 | |
Boris Brezillon | 0eec73a | 2019-09-14 18:40:23 +0200 | [diff] [blame] | 584 | for (unsigned i = 0; i < batch->key.nr_cbufs; ++i) { |
| 585 | struct panfrost_resource *rsrc = pan_resource(batch->key.cbufs[i]->texture); |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 586 | panfrost_batch_add_bo(batch, rsrc->bo, flags); |
Boris Brezillon | 0eec73a | 2019-09-14 18:40:23 +0200 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | if (batch->key.zsbuf) { |
| 590 | struct panfrost_resource *rsrc = pan_resource(batch->key.zsbuf->texture); |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 591 | panfrost_batch_add_bo(batch, rsrc->bo, flags); |
Boris Brezillon | 0eec73a | 2019-09-14 18:40:23 +0200 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | |
Boris Brezillon | 5a4d095 | 2019-09-14 17:57:06 +0200 | [diff] [blame] | 595 | struct panfrost_bo * |
| 596 | panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size, |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 597 | uint32_t create_flags, uint32_t access_flags) |
Boris Brezillon | 5a4d095 | 2019-09-14 17:57:06 +0200 | [diff] [blame] | 598 | { |
| 599 | struct panfrost_bo *bo; |
| 600 | |
| 601 | bo = panfrost_bo_create(pan_screen(batch->ctx->base.screen), size, |
| 602 | create_flags); |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 603 | panfrost_batch_add_bo(batch, bo, access_flags); |
Boris Brezillon | 5a4d095 | 2019-09-14 17:57:06 +0200 | [diff] [blame] | 604 | |
| 605 | /* panfrost_batch_add_bo() has retained a reference and |
| 606 | * panfrost_bo_create() initialize the refcnt to 1, so let's |
| 607 | * unreference the BO here so it gets released when the batch is |
| 608 | * destroyed (unless it's retained by someone else in the meantime). |
| 609 | */ |
| 610 | panfrost_bo_unreference(bo); |
| 611 | return bo; |
| 612 | } |
| 613 | |
Alyssa Rosenzweig | cd98d94 | 2019-08-02 19:18:48 +0200 | [diff] [blame] | 614 | /* Returns the polygon list's GPU address if available, or otherwise allocates |
| 615 | * the polygon list. It's perfectly fast to use allocate/free BO directly, |
| 616 | * since we'll hit the BO cache and this is one-per-batch anyway. */ |
| 617 | |
| 618 | mali_ptr |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 619 | panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size) |
Alyssa Rosenzweig | cd98d94 | 2019-08-02 19:18:48 +0200 | [diff] [blame] | 620 | { |
| 621 | if (batch->polygon_list) { |
| 622 | assert(batch->polygon_list->size >= size); |
| 623 | } else { |
Alyssa Rosenzweig | cd98d94 | 2019-08-02 19:18:48 +0200 | [diff] [blame] | 624 | /* Create the BO as invisible, as there's no reason to map */ |
| 625 | |
Boris Brezillon | 5a4d095 | 2019-09-14 17:57:06 +0200 | [diff] [blame] | 626 | batch->polygon_list = panfrost_batch_create_bo(batch, size, |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 627 | PAN_BO_INVISIBLE, |
| 628 | PAN_BO_ACCESS_PRIVATE | |
| 629 | PAN_BO_ACCESS_RW | |
| 630 | PAN_BO_ACCESS_VERTEX_TILER | |
| 631 | PAN_BO_ACCESS_FRAGMENT); |
Alyssa Rosenzweig | cd98d94 | 2019-08-02 19:18:48 +0200 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | return batch->polygon_list->gpu; |
| 635 | } |
| 636 | |
Boris Brezillon | 1e483a8 | 2019-09-14 19:18:51 +0200 | [diff] [blame] | 637 | struct panfrost_bo * |
| 638 | panfrost_batch_get_scratchpad(struct panfrost_batch *batch) |
| 639 | { |
| 640 | if (batch->scratchpad) |
| 641 | return batch->scratchpad; |
| 642 | |
| 643 | batch->scratchpad = panfrost_batch_create_bo(batch, 64 * 4 * 4096, |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 644 | PAN_BO_INVISIBLE, |
| 645 | PAN_BO_ACCESS_PRIVATE | |
| 646 | PAN_BO_ACCESS_RW | |
| 647 | PAN_BO_ACCESS_VERTEX_TILER | |
| 648 | PAN_BO_ACCESS_FRAGMENT); |
Boris Brezillon | 1e483a8 | 2019-09-14 19:18:51 +0200 | [diff] [blame] | 649 | assert(batch->scratchpad); |
| 650 | return batch->scratchpad; |
| 651 | } |
| 652 | |
| 653 | struct panfrost_bo * |
| 654 | panfrost_batch_get_tiler_heap(struct panfrost_batch *batch) |
| 655 | { |
| 656 | if (batch->tiler_heap) |
| 657 | return batch->tiler_heap; |
| 658 | |
| 659 | batch->tiler_heap = panfrost_batch_create_bo(batch, 4096 * 4096, |
| 660 | PAN_BO_INVISIBLE | |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 661 | PAN_BO_GROWABLE, |
| 662 | PAN_BO_ACCESS_PRIVATE | |
| 663 | PAN_BO_ACCESS_RW | |
| 664 | PAN_BO_ACCESS_VERTEX_TILER | |
| 665 | PAN_BO_ACCESS_FRAGMENT); |
Boris Brezillon | 1e483a8 | 2019-09-14 19:18:51 +0200 | [diff] [blame] | 666 | assert(batch->tiler_heap); |
| 667 | return batch->tiler_heap; |
| 668 | } |
| 669 | |
| 670 | struct panfrost_bo * |
| 671 | panfrost_batch_get_tiler_dummy(struct panfrost_batch *batch) |
| 672 | { |
| 673 | if (batch->tiler_dummy) |
| 674 | return batch->tiler_dummy; |
| 675 | |
| 676 | batch->tiler_dummy = panfrost_batch_create_bo(batch, 4096, |
Boris Brezillon | ada752a | 2019-09-15 09:21:13 +0200 | [diff] [blame] | 677 | PAN_BO_INVISIBLE, |
| 678 | PAN_BO_ACCESS_PRIVATE | |
| 679 | PAN_BO_ACCESS_RW | |
| 680 | PAN_BO_ACCESS_VERTEX_TILER | |
| 681 | PAN_BO_ACCESS_FRAGMENT); |
Boris Brezillon | 1e483a8 | 2019-09-14 19:18:51 +0200 | [diff] [blame] | 682 | assert(batch->tiler_dummy); |
| 683 | return batch->tiler_dummy; |
| 684 | } |
| 685 | |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 686 | static void |
| 687 | panfrost_batch_draw_wallpaper(struct panfrost_batch *batch) |
| 688 | { |
| 689 | /* Nothing to reload? TODO: MRT wallpapers */ |
| 690 | if (batch->key.cbufs[0] == NULL) |
| 691 | return; |
| 692 | |
| 693 | /* Check if the buffer has any content on it worth preserving */ |
| 694 | |
| 695 | struct pipe_surface *surf = batch->key.cbufs[0]; |
| 696 | struct panfrost_resource *rsrc = pan_resource(surf->texture); |
| 697 | unsigned level = surf->u.tex.level; |
| 698 | |
| 699 | if (!rsrc->slices[level].initialized) |
| 700 | return; |
| 701 | |
| 702 | batch->ctx->wallpaper_batch = batch; |
| 703 | |
| 704 | /* Clamp the rendering area to the damage extent. The |
| 705 | * KHR_partial_update() spec states that trying to render outside of |
| 706 | * the damage region is "undefined behavior", so we should be safe. |
| 707 | */ |
| 708 | unsigned damage_width = (rsrc->damage.extent.maxx - rsrc->damage.extent.minx); |
| 709 | unsigned damage_height = (rsrc->damage.extent.maxy - rsrc->damage.extent.miny); |
| 710 | |
| 711 | if (damage_width && damage_height) { |
| 712 | panfrost_batch_intersection_scissor(batch, |
| 713 | rsrc->damage.extent.minx, |
| 714 | rsrc->damage.extent.miny, |
| 715 | rsrc->damage.extent.maxx, |
| 716 | rsrc->damage.extent.maxy); |
| 717 | } |
| 718 | |
| 719 | /* FIXME: Looks like aligning on a tile is not enough, but |
| 720 | * aligning on twice the tile size seems to works. We don't |
| 721 | * know exactly what happens here but this deserves extra |
| 722 | * investigation to figure it out. |
| 723 | */ |
| 724 | batch->minx = batch->minx & ~((MALI_TILE_LENGTH * 2) - 1); |
| 725 | batch->miny = batch->miny & ~((MALI_TILE_LENGTH * 2) - 1); |
| 726 | batch->maxx = MIN2(ALIGN_POT(batch->maxx, MALI_TILE_LENGTH * 2), |
| 727 | rsrc->base.width0); |
| 728 | batch->maxy = MIN2(ALIGN_POT(batch->maxy, MALI_TILE_LENGTH * 2), |
| 729 | rsrc->base.height0); |
| 730 | |
| 731 | struct pipe_scissor_state damage; |
| 732 | struct pipe_box rects[4]; |
| 733 | |
| 734 | /* Clamp the damage box to the rendering area. */ |
| 735 | damage.minx = MAX2(batch->minx, rsrc->damage.biggest_rect.x); |
| 736 | damage.miny = MAX2(batch->miny, rsrc->damage.biggest_rect.y); |
| 737 | damage.maxx = MIN2(batch->maxx, |
| 738 | rsrc->damage.biggest_rect.x + |
| 739 | rsrc->damage.biggest_rect.width); |
| 740 | damage.maxy = MIN2(batch->maxy, |
| 741 | rsrc->damage.biggest_rect.y + |
| 742 | rsrc->damage.biggest_rect.height); |
| 743 | |
| 744 | /* One damage rectangle means we can end up with at most 4 reload |
| 745 | * regions: |
| 746 | * 1: left region, only exists if damage.x > 0 |
| 747 | * 2: right region, only exists if damage.x + damage.width < fb->width |
| 748 | * 3: top region, only exists if damage.y > 0. The intersection with |
| 749 | * the left and right regions are dropped |
| 750 | * 4: bottom region, only exists if damage.y + damage.height < fb->height. |
| 751 | * The intersection with the left and right regions are dropped |
| 752 | * |
| 753 | * ____________________________ |
| 754 | * | | 3 | | |
| 755 | * | |___________| | |
| 756 | * | | damage | | |
| 757 | * | 1 | rect | 2 | |
| 758 | * | |___________| | |
| 759 | * | | 4 | | |
| 760 | * |_______|___________|______| |
| 761 | */ |
| 762 | u_box_2d(batch->minx, batch->miny, damage.minx - batch->minx, |
| 763 | batch->maxy - batch->miny, &rects[0]); |
| 764 | u_box_2d(damage.maxx, batch->miny, batch->maxx - damage.maxx, |
| 765 | batch->maxy - batch->miny, &rects[1]); |
| 766 | u_box_2d(damage.minx, batch->miny, damage.maxx - damage.minx, |
| 767 | damage.miny - batch->miny, &rects[2]); |
| 768 | u_box_2d(damage.minx, damage.maxy, damage.maxx - damage.minx, |
| 769 | batch->maxy - damage.maxy, &rects[3]); |
| 770 | |
| 771 | for (unsigned i = 0; i < 4; i++) { |
| 772 | /* Width and height are always >= 0 even if width is declared as a |
| 773 | * signed integer: u_box_2d() helper takes unsigned args and |
| 774 | * panfrost_set_damage_region() is taking care of clamping |
| 775 | * negative values. |
| 776 | */ |
| 777 | if (!rects[i].width || !rects[i].height) |
| 778 | continue; |
| 779 | |
| 780 | /* Blit the wallpaper in */ |
| 781 | panfrost_blit_wallpaper(batch->ctx, &rects[i]); |
| 782 | } |
| 783 | batch->ctx->wallpaper_batch = NULL; |
| 784 | } |
| 785 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 786 | static int |
| 787 | panfrost_batch_submit_ioctl(struct panfrost_batch *batch, |
| 788 | mali_ptr first_job_desc, |
| 789 | uint32_t reqs) |
| 790 | { |
| 791 | struct panfrost_context *ctx = batch->ctx; |
| 792 | struct pipe_context *gallium = (struct pipe_context *) ctx; |
| 793 | struct panfrost_screen *screen = pan_screen(gallium->screen); |
| 794 | struct drm_panfrost_submit submit = {0,}; |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 795 | uint32_t *bo_handles, *in_syncs = NULL; |
| 796 | bool is_fragment_shader; |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 797 | int ret; |
| 798 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 799 | is_fragment_shader = (reqs & PANFROST_JD_REQ_FS) && batch->first_job.gpu; |
| 800 | if (is_fragment_shader) |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 801 | submit.in_sync_count = 1; |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 802 | else |
| 803 | submit.in_sync_count = util_dynarray_num_elements(&batch->dependencies, |
| 804 | struct panfrost_batch_fence *); |
| 805 | |
| 806 | if (submit.in_sync_count) { |
| 807 | in_syncs = calloc(submit.in_sync_count, sizeof(*in_syncs)); |
| 808 | assert(in_syncs); |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 809 | } |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 810 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 811 | /* The fragment job always depends on the vertex/tiler job if there's |
| 812 | * one |
| 813 | */ |
| 814 | if (is_fragment_shader) { |
| 815 | in_syncs[0] = batch->out_sync->syncobj; |
| 816 | } else { |
| 817 | unsigned int i = 0; |
| 818 | |
| 819 | util_dynarray_foreach(&batch->dependencies, |
| 820 | struct panfrost_batch_fence *, dep) |
| 821 | in_syncs[i++] = (*dep)->syncobj; |
| 822 | } |
| 823 | |
| 824 | submit.in_syncs = (uintptr_t)in_syncs; |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 825 | submit.out_sync = batch->out_sync->syncobj; |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 826 | submit.jc = first_job_desc; |
| 827 | submit.requirements = reqs; |
| 828 | |
| 829 | bo_handles = calloc(batch->bos->entries, sizeof(*bo_handles)); |
| 830 | assert(bo_handles); |
| 831 | |
Boris Brezillon | a8bd265 | 2019-09-15 09:27:14 +0200 | [diff] [blame] | 832 | hash_table_foreach(batch->bos, entry) { |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 833 | struct panfrost_bo *bo = (struct panfrost_bo *)entry->key; |
Boris Brezillon | 2225383 | 2019-08-31 18:51:20 +0200 | [diff] [blame] | 834 | uint32_t flags = (uintptr_t)entry->data; |
| 835 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 836 | assert(bo->gem_handle > 0); |
| 837 | bo_handles[submit.bo_handle_count++] = bo->gem_handle; |
Boris Brezillon | 2225383 | 2019-08-31 18:51:20 +0200 | [diff] [blame] | 838 | |
| 839 | /* Update the BO access flags so that panfrost_bo_wait() knows |
| 840 | * about all pending accesses. |
| 841 | * We only keep the READ/WRITE info since this is all the BO |
| 842 | * wait logic cares about. |
| 843 | * We also preserve existing flags as this batch might not |
| 844 | * be the first one to access the BO. |
| 845 | */ |
| 846 | bo->gpu_access |= flags & (PAN_BO_ACCESS_RW); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | submit.bo_handles = (u64) (uintptr_t) bo_handles; |
| 850 | ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_SUBMIT, &submit); |
| 851 | free(bo_handles); |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 852 | free(in_syncs); |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 853 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 854 | if (ret) { |
| 855 | fprintf(stderr, "Error submitting: %m\n"); |
| 856 | return errno; |
| 857 | } |
| 858 | |
| 859 | /* Trace the job if we're doing that */ |
| 860 | if (pan_debug & PAN_DBG_TRACE) { |
| 861 | /* Wait so we can get errors reported back */ |
Boris Brezillon | 819738e | 2019-09-15 10:57:26 +0200 | [diff] [blame] | 862 | drmSyncobjWait(screen->fd, &batch->out_sync->syncobj, 1, |
| 863 | INT64_MAX, 0, NULL); |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 864 | pandecode_jc(submit.jc, FALSE); |
| 865 | } |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | static int |
| 871 | panfrost_batch_submit_jobs(struct panfrost_batch *batch) |
| 872 | { |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 873 | bool has_draws = batch->first_job.gpu; |
| 874 | int ret = 0; |
| 875 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 876 | if (has_draws) { |
| 877 | ret = panfrost_batch_submit_ioctl(batch, batch->first_job.gpu, 0); |
| 878 | assert(!ret); |
| 879 | } |
| 880 | |
| 881 | if (batch->first_tiler.gpu || batch->clear) { |
| 882 | mali_ptr fragjob = panfrost_fragment_job(batch, has_draws); |
| 883 | |
| 884 | ret = panfrost_batch_submit_ioctl(batch, fragjob, PANFROST_JD_REQ_FS); |
| 885 | assert(!ret); |
| 886 | } |
| 887 | |
| 888 | return ret; |
| 889 | } |
| 890 | |
Boris Brezillon | a45984b | 2019-09-15 19:15:16 +0200 | [diff] [blame] | 891 | static void |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 892 | panfrost_batch_submit(struct panfrost_batch *batch) |
Rohan Garg | 0f43a2a | 2019-06-05 16:20:59 +0200 | [diff] [blame] | 893 | { |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 894 | assert(batch); |
| 895 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 896 | /* Submit the dependencies first. */ |
| 897 | util_dynarray_foreach(&batch->dependencies, |
| 898 | struct panfrost_batch_fence *, dep) { |
| 899 | if ((*dep)->batch) |
| 900 | panfrost_batch_submit((*dep)->batch); |
| 901 | } |
| 902 | |
Rohan Garg | 0f43a2a | 2019-06-05 16:20:59 +0200 | [diff] [blame] | 903 | int ret; |
| 904 | |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 905 | /* Nothing to do! */ |
Boris Brezillon | 6936b7f | 2019-09-15 10:27:07 +0200 | [diff] [blame] | 906 | if (!batch->last_job.gpu && !batch->clear) { |
| 907 | /* Mark the fence as signaled so the fence logic does not try |
| 908 | * to wait on it. |
| 909 | */ |
| 910 | batch->out_sync->signaled = true; |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 911 | goto out; |
Boris Brezillon | 6936b7f | 2019-09-15 10:27:07 +0200 | [diff] [blame] | 912 | } |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 913 | |
| 914 | if (!batch->clear && batch->last_tiler.gpu) |
| 915 | panfrost_batch_draw_wallpaper(batch); |
| 916 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 917 | panfrost_scoreboard_link_batch(batch); |
Alyssa Rosenzweig | f085474 | 2019-06-19 11:27:59 -0700 | [diff] [blame] | 918 | |
Boris Brezillon | 0500c9e | 2019-09-14 08:00:27 +0200 | [diff] [blame] | 919 | ret = panfrost_batch_submit_jobs(batch); |
Rohan Garg | 0f43a2a | 2019-06-05 16:20:59 +0200 | [diff] [blame] | 920 | |
| 921 | if (ret) |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 922 | fprintf(stderr, "panfrost_batch_submit failed: %d\n", ret); |
Boris Brezillon | 20b00e1 | 2019-08-02 19:18:40 +0200 | [diff] [blame] | 923 | |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 924 | out: |
Boris Brezillon | 40a07bf | 2019-09-15 12:14:22 +0200 | [diff] [blame] | 925 | panfrost_freeze_batch(batch); |
Boris Brezillon | 6ddfd37 | 2019-09-05 20:47:45 +0200 | [diff] [blame] | 926 | panfrost_free_batch(batch); |
Boris Brezillon | a45984b | 2019-09-15 19:15:16 +0200 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | void |
| 930 | panfrost_flush_all_batches(struct panfrost_context *ctx, bool wait) |
| 931 | { |
| 932 | struct util_dynarray fences, syncobjs; |
| 933 | |
| 934 | if (wait) { |
| 935 | util_dynarray_init(&fences, NULL); |
| 936 | util_dynarray_init(&syncobjs, NULL); |
| 937 | } |
| 938 | |
| 939 | hash_table_foreach(ctx->batches, hentry) { |
| 940 | struct panfrost_batch *batch = hentry->data; |
| 941 | |
| 942 | assert(batch); |
| 943 | |
| 944 | if (wait) { |
| 945 | panfrost_batch_fence_reference(batch->out_sync); |
| 946 | util_dynarray_append(&fences, struct panfrost_batch_fence *, |
| 947 | batch->out_sync); |
| 948 | util_dynarray_append(&syncobjs, uint32_t, |
| 949 | batch->out_sync->syncobj); |
| 950 | } |
| 951 | |
| 952 | panfrost_batch_submit(batch); |
| 953 | } |
| 954 | |
| 955 | assert(!ctx->batches->entries); |
| 956 | |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 957 | /* Collect batch fences before returning */ |
| 958 | panfrost_gc_fences(ctx); |
Boris Brezillon | a45984b | 2019-09-15 19:15:16 +0200 | [diff] [blame] | 959 | |
| 960 | if (!wait) |
| 961 | return; |
| 962 | |
| 963 | drmSyncobjWait(pan_screen(ctx->base.screen)->fd, |
| 964 | util_dynarray_begin(&syncobjs), |
| 965 | util_dynarray_num_elements(&syncobjs, uint32_t), |
| 966 | INT64_MAX, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL, NULL); |
| 967 | |
| 968 | util_dynarray_foreach(&fences, struct panfrost_batch_fence *, fence) |
| 969 | panfrost_batch_fence_unreference(*fence); |
| 970 | |
| 971 | util_dynarray_fini(&fences); |
| 972 | util_dynarray_fini(&syncobjs); |
Rohan Garg | 0f43a2a | 2019-06-05 16:20:59 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | void |
Boris Brezillon | 82399b5 | 2019-09-15 20:17:14 +0200 | [diff] [blame] | 976 | panfrost_flush_batches_accessing_bo(struct panfrost_context *ctx, |
| 977 | struct panfrost_bo *bo, |
| 978 | uint32_t access_type) |
| 979 | { |
| 980 | struct panfrost_bo_access *access; |
| 981 | struct hash_entry *hentry; |
| 982 | |
| 983 | /* It doesn't make any to flush only the readers. */ |
| 984 | assert(access_type == PAN_BO_ACCESS_WRITE || |
| 985 | access_type == PAN_BO_ACCESS_RW); |
| 986 | |
| 987 | hentry = _mesa_hash_table_search(ctx->accessed_bos, bo); |
| 988 | access = hentry ? hentry->data : NULL; |
| 989 | if (!access) |
| 990 | return; |
| 991 | |
| 992 | if (access_type & PAN_BO_ACCESS_WRITE && access->writer && |
| 993 | access->writer->batch) |
| 994 | panfrost_batch_submit(access->writer->batch); |
| 995 | |
| 996 | if (!(access_type & PAN_BO_ACCESS_READ)) |
| 997 | return; |
| 998 | |
| 999 | util_dynarray_foreach(&access->readers, struct panfrost_batch_fence *, |
| 1000 | reader) { |
| 1001 | if (*reader && (*reader)->batch) |
| 1002 | panfrost_batch_submit((*reader)->batch); |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | void |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 1007 | panfrost_batch_set_requirements(struct panfrost_batch *batch) |
Rohan Garg | bfca21b | 2019-06-05 17:49:14 +0200 | [diff] [blame] | 1008 | { |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 1009 | struct panfrost_context *ctx = batch->ctx; |
| 1010 | |
Rohan Garg | bfca21b | 2019-06-05 17:49:14 +0200 | [diff] [blame] | 1011 | if (ctx->rasterizer && ctx->rasterizer->base.multisample) |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1012 | batch->requirements |= PAN_REQ_MSAA; |
Rohan Garg | bfca21b | 2019-06-05 17:49:14 +0200 | [diff] [blame] | 1013 | |
| 1014 | if (ctx->depth_stencil && ctx->depth_stencil->depth.writemask) |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1015 | batch->requirements |= PAN_REQ_DEPTH_WRITE; |
Rohan Garg | bfca21b | 2019-06-05 17:49:14 +0200 | [diff] [blame] | 1016 | } |
| 1017 | |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1018 | /* Helper to smear a 32-bit color across 128-bit components */ |
| 1019 | |
| 1020 | static void |
| 1021 | pan_pack_color_32(uint32_t *packed, uint32_t v) |
| 1022 | { |
| 1023 | for (unsigned i = 0; i < 4; ++i) |
| 1024 | packed[i] = v; |
| 1025 | } |
| 1026 | |
| 1027 | static void |
| 1028 | pan_pack_color_64(uint32_t *packed, uint32_t lo, uint32_t hi) |
| 1029 | { |
| 1030 | for (unsigned i = 0; i < 4; i += 2) { |
| 1031 | packed[i + 0] = lo; |
| 1032 | packed[i + 1] = hi; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | static void |
| 1037 | pan_pack_color(uint32_t *packed, const union pipe_color_union *color, enum pipe_format format) |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1038 | { |
| 1039 | /* Alpha magicked to 1.0 if there is no alpha */ |
| 1040 | |
| 1041 | bool has_alpha = util_format_has_alpha(format); |
| 1042 | float clear_alpha = has_alpha ? color->f[3] : 1.0f; |
| 1043 | |
| 1044 | /* Packed color depends on the framebuffer format */ |
| 1045 | |
| 1046 | const struct util_format_description *desc = |
| 1047 | util_format_description(format); |
| 1048 | |
| 1049 | if (util_format_is_rgba8_variant(desc)) { |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1050 | pan_pack_color_32(packed, |
Alyssa Rosenzweig | a2d0ea9 | 2019-07-10 10:10:31 -0700 | [diff] [blame] | 1051 | (float_to_ubyte(clear_alpha) << 24) | |
| 1052 | (float_to_ubyte(color->f[2]) << 16) | |
| 1053 | (float_to_ubyte(color->f[1]) << 8) | |
| 1054 | (float_to_ubyte(color->f[0]) << 0)); |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1055 | } else if (format == PIPE_FORMAT_B5G6R5_UNORM) { |
| 1056 | /* First, we convert the components to R5, G6, B5 separately */ |
| 1057 | unsigned r5 = CLAMP(color->f[0], 0.0, 1.0) * 31.0; |
| 1058 | unsigned g6 = CLAMP(color->f[1], 0.0, 1.0) * 63.0; |
| 1059 | unsigned b5 = CLAMP(color->f[2], 0.0, 1.0) * 31.0; |
| 1060 | |
| 1061 | /* Then we pack into a sparse u32. TODO: Why these shifts? */ |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1062 | pan_pack_color_32(packed, (b5 << 25) | (g6 << 14) | (r5 << 5)); |
| 1063 | } else if (format == PIPE_FORMAT_B4G4R4A4_UNORM) { |
| 1064 | /* We scale the components against 0xF0 (=240.0), rather than 0xFF */ |
| 1065 | unsigned r4 = CLAMP(color->f[0], 0.0, 1.0) * 240.0; |
| 1066 | unsigned g4 = CLAMP(color->f[1], 0.0, 1.0) * 240.0; |
| 1067 | unsigned b4 = CLAMP(color->f[2], 0.0, 1.0) * 240.0; |
| 1068 | unsigned a4 = CLAMP(clear_alpha, 0.0, 1.0) * 240.0; |
| 1069 | |
| 1070 | /* Pack on *byte* intervals */ |
| 1071 | pan_pack_color_32(packed, (a4 << 24) | (b4 << 16) | (g4 << 8) | r4); |
| 1072 | } else if (format == PIPE_FORMAT_B5G5R5A1_UNORM) { |
| 1073 | /* Scale as expected but shift oddly */ |
| 1074 | unsigned r5 = round(CLAMP(color->f[0], 0.0, 1.0)) * 31.0; |
| 1075 | unsigned g5 = round(CLAMP(color->f[1], 0.0, 1.0)) * 31.0; |
| 1076 | unsigned b5 = round(CLAMP(color->f[2], 0.0, 1.0)) * 31.0; |
| 1077 | unsigned a1 = round(CLAMP(clear_alpha, 0.0, 1.0)) * 1.0; |
| 1078 | |
| 1079 | pan_pack_color_32(packed, (a1 << 31) | (b5 << 25) | (g5 << 15) | (r5 << 5)); |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1080 | } else { |
Alyssa Rosenzweig | 7692ad1 | 2019-06-28 18:46:43 -0700 | [diff] [blame] | 1081 | /* Try Gallium's generic default path. Doesn't work for all |
| 1082 | * formats but it's a good guess. */ |
| 1083 | |
| 1084 | union util_color out; |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1085 | |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1086 | if (util_format_is_pure_integer(format)) { |
| 1087 | memcpy(out.ui, color->ui, 16); |
| 1088 | } else { |
| 1089 | util_pack_color(color->f, format, &out); |
| 1090 | } |
| 1091 | |
| 1092 | unsigned size = util_format_get_blocksize(format); |
| 1093 | |
| 1094 | if (size == 1) { |
| 1095 | unsigned b = out.ui[0]; |
| 1096 | unsigned s = b | (b << 8); |
| 1097 | pan_pack_color_32(packed, s | (s << 16)); |
| 1098 | } else if (size == 2) |
| 1099 | pan_pack_color_32(packed, out.ui[0] | (out.ui[0] << 16)); |
| 1100 | else if (size == 4) |
| 1101 | pan_pack_color_32(packed, out.ui[0]); |
| 1102 | else if (size == 8) |
| 1103 | pan_pack_color_64(packed, out.ui[0], out.ui[1]); |
| 1104 | else if (size == 16) |
| 1105 | memcpy(packed, out.ui, 16); |
| 1106 | else |
| 1107 | unreachable("Unknown generic format size packing clear colour"); |
| 1108 | } |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | void |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 1112 | panfrost_batch_clear(struct panfrost_batch *batch, |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1113 | unsigned buffers, |
| 1114 | const union pipe_color_union *color, |
| 1115 | double depth, unsigned stencil) |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1116 | { |
Boris Brezillon | 12d8a17 | 2019-09-05 21:41:28 +0200 | [diff] [blame] | 1117 | struct panfrost_context *ctx = batch->ctx; |
| 1118 | |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1119 | if (buffers & PIPE_CLEAR_COLOR) { |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1120 | for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) { |
| 1121 | if (!(buffers & (PIPE_CLEAR_COLOR0 << i))) |
| 1122 | continue; |
| 1123 | |
| 1124 | enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format; |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1125 | pan_pack_color(batch->clear_color[i], color, format); |
Alyssa Rosenzweig | 8e4e467 | 2019-07-01 11:49:06 -0700 | [diff] [blame] | 1126 | } |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | if (buffers & PIPE_CLEAR_DEPTH) { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1130 | batch->clear_depth = depth; |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | if (buffers & PIPE_CLEAR_STENCIL) { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1134 | batch->clear_stencil = stencil; |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1137 | batch->clear |= buffers; |
Alyssa Rosenzweig | c378829 | 2019-06-18 12:30:55 -0700 | [diff] [blame] | 1138 | |
| 1139 | /* Clearing affects the entire framebuffer (by definition -- this is |
| 1140 | * the Gallium clear callback, which clears the whole framebuffer. If |
| 1141 | * the scissor test were enabled from the GL side, the state tracker |
| 1142 | * would emit a quad instead and we wouldn't go down this code path) */ |
| 1143 | |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1144 | panfrost_batch_union_scissor(batch, 0, 0, |
| 1145 | ctx->pipe_framebuffer.width, |
| 1146 | ctx->pipe_framebuffer.height); |
Rohan Garg | ad284f7 | 2019-06-05 19:04:04 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1149 | static bool |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1150 | panfrost_batch_compare(const void *a, const void *b) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1151 | { |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 1152 | return util_framebuffer_state_equal(a, b); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | static uint32_t |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1156 | panfrost_batch_hash(const void *key) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1157 | { |
Boris Brezillon | 1b5873b | 2019-09-01 10:24:30 +0200 | [diff] [blame] | 1158 | return _mesa_hash_data(key, sizeof(struct pipe_framebuffer_state)); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
Alyssa Rosenzweig | c378829 | 2019-06-18 12:30:55 -0700 | [diff] [blame] | 1161 | /* Given a new bounding rectangle (scissor), let the job cover the union of the |
| 1162 | * new and old bounding rectangles */ |
| 1163 | |
| 1164 | void |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1165 | panfrost_batch_union_scissor(struct panfrost_batch *batch, |
| 1166 | unsigned minx, unsigned miny, |
| 1167 | unsigned maxx, unsigned maxy) |
Alyssa Rosenzweig | c378829 | 2019-06-18 12:30:55 -0700 | [diff] [blame] | 1168 | { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1169 | batch->minx = MIN2(batch->minx, minx); |
| 1170 | batch->miny = MIN2(batch->miny, miny); |
| 1171 | batch->maxx = MAX2(batch->maxx, maxx); |
| 1172 | batch->maxy = MAX2(batch->maxy, maxy); |
Alyssa Rosenzweig | c378829 | 2019-06-18 12:30:55 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1175 | void |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1176 | panfrost_batch_intersection_scissor(struct panfrost_batch *batch, |
Boris Brezillon | 65ae86b | 2019-08-12 12:07:08 +0200 | [diff] [blame] | 1177 | unsigned minx, unsigned miny, |
| 1178 | unsigned maxx, unsigned maxy) |
| 1179 | { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1180 | batch->minx = MAX2(batch->minx, minx); |
| 1181 | batch->miny = MAX2(batch->miny, miny); |
| 1182 | batch->maxx = MIN2(batch->maxx, maxx); |
| 1183 | batch->maxy = MIN2(batch->maxy, maxy); |
Boris Brezillon | 65ae86b | 2019-08-12 12:07:08 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Boris Brezillon | e46d95d | 2019-09-01 10:54:38 +0200 | [diff] [blame] | 1186 | /* Are we currently rendering to the screen (rather than an FBO)? */ |
| 1187 | |
| 1188 | bool |
| 1189 | panfrost_batch_is_scanout(struct panfrost_batch *batch) |
| 1190 | { |
| 1191 | /* If there is no color buffer, it's an FBO */ |
| 1192 | if (batch->key.nr_cbufs != 1) |
| 1193 | return false; |
| 1194 | |
| 1195 | /* If we're too early that no framebuffer was sent, it's scanout */ |
| 1196 | if (!batch->key.cbufs[0]) |
| 1197 | return true; |
| 1198 | |
| 1199 | return batch->key.cbufs[0]->texture->bind & PIPE_BIND_DISPLAY_TARGET || |
| 1200 | batch->key.cbufs[0]->texture->bind & PIPE_BIND_SCANOUT || |
| 1201 | batch->key.cbufs[0]->texture->bind & PIPE_BIND_SHARED; |
| 1202 | } |
| 1203 | |
Boris Brezillon | 65ae86b | 2019-08-12 12:07:08 +0200 | [diff] [blame] | 1204 | void |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1205 | panfrost_batch_init(struct panfrost_context *ctx) |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1206 | { |
Boris Brezillon | 2c52699 | 2019-09-05 21:41:26 +0200 | [diff] [blame] | 1207 | ctx->batches = _mesa_hash_table_create(ctx, |
| 1208 | panfrost_batch_hash, |
| 1209 | panfrost_batch_compare); |
Boris Brezillon | 2dad9fd | 2019-09-15 13:39:52 +0200 | [diff] [blame] | 1210 | ctx->accessed_bos = _mesa_hash_table_create(ctx, _mesa_hash_pointer, |
| 1211 | _mesa_key_pointer_equal); |
Alyssa Rosenzweig | 59c9623 | 2019-02-25 05:32:16 +0000 | [diff] [blame] | 1212 | } |