1 #include "pipe/p_context.h"
2 #include "pipe/p_state.h"
3 #include "pipe/p_util.h"
5 #include "nv50_context.h"
8 nv50_prim(unsigned 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
;
26 NOUVEAU_ERR("invalid primitive type %d\n", mode
);
27 return NV50TCL_VERTEX_BEGIN_POINTS
;
31 nv50_draw_arrays(struct pipe_context
*pipe
, unsigned mode
, unsigned start
,
34 struct nv50_context
*nv50
= nv50_context(pipe
);
36 nv50_state_validate(nv50
);
38 BEGIN_RING(tesla
, 0x142c, 1);
40 BEGIN_RING(tesla
, 0x142c, 1);
43 BEGIN_RING(tesla
, NV50TCL_VERTEX_BEGIN
, 1);
44 OUT_RING (nv50_prim(mode
));
45 BEGIN_RING(tesla
, NV50TCL_VERTEX_BUFFER_FIRST
, 2);
48 BEGIN_RING(tesla
, NV50TCL_VERTEX_END
, 1);
51 pipe
->flush(pipe
, 0, NULL
);
56 nv50_draw_elements_inline_u08(struct nv50_context
*nv50
, uint8_t *map
,
57 unsigned start
, unsigned count
)
62 BEGIN_RING(tesla
, 0x15e8, 1);
69 unsigned nr
= count
> 2046 ? 2046 : count
;
72 BEGIN_RING(tesla
, 0x400015f0, nr
>> 1);
73 for (i
= 0; i
< nr
; i
+= 2)
74 OUT_RING ((map
[1] << 16) | map
[0]);
82 nv50_draw_elements_inline_u16(struct nv50_context
*nv50
, uint16_t *map
,
83 unsigned start
, unsigned count
)
88 BEGIN_RING(tesla
, 0x15e8, 1);
95 unsigned nr
= count
> 2046 ? 2046 : count
;
98 BEGIN_RING(tesla
, 0x400015f0, nr
>> 1);
99 for (i
= 0; i
< nr
; i
+= 2)
100 OUT_RING ((map
[1] << 16) | map
[0]);
108 nv50_draw_elements_inline_u32(struct nv50_context
*nv50
, uint8_t *map
,
109 unsigned start
, unsigned count
)
114 unsigned nr
= count
> 2047 ? 2047 : count
;
116 BEGIN_RING(tesla
, 0x400015e8, nr
);
125 nv50_draw_elements(struct pipe_context
*pipe
,
126 struct pipe_buffer
*indexBuffer
, unsigned indexSize
,
127 unsigned mode
, unsigned start
, unsigned count
)
129 struct nv50_context
*nv50
= nv50_context(pipe
);
130 struct pipe_winsys
*ws
= pipe
->winsys
;
131 void *map
= ws
->buffer_map(ws
, indexBuffer
, PIPE_BUFFER_USAGE_CPU_READ
);
133 nv50_state_validate(nv50
);
135 BEGIN_RING(tesla
, 0x142c, 1);
137 BEGIN_RING(tesla
, 0x142c, 1);
140 BEGIN_RING(tesla
, NV50TCL_VERTEX_BEGIN
, 1);
141 OUT_RING (nv50_prim(mode
));
144 nv50_draw_elements_inline_u08(nv50
, map
, start
, count
);
147 nv50_draw_elements_inline_u16(nv50
, map
, start
, count
);
150 nv50_draw_elements_inline_u32(nv50
, map
, start
, count
);
155 BEGIN_RING(tesla
, NV50TCL_VERTEX_END
, 1);
158 pipe
->flush(pipe
, 0, NULL
);
163 nv50_vbo_validate(struct nv50_context
*nv50
)
165 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
166 struct nouveau_stateobj
*vtxbuf
, *vtxfmt
;
169 vtxbuf
= so_new(nv50
->vtxelt_nr
* 4, nv50
->vtxelt_nr
* 2);
170 vtxfmt
= so_new(nv50
->vtxelt_nr
+ 1, 0);
171 so_method(vtxfmt
, tesla
, 0x1ac0, nv50
->vtxelt_nr
);
173 for (i
= 0; i
< nv50
->vtxelt_nr
; i
++) {
174 struct pipe_vertex_element
*ve
= &nv50
->vtxelt
[i
];
175 struct pipe_vertex_buffer
*vb
=
176 &nv50
->vtxbuf
[ve
->vertex_buffer_index
];
178 switch (ve
->src_format
) {
179 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
180 so_data(vtxfmt
, 0x7e080000 | i
);
182 case PIPE_FORMAT_R32G32B32_FLOAT
:
183 so_data(vtxfmt
, 0x7e100000 | i
);
185 case PIPE_FORMAT_R32G32_FLOAT
:
186 so_data(vtxfmt
, 0x7e200000 | i
);
188 case PIPE_FORMAT_R8G8B8A8_UNORM
:
189 so_data(vtxfmt
, 0x24500000 | i
);
194 pf_sprint_name(fmt
, ve
->src_format
);
195 NOUVEAU_ERR("invalid vbo format %s\n", fmt
);
201 so_method(vtxbuf
, tesla
, 0x900 + (i
* 16), 3);
202 so_data (vtxbuf
, 0x20000000 | vb
->pitch
);
203 so_reloc (vtxbuf
, vb
->buffer
, vb
->buffer_offset
+
204 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
205 NOUVEAU_BO_HIGH
, 0, 0);
206 so_reloc (vtxbuf
, vb
->buffer
, vb
->buffer_offset
+
207 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_RD
|
208 NOUVEAU_BO_LOW
, 0, 0);
211 so_ref (vtxfmt
, &nv50
->state
.vtxfmt
);
212 so_ref (vtxbuf
, &nv50
->state
.vtxbuf
);