r300_render.c revision c9167d868cfb2ba821f01e0217e3880c5df4c97b
1ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe/* 2da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com> 3da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * 4da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * Permission is hereby granted, free of charge, to any person obtaining a 5da751ca9665bcdeca56d2eec5b629a0953c07662Jens Axboe * copy of this software and associated documentation files (the "Software"), 6ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * to deal in the Software without restriction, including without limitation 7ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * on the rights to use, copy, modify, merge, publish, distribute, sub 8ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * license, and/or sell copies of the Software, and to permit persons to whom 9ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * the Software is furnished to do so, subject to the following conditions: 10ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * 11ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * The above copyright notice and this permission notice (including the next 12ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * paragraph) shall be included in all copies or substantial portions of the 13ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * Software. 14ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * 155fdd124a3b811993542825847f207587d5f4661eJens Axboe * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167292056a38857ded6f7a64f11d14d642772c31bdJens Axboe * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 170fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 187292056a38857ded6f7a64f11d14d642772c31bdJens Axboe * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 190fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 22ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 23b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe/* r300_render: Vertex and index buffer primitive emission. Contains both 24b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe * HW TCL fastpath rendering, and SW TCL Draw-assisted rendering. */ 259cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 269cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe#include "draw/draw_context.h" 27b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe#include "draw/draw_vbuf.h" 280fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 29b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe#include "pipe/p_inlines.h" 30ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 31de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "util/u_memory.h" 32de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "util/u_prim.h" 33de890a1e48d40238dac69f302708dde8719de240Steven Lang 34de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "r300_cs.h" 35de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "r300_context.h" 36de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "r300_emit.h" 37de890a1e48d40238dac69f302708dde8719de240Steven Lang#include "r300_reg.h" 38664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe#include "r300_render.h" 39664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe#include "r300_state_derived.h" 40664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe#include "r300_vbo.h" 41664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 42664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe/* r300_render: Vertex and index buffer primitive emission. */ 43664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe#define R300_MAX_VBO_SIZE (1024 * 1024) 44664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 45664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboeuint32_t r300_translate_primitive(unsigned prim) 460fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe{ 470fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe switch (prim) { 480fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe case PIPE_PRIM_POINTS: 490fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe return R300_VAP_VF_CNTL__PRIM_POINTS; 50664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe case PIPE_PRIM_LINES: 51664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return R300_VAP_VF_CNTL__PRIM_LINES; 52de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_LINE_LOOP: 53de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_LINE_LOOP; 54de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_LINE_STRIP: 55de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_LINE_STRIP; 56de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_TRIANGLES: 57de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_TRIANGLES; 58de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_TRIANGLE_STRIP: 59de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_TRIANGLE_STRIP; 60de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_TRIANGLE_FAN: 61de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_TRIANGLE_FAN; 62de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_QUADS: 63de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_QUADS; 64de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_QUAD_STRIP: 65de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_QUAD_STRIP; 66de890a1e48d40238dac69f302708dde8719de240Steven Lang case PIPE_PRIM_POLYGON: 67de890a1e48d40238dac69f302708dde8719de240Steven Lang return R300_VAP_VF_CNTL__PRIM_POLYGON; 68de890a1e48d40238dac69f302708dde8719de240Steven Lang default: 69de890a1e48d40238dac69f302708dde8719de240Steven Lang return 0; 70de890a1e48d40238dac69f302708dde8719de240Steven Lang } 71de890a1e48d40238dac69f302708dde8719de240Steven Lang} 72de890a1e48d40238dac69f302708dde8719de240Steven Lang 73de890a1e48d40238dac69f302708dde8719de240Steven Langstatic void r300_emit_draw_arrays(struct r300_context *r300, 74de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned mode, 75de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned count) 76de890a1e48d40238dac69f302708dde8719de240Steven Lang{ 77de890a1e48d40238dac69f302708dde8719de240Steven Lang CS_LOCALS(r300); 78de890a1e48d40238dac69f302708dde8719de240Steven Lang 79de890a1e48d40238dac69f302708dde8719de240Steven Lang BEGIN_CS(4); 80de890a1e48d40238dac69f302708dde8719de240Steven Lang OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count); 81de890a1e48d40238dac69f302708dde8719de240Steven Lang OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); 82f5cc3d0ea8acf13c8e722da6c2d485889968d132Bruce Cran OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | 83de890a1e48d40238dac69f302708dde8719de240Steven Lang r300_translate_primitive(mode)); 84de890a1e48d40238dac69f302708dde8719de240Steven Lang END_CS; 85de890a1e48d40238dac69f302708dde8719de240Steven Lang} 86de890a1e48d40238dac69f302708dde8719de240Steven Lang 87de890a1e48d40238dac69f302708dde8719de240Steven Langstatic void r300_emit_draw_elements(struct r300_context *r300, 88de890a1e48d40238dac69f302708dde8719de240Steven Lang struct pipe_buffer* indexBuffer, 89de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned indexSize, 90de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned minIndex, 91de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned maxIndex, 92de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned mode, 93de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned start, 94de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned count) 95de890a1e48d40238dac69f302708dde8719de240Steven Lang{ 96de890a1e48d40238dac69f302708dde8719de240Steven Lang uint32_t count_dwords; 97de890a1e48d40238dac69f302708dde8719de240Steven Lang uint32_t offset_dwords = indexSize * start / sizeof(uint32_t); 98de890a1e48d40238dac69f302708dde8719de240Steven Lang CS_LOCALS(r300); 99de890a1e48d40238dac69f302708dde8719de240Steven Lang 100de890a1e48d40238dac69f302708dde8719de240Steven Lang /* XXX most of these are stupid */ 101371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe assert(indexSize == 4 || indexSize == 2); 102371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe assert((start * indexSize) % 4 == 0); 103371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe assert(offset_dwords == 0); 104371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe 105371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe BEGIN_CS(10); 106371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); 107371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); 108371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe if (indexSize == 4) { 109371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe count_dwords = count + start; 110371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | 111371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe R300_VAP_VF_CNTL__INDEX_SIZE_32bit | 112371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe r300_translate_primitive(mode)); 113371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe } else { 114371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe count_dwords = (count + start + 1) / 2; 115371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | 116d5b388a560783a61af7b424757bc6dead2309c28Jens Axboe r300_translate_primitive(mode)); 117371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe } 118371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe 119371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe /* INDX_BUFFER is a truly special packet3. 120371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe * Unlike most other packet3, where the offset is after the count, 121371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe * the order is reversed, so the relocation ends up carrying the 122371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe * size of the indexbuf instead of the offset. 123371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe * 124371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe * XXX Fix offset 125371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe */ 126371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); 127371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | 128371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe (0 << R300_INDX_BUFFER_SKIP_SHIFT)); 129371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS(offset_dwords); 130371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe OUT_CS_RELOC(indexBuffer, count_dwords, 131371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe RADEON_GEM_DOMAIN_GTT, 0, 0); 132ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 133ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe END_CS; 134de890a1e48d40238dac69f302708dde8719de240Steven Lang} 135ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 1367a6499dada619928267d26b4629b0c8623dc423aJens Axboe 1377a6499dada619928267d26b4629b0c8623dc423aJens Axboestatic boolean r300_setup_vertex_buffers(struct r300_context *r300) 1387a6499dada619928267d26b4629b0c8623dc423aJens Axboe{ 139de890a1e48d40238dac69f302708dde8719de240Steven Lang struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; 140de890a1e48d40238dac69f302708dde8719de240Steven Lang struct pipe_vertex_element *velem = r300->vertex_element; 141de890a1e48d40238dac69f302708dde8719de240Steven Lang 142de890a1e48d40238dac69f302708dde8719de240Steven Langvalidate: 143de890a1e48d40238dac69f302708dde8719de240Steven Lang for (int i = 0; i < r300->vertex_element_count; i++) { 144e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe if (!r300->winsys->add_buffer(r300->winsys, 1457a6499dada619928267d26b4629b0c8623dc423aJens Axboe vbuf[velem[i].vertex_buffer_index].buffer, 146ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe RADEON_GEM_DOMAIN_GTT, 0)) { 1477a6499dada619928267d26b4629b0c8623dc423aJens Axboe r300->context.flush(&r300->context, 0, NULL); 148f85ac25a7d5c9d5ba4d5c73363a6a2a461a9b013Jens Axboe goto validate; 149ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 150ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe } 1515921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 152cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe if (!r300->winsys->validate(r300->winsys)) { 153ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe r300->context.flush(&r300->context, 0, NULL); 1549cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return r300->winsys->validate(r300->winsys); 1557a6499dada619928267d26b4629b0c8623dc423aJens Axboe } 1569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 157cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return TRUE; 1589cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1599cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1609cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* This is the fast-path drawing & emission for HW TCL. */ 1619cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboeboolean r300_draw_range_elements(struct pipe_context* pipe, 1629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct pipe_buffer* indexBuffer, 1639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned indexSize, 1649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned minIndex, 1659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned maxIndex, 1669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned mode, 1679cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned start, 168f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe unsigned count) 1699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 1709cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct r300_context* r300 = r300_context(pipe); 1719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1729cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!u_trim_pipe_prim(mode, &count)) { 1739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return FALSE; 1749cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 175cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 1769cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (count > 65535) { 177cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return FALSE; 1789cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 1799cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1809cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300_update_derived_state(r300); 181cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 1829cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!r300_setup_vertex_buffers(r300)) { 1839cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return FALSE; 1849cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 185cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 1869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe setup_vertex_attributes(r300); 187cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 188cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe setup_index_buffer(r300, indexBuffer, indexSize); 1899cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 1909cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300_emit_dirty_state(r300); 191cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 192cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_emit_aos(r300, 0); 193cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 194cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex, 195cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe mode, start, count); 196cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 1979cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return TRUE; 1989cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 1999cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2009cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe/* Simple helpers for context setup. Should probably be moved to util. */ 2019cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboeboolean r300_draw_elements(struct pipe_context* pipe, 2029cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct pipe_buffer* indexBuffer, 2039cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned indexSize, unsigned mode, 204cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe unsigned start, unsigned count) 2059cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2069cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0, 2079cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe mode, start, count); 2089cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe} 2099cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2109cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboeboolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode, 2119cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned start, unsigned count) 2129cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct r300_context* r300 = r300_context(pipe); 214cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 215f657a2fbbb0deaf455edc478d73b664929bcb766Jens Axboe if (!u_trim_pipe_prim(mode, &count)) { 2169cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return FALSE; 2179cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 2189cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 219cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe if (count > 65535) { 2209cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return FALSE; 2219cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 2229cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 223cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_update_derived_state(r300); 2249cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 225cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe if (!r300_setup_vertex_buffers(r300)) { 226cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return FALSE; 2279cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 2289cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2299cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe setup_vertex_attributes(r300); 230cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 231cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_emit_dirty_state(r300); 2329cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 233cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_emit_aos(r300, start); 234cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 235cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300_emit_draw_arrays(r300, mode, count); 236cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 237cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return TRUE; 238cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe} 239ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 240cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe/**************************************************************************** 2419cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * The rest of this file is for SW TCL rendering only. Please be polite and * 2429cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe * keep these functions separated so that they are easier to locate. ~C. * 243cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe ***************************************************************************/ 244cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 245cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe/* SW TCL arrays, using Draw. */ 246cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboeboolean r300_swtcl_draw_arrays(struct pipe_context* pipe, 2479cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned mode, 2489cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned start, 2499cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned count) 2509cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe{ 2519cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct r300_context* r300 = r300_context(pipe); 252cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe int i; 253cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe 2549cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe if (!u_trim_pipe_prim(mode, &count)) { 255cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe return FALSE; 2569cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 2579cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 258cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe for (i = 0; i < r300->vertex_buffer_count; i++) { 259cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe void* buf = pipe_buffer_map(pipe->screen, 260cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300->vertex_buffer[i].buffer, 261cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe PIPE_BUFFER_USAGE_CPU_READ); 2629cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe draw_set_mapped_vertex_buffer(r300->draw, i, buf); 2639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe } 2649cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2659cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe draw_set_mapped_element_buffer(r300->draw, 0, NULL); 2669cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 267cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe draw_set_mapped_constant_buffer(r300->draw, 268cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe r300->shader_constants[PIPE_SHADER_VERTEX].constants, 2699cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300->shader_constants[PIPE_SHADER_VERTEX].count * 270cd963e18de21e08ebb2ed86366f07347b4c58e3dJens Axboe (sizeof(float) * 4)); 2719cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 2725921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe draw_arrays(r300->draw, mode, start, count); 2735921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 2745921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe for (i = 0; i < r300->vertex_buffer_count; i++) { 275af8771b9b91eb2cd23a40aaa729bad4f78acb928Jens Axboe pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer); 2765921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe draw_set_mapped_vertex_buffer(r300->draw, i, NULL); 2775921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe } 2785921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe 2795921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe return TRUE; 2805921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe} 281af8771b9b91eb2cd23a40aaa729bad4f78acb928Jens Axboe 2825921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe/* SW TCL elements, using Draw. */ 2835921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboeboolean r300_swtcl_draw_range_elements(struct pipe_context* pipe, 2845921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe struct pipe_buffer* indexBuffer, 2859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned indexSize, 2869cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned minIndex, 2879cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned maxIndex, 288414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe unsigned mode, 289de890a1e48d40238dac69f302708dde8719de240Steven Lang unsigned start, 2908e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe unsigned count) 291371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe{ 292664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct r300_context* r300 = r300_context(pipe); 293de890a1e48d40238dac69f302708dde8719de240Steven Lang int i; 29462b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe 29562b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe if (!u_trim_pipe_prim(mode, &count)) { 296664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return FALSE; 29762b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe } 29862b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe 299664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe for (i = 0; i < r300->vertex_buffer_count; i++) { 300664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe void* buf = pipe_buffer_map(pipe->screen, 301664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe r300->vertex_buffer[i].buffer, 302664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe PIPE_BUFFER_USAGE_CPU_READ); 3035921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe draw_set_mapped_vertex_buffer(r300->draw, i, buf); 304664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe } 305664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 306664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe void* indices = pipe_buffer_map(pipe->screen, indexBuffer, 3075921e80c5dfc9f96d2f21da6ae58f2b5d3a0b373Jens Axboe PIPE_BUFFER_USAGE_CPU_READ); 308664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_set_mapped_element_buffer_range(r300->draw, indexSize, 309664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe minIndex, maxIndex, indices); 310664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 311664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_set_mapped_constant_buffer(r300->draw, 312664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe r300->shader_constants[PIPE_SHADER_VERTEX].constants, 3139cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300->shader_constants[PIPE_SHADER_VERTEX].count * 314664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe (sizeof(float) * 4)); 315664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 316664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_arrays(r300->draw, mode, start, count); 317664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 3188e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe for (i = 0; i < r300->vertex_buffer_count; i++) { 319664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe pipe_buffer_unmap(pipe->screen, r300->vertex_buffer[i].buffer); 320664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_set_mapped_vertex_buffer(r300->draw, i, NULL); 321664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe } 322664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 323664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe pipe_buffer_unmap(pipe->screen, indexBuffer); 324664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_set_mapped_element_buffer_range(r300->draw, 0, start, 325664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe start + count - 1, NULL); 326664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 327664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return TRUE; 328664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe} 329664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 330664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe/* Object for rendering using Draw. */ 331664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboestruct r300_render { 332664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe /* Parent class */ 333664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct vbuf_render base; 334664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 335664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe /* Pipe context */ 336664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct r300_context* r300; 337664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 3389cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe /* Vertex information */ 3399cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe size_t vertex_size; 340414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe unsigned prim; 3419cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe unsigned hwprim; 342414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 343de890a1e48d40238dac69f302708dde8719de240Steven Lang /* VBO */ 3448e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe struct pipe_buffer* vbo; 345664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe size_t vbo_size; 346664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe size_t vbo_offset; 347de890a1e48d40238dac69f302708dde8719de240Steven Lang size_t vbo_max_used; 3485ba13ea6968cf2773f10d34376afe28ef81aeee5Jens Axboe void * vbo_ptr; 34962b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe}; 350664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 351664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboestatic INLINE struct r300_render* 35262b38926a8f02a03534813fc80e73e5e169bf03eJens Axboer300_render(struct vbuf_render* render) 353664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe{ 354664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return (struct r300_render*)render; 355664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe} 356664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 357664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboestatic const struct vertex_info* 358664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboer300_render_get_vertex_info(struct vbuf_render* render) 359664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe{ 360664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct r300_render* r300render = r300_render(render); 361664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct r300_context* r300 = r300render->r300; 362664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 3639cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300_update_derived_state(r300); 364664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 365664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return &r300->vertex_info->vinfo; 366664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe} 3678e239cae8aae89f07a885ffcc985600ce9c65d5dJens Axboe 368664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboestatic boolean r300_render_allocate_vertices(struct vbuf_render* render, 369664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe ushort vertex_size, 370414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe ushort count) 371664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe{ 3729cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct r300_render* r300render = r300_render(render); 3739cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct r300_context* r300 = r300render->r300; 3749cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe struct pipe_screen* screen = r300->context.screen; 3759cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe size_t size = (size_t)vertex_size * (size_t)count; 3769cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe 377de890a1e48d40238dac69f302708dde8719de240Steven Lang if (size + r300render->vbo_offset > r300render->vbo_size) 3789cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe { 3799cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe pipe_buffer_reference(&r300->vbo, NULL); 3807101d9c24abec4be58a086d85d6d92ec6e6492e9Jens Axboe r300render->vbo = pipe_buffer_create(screen, 3817101d9c24abec4be58a086d85d6d92ec6e6492e9Jens Axboe 64, 3829cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe PIPE_BUFFER_USAGE_VERTEX, 383de890a1e48d40238dac69f302708dde8719de240Steven Lang R300_MAX_VBO_SIZE); 384de890a1e48d40238dac69f302708dde8719de240Steven Lang r300render->vbo_offset = 0; 3859cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe r300render->vbo_size = R300_MAX_VBO_SIZE; 386414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe } 387414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 388d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe r300render->vertex_size = vertex_size; 389de890a1e48d40238dac69f302708dde8719de240Steven Lang r300->vbo = r300render->vbo; 390de890a1e48d40238dac69f302708dde8719de240Steven Lang r300->vbo_offset = r300render->vbo_offset; 391414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 3929cce02e89e01984a5bf58e730fb9311dc5273554Jens Axboe return (r300render->vbo) ? TRUE : FALSE; 393414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe} 394d4f12dd05cfb2e8e7a72604cd870e10f2394914eJens Axboe 3957a6499dada619928267d26b4629b0c8623dc423aJens Axboestatic void* r300_render_map_vertices(struct vbuf_render* render) 396ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 397cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe struct r300_render* r300render = r300_render(render); 39822819ec237297fc39435ed566bee01a4225bfb39Jens Axboe struct pipe_screen* screen = r300render->r300->context.screen; 399cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe 400cec6b55da1c282b5b91ad346c7804171fccf151eJens Axboe r300render->vbo_ptr = pipe_buffer_map(screen, r300render->vbo, 40136167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe PIPE_BUFFER_USAGE_CPU_WRITE); 402414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 403414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe return (r300render->vbo_ptr + r300render->vbo_offset); 404414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe} 405414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 406414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboestatic void r300_render_unmap_vertices(struct vbuf_render* render, 407414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe ushort min, 408414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe ushort max) 409414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe{ 410ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe struct r300_render* r300render = r300_render(render); 411ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe struct pipe_screen* screen = r300render->r300->context.screen; 41236167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe CS_LOCALS(r300render->r300); 413e1161c325f7866bae879e686d1c673ca32ab09aeJens Axboe BEGIN_CS(2); 414ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, max); 41536167d82e5f49dee91c6d2cd426068edee90e36fJens Axboe END_CS; 416ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 417ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe r300render->vbo_max_used = MAX2(r300render->vbo_max_used, 418b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe r300render->vertex_size * (max + 1)); 419ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe pipe_buffer_unmap(screen, r300render->vbo); 420b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe} 421de890a1e48d40238dac69f302708dde8719de240Steven Lang 4220fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboestatic void r300_render_release_vertices(struct vbuf_render* render) 423414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe{ 424de890a1e48d40238dac69f302708dde8719de240Steven Lang struct r300_render* r300render = r300_render(render); 4250fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 426414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe r300render->vbo_offset += r300render->vbo_max_used; 427de890a1e48d40238dac69f302708dde8719de240Steven Lang r300render->vbo_max_used = 0; 4280fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe} 429414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 430de890a1e48d40238dac69f302708dde8719de240Steven Langstatic boolean r300_render_set_primitive(struct vbuf_render* render, 4310fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe unsigned prim) 4320fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe{ 4330fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe struct r300_render* r300render = r300_render(render); 434de890a1e48d40238dac69f302708dde8719de240Steven Lang 4350fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->prim = prim; 4360fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->hwprim = r300_translate_primitive(prim); 4370fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 438ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe return TRUE; 4390fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe} 440b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 441b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic void r300_render_draw_arrays(struct vbuf_render* render, 442b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe unsigned start, 443ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe unsigned count) 444ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe{ 445de890a1e48d40238dac69f302708dde8719de240Steven Lang struct r300_render* r300render = r300_render(render); 446414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe struct r300_context* r300 = r300render->r300; 447de890a1e48d40238dac69f302708dde8719de240Steven Lang 4480fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe CS_LOCALS(r300); 449414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe 4500fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300_emit_dirty_state(r300); 4510fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 452b94cba47cfdf96e72ec894080b3a7bf645a86e9cJens Axboe DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count); 4530fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 4540fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe BEGIN_CS(2); 4550fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); 4560fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | 4570fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->hwprim); 4580fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe END_CS; 4590fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe} 4600fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 4610fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboestatic void r300_render_draw(struct vbuf_render* render, 4620fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe const ushort* indices, 463b94cba47cfdf96e72ec894080b3a7bf645a86e9cJens Axboe uint count) 4640fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe{ 4650fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe struct r300_render* r300render = r300_render(render); 466ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe struct r300_context* r300 = r300render->r300; 467ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe int i; 468ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 469ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe CS_LOCALS(r300); 470ed92ac0ce9ce1cc64697272d307d4fa7d18ed64cJens Axboe 471b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe r300_emit_dirty_state(r300); 4725fdd124a3b811993542825847f207587d5f4661eJens Axboe 473b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe BEGIN_CS(2 + (count+1)/2); 474de890a1e48d40238dac69f302708dde8719de240Steven Lang OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2); 4755ba13ea6968cf2773f10d34376afe28ef81aeee5Jens Axboe OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | 4765fdd124a3b811993542825847f207587d5f4661eJens Axboe r300render->hwprim); 477de890a1e48d40238dac69f302708dde8719de240Steven Lang for (i = 0; i < count-1; i += 2) { 478414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe OUT_CS(indices[i+1] << 16 | indices[i]); 479414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe } 480414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe if (count % 2) { 481414c2a3e741bb7dd7147ce6843f529c7773cea38Jens Axboe OUT_CS(indices[count-1]); 4826d86144dd10b05e8b82e9b895c35dd778e5e71abJens Axboe } 4835fdd124a3b811993542825847f207587d5f4661eJens Axboe END_CS; 484371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe} 485371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe 4860c09442b26216aed16f758712f744a2c54726cdbJens Axboestatic void r300_render_destroy(struct vbuf_render* render) 487371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe{ 488371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe FREE(render); 489371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe} 490371d456c48b73c8a424e4c807c511fc891a38e7dJens Axboe 491b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboestatic struct vbuf_render* r300_render_create(struct r300_context* r300) 4925fdd124a3b811993542825847f207587d5f4661eJens Axboe{ 493b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe struct r300_render* r300render = CALLOC_STRUCT(r300_render); 494b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 495b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe r300render->r300 = r300; 496b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 497b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe /* XXX find real numbers plz */ 4980fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.max_vertex_buffer_bytes = 128 * 1024; 499991802b8a8857c3e8b8d54ae5b0dda589369fec1Yufei Ren r300render->base.max_indices = 16 * 1024; 5000fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe 501991802b8a8857c3e8b8d54ae5b0dda589369fec1Yufei Ren r300render->base.get_vertex_info = r300_render_get_vertex_info; 5020fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.allocate_vertices = r300_render_allocate_vertices; 503b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe r300render->base.map_vertices = r300_render_map_vertices; 5040fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.unmap_vertices = r300_render_unmap_vertices; 5050fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.set_primitive = r300_render_set_primitive; 5060fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.draw = r300_render_draw; 5070fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.draw_arrays = r300_render_draw_arrays; 5080fd666bf0d5fc373f28b1b43d1df817f8ec89605Jens Axboe r300render->base.release_vertices = r300_render_release_vertices; 509b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe r300render->base.destroy = r300_render_destroy; 510b5af82930ccfd7dda6a1b11794efb452eb76d8dcJens Axboe 511664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe r300render->vbo = NULL; 512664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe r300render->vbo_size = 0; 513664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe r300render->vbo_offset = 0; 514664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 51562b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe return &r300render->base; 516664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe} 517664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 518664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboestruct draw_stage* r300_draw_stage(struct r300_context* r300) 519664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe{ 520664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe struct vbuf_render* render; 52162b38926a8f02a03534813fc80e73e5e169bf03eJens Axboe struct draw_stage* stage; 522664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 523664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe render = r300_render_create(r300); 524664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 525664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe if (!render) { 526664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return NULL; 527664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe } 528664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 529de890a1e48d40238dac69f302708dde8719de240Steven Lang stage = draw_vbuf_stage(r300->draw, render); 530664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 531664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe if (!stage) { 532664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe render->destroy(render); 533664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return NULL; 534664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe } 535de890a1e48d40238dac69f302708dde8719de240Steven Lang 536664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe draw_set_render(r300->draw, render); 537664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe 538664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe return stage; 539664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe} 540664fb3bde9ed3b61d0520b6b4f3d0ba9599834b0Jens Axboe