nouveau: gallium directory structure changed again..
[mesa.git] / src / gallium / drivers / nouveau / nouveau_stateobj.h
1 #ifndef __NOUVEAU_STATEOBJ_H__
2 #define __NOUVEAU_STATEOBJ_H__
3
4 #include "pipe/p_debug.h"
5
6 struct nouveau_stateobj_reloc {
7 struct pipe_buffer *bo;
8
9 unsigned offset;
10 unsigned packet;
11
12 unsigned data;
13 unsigned flags;
14 unsigned vor;
15 unsigned tor;
16 };
17
18 struct nouveau_stateobj {
19 int refcount;
20
21 unsigned *push;
22 struct nouveau_stateobj_reloc *reloc;
23
24 unsigned *cur;
25 unsigned cur_packet;
26 unsigned cur_reloc;
27 };
28
29 static INLINE struct nouveau_stateobj *
30 so_new(unsigned push, unsigned reloc)
31 {
32 struct nouveau_stateobj *so;
33
34 so = MALLOC(sizeof(struct nouveau_stateobj));
35 so->refcount = 0;
36 so->push = MALLOC(sizeof(unsigned) * push);
37 so->reloc = MALLOC(sizeof(struct nouveau_stateobj_reloc) * reloc);
38
39 so->cur = so->push;
40 so->cur_reloc = so->cur_packet = 0;
41
42 return so;
43 }
44
45 static INLINE void
46 so_ref(struct nouveau_stateobj *ref, struct nouveau_stateobj **pso)
47 {
48 struct nouveau_stateobj *so = *pso;
49
50 if (ref) {
51 ref->refcount++;
52 }
53
54 if (so && --so->refcount <= 0) {
55 free(so->push);
56 free(so->reloc);
57 free(so);
58 }
59
60 *pso = ref;
61 }
62
63 static INLINE void
64 so_data(struct nouveau_stateobj *so, unsigned data)
65 {
66 (*so->cur++) = (data);
67 so->cur_packet += 4;
68 }
69
70 static INLINE void
71 so_datap(struct nouveau_stateobj *so, unsigned *data, unsigned size)
72 {
73 so->cur_packet += (4 * size);
74 while (size--)
75 (*so->cur++) = (*data++);
76 }
77
78 static INLINE void
79 so_method(struct nouveau_stateobj *so, struct nouveau_grobj *gr,
80 unsigned mthd, unsigned size)
81 {
82 so->cur_packet = (gr->subc << 13) | (1 << 18) | (mthd - 4);
83 so_data(so, (gr->subc << 13) | (size << 18) | mthd);
84 }
85
86 static INLINE void
87 so_reloc(struct nouveau_stateobj *so, struct pipe_buffer *bo,
88 unsigned data, unsigned flags, unsigned vor, unsigned tor)
89 {
90 struct nouveau_stateobj_reloc *r = &so->reloc[so->cur_reloc++];
91
92 r->bo = bo;
93 r->offset = so->cur - so->push;
94 r->packet = so->cur_packet;
95 r->data = data;
96 r->flags = flags;
97 r->vor = vor;
98 r->tor = tor;
99 so_data(so, data);
100 }
101
102 static INLINE void
103 so_dump(struct nouveau_stateobj *so)
104 {
105 unsigned i, nr = so->cur - so->push;
106
107 for (i = 0; i < nr; i++)
108 debug_printf("+0x%04x: 0x%08x\n", i, so->push[i]);
109 }
110
111 static INLINE void
112 so_emit(struct nouveau_winsys *nvws, struct nouveau_stateobj *so)
113 {
114 struct nouveau_pushbuf *pb = nvws->channel->pushbuf;
115 unsigned nr, i;
116
117 nr = so->cur - so->push;
118 if (pb->remaining < nr)
119 nvws->push_flush(nvws, nr, NULL);
120 pb->remaining -= nr;
121
122 memcpy(pb->cur, so->push, nr * 4);
123 for (i = 0; i < so->cur_reloc; i++) {
124 struct nouveau_stateobj_reloc *r = &so->reloc[i];
125
126 nvws->push_reloc(nvws, pb->cur + r->offset, r->bo,
127 r->data, r->flags, r->vor, r->tor);
128 }
129 pb->cur += nr;
130 }
131
132 static INLINE void
133 so_emit_reloc_markers(struct nouveau_winsys *nvws, struct nouveau_stateobj *so)
134 {
135 struct nouveau_pushbuf *pb = nvws->channel->pushbuf;
136 unsigned i;
137
138 if (!so)
139 return;
140
141 i = so->cur_reloc << 1;
142 if (nvws->channel->pushbuf->remaining < i)
143 nvws->push_flush(nvws, i, NULL);
144 nvws->channel->pushbuf->remaining -= i;
145
146 for (i = 0; i < so->cur_reloc; i++) {
147 struct nouveau_stateobj_reloc *r = &so->reloc[i];
148
149 nvws->push_reloc(nvws, pb->cur++, r->bo, r->packet,
150 (r->flags &
151 (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)) |
152 NOUVEAU_BO_DUMMY, 0, 0);
153 nvws->push_reloc(nvws, pb->cur++, r->bo, r->data,
154 r->flags | NOUVEAU_BO_DUMMY, r->vor, r->tor);
155 }
156 }
157
158 #endif