xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/nouveau/nouveau_fence.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 
2 #ifndef __NOUVEAU_FENCE_H__
3 #define __NOUVEAU_FENCE_H__
4 
5 #include "util/u_inlines.h"
6 #include "util/list.h"
7 #include "util/simple_mtx.h"
8 
9 #define NOUVEAU_FENCE_STATE_AVAILABLE 0
10 #define NOUVEAU_FENCE_STATE_EMITTING  1
11 #define NOUVEAU_FENCE_STATE_EMITTED   2
12 #define NOUVEAU_FENCE_STATE_FLUSHED   3
13 #define NOUVEAU_FENCE_STATE_SIGNALLED 4
14 
15 struct util_debug_callback;
16 
17 struct nouveau_fence_work {
18    struct list_head list;
19    void (*func)(void *);
20    void *data;
21 };
22 
23 struct nouveau_fence {
24    struct nouveau_fence *next;
25    struct nouveau_screen *screen;
26    struct nouveau_context *context;
27    struct nouveau_bo *bo;
28    int state;
29    int ref;
30    uint32_t sequence;
31    uint32_t work_count;
32    struct list_head work;
33 };
34 
35 struct nouveau_fence_list {
36    struct nouveau_fence *head;
37    struct nouveau_fence *tail;
38    uint32_t sequence;
39    uint32_t sequence_ack;
40    simple_mtx_t lock;
41    void (*emit)(struct pipe_context *, uint32_t *sequence, struct nouveau_bo *wait);
42    uint32_t (*update)(struct pipe_screen *);
43 };
44 
45 static inline void
nouveau_fence_list_init(struct nouveau_fence_list * fence_list)46 nouveau_fence_list_init(struct nouveau_fence_list *fence_list)
47 {
48    simple_mtx_init(&fence_list->lock, mtx_plain);
49 }
50 
51 static inline void
nouveau_fence_list_destroy(struct nouveau_fence_list * fence_list)52 nouveau_fence_list_destroy(struct nouveau_fence_list *fence_list)
53 {
54    simple_mtx_destroy(&fence_list->lock);
55 }
56 
57 /* unlocked versions, use with care */
58 void _nouveau_fence_update(struct nouveau_screen *, bool flushed);
59 void _nouveau_fence_next(struct nouveau_context *);
60 void _nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
61 
62 bool nouveau_fence_new(struct nouveau_context *, struct nouveau_fence **);
63 void nouveau_fence_cleanup(struct nouveau_context *);
64 bool nouveau_fence_work(struct nouveau_fence *, void (*)(void *), void *);
65 void nouveau_fence_update(struct nouveau_screen *, bool flushed);
66 void nouveau_fence_next_if_current(struct nouveau_context *, struct nouveau_fence *);
67 bool nouveau_fence_wait(struct nouveau_fence *, struct util_debug_callback *);
68 bool nouveau_fence_signalled(struct nouveau_fence *);
69 void nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
70 
71 void nouveau_fence_unref_bo(void *data); /* generic unref bo callback */
72 
73 static inline struct nouveau_fence *
nouveau_fence(struct pipe_fence_handle * fence)74 nouveau_fence(struct pipe_fence_handle *fence)
75 {
76    return (struct nouveau_fence *)fence;
77 }
78 
79 #endif // __NOUVEAU_FENCE_H__
80