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