nouveau: make sure there's always room to emit a fence
[mesa.git] / src / gallium / drivers / nouveau / nouveau_winsys.h
1 #ifndef NOUVEAU_WINSYS_H
2 #define NOUVEAU_WINSYS_H
3
4 #include <stdint.h>
5 #include <inttypes.h>
6
7 #include "pipe/p_defines.h"
8
9 #include <nouveau.h>
10
11 #ifndef NV04_PFIFO_MAX_PACKET_LEN
12 #define NV04_PFIFO_MAX_PACKET_LEN 2047
13 #endif
14
15 #define NOUVEAU_MIN_BUFFER_MAP_ALIGN 64
16 #define NOUVEAU_MIN_BUFFER_MAP_ALIGN_MASK (NOUVEAU_MIN_BUFFER_MAP_ALIGN - 1)
17
18 static inline uint32_t
19 PUSH_AVAIL(struct nouveau_pushbuf *push)
20 {
21 return push->end - push->cur;
22 }
23
24 static inline bool
25 PUSH_SPACE(struct nouveau_pushbuf *push, uint32_t size)
26 {
27 /* Provide a buffer so that fences always have room to be emitted */
28 size += 8;
29 if (PUSH_AVAIL(push) < size)
30 return nouveau_pushbuf_space(push, size, 0, 0) == 0;
31 return true;
32 }
33
34 static inline void
35 PUSH_DATA(struct nouveau_pushbuf *push, uint32_t data)
36 {
37 *push->cur++ = data;
38 }
39
40 static inline void
41 PUSH_DATAp(struct nouveau_pushbuf *push, const void *data, uint32_t size)
42 {
43 memcpy(push->cur, data, size * 4);
44 push->cur += size;
45 }
46
47 static inline void
48 PUSH_DATAf(struct nouveau_pushbuf *push, float f)
49 {
50 union { float f; uint32_t i; } u;
51 u.f = f;
52 PUSH_DATA(push, u.i);
53 }
54
55 static inline void
56 PUSH_KICK(struct nouveau_pushbuf *push)
57 {
58 nouveau_pushbuf_kick(push, push->channel);
59 }
60
61
62 #define NOUVEAU_RESOURCE_FLAG_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
63 #define NOUVEAU_RESOURCE_FLAG_DRV_PRIV (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
64
65 static inline uint32_t
66 nouveau_screen_transfer_flags(unsigned pipe)
67 {
68 uint32_t flags = 0;
69
70 if (!(pipe & PIPE_TRANSFER_UNSYNCHRONIZED)) {
71 if (pipe & PIPE_TRANSFER_READ)
72 flags |= NOUVEAU_BO_RD;
73 if (pipe & PIPE_TRANSFER_WRITE)
74 flags |= NOUVEAU_BO_WR;
75 if (pipe & PIPE_TRANSFER_DONTBLOCK)
76 flags |= NOUVEAU_BO_NOBLOCK;
77 }
78
79 return flags;
80 }
81
82 extern struct pipe_screen *
83 nv30_screen_create(struct nouveau_device *);
84
85 extern struct pipe_screen *
86 nv50_screen_create(struct nouveau_device *);
87
88 extern struct pipe_screen *
89 nvc0_screen_create(struct nouveau_device *);
90
91 #endif