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