draw_pt_fetch.c revision 5fcd84ab39318a371253b1a7285bc657fb82efed
1/************************************************************************** 2 * 3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include "pipe/p_util.h" 29#include "draw/draw_context.h" 30#include "draw/draw_private.h" 31#include "draw/draw_vbuf.h" 32#include "draw/draw_vertex.h" 33#include "draw/draw_pt.h" 34#include "translate/translate.h" 35#include "translate/translate_cache.h" 36 37 38struct pt_fetch { 39 struct draw_context *draw; 40 41 struct translate *translate; 42 43 unsigned vertex_size; 44 45 struct translate_cache *cache; 46}; 47 48/* Perform the fetch from API vertex elements & vertex buffers, to a 49 * contiguous set of float[4] attributes as required for the 50 * vertex_shader->run_linear() method. 51 * 52 * This is used in all cases except pure passthrough 53 * (draw_pt_fetch_emit.c) which has its own version to translate 54 * directly to hw vertices. 55 * 56 */ 57void draw_pt_fetch_prepare( struct pt_fetch *fetch, 58 unsigned vertex_size ) 59{ 60 struct draw_context *draw = fetch->draw; 61 unsigned i, nr = 0; 62 unsigned dst_offset = 0; 63 struct translate_key key; 64 65 fetch->vertex_size = vertex_size; 66 67 memset(&key, 0, sizeof(key)); 68 69 /* Always emit/leave space for a vertex header. 70 * 71 * It's worth considering whether the vertex headers should contain 72 * a pointer to the 'data', rather than having it inline. 73 * Something to look at after we've fully switched over to the pt 74 * paths. 75 */ 76 { 77 /* Need to set header->vertex_id = 0xffff somehow. 78 */ 79 key.element[nr].input_format = PIPE_FORMAT_R32_FLOAT; 80 key.element[nr].input_buffer = draw->pt.nr_vertex_buffers; 81 key.element[nr].input_offset = 0; 82 key.element[nr].output_format = PIPE_FORMAT_R32_FLOAT; 83 key.element[nr].output_offset = dst_offset; 84 dst_offset += 1 * sizeof(float); 85 nr++; 86 87 88 /* Just leave the clip[] array untouched. 89 */ 90 dst_offset += 4 * sizeof(float); 91 } 92 93 94 for (i = 0; i < draw->pt.nr_vertex_elements; i++) { 95 key.element[nr].input_format = draw->pt.vertex_element[i].src_format; 96 key.element[nr].input_buffer = draw->pt.vertex_element[i].vertex_buffer_index; 97 key.element[nr].input_offset = draw->pt.vertex_element[i].src_offset; 98 key.element[nr].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; 99 key.element[nr].output_offset = dst_offset; 100 101 dst_offset += 4 * sizeof(float); 102 nr++; 103 } 104 105 assert(dst_offset <= vertex_size); 106 107 key.nr_elements = nr; 108 key.output_stride = vertex_size; 109 110 111 if (!fetch->translate || 112 memcmp(&fetch->translate->key, &key, sizeof(key)) != 0) 113 { 114 fetch->translate = translate_cache_find(fetch->cache, &key); 115 116 { 117 static struct vertex_header vh = { 0, 0, 0, 0xffff }; 118 fetch->translate->set_buffer(fetch->translate, 119 draw->pt.nr_vertex_buffers, 120 &vh, 121 0); 122 } 123 } 124} 125 126 127 128 129void draw_pt_fetch_run( struct pt_fetch *fetch, 130 const unsigned *elts, 131 unsigned count, 132 char *verts ) 133{ 134 struct draw_context *draw = fetch->draw; 135 struct translate *translate = fetch->translate; 136 unsigned i; 137 138 for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { 139 translate->set_buffer(translate, 140 i, 141 ((char *)draw->pt.user.vbuffer[i] + 142 draw->pt.vertex_buffer[i].buffer_offset), 143 draw->pt.vertex_buffer[i].pitch ); 144 } 145 146 translate->run_elts( translate, 147 elts, 148 count, 149 verts ); 150} 151 152 153struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw ) 154{ 155 struct pt_fetch *fetch = CALLOC_STRUCT(pt_fetch); 156 if (!fetch) 157 return NULL; 158 159 fetch->draw = draw; 160 fetch->cache = translate_cache_create(); 161 return fetch; 162} 163 164void draw_pt_fetch_destroy( struct pt_fetch *fetch ) 165{ 166 translate_cache_destroy(fetch->cache); 167 168 FREE(fetch); 169} 170 171