24
24
**********************************************************/
28
* Fencing is currently a bit inefficient, since we need to call the
29
* kernel do determine a fence object signaled status if the fence is not
30
* signaled. This can be greatly improved upon by using the fact that the
31
* execbuf ioctl returns the last signaled fence seqno, as does the
32
* fence signaled ioctl. We should set up a ring of fence objects and
33
* walk through them checking for signaled status each time we receive a
34
* new passed fence seqno.
27
37
#include "util/u_memory.h"
38
#include "util/u_atomic.h"
28
40
#include "pipebuffer/pb_buffer_fenced.h"
30
42
#include "vmw_screen.h"
31
43
#include "vmw_fence.h"
35
45
struct vmw_fence_ops
37
47
struct pb_fence_ops base;
39
49
struct vmw_winsys_screen *vws;
61
* vmw_fence - return the vmw_fence object identified by a
62
* struct pipe_fence_handle *
64
* @fence: The opaque pipe fence handle.
66
static INLINE struct vmw_fence *
67
vmw_fence(struct pipe_fence_handle *fence)
69
return (struct vmw_fence *) fence;
73
* vmw_fence_create - Create a user-space fence object.
75
* @handle: Handle identifying the kernel fence object.
76
* @mask: Mask of flags that this fence object may signal.
78
* Returns NULL on failure.
80
struct pipe_fence_handle *
81
vmw_fence_create(uint32_t handle, uint32_t mask)
83
struct vmw_fence *fence = CALLOC_STRUCT(vmw_fence);
88
p_atomic_set(&fence->refcount, 1);
89
fence->handle = handle;
91
p_atomic_set(&fence->signalled, 0);
93
return (struct pipe_fence_handle *) fence;
97
* vmw_fence_ops - Return the vmw_fence_ops structure backing a
98
* struct pb_fence_ops pointer.
100
* @ops: Pointer to a struct pb_fence_ops.
43
103
static INLINE struct vmw_fence_ops *
44
104
vmw_fence_ops(struct pb_fence_ops *ops)
113
* vmw_fence_reference - Reference / unreference a vmw fence object.
115
* @vws: Pointer to the winsys screen.
116
* @ptr: Pointer to reference transfer destination.
117
* @fence: Pointer to object to reference. May be NULL.
120
vmw_fence_reference(struct vmw_winsys_screen *vws,
121
struct pipe_fence_handle **ptr,
122
struct pipe_fence_handle *fence)
125
struct vmw_fence *vfence = vmw_fence(*ptr);
127
if (p_atomic_dec_zero(&vfence->refcount)) {
128
vmw_ioctl_fence_unref(vws, vfence->handle);
134
struct vmw_fence *vfence = vmw_fence(fence);
136
p_atomic_inc(&vfence->refcount);
144
* vmw_fence_signalled - Check whether a fence object is signalled.
146
* @vws: Pointer to the winsys screen.
147
* @fence: Handle to the fence object.
148
* @flag: Fence flags to check. If the fence object can't signal
149
* a flag, it is assumed to be already signaled.
151
* Returns 0 if the fence object was signaled, nonzero otherwise.
154
vmw_fence_signalled(struct vmw_winsys_screen *vws,
155
struct pipe_fence_handle *fence,
158
struct vmw_fence *vfence;
159
int32_t vflags = SVGA_FENCE_FLAG_EXEC;
166
vfence = vmw_fence(fence);
167
old = p_atomic_read(&vfence->signalled);
169
vflags &= ~vfence->mask;
171
if ((old & vflags) == vflags)
174
ret = vmw_ioctl_fence_signalled(vws, vfence->handle, vflags);
181
prev = p_atomic_cmpxchg(&vfence->signalled, old, old | vflags);
182
} while (prev != old);
189
* vmw_fence_finish - Wait for a fence object to signal.
191
* @vws: Pointer to the winsys screen.
192
* @fence: Handle to the fence object.
193
* @flag: Fence flags to wait for. If the fence object can't signal
194
* a flag, it is assumed to be already signaled.
196
* Returns 0 if the wait succeeded. Nonzero otherwise.
199
vmw_fence_finish(struct vmw_winsys_screen *vws,
200
struct pipe_fence_handle *fence,
203
struct vmw_fence *vfence;
204
int32_t vflags = SVGA_FENCE_FLAG_EXEC;
211
vfence = vmw_fence(fence);
212
old = p_atomic_read(&vfence->signalled);
213
vflags &= ~vfence->mask;
215
if ((old & vflags) == vflags)
218
ret = vmw_ioctl_fence_finish(vws, vfence->handle, vflags);
225
prev = p_atomic_cmpxchg(&vfence->signalled, old, old | vflags);
226
} while (prev != old);
234
* vmw_fence_ops_fence_reference - wrapper for the pb_fence_ops api.
236
* wrapper around vmw_fence_reference.
52
239
vmw_fence_ops_fence_reference(struct pb_fence_ops *ops,
53
240
struct pipe_fence_handle **ptr,
54
241
struct pipe_fence_handle *fence)
243
struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws;
245
vmw_fence_reference(vws, ptr, fence);
249
* vmw_fence_ops_fence_signalled - wrapper for the pb_fence_ops api.
251
* wrapper around vmw_fence_signalled.
61
254
vmw_fence_ops_fence_signalled(struct pb_fence_ops *ops,
62
255
struct pipe_fence_handle *fence,
65
258
struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws;
67
return vmw_ioctl_fence_signalled(vws, vmw_fence(fence));
260
return vmw_fence_signalled(vws, fence, flag);
265
* vmw_fence_ops_fence_finish - wrapper for the pb_fence_ops api.
267
* wrapper around vmw_fence_finish.
72
270
vmw_fence_ops_fence_finish(struct pb_fence_ops *ops,
73
271
struct pipe_fence_handle *fence,
76
274
struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws;
78
return vmw_ioctl_fence_finish(vws, vmw_fence(fence));
276
return vmw_fence_finish(vws, fence, flag);
281
* vmw_fence_ops_destroy - Destroy a pb_fence_ops function table.
283
* @ops: The function table to destroy.
285
* Part of the pb_fence_ops api.
83
288
vmw_fence_ops_destroy(struct pb_fence_ops *ops)