1 #include "pipe/p_context.h"
2 #include "pipe/p_state.h"
3 #include "pipe/p_util.h"
5 #include "nv40_context.h"
7 #include "nv40_state.h"
11 nv40_draw_arrays(struct pipe_context
*pipe
, unsigned mode
, unsigned start
,
14 struct nv40_context
*nv40
= (struct nv40_context
*)pipe
;
18 nv40_emit_hw_state(nv40
);
20 BEGIN_RING(curie
, NV40TCL_BEGIN_END
, 1);
21 OUT_RING (nvgl_primitive(mode
));
25 BEGIN_RING(curie
, NV40TCL_VB_VERTEX_BATCH
, 1);
26 OUT_RING (((nr
- 1) << 24) | start
);
30 /*XXX: large arrays (nr>2047) will blow up */
35 BEGIN_RING_NI(curie
, NV40TCL_VB_VERTEX_BATCH
, nr
);
37 OUT_RING(((0x100 - 1) << 24) | start
);
42 BEGIN_RING(curie
, NV40TCL_BEGIN_END
, 1);
45 pipe
->flush(pipe
, PIPE_FLUSH_WAIT
);
50 nv40_draw_elements_u08(struct nv40_context
*nv40
, void *ib
,
51 unsigned start
, unsigned count
)
53 uint8_t *elts
= (uint8_t *)ib
+ start
;
57 BEGIN_RING(curie
, NV40TCL_VB_ELEMENT_U32
, 1);
63 push
= MIN2(count
, 2046);
65 BEGIN_RING_NI(curie
, NV40TCL_VB_ELEMENT_U16
, push
);
66 for (i
= 0; i
< push
; i
+=2)
67 OUT_RING((elts
[i
+1] << 16) | elts
[i
]);
75 nv40_draw_elements_u16(struct nv40_context
*nv40
, void *ib
,
76 unsigned start
, unsigned count
)
78 uint16_t *elts
= (uint16_t *)ib
+ start
;
82 BEGIN_RING(curie
, NV40TCL_VB_ELEMENT_U32
, 1);
88 push
= MIN2(count
, 2046);
90 BEGIN_RING_NI(curie
, NV40TCL_VB_ELEMENT_U16
, push
);
91 for (i
= 0; i
< push
; i
+=2)
92 OUT_RING((elts
[i
+1] << 16) | elts
[i
]);
100 nv40_draw_elements_u32(struct nv40_context
*nv40
, void *ib
,
101 unsigned start
, unsigned count
)
103 uint32_t *elts
= (uint32_t *)ib
+ start
;
107 push
= MIN2(count
, 2047);
109 BEGIN_RING_NI(curie
, NV40TCL_VB_ELEMENT_U32
, push
);
110 OUT_RINGp (elts
, push
);
118 nv40_draw_elements(struct pipe_context
*pipe
,
119 struct pipe_buffer_handle
*indexBuffer
, unsigned indexSize
,
120 unsigned mode
, unsigned start
, unsigned count
)
122 struct nv40_context
*nv40
= (struct nv40_context
*)pipe
;
126 nv40_emit_hw_state(nv40
);
128 ib
= pipe
->winsys
->buffer_map(pipe
->winsys
, indexBuffer
,
129 PIPE_BUFFER_FLAG_READ
);
131 NOUVEAU_ERR("Couldn't map index buffer!!\n");
135 BEGIN_RING(curie
, NV40TCL_BEGIN_END
, 1);
136 OUT_RING (nvgl_primitive(mode
));
140 nv40_draw_elements_u08(nv40
, ib
, start
, count
);
143 nv40_draw_elements_u16(nv40
, ib
, start
, count
);
146 nv40_draw_elements_u32(nv40
, ib
, start
, count
);
149 NOUVEAU_ERR("unsupported elt size %d\n", indexSize
);
153 BEGIN_RING(curie
, NV40TCL_BEGIN_END
, 1);
156 pipe
->winsys
->buffer_unmap(pipe
->winsys
, ib
);
157 pipe
->flush(pipe
, PIPE_FLUSH_WAIT
);
162 nv40_vbo_format_to_ncomp(uint format
)
165 case PIPE_FORMAT_R32G32B32A32_FLOAT
: return 4;
166 case PIPE_FORMAT_R32G32B32_FLOAT
: return 3;
167 case PIPE_FORMAT_R32G32_FLOAT
: return 2;
168 case PIPE_FORMAT_R32_FLOAT
: return 1;
170 NOUVEAU_ERR("AII, unknown vbo format %d\n", format
);
176 nv40_vbo_arrays_update(struct nv40_context
*nv40
)
178 struct nv40_vertex_program
*vp
= nv40
->vertprog
.active
;
179 uint32_t inputs
, vtxfmt
[16];
183 for (hw
= 0; hw
< 16 && inputs
; hw
++) {
184 if (inputs
& (1 << hw
)) {
186 inputs
&= ~(1 << hw
);
192 BEGIN_RING(curie
, NV40TCL_VTXBUF_ADDRESS(0), num_hw
);
193 for (hw
= 0; hw
< num_hw
; hw
++) {
194 struct pipe_vertex_element
*ve
;
195 struct pipe_vertex_buffer
*vb
;
197 if (!(inputs
& (1 << hw
))) {
199 vtxfmt
[hw
] = NV40TCL_VTXFMT_TYPE_FLOAT
;
203 ve
= &nv40
->vtxelt
[hw
];
204 vb
= &nv40
->vtxbuf
[ve
->vertex_buffer_index
];
206 OUT_RELOC(vb
->buffer
, vb
->buffer_offset
+ ve
->src_offset
,
207 NOUVEAU_BO_GART
| NOUVEAU_BO_VRAM
| NOUVEAU_BO_LOW
|
208 NOUVEAU_BO_OR
| NOUVEAU_BO_RD
, 0,
209 NV40TCL_VTXBUF_ADDRESS_DMA1
);
210 vtxfmt
[hw
] = ((vb
->pitch
<< NV40TCL_VTXFMT_STRIDE_SHIFT
) |
211 (nv40_vbo_format_to_ncomp(ve
->src_format
) <<
212 NV40TCL_VTXFMT_SIZE_SHIFT
) |
213 NV40TCL_VTXFMT_TYPE_FLOAT
);
216 BEGIN_RING(curie
, 0x1710, 1);
217 OUT_RING (0); /* vtx cache flush */
218 BEGIN_RING(curie
, NV40TCL_VTXFMT(0), num_hw
);
219 OUT_RINGp (vtxfmt
, num_hw
);