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"
25 #include "pipe/p_inlines.h"
27 #include "util/u_format.h"
29 #include "nv50_context.h"
32 nv50_push_elements_u08(struct nv50_context
*, uint8_t *, unsigned);
35 nv50_push_elements_u16(struct nv50_context
*, uint16_t *, unsigned);
38 nv50_push_elements_u32(struct nv50_context
*, uint32_t *, unsigned);
41 nv50_push_arrays(struct nv50_context
*, unsigned, unsigned);
43 static INLINE
unsigned
44 nv50_prim(unsigned mode
)
47 case PIPE_PRIM_POINTS
: return NV50TCL_VERTEX_BEGIN_POINTS
;
48 case PIPE_PRIM_LINES
: return NV50TCL_VERTEX_BEGIN_LINES
;
49 case PIPE_PRIM_LINE_LOOP
: return NV50TCL_VERTEX_BEGIN_LINE_LOOP
;
50 case PIPE_PRIM_LINE_STRIP
: return NV50TCL_VERTEX_BEGIN_LINE_STRIP
;
51 case PIPE_PRIM_TRIANGLES
: return NV50TCL_VERTEX_BEGIN_TRIANGLES
;
52 case PIPE_PRIM_TRIANGLE_STRIP
:
53 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP
;
54 case PIPE_PRIM_TRIANGLE_FAN
: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN
;
55 case PIPE_PRIM_QUADS
: return NV50TCL_VERTEX_BEGIN_QUADS
;
56 case PIPE_PRIM_QUAD_STRIP
: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP
;
57 case PIPE_PRIM_POLYGON
: return NV50TCL_VERTEX_BEGIN_POLYGON
;
58 case PIPE_PRIM_LINES_ADJACENCY
:
59 return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY
;
60 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
61 return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY
;
62 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
63 return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY
;
64 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
65 return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY
;
70 NOUVEAU_ERR("invalid primitive type %d\n", mode
);
71 return NV50TCL_VERTEX_BEGIN_POINTS
;
74 static INLINE
uint32_t
75 nv50_vbo_type_to_hw(enum pipe_format format
)
77 const struct util_format_description
*desc
;
79 desc
= util_format_description(format
);
82 switch (desc
->channel
[0].type
) {
83 case UTIL_FORMAT_TYPE_FLOAT
:
84 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_FLOAT
;
85 case UTIL_FORMAT_TYPE_UNSIGNED
:
86 if (desc
->channel
[0].normalized
) {
87 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_UNORM
;
89 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_USCALED
;
90 case UTIL_FORMAT_TYPE_SIGNED
:
91 if (desc
->channel
[0].normalized
) {
92 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SNORM
;
94 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SSCALED
;
96 case PIPE_FORMAT_TYPE_UINT:
97 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_UINT;
98 case PIPE_FORMAT_TYPE_SINT:
99 return NV50TCL_VERTEX_ARRAY_ATTRIB_TYPE_SINT; */
105 static INLINE
uint32_t
106 nv50_vbo_size_to_hw(unsigned size
, unsigned nr_c
)
108 static const uint32_t hw_values
[] = {
110 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8
,
111 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8
,
112 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8_8
,
113 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_8_8_8_8
,
114 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16
,
115 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16
,
116 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16_16
,
117 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_16_16_16_16
,
119 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32
,
120 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32
,
121 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32_32
,
122 NV50TCL_VERTEX_ARRAY_ATTRIB_FORMAT_32_32_32_32
};
124 /* we'd also have R11G11B10 and R10G10B10A2 */
126 assert(nr_c
> 0 && nr_c
<= 4);
132 return hw_values
[size
+ (nr_c
- 1)];
135 static INLINE
uint32_t
136 nv50_vbo_vtxelt_to_hw(struct pipe_vertex_element
*ve
)
138 uint32_t hw_type
, hw_size
;
139 enum pipe_format pf
= ve
->src_format
;
140 const struct util_format_description
*desc
;
143 desc
= util_format_description(pf
);
146 size
= util_format_get_component_bits(pf
, UTIL_FORMAT_COLORSPACE_RGB
, 0);
148 hw_type
= nv50_vbo_type_to_hw(pf
);
149 hw_size
= nv50_vbo_size_to_hw(size
, ve
->nr_components
);
151 if (!hw_type
|| !hw_size
) {
152 NOUVEAU_ERR("unsupported vbo format: %s\n", pf_name(pf
));
157 if (desc
->swizzle
[0] == UTIL_FORMAT_SWIZZLE_Z
) /* BGRA */
158 hw_size
|= (1 << 31); /* no real swizzle bits :-( */
160 return (hw_type
| hw_size
);
164 nv50_draw_arrays(struct pipe_context
*pipe
, unsigned mode
, unsigned start
,
167 struct nv50_context
*nv50
= nv50_context(pipe
);
168 struct nouveau_channel
*chan
= nv50
->screen
->tesla
->channel
;
169 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
172 nv50_state_validate(nv50
);
174 BEGIN_RING(chan
, tesla
, 0x142c, 1);
176 BEGIN_RING(chan
, tesla
, 0x142c, 1);
179 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BEGIN
, 1);
180 OUT_RING (chan
, nv50_prim(mode
));
183 ret
= nv50_push_arrays(nv50
, start
, count
);
185 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BUFFER_FIRST
, 2);
186 OUT_RING (chan
, start
);
187 OUT_RING (chan
, count
);
190 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_END
, 1);
193 /* XXX: not sure what to do if ret != TRUE: flush and retry?
198 static INLINE boolean
199 nv50_draw_elements_inline_u08(struct nv50_context
*nv50
, uint8_t *map
,
200 unsigned start
, unsigned count
)
202 struct nouveau_channel
*chan
= nv50
->screen
->tesla
->channel
;
203 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
208 return nv50_push_elements_u08(nv50
, map
, count
);
211 BEGIN_RING(chan
, tesla
, NV50TCL_VB_ELEMENT_U32
, 1);
212 OUT_RING (chan
, map
[0]);
218 unsigned nr
= count
> 2046 ? 2046 : count
;
221 BEGIN_RING(chan
, tesla
, NV50TCL_VB_ELEMENT_U16
| 0x40000000, nr
>> 1);
222 for (i
= 0; i
< nr
; i
+= 2)
223 OUT_RING (chan
, (map
[i
+ 1] << 16) | map
[i
]);
231 static INLINE boolean
232 nv50_draw_elements_inline_u16(struct nv50_context
*nv50
, uint16_t *map
,
233 unsigned start
, unsigned count
)
235 struct nouveau_channel
*chan
= nv50
->screen
->tesla
->channel
;
236 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
241 return nv50_push_elements_u16(nv50
, map
, count
);
244 BEGIN_RING(chan
, tesla
, NV50TCL_VB_ELEMENT_U32
, 1);
245 OUT_RING (chan
, map
[0]);
251 unsigned nr
= count
> 2046 ? 2046 : count
;
254 BEGIN_RING(chan
, tesla
, NV50TCL_VB_ELEMENT_U16
| 0x40000000, nr
>> 1);
255 for (i
= 0; i
< nr
; i
+= 2)
256 OUT_RING (chan
, (map
[i
+ 1] << 16) | map
[i
]);
264 static INLINE boolean
265 nv50_draw_elements_inline_u32(struct nv50_context
*nv50
, uint32_t *map
,
266 unsigned start
, unsigned count
)
268 struct nouveau_channel
*chan
= nv50
->screen
->tesla
->channel
;
269 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
274 return nv50_push_elements_u32(nv50
, map
, count
);
277 unsigned nr
= count
> 2047 ? 2047 : count
;
279 BEGIN_RING(chan
, tesla
, NV50TCL_VB_ELEMENT_U32
| 0x40000000, nr
);
280 OUT_RINGp (chan
, map
, nr
);
289 nv50_draw_elements(struct pipe_context
*pipe
,
290 struct pipe_buffer
*indexBuffer
, unsigned indexSize
,
291 unsigned mode
, unsigned start
, unsigned count
)
293 struct nv50_context
*nv50
= nv50_context(pipe
);
294 struct nouveau_channel
*chan
= nv50
->screen
->tesla
->channel
;
295 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
296 struct pipe_screen
*pscreen
= pipe
->screen
;
300 map
= pipe_buffer_map(pscreen
, indexBuffer
, PIPE_BUFFER_USAGE_CPU_READ
);
302 nv50_state_validate(nv50
);
304 BEGIN_RING(chan
, tesla
, 0x142c, 1);
306 BEGIN_RING(chan
, tesla
, 0x142c, 1);
309 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_BEGIN
, 1);
310 OUT_RING (chan
, nv50_prim(mode
));
313 ret
= nv50_draw_elements_inline_u08(nv50
, map
, start
, count
);
316 ret
= nv50_draw_elements_inline_u16(nv50
, map
, start
, count
);
319 ret
= nv50_draw_elements_inline_u32(nv50
, map
, start
, count
);
326 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_END
, 1);
329 pipe_buffer_unmap(pscreen
, indexBuffer
);
331 /* XXX: what to do if ret != TRUE? Flush and retry?
336 static INLINE boolean
337 nv50_vbo_static_attrib(struct nv50_context
*nv50
, unsigned attrib
,
338 struct nouveau_stateobj
**pso
,
339 struct pipe_vertex_element
*ve
,
340 struct pipe_vertex_buffer
*vb
)
343 struct nouveau_stateobj
*so
;
344 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
345 struct nouveau_bo
*bo
= nouveau_bo(vb
->buffer
);
348 enum pipe_format pf
= ve
->src_format
;
349 const struct util_format_description
*desc
;
351 desc
= util_format_description(pf
);
354 if ((desc
->channel
[0].type
!= UTIL_FORMAT_TYPE_FLOAT
) ||
355 util_format_get_component_bits(pf
, UTIL_FORMAT_COLORSPACE_RGB
, 0) != 32)
358 ret
= nouveau_bo_map(bo
, NOUVEAU_BO_RD
);
361 v
= (float *)(bo
->map
+ (vb
->buffer_offset
+ ve
->src_offset
));
365 *pso
= so
= so_new(nv50
->vtxelt_nr
, nv50
->vtxelt_nr
* 4, 0);
367 switch (ve
->nr_components
) {
369 so_method(so
, tesla
, NV50TCL_VTX_ATTR_4F_X(attrib
), 4);
370 so_data (so
, fui(v
[0]));
371 so_data (so
, fui(v
[1]));
372 so_data (so
, fui(v
[2]));
373 so_data (so
, fui(v
[3]));
376 so_method(so
, tesla
, NV50TCL_VTX_ATTR_3F_X(attrib
), 3);
377 so_data (so
, fui(v
[0]));
378 so_data (so
, fui(v
[1]));
379 so_data (so
, fui(v
[2]));
382 so_method(so
, tesla
, NV50TCL_VTX_ATTR_2F_X(attrib
), 2);
383 so_data (so
, fui(v
[0]));
384 so_data (so
, fui(v
[1]));
387 if (attrib
== nv50
->vertprog
->cfg
.edgeflag_in
) {
388 so_method(so
, tesla
, NV50TCL_EDGEFLAG_ENABLE
, 1);
389 so_data (so
, v
[0] ? 1 : 0);
391 so_method(so
, tesla
, NV50TCL_VTX_ATTR_1F(attrib
), 1);
392 so_data (so
, fui(v
[0]));
395 nouveau_bo_unmap(bo
);
399 nouveau_bo_unmap(bo
);
404 nv50_vbo_validate(struct nv50_context
*nv50
)
406 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
407 struct nouveau_stateobj
*vtxbuf
, *vtxfmt
, *vtxattr
;
410 /* don't validate if Gallium took away our buffers */
411 if (nv50
->vtxbuf_nr
== 0)
415 for (i
= 0; i
< nv50
->vtxbuf_nr
; ++i
)
416 if (nv50
->vtxbuf
[i
].stride
&&
417 !(nv50
->vtxbuf
[i
].buffer
->usage
& PIPE_BUFFER_USAGE_VERTEX
))
418 nv50
->vbo_fifo
= 0xffff;
420 if (nv50
->vertprog
->cfg
.edgeflag_in
< 16)
421 nv50
->vbo_fifo
= 0xffff; /* vertprog can't set edgeflag */
423 n_ve
= MAX2(nv50
->vtxelt_nr
, nv50
->state
.vtxelt_nr
);
426 vtxbuf
= so_new(n_ve
* 2, n_ve
* 5, nv50
->vtxelt_nr
* 4);
427 vtxfmt
= so_new(1, n_ve
, 0);
428 so_method(vtxfmt
, tesla
, NV50TCL_VERTEX_ARRAY_ATTRIB(0), n_ve
);
430 for (i
= 0; i
< nv50
->vtxelt_nr
; i
++) {
431 struct pipe_vertex_element
*ve
= &nv50
->vtxelt
[i
];
432 struct pipe_vertex_buffer
*vb
=
433 &nv50
->vtxbuf
[ve
->vertex_buffer_index
];
434 struct nouveau_bo
*bo
= nouveau_bo(vb
->buffer
);
435 uint32_t hw
= nv50_vbo_vtxelt_to_hw(ve
);
438 nv50_vbo_static_attrib(nv50
, i
, &vtxattr
, ve
, vb
)) {
439 so_data(vtxfmt
, hw
| (1 << 4));
441 so_method(vtxbuf
, tesla
,
442 NV50TCL_VERTEX_ARRAY_FORMAT(i
), 1);
445 nv50
->vbo_fifo
&= ~(1 << i
);
448 so_data(vtxfmt
, hw
| i
);
450 if (nv50
->vbo_fifo
) {
451 so_method(vtxbuf
, tesla
,
452 NV50TCL_VERTEX_ARRAY_FORMAT(i
), 1);
457 so_method(vtxbuf
, tesla
, NV50TCL_VERTEX_ARRAY_FORMAT(i
), 3);
458 so_data (vtxbuf
, 0x20000000 | vb
->stride
);
459 so_reloc (vtxbuf
, bo
, vb
->buffer_offset
+
460 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
|
461 NOUVEAU_BO_RD
| NOUVEAU_BO_HIGH
, 0, 0);
462 so_reloc (vtxbuf
, bo
, vb
->buffer_offset
+
463 ve
->src_offset
, NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
|
464 NOUVEAU_BO_RD
| NOUVEAU_BO_LOW
, 0, 0);
466 /* vertex array limits */
467 so_method(vtxbuf
, tesla
, NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i
), 2);
468 so_reloc (vtxbuf
, bo
, vb
->buffer
->size
- 1,
469 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
|
470 NOUVEAU_BO_HIGH
, 0, 0);
471 so_reloc (vtxbuf
, bo
, vb
->buffer
->size
- 1,
472 NOUVEAU_BO_VRAM
| NOUVEAU_BO_GART
| NOUVEAU_BO_RD
|
473 NOUVEAU_BO_LOW
, 0, 0);
475 for (; i
< n_ve
; ++i
) {
476 so_data (vtxfmt
, 0x7e080010);
478 so_method(vtxbuf
, tesla
, NV50TCL_VERTEX_ARRAY_FORMAT(i
), 1);
481 nv50
->state
.vtxelt_nr
= nv50
->vtxelt_nr
;
483 so_ref (vtxfmt
, &nv50
->state
.vtxfmt
);
484 so_ref (vtxbuf
, &nv50
->state
.vtxbuf
);
485 so_ref (vtxattr
, &nv50
->state
.vtxattr
);
486 so_ref (NULL
, &vtxbuf
);
487 so_ref (NULL
, &vtxfmt
);
488 so_ref (NULL
, &vtxattr
);
491 typedef void (*pfn_push
)(struct nouveau_channel
*, void *);
493 struct nv50_vbo_emitctx
503 unsigned ve_edgeflag
;
507 emit_vtx_next(struct nouveau_channel
*chan
, struct nv50_vbo_emitctx
*emit
)
511 for (i
= 0; i
< emit
->nr_ve
; ++i
) {
512 emit
->push
[i
](chan
, emit
->map
[i
]);
513 emit
->map
[i
] += emit
->stride
[i
];
518 emit_vtx(struct nouveau_channel
*chan
, struct nv50_vbo_emitctx
*emit
,
523 for (i
= 0; i
< emit
->nr_ve
; ++i
)
524 emit
->push
[i
](chan
, emit
->map
[i
] + emit
->stride
[i
] * vi
);
527 static INLINE boolean
528 nv50_map_vbufs(struct nv50_context
*nv50
)
532 for (i
= 0; i
< nv50
->vtxbuf_nr
; ++i
) {
533 struct pipe_vertex_buffer
*vb
= &nv50
->vtxbuf
[i
];
534 unsigned size
, delta
;
536 if (nouveau_bo(vb
->buffer
)->map
)
539 size
= vb
->stride
* (vb
->max_index
+ 1);
540 delta
= vb
->buffer_offset
;
543 size
= vb
->buffer
->size
- vb
->buffer_offset
;
545 if (nouveau_bo_map_range(nouveau_bo(vb
->buffer
),
546 delta
, size
, NOUVEAU_BO_RD
))
550 if (i
== nv50
->vtxbuf_nr
)
553 nouveau_bo_unmap(nouveau_bo(nv50
->vtxbuf
[i
].buffer
));
558 nv50_unmap_vbufs(struct nv50_context
*nv50
)
562 for (i
= 0; i
< nv50
->vtxbuf_nr
; ++i
)
563 if (nouveau_bo(nv50
->vtxbuf
[i
].buffer
)->map
)
564 nouveau_bo_unmap(nouveau_bo(nv50
->vtxbuf
[i
].buffer
));
568 emit_b32_1(struct nouveau_channel
*chan
, void *data
)
572 OUT_RING(chan
, v
[0]);
576 emit_b32_2(struct nouveau_channel
*chan
, void *data
)
580 OUT_RING(chan
, v
[0]);
581 OUT_RING(chan
, v
[1]);
585 emit_b32_3(struct nouveau_channel
*chan
, void *data
)
589 OUT_RING(chan
, v
[0]);
590 OUT_RING(chan
, v
[1]);
591 OUT_RING(chan
, v
[2]);
595 emit_b32_4(struct nouveau_channel
*chan
, void *data
)
599 OUT_RING(chan
, v
[0]);
600 OUT_RING(chan
, v
[1]);
601 OUT_RING(chan
, v
[2]);
602 OUT_RING(chan
, v
[3]);
606 emit_b16_1(struct nouveau_channel
*chan
, void *data
)
610 OUT_RING(chan
, v
[0]);
614 emit_b16_3(struct nouveau_channel
*chan
, void *data
)
618 OUT_RING(chan
, (v
[1] << 16) | v
[0]);
619 OUT_RING(chan
, v
[2]);
623 emit_b08_1(struct nouveau_channel
*chan
, void *data
)
627 OUT_RING(chan
, v
[0]);
631 emit_b08_3(struct nouveau_channel
*chan
, void *data
)
635 OUT_RING(chan
, (v
[2] << 16) | (v
[1] << 8) | v
[0]);
639 emit_prepare(struct nv50_context
*nv50
, struct nv50_vbo_emitctx
*emit
,
644 if (nv50_map_vbufs(nv50
) == FALSE
)
647 emit
->ve_edgeflag
= nv50
->vertprog
->cfg
.edgeflag_in
;
649 emit
->edgeflag
= 0.5f
;
651 emit
->vtx_dwords
= 0;
653 for (i
= 0; i
< nv50
->vtxelt_nr
; ++i
) {
654 struct pipe_vertex_element
*ve
;
655 struct pipe_vertex_buffer
*vb
;
657 const struct util_format_description
*desc
;
659 ve
= &nv50
->vtxelt
[i
];
660 vb
= &nv50
->vtxbuf
[ve
->vertex_buffer_index
];
661 if (!(nv50
->vbo_fifo
& (1 << i
)))
665 emit
->stride
[n
] = vb
->stride
;
666 emit
->map
[n
] = nouveau_bo(vb
->buffer
)->map
+
667 (start
* vb
->stride
+ ve
->src_offset
);
669 desc
= util_format_description(ve
->src_format
);
672 size
= util_format_get_component_bits(
673 ve
->src_format
, UTIL_FORMAT_COLORSPACE_RGB
, 0);
675 assert(ve
->nr_components
> 0 && ve
->nr_components
<= 4);
677 /* It shouldn't be necessary to push the implicit 1s
678 * for case 3 and size 8 cases 1, 2, 3.
682 NOUVEAU_ERR("unsupported vtxelt size: %u\n", size
);
685 switch (ve
->nr_components
) {
686 case 1: emit
->push
[n
] = emit_b32_1
; break;
687 case 2: emit
->push
[n
] = emit_b32_2
; break;
688 case 3: emit
->push
[n
] = emit_b32_3
; break;
689 case 4: emit
->push
[n
] = emit_b32_4
; break;
691 emit
->vtx_dwords
+= ve
->nr_components
;
694 switch (ve
->nr_components
) {
695 case 1: emit
->push
[n
] = emit_b16_1
; break;
696 case 2: emit
->push
[n
] = emit_b32_1
; break;
697 case 3: emit
->push
[n
] = emit_b16_3
; break;
698 case 4: emit
->push
[n
] = emit_b32_2
; break;
700 emit
->vtx_dwords
+= (ve
->nr_components
+ 1) >> 1;
703 switch (ve
->nr_components
) {
704 case 1: emit
->push
[n
] = emit_b08_1
; break;
705 case 2: emit
->push
[n
] = emit_b16_1
; break;
706 case 3: emit
->push
[n
] = emit_b08_3
; break;
707 case 4: emit
->push
[n
] = emit_b32_1
; break;
709 emit
->vtx_dwords
+= 1;
714 emit
->vtx_max
= 512 / emit
->vtx_dwords
;
715 if (emit
->ve_edgeflag
< 16)
722 set_edgeflag(struct nouveau_channel
*chan
,
723 struct nouveau_grobj
*tesla
,
724 struct nv50_vbo_emitctx
*emit
, uint32_t index
)
726 unsigned i
= emit
->ve_edgeflag
;
729 float f
= *((float *)(emit
->map
[i
] + index
* emit
->stride
[i
]));
731 if (emit
->edgeflag
!= f
) {
734 BEGIN_RING(chan
, tesla
, 0x15e4, 1);
735 OUT_RING (chan
, f
? 1 : 0);
741 nv50_push_arrays(struct nv50_context
*nv50
, unsigned start
, unsigned count
)
743 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
744 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
745 struct nv50_vbo_emitctx emit
;
747 if (emit_prepare(nv50
, &emit
, start
) == FALSE
)
751 unsigned i
, dw
, nr
= MIN2(count
, emit
.vtx_max
);
752 dw
= nr
* emit
.vtx_dwords
;
754 set_edgeflag(chan
, tesla
, &emit
, 0); /* nr will be 1 */
756 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_DATA
| 0x40000000, dw
);
757 for (i
= 0; i
< nr
; ++i
)
758 emit_vtx_next(chan
, &emit
);
762 nv50_unmap_vbufs(nv50
);
768 nv50_push_elements_u32(struct nv50_context
*nv50
, uint32_t *map
, unsigned count
)
770 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
771 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
772 struct nv50_vbo_emitctx emit
;
774 if (emit_prepare(nv50
, &emit
, 0) == FALSE
)
778 unsigned i
, dw
, nr
= MIN2(count
, emit
.vtx_max
);
779 dw
= nr
* emit
.vtx_dwords
;
781 set_edgeflag(chan
, tesla
, &emit
, *map
);
783 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_DATA
| 0x40000000, dw
);
784 for (i
= 0; i
< nr
; ++i
)
785 emit_vtx(chan
, &emit
, *map
++);
789 nv50_unmap_vbufs(nv50
);
795 nv50_push_elements_u16(struct nv50_context
*nv50
, uint16_t *map
, unsigned count
)
797 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
798 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
799 struct nv50_vbo_emitctx emit
;
801 if (emit_prepare(nv50
, &emit
, 0) == FALSE
)
805 unsigned i
, dw
, nr
= MIN2(count
, emit
.vtx_max
);
806 dw
= nr
* emit
.vtx_dwords
;
808 set_edgeflag(chan
, tesla
, &emit
, *map
);
810 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_DATA
| 0x40000000, dw
);
811 for (i
= 0; i
< nr
; ++i
)
812 emit_vtx(chan
, &emit
, *map
++);
816 nv50_unmap_vbufs(nv50
);
822 nv50_push_elements_u08(struct nv50_context
*nv50
, uint8_t *map
, unsigned count
)
824 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
825 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
826 struct nv50_vbo_emitctx emit
;
828 if (emit_prepare(nv50
, &emit
, 0) == FALSE
)
832 unsigned i
, dw
, nr
= MIN2(count
, emit
.vtx_max
);
833 dw
= nr
* emit
.vtx_dwords
;
835 set_edgeflag(chan
, tesla
, &emit
, *map
);
837 BEGIN_RING(chan
, tesla
, NV50TCL_VERTEX_DATA
| 0x40000000, dw
);
838 for (i
= 0; i
< nr
; ++i
)
839 emit_vtx(chan
, &emit
, *map
++);
843 nv50_unmap_vbufs(nv50
);