2 * Copyright 2010 Christoph Bumiller
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 "util/u_inlines.h"
26 #include "util/u_format.h"
27 #include "translate/translate.h"
29 #include "nv50_context.h"
30 #include "nv50_resource.h"
32 #include "nv50_3d.xml.h"
35 nv50_vertex_state_delete(struct pipe_context
*pipe
,
38 struct nv50_vertex_stateobj
*so
= hwcso
;
41 so
->translate
->release(so
->translate
);
46 nv50_vertex_state_create(struct pipe_context
*pipe
,
47 unsigned num_elements
,
48 const struct pipe_vertex_element
*elements
)
50 struct nv50_vertex_stateobj
*so
;
51 struct translate_key transkey
;
54 so
= MALLOC(sizeof(*so
) +
55 num_elements
* sizeof(struct nv50_vertex_element
));
58 so
->num_elements
= num_elements
;
59 so
->instance_elts
= 0;
60 so
->instance_bufs
= 0;
61 so
->need_conversion
= FALSE
;
63 transkey
.nr_elements
= 0;
64 transkey
.output_stride
= 0;
66 for (i
= 0; i
< num_elements
; ++i
) {
67 const struct pipe_vertex_element
*ve
= &elements
[i
];
68 const unsigned vbi
= ve
->vertex_buffer_index
;
69 enum pipe_format fmt
= ve
->src_format
;
71 so
->element
[i
].pipe
= elements
[i
];
72 so
->element
[i
].state
= nv50_format_table
[fmt
].vtx
;
74 if (!so
->element
[i
].state
) {
75 switch (util_format_get_nr_components(fmt
)) {
76 case 1: fmt
= PIPE_FORMAT_R32_FLOAT
; break;
77 case 2: fmt
= PIPE_FORMAT_R32G32_FLOAT
; break;
78 case 3: fmt
= PIPE_FORMAT_R32G32B32_FLOAT
; break;
79 case 4: fmt
= PIPE_FORMAT_R32G32B32A32_FLOAT
; break;
84 so
->element
[i
].state
= nv50_format_table
[fmt
].vtx
;
85 so
->need_conversion
= TRUE
;
87 so
->element
[i
].state
|= i
;
90 unsigned j
= transkey
.nr_elements
++;
92 transkey
.element
[j
].type
= TRANSLATE_ELEMENT_NORMAL
;
93 transkey
.element
[j
].input_format
= ve
->src_format
;
94 transkey
.element
[j
].input_buffer
= vbi
;
95 transkey
.element
[j
].input_offset
= ve
->src_offset
;
96 transkey
.element
[j
].instance_divisor
= ve
->instance_divisor
;
98 transkey
.element
[j
].output_format
= fmt
;
99 transkey
.element
[j
].output_offset
= transkey
.output_stride
;
100 transkey
.output_stride
+= (util_format_get_stride(fmt
, 1) + 3) & ~3;
102 if (unlikely(ve
->instance_divisor
)) {
103 so
->instance_elts
|= 1 << i
;
104 so
->instance_bufs
|= 1 << vbi
;
109 so
->translate
= translate_create(&transkey
);
110 so
->vertex_size
= transkey
.output_stride
/ 4;
111 so
->packet_vertex_limit
= NV04_PFIFO_MAX_PACKET_LEN
/
112 MAX2(so
->vertex_size
, 1);
117 #define NV50_3D_VERTEX_ATTRIB_INACTIVE \
118 NV50_3D_VERTEX_ARRAY_ATTRIB_TYPE_FLOAT | \
119 NV50_3D_VERTEX_ARRAY_ATTRIB_FORMAT_32_32_32_32 | \
120 NV50_3D_VERTEX_ARRAY_ATTRIB_CONST
123 nv50_emit_vtxattr(struct nv50_context
*nv50
, struct pipe_vertex_buffer
*vb
,
124 struct pipe_vertex_element
*ve
, unsigned attr
)
127 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
128 struct nv04_resource
*res
= nv04_resource(vb
->buffer
);
130 const unsigned nc
= util_format_get_nr_components(ve
->src_format
);
132 data
= nouveau_resource_map_offset(&nv50
->base
, res
, vb
->buffer_offset
+
133 ve
->src_offset
, NOUVEAU_BO_RD
);
135 util_format_read_4f(ve
->src_format
, v
, 0, data
, 0, 0, 0, 1, 1);
139 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_4F_X(attr
)), 4);
140 PUSH_DATAf(push
, v
[0]);
141 PUSH_DATAf(push
, v
[1]);
142 PUSH_DATAf(push
, v
[2]);
143 PUSH_DATAf(push
, v
[3]);
146 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_3F_X(attr
)), 3);
147 PUSH_DATAf(push
, v
[0]);
148 PUSH_DATAf(push
, v
[1]);
149 PUSH_DATAf(push
, v
[2]);
152 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_2F_X(attr
)), 2);
153 PUSH_DATAf(push
, v
[0]);
154 PUSH_DATAf(push
, v
[1]);
157 if (attr
== nv50
->vertprog
->vp
.edgeflag
) {
158 BEGIN_NV04(push
, NV50_3D(EDGEFLAG
), 1);
159 PUSH_DATA (push
, v
[0] ? 1 : 0);
161 BEGIN_NV04(push
, NV50_3D(VTX_ATTR_1F(attr
)), 1);
162 PUSH_DATAf(push
, v
[0]);
171 nv50_vbuf_range(struct nv50_context
*nv50
, int vbi
,
172 uint32_t *base
, uint32_t *size
)
174 if (unlikely(nv50
->vertex
->instance_bufs
& (1 << vbi
))) {
175 /* TODO: use min and max instance divisor to get a proper range */
177 *size
= nv50
->vtxbuf
[vbi
].buffer
->width0
;
179 assert(nv50
->vbo_max_index
!= ~0);
180 *base
= nv50
->vbo_min_index
* nv50
->vtxbuf
[vbi
].stride
;
181 *size
= (nv50
->vbo_max_index
-
182 nv50
->vbo_min_index
+ 1) * nv50
->vtxbuf
[vbi
].stride
;
187 nv50_prevalidate_vbufs(struct nv50_context
*nv50
)
189 struct pipe_vertex_buffer
*vb
;
190 struct nv04_resource
*buf
;
194 nv50
->vbo_fifo
= nv50
->vbo_user
= 0;
196 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_VERTEX
);
198 for (i
= 0; i
< nv50
->num_vtxbufs
; ++i
) {
199 vb
= &nv50
->vtxbuf
[i
];
202 buf
= nv04_resource(vb
->buffer
);
204 /* NOTE: user buffers with temporary storage count as mapped by GPU */
205 if (!nouveau_resource_mapped_by_gpu(vb
->buffer
)) {
206 if (nv50
->vbo_push_hint
) {
210 if (buf
->status
& NOUVEAU_BUFFER_STATUS_USER_MEMORY
) {
211 nv50
->vbo_user
|= 1 << i
;
212 assert(vb
->stride
> vb
->buffer_offset
);
213 nv50_vbuf_range(nv50
, i
, &base
, &size
);
214 nouveau_user_buffer_upload(&nv50
->base
, buf
, base
, size
);
216 nouveau_buffer_migrate(&nv50
->base
, buf
, NOUVEAU_BO_GART
);
218 nv50
->base
.vbo_dirty
= TRUE
;
221 BCTX_REFN(nv50
->bufctx_3d
, VERTEX
, buf
, RD
);
226 nv50_update_user_vbufs(struct nv50_context
*nv50
)
228 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
229 uint32_t base
, offset
, size
;
231 uint32_t written
= 0;
233 nouveau_bufctx_reset(nv50
->bufctx_3d
, NV50_BIND_VERTEX
);
235 for (i
= 0; i
< nv50
->vertex
->num_elements
; ++i
) {
236 struct pipe_vertex_element
*ve
= &nv50
->vertex
->element
[i
].pipe
;
237 const int b
= ve
->vertex_buffer_index
;
238 struct pipe_vertex_buffer
*vb
= &nv50
->vtxbuf
[b
];
239 struct nv04_resource
*buf
= nv04_resource(vb
->buffer
);
241 if (!(nv50
->vbo_user
& (1 << b
))) {
242 BCTX_REFN(nv50
->bufctx_3d
, VERTEX
, buf
, RD
);
247 nv50_emit_vtxattr(nv50
, vb
, ve
, i
);
250 nv50_vbuf_range(nv50
, b
, &base
, &size
);
252 if (!(written
& (1 << b
))) {
254 nouveau_user_buffer_upload(&nv50
->base
, buf
, base
, size
);
256 offset
= vb
->buffer_offset
+ ve
->src_offset
;
258 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_LIMIT_HIGH(i
)), 2);
259 PUSH_DATAh(push
, buf
->address
+ base
+ size
- 1);
260 PUSH_DATA (push
, buf
->address
+ base
+ size
- 1);
261 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_START_HIGH(i
)), 2);
262 PUSH_DATAh(push
, buf
->address
+ offset
);
263 PUSH_DATA (push
, buf
->address
+ offset
);
265 BCTX_REFN(nv50
->bufctx_3d
, VERTEX
, buf
, RD
);
267 nv50
->base
.vbo_dirty
= TRUE
;
271 nv50_release_user_vbufs(struct nv50_context
*nv50
)
273 uint32_t vbo_user
= nv50
->vbo_user
;
276 int i
= ffs(vbo_user
) - 1;
277 vbo_user
&= ~(1 << i
);
279 nouveau_buffer_release_gpu_storage(nv04_resource(nv50
->vtxbuf
[i
].buffer
));
284 nv50_vertex_arrays_validate(struct nv50_context
*nv50
)
286 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
287 struct nv50_vertex_stateobj
*vertex
= nv50
->vertex
;
288 struct pipe_vertex_buffer
*vb
;
289 struct nv50_vertex_element
*ve
;
292 if (unlikely(vertex
->need_conversion
)) {
296 nv50_prevalidate_vbufs(nv50
);
299 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_ATTRIB(0)), vertex
->num_elements
);
300 for (i
= 0; i
< vertex
->num_elements
; ++i
) {
301 ve
= &vertex
->element
[i
];
302 vb
= &nv50
->vtxbuf
[ve
->pipe
.vertex_buffer_index
];
304 if (likely(vb
->stride
) || nv50
->vbo_fifo
) {
305 PUSH_DATA(push
, ve
->state
);
307 PUSH_DATA(push
, ve
->state
| NV50_3D_VERTEX_ARRAY_ATTRIB_CONST
);
308 nv50
->vbo_fifo
&= ~(1 << i
);
312 for (i
= 0; i
< vertex
->num_elements
; ++i
) {
313 struct nv04_resource
*res
;
314 unsigned size
, offset
;
316 ve
= &vertex
->element
[i
];
317 vb
= &nv50
->vtxbuf
[ve
->pipe
.vertex_buffer_index
];
319 if (unlikely(ve
->pipe
.instance_divisor
)) {
320 if (!(nv50
->state
.instance_elts
& (1 << i
))) {
321 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_PER_INSTANCE(i
)), 1);
324 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_DIVISOR(i
)), 1);
325 PUSH_DATA (push
, ve
->pipe
.instance_divisor
);
327 if (unlikely(nv50
->state
.instance_elts
& (1 << i
))) {
328 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_PER_INSTANCE(i
)), 1);
332 res
= nv04_resource(vb
->buffer
);
334 if (nv50
->vbo_fifo
|| unlikely(vb
->stride
== 0)) {
336 nv50_emit_vtxattr(nv50
, vb
, &ve
->pipe
, i
);
337 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_FETCH(i
)), 1);
342 size
= vb
->buffer
->width0
;
343 offset
= ve
->pipe
.src_offset
+ vb
->buffer_offset
;
345 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_FETCH(i
)), 1);
346 PUSH_DATA (push
, NV50_3D_VERTEX_ARRAY_FETCH_ENABLE
| vb
->stride
);
347 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_LIMIT_HIGH(i
)), 2);
348 PUSH_DATAh(push
, res
->address
+ size
- 1);
349 PUSH_DATA (push
, res
->address
+ size
- 1);
350 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_START_HIGH(i
)), 2);
351 PUSH_DATAh(push
, res
->address
+ offset
);
352 PUSH_DATA (push
, res
->address
+ offset
);
354 for (; i
< nv50
->state
.num_vtxelts
; ++i
) {
355 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_ATTRIB(i
)), 1);
356 PUSH_DATA (push
, NV50_3D_VERTEX_ATTRIB_INACTIVE
);
357 if (unlikely(nv50
->state
.instance_elts
& (1 << i
))) {
358 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_PER_INSTANCE(i
)), 1);
361 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_FETCH(i
)), 1);
365 nv50
->state
.num_vtxelts
= vertex
->num_elements
;
366 nv50
->state
.instance_elts
= vertex
->instance_elts
;
369 #define NV50_PRIM_GL_CASE(n) \
370 case PIPE_PRIM_##n: return NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_##n
372 static INLINE
unsigned
373 nv50_prim_gl(unsigned prim
)
376 NV50_PRIM_GL_CASE(POINTS
);
377 NV50_PRIM_GL_CASE(LINES
);
378 NV50_PRIM_GL_CASE(LINE_LOOP
);
379 NV50_PRIM_GL_CASE(LINE_STRIP
);
380 NV50_PRIM_GL_CASE(TRIANGLES
);
381 NV50_PRIM_GL_CASE(TRIANGLE_STRIP
);
382 NV50_PRIM_GL_CASE(TRIANGLE_FAN
);
383 NV50_PRIM_GL_CASE(QUADS
);
384 NV50_PRIM_GL_CASE(QUAD_STRIP
);
385 NV50_PRIM_GL_CASE(POLYGON
);
386 NV50_PRIM_GL_CASE(LINES_ADJACENCY
);
387 NV50_PRIM_GL_CASE(LINE_STRIP_ADJACENCY
);
388 NV50_PRIM_GL_CASE(TRIANGLES_ADJACENCY
);
389 NV50_PRIM_GL_CASE(TRIANGLE_STRIP_ADJACENCY
);
391 return NV50_3D_VERTEX_BEGIN_GL_PRIMITIVE_POINTS
;
397 nv50_draw_arrays(struct nv50_context
*nv50
,
398 unsigned mode
, unsigned start
, unsigned count
,
399 unsigned instance_count
)
401 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
404 if (nv50
->state
.index_bias
) {
405 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_BASE
), 1);
407 nv50
->state
.index_bias
= 0;
410 prim
= nv50_prim_gl(mode
);
412 while (instance_count
--) {
413 BEGIN_NV04(push
, NV50_3D(VERTEX_BEGIN_GL
), 1);
414 PUSH_DATA (push
, prim
);
415 BEGIN_NV04(push
, NV50_3D(VERTEX_BUFFER_FIRST
), 2);
416 PUSH_DATA (push
, start
);
417 PUSH_DATA (push
, count
);
418 BEGIN_NV04(push
, NV50_3D(VERTEX_END_GL
), 1);
421 prim
|= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
426 nv50_draw_elements_inline_u08(struct nouveau_pushbuf
*push
, uint8_t *map
,
427 unsigned start
, unsigned count
)
433 BEGIN_NI04(push
, NV50_3D(VB_ELEMENT_U32
), count
& 3);
434 for (i
= 0; i
< (count
& 3); ++i
)
435 PUSH_DATA(push
, *map
++);
439 unsigned i
, nr
= MIN2(count
, NV04_PFIFO_MAX_PACKET_LEN
* 4) / 4;
441 BEGIN_NI04(push
, NV50_3D(VB_ELEMENT_U8
), nr
);
442 for (i
= 0; i
< nr
; ++i
) {
444 (map
[3] << 24) | (map
[2] << 16) | (map
[1] << 8) | map
[0]);
452 nv50_draw_elements_inline_u16(struct nouveau_pushbuf
*push
, uint16_t *map
,
453 unsigned start
, unsigned count
)
459 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U32
), 1);
460 PUSH_DATA (push
, *map
++);
463 unsigned i
, nr
= MIN2(count
, NV04_PFIFO_MAX_PACKET_LEN
* 2) / 2;
465 BEGIN_NI04(push
, NV50_3D(VB_ELEMENT_U16
), nr
);
466 for (i
= 0; i
< nr
; ++i
) {
467 PUSH_DATA(push
, (map
[1] << 16) | map
[0]);
475 nv50_draw_elements_inline_u32(struct nouveau_pushbuf
*push
, uint32_t *map
,
476 unsigned start
, unsigned count
)
481 const unsigned nr
= MIN2(count
, NV04_PFIFO_MAX_PACKET_LEN
);
483 BEGIN_NI04(push
, NV50_3D(VB_ELEMENT_U32
), nr
);
484 PUSH_DATAp(push
, map
, nr
);
492 nv50_draw_elements_inline_u32_short(struct nouveau_pushbuf
*push
, uint32_t *map
,
493 unsigned start
, unsigned count
)
499 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U32
), 1);
500 PUSH_DATA (push
, *map
++);
503 unsigned i
, nr
= MIN2(count
, NV04_PFIFO_MAX_PACKET_LEN
* 2) / 2;
505 BEGIN_NI04(push
, NV50_3D(VB_ELEMENT_U16
), nr
);
506 for (i
= 0; i
< nr
; ++i
) {
507 PUSH_DATA(push
, (map
[1] << 16) | map
[0]);
515 nv50_draw_elements(struct nv50_context
*nv50
, boolean shorten
,
516 unsigned mode
, unsigned start
, unsigned count
,
517 unsigned instance_count
, int32_t index_bias
)
519 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
521 struct nv04_resource
*buf
= nv04_resource(nv50
->idxbuf
.buffer
);
523 const unsigned index_size
= nv50
->idxbuf
.index_size
;
525 prim
= nv50_prim_gl(mode
);
527 if (index_bias
!= nv50
->state
.index_bias
) {
528 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_BASE
), 1);
529 PUSH_DATA (push
, index_bias
);
530 nv50
->state
.index_bias
= index_bias
;
533 if (nouveau_resource_mapped_by_gpu(nv50
->idxbuf
.buffer
)) {
536 const unsigned base
= buf
->offset
;
538 start
+= nv50
->idxbuf
.offset
>> (index_size
>> 1);
540 while (instance_count
--) {
541 BEGIN_NV04(push
, NV50_3D(VERTEX_BEGIN_GL
), 1);
542 PUSH_DATA (push
, prim
);
544 nouveau_pushbuf_space(push
, 8, 0, 1);
546 switch (index_size
) {
548 BEGIN_NL50(push
, NV50_3D(VB_ELEMENT_U32
), count
);
549 nouveau_pushbuf_data(push
, buf
->bo
, base
+ start
* 4, count
* 4);
552 pb_start
= (start
& ~1) * 2;
553 pb_bytes
= ((start
+ count
+ 1) & ~1) * 2 - pb_start
;
555 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U16_SETUP
), 1);
556 PUSH_DATA (push
, (start
<< 31) | count
);
557 BEGIN_NL50(push
, NV50_3D(VB_ELEMENT_U16
), pb_bytes
/ 4);
558 nouveau_pushbuf_data(push
, buf
->bo
, base
+ pb_start
, pb_bytes
);
559 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U16_SETUP
), 1);
563 assert(index_size
== 1);
564 pb_start
= start
& ~3;
565 pb_bytes
= ((start
+ count
+ 3) & ~3) - pb_start
;
567 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U8_SETUP
), 1);
568 PUSH_DATA (push
, (start
<< 30) | count
);
569 BEGIN_NL50(push
, NV50_3D(VB_ELEMENT_U8
), pb_bytes
/ 4);
570 nouveau_pushbuf_data(push
, buf
->bo
, base
+ pb_start
, pb_bytes
);
571 BEGIN_NV04(push
, NV50_3D(VB_ELEMENT_U8_SETUP
), 1);
575 BEGIN_NV04(push
, NV50_3D(VERTEX_END_GL
), 1);
578 prim
|= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
581 data
= nouveau_resource_map_offset(&nv50
->base
, buf
,
582 nv50
->idxbuf
.offset
, NOUVEAU_BO_RD
);
586 while (instance_count
--) {
587 BEGIN_NV04(push
, NV50_3D(VERTEX_BEGIN_GL
), 1);
588 PUSH_DATA (push
, prim
);
589 switch (index_size
) {
591 nv50_draw_elements_inline_u08(push
, data
, start
, count
);
594 nv50_draw_elements_inline_u16(push
, data
, start
, count
);
598 nv50_draw_elements_inline_u32_short(push
, data
, start
, count
);
600 nv50_draw_elements_inline_u32(push
, data
, start
, count
);
606 BEGIN_NV04(push
, NV50_3D(VERTEX_END_GL
), 1);
609 prim
|= NV50_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT
;
615 nv50_draw_vbo_kick_notify(struct nouveau_pushbuf
*chan
)
617 struct nv50_screen
*screen
= chan
->user_priv
;
619 nouveau_fence_update(&screen
->base
, TRUE
);
621 nv50_bufctx_fence(screen
->cur_ctx
->bufctx_3d
, TRUE
);
625 nv50_draw_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
)
627 struct nv50_context
*nv50
= nv50_context(pipe
);
628 struct nouveau_pushbuf
*push
= nv50
->base
.pushbuf
;
630 /* For picking only a few vertices from a large user buffer, push is better,
631 * if index count is larger and we expect repeated vertices, suggest upload.
633 nv50
->vbo_push_hint
= /* the 64 is heuristic */
635 ((info
->max_index
- info
->min_index
+ 64) < info
->count
));
637 nv50
->vbo_min_index
= info
->min_index
;
638 nv50
->vbo_max_index
= info
->max_index
;
640 if (nv50
->vbo_push_hint
!= !!nv50
->vbo_fifo
)
641 nv50
->dirty
|= NV50_NEW_ARRAYS
;
643 if (nv50
->vbo_user
&& !(nv50
->dirty
& (NV50_NEW_VERTEX
| NV50_NEW_ARRAYS
)))
644 nv50_update_user_vbufs(nv50
);
646 nv50_state_validate(nv50
, ~0, 8); /* 8 as minimum, we use flush_notify */
648 push
->kick_notify
= nv50_draw_vbo_kick_notify
;
650 if (nv50
->vbo_fifo
) {
651 nv50_push_vbo(nv50
, info
);
652 push
->kick_notify
= nv50_default_kick_notify
;
653 nouveau_pushbuf_bufctx(push
, NULL
);
657 if (nv50
->state
.instance_base
!= info
->start_instance
) {
658 nv50
->state
.instance_base
= info
->start_instance
;
659 /* NOTE: this does not affect the shader input, should it ? */
660 BEGIN_NV04(push
, NV50_3D(VB_INSTANCE_BASE
), 1);
661 PUSH_DATA (push
, info
->start_instance
);
664 if (nv50
->base
.vbo_dirty
) {
665 BEGIN_NV04(push
, NV50_3D(VERTEX_ARRAY_FLUSH
), 1);
667 nv50
->base
.vbo_dirty
= FALSE
;
670 if (!info
->indexed
) {
671 nv50_draw_arrays(nv50
,
672 info
->mode
, info
->start
, info
->count
,
673 info
->instance_count
);
675 boolean shorten
= info
->max_index
<= 65535;
677 assert(nv50
->idxbuf
.buffer
);
679 if (info
->primitive_restart
!= nv50
->state
.prim_restart
) {
680 if (info
->primitive_restart
) {
681 BEGIN_NV04(push
, NV50_3D(PRIM_RESTART_ENABLE
), 2);
683 PUSH_DATA (push
, info
->restart_index
);
685 if (info
->restart_index
> 65535)
688 BEGIN_NV04(push
, NV50_3D(PRIM_RESTART_ENABLE
), 1);
691 nv50
->state
.prim_restart
= info
->primitive_restart
;
693 if (info
->primitive_restart
) {
694 BEGIN_NV04(push
, NV50_3D(PRIM_RESTART_INDEX
), 1);
695 PUSH_DATA (push
, info
->restart_index
);
697 if (info
->restart_index
> 65535)
701 nv50_draw_elements(nv50
, shorten
,
702 info
->mode
, info
->start
, info
->count
,
703 info
->instance_count
, info
->index_bias
);
705 push
->kick_notify
= nv50_default_kick_notify
;
707 nv50_release_user_vbufs(nv50
);
709 nouveau_pushbuf_bufctx(push
, NULL
);