1 #ifndef __NOUVEAU_STATEOBJ_H__
2 #define __NOUVEAU_STATEOBJ_H__
4 #include "pipe/p_util.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
;
52 if (--so
->refcount
<= 0) {
67 so_data(struct nouveau_stateobj
*so
, unsigned data
)
69 (*so
->cur
++) = (data
);
74 so_method(struct nouveau_stateobj
*so
, struct nouveau_grobj
*gr
,
75 unsigned mthd
, unsigned size
)
77 so
->cur_packet
= (gr
->subc
<< 13) | (1 << 18) | (mthd
- 4);
78 so_data(so
, (gr
->subc
<< 13) | (size
<< 18) | mthd
);
82 so_reloc(struct nouveau_stateobj
*so
, struct pipe_buffer
*bo
,
83 unsigned data
, unsigned flags
, unsigned vor
, unsigned tor
)
85 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[so
->cur_reloc
++];
88 r
->offset
= so
->cur
- so
->push
;
89 r
->packet
= so
->cur_packet
;
98 so_emit(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
100 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
103 nr
= so
->cur
- so
->push
;
104 if (pb
->remaining
< nr
)
105 nvws
->push_flush(nvws
->channel
, nr
);
108 memcpy(pb
->cur
, so
->push
, nr
* 4);
109 for (i
= 0; i
< so
->cur_reloc
; i
++) {
110 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[i
];
112 nvws
->push_reloc(nvws
->channel
, pb
->cur
+ r
->offset
, r
->bo
,
113 r
->data
, r
->flags
, r
->vor
, r
->tor
);
119 so_emit_reloc_markers(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
121 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
124 i
= so
->cur_reloc
<< 1;
125 if (nvws
->channel
->pushbuf
->remaining
< i
)
126 nvws
->push_flush(nvws
->channel
, i
);
127 nvws
->channel
->pushbuf
->remaining
-= i
;
129 for (i
= 0; i
< so
->cur_reloc
; i
++) {
130 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[i
];
132 nvws
->push_reloc(nvws
->channel
, pb
->cur
++, r
->bo
, r
->packet
,
134 (NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
)) |
135 NOUVEAU_BO_DUMMY
, 0, 0);
136 nvws
->push_reloc(nvws
->channel
, pb
->cur
++, r
->bo
, r
->data
,
137 r
->flags
| NOUVEAU_BO_DUMMY
, r
->vor
, r
->tor
);