140d60cc9a677da4f51b253b4d06095abc94f187
[mesa.git] / src / gallium / drivers / nv50 / nv50_vbo.c
1 #include "pipe/p_context.h"
2 #include "pipe/p_state.h"
3 #include "pipe/p_util.h"
4
5 #include "nv50_context.h"
6
7 static INLINE unsigned
8 nv50_prim(unsigned mode)
9 {
10 switch (mode) {
11 case PIPE_PRIM_POINTS: return NV50TCL_VERTEX_BEGIN_POINTS;
12 case PIPE_PRIM_LINES: return NV50TCL_VERTEX_BEGIN_LINES;
13 case PIPE_PRIM_LINE_LOOP: return NV50TCL_VERTEX_BEGIN_LINE_LOOP;
14 case PIPE_PRIM_LINE_STRIP: return NV50TCL_VERTEX_BEGIN_LINE_STRIP;
15 case PIPE_PRIM_TRIANGLES: return NV50TCL_VERTEX_BEGIN_TRIANGLES;
16 case PIPE_PRIM_TRIANGLE_STRIP:
17 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP;
18 case PIPE_PRIM_TRIANGLE_FAN: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN;
19 case PIPE_PRIM_QUADS: return NV50TCL_VERTEX_BEGIN_QUADS;
20 case PIPE_PRIM_QUAD_STRIP: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP;
21 case PIPE_PRIM_POLYGON: return NV50TCL_VERTEX_BEGIN_POLYGON;
22 default:
23 break;
24 }
25
26 NOUVEAU_ERR("invalid primitive type %d\n", mode);
27 return NV50TCL_VERTEX_BEGIN_POINTS;
28 }
29
30 boolean
31 nv50_draw_arrays(struct pipe_context *pipe, unsigned mode, unsigned start,
32 unsigned count)
33 {
34 struct nv50_context *nv50 = nv50_context(pipe);
35
36 nv50_state_validate(nv50);
37
38 BEGIN_RING(tesla, 0x142c, 1);
39 OUT_RING (0);
40 BEGIN_RING(tesla, 0x142c, 1);
41 OUT_RING (0);
42
43 BEGIN_RING(tesla, NV50TCL_VERTEX_BEGIN, 1);
44 OUT_RING (nv50_prim(mode));
45 BEGIN_RING(tesla, NV50TCL_VERTEX_BUFFER_FIRST, 2);
46 OUT_RING (start);
47 OUT_RING (count);
48 BEGIN_RING(tesla, NV50TCL_VERTEX_END, 1);
49 OUT_RING (0);
50
51 pipe->flush(pipe, 0, NULL);
52 return TRUE;
53 }
54
55 boolean
56 nv50_draw_elements(struct pipe_context *pipe,
57 struct pipe_buffer *indexBuffer, unsigned indexSize,
58 unsigned mode, unsigned start, unsigned count)
59 {
60 struct nv50_context *nv50 = nv50_context(pipe);
61
62 nv50_state_validate(nv50);
63
64 NOUVEAU_ERR("unimplemented\n");
65 return TRUE;
66 }
67
68 void
69 nv50_vbo_validate(struct nv50_context *nv50)
70 {
71 struct nouveau_grobj *tesla = nv50->screen->tesla;
72 struct nouveau_stateobj *vtxbuf, *vtxfmt;
73 int i, vpi = 0;
74
75 vtxbuf = so_new(nv50->vtxelt_nr * 4, nv50->vtxelt_nr * 2);
76 vtxfmt = so_new(nv50->vtxelt_nr + 1, 0);
77 so_method(vtxfmt, tesla, 0x1ac0, nv50->vtxelt_nr);
78
79 for (i = 0; i < nv50->vtxelt_nr; i++) {
80 struct pipe_vertex_element *ve = &nv50->vtxelt[i];
81 struct pipe_vertex_buffer *vb =
82 &nv50->vtxbuf[ve->vertex_buffer_index];
83
84 switch (ve->src_format) {
85 case PIPE_FORMAT_R32G32B32_FLOAT:
86 so_data(vtxfmt, 0x7e100000 | i);
87 break;
88 default:
89 {
90 char fmt[128];
91 pf_sprint_name(fmt, ve->src_format);
92 NOUVEAU_ERR("invalid vbo format %s\n", fmt);
93 assert(0);
94 return;
95 }
96 }
97
98 so_method(vtxbuf, tesla, 0x900 + (i * 16), 3);
99 so_data (vtxbuf, 0x20000000 | vb->pitch);
100 so_reloc (vtxbuf, vb->buffer, vb->buffer_offset +
101 ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD |
102 NOUVEAU_BO_HIGH, 0, 0);
103 so_reloc (vtxbuf, vb->buffer, vb->buffer_offset +
104 ve->src_offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD |
105 NOUVEAU_BO_LOW, 0, 0);
106 }
107
108 so_emit(nv50->screen->nvws, vtxfmt);
109 so_ref (NULL, &vtxfmt);
110 so_emit(nv50->screen->nvws, vtxbuf);
111 so_ref (NULL, &vtxbuf);
112 }
113