draw_vs.h revision f8762ba5234fd1b44e11e76bb5f58d2305c90572
1/************************************************************************** 2 * 3 * Copyright 2007 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/* Authors: Keith Whitwell <keith@tungstengraphics.com> 29 */ 30 31#ifndef DRAW_VS_H 32#define DRAW_VS_H 33 34#include "draw_context.h" 35#include "draw_private.h" 36 37 38struct draw_context; 39struct pipe_shader_state; 40 41struct draw_vs_input 42{ 43 enum pipe_format format; 44 unsigned buffer; 45 unsigned offset; 46}; 47 48struct draw_vs_output 49{ 50 enum pipe_format format; 51 unsigned offset; 52}; 53 54struct draw_vs_element { 55 struct draw_vs_input in; 56 struct draw_vs_output out; 57}; 58 59struct draw_vs_varient_key { 60 unsigned output_stride; 61 unsigned nr_elements:8; /* max2(nr_inputs, nr_outputs) */ 62 unsigned nr_inputs:8; 63 unsigned nr_outputs:8; 64 unsigned viewport:1; 65 unsigned clip:1; 66 unsigned pad:5; 67 struct draw_vs_element element[PIPE_MAX_ATTRIBS]; 68}; 69 70struct draw_vs_varient; 71 72typedef void (PIPE_CDECL *vsv_run_elts_func)( struct draw_vs_varient *, 73 const unsigned *elts, 74 unsigned count, 75 void *output_buffer); 76 77typedef void (PIPE_CDECL *vsv_run_linear_func)( struct draw_vs_varient *, 78 unsigned start, 79 unsigned count, 80 void *output_buffer); 81 82 83struct draw_vs_varient { 84 struct draw_vs_varient_key key; 85 86 struct draw_vertex_shader *vs; 87 88 void (*set_input)( struct draw_vs_varient *, 89 unsigned i, 90 const void *ptr, 91 unsigned stride ); 92 93 void (*set_constants)( struct draw_vs_varient *, 94 const float (*constants)[4] ); 95 96 void (*set_viewport)( struct draw_vs_varient *, 97 const struct pipe_viewport_state * ); 98 99 void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader, 100 unsigned start, 101 unsigned count, 102 void *output_buffer ); 103 104 void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader, 105 const unsigned *elts, 106 unsigned count, 107 void *output_buffer ); 108 109 void (*destroy)( struct draw_vs_varient * ); 110}; 111 112 113/** 114 * Private version of the compiled vertex_shader 115 */ 116struct draw_vertex_shader { 117 struct draw_context *draw; 118 119 /* This member will disappear shortly: 120 */ 121 struct pipe_shader_state state; 122 123 struct tgsi_shader_info info; 124 125 /* 126 */ 127 struct draw_vs_varient *varient[16]; 128 unsigned nr_varients; 129 struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader, 130 const struct draw_vs_varient_key *key ); 131 132 133 void (*prepare)( struct draw_vertex_shader *shader, 134 struct draw_context *draw ); 135 136 /* Run the shader - this interface will get cleaned up in the 137 * future: 138 */ 139 void (*run_linear)( struct draw_vertex_shader *shader, 140 const float (*input)[4], 141 float (*output)[4], 142 const float (*constants)[4], 143 unsigned count, 144 unsigned input_stride, 145 unsigned output_stride ); 146 147 148 void (*delete)( struct draw_vertex_shader * ); 149}; 150 151 152struct draw_vs_varient * 153draw_vs_lookup_varient( struct draw_vertex_shader *base, 154 const struct draw_vs_varient_key *key ); 155 156 157/******************************************************************************** 158 * Internal functions: 159 */ 160 161struct draw_vertex_shader * 162draw_create_vs_exec(struct draw_context *draw, 163 const struct pipe_shader_state *templ); 164 165struct draw_vertex_shader * 166draw_create_vs_sse(struct draw_context *draw, 167 const struct pipe_shader_state *templ); 168 169struct draw_vertex_shader * 170draw_create_vs_llvm(struct draw_context *draw, 171 const struct pipe_shader_state *templ); 172 173 174 175struct draw_vs_varient_key; 176struct draw_vertex_shader; 177 178struct draw_vs_varient *draw_vs_varient_aos_sse( struct draw_vertex_shader *vs, 179 const struct draw_vs_varient_key *key ); 180 181 182 183/******************************************************************************** 184 * Helpers for vs implementations that don't do their own fetch/emit varients. 185 * Means these can be shared between shaders. 186 */ 187struct translate; 188struct translate_key; 189 190struct translate *draw_vs_get_fetch( struct draw_context *draw, 191 struct translate_key *key ); 192 193 194struct translate *draw_vs_get_emit( struct draw_context *draw, 195 struct translate_key *key ); 196 197struct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs, 198 const struct draw_vs_varient_key *key ); 199 200 201 202static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key ) 203{ 204 return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_vs_element); 205} 206 207static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a, 208 const struct draw_vs_varient_key *b ) 209{ 210 int keysize = draw_vs_varient_keysize(a); 211 return memcmp(a, b, keysize); 212} 213 214 215 216 217 218#define MAX_TGSI_VERTICES 4 219 220 221 222#endif 223