2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 /* r300_render: Vertex and index buffer primitive emission. Contains both
24 * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */
26 #include "draw/draw_context.h"
27 #include "draw/draw_vbuf.h"
29 #include "util/u_inlines.h"
31 #include "util/u_format.h"
32 #include "util/u_memory.h"
33 #include "util/u_upload_mgr.h"
34 #include "util/u_prim.h"
37 #include "r300_context.h"
38 #include "r300_screen_buffer.h"
39 #include "r300_emit.h"
41 #include "r300_render.h"
42 #include "r300_state_derived.h"
44 /* r300_render: Vertex and index buffer primitive emission. */
45 #define R300_MAX_VBO_SIZE (1024 * 1024)
47 /* XXX The DRM rejects VAP_ALT_NUM_VERTICES.. */
48 //#define ENABLE_ALT_NUM_VERTS
50 uint32_t r300_translate_primitive(unsigned prim
)
53 case PIPE_PRIM_POINTS
:
54 return R300_VAP_VF_CNTL__PRIM_POINTS
;
56 return R300_VAP_VF_CNTL__PRIM_LINES
;
57 case PIPE_PRIM_LINE_LOOP
:
58 return R300_VAP_VF_CNTL__PRIM_LINE_LOOP
;
59 case PIPE_PRIM_LINE_STRIP
:
60 return R300_VAP_VF_CNTL__PRIM_LINE_STRIP
;
61 case PIPE_PRIM_TRIANGLES
:
62 return R300_VAP_VF_CNTL__PRIM_TRIANGLES
;
63 case PIPE_PRIM_TRIANGLE_STRIP
:
64 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP
;
65 case PIPE_PRIM_TRIANGLE_FAN
:
66 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN
;
68 return R300_VAP_VF_CNTL__PRIM_QUADS
;
69 case PIPE_PRIM_QUAD_STRIP
:
70 return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP
;
71 case PIPE_PRIM_POLYGON
:
72 return R300_VAP_VF_CNTL__PRIM_POLYGON
;
78 static uint32_t r300_provoking_vertex_fixes(struct r300_context
*r300
,
81 struct r300_rs_state
* rs
= (struct r300_rs_state
*)r300
->rs_state
.state
;
82 uint32_t color_control
= rs
->color_control
;
84 /* By default (see r300_state.c:r300_create_rs_state) color_control is
85 * initialized to provoking the first vertex.
87 * Triangle fans must be reduced to the second vertex, not the first, in
88 * Gallium flatshade-first mode, as per the GL spec.
89 * (http://www.opengl.org/registry/specs/ARB/provoking_vertex.txt)
91 * Quads never provoke correctly in flatshade-first mode. The first
92 * vertex is never considered as provoking, so only the second, third,
93 * and fourth vertices can be selected, and both "third" and "last" modes
94 * select the fourth vertex. This is probably due to D3D lacking quads.
96 * Similarly, polygons reduce to the first, not the last, vertex, when in
97 * "last" mode, and all other modes start from the second vertex.
102 if (rs
->rs
.flatshade_first
) {
104 case PIPE_PRIM_TRIANGLE_FAN
:
105 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND
;
107 case PIPE_PRIM_QUADS
:
108 case PIPE_PRIM_QUAD_STRIP
:
109 case PIPE_PRIM_POLYGON
:
110 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST
;
113 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST
;
117 color_control
|= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST
;
120 return color_control
;
123 /* Check if the requested number of dwords is available in the CS and
124 * if not, flush. Return TRUE if the flush occured. */
125 static boolean
r300_reserve_cs_space(struct r300_context
*r300
,
128 if (!r300
->rws
->check_cs(r300
->rws
, dwords
)) {
129 r300
->context
.flush(&r300
->context
, 0, NULL
);
135 static boolean
immd_is_good_idea(struct r300_context
*r300
,
138 struct pipe_vertex_element
* velem
;
139 struct pipe_vertex_buffer
* vbuf
;
140 boolean checked
[PIPE_MAX_ATTRIBS
] = {0};
141 unsigned vertex_element_count
= r300
->velems
->count
;
148 /* We shouldn't map buffers referenced by CS, busy buffers,
149 * and ones placed in VRAM. */
150 /* XXX Check for VRAM buffers. */
151 for (i
= 0; i
< vertex_element_count
; i
++) {
152 velem
= &r300
->velems
->velem
[i
];
153 vbi
= velem
->vertex_buffer_index
;
156 vbuf
= &r300
->vertex_buffer
[vbi
];
158 if (r300_buffer_is_referenced(r300
, vbuf
->buffer
)) {
159 /* It's a very bad idea to map it... */
168 static void r300_emit_draw_arrays_immediate(struct r300_context
*r300
,
173 struct pipe_vertex_element
* velem
;
174 struct pipe_vertex_buffer
* vbuf
;
175 unsigned vertex_element_count
= r300
->velems
->count
;
176 unsigned i
, v
, vbi
, dw
, elem_offset
, dwords
;
178 /* Size of the vertex, in dwords. */
179 unsigned vertex_size
= 0;
181 /* Offsets of the attribute, in dwords, from the start of the vertex. */
182 unsigned offset
[PIPE_MAX_ATTRIBS
];
184 /* Size of the vertex element, in dwords. */
185 unsigned size
[PIPE_MAX_ATTRIBS
];
187 /* Stride to the same attrib in the next vertex in the vertex buffer,
189 unsigned stride
[PIPE_MAX_ATTRIBS
] = {0};
191 /* Mapped vertex buffers. */
192 uint32_t* map
[PIPE_MAX_ATTRIBS
] = {0};
196 /* Calculate the vertex size, offsets, strides etc. and map the buffers. */
197 for (i
= 0; i
< vertex_element_count
; i
++) {
198 velem
= &r300
->velems
->velem
[i
];
199 offset
[i
] = velem
->src_offset
/ 4;
200 size
[i
] = util_format_get_blocksize(velem
->src_format
) / 4;
201 vertex_size
+= size
[i
];
202 vbi
= velem
->vertex_buffer_index
;
204 /* Map the buffer. */
206 vbuf
= &r300
->vertex_buffer
[vbi
];
207 map
[vbi
] = (uint32_t*)pipe_buffer_map(r300
->context
.screen
,
209 PIPE_BUFFER_USAGE_CPU_READ
);
210 map
[vbi
] += vbuf
->buffer_offset
/ 4;
211 stride
[vbi
] = vbuf
->stride
/ 4;
215 dwords
= 9 + count
* vertex_size
;
217 r300_reserve_cs_space(r300
, r300_get_num_dirty_dwords(r300
) + dwords
);
218 r300_emit_buffer_validate(r300
, FALSE
, NULL
);
219 r300_emit_dirty_state(r300
);
222 OUT_CS_REG(R300_GA_COLOR_CONTROL
,
223 r300_provoking_vertex_fixes(r300
, mode
));
224 OUT_CS_REG(R300_VAP_VTX_SIZE
, vertex_size
);
225 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX
, 2);
228 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2
, count
* vertex_size
);
229 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED
| (count
<< 16) |
230 r300_translate_primitive(mode
));
233 for (v
= 0; v
< count
; v
++) {
234 for (i
= 0; i
< vertex_element_count
; i
++) {
235 velem
= &r300
->velems
->velem
[i
];
236 vbi
= velem
->vertex_buffer_index
;
237 elem_offset
= offset
[i
] + stride
[vbi
] * (v
+ start
);
239 for (dw
= 0; dw
< size
[i
]; dw
++) {
240 OUT_CS(map
[vbi
][elem_offset
+ dw
]);
247 for (i
= 0; i
< vertex_element_count
; i
++) {
248 vbi
= r300
->velems
->velem
[i
].vertex_buffer_index
;
251 vbuf
= &r300
->vertex_buffer
[vbi
];
252 pipe_buffer_unmap(r300
->context
.screen
, vbuf
->buffer
);
258 static void r300_emit_draw_arrays(struct r300_context
*r300
,
262 #if defined(ENABLE_ALT_NUM_VERTS)
263 boolean alt_num_verts
= count
> 65535;
265 boolean alt_num_verts
= FALSE
;
270 assert(count
< (1 << 24));
272 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES
, count
);
276 OUT_CS_REG(R300_GA_COLOR_CONTROL
,
277 r300_provoking_vertex_fixes(r300
, mode
));
278 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX
, 2);
281 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
282 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (count
<< 16) |
283 r300_translate_primitive(mode
) |
284 (alt_num_verts
? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS
: 0));
288 static void r300_emit_draw_elements(struct r300_context
*r300
,
289 struct pipe_buffer
* indexBuffer
,
297 uint32_t count_dwords
;
298 uint32_t offset_dwords
= indexSize
* start
/ sizeof(uint32_t);
299 #if defined(ENABLE_ALT_NUM_VERTS)
300 boolean alt_num_verts
= count
> 65535;
302 boolean alt_num_verts
= FALSE
;
306 assert((start
* indexSize
) % 4 == 0);
307 assert(count
< (1 << 24));
309 maxIndex
= MIN2(maxIndex
, r300
->vertex_buffer_max_index
);
311 DBG(r300
, DBG_DRAW
, "r300: Indexbuf of %u indices, min %u max %u\n",
312 count
, minIndex
, maxIndex
);
316 OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES
, count
);
320 OUT_CS_REG(R300_GA_COLOR_CONTROL
,
321 r300_provoking_vertex_fixes(r300
, mode
));
322 OUT_CS_REG_SEQ(R300_VAP_VF_MAX_VTX_INDX
, 2);
325 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2
, 0);
326 if (indexSize
== 4) {
327 count_dwords
= count
;
328 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
329 R300_VAP_VF_CNTL__INDEX_SIZE_32bit
|
330 r300_translate_primitive(mode
) |
331 (alt_num_verts
? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS
: 0));
333 count_dwords
= (count
+ 1) / 2;
334 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
335 r300_translate_primitive(mode
) |
336 (alt_num_verts
? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS
: 0));
339 /* INDX_BUFFER is a truly special packet3.
340 * Unlike most other packet3, where the offset is after the count,
341 * the order is reversed, so the relocation ends up carrying the
342 * size of the indexbuf instead of the offset.
344 OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER
, 2);
345 OUT_CS(R300_INDX_BUFFER_ONE_REG_WR
| (R300_VAP_PORT_IDX0
>> 2) |
346 (0 << R300_INDX_BUFFER_SKIP_SHIFT
));
347 OUT_CS(offset_dwords
<< 2);
348 OUT_CS_BUF_RELOC(indexBuffer
, count_dwords
,
349 RADEON_GEM_DOMAIN_GTT
, 0, 0);
354 static void r300_shorten_ubyte_elts(struct r300_context
* r300
,
355 struct pipe_buffer
** elts
,
358 struct pipe_screen
* screen
= r300
->context
.screen
;
359 struct pipe_buffer
* new_elts
;
360 unsigned char *in_map
;
361 unsigned short *out_map
;
364 new_elts
= screen
->buffer_create(screen
, 32,
365 PIPE_BUFFER_USAGE_INDEX
|
366 PIPE_BUFFER_USAGE_CPU_WRITE
|
367 PIPE_BUFFER_USAGE_GPU_READ
,
370 in_map
= pipe_buffer_map(screen
, *elts
, PIPE_BUFFER_USAGE_CPU_READ
);
371 out_map
= pipe_buffer_map(screen
, new_elts
, PIPE_BUFFER_USAGE_CPU_WRITE
);
373 for (i
= 0; i
< count
; i
++) {
374 *out_map
= (unsigned short)*in_map
;
379 pipe_buffer_unmap(screen
, *elts
);
380 pipe_buffer_unmap(screen
, new_elts
);
385 /* This is the fast-path drawing & emission for HW TCL. */
386 void r300_draw_range_elements(struct pipe_context
* pipe
,
387 struct pipe_buffer
* indexBuffer
,
395 struct r300_context
* r300
= r300_context(pipe
);
396 struct pipe_buffer
* orgIndexBuffer
= indexBuffer
;
397 #if defined(ENABLE_ALT_NUM_VERTS)
398 boolean alt_num_verts
= r300_screen(pipe
->screen
)->caps
->is_r500
&&
401 boolean alt_num_verts
= FALSE
;
403 unsigned short_count
;
405 if (!u_trim_pipe_prim(mode
, &count
)) {
409 if (indexSize
== 1) {
410 r300_shorten_ubyte_elts(r300
, &indexBuffer
, count
);
414 r300_update_derived_state(r300
);
416 r300_upload_index_buffer(r300
, &indexBuffer
, indexSize
, start
, count
);
418 /* 128 dwords for emit_aos and emit_draw_elements */
419 r300_reserve_cs_space(r300
, r300_get_num_dirty_dwords(r300
) + 128);
420 r300_emit_buffer_validate(r300
, TRUE
, indexBuffer
);
421 r300_emit_dirty_state(r300
);
422 r300_emit_aos(r300
, 0);
424 u_upload_flush(r300
->upload_vb
);
425 u_upload_flush(r300
->upload_ib
);
426 if (alt_num_verts
|| count
<= 65535) {
427 r300_emit_draw_elements(r300
, indexBuffer
, indexSize
, minIndex
,
428 maxIndex
, mode
, start
, count
);
431 short_count
= MIN2(count
, 65534);
432 r300_emit_draw_elements(r300
, indexBuffer
, indexSize
, minIndex
,
433 maxIndex
, mode
, start
, short_count
);
435 start
+= short_count
;
436 count
-= short_count
;
438 /* 16 spare dwords are enough for emit_draw_elements. */
439 if (count
&& r300_reserve_cs_space(r300
, 16)) {
440 r300_emit_buffer_validate(r300
, TRUE
, indexBuffer
);
441 r300_emit_dirty_state(r300
);
442 r300_emit_aos(r300
, 0);
447 if (indexBuffer
!= orgIndexBuffer
) {
448 pipe_buffer_reference( &indexBuffer
, NULL
);
452 /* Simple helpers for context setup. Should probably be moved to util. */
453 void r300_draw_elements(struct pipe_context
* pipe
,
454 struct pipe_buffer
* indexBuffer
,
455 unsigned indexSize
, unsigned mode
,
456 unsigned start
, unsigned count
)
458 struct r300_context
*r300
= r300_context(pipe
);
460 pipe
->draw_range_elements(pipe
, indexBuffer
, indexSize
, 0,
461 r300
->vertex_buffer_max_index
,
465 void r300_draw_arrays(struct pipe_context
* pipe
, unsigned mode
,
466 unsigned start
, unsigned count
)
468 struct r300_context
* r300
= r300_context(pipe
);
469 #if defined(ENABLE_ALT_NUM_VERTS)
470 boolean alt_num_verts
= r300_screen(pipe
->screen
)->caps
->is_r500
&&
473 boolean alt_num_verts
= FALSE
;
475 unsigned short_count
;
477 if (!u_trim_pipe_prim(mode
, &count
)) {
481 r300_update_derived_state(r300
);
483 if (immd_is_good_idea(r300
, count
)) {
484 r300_emit_draw_arrays_immediate(r300
, mode
, start
, count
);
486 /* Make sure there are at least 128 spare dwords in the command buffer.
487 * (most of it being consumed by emit_aos) */
488 r300_reserve_cs_space(r300
, r300_get_num_dirty_dwords(r300
) + 128);
489 r300_emit_buffer_validate(r300
, TRUE
, NULL
);
490 r300_emit_dirty_state(r300
);
492 if (alt_num_verts
|| count
<= 65535) {
493 r300_emit_aos(r300
, start
);
494 r300_emit_draw_arrays(r300
, mode
, count
);
497 short_count
= MIN2(count
, 65535);
498 r300_emit_aos(r300
, start
);
499 r300_emit_draw_arrays(r300
, mode
, short_count
);
501 start
+= short_count
;
502 count
-= short_count
;
504 /* Again, we emit both AOS and draw_arrays so there should be
505 * at least 128 spare dwords. */
506 if (count
&& r300_reserve_cs_space(r300
, 128)) {
507 r300_emit_buffer_validate(r300
, TRUE
, NULL
);
508 r300_emit_dirty_state(r300
);
512 u_upload_flush(r300
->upload_vb
);
516 /****************************************************************************
517 * The rest of this file is for SW TCL rendering only. Please be polite and *
518 * keep these functions separated so that they are easier to locate. ~C. *
519 ***************************************************************************/
521 /* SW TCL arrays, using Draw. */
522 void r300_swtcl_draw_arrays(struct pipe_context
* pipe
,
527 struct r300_context
* r300
= r300_context(pipe
);
530 if (!u_trim_pipe_prim(mode
, &count
)) {
534 for (i
= 0; i
< r300
->vertex_buffer_count
; i
++) {
535 void* buf
= pipe_buffer_map(pipe
->screen
,
536 r300
->vertex_buffer
[i
].buffer
,
537 PIPE_BUFFER_USAGE_CPU_READ
);
538 draw_set_mapped_vertex_buffer(r300
->draw
, i
, buf
);
541 draw_set_mapped_element_buffer(r300
->draw
, 0, NULL
);
543 draw_set_mapped_constant_buffer(r300
->draw
,
546 r300
->shader_constants
[PIPE_SHADER_VERTEX
].constants
,
547 r300
->shader_constants
[PIPE_SHADER_VERTEX
].count
*
548 (sizeof(float) * 4));
550 draw_arrays(r300
->draw
, mode
, start
, count
);
552 for (i
= 0; i
< r300
->vertex_buffer_count
; i
++) {
553 pipe_buffer_unmap(pipe
->screen
, r300
->vertex_buffer
[i
].buffer
);
554 draw_set_mapped_vertex_buffer(r300
->draw
, i
, NULL
);
558 /* SW TCL elements, using Draw. */
559 void r300_swtcl_draw_range_elements(struct pipe_context
* pipe
,
560 struct pipe_buffer
* indexBuffer
,
568 struct r300_context
* r300
= r300_context(pipe
);
572 if (!u_trim_pipe_prim(mode
, &count
)) {
576 for (i
= 0; i
< r300
->vertex_buffer_count
; i
++) {
577 void* buf
= pipe_buffer_map(pipe
->screen
,
578 r300
->vertex_buffer
[i
].buffer
,
579 PIPE_BUFFER_USAGE_CPU_READ
);
580 draw_set_mapped_vertex_buffer(r300
->draw
, i
, buf
);
583 indices
= pipe_buffer_map(pipe
->screen
, indexBuffer
,
584 PIPE_BUFFER_USAGE_CPU_READ
);
585 draw_set_mapped_element_buffer_range(r300
->draw
, indexSize
,
586 minIndex
, maxIndex
, indices
);
588 draw_set_mapped_constant_buffer(r300
->draw
,
591 r300
->shader_constants
[PIPE_SHADER_VERTEX
].constants
,
592 r300
->shader_constants
[PIPE_SHADER_VERTEX
].count
*
593 (sizeof(float) * 4));
595 draw_arrays(r300
->draw
, mode
, start
, count
);
597 for (i
= 0; i
< r300
->vertex_buffer_count
; i
++) {
598 pipe_buffer_unmap(pipe
->screen
, r300
->vertex_buffer
[i
].buffer
);
599 draw_set_mapped_vertex_buffer(r300
->draw
, i
, NULL
);
602 pipe_buffer_unmap(pipe
->screen
, indexBuffer
);
603 draw_set_mapped_element_buffer_range(r300
->draw
, 0, start
,
604 start
+ count
- 1, NULL
);
607 /* Object for rendering using Draw. */
610 struct vbuf_render base
;
613 struct r300_context
* r300
;
615 /* Vertex information */
621 struct pipe_buffer
* vbo
;
628 static INLINE
struct r300_render
*
629 r300_render(struct vbuf_render
* render
)
631 return (struct r300_render
*)render
;
634 static const struct vertex_info
*
635 r300_render_get_vertex_info(struct vbuf_render
* render
)
637 struct r300_render
* r300render
= r300_render(render
);
638 struct r300_context
* r300
= r300render
->r300
;
640 r300_update_derived_state(r300
);
642 return &r300
->vertex_info
;
645 static boolean
r300_render_allocate_vertices(struct vbuf_render
* render
,
649 struct r300_render
* r300render
= r300_render(render
);
650 struct r300_context
* r300
= r300render
->r300
;
651 struct pipe_screen
* screen
= r300
->context
.screen
;
652 size_t size
= (size_t)vertex_size
* (size_t)count
;
654 if (size
+ r300render
->vbo_offset
> r300render
->vbo_size
)
656 pipe_buffer_reference(&r300
->vbo
, NULL
);
657 r300render
->vbo
= pipe_buffer_create(screen
,
659 PIPE_BUFFER_USAGE_VERTEX
,
661 r300render
->vbo_offset
= 0;
662 r300render
->vbo_size
= R300_MAX_VBO_SIZE
;
665 r300render
->vertex_size
= vertex_size
;
666 r300
->vbo
= r300render
->vbo
;
667 r300
->vbo_offset
= r300render
->vbo_offset
;
669 return (r300render
->vbo
) ? TRUE
: FALSE
;
672 static void* r300_render_map_vertices(struct vbuf_render
* render
)
674 struct r300_render
* r300render
= r300_render(render
);
675 struct pipe_screen
* screen
= r300render
->r300
->context
.screen
;
677 r300render
->vbo_ptr
= pipe_buffer_map(screen
, r300render
->vbo
,
678 PIPE_BUFFER_USAGE_CPU_WRITE
);
680 return ((uint8_t*)r300render
->vbo_ptr
+ r300render
->vbo_offset
);
683 static void r300_render_unmap_vertices(struct vbuf_render
* render
,
687 struct r300_render
* r300render
= r300_render(render
);
688 struct pipe_screen
* screen
= r300render
->r300
->context
.screen
;
689 CS_LOCALS(r300render
->r300
);
691 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX
, max
);
694 r300render
->vbo_max_used
= MAX2(r300render
->vbo_max_used
,
695 r300render
->vertex_size
* (max
+ 1));
696 pipe_buffer_unmap(screen
, r300render
->vbo
);
699 static void r300_render_release_vertices(struct vbuf_render
* render
)
701 struct r300_render
* r300render
= r300_render(render
);
703 r300render
->vbo_offset
+= r300render
->vbo_max_used
;
704 r300render
->vbo_max_used
= 0;
707 static boolean
r300_render_set_primitive(struct vbuf_render
* render
,
710 struct r300_render
* r300render
= r300_render(render
);
712 r300render
->prim
= prim
;
713 r300render
->hwprim
= r300_translate_primitive(prim
);
718 static void r300_render_draw_arrays(struct vbuf_render
* render
,
722 struct r300_render
* r300render
= r300_render(render
);
723 struct r300_context
* r300
= r300render
->r300
;
727 r300_reserve_cs_space(r300
, r300_get_num_dirty_dwords(r300
) + 2);
728 r300_emit_buffer_validate(r300
, FALSE
, NULL
);
729 r300_emit_dirty_state(r300
);
731 DBG(r300
, DBG_DRAW
, "r300: Doing vbuf render, count %d\n", count
);
734 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2
, 0);
735 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST
| (count
<< 16) |
740 static void r300_render_draw(struct vbuf_render
* render
,
741 const ushort
* indices
,
744 struct r300_render
* r300render
= r300_render(render
);
745 struct r300_context
* r300
= r300render
->r300
;
747 unsigned dwords
= 2 + (count
+1)/2;
751 r300_reserve_cs_space(r300
, r300_get_num_dirty_dwords(r300
) + dwords
);
752 r300_emit_buffer_validate(r300
, FALSE
, NULL
);
753 r300_emit_dirty_state(r300
);
756 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2
, (count
+1)/2);
757 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES
| (count
<< 16) |
759 for (i
= 0; i
< count
-1; i
+= 2) {
760 OUT_CS(indices
[i
+1] << 16 | indices
[i
]);
763 OUT_CS(indices
[count
-1]);
768 static void r300_render_destroy(struct vbuf_render
* render
)
773 static struct vbuf_render
* r300_render_create(struct r300_context
* r300
)
775 struct r300_render
* r300render
= CALLOC_STRUCT(r300_render
);
777 r300render
->r300
= r300
;
779 /* XXX find real numbers plz */
780 r300render
->base
.max_vertex_buffer_bytes
= 128 * 1024;
781 r300render
->base
.max_indices
= 16 * 1024;
783 r300render
->base
.get_vertex_info
= r300_render_get_vertex_info
;
784 r300render
->base
.allocate_vertices
= r300_render_allocate_vertices
;
785 r300render
->base
.map_vertices
= r300_render_map_vertices
;
786 r300render
->base
.unmap_vertices
= r300_render_unmap_vertices
;
787 r300render
->base
.set_primitive
= r300_render_set_primitive
;
788 r300render
->base
.draw
= r300_render_draw
;
789 r300render
->base
.draw_arrays
= r300_render_draw_arrays
;
790 r300render
->base
.release_vertices
= r300_render_release_vertices
;
791 r300render
->base
.destroy
= r300_render_destroy
;
793 r300render
->vbo
= NULL
;
794 r300render
->vbo_size
= 0;
795 r300render
->vbo_offset
= 0;
797 return &r300render
->base
;
800 struct draw_stage
* r300_draw_stage(struct r300_context
* r300
)
802 struct vbuf_render
* render
;
803 struct draw_stage
* stage
;
805 render
= r300_render_create(r300
);
811 stage
= draw_vbuf_stage(r300
->draw
, render
);
814 render
->destroy(render
);
818 draw_set_render(r300
->draw
, render
);