1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright © 2014 Broadcom
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/** @file v3d_fence.c
*
* Seqno-based fence management.
*
* We have two mechanisms for waiting in our kernel API: You can wait on a BO
* to have all rendering to from any process to be completed, or wait on a
* seqno for that particular seqno to be passed. The fence API we're
* implementing is based on waiting for all rendering in the context to have
* completed (with no reference to what other processes might be doing with
* the same BOs), so we can just use the seqno of the last rendering we'd
* fired off as our fence marker.
*/
#include "util/u_inlines.h"
#include "util/os_time.h"
#include "v3d_context.h"
#include "v3d_bufmgr.h"
struct v3d_fence {
struct pipe_reference reference;
uint32_t sync;
};
static void
v3d_fence_reference(struct pipe_screen *pscreen,
struct pipe_fence_handle **pp,
struct pipe_fence_handle *pf)
{
struct v3d_screen *screen = v3d_screen(pscreen);
struct v3d_fence **p = (struct v3d_fence **)pp;
struct v3d_fence *f = (struct v3d_fence *)pf;
struct v3d_fence *old = *p;
if (pipe_reference(&(*p)->reference, &f->reference)) {
drmSyncobjDestroy(screen->fd, old->sync);
free(old);
}
*p = f;
}
static boolean
v3d_fence_finish(struct pipe_screen *pscreen,
struct pipe_context *ctx,
struct pipe_fence_handle *pf,
uint64_t timeout_ns)
{
struct v3d_screen *screen = v3d_screen(pscreen);
struct v3d_fence *f = (struct v3d_fence *)pf;
uint64_t abs_timeout = os_time_get_absolute_timeout(timeout_ns);
if (abs_timeout == OS_TIMEOUT_INFINITE)
abs_timeout = INT64_MAX;
return drmSyncobjWait(screen->fd, &f->sync, 1, abs_timeout,
0, NULL) >= 0;
}
struct v3d_fence *
v3d_fence_create(struct v3d_context *v3d)
{
struct v3d_fence *f = calloc(1, sizeof(*f));
if (!f)
return NULL;
uint32_t new_sync;
/* Make a new sync object for the context. */
int ret = drmSyncobjCreate(v3d->fd, DRM_SYNCOBJ_CREATE_SIGNALED,
&new_sync);
if (ret) {
free(f);
return NULL;
}
pipe_reference_init(&f->reference, 1);
f->sync = v3d->out_sync;
v3d->out_sync = new_sync;
return f;
}
void
v3d_fence_init(struct v3d_screen *screen)
{
screen->base.fence_reference = v3d_fence_reference;
screen->base.fence_finish = v3d_fence_finish;
}
|