2 * Copyright © 2014 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 * Seqno-based fence management.
28 * We have two mechanisms for waiting in our kernel API: You can wait on a BO
29 * to have all rendering to from any process to be completed, or wait on a
30 * seqno for that particular seqno to be passed. The fence API we're
31 * implementing is based on waiting for all rendering in the context to have
32 * completed (with no reference to what other processes might be doing with
33 * the same BOs), so we can just use the seqno of the last rendering we'd
34 * fired off as our fence marker.
37 #include "util/u_inlines.h"
39 #include "vc4_screen.h"
40 #include "vc4_bufmgr.h"
43 struct pipe_reference reference
;
48 vc4_fence_reference(struct pipe_screen
*pscreen
,
49 struct pipe_fence_handle
**pp
,
50 struct pipe_fence_handle
*pf
)
52 struct vc4_fence
**p
= (struct vc4_fence
**)pp
;
53 struct vc4_fence
*f
= (struct vc4_fence
*)pf
;
54 struct vc4_fence
*old
= *p
;
56 if (pipe_reference(&(*p
)->reference
, &f
->reference
)) {
63 vc4_fence_signalled(struct pipe_screen
*pscreen
,
64 struct pipe_fence_handle
*pf
)
66 struct vc4_screen
*screen
= vc4_screen(pscreen
);
67 struct vc4_fence
*f
= (struct vc4_fence
*)pf
;
69 if (screen
->finished_seqno
>= f
->seqno
)
72 return vc4_wait_seqno(screen
, f
->seqno
, 0);
76 vc4_fence_finish(struct pipe_screen
*pscreen
,
77 struct pipe_fence_handle
*pf
,
80 struct vc4_screen
*screen
= vc4_screen(pscreen
);
81 struct vc4_fence
*f
= (struct vc4_fence
*)pf
;
83 if (screen
->finished_seqno
>= f
->seqno
)
86 return vc4_wait_seqno(screen
, f
->seqno
, timeout_ns
);
90 vc4_fence_create(struct vc4_screen
*screen
, uint64_t seqno
)
92 struct vc4_fence
*f
= calloc(1, sizeof(*f
));
97 pipe_reference_init(&f
->reference
, 1);
104 vc4_fence_init(struct vc4_screen
*screen
)
106 screen
->base
.fence_reference
= vc4_fence_reference
;
107 screen
->base
.fence_signalled
= vc4_fence_signalled
;
108 screen
->base
.fence_finish
= vc4_fence_finish
;