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 "vc5_screen.h"
40 #include "vc5_bufmgr.h"
43 struct pipe_reference reference
;
48 vc5_fence_reference(struct pipe_screen
*pscreen
,
49 struct pipe_fence_handle
**pp
,
50 struct pipe_fence_handle
*pf
)
52 struct vc5_fence
**p
= (struct vc5_fence
**)pp
;
53 struct vc5_fence
*f
= (struct vc5_fence
*)pf
;
54 struct vc5_fence
*old
= *p
;
56 if (pipe_reference(&(*p
)->reference
, &f
->reference
)) {
63 vc5_fence_finish(struct pipe_screen
*pscreen
,
64 struct pipe_context
*ctx
,
65 struct pipe_fence_handle
*pf
,
68 struct vc5_screen
*screen
= vc5_screen(pscreen
);
69 struct vc5_fence
*f
= (struct vc5_fence
*)pf
;
71 return vc5_wait_seqno(screen
, f
->seqno
, timeout_ns
, "fence wait");
75 vc5_fence_create(struct vc5_screen
*screen
, uint64_t seqno
)
77 struct vc5_fence
*f
= calloc(1, sizeof(*f
));
82 pipe_reference_init(&f
->reference
, 1);
89 vc5_fence_init(struct vc5_screen
*screen
)
91 screen
->base
.fence_reference
= vc5_fence_reference
;
92 screen
->base
.fence_finish
= vc5_fence_finish
;