r300g: Respect fill modes in indices fallback.
[mesa.git] / src / gallium / drivers / r300 / r300_render.c
1 /*
2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
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:
10 *
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
13 * Software.
14 *
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. */
22
23 /* r300_render: Vertex and index buffer primitive emission. Contains both
24 * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */
25
26 #include "draw/draw_context.h"
27 #include "draw/draw_vbuf.h"
28
29 #include "indices/u_indices.h"
30
31 #include "pipe/p_inlines.h"
32
33 #include "util/u_memory.h"
34 #include "util/u_prim.h"
35
36 #include "r300_cs.h"
37 #include "r300_context.h"
38 #include "r300_emit.h"
39 #include "r300_reg.h"
40 #include "r300_render.h"
41 #include "r300_state_derived.h"
42
43 /* r300_render: Vertex and index buffer primitive emission. */
44 #define R300_MAX_VBO_SIZE (1024 * 1024)
45
46 uint32_t r300_translate_primitive(unsigned prim)
47 {
48 switch (prim) {
49 case PIPE_PRIM_POINTS:
50 return R300_VAP_VF_CNTL__PRIM_POINTS;
51 case PIPE_PRIM_LINES:
52 return R300_VAP_VF_CNTL__PRIM_LINES;
53 case PIPE_PRIM_LINE_LOOP:
54 return R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
55 case PIPE_PRIM_LINE_STRIP:
56 return R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
57 case PIPE_PRIM_TRIANGLES:
58 return R300_VAP_VF_CNTL__PRIM_TRIANGLES;
59 case PIPE_PRIM_TRIANGLE_STRIP:
60 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP;
61 case PIPE_PRIM_TRIANGLE_FAN:
62 return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN;
63 case PIPE_PRIM_QUADS:
64 return R300_VAP_VF_CNTL__PRIM_QUADS;
65 case PIPE_PRIM_QUAD_STRIP:
66 return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP;
67 case PIPE_PRIM_POLYGON:
68 return R300_VAP_VF_CNTL__PRIM_POLYGON;
69 default:
70 return 0;
71 }
72 }
73
74 static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300,
75 unsigned mode)
76 {
77 struct r300_rs_state* rs = (struct r300_rs_state*)r300->rs_state.state;
78 uint32_t color_control = rs->color_control;
79
80 /* By default (see r300_state.c:r300_create_rs_state) color_control is
81 * initialized to provoking the first vertex.
82 *
83 * Triangle fans must be reduced to the second vertex, not the first, in
84 * Gallium flatshade-first mode, as per the GL spec.
85 * (http://www.opengl.org/registry/specs/ARB/provoking_vertex.txt)
86 *
87 * Quads never provoke correctly in flatshade-first mode. The first
88 * vertex is never considered as provoking, so only the second, third,
89 * and fourth vertices can be selected, and both "third" and "last" modes
90 * select the fourth vertex. This is probably due to D3D lacking quads.
91 *
92 * Similarly, polygons reduce to the first, not the last, vertex, when in
93 * "last" mode, and all other modes start from the second vertex.
94 *
95 * ~ C.
96 */
97
98 if (rs->rs.flatshade_first) {
99 switch (mode) {
100 case PIPE_PRIM_TRIANGLE_FAN:
101 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_SECOND;
102 break;
103 case PIPE_PRIM_QUADS:
104 case PIPE_PRIM_QUAD_STRIP:
105 case PIPE_PRIM_POLYGON:
106 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST;
107 break;
108 default:
109 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_FIRST;
110 break;
111 }
112 } else {
113 color_control |= R300_GA_COLOR_CONTROL_PROVOKING_VERTEX_LAST;
114 }
115
116 return color_control;
117 }
118
119 static void r300_emit_draw_immediate(struct r300_context *r300,
120 unsigned mode,
121 unsigned start,
122 unsigned count)
123 {
124 struct pipe_buffer* vbo = r300->vertex_buffer[0].buffer;
125 unsigned vertex_size = r300->vertex_buffer[0].stride / sizeof(float);
126 unsigned i;
127 uint32_t* map;
128 CS_LOCALS(r300);
129
130 map = (uint32_t*)pipe_buffer_map_range(r300->context.screen, vbo,
131 start * vertex_size, count * vertex_size,
132 PIPE_BUFFER_USAGE_CPU_READ);
133
134 BEGIN_CS(10 + count * vertex_size);
135 OUT_CS_REG(R300_GA_COLOR_CONTROL,
136 r300_provoking_vertex_fixes(r300, mode));
137 OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size);
138 OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0);
139 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
140 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_IMMD_2, count * vertex_size);
141 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_EMBEDDED | (count << 16) |
142 r300_translate_primitive(mode));
143 //debug_printf("r300: Immd %d verts, %d attrs\n", count, vertex_size);
144 for (i = 0; i < count * vertex_size; i++) {
145 if (i % vertex_size == 0) {
146 //debug_printf("r300: -- vert --\n");
147 }
148 //debug_printf("r300: 0x%08x\n", *map);
149 OUT_CS(*map);
150 map++;
151 }
152 END_CS;
153
154 pipe_buffer_unmap(r300->context.screen, vbo);
155 }
156
157 static void r300_emit_draw_arrays(struct r300_context *r300,
158 unsigned mode,
159 unsigned count)
160 {
161 CS_LOCALS(r300);
162
163 BEGIN_CS(8);
164 OUT_CS_REG(R300_GA_COLOR_CONTROL,
165 r300_provoking_vertex_fixes(r300, mode));
166 OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0);
167 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
168 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
169 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
170 r300_translate_primitive(mode));
171 END_CS;
172 }
173
174 static void r300_emit_draw_elements(struct r300_context *r300,
175 struct pipe_buffer* indexBuffer,
176 unsigned indexSize,
177 unsigned minIndex,
178 unsigned maxIndex,
179 unsigned mode,
180 unsigned start,
181 unsigned count)
182 {
183 uint32_t count_dwords;
184 uint32_t offset_dwords = indexSize * start / sizeof(uint32_t);
185 CS_LOCALS(r300);
186
187 /* XXX most of these are stupid */
188 assert(indexSize == 4 || indexSize == 2);
189 assert((start * indexSize) % 4 == 0);
190 assert(offset_dwords == 0);
191
192 BEGIN_CS(14);
193 OUT_CS_REG(R300_GA_COLOR_CONTROL,
194 r300_provoking_vertex_fixes(r300, mode));
195 OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, minIndex);
196 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex);
197 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0);
198 if (indexSize == 4) {
199 count_dwords = count + start;
200 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
201 R300_VAP_VF_CNTL__INDEX_SIZE_32bit |
202 r300_translate_primitive(mode));
203 } else {
204 count_dwords = (count + start + 1) / 2;
205 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
206 r300_translate_primitive(mode));
207 }
208
209 /* INDX_BUFFER is a truly special packet3.
210 * Unlike most other packet3, where the offset is after the count,
211 * the order is reversed, so the relocation ends up carrying the
212 * size of the indexbuf instead of the offset.
213 *
214 * XXX Fix offset
215 */
216 OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2);
217 OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) |
218 (0 << R300_INDX_BUFFER_SKIP_SHIFT));
219 OUT_CS(offset_dwords);
220 OUT_CS_RELOC(indexBuffer, count_dwords,
221 RADEON_GEM_DOMAIN_GTT, 0, 0);
222
223 END_CS;
224 }
225
226
227 static boolean r300_setup_vertex_buffers(struct r300_context *r300)
228 {
229 struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
230 struct pipe_vertex_element *velem = r300->vertex_element;
231
232 validate:
233 for (int i = 0; i < r300->vertex_element_count; i++) {
234 if (!r300->winsys->add_buffer(r300->winsys,
235 vbuf[velem[i].vertex_buffer_index].buffer,
236 RADEON_GEM_DOMAIN_GTT, 0)) {
237 r300->context.flush(&r300->context, 0, NULL);
238 goto validate;
239 }
240 }
241
242 if (!r300->winsys->validate(r300->winsys)) {
243 r300->context.flush(&r300->context, 0, NULL);
244 return r300->winsys->validate(r300->winsys);
245 }
246
247 return TRUE;
248 }
249
250 static struct pipe_buffer* r300_translate_elts(struct r300_context* r300,
251 struct pipe_buffer* elts,
252 unsigned* size,
253 unsigned* mode,
254 unsigned* count)
255 {
256 struct pipe_screen* screen = r300->context.screen;
257 struct pipe_buffer* new_elts;
258 void *in_map, *out_map;
259 unsigned out_prim, out_index_size, out_nr;
260 struct pipe_rasterizer_state* rs;
261 u_translate_func out_translate;
262
263 rs = &((struct r300_rs_state*)r300->rs_state.state)->rs;
264
265 if (rs->fill_cw == rs->fill_ccw &&
266 rs->fill_cw != PIPE_POLYGON_MODE_FILL) {
267 (void)u_unfilled_translator(*mode, *size, *count, rs->fill_cw,
268 &out_prim, &out_index_size, &out_nr, &out_translate);
269 } else {
270 (void)u_index_translator(~0, *mode, *size, *count, PV_LAST, PV_LAST,
271 &out_prim, &out_index_size, &out_nr, &out_translate);
272 }
273
274 debug_printf("r300: old mode %d, new mode %d\n", *mode, out_prim);
275 debug_printf("r300: old count %d, new count %d\n", *count, out_nr);
276 debug_printf("r300: old size %d, new size %d\n", *size, out_index_size);
277
278 new_elts = screen->buffer_create(screen, 32,
279 PIPE_BUFFER_USAGE_INDEX |
280 PIPE_BUFFER_USAGE_CPU_WRITE |
281 PIPE_BUFFER_USAGE_GPU_READ,
282 out_index_size * out_nr);
283
284 in_map = pipe_buffer_map(screen, elts, PIPE_BUFFER_USAGE_CPU_READ);
285 out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE);
286
287 out_translate(in_map, *count, out_map);
288
289 pipe_buffer_unmap(screen, elts);
290 pipe_buffer_unmap(screen, new_elts);
291
292 *size = out_index_size;
293 *mode = out_prim;
294 *count = out_nr;
295
296 return new_elts;
297 }
298
299 /* This is the fast-path drawing & emission for HW TCL. */
300 void r300_draw_range_elements(struct pipe_context* pipe,
301 struct pipe_buffer* indexBuffer,
302 unsigned indexSize,
303 unsigned minIndex,
304 unsigned maxIndex,
305 unsigned mode,
306 unsigned start,
307 unsigned count)
308 {
309 struct r300_context* r300 = r300_context(pipe);
310 struct pipe_buffer* orgIndexBuffer = indexBuffer;
311
312 if (!u_trim_pipe_prim(mode, &count)) {
313 return;
314 }
315
316 if (count > 65535) {
317 /* XXX: use aux/indices functions to split this into smaller
318 * primitives.
319 */
320 return;
321 }
322
323 r300_update_derived_state(r300);
324
325 if (!r300_setup_vertex_buffers(r300)) {
326 return;
327 }
328
329 if (indexSize == 1) {
330 indexBuffer = r300_translate_elts(r300, indexBuffer,
331 &indexSize, &mode, &count);
332 }
333
334 if (!r300->winsys->add_buffer(r300->winsys, indexBuffer,
335 RADEON_GEM_DOMAIN_GTT, 0)) {
336 goto cleanup;
337 }
338
339 if (!r300->winsys->validate(r300->winsys)) {
340 goto cleanup;
341 }
342
343 r300_emit_dirty_state(r300);
344
345 r300_emit_aos(r300, 0);
346
347 r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex,
348 mode, start, count);
349
350 cleanup:
351 if (indexBuffer != orgIndexBuffer) {
352 pipe->screen->buffer_destroy(indexBuffer);
353 }
354 }
355
356 /* Simple helpers for context setup. Should probably be moved to util. */
357 void r300_draw_elements(struct pipe_context* pipe,
358 struct pipe_buffer* indexBuffer,
359 unsigned indexSize, unsigned mode,
360 unsigned start, unsigned count)
361 {
362 pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0,
363 mode, start, count);
364 }
365
366 void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
367 unsigned start, unsigned count)
368 {
369 struct r300_context* r300 = r300_context(pipe);
370
371 if (!u_trim_pipe_prim(mode, &count)) {
372 return;
373 }
374
375 if (count > 65535) {
376 /* XXX: driver needs to handle this -- use the functions in
377 * aux/indices to split this into several smaller primitives.
378 */
379 return;
380 }
381
382 r300_update_derived_state(r300);
383
384 if (!r300_setup_vertex_buffers(r300)) {
385 return;
386 }
387
388 r300_emit_dirty_state(r300);
389
390 if (FALSE && count <= 4 && r300->vertex_buffer_count == 1) {
391 r300_emit_draw_immediate(r300, mode, start, count);
392 } else {
393 r300_emit_aos(r300, start);
394 r300_emit_draw_arrays(r300, mode, count);
395 }
396 }
397
398 /****************************************************************************
399 * The rest of this file is for SW TCL rendering only. Please be polite and *
400 * keep these functions separated so that they are easier to locate. ~C. *
401 ***************************************************************************/
402
403 /* SW TCL arrays, using Draw. */
404 void r300_swtcl_draw_arrays(struct pipe_context* pipe,
405 unsigned mode,
406 unsigned start,
407 unsigned count)
408 {
409 struct r300_context* r300 = r300_context(pipe);
410 int i;
411
412 if (!u_trim_pipe_prim(mode, &count)) {
413 return;
414 }
415
416 for (i = 0; i < r300->vertex_buffer_count; i++) {
417 void* buf = pipe_buffer_map(pipe->screen,
418 r300->vertex_buffer[i].buffer,
419 PIPE_BUFFER_USAGE_CPU_READ);
420 draw_set_mapped_vertex_buffer(r300->draw, i, buf);
421 }
422
423 draw_set_mapped_element_buffer(r300->draw, 0, NULL);
424
425 draw_set_mapped_constant_buffer(r300->draw,
426 PIPE_SHADER_VERTEX,
427 r300->shader_constants[PIPE_SHADER_VERTEX].constants,
428 r300->shader_constants[PIPE_SHADER_VERTEX].count *
429 (sizeof(float) * 4));
430
431 draw_arrays(r300->draw, mode, start, count);
432
433 for (i = 0; i < r300->vertex_buffer_count; i++) {
434 pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer);
435 draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
436 }
437 }
438
439 /* SW TCL elements, using Draw. */
440 void r300_swtcl_draw_range_elements(struct pipe_context* pipe,
441 struct pipe_buffer* indexBuffer,
442 unsigned indexSize,
443 unsigned minIndex,
444 unsigned maxIndex,
445 unsigned mode,
446 unsigned start,
447 unsigned count)
448 {
449 struct r300_context* r300 = r300_context(pipe);
450 int i;
451 void* indices;
452
453 if (!u_trim_pipe_prim(mode, &count)) {
454 return;
455 }
456
457 for (i = 0; i < r300->vertex_buffer_count; i++) {
458 void* buf = pipe_buffer_map(pipe->screen,
459 r300->vertex_buffer[i].buffer,
460 PIPE_BUFFER_USAGE_CPU_READ);
461 draw_set_mapped_vertex_buffer(r300->draw, i, buf);
462 }
463
464 indices = pipe_buffer_map(pipe->screen, indexBuffer,
465 PIPE_BUFFER_USAGE_CPU_READ);
466 draw_set_mapped_element_buffer_range(r300->draw, indexSize,
467 minIndex, maxIndex, indices);
468
469 draw_set_mapped_constant_buffer(r300->draw,
470 PIPE_SHADER_VERTEX,
471 r300->shader_constants[PIPE_SHADER_VERTEX].constants,
472 r300->shader_constants[PIPE_SHADER_VERTEX].count *
473 (sizeof(float) * 4));
474
475 draw_arrays(r300->draw, mode, start, count);
476
477 for (i = 0; i < r300->vertex_buffer_count; i++) {
478 pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer);
479 draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
480 }
481
482 pipe_buffer_unmap(pipe->screen, indexBuffer);
483 draw_set_mapped_element_buffer_range(r300->draw, 0, start,
484 start + count - 1, NULL);
485 }
486
487 /* Object for rendering using Draw. */
488 struct r300_render {
489 /* Parent class */
490 struct vbuf_render base;
491
492 /* Pipe context */
493 struct r300_context* r300;
494
495 /* Vertex information */
496 size_t vertex_size;
497 unsigned prim;
498 unsigned hwprim;
499
500 /* VBO */
501 struct pipe_buffer* vbo;
502 size_t vbo_size;
503 size_t vbo_offset;
504 size_t vbo_max_used;
505 void * vbo_ptr;
506 };
507
508 static INLINE struct r300_render*
509 r300_render(struct vbuf_render* render)
510 {
511 return (struct r300_render*)render;
512 }
513
514 static const struct vertex_info*
515 r300_render_get_vertex_info(struct vbuf_render* render)
516 {
517 struct r300_render* r300render = r300_render(render);
518 struct r300_context* r300 = r300render->r300;
519
520 r300_update_derived_state(r300);
521
522 return &r300->vertex_info->vinfo;
523 }
524
525 static boolean r300_render_allocate_vertices(struct vbuf_render* render,
526 ushort vertex_size,
527 ushort count)
528 {
529 struct r300_render* r300render = r300_render(render);
530 struct r300_context* r300 = r300render->r300;
531 struct pipe_screen* screen = r300->context.screen;
532 size_t size = (size_t)vertex_size * (size_t)count;
533
534 if (size + r300render->vbo_offset > r300render->vbo_size)
535 {
536 pipe_buffer_reference(&r300->vbo, NULL);
537 r300render->vbo = pipe_buffer_create(screen,
538 64,
539 PIPE_BUFFER_USAGE_VERTEX,
540 R300_MAX_VBO_SIZE);
541 r300render->vbo_offset = 0;
542 r300render->vbo_size = R300_MAX_VBO_SIZE;
543 }
544
545 r300render->vertex_size = vertex_size;
546 r300->vbo = r300render->vbo;
547 r300->vbo_offset = r300render->vbo_offset;
548
549 return (r300render->vbo) ? TRUE : FALSE;
550 }
551
552 static void* r300_render_map_vertices(struct vbuf_render* render)
553 {
554 struct r300_render* r300render = r300_render(render);
555 struct pipe_screen* screen = r300render->r300->context.screen;
556
557 r300render->vbo_ptr = pipe_buffer_map(screen, r300render->vbo,
558 PIPE_BUFFER_USAGE_CPU_WRITE);
559
560 return ((uint8_t*)r300render->vbo_ptr + r300render->vbo_offset);
561 }
562
563 static void r300_render_unmap_vertices(struct vbuf_render* render,
564 ushort min,
565 ushort max)
566 {
567 struct r300_render* r300render = r300_render(render);
568 struct pipe_screen* screen = r300render->r300->context.screen;
569 CS_LOCALS(r300render->r300);
570 BEGIN_CS(2);
571 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max);
572 END_CS;
573
574 r300render->vbo_max_used = MAX2(r300render->vbo_max_used,
575 r300render->vertex_size * (max + 1));
576 pipe_buffer_unmap(screen, r300render->vbo);
577 }
578
579 static void r300_render_release_vertices(struct vbuf_render* render)
580 {
581 struct r300_render* r300render = r300_render(render);
582
583 r300render->vbo_offset += r300render->vbo_max_used;
584 r300render->vbo_max_used = 0;
585 }
586
587 static boolean r300_render_set_primitive(struct vbuf_render* render,
588 unsigned prim)
589 {
590 struct r300_render* r300render = r300_render(render);
591
592 r300render->prim = prim;
593 r300render->hwprim = r300_translate_primitive(prim);
594
595 return TRUE;
596 }
597
598 static void r300_render_draw_arrays(struct vbuf_render* render,
599 unsigned start,
600 unsigned count)
601 {
602 struct r300_render* r300render = r300_render(render);
603 struct r300_context* r300 = r300render->r300;
604
605 CS_LOCALS(r300);
606
607 r300_emit_dirty_state(r300);
608
609 DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count);
610
611 BEGIN_CS(2);
612 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
613 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
614 r300render->hwprim);
615 END_CS;
616 }
617
618 static void r300_render_draw(struct vbuf_render* render,
619 const ushort* indices,
620 uint count)
621 {
622 struct r300_render* r300render = r300_render(render);
623 struct r300_context* r300 = r300render->r300;
624 int i;
625
626 CS_LOCALS(r300);
627
628 r300_emit_dirty_state(r300);
629
630 BEGIN_CS(2 + (count+1)/2);
631 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2);
632 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
633 r300render->hwprim);
634 for (i = 0; i < count-1; i += 2) {
635 OUT_CS(indices[i+1] << 16 | indices[i]);
636 }
637 if (count % 2) {
638 OUT_CS(indices[count-1]);
639 }
640 END_CS;
641 }
642
643 static void r300_render_destroy(struct vbuf_render* render)
644 {
645 FREE(render);
646 }
647
648 static struct vbuf_render* r300_render_create(struct r300_context* r300)
649 {
650 struct r300_render* r300render = CALLOC_STRUCT(r300_render);
651
652 r300render->r300 = r300;
653
654 /* XXX find real numbers plz */
655 r300render->base.max_vertex_buffer_bytes = 128 * 1024;
656 r300render->base.max_indices = 16 * 1024;
657
658 r300render->base.get_vertex_info = r300_render_get_vertex_info;
659 r300render->base.allocate_vertices = r300_render_allocate_vertices;
660 r300render->base.map_vertices = r300_render_map_vertices;
661 r300render->base.unmap_vertices = r300_render_unmap_vertices;
662 r300render->base.set_primitive = r300_render_set_primitive;
663 r300render->base.draw = r300_render_draw;
664 r300render->base.draw_arrays = r300_render_draw_arrays;
665 r300render->base.release_vertices = r300_render_release_vertices;
666 r300render->base.destroy = r300_render_destroy;
667
668 r300render->vbo = NULL;
669 r300render->vbo_size = 0;
670 r300render->vbo_offset = 0;
671
672 return &r300render->base;
673 }
674
675 struct draw_stage* r300_draw_stage(struct r300_context* r300)
676 {
677 struct vbuf_render* render;
678 struct draw_stage* stage;
679
680 render = r300_render_create(r300);
681
682 if (!render) {
683 return NULL;
684 }
685
686 stage = draw_vbuf_stage(r300->draw, render);
687
688 if (!stage) {
689 render->destroy(render);
690 return NULL;
691 }
692
693 draw_set_render(r300->draw, render);
694
695 return stage;
696 }