draw_pt_emit.c revision 8c3cc83432bbbc190b0f71f87e3e9583ae11f0b2
1c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell/************************************************************************** 2c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 3c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * All Rights Reserved. 5c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 6c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 7c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * copy of this software and associated documentation files (the 8c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * "Software"), to deal in the Software without restriction, including 9c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 10c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 11c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to 12c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * the following conditions: 13c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 14c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * The above copyright notice and this permission notice (including the 15c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * next paragraph) shall be included in all copies or substantial portions 16c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * of the Software. 17c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 18c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell * 26c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell **************************************************************************/ 27c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 284f25420bdd834e81a3e22733304efc5261c2998aBrian Paul#include "util/u_memory.h" 29c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_context.h" 30c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_private.h" 31c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_vbuf.h" 32c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_vertex.h" 33c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "draw/draw_pt.h" 34c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell#include "translate/translate.h" 355fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin#include "translate/translate_cache.h" 36c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 37c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellstruct pt_emit { 38c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw; 39c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 40c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate *translate; 41f088b53769aacbee20135d912c33d688b6002011Zack Rusin 425fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin struct translate_cache *cache; 43d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell unsigned prim; 44fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 45fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell const struct vertex_info *vinfo; 46c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell}; 47c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 48c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit_prepare( struct pt_emit *emit, 490a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell unsigned prim, 500a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell unsigned *max_vertices ) 51c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 52c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 53c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell const struct vertex_info *vinfo; 54c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned dst_offset; 55c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate_key hw_key; 56c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned i; 57c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell boolean ok; 58d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 59aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 60aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell */ 61aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 62aa16e3a2750993afdba16c24237bb6d8d8e4d91aKeith Whitwell 63c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 64d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell /* XXX: may need to defensively reset this later on as clipping can 65d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell * clobber this state in the render backend. 66d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell */ 67d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell emit->prim = prim; 68d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 69d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell ok = draw->render->set_primitive(draw->render, emit->prim); 70c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!ok) { 71c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell assert(0); 72c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return; 73c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 74c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 75c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell /* Must do this after set_primitive() above: 76c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 77fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell emit->vinfo = vinfo = draw->render->get_vertex_info(draw->render); 787ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell 79c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 80cb9f0a589623397c3437911aeef39f189213527aKeith Whitwell /* Translate from pipeline vertices to hw vertices. 81c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 82c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset = 0; 83c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell for (i = 0; i < vinfo->num_attribs; i++) { 84c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned emit_sz = 0; 85c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned src_buffer = 0; 86c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell unsigned output_format; 8753d4706c6c0922160f310834daaec5718ff1c511Keith Whitwell unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) ); 88c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 8984a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); 9084a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); 91c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 9284a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz /* doesn't handle EMIT_OMIT */ 9384a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz assert(emit_sz != 0); 9484a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz 9584a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7Jakob Bornecrantz if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { 96c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_buffer = 1; 97c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell src_offset = 0; 98c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 99543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol 100543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; 101c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 102c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_buffer = src_buffer; 103c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].input_offset = src_offset; 1047ca0ce38340144794267609646048b3820d594abMichal Krol hw_key.element[i].instance_divisor = 0; 105c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_format = output_format; 106c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.element[i].output_offset = dst_offset; 107c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 108c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell dst_offset += emit_sz; 109c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 110c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 111c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.nr_elements = vinfo->num_attribs; 112c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_key.output_stride = vinfo->size * 4; 113c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 114c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit->translate || 1157ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_key_compare(&emit->translate->key, &hw_key) != 0) 116c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell { 1177ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_key_sanitize(&hw_key); 1185fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin emit->translate = translate_cache_find(emit->cache, &hw_key); 119c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 1200a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell 1210a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell *max_vertices = (draw->render->max_vertex_buffer_bytes / 1220a4aea0e86a897d9afb9f2a0ec27f03faf8f1b21Keith Whitwell (vinfo->size * 4)); 123f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul 124f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul /* even number */ 125f1401385587882bb9d18a5f5b01dcbb71ddf0a2fBrian Paul *max_vertices = *max_vertices & ~1; 126c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 127c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 128c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 129c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit( struct pt_emit *emit, 130b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const struct draw_vertex_info *vert_info, 131b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const struct draw_prim_info *prim_info) 132c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 133b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; 134b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned vertex_count = vert_info->count; 135b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned stride = vert_info->stride; 136b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const ushort *elts = prim_info->elts; 137c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct draw_context *draw = emit->draw; 138c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct translate *translate = emit->translate; 139c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct vbuf_render *render = draw->render; 140b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned start, i; 141c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell void *hw_verts; 142c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 143c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 144c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell */ 145c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 146c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1471c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell if (vertex_count == 0) 1481c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell return; 1491c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell 150b716de47798defa7d22b0f15b201af6fba27f0b9Alan Hourihane if (vertex_count >= UNDEFINED_VERTEX_ID) { 151a8e7852b05f95cc695f3a05692a6ccd36298faf7Alan Hourihane assert(0); 152a8e7852b05f95cc695f3a05692a6ccd36298faf7Alan Hourihane return; 153a8e7852b05f95cc695f3a05692a6ccd36298faf7Alan Hourihane } 154e3f5370d637f367dbfe7d21f726e84185ad1e07dAlan Hourihane 155d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell /* XXX: and work out some way to coordinate the render primitive 156d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell * between vbuf.c and here... 157d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell */ 158d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell if (!draw->render->set_primitive(draw->render, emit->prim)) { 159d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell assert(0); 160d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell return; 161d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell } 162d80c24a81a9a46c132fe877dde6919a57cacf8c0Keith Whitwell 163befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->allocate_vertices(render, 164befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)translate->key.output_stride, 165befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)vertex_count); 166befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 167befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell hw_verts = render->map_vertices( render ); 168c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!hw_verts) { 169c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell assert(0); 170c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return; 171c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell } 172c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 173c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->set_buffer(translate, 174c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 0, 175a773f06e969a3992451dd7fe6fd55ea96b2774faKeith Whitwell vertex_data, 1762a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca stride, 1772a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0); 178c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 179c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->set_buffer(translate, 180c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1, 181c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell &draw->rasterizer->point_size, 1822a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, 1832a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca ~0); 184c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 1858c3cc83432bbbc190b0f71f87e3e9583ae11f0b2Brian Paul /* fetch/translate vertex attribs to fill hw_verts[] */ 186c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell translate->run( translate, 187c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 0, 188c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell vertex_count, 1897ca0ce38340144794267609646048b3820d594abMichal Krol draw->instance_id, 190c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell hw_verts ); 191c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 192befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->unmap_vertices( render, 193befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 0, 1941c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell vertex_count - 1 ); 195befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 196b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell for (start = i = 0; 197b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell i < prim_info->primitive_count; 198b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start += prim_info->primitive_lengths[i], i++) 199b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell { 200b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell render->draw_elements(render, 201b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell elts + start, 202b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell prim_info->primitive_lengths[i]); 203b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell } 204c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 205befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->release_vertices(render); 206c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 207c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 208c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 209abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusinvoid draw_pt_emit_linear(struct pt_emit *emit, 210b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const struct draw_vertex_info *vert_info, 211b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const struct draw_prim_info *prim_info) 212abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin{ 213b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell const float (*vertex_data)[4] = (const float (*)[4])vert_info->verts->data; 214b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned stride = vert_info->stride; 215b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned count = vert_info->count; 216abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct draw_context *draw = emit->draw; 217abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct translate *translate = emit->translate; 218abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin struct vbuf_render *render = draw->render; 219abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin void *hw_verts; 220b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell unsigned start, i; 221abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 22266d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#if 0 22366d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin debug_printf("Linear emit\n"); 22466d72f176de2568f053c6dc54e93d423723ae8aaZack Rusin#endif 225abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin /* XXX: need to flush to get prim_vbuf.c to release its allocation?? 226abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin */ 227abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin draw_do_flush( draw, DRAW_FLUSH_BACKEND ); 228abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 229befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (count >= UNDEFINED_VERTEX_ID) 230befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 231a8e7852b05f95cc695f3a05692a6ccd36298faf7Alan Hourihane 23293bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell /* XXX: and work out some way to coordinate the render primitive 23393bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell * between vbuf.c and here... 23493bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell */ 235befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (!draw->render->set_primitive(draw->render, emit->prim)) 236befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 23793bfc94c351a2eafd43ac7a20b362d969f98d86aKeith Whitwell 238befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (!render->allocate_vertices(render, 239befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)translate->key.output_stride, 240befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell (ushort)count)) 241befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 242befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 243befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell hw_verts = render->map_vertices( render ); 244befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell if (!hw_verts) 245befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell goto fail; 246abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 247abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 0, 2482a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca vertex_data, stride, count - 1); 249abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 250abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->set_buffer(translate, 1, 251abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin &draw->rasterizer->point_size, 2522a30d3d74a0b87f8066659952628ccd072a4e2b0José Fonseca 0, ~0); 253abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 254abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin translate->run(translate, 255abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 0, 256befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell count, 2577ca0ce38340144794267609646048b3820d594abMichal Krol draw->instance_id, 258abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin hw_verts); 259abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 260fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell if (0) { 261fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell unsigned i; 262befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell for (i = 0; i < count; i++) { 263fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell debug_printf("\n\n%s vertex %d:\n", __FUNCTION__, i); 264fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell draw_dump_emitted_vertex( emit->vinfo, 265fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell (const uint8_t *)hw_verts + 266fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell translate->key.output_stride * i ); 267fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 268fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell } 269fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 2701c4f67b980b6bec5788336a9cdd18c4fcec5e492Keith Whitwell render->unmap_vertices( render, 0, count - 1 ); 271befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 272b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell for (start = i = 0; 273b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell i < prim_info->primitive_count; 274b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start += prim_info->primitive_lengths[i], i++) 275b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell { 276b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell render->draw_arrays(render, 277b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell start, 278b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell prim_info->primitive_lengths[i]); 279b85a361ccbac956d2842251395c048a4b3f4c440Keith Whitwell } 280befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell 281befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell render->release_vertices(render); 282fd20d1c7e8bbe2f40d73679b1514023772cfd8f6Keith Whitwell 283befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell return; 284abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 285befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwellfail: 286befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell assert(0); 287befa4ff50ec4728de70c04532f8c7342fbd70147Keith Whitwell return; 288abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin} 289abb08e9335b5d7cb004dc9e6cec390ab6968abe5Zack Rusin 290c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellstruct pt_emit *draw_pt_emit_create( struct draw_context *draw ) 291c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 292c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell struct pt_emit *emit = CALLOC_STRUCT(pt_emit); 293c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell if (!emit) 294c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return NULL; 295c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 296c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell emit->draw = draw; 2975fcd84ab39318a371253b1a7285bc657fb82efedZack Rusin emit->cache = translate_cache_create(); 29895f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin if (!emit->cache) { 29995f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin FREE(emit); 30095f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin return NULL; 30195f8f8863a80ce1e584160d4d085213a9bbaef12Zack Rusin } 302c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 303c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell return emit; 304c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 305c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 306c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwellvoid draw_pt_emit_destroy( struct pt_emit *emit ) 307c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell{ 3087ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell if (emit->cache) 3097ddb925b8bc6c18eba953e34d2b630a3a6593f05Keith Whitwell translate_cache_destroy(emit->cache); 310c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell 311c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell FREE(emit); 312c503e55d74cf84f87f82b3dab3cb4d38b201d47aKeith Whitwell} 313