draw_private.h revision a2c1df4c9a7375bc5306e8cfd07a9f7087759a96
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/** 29 * Private data structures, etc for the draw module. 30 */ 31 32 33/** 34 * Authors: 35 * Keith Whitwell <keith@tungstengraphics.com> 36 * Brian Paul 37 */ 38 39 40#ifndef DRAW_PRIVATE_H 41#define DRAW_PRIVATE_H 42 43 44#include "pipe/p_state.h" 45#include "pipe/p_defines.h" 46 47#include "tgsi/tgsi_scan.h" 48 49#ifdef HAVE_LLVM 50struct draw_llvm; 51struct gallivm_state; 52#endif 53 54 55/** Sum of frustum planes and user-defined planes */ 56#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES) 57 58 59struct pipe_context; 60struct draw_vertex_shader; 61struct draw_context; 62struct draw_stage; 63struct vbuf_render; 64struct tgsi_exec_machine; 65struct tgsi_sampler; 66struct draw_pt_front_end; 67 68 69/** 70 * Basic vertex info. 71 * Carry some useful information around with the vertices in the prim pipe. 72 */ 73struct vertex_header { 74 unsigned clipmask:DRAW_TOTAL_CLIP_PLANES; 75 unsigned edgeflag:1; 76 unsigned have_clipdist:1; 77 unsigned vertex_id:16; 78 79 float clip[4]; 80 float pre_clip_pos[4]; 81 82 /* This will probably become float (*data)[4] soon: 83 */ 84 float data[][4]; 85}; 86 87/* NOTE: It should match vertex_id size above */ 88#define UNDEFINED_VERTEX_ID 0xffff 89 90 91/* maximum number of shader variants we can cache */ 92#define DRAW_MAX_SHADER_VARIANTS 128 93 94/** 95 * Private context for the drawing module. 96 */ 97struct draw_context 98{ 99 struct pipe_context *pipe; 100 101 /** Drawing/primitive pipeline stages */ 102 struct { 103 struct draw_stage *first; /**< one of the following */ 104 105 struct draw_stage *validate; 106 107 /* stages (in logical order) */ 108 struct draw_stage *flatshade; 109 struct draw_stage *clip; 110 struct draw_stage *cull; 111 struct draw_stage *twoside; 112 struct draw_stage *offset; 113 struct draw_stage *unfilled; 114 struct draw_stage *stipple; 115 struct draw_stage *aapoint; 116 struct draw_stage *aaline; 117 struct draw_stage *pstipple; 118 struct draw_stage *wide_line; 119 struct draw_stage *wide_point; 120 struct draw_stage *rasterize; 121 122 float wide_point_threshold; /**< convert pnts to tris if larger than this */ 123 float wide_line_threshold; /**< convert lines to tris if wider than this */ 124 boolean wide_point_sprites; /**< convert points to tris for sprite mode */ 125 boolean line_stipple; /**< do line stipple? */ 126 boolean point_sprite; /**< convert points to quads for sprites? */ 127 128 /* Temporary storage while the pipeline is being run: 129 */ 130 char *verts; 131 unsigned vertex_stride; 132 unsigned vertex_count; 133 } pipeline; 134 135 136 struct vbuf_render *render; 137 138 /* Support prototype passthrough path: 139 */ 140 struct { 141 /* Current active frontend */ 142 struct draw_pt_front_end *frontend; 143 unsigned prim; 144 unsigned opt; 145 unsigned eltSize; /* saved eltSize for flushing */ 146 147 struct { 148 struct draw_pt_middle_end *fetch_emit; 149 struct draw_pt_middle_end *fetch_shade_emit; 150 struct draw_pt_middle_end *general; 151 struct draw_pt_middle_end *llvm; 152 } middle; 153 154 struct { 155 struct draw_pt_front_end *vsplit; 156 } front; 157 158 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; 159 unsigned nr_vertex_buffers; 160 161 /* 162 * This is the largest legal index value for the current set of 163 * bound vertex buffers. Regardless of any other consideration, 164 * all vertex lookups need to be clamped to 0..max_index to 165 * prevent out-of-bound access. 166 */ 167 unsigned max_index; 168 169 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; 170 unsigned nr_vertex_elements; 171 172 /* user-space vertex data, buffers */ 173 struct { 174 /** vertex element/index buffer (ex: glDrawElements) */ 175 const void *elts; 176 /** bytes per index (0, 1, 2 or 4) */ 177 unsigned eltSize; 178 int eltBias; 179 unsigned min_index; 180 unsigned max_index; 181 182 /** vertex arrays */ 183 const void *vbuffer[PIPE_MAX_ATTRIBS]; 184 185 /** constant buffers (for vertex/geometry shader) */ 186 const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS]; 187 unsigned vs_constants_size[PIPE_MAX_CONSTANT_BUFFERS]; 188 const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS]; 189 unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS]; 190 191 /* pointer to planes */ 192 float (*planes)[DRAW_TOTAL_CLIP_PLANES][4]; 193 } user; 194 195 boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */ 196 boolean no_fse; /* disable FSE even when it is correct */ 197 } pt; 198 199 struct { 200 boolean bypass_clip_xy; 201 boolean bypass_clip_z; 202 boolean guard_band_xy; 203 } driver; 204 205 boolean quads_always_flatshade_last; 206 207 boolean flushing; /**< debugging/sanity */ 208 boolean suspend_flushing; /**< internally set */ 209 210 /* Flags set if API requires clipping in these planes and the 211 * driver doesn't indicate that it can do it for us. 212 */ 213 boolean clip_xy; 214 boolean clip_z; 215 boolean clip_user; 216 boolean guard_band_xy; 217 218 boolean force_passthrough; /**< never clip or shade */ 219 220 boolean dump_vs; 221 222 double mrd; /**< minimum resolvable depth value, for polygon offset */ 223 224 /** Current rasterizer state given to us by the driver */ 225 const struct pipe_rasterizer_state *rasterizer; 226 /** Driver CSO handle for the current rasterizer state */ 227 void *rast_handle; 228 229 /** Rasterizer CSOs without culling/stipple/etc */ 230 void *rasterizer_no_cull[2][2]; 231 232 struct pipe_viewport_state viewport; 233 boolean identity_viewport; 234 235 /** Vertex shader state */ 236 struct { 237 struct draw_vertex_shader *vertex_shader; 238 uint num_vs_outputs; /**< convenience, from vertex_shader */ 239 uint position_output; 240 uint edgeflag_output; 241 uint clipvertex_output; 242 uint clipdistance_output[2]; 243 244 /** Fields for TGSI interpreter / execution */ 245 struct { 246 struct tgsi_exec_machine *machine; 247 248 struct tgsi_sampler **samplers; 249 uint num_samplers; 250 } tgsi; 251 252 const void *aligned_constants[PIPE_MAX_CONSTANT_BUFFERS]; 253 254 const void *aligned_constant_storage[PIPE_MAX_CONSTANT_BUFFERS]; 255 unsigned const_storage_size[PIPE_MAX_CONSTANT_BUFFERS]; 256 257 258 struct translate *fetch; 259 struct translate_cache *fetch_cache; 260 struct translate *emit; 261 struct translate_cache *emit_cache; 262 } vs; 263 264 /** Geometry shader state */ 265 struct { 266 struct draw_geometry_shader *geometry_shader; 267 uint num_gs_outputs; /**< convenience, from geometry_shader */ 268 uint position_output; 269 270 /** Fields for TGSI interpreter / execution */ 271 struct { 272 struct tgsi_exec_machine *machine; 273 274 struct tgsi_sampler **samplers; 275 uint num_samplers; 276 } tgsi; 277 278 } gs; 279 280 /** Fragment shader state */ 281 struct { 282 struct draw_fragment_shader *fragment_shader; 283 } fs; 284 285 /** Stream output (vertex feedback) state */ 286 struct { 287 struct pipe_stream_output_info state; 288 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]; 289 uint num_targets; 290 } so; 291 292 /* Clip derived state: 293 */ 294 float plane[DRAW_TOTAL_CLIP_PLANES][4]; 295 296 /* If a prim stage introduces new vertex attributes, they'll be stored here 297 */ 298 struct { 299 uint num; 300 uint semantic_name[10]; 301 uint semantic_index[10]; 302 uint slot[10]; 303 } extra_shader_outputs; 304 305 unsigned instance_id; 306 307#ifdef HAVE_LLVM 308 struct draw_llvm *llvm; 309#endif 310 311 /** Texture sampler and sampler view state. 312 * Note that we have arrays indexed by shader type. At this time 313 * we only handle vertex and geometry shaders in the draw module, but 314 * there may be more in the future (ex: hull and tessellation). 315 */ 316 struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; 317 unsigned num_sampler_views[PIPE_SHADER_TYPES]; 318 const struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; 319 unsigned num_samplers[PIPE_SHADER_TYPES]; 320 321 void *driver_private; 322}; 323 324 325struct draw_fetch_info { 326 boolean linear; 327 unsigned start; 328 const unsigned *elts; 329 unsigned count; 330}; 331 332struct draw_vertex_info { 333 struct vertex_header *verts; 334 unsigned vertex_size; 335 unsigned stride; 336 unsigned count; 337}; 338 339/* these flags are set if the primitive is a segment of a larger one */ 340#define DRAW_SPLIT_BEFORE 0x1 341#define DRAW_SPLIT_AFTER 0x2 342 343struct draw_prim_info { 344 boolean linear; 345 unsigned start; 346 347 const ushort *elts; 348 unsigned count; 349 350 unsigned prim; 351 unsigned flags; 352 unsigned *primitive_lengths; 353 unsigned primitive_count; 354}; 355 356 357/******************************************************************************* 358 * Draw common initialization code 359 */ 360boolean draw_init(struct draw_context *draw); 361 362/******************************************************************************* 363 * Vertex shader code: 364 */ 365boolean draw_vs_init( struct draw_context *draw ); 366void draw_vs_destroy( struct draw_context *draw ); 367 368void draw_vs_set_viewport( struct draw_context *, 369 const struct pipe_viewport_state * ); 370 371void 372draw_vs_set_constants(struct draw_context *, 373 unsigned slot, 374 const void *constants, 375 unsigned size); 376 377 378 379/******************************************************************************* 380 * Geometry shading code: 381 */ 382boolean draw_gs_init( struct draw_context *draw ); 383 384void 385draw_gs_set_constants(struct draw_context *, 386 unsigned slot, 387 const void *constants, 388 unsigned size); 389 390void draw_gs_destroy( struct draw_context *draw ); 391 392/******************************************************************************* 393 * Common shading code: 394 */ 395uint draw_current_shader_outputs(const struct draw_context *draw); 396uint draw_current_shader_position_output(const struct draw_context *draw); 397uint draw_current_shader_clipvertex_output(const struct draw_context *draw); 398uint draw_current_shader_clipdistance_output(const struct draw_context *draw, int index); 399int draw_alloc_extra_vertex_attrib(struct draw_context *draw, 400 uint semantic_name, uint semantic_index); 401void draw_remove_extra_vertex_attribs(struct draw_context *draw); 402 403 404/******************************************************************************* 405 * Vertex processing (was passthrough) code: 406 */ 407boolean draw_pt_init( struct draw_context *draw ); 408void draw_pt_destroy( struct draw_context *draw ); 409void draw_pt_reset_vertex_ids( struct draw_context *draw ); 410void draw_pt_flush( struct draw_context *draw, unsigned flags ); 411 412 413/******************************************************************************* 414 * Primitive processing (pipeline) code: 415 */ 416 417boolean draw_pipeline_init( struct draw_context *draw ); 418void draw_pipeline_destroy( struct draw_context *draw ); 419 420 421 422 423 424/* 425 * These flags are used by the pipeline when unfilled and/or line stipple modes 426 * are operational. 427 */ 428#define DRAW_PIPE_EDGE_FLAG_0 0x1 429#define DRAW_PIPE_EDGE_FLAG_1 0x2 430#define DRAW_PIPE_EDGE_FLAG_2 0x4 431#define DRAW_PIPE_EDGE_FLAG_ALL 0x7 432#define DRAW_PIPE_RESET_STIPPLE 0x8 433 434void draw_pipeline_run( struct draw_context *draw, 435 const struct draw_vertex_info *vert, 436 const struct draw_prim_info *prim); 437 438void draw_pipeline_run_linear( struct draw_context *draw, 439 const struct draw_vertex_info *vert, 440 const struct draw_prim_info *prim); 441 442 443 444 445void draw_pipeline_flush( struct draw_context *draw, 446 unsigned flags ); 447 448 449 450/******************************************************************************* 451 * Flushing 452 */ 453 454#define DRAW_FLUSH_STATE_CHANGE 0x8 455#define DRAW_FLUSH_BACKEND 0x10 456 457 458void draw_do_flush( struct draw_context *draw, unsigned flags ); 459 460 461 462void * 463draw_get_rasterizer_no_cull( struct draw_context *draw, 464 boolean scissor, 465 boolean flatshade ); 466 467 468#endif /* DRAW_PRIVATE_H */ 469