439c7e4734ad3514bfa15576921a4548acc1c8a7
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
= *pso
;
54 if (so
&& --so
->refcount
<= 0) {
64 so_data(struct nouveau_stateobj
*so
, unsigned data
)
66 (*so
->cur
++) = (data
);
71 so_method(struct nouveau_stateobj
*so
, struct nouveau_grobj
*gr
,
72 unsigned mthd
, unsigned size
)
74 so
->cur_packet
= (gr
->subc
<< 13) | (1 << 18) | (mthd
- 4);
75 so_data(so
, (gr
->subc
<< 13) | (size
<< 18) | mthd
);
79 so_reloc(struct nouveau_stateobj
*so
, struct pipe_buffer
*bo
,
80 unsigned data
, unsigned flags
, unsigned vor
, unsigned tor
)
82 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[so
->cur_reloc
++];
85 r
->offset
= so
->cur
- so
->push
;
86 r
->packet
= so
->cur_packet
;
95 so_emit(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
97 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
100 nr
= so
->cur
- so
->push
;
101 if (pb
->remaining
< nr
)
102 nvws
->push_flush(nvws
->channel
, nr
);
105 memcpy(pb
->cur
, so
->push
, nr
* 4);
106 for (i
= 0; i
< so
->cur_reloc
; i
++) {
107 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[i
];
109 nvws
->push_reloc(nvws
->channel
, pb
->cur
+ r
->offset
, r
->bo
,
110 r
->data
, r
->flags
, r
->vor
, r
->tor
);
116 so_emit_reloc_markers(struct nouveau_winsys
*nvws
, struct nouveau_stateobj
*so
)
118 struct nouveau_pushbuf
*pb
= nvws
->channel
->pushbuf
;
121 i
= so
->cur_reloc
<< 1;
122 if (nvws
->channel
->pushbuf
->remaining
< i
)
123 nvws
->push_flush(nvws
->channel
, i
);
124 nvws
->channel
->pushbuf
->remaining
-= i
;
126 for (i
= 0; i
< so
->cur_reloc
; i
++) {
127 struct nouveau_stateobj_reloc
*r
= &so
->reloc
[i
];
129 nvws
->push_reloc(nvws
->channel
, pb
->cur
++, r
->bo
, r
->packet
,
131 (NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
)) |
132 NOUVEAU_BO_DUMMY
, 0, 0);
133 nvws
->push_reloc(nvws
->channel
, pb
->cur
++, r
->bo
, r
->data
,
134 r
->flags
| NOUVEAU_BO_DUMMY
, r
->vor
, r
->tor
);