2efcab2172dc2ce99b8e3d073d17477e5ae493bf
[mesa.git] / src / gallium / drivers / nouveau / nouveau_fence.h
1
2 #ifndef __NOUVEAU_FENCE_H__
3 #define __NOUVEAU_FENCE_H__
4
5 #include "util/u_inlines.h"
6 #include "util/list.h"
7
8 #define NOUVEAU_FENCE_STATE_AVAILABLE 0
9 #define NOUVEAU_FENCE_STATE_EMITTING 1
10 #define NOUVEAU_FENCE_STATE_EMITTED 2
11 #define NOUVEAU_FENCE_STATE_FLUSHED 3
12 #define NOUVEAU_FENCE_STATE_SIGNALLED 4
13
14 struct nouveau_fence_work {
15 struct list_head list;
16 void (*func)(void *);
17 void *data;
18 };
19
20 struct nouveau_fence {
21 struct nouveau_fence *next;
22 struct nouveau_screen *screen;
23 int state;
24 int ref;
25 uint32_t sequence;
26 struct list_head work;
27 };
28
29 void nouveau_fence_emit(struct nouveau_fence *);
30 void nouveau_fence_del(struct nouveau_fence *);
31
32 bool nouveau_fence_new(struct nouveau_screen *, struct nouveau_fence **,
33 bool emit);
34 bool nouveau_fence_work(struct nouveau_fence *, void (*)(void *), void *);
35 void nouveau_fence_update(struct nouveau_screen *, bool flushed);
36 void nouveau_fence_next(struct nouveau_screen *);
37 bool nouveau_fence_wait(struct nouveau_fence *);
38 bool nouveau_fence_signalled(struct nouveau_fence *);
39
40 void nouveau_fence_unref_bo(void *data); /* generic unref bo callback */
41
42
43 static inline void
44 nouveau_fence_ref(struct nouveau_fence *fence, struct nouveau_fence **ref)
45 {
46 if (fence)
47 ++fence->ref;
48
49 if (*ref) {
50 if (--(*ref)->ref == 0)
51 nouveau_fence_del(*ref);
52 }
53
54 *ref = fence;
55 }
56
57 static inline struct nouveau_fence *
58 nouveau_fence(struct pipe_fence_handle *fence)
59 {
60 return (struct nouveau_fence *)fence;
61 }
62
63 #endif // __NOUVEAU_FENCE_H__