2 * Copyright 2008 Ben Skeggs
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "pipe/p_context.h"
24 #include "pipe/p_state.h"
26 #include "nv50_context.h"
28 static INLINE
unsigned
29 nv50_prim(unsigned mode
)
32 case PIPE_PRIM_POINTS
: return NV50TCL_VERTEX_BEGIN_POINTS
;
33 case PIPE_PRIM_LINES
: return NV50TCL_VERTEX_BEGIN_LINES
;
34 case PIPE_PRIM_LINE_LOOP
: return NV50TCL_VERTEX_BEGIN_LINE_LOOP
;
35 case PIPE_PRIM_LINE_STRIP
: return NV50TCL_VERTEX_BEGIN_LINE_STRIP
;
36 case PIPE_PRIM_TRIANGLES
: return NV50TCL_VERTEX_BEGIN_TRIANGLES
;
37 case PIPE_PRIM_TRIANGLE_STRIP
:
38 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP
;
39 case PIPE_PRIM_TRIANGLE_FAN
: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN
;
40 case PIPE_PRIM_QUADS
: return NV50TCL_VERTEX_BEGIN_QUADS
;
41 case PIPE_PRIM_QUAD_STRIP
: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP
;
42 case PIPE_PRIM_POLYGON
: return NV50TCL_VERTEX_BEGIN_POLYGON
;
47 NOUVEAU_ERR("invalid primitive type %d\n", mode
);
48 return NV50TCL_VERTEX_BEGIN_POINTS
;
52 nv50_draw_arrays(struct pipe_context
*pipe
, unsigned mode
, unsigned start
,
55 struct nv50_context
*nv50
= nv50_context(pipe
);
56 struct nouveau_channel
*chan
= nv50
->screen
->nvws
->channel
;
57 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
59 nv50_state_validate(nv50
);
61 BEGIN_RING(chan
, tesla
, 0x142c, 1);
63 BEGIN_RING(chan
, tesla
, 0x142c, 1);
65 BEGIN_RING(chan
, tesla
, 0x1440, 1);
67 BEGIN_RING(chan
, tesla
, 0x1334, 1);
70 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BEGIN
, 1);
71 OUT_RING (chan
, nv50_prim(mode
));
72 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BUFFER_FIRST
, 2);
73 OUT_RING (chan
, start
);
74 OUT_RING (chan
, count
);
75 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_END
, 1);
78 pipe
->flush(pipe
, 0, NULL
);
83 nv50_draw_elements_inline_u08(struct nv50_context
*nv50
, uint8_t *map
,
84 unsigned start
, unsigned count
)
86 struct nouveau_channel
*chan
= nv50
->screen
->nvws
->channel
;
87 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
92 BEGIN_RING(chan
, tesla
, 0x15e8, 1);
93 OUT_RING (chan
, map
[0]);
99 unsigned nr
= count
> 2046 ? 2046 : count
;
102 BEGIN_RING(chan
, tesla
, 0x400015f0, nr
>> 1);
103 for (i
= 0; i
< nr
; i
+= 2)
104 OUT_RING (chan
, (map
[1] << 16) | map
[0]);
112 nv50_draw_elements_inline_u16(struct nv50_context
*nv50
, uint16_t *map
,
113 unsigned start
, unsigned count
)
115 struct nouveau_channel
*chan
= nv50
->screen
->nvws
->channel
;
116 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
121 BEGIN_RING(chan
, tesla
, 0x15e8, 1);
122 OUT_RING (chan
, map
[0]);
128 unsigned nr
= count
> 2046 ? 2046 : count
;
131 BEGIN_RING(chan
, tesla
, 0x400015f0, nr
>> 1);
132 for (i
= 0; i
< nr
; i
+= 2)
133 OUT_RING (chan
, (map
[1] << 16) | map
[0]);
141 nv50_draw_elements_inline_u32(struct nv50_context
*nv50
, uint8_t *map
,
142 unsigned start
, unsigned count
)
144 struct nouveau_channel
*chan
= nv50
->screen
->nvws
->channel
;
145 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
150 unsigned nr
= count
> 2047 ? 2047 : count
;
152 BEGIN_RING(chan
, tesla
, 0x400015e8, nr
);
153 OUT_RINGp (chan
, map
, nr
);
161 nv50_draw_elements(struct pipe_context
*pipe
,
162 struct pipe_buffer
*indexBuffer
, unsigned indexSize
,
163 unsigned mode
, unsigned start
, unsigned count
)
165 struct nv50_context
*nv50
= nv50_context(pipe
);
166 struct nouveau_channel
*chan
= nv50
->screen
->nvws
->channel
;
167 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
168 struct pipe_winsys
*ws
= pipe
->winsys
;
169 void *map
= ws
->buffer_map(ws
, indexBuffer
, PIPE_BUFFER_USAGE_CPU_READ
);
171 nv50_state_validate(nv50
);
173 BEGIN_RING(chan
, tesla
, 0x142c, 1);
175 BEGIN_RING(chan
, tesla
, 0x142c, 1);
178 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BEGIN
, 1);
179 OUT_RING (chan
, nv50_prim(mode
));
182 nv50_draw_elements_inline_u08(nv50
, map
, start
, count
);
185 nv50_draw_elements_inline_u16(nv50
, map
, start
, count
);
188 nv50_draw_elements_inline_u32(nv50
, map
, start
, count
);
193 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_END
, 1);
196 pipe
->flush(pipe
, 0, NULL
);
201 nv50_vbo_validate(struct nv50_context
*nv50
)
203 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
204 struct nouveau_stateobj
*vtxbuf
, *vtxfmt
;
207 vtxbuf
= so_new(nv50
->vtxelt_nr
* 4, nv50
->vtxelt_nr
* 2);
208 vtxfmt
= so_new(nv50
->vtxelt_nr
+ 1, 0);
209 so_method(vtxfmt
, tesla
, 0x1ac0, nv50
->vtxelt_nr
);
211 for (i
= 0; i
< nv50
->vtxelt_nr
; i
++) {
212 struct pipe_vertex_element
*ve
= &nv50
->vtxelt
[i
];
213 struct pipe_vertex_buffer
*vb
=
214 &nv50
->vtxbuf
[ve
->vertex_buffer_index
];
216 switch (ve
->src_format
) {
217 case PIPE_FORMAT_R32G32B32A32_FLOAT
:
218 so_data(vtxfmt
, 0x7e080000 | i
);
220 case PIPE_FORMAT_R32G32B32_FLOAT
:
221 so_data(vtxfmt
, 0x7e100000 | i
);
223 case PIPE_FORMAT_R32G32_FLOAT
:
224 so_data(vtxfmt
, 0x7e200000 | i
);
226 case PIPE_FORMAT_R32_FLOAT
:
227 so_data(vtxfmt
, 0x7e900000 | i
);
229 case PIPE_FORMAT_R8G8B8A8_UNORM
:
230 so_data(vtxfmt
, 0x24500000 | i
);
234 NOUVEAU_ERR("invalid vbo format %s\n",
235 pf_name(ve
->src_format
));
241 so_method(vtxbuf
, tesla
, 0x900 + (i
* 16), 3);
242 so_data (vtxbuf
, 0x20000000 | vb
->stride
);
243 so_reloc (vtxbuf
, vb
->buffer
, vb
->buffer_offset
+
244 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
|
245 NOUVEAU_BO_RD
| NOUVEAU_BO_HIGH
, 0, 0);
246 so_reloc (vtxbuf
, vb
->buffer
, vb
->buffer_offset
+
247 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
|
248 NOUVEAU_BO_RD
| NOUVEAU_BO_LOW
, 0, 0);
251 so_ref (vtxfmt
, &nv50
->state
.vtxfmt
);
252 so_ref (vtxbuf
, &nv50
->state
.vtxbuf
);