1 #ifndef __NOUVEAU_STATEOBJ_H__
2 #define __NOUVEAU_STATEOBJ_H__
4 #include "pipe/p_debug.h"
6 struct nouveau_stateobj_reloc
{
7 struct pipe_buffer
*bo
;
18 struct nouveau_stateobj
{
22 struct nouveau_stateobj_reloc
*reloc
;
29 static INLINE
struct nouveau_stateobj
*
30 so_new(unsigned push
, unsigned reloc
)
32 struct nouveau_stateobj
*so
;
34 so
= MALLOC(sizeof(struct nouveau_stateobj
));
36 so
->push
= MALLOC(sizeof(unsigned) * push
);
37 so
->reloc
= MALLOC(sizeof(struct nouveau_stateobj_reloc
) * reloc
);
40 so
->cur_reloc
= so
->cur_packet
= 0;
46 so_ref(struct nouveau_stateobj
*ref
, struct nouveau_stateobj
**pso
)
48 struct nouveau_stateobj
*so
= *pso
;
54 if (so
&& --so
->refcount
<= 0) {
64 so_data(struct nouveau_stateobj
*so
, unsigned data
)
66 (*so
->cur
++) = (data
);
71 so_datap(struct nouveau_stateobj
*so
, unsigned *data
, unsigned size
)
73 so
->cur_packet
+= (4 * size
);
75 (*so
->cur
++) = (*data
++);
79 so_method(struct nouveau_stateobj
*so
, struct nouveau_grobj
*gr
,
80 unsigned mthd
, unsigned size
)
82 so
->cur_packet
= (gr
->subc
<< 13) | (1 << 18) | (mthd
- 4);
83 so_data(so
, (gr
->subc
<< 13) | (size
<< 18) | mthd
);
87 so_reloc(struct nouveau_stateobj
*so
, struct pipe_buffer
*bo
,
88 unsigned data
, unsigned flags
, unsigned vor
, unsigned tor
)
90 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[so
->cur_reloc
++];
93 r
->offset
= so
->cur
- so
->push
;
94 r
->packet
= so
->cur_packet
;
103 so_dump(struct nouveau_stateobj
*so
)
105 unsigned i
, nr
= so
->cur
- so
->push
;
107 for (i
= 0; i
< nr
; i
++)
108 debug_printf("+0x%04x: 0x%08x\n", i
, so
->push
[i
]);
112 so_emit(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
114 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
117 nr
= so
->cur
- so
->push
;
118 if (pb
->remaining
< nr
)
119 nvws
->push_flush(nvws
, nr
, NULL
);
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
];
126 nvws
->push_reloc(nvws
, pb
->cur
+ r
->offset
, r
->bo
,
127 r
->data
, r
->flags
, r
->vor
, r
->tor
);
133 so_emit_reloc_markers(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
135 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
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
;
146 for (i
= 0; i
< so
->cur_reloc
; i
++) {
147 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[i
];
149 nvws
->push_reloc(nvws
, pb
->cur
++, r
->bo
, r
->packet
,
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
);