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