1 /*
2 * Copyright 2013-2017 Advanced Micro Devices, Inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "si_build_pm4.h"
8 #include "util/os_time.h"
9 #include "util/u_memory.h"
10 #include "util/u_queue.h"
11 #include "util/u_upload_mgr.h"
12
13 #include <libsync.h>
14
15 struct si_fine_fence {
16 struct si_resource *buf;
17 unsigned offset;
18 };
19
20 struct si_fence {
21 struct pipe_reference reference;
22 struct pipe_fence_handle *gfx;
23 struct tc_unflushed_batch_token *tc_token;
24 struct util_queue_fence ready;
25
26 /* If the context wasn't flushed at fence creation, this is non-NULL. */
27 struct {
28 struct si_context *ctx;
29 unsigned ib_index;
30 } gfx_unflushed;
31
32 struct si_fine_fence fine;
33 };
34
35 /**
36 * Write an EOP event.
37 *
38 * \param event EVENT_TYPE_*
39 * \param event_flags Optional cache flush flags (TC)
40 * \param dst_sel MEM or TC_L2
41 * \param int_sel NONE or SEND_DATA_AFTER_WR_CONFIRM
42 * \param data_sel DISCARD, VALUE_32BIT, TIMESTAMP, or GDS
43 * \param buf Buffer
44 * \param va GPU address
45 * \param old_value Previous fence value (for a bug workaround)
46 * \param new_value Fence value to write for this event.
47 */
si_cp_release_mem(struct si_context * ctx,struct radeon_cmdbuf * cs,unsigned event,unsigned event_flags,unsigned dst_sel,unsigned int_sel,unsigned data_sel,struct si_resource * buf,uint64_t va,uint32_t new_fence,unsigned query_type)48 void si_cp_release_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, unsigned event,
49 unsigned event_flags, unsigned dst_sel, unsigned int_sel, unsigned data_sel,
50 struct si_resource *buf, uint64_t va, uint32_t new_fence,
51 unsigned query_type)
52 {
53 unsigned op = EVENT_TYPE(event) |
54 EVENT_INDEX(event == V_028A90_CS_DONE || event == V_028A90_PS_DONE ? 6 : 5) |
55 event_flags;
56 unsigned sel = EOP_DST_SEL(dst_sel) | EOP_INT_SEL(int_sel) | EOP_DATA_SEL(data_sel);
57 bool compute_ib = !ctx->has_graphics;
58
59 radeon_begin(cs);
60
61 if (ctx->gfx_level >= GFX9 || (compute_ib && ctx->gfx_level >= GFX7)) {
62 /* A ZPASS_DONE or PIXEL_STAT_DUMP_EVENT (of the DB occlusion
63 * counters) must immediately precede every timestamp event to
64 * prevent a GPU hang on GFX9.
65 *
66 * Occlusion queries don't need to do it here, because they
67 * always do ZPASS_DONE before the timestamp.
68 */
69 if (ctx->gfx_level == GFX9 && !compute_ib && query_type != PIPE_QUERY_OCCLUSION_COUNTER &&
70 query_type != PIPE_QUERY_OCCLUSION_PREDICATE &&
71 query_type != PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE) {
72 struct si_screen *sscreen = ctx->screen;
73 struct si_resource *scratch;
74
75 if (!ctx->ws->cs_is_secure(&ctx->gfx_cs)) {
76 scratch = ctx->eop_bug_scratch;
77 } else {
78 assert(ctx->screen->info.has_tmz_support);
79 if (!ctx->eop_bug_scratch_tmz)
80 ctx->eop_bug_scratch_tmz =
81 si_aligned_buffer_create(&sscreen->b,
82 PIPE_RESOURCE_FLAG_ENCRYPTED |
83 PIPE_RESOURCE_FLAG_UNMAPPABLE |
84 SI_RESOURCE_FLAG_DRIVER_INTERNAL,
85 PIPE_USAGE_DEFAULT,
86 16 * sscreen->info.max_render_backends, 256);
87
88 scratch = ctx->eop_bug_scratch_tmz;
89 }
90
91 assert(16 * ctx->screen->info.max_render_backends <= scratch->b.b.width0);
92 radeon_emit(PKT3(PKT3_EVENT_WRITE, 2, 0));
93 radeon_emit(EVENT_TYPE(V_028A90_ZPASS_DONE) | EVENT_INDEX(1));
94 radeon_emit(scratch->gpu_address);
95 radeon_emit(scratch->gpu_address >> 32);
96
97 radeon_add_to_buffer_list(ctx, &ctx->gfx_cs, scratch,
98 RADEON_USAGE_WRITE | RADEON_PRIO_QUERY);
99 }
100
101 radeon_emit(PKT3(PKT3_RELEASE_MEM, ctx->gfx_level >= GFX9 ? 6 : 5, 0));
102 radeon_emit(op);
103 radeon_emit(sel);
104 radeon_emit(va); /* address lo */
105 radeon_emit(va >> 32); /* address hi */
106 radeon_emit(new_fence); /* immediate data lo */
107 radeon_emit(0); /* immediate data hi */
108 if (ctx->gfx_level >= GFX9)
109 radeon_emit(0); /* unused */
110 } else {
111 if (ctx->gfx_level == GFX7 || ctx->gfx_level == GFX8) {
112 struct si_resource *scratch = ctx->eop_bug_scratch;
113 uint64_t va = scratch->gpu_address;
114
115 /* Two EOP events are required to make all engines go idle
116 * (and optional cache flushes executed) before the timestamp
117 * is written.
118 */
119 radeon_emit(PKT3(PKT3_EVENT_WRITE_EOP, 4, 0));
120 radeon_emit(op);
121 radeon_emit(va);
122 radeon_emit(((va >> 32) & 0xffff) | sel);
123 radeon_emit(0); /* immediate data */
124 radeon_emit(0); /* unused */
125
126 radeon_add_to_buffer_list(ctx, &ctx->gfx_cs, scratch,
127 RADEON_USAGE_WRITE | RADEON_PRIO_QUERY);
128 }
129
130 radeon_emit(PKT3(PKT3_EVENT_WRITE_EOP, 4, 0));
131 radeon_emit(op);
132 radeon_emit(va);
133 radeon_emit(((va >> 32) & 0xffff) | sel);
134 radeon_emit(new_fence); /* immediate data */
135 radeon_emit(0); /* unused */
136 }
137
138 radeon_end();
139
140 if (buf) {
141 radeon_add_to_buffer_list(ctx, &ctx->gfx_cs, buf, RADEON_USAGE_WRITE | RADEON_PRIO_QUERY);
142 }
143 }
144
si_cp_write_fence_dwords(struct si_screen * screen)145 unsigned si_cp_write_fence_dwords(struct si_screen *screen)
146 {
147 unsigned dwords = 6;
148
149 if (screen->info.gfx_level == GFX7 || screen->info.gfx_level == GFX8)
150 dwords *= 2;
151
152 return dwords;
153 }
154
si_cp_wait_mem(struct si_context * ctx,struct radeon_cmdbuf * cs,uint64_t va,uint32_t ref,uint32_t mask,unsigned flags)155 void si_cp_wait_mem(struct si_context *ctx, struct radeon_cmdbuf *cs, uint64_t va, uint32_t ref,
156 uint32_t mask, unsigned flags)
157 {
158 radeon_begin(cs);
159 radeon_emit(PKT3(PKT3_WAIT_REG_MEM, 5, 0));
160 radeon_emit(WAIT_REG_MEM_MEM_SPACE(1) | flags);
161 radeon_emit(va);
162 radeon_emit(va >> 32);
163 radeon_emit(ref); /* reference value */
164 radeon_emit(mask); /* mask */
165 radeon_emit(4); /* poll interval */
166 radeon_end();
167 }
168
si_add_fence_dependency(struct si_context * sctx,struct pipe_fence_handle * fence)169 static void si_add_fence_dependency(struct si_context *sctx, struct pipe_fence_handle *fence)
170 {
171 struct radeon_winsys *ws = sctx->ws;
172
173 ws->cs_add_fence_dependency(&sctx->gfx_cs, fence);
174 }
175
si_add_syncobj_signal(struct si_context * sctx,struct pipe_fence_handle * fence)176 static void si_add_syncobj_signal(struct si_context *sctx, struct pipe_fence_handle *fence)
177 {
178 sctx->ws->cs_add_syncobj_signal(&sctx->gfx_cs, fence);
179 }
180
si_fence_reference(struct pipe_screen * screen,struct pipe_fence_handle ** dst,struct pipe_fence_handle * src)181 static void si_fence_reference(struct pipe_screen *screen, struct pipe_fence_handle **dst,
182 struct pipe_fence_handle *src)
183 {
184 struct radeon_winsys *ws = ((struct si_screen *)screen)->ws;
185 struct si_fence **sdst = (struct si_fence **)dst;
186 struct si_fence *ssrc = (struct si_fence *)src;
187
188 if (pipe_reference(&(*sdst)->reference, &ssrc->reference)) {
189 ws->fence_reference(ws, &(*sdst)->gfx, NULL);
190 tc_unflushed_batch_token_reference(&(*sdst)->tc_token, NULL);
191 si_resource_reference(&(*sdst)->fine.buf, NULL);
192 FREE(*sdst);
193 }
194 *sdst = ssrc;
195 }
196
si_alloc_fence()197 static struct si_fence *si_alloc_fence()
198 {
199 struct si_fence *fence = CALLOC_STRUCT(si_fence);
200 if (!fence)
201 return NULL;
202
203 pipe_reference_init(&fence->reference, 1);
204 util_queue_fence_init(&fence->ready);
205
206 return fence;
207 }
208
si_create_fence(struct pipe_context * ctx,struct tc_unflushed_batch_token * tc_token)209 struct pipe_fence_handle *si_create_fence(struct pipe_context *ctx,
210 struct tc_unflushed_batch_token *tc_token)
211 {
212 struct si_fence *fence = si_alloc_fence();
213 if (!fence)
214 return NULL;
215
216 util_queue_fence_reset(&fence->ready);
217 tc_unflushed_batch_token_reference(&fence->tc_token, tc_token);
218
219 return (struct pipe_fence_handle *)fence;
220 }
221
si_fine_fence_signaled(struct radeon_winsys * rws,const struct si_fine_fence * fine)222 static bool si_fine_fence_signaled(struct radeon_winsys *rws, const struct si_fine_fence *fine)
223 {
224 char *map =
225 rws->buffer_map(rws, fine->buf->buf, NULL, PIPE_MAP_READ | PIPE_MAP_UNSYNCHRONIZED);
226 if (!map)
227 return false;
228
229 uint32_t *fence = (uint32_t *)(map + fine->offset);
230 return *fence != 0;
231 }
232
si_fine_fence_set(struct si_context * ctx,struct si_fine_fence * fine,unsigned flags)233 static void si_fine_fence_set(struct si_context *ctx, struct si_fine_fence *fine, unsigned flags)
234 {
235 uint32_t *fence_ptr;
236
237 assert(util_bitcount(flags & (PIPE_FLUSH_TOP_OF_PIPE | PIPE_FLUSH_BOTTOM_OF_PIPE)) == 1);
238
239 /* Use cached system memory for the fence. */
240 u_upload_alloc(ctx->cached_gtt_allocator, 0, 4, 4, &fine->offset,
241 (struct pipe_resource **)&fine->buf, (void **)&fence_ptr);
242 if (!fine->buf)
243 return;
244
245 *fence_ptr = 0;
246
247 if (flags & PIPE_FLUSH_TOP_OF_PIPE) {
248 uint32_t value = 0x80000000;
249
250 si_cp_write_data(ctx, fine->buf, fine->offset, 4, V_370_MEM, V_370_PFP, &value);
251 } else if (flags & PIPE_FLUSH_BOTTOM_OF_PIPE) {
252 uint64_t fence_va = fine->buf->gpu_address + fine->offset;
253
254 radeon_add_to_buffer_list(ctx, &ctx->gfx_cs, fine->buf, RADEON_USAGE_WRITE | RADEON_PRIO_QUERY);
255 si_cp_release_mem(ctx, &ctx->gfx_cs, V_028A90_BOTTOM_OF_PIPE_TS, 0, EOP_DST_SEL_MEM,
256 EOP_INT_SEL_NONE, EOP_DATA_SEL_VALUE_32BIT, NULL, fence_va, 0x80000000,
257 PIPE_QUERY_GPU_FINISHED);
258 } else {
259 assert(false);
260 }
261 }
262
si_fence_finish(struct pipe_screen * screen,struct pipe_context * ctx,struct pipe_fence_handle * fence,uint64_t timeout)263 static bool si_fence_finish(struct pipe_screen *screen, struct pipe_context *ctx,
264 struct pipe_fence_handle *fence, uint64_t timeout)
265 {
266 struct radeon_winsys *rws = ((struct si_screen *)screen)->ws;
267 struct si_fence *sfence = (struct si_fence *)fence;
268 struct si_context *sctx;
269 int64_t abs_timeout = os_time_get_absolute_timeout(timeout);
270
271 ctx = threaded_context_unwrap_sync(ctx);
272 sctx = (struct si_context *)(ctx ? ctx : NULL);
273
274 if (!util_queue_fence_is_signalled(&sfence->ready)) {
275 if (sfence->tc_token) {
276 /* Ensure that si_flush_from_st will be called for
277 * this fence, but only if we're in the API thread
278 * where the context is current.
279 *
280 * Note that the batch containing the flush may already
281 * be in flight in the driver thread, so the fence
282 * may not be ready yet when this call returns.
283 */
284 threaded_context_flush(ctx, sfence->tc_token, timeout == 0);
285 }
286
287 if (!timeout)
288 return false;
289
290 if (timeout == OS_TIMEOUT_INFINITE) {
291 util_queue_fence_wait(&sfence->ready);
292 } else {
293 if (!util_queue_fence_wait_timeout(&sfence->ready, abs_timeout))
294 return false;
295 }
296
297 if (timeout && timeout != OS_TIMEOUT_INFINITE) {
298 int64_t time = os_time_get_nano();
299 timeout = abs_timeout > time ? abs_timeout - time : 0;
300 }
301 }
302
303 if (!sfence->gfx)
304 return true;
305
306 if (sfence->fine.buf && si_fine_fence_signaled(rws, &sfence->fine)) {
307 rws->fence_reference(rws, &sfence->gfx, NULL);
308 si_resource_reference(&sfence->fine.buf, NULL);
309 return true;
310 }
311
312 /* Flush the gfx IB if it hasn't been flushed yet. */
313 if (sctx && sfence->gfx_unflushed.ctx == sctx &&
314 sfence->gfx_unflushed.ib_index == sctx->num_gfx_cs_flushes) {
315 /* Section 4.1.2 (Signaling) of the OpenGL 4.6 (Core profile)
316 * spec says:
317 *
318 * "If the sync object being blocked upon will not be
319 * signaled in finite time (for example, by an associated
320 * fence command issued previously, but not yet flushed to
321 * the graphics pipeline), then ClientWaitSync may hang
322 * forever. To help prevent this behavior, if
323 * ClientWaitSync is called and all of the following are
324 * true:
325 *
326 * * the SYNC_FLUSH_COMMANDS_BIT bit is set in flags,
327 * * sync is unsignaled when ClientWaitSync is called,
328 * * and the calls to ClientWaitSync and FenceSync were
329 * issued from the same context,
330 *
331 * then the GL will behave as if the equivalent of Flush
332 * were inserted immediately after the creation of sync."
333 *
334 * This means we need to flush for such fences even when we're
335 * not going to wait.
336 */
337 si_flush_gfx_cs(sctx, (timeout ? 0 : PIPE_FLUSH_ASYNC) | RADEON_FLUSH_START_NEXT_GFX_IB_NOW,
338 NULL);
339 sfence->gfx_unflushed.ctx = NULL;
340
341 if (!timeout)
342 return false;
343
344 /* Recompute the timeout after all that. */
345 if (timeout && timeout != OS_TIMEOUT_INFINITE) {
346 int64_t time = os_time_get_nano();
347 timeout = abs_timeout > time ? abs_timeout - time : 0;
348 }
349 }
350
351 if (rws->fence_wait(rws, sfence->gfx, timeout))
352 return true;
353
354 /* Re-check in case the GPU is slow or hangs, but the commands before
355 * the fine-grained fence have completed. */
356 if (sfence->fine.buf && si_fine_fence_signaled(rws, &sfence->fine))
357 return true;
358
359 return false;
360 }
361
si_create_fence_fd(struct pipe_context * ctx,struct pipe_fence_handle ** pfence,int fd,enum pipe_fd_type type)362 static void si_create_fence_fd(struct pipe_context *ctx, struct pipe_fence_handle **pfence, int fd,
363 enum pipe_fd_type type)
364 {
365 struct si_screen *sscreen = (struct si_screen *)ctx->screen;
366 struct radeon_winsys *ws = sscreen->ws;
367 struct si_fence *sfence;
368
369 *pfence = NULL;
370
371 sfence = si_alloc_fence();
372 if (!sfence)
373 return;
374
375 switch (type) {
376 case PIPE_FD_TYPE_NATIVE_SYNC:
377 sfence->gfx = ws->fence_import_sync_file(ws, fd);
378 break;
379
380 case PIPE_FD_TYPE_SYNCOBJ:
381 sfence->gfx = ws->fence_import_syncobj(ws, fd);
382 break;
383
384 default:
385 unreachable("bad fence fd type when importing");
386 }
387
388 if (!sfence->gfx) {
389 FREE(sfence);
390 return;
391 }
392
393 *pfence = (struct pipe_fence_handle *)sfence;
394 }
395
si_fence_get_fd(struct pipe_screen * screen,struct pipe_fence_handle * fence)396 static int si_fence_get_fd(struct pipe_screen *screen, struct pipe_fence_handle *fence)
397 {
398 struct si_screen *sscreen = (struct si_screen *)screen;
399 struct radeon_winsys *ws = sscreen->ws;
400 struct si_fence *sfence = (struct si_fence *)fence;
401 int gfx_fd = -1;
402
403 util_queue_fence_wait(&sfence->ready);
404
405 /* Deferred fences aren't supported. */
406 assert(!sfence->gfx_unflushed.ctx);
407 if (sfence->gfx_unflushed.ctx)
408 return -1;
409
410 if (sfence->gfx) {
411 gfx_fd = ws->fence_export_sync_file(ws, sfence->gfx);
412 if (gfx_fd == -1) {
413 return -1;
414 }
415 }
416
417 /* If we don't have FDs at this point, it means we don't have fences
418 * either. */
419 if (gfx_fd == -1)
420 return ws->export_signalled_sync_file(ws);
421
422 return gfx_fd;
423 }
424
si_flush_all_queues(struct pipe_context * ctx,struct pipe_fence_handle ** fence,unsigned flags,bool force_flush)425 static void si_flush_all_queues(struct pipe_context *ctx,
426 struct pipe_fence_handle **fence,
427 unsigned flags, bool force_flush)
428 {
429 struct pipe_screen *screen = ctx->screen;
430 struct si_context *sctx = (struct si_context *)ctx;
431 struct radeon_winsys *ws = sctx->ws;
432 struct pipe_fence_handle *gfx_fence = NULL;
433 bool deferred_fence = false;
434 struct si_fine_fence fine = {};
435 unsigned rflags = PIPE_FLUSH_ASYNC;
436
437 if (!(flags & PIPE_FLUSH_DEFERRED)) {
438 si_flush_implicit_resources(sctx);
439 }
440
441 if (flags & PIPE_FLUSH_END_OF_FRAME)
442 rflags |= PIPE_FLUSH_END_OF_FRAME;
443
444 if (flags & (PIPE_FLUSH_TOP_OF_PIPE | PIPE_FLUSH_BOTTOM_OF_PIPE)) {
445 assert(flags & PIPE_FLUSH_DEFERRED);
446 assert(fence);
447
448 si_fine_fence_set(sctx, &fine, flags);
449 }
450
451 if (force_flush) {
452 sctx->initial_gfx_cs_size = 0;
453 }
454
455 if (!radeon_emitted(&sctx->gfx_cs, sctx->initial_gfx_cs_size)) {
456 if (fence)
457 ws->fence_reference(ws, &gfx_fence, sctx->last_gfx_fence);
458 if (!(flags & PIPE_FLUSH_DEFERRED))
459 ws->cs_sync_flush(&sctx->gfx_cs);
460
461 tc_driver_internal_flush_notify(sctx->tc);
462
463 if (unlikely(sctx->sqtt && (flags & PIPE_FLUSH_END_OF_FRAME))) {
464 si_handle_sqtt(sctx, &sctx->gfx_cs);
465 }
466
467 if (u_trace_perfetto_active(&sctx->ds.trace_context)) {
468 u_trace_context_process(&sctx->ds.trace_context, flags & PIPE_FLUSH_END_OF_FRAME);
469 }
470 } else {
471 /* Instead of flushing, create a deferred fence. Constraints:
472 * - the gallium frontend must allow a deferred flush.
473 * - the gallium frontend must request a fence.
474 * - fence_get_fd is not allowed.
475 * Thread safety in fence_finish must be ensured by the gallium frontend.
476 */
477 if (flags & PIPE_FLUSH_DEFERRED && !(flags & PIPE_FLUSH_FENCE_FD) && fence) {
478 gfx_fence = sctx->ws->cs_get_next_fence(&sctx->gfx_cs);
479 deferred_fence = true;
480 } else {
481 si_flush_gfx_cs(sctx, rflags, fence ? &gfx_fence : NULL);
482 }
483 }
484
485 /* Both engines can signal out of order, so we need to keep both fences. */
486 if (fence) {
487 struct si_fence *new_fence;
488
489 if (flags & TC_FLUSH_ASYNC) {
490 new_fence = (struct si_fence *)*fence;
491 assert(new_fence);
492 } else {
493 new_fence = si_alloc_fence();
494 if (!new_fence) {
495 ws->fence_reference(ws, &gfx_fence, NULL);
496 goto finish;
497 }
498
499 screen->fence_reference(screen, fence, NULL);
500 *fence = (struct pipe_fence_handle *)new_fence;
501 }
502
503 /* If both fences are NULL, fence_finish will always return true. */
504 new_fence->gfx = gfx_fence;
505
506 if (deferred_fence) {
507 new_fence->gfx_unflushed.ctx = sctx;
508 new_fence->gfx_unflushed.ib_index = sctx->num_gfx_cs_flushes;
509 }
510
511 new_fence->fine = fine;
512 fine.buf = NULL;
513
514 if (flags & TC_FLUSH_ASYNC) {
515 util_queue_fence_signal(&new_fence->ready);
516 tc_unflushed_batch_token_reference(&new_fence->tc_token, NULL);
517 }
518 }
519 assert(!fine.buf);
520 finish:
521 if (!(flags & (PIPE_FLUSH_DEFERRED | PIPE_FLUSH_ASYNC))) {
522 ws->cs_sync_flush(&sctx->gfx_cs);
523 }
524 }
525
si_flush_from_st(struct pipe_context * ctx,struct pipe_fence_handle ** fence,unsigned flags)526 static void si_flush_from_st(struct pipe_context *ctx, struct pipe_fence_handle **fence,
527 unsigned flags)
528 {
529 return si_flush_all_queues(ctx, fence, flags, false);
530 }
531
si_fence_server_signal(struct pipe_context * ctx,struct pipe_fence_handle * fence)532 static void si_fence_server_signal(struct pipe_context *ctx, struct pipe_fence_handle *fence)
533 {
534 struct si_context *sctx = (struct si_context *)ctx;
535 struct si_fence *sfence = (struct si_fence *)fence;
536
537 assert(sfence->gfx);
538
539 if (sfence->gfx)
540 si_add_syncobj_signal(sctx, sfence->gfx);
541
542 /**
543 * The spec requires a flush here. We insert a flush
544 * because syncobj based signals are not directly placed into
545 * the command stream. Instead the signal happens when the
546 * submission associated with the syncobj finishes execution.
547 *
548 * Therefore, we must make sure that we flush the pipe to avoid
549 * new work being emitted and getting executed before the signal
550 * operation.
551 *
552 * Forces a flush even if the GFX CS is empty.
553 *
554 * The flush must not be asynchronous because the kernel must receive
555 * the scheduled "signal" operation before any wait.
556 */
557 si_flush_all_queues(ctx, NULL, 0, true);
558 }
559
si_fence_server_sync(struct pipe_context * ctx,struct pipe_fence_handle * fence)560 static void si_fence_server_sync(struct pipe_context *ctx, struct pipe_fence_handle *fence)
561 {
562 struct si_context *sctx = (struct si_context *)ctx;
563 struct si_fence *sfence = (struct si_fence *)fence;
564
565 util_queue_fence_wait(&sfence->ready);
566
567 /* Unflushed fences from the same context are no-ops. */
568 if (sfence->gfx_unflushed.ctx && sfence->gfx_unflushed.ctx == sctx)
569 return;
570
571 /* All unflushed commands will not start execution before this fence
572 * dependency is signalled. That's fine. Flushing is very expensive
573 * if we get fence_server_sync after every draw call. (which happens
574 * with Android/SurfaceFlinger)
575 *
576 * In a nutshell, when CPU overhead is greater than GPU overhead,
577 * or when the time it takes to execute an IB on the GPU is less than
578 * the time it takes to create and submit that IB, flushing decreases
579 * performance. Therefore, DO NOT FLUSH.
580 */
581 if (sfence->gfx)
582 si_add_fence_dependency(sctx, sfence->gfx);
583 }
584
si_init_fence_functions(struct si_context * ctx)585 void si_init_fence_functions(struct si_context *ctx)
586 {
587 ctx->b.flush = si_flush_from_st;
588 ctx->b.create_fence_fd = si_create_fence_fd;
589 ctx->b.fence_server_sync = si_fence_server_sync;
590 ctx->b.fence_server_signal = si_fence_server_signal;
591 }
592
si_init_screen_fence_functions(struct si_screen * screen)593 void si_init_screen_fence_functions(struct si_screen *screen)
594 {
595 screen->b.fence_finish = si_fence_finish;
596 screen->b.fence_reference = si_fence_reference;
597 screen->b.fence_get_fd = si_fence_get_fd;
598 }
599