draw: disable depth clipping if depth clamp is enabled
[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 *vcache;
144 struct draw_pt_front_end *varray;
145 } front;
146
147 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
148 unsigned nr_vertex_buffers;
149
150 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
151 unsigned nr_vertex_elements;
152
153 /* user-space vertex data, buffers */
154 struct {
155 /** vertex element/index buffer (ex: glDrawElements) */
156 const void *elts;
157 /** bytes per index (0, 1, 2 or 4) */
158 unsigned eltSize;
159 int eltBias;
160 unsigned min_index;
161 unsigned max_index;
162
163 /** vertex arrays */
164 const void *vbuffer[PIPE_MAX_ATTRIBS];
165
166 /** constant buffer (for vertex/geometry shader) */
167 const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS];
168 const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
169 } user;
170
171 boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
172 boolean no_fse; /* disable FSE even when it is correct */
173 } pt;
174
175 struct {
176 boolean bypass_clipping;
177 boolean bypass_vs;
178 } driver;
179
180 boolean flushing; /**< debugging/sanity */
181 boolean suspend_flushing; /**< internally set */
182 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
183
184 boolean force_passthrough; /**< never clip or shade */
185
186 boolean dump_vs;
187
188 double mrd; /**< minimum resolvable depth value, for polygon offset */
189
190 /** Current rasterizer state given to us by the driver */
191 const struct pipe_rasterizer_state *rasterizer;
192 /** Driver CSO handle for the current rasterizer state */
193 void *rast_handle;
194
195 /** Rasterizer CSOs without culling/stipple/etc */
196 void *rasterizer_no_cull[2][2];
197
198 struct pipe_viewport_state viewport;
199 boolean identity_viewport;
200
201 struct {
202 struct draw_vertex_shader *vertex_shader;
203 uint num_vs_outputs; /**< convenience, from vertex_shader */
204 uint position_output;
205 uint edgeflag_output;
206
207 /** TGSI program interpreter runtime state */
208 struct tgsi_exec_machine *machine;
209
210 uint num_samplers;
211 struct tgsi_sampler **samplers;
212
213 /* Here's another one:
214 */
215 struct aos_machine *aos_machine;
216
217
218 const void *aligned_constants[PIPE_MAX_CONSTANT_BUFFERS];
219
220 const void *aligned_constant_storage[PIPE_MAX_CONSTANT_BUFFERS];
221 unsigned const_storage_size[PIPE_MAX_CONSTANT_BUFFERS];
222
223
224 struct translate *fetch;
225 struct translate_cache *fetch_cache;
226 struct translate *emit;
227 struct translate_cache *emit_cache;
228 } vs;
229
230 struct {
231 struct draw_geometry_shader *geometry_shader;
232 uint num_gs_outputs; /**< convenience, from geometry_shader */
233 uint position_output;
234
235 /** TGSI program interpreter runtime state */
236 struct tgsi_exec_machine *machine;
237
238 uint num_samplers;
239 struct tgsi_sampler **samplers;
240 } gs;
241
242 struct {
243 struct pipe_stream_output_state state;
244 void *buffers[PIPE_MAX_SO_BUFFERS];
245 uint num_buffers;
246 } so;
247
248 /* Clip derived state:
249 */
250 float plane[12][4];
251 unsigned nr_planes;
252 boolean depth_clamp;
253
254 /* If a prim stage introduces new vertex attributes, they'll be stored here
255 */
256 struct {
257 uint semantic_name;
258 uint semantic_index;
259 int slot;
260 } extra_shader_outputs;
261
262 unsigned reduced_prim;
263
264 unsigned instance_id;
265
266 #ifdef HAVE_LLVM
267 struct draw_llvm *llvm;
268 LLVMExecutionEngineRef engine;
269 #endif
270
271 struct pipe_sampler_view *sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
272 unsigned num_sampler_views;
273 const struct pipe_sampler_state *samplers[PIPE_MAX_VERTEX_SAMPLERS];
274 unsigned num_samplers;
275
276 void *driver_private;
277 };
278
279
280 struct draw_fetch_info {
281 boolean linear;
282 unsigned start;
283 const unsigned *elts;
284 unsigned count;
285 };
286
287 struct draw_vertex_info {
288 struct vertex_header *verts;
289 unsigned vertex_size;
290 unsigned stride;
291 unsigned count;
292 };
293
294 struct draw_prim_info {
295 boolean linear;
296 unsigned start;
297
298 const ushort *elts;
299 unsigned count;
300
301 unsigned prim;
302 unsigned *primitive_lengths;
303 unsigned primitive_count;
304 };
305
306
307 /*******************************************************************************
308 * Draw common initialization code
309 */
310 boolean draw_init(struct draw_context *draw);
311
312 /*******************************************************************************
313 * Vertex shader code:
314 */
315 boolean draw_vs_init( struct draw_context *draw );
316 void draw_vs_destroy( struct draw_context *draw );
317
318 void draw_vs_set_viewport( struct draw_context *,
319 const struct pipe_viewport_state * );
320
321 void
322 draw_vs_set_constants(struct draw_context *,
323 unsigned slot,
324 const void *constants,
325 unsigned size);
326
327
328
329 /*******************************************************************************
330 * Geometry shading code:
331 */
332 boolean draw_gs_init( struct draw_context *draw );
333
334 void
335 draw_gs_set_constants(struct draw_context *,
336 unsigned slot,
337 const void *constants,
338 unsigned size);
339
340 void draw_gs_destroy( struct draw_context *draw );
341
342 /*******************************************************************************
343 * Common shading code:
344 */
345 uint draw_current_shader_outputs(const struct draw_context *draw);
346 uint draw_current_shader_position_output(const struct draw_context *draw);
347
348 /*******************************************************************************
349 * Vertex processing (was passthrough) code:
350 */
351 boolean draw_pt_init( struct draw_context *draw );
352 void draw_pt_destroy( struct draw_context *draw );
353 void draw_pt_reset_vertex_ids( struct draw_context *draw );
354
355
356 /*******************************************************************************
357 * Primitive processing (pipeline) code:
358 */
359
360 boolean draw_pipeline_init( struct draw_context *draw );
361 void draw_pipeline_destroy( struct draw_context *draw );
362
363
364
365
366
367 /* We use the top few bits in the elts[] parameter to convey a little
368 * API information. This limits the number of vertices we can address
369 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
370 * draw indices.
371 *
372 * These flags expected at first vertex of lines & triangles when
373 * unfilled and/or line stipple modes are operational.
374 */
375 #define DRAW_PIPE_MAX_VERTICES (0x1<<12)
376 #define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
377 #define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
378 #define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
379 #define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
380 #define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
381 #define DRAW_PIPE_FLAG_MASK (0xf<<12)
382
383 void draw_pipeline_run( struct draw_context *draw,
384 const struct draw_vertex_info *vert,
385 const struct draw_prim_info *prim);
386
387 void draw_pipeline_run_linear( struct draw_context *draw,
388 const struct draw_vertex_info *vert,
389 const struct draw_prim_info *prim);
390
391
392
393
394 void draw_pipeline_flush( struct draw_context *draw,
395 unsigned flags );
396
397
398
399 /*******************************************************************************
400 * Flushing
401 */
402
403 #define DRAW_FLUSH_STATE_CHANGE 0x8
404 #define DRAW_FLUSH_BACKEND 0x10
405
406
407 void draw_do_flush( struct draw_context *draw, unsigned flags );
408
409
410
411 void *
412 draw_get_rasterizer_no_cull( struct draw_context *draw,
413 boolean scissor,
414 boolean flatshade );
415
416
417 #endif /* DRAW_PRIVATE_H */