r300_render.c revision 1bc77e9931a248b74e0ef6b6aa2f4c5b2d1a2ca3
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 46uint32_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 74static 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 119static 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 157static 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 174static 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 227static 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 232validate: 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 250static 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 u_translate_func out_translate; 261 262 (void)u_index_translator(~0, *mode, *size, *count, PV_LAST, PV_LAST, 263 &out_prim, &out_index_size, &out_nr, &out_translate); 264 265 new_elts = screen->buffer_create(screen, 32, 266 PIPE_BUFFER_USAGE_INDEX | 267 PIPE_BUFFER_USAGE_CPU_WRITE | 268 PIPE_BUFFER_USAGE_GPU_READ, 269 out_index_size * out_nr); 270 271 in_map = pipe_buffer_map(screen, elts, PIPE_BUFFER_USAGE_CPU_READ); 272 out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE); 273 274 out_translate(in_map, *count, out_map); 275 276 pipe_buffer_unmap(screen, elts); 277 pipe_buffer_unmap(screen, new_elts); 278 279 *size = out_index_size; 280 *mode = out_prim; 281 *count = out_nr; 282 283 return new_elts; 284} 285 286/* This is the fast-path drawing & emission for HW TCL. */ 287void r300_draw_range_elements(struct pipe_context* pipe, 288 struct pipe_buffer* indexBuffer, 289 unsigned indexSize, 290 unsigned minIndex, 291 unsigned maxIndex, 292 unsigned mode, 293 unsigned start, 294 unsigned count) 295{ 296 struct r300_context* r300 = r300_context(pipe); 297 struct pipe_buffer* orgIndexBuffer = indexBuffer; 298 299 if (!u_trim_pipe_prim(mode, &count)) { 300 return; 301 } 302 303 if (count > 65535) { 304 /* XXX: use aux/indices functions to split this into smaller 305 * primitives. 306 */ 307 return; 308 } 309 310 r300_update_derived_state(r300); 311 312 if (!r300_setup_vertex_buffers(r300)) { 313 return; 314 } 315 316 if (indexSize == 1) { 317 indexBuffer = r300_translate_elts(r300, indexBuffer, 318 &indexSize, &mode, &count); 319 } 320 321 if (!r300->winsys->add_buffer(r300->winsys, indexBuffer, 322 RADEON_GEM_DOMAIN_GTT, 0)) { 323 goto cleanup; 324 } 325 326 if (!r300->winsys->validate(r300->winsys)) { 327 goto cleanup; 328 } 329 330 r300_emit_dirty_state(r300); 331 332 r300_emit_aos(r300, 0); 333 334 r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex, 335 mode, start, count); 336 337cleanup: 338 if (indexBuffer != orgIndexBuffer) { 339 pipe->screen->buffer_destroy(indexBuffer); 340 } 341} 342 343/* Simple helpers for context setup. Should probably be moved to util. */ 344void r300_draw_elements(struct pipe_context* pipe, 345 struct pipe_buffer* indexBuffer, 346 unsigned indexSize, unsigned mode, 347 unsigned start, unsigned count) 348{ 349 pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0, 350 mode, start, count); 351} 352 353void r300_draw_arrays(struct pipe_context* pipe, unsigned mode, 354 unsigned start, unsigned count) 355{ 356 struct r300_context* r300 = r300_context(pipe); 357 358 if (!u_trim_pipe_prim(mode, &count)) { 359 return; 360 } 361 362 if (count > 65535) { 363 /* XXX: driver needs to handle this -- use the functions in 364 * aux/indices to split this into several smaller primitives. 365 */ 366 return; 367 } 368 369 r300_update_derived_state(r300); 370 371 if (!r300_setup_vertex_buffers(r300)) { 372 return; 373 } 374 375 r300_emit_dirty_state(r300); 376 377 if (FALSE && count <= 4 && r300->vertex_buffer_count == 1) { 378 r300_emit_draw_immediate(r300, mode, start, count); 379 } else { 380 r300_emit_aos(r300, start); 381 r300_emit_draw_arrays(r300, mode, count); 382 } 383} 384 385/**************************************************************************** 386 * The rest of this file is for SW TCL rendering only. Please be polite and * 387 * keep these functions separated so that they are easier to locate. ~C. * 388 ***************************************************************************/ 389 390/* SW TCL arrays, using Draw. */ 391void r300_swtcl_draw_arrays(struct pipe_context* pipe, 392 unsigned mode, 393 unsigned start, 394 unsigned count) 395{ 396 struct r300_context* r300 = r300_context(pipe); 397 int i; 398 399 if (!u_trim_pipe_prim(mode, &count)) { 400 return; 401 } 402 403 for (i = 0; i < r300->vertex_buffer_count; i++) { 404 void* buf = pipe_buffer_map(pipe->screen, 405 r300->vertex_buffer[i].buffer, 406 PIPE_BUFFER_USAGE_CPU_READ); 407 draw_set_mapped_vertex_buffer(r300->draw, i, buf); 408 } 409 410 draw_set_mapped_element_buffer(r300->draw, 0, NULL); 411 412 draw_set_mapped_constant_buffer(r300->draw, 413 PIPE_SHADER_VERTEX, 414 r300->shader_constants[PIPE_SHADER_VERTEX].constants, 415 r300->shader_constants[PIPE_SHADER_VERTEX].count * 416 (sizeof(float) * 4)); 417 418 draw_arrays(r300->draw, mode, start, count); 419 420 for (i = 0; i < r300->vertex_buffer_count; i++) { 421 pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer); 422 draw_set_mapped_vertex_buffer(r300->draw, i, NULL); 423 } 424} 425 426/* SW TCL elements, using Draw. */ 427void r300_swtcl_draw_range_elements(struct pipe_context* pipe, 428 struct pipe_buffer* indexBuffer, 429 unsigned indexSize, 430 unsigned minIndex, 431 unsigned maxIndex, 432 unsigned mode, 433 unsigned start, 434 unsigned count) 435{ 436 struct r300_context* r300 = r300_context(pipe); 437 int i; 438 void* indices; 439 440 if (!u_trim_pipe_prim(mode, &count)) { 441 return; 442 } 443 444 for (i = 0; i < r300->vertex_buffer_count; i++) { 445 void* buf = pipe_buffer_map(pipe->screen, 446 r300->vertex_buffer[i].buffer, 447 PIPE_BUFFER_USAGE_CPU_READ); 448 draw_set_mapped_vertex_buffer(r300->draw, i, buf); 449 } 450 451 indices = pipe_buffer_map(pipe->screen, indexBuffer, 452 PIPE_BUFFER_USAGE_CPU_READ); 453 draw_set_mapped_element_buffer_range(r300->draw, indexSize, 454 minIndex, maxIndex, indices); 455 456 draw_set_mapped_constant_buffer(r300->draw, 457 PIPE_SHADER_VERTEX, 458 r300->shader_constants[PIPE_SHADER_VERTEX].constants, 459 r300->shader_constants[PIPE_SHADER_VERTEX].count * 460 (sizeof(float) * 4)); 461 462 draw_arrays(r300->draw, mode, start, count); 463 464 for (i = 0; i < r300->vertex_buffer_count; i++) { 465 pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer); 466 draw_set_mapped_vertex_buffer(r300->draw, i, NULL); 467 } 468 469 pipe_buffer_unmap(pipe->screen, indexBuffer); 470 draw_set_mapped_element_buffer_range(r300->draw, 0, start, 471 start + count - 1, NULL); 472} 473 474/* Object for rendering using Draw. */ 475struct r300_render { 476 /* Parent class */ 477 struct vbuf_render base; 478 479 /* Pipe context */ 480 struct r300_context* r300; 481 482 /* Vertex information */ 483 size_t vertex_size; 484 unsigned prim; 485 unsigned hwprim; 486 487 /* VBO */ 488 struct pipe_buffer* vbo; 489 size_t vbo_size; 490 size_t vbo_offset; 491 size_t vbo_max_used; 492 void * vbo_ptr; 493}; 494 495static INLINE struct r300_render* 496r300_render(struct vbuf_render* render) 497{ 498 return (struct r300_render*)render; 499} 500 501static const struct vertex_info* 502r300_render_get_vertex_info(struct vbuf_render* render) 503{ 504 struct r300_render* r300render = r300_render(render); 505 struct r300_context* r300 = r300render->r300; 506 507 r300_update_derived_state(r300); 508 509 return &r300->vertex_info->vinfo; 510} 511 512static boolean r300_render_allocate_vertices(struct vbuf_render* render, 513 ushort vertex_size, 514 ushort count) 515{ 516 struct r300_render* r300render = r300_render(render); 517 struct r300_context* r300 = r300render->r300; 518 struct pipe_screen* screen = r300->context.screen; 519 size_t size = (size_t)vertex_size * (size_t)count; 520 521 if (size + r300render->vbo_offset > r300render->vbo_size) 522 { 523 pipe_buffer_reference(&r300->vbo, NULL); 524 r300render->vbo = pipe_buffer_create(screen, 525 64, 526 PIPE_BUFFER_USAGE_VERTEX, 527 R300_MAX_VBO_SIZE); 528 r300render->vbo_offset = 0; 529 r300render->vbo_size = R300_MAX_VBO_SIZE; 530 } 531 532 r300render->vertex_size = vertex_size; 533 r300->vbo = r300render->vbo; 534 r300->vbo_offset = r300render->vbo_offset; 535 536 return (r300render->vbo) ? TRUE : FALSE; 537} 538 539static void* r300_render_map_vertices(struct vbuf_render* render) 540{ 541 struct r300_render* r300render = r300_render(render); 542 struct pipe_screen* screen = r300render->r300->context.screen; 543 544 r300render->vbo_ptr = pipe_buffer_map(screen, r300render->vbo, 545 PIPE_BUFFER_USAGE_CPU_WRITE); 546 547 return ((uint8_t*)r300render->vbo_ptr + r300render->vbo_offset); 548} 549 550static void r300_render_unmap_vertices(struct vbuf_render* render, 551 ushort min, 552 ushort max) 553{ 554 struct r300_render* r300render = r300_render(render); 555 struct pipe_screen* screen = r300render->r300->context.screen; 556 CS_LOCALS(r300render->r300); 557 BEGIN_CS(2); 558 OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max); 559 END_CS; 560 561 r300render->vbo_max_used = MAX2(r300render->vbo_max_used, 562 r300render->vertex_size * (max + 1)); 563 pipe_buffer_unmap(screen, r300render->vbo); 564} 565 566static void r300_render_release_vertices(struct vbuf_render* render) 567{ 568 struct r300_render* r300render = r300_render(render); 569 570 r300render->vbo_offset += r300render->vbo_max_used; 571 r300render->vbo_max_used = 0; 572} 573 574static boolean r300_render_set_primitive(struct vbuf_render* render, 575 unsigned prim) 576{ 577 struct r300_render* r300render = r300_render(render); 578 579 r300render->prim = prim; 580 r300render->hwprim = r300_translate_primitive(prim); 581 582 return TRUE; 583} 584 585static void r300_render_draw_arrays(struct vbuf_render* render, 586 unsigned start, 587 unsigned count) 588{ 589 struct r300_render* r300render = r300_render(render); 590 struct r300_context* r300 = r300render->r300; 591 592 CS_LOCALS(r300); 593 594 r300_emit_dirty_state(r300); 595 596 DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count); 597 598 BEGIN_CS(2); 599 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); 600 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | 601 r300render->hwprim); 602 END_CS; 603} 604 605static void r300_render_draw(struct vbuf_render* render, 606 const ushort* indices, 607 uint count) 608{ 609 struct r300_render* r300render = r300_render(render); 610 struct r300_context* r300 = r300render->r300; 611 int i; 612 613 CS_LOCALS(r300); 614 615 r300_emit_dirty_state(r300); 616 617 BEGIN_CS(2 + (count+1)/2); 618 OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2); 619 OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | 620 r300render->hwprim); 621 for (i = 0; i < count-1; i += 2) { 622 OUT_CS(indices[i+1] << 16 | indices[i]); 623 } 624 if (count % 2) { 625 OUT_CS(indices[count-1]); 626 } 627 END_CS; 628} 629 630static void r300_render_destroy(struct vbuf_render* render) 631{ 632 FREE(render); 633} 634 635static struct vbuf_render* r300_render_create(struct r300_context* r300) 636{ 637 struct r300_render* r300render = CALLOC_STRUCT(r300_render); 638 639 r300render->r300 = r300; 640 641 /* XXX find real numbers plz */ 642 r300render->base.max_vertex_buffer_bytes = 128 * 1024; 643 r300render->base.max_indices = 16 * 1024; 644 645 r300render->base.get_vertex_info = r300_render_get_vertex_info; 646 r300render->base.allocate_vertices = r300_render_allocate_vertices; 647 r300render->base.map_vertices = r300_render_map_vertices; 648 r300render->base.unmap_vertices = r300_render_unmap_vertices; 649 r300render->base.set_primitive = r300_render_set_primitive; 650 r300render->base.draw = r300_render_draw; 651 r300render->base.draw_arrays = r300_render_draw_arrays; 652 r300render->base.release_vertices = r300_render_release_vertices; 653 r300render->base.destroy = r300_render_destroy; 654 655 r300render->vbo = NULL; 656 r300render->vbo_size = 0; 657 r300render->vbo_offset = 0; 658 659 return &r300render->base; 660} 661 662struct draw_stage* r300_draw_stage(struct r300_context* r300) 663{ 664 struct vbuf_render* render; 665 struct draw_stage* stage; 666 667 render = r300_render_create(r300); 668 669 if (!render) { 670 return NULL; 671 } 672 673 stage = draw_vbuf_stage(r300->draw, render); 674 675 if (!stage) { 676 render->destroy(render); 677 return NULL; 678 } 679 680 draw_set_render(r300->draw, render); 681 682 return stage; 683} 684