r300_render.c revision 3445f476977ae403cef9ca15661fa0f96ff50eca
1e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson/*
25c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson *
4e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * Permission is hereby granted, free of charge, to any person obtaining a
5e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * copy of this software and associated documentation files (the "Software"),
6e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * to deal in the Software without restriction, including without limitation
7e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * on the rights to use, copy, modify, merge, publish, distribute, sub
8e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * license, and/or sell copies of the Software, and to permit persons to whom
9e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * the Software is furnished to do so, subject to the following conditions:
10e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson *
11e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * The above copyright notice and this permission notice (including the next
12e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * paragraph) shall be included in all copies or substantial portions of the
13e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * Software.
14e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson *
15e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
236acb26eadfcb3c21fd09d0b22804b49de9a82cf7Maciej Cencora/* r300_render: Vertex and index buffer primitive emission. Contains both
246acb26eadfcb3c21fd09d0b22804b49de9a82cf7Maciej Cencora * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */
256acb26eadfcb3c21fd09d0b22804b49de9a82cf7Maciej Cencora
266a448a525baf81173f92ee8c3074b98baa54397bCorbin Simpson#include "draw/draw_context.h"
2781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson#include "draw/draw_vbuf.h"
286a448a525baf81173f92ee8c3074b98baa54397bCorbin Simpson
296a448a525baf81173f92ee8c3074b98baa54397bCorbin Simpson#include "pipe/p_inlines.h"
306a448a525baf81173f92ee8c3074b98baa54397bCorbin Simpson
31e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson#include "util/u_memory.h"
32f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson#include "util/u_prim.h"
33e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
343445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora#include "r300_vbo.h"
35f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson#include "r300_cs.h"
36e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson#include "r300_context.h"
371ddb22675c123fc955ad3ab46bba45d3330d2ec4Nicolai Hähnle#include "r300_emit.h"
38e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson#include "r300_reg.h"
391f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson#include "r300_render.h"
4065021162a494cfffd6b0d50d3e93fb1082e90332Corbin Simpson#include "r300_state_derived.h"
41e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
425c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson/* r300_render: Vertex and index buffer primitive emission. */
43622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan#define R300_MAX_VBO_SIZE  (1024 * 1024)
44e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
456acb26eadfcb3c21fd09d0b22804b49de9a82cf7Maciej Cencorauint32_t r300_translate_primitive(unsigned prim)
461f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson{
471f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    switch (prim) {
481f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_POINTS:
491f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_POINTS;
501f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_LINES:
511f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_LINES;
521f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_LINE_LOOP:
531f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_LINE_LOOP;
541f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_LINE_STRIP:
551f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_LINE_STRIP;
561f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_TRIANGLES:
571f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_TRIANGLES;
581f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_TRIANGLE_STRIP:
591f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP;
601f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_TRIANGLE_FAN:
611f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN;
621f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_QUADS:
631f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_QUADS;
641f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_QUAD_STRIP:
651f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP;
661f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        case PIPE_PRIM_POLYGON:
671f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return R300_VAP_VF_CNTL__PRIM_POLYGON;
681f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        default:
691f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            return 0;
701f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
711f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson}
721f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
733445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencorastatic boolean setup_vertex_buffers(struct r300_context *r300)
741f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson{
753445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    unsigned vbuf_count = r300->aos_count;
763445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    struct pipe_vertex_buffer *vbuf= r300->vertex_buffer;
773445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    struct pipe_vertex_element *velem= r300->vertex_element;
783445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    bool invalid = false;
79f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson
801f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpsonvalidate:
813445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    for (int i = 0; i < vbuf_count; i++) {
823445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora        if (!r300->winsys->add_buffer(r300->winsys, vbuf[velem[i].vertex_buffer_index].buffer,
833445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora            RADEON_GEM_DOMAIN_GTT, 0)) {
843445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora            r300->context.flush(&r300->context, 0, NULL);
851f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            goto validate;
861f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        }
871f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
883445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
891f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    if (!r300->winsys->validate(r300->winsys)) {
903445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora        r300->context.flush(&r300->context, 0, NULL);
911f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        if (invalid) {
921f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            /* Well, hell. */
931f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            debug_printf("r300: Stuck in validation loop, gonna quit now.");
941f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            exit(1);
951f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        }
963445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora        invalid = true;
971f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        goto validate;
981f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
991f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1003445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    return invalid;
1013445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora}
1021f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1033445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora/* This is the fast-path drawing & emission for HW TCL. */
1043445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencoraboolean r300_draw_range_elements(struct pipe_context* pipe,
1053445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 struct pipe_buffer* indexBuffer,
1063445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned indexSize,
1073445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned minIndex,
1083445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned maxIndex,
1093445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned mode,
1103445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned start,
1113445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                                 unsigned count)
1123445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora{
1133445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    struct r300_context* r300 = r300_context(pipe);
1141f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1153445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_update_derived_state(r300);
1161f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1173445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    setup_vertex_buffers(r300);
1181f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1193445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    setup_vertex_attributes(r300);
1203445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1213445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    setup_index_buffer(r300, indexBuffer, indexSize);
1223445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1233445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300->hw_prim = r300_translate_primitive(mode);
1243445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1253445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_dirty_state(r300);
1263445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1273445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_aos(r300, 0);
1283445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1293445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex,
1303445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora                            start, count);
1311f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1321f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    return TRUE;
1331f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson}
1341f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1351f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson/* Simple helpers for context setup. Should probably be moved to util. */
1361f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpsonboolean r300_draw_elements(struct pipe_context* pipe,
1371f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                           struct pipe_buffer* indexBuffer,
1381f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                           unsigned indexSize, unsigned mode,
1391f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                           unsigned start, unsigned count)
1401f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson{
1411f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    return pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0,
1421f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                     mode, start, count);
1431f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson}
1441f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1451f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpsonboolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
1461f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                         unsigned start, unsigned count)
1471f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson{
1483445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    struct r300_context* r300 = r300_context(pipe);
1493445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1503445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_update_derived_state(r300);
1513445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1523445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    setup_vertex_buffers(r300);
1533445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1543445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    setup_vertex_attributes(r300);
1553445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1563445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300->hw_prim = r300_translate_primitive(mode);
1573445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1583445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_dirty_state(r300);
1593445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1603445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_aos(r300, start);
1613445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1623445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    r300_emit_draw_arrays(r300, count);
1633445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora
1643445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    return TRUE;
1651f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson}
1661f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1671f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson/****************************************************************************
1681f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson * The rest of this file is for SW TCL rendering only. Please be polite and *
1691f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson * keep these functions separated so that they are easier to locate. ~C.    *
1701f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson ***************************************************************************/
1711f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1721f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson/* Draw-based drawing for SW TCL chipsets. */
1731f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpsonboolean r300_swtcl_draw_range_elements(struct pipe_context* pipe,
1741f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       struct pipe_buffer* indexBuffer,
1751f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned indexSize,
1761f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned minIndex,
1771f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned maxIndex,
1781f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned mode,
1791f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned start,
1801f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                       unsigned count)
1811f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson{
1823445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora    assert(0);
1831f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    struct r300_context* r300 = r300_context(pipe);
1843445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora#if 0
1851f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    int i;
1861f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
187f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson    if (!u_trim_pipe_prim(mode, &count)) {
188f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson        return FALSE;
189f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson    }
190f3d8d534e6f1d102d71338d58fbaa98c382f1858Corbin Simpson
1911f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    for (i = 0; i < r300->vertex_buffer_count; i++) {
1921f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        void* buf = pipe_buffer_map(pipe->screen,
1931f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                    r300->vertex_buffers[i].buffer,
1941f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                    PIPE_BUFFER_USAGE_CPU_READ);
1951f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        draw_set_mapped_vertex_buffer(r300->draw, i, buf);
1961f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
1971f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
1981f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    if (indexBuffer) {
1991f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        void* indices = pipe_buffer_map(pipe->screen, indexBuffer,
2001f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                        PIPE_BUFFER_USAGE_CPU_READ);
2011f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        draw_set_mapped_element_buffer_range(r300->draw, indexSize,
2021f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                             minIndex, maxIndex, indices);
2031f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    } else {
2041f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        draw_set_mapped_element_buffer(r300->draw, 0, NULL);
2051f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
2061f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
2071f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    draw_set_mapped_constant_buffer(r300->draw,
2081f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            r300->shader_constants[PIPE_SHADER_VERTEX].constants,
2091f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson            r300->shader_constants[PIPE_SHADER_VERTEX].count *
2101f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                (sizeof(float) * 4));
2111f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
2121f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    draw_arrays(r300->draw, mode, start, count);
2131f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
2141f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    for (i = 0; i < r300->vertex_buffer_count; i++) {
2151f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        pipe_buffer_unmap(pipe->screen, r300->vertex_buffers[i].buffer);
2161f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
2171f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
2181f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
2191f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    if (indexBuffer) {
2201f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        pipe_buffer_unmap(pipe->screen, indexBuffer);
2211f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson        draw_set_mapped_element_buffer_range(r300->draw, 0, start,
2221f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson                                             start + count - 1, NULL);
2231f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    }
2243445f476977ae403cef9ca15661fa0f96ff50ecaMaciej Cencora#endif
2251f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson    return TRUE;
2261f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson}
2271f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson
2281f7f9bab8139681e1dcbc6c10fb42965059d1395Corbin Simpson/* Object for rendering using Draw. */
2295c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstruct r300_render {
230e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson    /* Parent class */
23181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct vbuf_render base;
2324b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle
23381daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    /* Pipe context */
234e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson    struct r300_context* r300;
23581daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
23681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    /* Vertex information */
23781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    size_t vertex_size;
23881daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    unsigned prim;
23981daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    unsigned hwprim;
24081daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
24181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    /* VBO */
24281daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct pipe_buffer* vbo;
243622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    size_t vbo_size;
244622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    size_t vbo_offset;
245622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    size_t vbo_max_used;
246622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    void * vbo_ptr;
247e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson};
248e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
2495c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic INLINE struct r300_render*
2505c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonr300_render(struct vbuf_render* render)
25181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson{
2525c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    return (struct r300_render*)render;
253e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
254e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
25581daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpsonstatic const struct vertex_info*
2565c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonr300_render_get_vertex_info(struct vbuf_render* render)
257f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson{
2585c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
25981daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct r300_context* r300 = r300render->r300;
26081daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
26181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    r300_update_derived_state(r300);
26281daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
263fc8a156cfc539b9c04dc3527e4fc61cb4b0b688eCorbin Simpson    return &r300->vertex_info->vinfo;
264f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson}
265f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson
2665c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic boolean r300_render_allocate_vertices(struct vbuf_render* render,
26781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson                                                   ushort vertex_size,
26881daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson                                                   ushort count)
269e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
2705c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
27181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct r300_context* r300 = r300render->r300;
27281daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct pipe_screen* screen = r300->context.screen;
27381daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    size_t size = (size_t)vertex_size * (size_t)count;
274f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson
275751aa58e01bd2b4f35aa0e1477d77a0dc5490f39Nicolai Hähnle    if (size + r300render->vbo_offset > r300render->vbo_size)
276622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    {
2778c8b77a5f3ec1dac0bddc98da3ccbb64f58f22e0Maciej Cencora        pipe_buffer_reference(&r300->vbo, NULL);
27845b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt        r300render->vbo = pipe_buffer_create(screen,
27945b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt                                             64,
28045b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt                                             PIPE_BUFFER_USAGE_VERTEX,
281622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan                                             R300_MAX_VBO_SIZE);
282751aa58e01bd2b4f35aa0e1477d77a0dc5490f39Nicolai Hähnle        r300render->vbo_offset = 0;
283622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan        r300render->vbo_size = R300_MAX_VBO_SIZE;
28445b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    }
285f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson
28681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    r300render->vertex_size = vertex_size;
287622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300->vbo = r300render->vbo;
288622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300->vbo_offset = r300render->vbo_offset;
289f097465bb85d3ca212a23c2dcc9cf73988de9160Corbin Simpson
29045b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    return (r300render->vbo) ? TRUE : FALSE;
291e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
292e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
2935c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void* r300_render_map_vertices(struct vbuf_render* render)
294e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
2955c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
29681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct pipe_screen* screen = r300render->r300->context.screen;
29781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
298622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo_ptr = pipe_buffer_map(screen, r300render->vbo,
299622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan                                          PIPE_BUFFER_USAGE_CPU_WRITE);
300622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan
301622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    return (r300render->vbo_ptr + r300render->vbo_offset);
302e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
303e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3045c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void r300_render_unmap_vertices(struct vbuf_render* render,
305b003b2f6dd4ddba45910560ab6d495fb01b5301bCorbin Simpson                                             ushort min,
306b003b2f6dd4ddba45910560ab6d495fb01b5301bCorbin Simpson                                             ushort max)
307e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
3085c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
30981daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct pipe_screen* screen = r300render->r300->context.screen;
310622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    CS_LOCALS(r300render->r300);
311622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    BEGIN_CS(2);
312622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max);
313622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    END_CS;
31481daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
315751aa58e01bd2b4f35aa0e1477d77a0dc5490f39Nicolai Hähnle    r300render->vbo_max_used = MAX2(r300render->vbo_max_used,
316622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan                                    r300render->vertex_size * (max + 1));
31781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    pipe_buffer_unmap(screen, r300render->vbo);
318e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
319e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3205c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void r300_render_release_vertices(struct vbuf_render* render)
321e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
3225c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
32381daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
324622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo_offset += r300render->vbo_max_used;
325622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo_max_used = 0;
326e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
327e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3285c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic boolean r300_render_set_primitive(struct vbuf_render* render,
32981daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson                                               unsigned prim)
330e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
3315c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
33281daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
33306e464c2d57552d5ccde2b98885aeef953d8b2a1Corbin Simpson    r300render->prim = prim;
33406e464c2d57552d5ccde2b98885aeef953d8b2a1Corbin Simpson    r300render->hwprim = r300_translate_primitive(prim);
33581daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
336fd5411fe362a398ab0506c2becdd5953711476d5Corbin Simpson    return TRUE;
337e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
338e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3395c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void r300_render_draw_arrays(struct vbuf_render* render,
340922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson                                          unsigned start,
341922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson                                          unsigned count)
342922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson{
3435c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
344922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson    struct r300_context* r300 = r300render->r300;
345922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson
346922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson    CS_LOCALS(r300);
347922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson
34806e464c2d57552d5ccde2b98885aeef953d8b2a1Corbin Simpson    r300_emit_dirty_state(r300);
349922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson
3504b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle    DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count);
351d265706cd3849679e543797b4ad4edf463cd4586Corbin Simpson
3528e234d655dc3d8f8edefbf3bffdb726a331da2cdCorbin Simpson    BEGIN_CS(2);
3538066edb2a254d15ed92c2d350a7799adf3cca0d7Corbin Simpson    OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
354d265706cd3849679e543797b4ad4edf463cd4586Corbin Simpson    OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
35565021162a494cfffd6b0d50d3e93fb1082e90332Corbin Simpson           r300render->hwprim);
356922000d38a6e90c525328b381f04fea1244f616fCorbin Simpson    END_CS;
3578e234d655dc3d8f8edefbf3bffdb726a331da2cdCorbin Simpson}
3588e234d655dc3d8f8edefbf3bffdb726a331da2cdCorbin Simpson
3595c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void r300_render_draw(struct vbuf_render* render,
36081daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson                                   const ushort* indices,
36181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson                                   uint count)
362e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
3635c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = r300_render(render);
36481daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    struct r300_context* r300 = r300render->r300;
365a4e0a46a8d6a4f308216c085849305ad82c52f15Corbin Simpson    int i;
36681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
36781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    CS_LOCALS(r300);
36881daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
36906e464c2d57552d5ccde2b98885aeef953d8b2a1Corbin Simpson    r300_emit_dirty_state(r300);
37081daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
371622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    BEGIN_CS(2 + (count+1)/2);
37245b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2);
373a4e0a46a8d6a4f308216c085849305ad82c52f15Corbin Simpson    OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
37445b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt           r300render->hwprim);
37545b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    for (i = 0; i < count-1; i += 2) {
37645b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt        OUT_CS(indices[i+1] << 16 | indices[i]);
37745b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    }
37845b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt    if (count % 2) {
37945b77830eb6fa1b712b0416a27990ad8b6eaf78bJoakim Sindholt        OUT_CS(indices[count-1]);
380a4e0a46a8d6a4f308216c085849305ad82c52f15Corbin Simpson    }
38181daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    END_CS;
382e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
383e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3845c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic void r300_render_destroy(struct vbuf_render* render)
385e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
38681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    FREE(render);
387e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
388e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
3895c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstatic struct vbuf_render* r300_render_create(struct r300_context* r300)
390e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson{
3915c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    struct r300_render* r300render = CALLOC_STRUCT(r300_render);
39281daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
39381daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    r300render->r300 = r300;
39481daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
39581daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    /* XXX find real numbers plz */
39681daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    r300render->base.max_vertex_buffer_bytes = 128 * 1024;
39781daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    r300render->base.max_indices = 16 * 1024;
39881daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson
3995c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.get_vertex_info = r300_render_get_vertex_info;
4005c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.allocate_vertices = r300_render_allocate_vertices;
4015c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.map_vertices = r300_render_map_vertices;
4025c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.unmap_vertices = r300_render_unmap_vertices;
4035c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.set_primitive = r300_render_set_primitive;
4045c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.draw = r300_render_draw;
4055c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.draw_arrays = r300_render_draw_arrays;
4065c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.release_vertices = r300_render_release_vertices;
4075c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    r300render->base.destroy = r300_render_destroy;
408e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson
409622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo = NULL;
410622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo_size = 0;
411622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan    r300render->vbo_offset = 0;
412622b31925b6a68b496cd65c627b8a1ed7e811cc3Cooper Yuan
41381daa5323efbe798b11ea73d7ba289f3bb5e24cfCorbin Simpson    return &r300render->base;
414e5018a5675603ec26e833bc0808e4150a6bba16aCorbin Simpson}
41546ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
4165c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpsonstruct draw_stage* r300_draw_stage(struct r300_context* r300)
41746ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson{
41846ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    struct vbuf_render* render;
41946ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    struct draw_stage* stage;
42046ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
4215c50218d009a4c8276aa561bd1483742cf6aa20eCorbin Simpson    render = r300_render_create(r300);
42246ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
42346ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    if (!render) {
42446ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson        return NULL;
42546ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    }
42646ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
42746ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    stage = draw_vbuf_stage(r300->draw, render);
42846ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
42946ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    if (!stage) {
43046ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson        render->destroy(render);
43146ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson        return NULL;
43246ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    }
43346ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
43446ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    draw_set_render(r300->draw, render);
43546ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson
43646ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson    return stage;
43746ef26eb90a28b009de9349f38f36972d828a575Corbin Simpson}
438