radeonsi: rename si_gfx_* functions to si_cp_*
[mesa.git] / src / gallium / drivers / radeonsi / si_fence.c
1 /*
2 * Copyright 2013-2017 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 */
25
26 #include <libsync.h>
27
28 #include "util/os_time.h"
29 #include "util/u_memory.h"
30 #include "util/u_queue.h"
31 #include "util/u_upload_mgr.h"
32
33 #include "si_build_pm4.h"
34
35 struct si_fine_fence {
36 struct r600_resource *buf;
37 unsigned offset;
38 };
39
40 struct si_multi_fence {
41 struct pipe_reference reference;
42 struct pipe_fence_handle *gfx;
43 struct pipe_fence_handle *sdma;
44 struct tc_unflushed_batch_token *tc_token;
45 struct util_queue_fence ready;
46
47 /* If the context wasn't flushed at fence creation, this is non-NULL. */
48 struct {
49 struct si_context *ctx;
50 unsigned ib_index;
51 } gfx_unflushed;
52
53 struct si_fine_fence fine;
54 };
55
56 /**
57 * Write an EOP event.
58 *
59 * \param event EVENT_TYPE_*
60 * \param event_flags Optional cache flush flags (TC)
61 * \param dst_sel MEM or TC_L2
62 * \param int_sel NONE or SEND_DATA_AFTER_WR_CONFIRM
63 * \param data_sel DISCARD, VALUE_32BIT, TIMESTAMP, or GDS
64 * \param buf Buffer
65 * \param va GPU address
66 * \param old_value Previous fence value (for a bug workaround)
67 * \param new_value Fence value to write for this event.
68 */
69 void si_cp_release_mem(struct si_context *ctx,
70 unsigned event, unsigned event_flags,
71 unsigned dst_sel, unsigned int_sel, unsigned data_sel,
72 struct r600_resource *buf, uint64_t va,
73 uint32_t new_fence, unsigned query_type)
74 {
75 struct radeon_cmdbuf *cs = ctx->gfx_cs;
76 unsigned op = EVENT_TYPE(event) |
77 EVENT_INDEX(event == V_028A90_CS_DONE ||
78 event == V_028A90_PS_DONE ? 6 : 5) |
79 event_flags;
80 unsigned sel = EOP_DST_SEL(dst_sel) |
81 EOP_INT_SEL(int_sel) |
82 EOP_DATA_SEL(data_sel);
83
84 if (ctx->chip_class >= GFX9) {
85 /* A ZPASS_DONE or PIXEL_STAT_DUMP_EVENT (of the DB occlusion
86 * counters) must immediately precede every timestamp event to
87 * prevent a GPU hang on GFX9.
88 *
89 * Occlusion queries don't need to do it here, because they
90 * always do ZPASS_DONE before the timestamp.
91 */
92 if (ctx->chip_class == GFX9 &&
93 query_type != PIPE_QUERY_OCCLUSION_COUNTER &&
94 query_type != PIPE_QUERY_OCCLUSION_PREDICATE &&
95 query_type != PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE) {
96 struct r600_resource *scratch = ctx->eop_bug_scratch;
97
98 assert(16 * ctx->screen->info.num_render_backends <=
99 scratch->b.b.width0);
100 radeon_emit(cs, PKT3(PKT3_EVENT_WRITE, 2, 0));
101 radeon_emit(cs, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1));
102 radeon_emit(cs, scratch->gpu_address);
103 radeon_emit(cs, scratch->gpu_address >> 32);
104
105 radeon_add_to_buffer_list(ctx, ctx->gfx_cs, scratch,
106 RADEON_USAGE_WRITE, RADEON_PRIO_QUERY);
107 }
108
109 radeon_emit(cs, PKT3(PKT3_RELEASE_MEM, 6, 0));
110 radeon_emit(cs, op);
111 radeon_emit(cs, sel);
112 radeon_emit(cs, va); /* address lo */
113 radeon_emit(cs, va >> 32); /* address hi */
114 radeon_emit(cs, new_fence); /* immediate data lo */
115 radeon_emit(cs, 0); /* immediate data hi */
116 radeon_emit(cs, 0); /* unused */
117 } else {
118 if (ctx->chip_class == CIK ||
119 ctx->chip_class == VI) {
120 struct r600_resource *scratch = ctx->eop_bug_scratch;
121 uint64_t va = scratch->gpu_address;
122
123 /* Two EOP events are required to make all engines go idle
124 * (and optional cache flushes executed) before the timestamp
125 * is written.
126 */
127 radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, 0));
128 radeon_emit(cs, op);
129 radeon_emit(cs, va);
130 radeon_emit(cs, ((va >> 32) & 0xffff) | sel);
131 radeon_emit(cs, 0); /* immediate data */
132 radeon_emit(cs, 0); /* unused */
133
134 radeon_add_to_buffer_list(ctx, ctx->gfx_cs, scratch,
135 RADEON_USAGE_WRITE, RADEON_PRIO_QUERY);
136 }
137
138 radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, 0));
139 radeon_emit(cs, op);
140 radeon_emit(cs, va);
141 radeon_emit(cs, ((va >> 32) & 0xffff) | sel);
142 radeon_emit(cs, new_fence); /* immediate data */
143 radeon_emit(cs, 0); /* unused */
144 }
145
146 if (buf) {
147 radeon_add_to_buffer_list(ctx, ctx->gfx_cs, buf, RADEON_USAGE_WRITE,
148 RADEON_PRIO_QUERY);
149 }
150 }
151
152 unsigned si_cp_write_fence_dwords(struct si_screen *screen)
153 {
154 unsigned dwords = 6;
155
156 if (screen->info.chip_class == CIK ||
157 screen->info.chip_class == VI)
158 dwords *= 2;
159
160 return dwords;
161 }
162
163 void si_cp_wait_mem(struct si_context *ctx,
164 uint64_t va, uint32_t ref, uint32_t mask, unsigned flags)
165 {
166 struct radeon_cmdbuf *cs = ctx->gfx_cs;
167
168 radeon_emit(cs, PKT3(PKT3_WAIT_REG_MEM, 5, 0));
169 radeon_emit(cs, WAIT_REG_MEM_EQUAL | WAIT_REG_MEM_MEM_SPACE(1) | flags);
170 radeon_emit(cs, va);
171 radeon_emit(cs, va >> 32);
172 radeon_emit(cs, ref); /* reference value */
173 radeon_emit(cs, mask); /* mask */
174 radeon_emit(cs, 4); /* poll interval */
175 }
176
177 static void si_add_fence_dependency(struct si_context *sctx,
178 struct pipe_fence_handle *fence)
179 {
180 struct radeon_winsys *ws = sctx->ws;
181
182 if (sctx->dma_cs)
183 ws->cs_add_fence_dependency(sctx->dma_cs, fence);
184 ws->cs_add_fence_dependency(sctx->gfx_cs, fence);
185 }
186
187 static void si_add_syncobj_signal(struct si_context *sctx,
188 struct pipe_fence_handle *fence)
189 {
190 sctx->ws->cs_add_syncobj_signal(sctx->gfx_cs, fence);
191 }
192
193 static void si_fence_reference(struct pipe_screen *screen,
194 struct pipe_fence_handle **dst,
195 struct pipe_fence_handle *src)
196 {
197 struct radeon_winsys *ws = ((struct si_screen*)screen)->ws;
198 struct si_multi_fence **rdst = (struct si_multi_fence **)dst;
199 struct si_multi_fence *rsrc = (struct si_multi_fence *)src;
200
201 if (pipe_reference(&(*rdst)->reference, &rsrc->reference)) {
202 ws->fence_reference(&(*rdst)->gfx, NULL);
203 ws->fence_reference(&(*rdst)->sdma, NULL);
204 tc_unflushed_batch_token_reference(&(*rdst)->tc_token, NULL);
205 r600_resource_reference(&(*rdst)->fine.buf, NULL);
206 FREE(*rdst);
207 }
208 *rdst = rsrc;
209 }
210
211 static struct si_multi_fence *si_create_multi_fence()
212 {
213 struct si_multi_fence *fence = CALLOC_STRUCT(si_multi_fence);
214 if (!fence)
215 return NULL;
216
217 pipe_reference_init(&fence->reference, 1);
218 util_queue_fence_init(&fence->ready);
219
220 return fence;
221 }
222
223 struct pipe_fence_handle *si_create_fence(struct pipe_context *ctx,
224 struct tc_unflushed_batch_token *tc_token)
225 {
226 struct si_multi_fence *fence = si_create_multi_fence();
227 if (!fence)
228 return NULL;
229
230 util_queue_fence_reset(&fence->ready);
231 tc_unflushed_batch_token_reference(&fence->tc_token, tc_token);
232
233 return (struct pipe_fence_handle *)fence;
234 }
235
236 static bool si_fine_fence_signaled(struct radeon_winsys *rws,
237 const struct si_fine_fence *fine)
238 {
239 char *map = rws->buffer_map(fine->buf->buf, NULL, PIPE_TRANSFER_READ |
240 PIPE_TRANSFER_UNSYNCHRONIZED);
241 if (!map)
242 return false;
243
244 uint32_t *fence = (uint32_t*)(map + fine->offset);
245 return *fence != 0;
246 }
247
248 static void si_fine_fence_set(struct si_context *ctx,
249 struct si_fine_fence *fine,
250 unsigned flags)
251 {
252 uint32_t *fence_ptr;
253
254 assert(util_bitcount(flags & (PIPE_FLUSH_TOP_OF_PIPE | PIPE_FLUSH_BOTTOM_OF_PIPE)) == 1);
255
256 /* Use uncached system memory for the fence. */
257 u_upload_alloc(ctx->cached_gtt_allocator, 0, 4, 4,
258 &fine->offset, (struct pipe_resource **)&fine->buf, (void **)&fence_ptr);
259 if (!fine->buf)
260 return;
261
262 *fence_ptr = 0;
263
264 uint64_t fence_va = fine->buf->gpu_address + fine->offset;
265
266 radeon_add_to_buffer_list(ctx, ctx->gfx_cs, fine->buf,
267 RADEON_USAGE_WRITE, RADEON_PRIO_QUERY);
268 if (flags & PIPE_FLUSH_TOP_OF_PIPE) {
269 struct radeon_cmdbuf *cs = ctx->gfx_cs;
270 radeon_emit(cs, PKT3(PKT3_WRITE_DATA, 3, 0));
271 radeon_emit(cs, S_370_DST_SEL(V_370_MEM_ASYNC) |
272 S_370_WR_CONFIRM(1) |
273 S_370_ENGINE_SEL(V_370_PFP));
274 radeon_emit(cs, fence_va);
275 radeon_emit(cs, fence_va >> 32);
276 radeon_emit(cs, 0x80000000);
277 } else if (flags & PIPE_FLUSH_BOTTOM_OF_PIPE) {
278 si_cp_release_mem(ctx,
279 V_028A90_BOTTOM_OF_PIPE_TS, 0,
280 EOP_DST_SEL_MEM,
281 EOP_INT_SEL_SEND_DATA_AFTER_WR_CONFIRM,
282 EOP_DATA_SEL_VALUE_32BIT,
283 NULL, fence_va, 0x80000000,
284 PIPE_QUERY_GPU_FINISHED);
285 } else {
286 assert(false);
287 }
288 }
289
290 static boolean si_fence_finish(struct pipe_screen *screen,
291 struct pipe_context *ctx,
292 struct pipe_fence_handle *fence,
293 uint64_t timeout)
294 {
295 struct radeon_winsys *rws = ((struct si_screen*)screen)->ws;
296 struct si_multi_fence *rfence = (struct si_multi_fence *)fence;
297 struct si_context *sctx;
298 int64_t abs_timeout = os_time_get_absolute_timeout(timeout);
299
300 ctx = threaded_context_unwrap_sync(ctx);
301 sctx = (struct si_context*)(ctx ? ctx : NULL);
302
303 if (!util_queue_fence_is_signalled(&rfence->ready)) {
304 if (rfence->tc_token) {
305 /* Ensure that si_flush_from_st will be called for
306 * this fence, but only if we're in the API thread
307 * where the context is current.
308 *
309 * Note that the batch containing the flush may already
310 * be in flight in the driver thread, so the fence
311 * may not be ready yet when this call returns.
312 */
313 threaded_context_flush(ctx, rfence->tc_token,
314 timeout == 0);
315 }
316
317 if (!timeout)
318 return false;
319
320 if (timeout == PIPE_TIMEOUT_INFINITE) {
321 util_queue_fence_wait(&rfence->ready);
322 } else {
323 if (!util_queue_fence_wait_timeout(&rfence->ready, abs_timeout))
324 return false;
325 }
326
327 if (timeout && timeout != PIPE_TIMEOUT_INFINITE) {
328 int64_t time = os_time_get_nano();
329 timeout = abs_timeout > time ? abs_timeout - time : 0;
330 }
331 }
332
333 if (rfence->sdma) {
334 if (!rws->fence_wait(rws, rfence->sdma, timeout))
335 return false;
336
337 /* Recompute the timeout after waiting. */
338 if (timeout && timeout != PIPE_TIMEOUT_INFINITE) {
339 int64_t time = os_time_get_nano();
340 timeout = abs_timeout > time ? abs_timeout - time : 0;
341 }
342 }
343
344 if (!rfence->gfx)
345 return true;
346
347 if (rfence->fine.buf &&
348 si_fine_fence_signaled(rws, &rfence->fine)) {
349 rws->fence_reference(&rfence->gfx, NULL);
350 r600_resource_reference(&rfence->fine.buf, NULL);
351 return true;
352 }
353
354 /* Flush the gfx IB if it hasn't been flushed yet. */
355 if (sctx && rfence->gfx_unflushed.ctx == sctx &&
356 rfence->gfx_unflushed.ib_index == sctx->num_gfx_cs_flushes) {
357 /* Section 4.1.2 (Signaling) of the OpenGL 4.6 (Core profile)
358 * spec says:
359 *
360 * "If the sync object being blocked upon will not be
361 * signaled in finite time (for example, by an associated
362 * fence command issued previously, but not yet flushed to
363 * the graphics pipeline), then ClientWaitSync may hang
364 * forever. To help prevent this behavior, if
365 * ClientWaitSync is called and all of the following are
366 * true:
367 *
368 * * the SYNC_FLUSH_COMMANDS_BIT bit is set in flags,
369 * * sync is unsignaled when ClientWaitSync is called,
370 * * and the calls to ClientWaitSync and FenceSync were
371 * issued from the same context,
372 *
373 * then the GL will behave as if the equivalent of Flush
374 * were inserted immediately after the creation of sync."
375 *
376 * This means we need to flush for such fences even when we're
377 * not going to wait.
378 */
379 si_flush_gfx_cs(sctx,
380 (timeout ? 0 : PIPE_FLUSH_ASYNC) |
381 RADEON_FLUSH_START_NEXT_GFX_IB_NOW,
382 NULL);
383 rfence->gfx_unflushed.ctx = NULL;
384
385 if (!timeout)
386 return false;
387
388 /* Recompute the timeout after all that. */
389 if (timeout && timeout != PIPE_TIMEOUT_INFINITE) {
390 int64_t time = os_time_get_nano();
391 timeout = abs_timeout > time ? abs_timeout - time : 0;
392 }
393 }
394
395 if (rws->fence_wait(rws, rfence->gfx, timeout))
396 return true;
397
398 /* Re-check in case the GPU is slow or hangs, but the commands before
399 * the fine-grained fence have completed. */
400 if (rfence->fine.buf &&
401 si_fine_fence_signaled(rws, &rfence->fine))
402 return true;
403
404 return false;
405 }
406
407 static void si_create_fence_fd(struct pipe_context *ctx,
408 struct pipe_fence_handle **pfence, int fd,
409 enum pipe_fd_type type)
410 {
411 struct si_screen *sscreen = (struct si_screen*)ctx->screen;
412 struct radeon_winsys *ws = sscreen->ws;
413 struct si_multi_fence *rfence;
414
415 *pfence = NULL;
416
417 rfence = si_create_multi_fence();
418 if (!rfence)
419 return;
420
421 switch (type) {
422 case PIPE_FD_TYPE_NATIVE_SYNC:
423 if (!sscreen->info.has_fence_to_handle)
424 goto finish;
425
426 rfence->gfx = ws->fence_import_sync_file(ws, fd);
427 break;
428
429 case PIPE_FD_TYPE_SYNCOBJ:
430 if (!sscreen->info.has_syncobj)
431 goto finish;
432
433 rfence->gfx = ws->fence_import_syncobj(ws, fd);
434 break;
435
436 default:
437 unreachable("bad fence fd type when importing");
438 }
439
440 finish:
441 if (!rfence->gfx) {
442 FREE(rfence);
443 return;
444 }
445
446 *pfence = (struct pipe_fence_handle*)rfence;
447 }
448
449 static int si_fence_get_fd(struct pipe_screen *screen,
450 struct pipe_fence_handle *fence)
451 {
452 struct si_screen *sscreen = (struct si_screen*)screen;
453 struct radeon_winsys *ws = sscreen->ws;
454 struct si_multi_fence *rfence = (struct si_multi_fence *)fence;
455 int gfx_fd = -1, sdma_fd = -1;
456
457 if (!sscreen->info.has_fence_to_handle)
458 return -1;
459
460 util_queue_fence_wait(&rfence->ready);
461
462 /* Deferred fences aren't supported. */
463 assert(!rfence->gfx_unflushed.ctx);
464 if (rfence->gfx_unflushed.ctx)
465 return -1;
466
467 if (rfence->sdma) {
468 sdma_fd = ws->fence_export_sync_file(ws, rfence->sdma);
469 if (sdma_fd == -1)
470 return -1;
471 }
472 if (rfence->gfx) {
473 gfx_fd = ws->fence_export_sync_file(ws, rfence->gfx);
474 if (gfx_fd == -1) {
475 if (sdma_fd != -1)
476 close(sdma_fd);
477 return -1;
478 }
479 }
480
481 /* If we don't have FDs at this point, it means we don't have fences
482 * either. */
483 if (sdma_fd == -1 && gfx_fd == -1)
484 return ws->export_signalled_sync_file(ws);
485 if (sdma_fd == -1)
486 return gfx_fd;
487 if (gfx_fd == -1)
488 return sdma_fd;
489
490 /* Get a fence that will be a combination of both fences. */
491 sync_accumulate("radeonsi", &gfx_fd, sdma_fd);
492 close(sdma_fd);
493 return gfx_fd;
494 }
495
496 static void si_flush_from_st(struct pipe_context *ctx,
497 struct pipe_fence_handle **fence,
498 unsigned flags)
499 {
500 struct pipe_screen *screen = ctx->screen;
501 struct si_context *sctx = (struct si_context *)ctx;
502 struct radeon_winsys *ws = sctx->ws;
503 struct pipe_fence_handle *gfx_fence = NULL;
504 struct pipe_fence_handle *sdma_fence = NULL;
505 bool deferred_fence = false;
506 struct si_fine_fence fine = {};
507 unsigned rflags = PIPE_FLUSH_ASYNC;
508
509 if (flags & PIPE_FLUSH_END_OF_FRAME)
510 rflags |= PIPE_FLUSH_END_OF_FRAME;
511
512 if (flags & (PIPE_FLUSH_TOP_OF_PIPE | PIPE_FLUSH_BOTTOM_OF_PIPE)) {
513 assert(flags & PIPE_FLUSH_DEFERRED);
514 assert(fence);
515
516 si_fine_fence_set(sctx, &fine, flags);
517 }
518
519 /* DMA IBs are preambles to gfx IBs, therefore must be flushed first. */
520 if (sctx->dma_cs)
521 si_flush_dma_cs(sctx, rflags, fence ? &sdma_fence : NULL);
522
523 if (!radeon_emitted(sctx->gfx_cs, sctx->initial_gfx_cs_size)) {
524 if (fence)
525 ws->fence_reference(&gfx_fence, sctx->last_gfx_fence);
526 if (!(flags & PIPE_FLUSH_DEFERRED))
527 ws->cs_sync_flush(sctx->gfx_cs);
528 } else {
529 /* Instead of flushing, create a deferred fence. Constraints:
530 * - The state tracker must allow a deferred flush.
531 * - The state tracker must request a fence.
532 * - fence_get_fd is not allowed.
533 * Thread safety in fence_finish must be ensured by the state tracker.
534 */
535 if (flags & PIPE_FLUSH_DEFERRED &&
536 !(flags & PIPE_FLUSH_FENCE_FD) &&
537 fence) {
538 gfx_fence = sctx->ws->cs_get_next_fence(sctx->gfx_cs);
539 deferred_fence = true;
540 } else {
541 si_flush_gfx_cs(sctx, rflags, fence ? &gfx_fence : NULL);
542 }
543 }
544
545 /* Both engines can signal out of order, so we need to keep both fences. */
546 if (fence) {
547 struct si_multi_fence *multi_fence;
548
549 if (flags & TC_FLUSH_ASYNC) {
550 multi_fence = (struct si_multi_fence *)*fence;
551 assert(multi_fence);
552 } else {
553 multi_fence = si_create_multi_fence();
554 if (!multi_fence) {
555 ws->fence_reference(&sdma_fence, NULL);
556 ws->fence_reference(&gfx_fence, NULL);
557 goto finish;
558 }
559
560 screen->fence_reference(screen, fence, NULL);
561 *fence = (struct pipe_fence_handle*)multi_fence;
562 }
563
564 /* If both fences are NULL, fence_finish will always return true. */
565 multi_fence->gfx = gfx_fence;
566 multi_fence->sdma = sdma_fence;
567
568 if (deferred_fence) {
569 multi_fence->gfx_unflushed.ctx = sctx;
570 multi_fence->gfx_unflushed.ib_index = sctx->num_gfx_cs_flushes;
571 }
572
573 multi_fence->fine = fine;
574 fine.buf = NULL;
575
576 if (flags & TC_FLUSH_ASYNC) {
577 util_queue_fence_signal(&multi_fence->ready);
578 tc_unflushed_batch_token_reference(&multi_fence->tc_token, NULL);
579 }
580 }
581 assert(!fine.buf);
582 finish:
583 if (!(flags & PIPE_FLUSH_DEFERRED)) {
584 if (sctx->dma_cs)
585 ws->cs_sync_flush(sctx->dma_cs);
586 ws->cs_sync_flush(sctx->gfx_cs);
587 }
588 }
589
590 static void si_fence_server_signal(struct pipe_context *ctx,
591 struct pipe_fence_handle *fence)
592 {
593 struct si_context *sctx = (struct si_context *)ctx;
594 struct si_multi_fence *rfence = (struct si_multi_fence *)fence;
595
596 /* We should have at least one syncobj to signal */
597 assert(rfence->sdma || rfence->gfx);
598
599 if (rfence->sdma)
600 si_add_syncobj_signal(sctx, rfence->sdma);
601 if (rfence->gfx)
602 si_add_syncobj_signal(sctx, rfence->gfx);
603
604 /**
605 * The spec does not require a flush here. We insert a flush
606 * because syncobj based signals are not directly placed into
607 * the command stream. Instead the signal happens when the
608 * submission associated with the syncobj finishes execution.
609 *
610 * Therefore, we must make sure that we flush the pipe to avoid
611 * new work being emitted and getting executed before the signal
612 * operation.
613 */
614 si_flush_from_st(ctx, NULL, PIPE_FLUSH_ASYNC);
615 }
616
617 static void si_fence_server_sync(struct pipe_context *ctx,
618 struct pipe_fence_handle *fence)
619 {
620 struct si_context *sctx = (struct si_context *)ctx;
621 struct si_multi_fence *rfence = (struct si_multi_fence *)fence;
622
623 util_queue_fence_wait(&rfence->ready);
624
625 /* Unflushed fences from the same context are no-ops. */
626 if (rfence->gfx_unflushed.ctx &&
627 rfence->gfx_unflushed.ctx == sctx)
628 return;
629
630 /* All unflushed commands will not start execution before
631 * this fence dependency is signalled.
632 *
633 * Therefore we must flush before inserting the dependency
634 */
635 si_flush_from_st(ctx, NULL, PIPE_FLUSH_ASYNC);
636
637 if (rfence->sdma)
638 si_add_fence_dependency(sctx, rfence->sdma);
639 if (rfence->gfx)
640 si_add_fence_dependency(sctx, rfence->gfx);
641 }
642
643 void si_init_fence_functions(struct si_context *ctx)
644 {
645 ctx->b.flush = si_flush_from_st;
646 ctx->b.create_fence_fd = si_create_fence_fd;
647 ctx->b.fence_server_sync = si_fence_server_sync;
648 ctx->b.fence_server_signal = si_fence_server_signal;
649 }
650
651 void si_init_screen_fence_functions(struct si_screen *screen)
652 {
653 screen->b.fence_finish = si_fence_finish;
654 screen->b.fence_reference = si_fence_reference;
655 screen->b.fence_get_fd = si_fence_get_fd;
656 }