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