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