nve4: fix uploading unaligned sized input buffers
[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 "drm-uapi/drm.h"
10 #include <nouveau.h>
11
12 #ifndef NV04_PFIFO_MAX_PACKET_LEN
13 #define NV04_PFIFO_MAX_PACKET_LEN 2047
14 #endif
15
16 #define NOUVEAU_MIN_BUFFER_MAP_ALIGN 64
17 #define NOUVEAU_MIN_BUFFER_MAP_ALIGN_MASK (NOUVEAU_MIN_BUFFER_MAP_ALIGN - 1)
18
19 static inline uint32_t
20 PUSH_AVAIL(struct nouveau_pushbuf *push)
21 {
22 return push->end - push->cur;
23 }
24
25 static inline bool
26 PUSH_SPACE(struct nouveau_pushbuf *push, uint32_t size)
27 {
28 /* Provide a buffer so that fences always have room to be emitted */
29 size += 8;
30 if (PUSH_AVAIL(push) < size)
31 return nouveau_pushbuf_space(push, size, 0, 0) == 0;
32 return true;
33 }
34
35 static inline void
36 PUSH_DATA(struct nouveau_pushbuf *push, uint32_t data)
37 {
38 *push->cur++ = data;
39 }
40
41 static inline void
42 PUSH_DATAp(struct nouveau_pushbuf *push, const void *data, uint32_t size)
43 {
44 memcpy(push->cur, data, size * 4);
45 push->cur += size;
46 }
47
48 static inline void
49 PUSH_DATAb(struct nouveau_pushbuf *push, const void *data, uint32_t size)
50 {
51 memcpy(push->cur, data, size);
52 push->cur += DIV_ROUND_UP(size, 4);
53 }
54
55 static inline void
56 PUSH_DATAf(struct nouveau_pushbuf *push, float f)
57 {
58 union { float f; uint32_t i; } u;
59 u.f = f;
60 PUSH_DATA(push, u.i);
61 }
62
63 static inline void
64 PUSH_KICK(struct nouveau_pushbuf *push)
65 {
66 nouveau_pushbuf_kick(push, push->channel);
67 }
68
69
70 #define NOUVEAU_RESOURCE_FLAG_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
71 #define NOUVEAU_RESOURCE_FLAG_DRV_PRIV (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
72
73 static inline uint32_t
74 nouveau_screen_transfer_flags(unsigned pipe)
75 {
76 uint32_t flags = 0;
77
78 if (!(pipe & PIPE_TRANSFER_UNSYNCHRONIZED)) {
79 if (pipe & PIPE_TRANSFER_READ)
80 flags |= NOUVEAU_BO_RD;
81 if (pipe & PIPE_TRANSFER_WRITE)
82 flags |= NOUVEAU_BO_WR;
83 if (pipe & PIPE_TRANSFER_DONTBLOCK)
84 flags |= NOUVEAU_BO_NOBLOCK;
85 }
86
87 return flags;
88 }
89
90 extern struct nouveau_screen *
91 nv30_screen_create(struct nouveau_device *);
92
93 extern struct nouveau_screen *
94 nv50_screen_create(struct nouveau_device *);
95
96 extern struct nouveau_screen *
97 nvc0_screen_create(struct nouveau_device *);
98
99 #endif