0b3c9e69bd53cbd6ce7515df2e563450a0f95aab
[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 #endif
52
53
54 struct pipe_context;
55 struct draw_vertex_shader;
56 struct draw_context;
57 struct draw_stage;
58 struct vbuf_render;
59 struct tgsi_exec_machine;
60 struct tgsi_sampler;
61
62
63 /**
64 * Basic vertex info.
65 * Carry some useful information around with the vertices in the prim pipe.
66 */
67 struct vertex_header {
68 unsigned clipmask:12;
69 unsigned edgeflag:1;
70 unsigned pad:3;
71 unsigned vertex_id:16;
72
73 float clip[4];
74
75 /* This will probably become float (*data)[4] soon:
76 */
77 float data[][4];
78 };
79
80 /* NOTE: It should match vertex_id size above */
81 #define UNDEFINED_VERTEX_ID 0xffff
82
83
84 /**
85 * Private context for the drawing module.
86 */
87 struct draw_context
88 {
89 struct pipe_context *pipe;
90
91 /** Drawing/primitive pipeline stages */
92 struct {
93 struct draw_stage *first; /**< one of the following */
94
95 struct draw_stage *validate;
96
97 /* stages (in logical order) */
98 struct draw_stage *flatshade;
99 struct draw_stage *clip;
100 struct draw_stage *cull;
101 struct draw_stage *twoside;
102 struct draw_stage *offset;
103 struct draw_stage *unfilled;
104 struct draw_stage *stipple;
105 struct draw_stage *aapoint;
106 struct draw_stage *aaline;
107 struct draw_stage *pstipple;
108 struct draw_stage *wide_line;
109 struct draw_stage *wide_point;
110 struct draw_stage *rasterize;
111
112 float wide_point_threshold; /**< convert pnts to tris if larger than this */
113 float wide_line_threshold; /**< convert lines to tris if wider than this */
114 boolean line_stipple; /**< do line stipple? */
115 boolean point_sprite; /**< convert points to quads for sprites? */
116
117 /* Temporary storage while the pipeline is being run:
118 */
119 char *verts;
120 unsigned vertex_stride;
121 unsigned vertex_count;
122 } pipeline;
123
124
125 struct vbuf_render *render;
126
127 /* Support prototype passthrough path:
128 */
129 struct {
130 struct {
131 struct draw_pt_middle_end *fetch_emit;
132 struct draw_pt_middle_end *fetch_shade_emit;
133 struct draw_pt_middle_end *general;
134 } middle;
135
136 struct {
137 struct draw_pt_front_end *vcache;
138 struct draw_pt_front_end *varray;
139 } front;
140
141 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
142 unsigned nr_vertex_buffers;
143
144 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
145 unsigned nr_vertex_elements;
146
147 /* user-space vertex data, buffers */
148 struct {
149 /** vertex element/index buffer (ex: glDrawElements) */
150 const void *elts;
151 /** bytes per index (0, 1, 2 or 4) */
152 unsigned eltSize;
153 int eltBias;
154 unsigned min_index;
155 unsigned max_index;
156
157 /** vertex arrays */
158 const void *vbuffer[PIPE_MAX_ATTRIBS];
159
160 /** constant buffer (for vertex/geometry shader) */
161 const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS];
162 const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
163 } user;
164
165 boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
166 boolean no_fse; /* disable FSE even when it is correct */
167 } pt;
168
169 struct {
170 boolean bypass_clipping;
171 boolean bypass_vs;
172 } driver;
173
174 boolean flushing; /**< debugging/sanity */
175 boolean suspend_flushing; /**< internally set */
176 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
177
178 boolean force_passthrough; /**< never clip or shade */
179
180 boolean dump_vs;
181
182 double mrd; /**< minimum resolvable depth value, for polygon offset */
183
184 /** Current rasterizer state given to us by the driver */
185 const struct pipe_rasterizer_state *rasterizer;
186 /** Driver CSO handle for the current rasterizer state */
187 void *rast_handle;
188
189 /** Rasterizer CSOs without culling/stipple/etc */
190 void *rasterizer_no_cull[2][2];
191
192 struct pipe_viewport_state viewport;
193 boolean identity_viewport;
194
195 struct {
196 struct draw_vertex_shader *vertex_shader;
197 uint num_vs_outputs; /**< convenience, from vertex_shader */
198 uint position_output;
199 uint edgeflag_output;
200
201 /** TGSI program interpreter runtime state */
202 struct tgsi_exec_machine *machine;
203
204 uint num_samplers;
205 struct tgsi_sampler **samplers;
206
207 /* Here's another one:
208 */
209 struct aos_machine *aos_machine;
210
211
212 const void *aligned_constants[PIPE_MAX_CONSTANT_BUFFERS];
213
214 const void *aligned_constant_storage[PIPE_MAX_CONSTANT_BUFFERS];
215 unsigned const_storage_size[PIPE_MAX_CONSTANT_BUFFERS];
216
217
218 struct translate *fetch;
219 struct translate_cache *fetch_cache;
220 struct translate *emit;
221 struct translate_cache *emit_cache;
222 } vs;
223
224 struct {
225 struct draw_geometry_shader *geometry_shader;
226 uint num_gs_outputs; /**< convenience, from geometry_shader */
227 uint position_output;
228
229 /** TGSI program interpreter runtime state */
230 struct tgsi_exec_machine *machine;
231
232 uint num_samplers;
233 struct tgsi_sampler **samplers;
234 } gs;
235
236 /* Clip derived state:
237 */
238 float plane[12][4];
239 unsigned nr_planes;
240
241 /* If a prim stage introduces new vertex attributes, they'll be stored here
242 */
243 struct {
244 uint semantic_name;
245 uint semantic_index;
246 int slot;
247 } extra_shader_outputs;
248
249 unsigned reduced_prim;
250
251 unsigned instance_id;
252
253 #ifdef HAVE_LLVM
254 LLVMExecutionEngineRef engine;
255 boolean use_llvm;
256 #endif
257 void *driver_private;
258 };
259
260 /*******************************************************************************
261 * Draw common initialization code
262 */
263 boolean draw_init(struct draw_context *draw);
264
265 /*******************************************************************************
266 * Vertex shader code:
267 */
268 boolean draw_vs_init( struct draw_context *draw );
269 void draw_vs_destroy( struct draw_context *draw );
270
271 void draw_vs_set_viewport( struct draw_context *,
272 const struct pipe_viewport_state * );
273
274 void
275 draw_vs_set_constants(struct draw_context *,
276 unsigned slot,
277 const void *constants,
278 unsigned size);
279
280
281
282 /*******************************************************************************
283 * Geometry shading code:
284 */
285 boolean draw_gs_init( struct draw_context *draw );
286
287 void
288 draw_gs_set_constants(struct draw_context *,
289 unsigned slot,
290 const void *constants,
291 unsigned size);
292
293 void draw_gs_destroy( struct draw_context *draw );
294
295 /*******************************************************************************
296 * Common shading code:
297 */
298 uint draw_current_shader_outputs(const struct draw_context *draw);
299 uint draw_current_shader_position_output(const struct draw_context *draw);
300
301 /*******************************************************************************
302 * Vertex processing (was passthrough) code:
303 */
304 boolean draw_pt_init( struct draw_context *draw );
305 void draw_pt_destroy( struct draw_context *draw );
306 void draw_pt_reset_vertex_ids( struct draw_context *draw );
307
308
309 /*******************************************************************************
310 * Primitive processing (pipeline) code:
311 */
312
313 boolean draw_pipeline_init( struct draw_context *draw );
314 void draw_pipeline_destroy( struct draw_context *draw );
315
316
317
318
319
320 /* We use the top few bits in the elts[] parameter to convey a little
321 * API information. This limits the number of vertices we can address
322 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
323 * draw indices.
324 *
325 * These flags expected at first vertex of lines & triangles when
326 * unfilled and/or line stipple modes are operational.
327 */
328 #define DRAW_PIPE_MAX_VERTICES (0x1<<12)
329 #define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
330 #define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
331 #define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
332 #define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
333 #define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
334 #define DRAW_PIPE_FLAG_MASK (0xf<<12)
335
336 void draw_pipeline_run( struct draw_context *draw,
337 unsigned prim,
338 struct vertex_header *vertices,
339 unsigned vertex_count,
340 unsigned stride,
341 const ushort *elts,
342 unsigned count );
343
344 void draw_pipeline_run_linear( struct draw_context *draw,
345 unsigned prim,
346 struct vertex_header *vertices,
347 unsigned count,
348 unsigned stride );
349
350
351
352 void draw_pipeline_flush( struct draw_context *draw,
353 unsigned flags );
354
355
356
357 /*******************************************************************************
358 * Flushing
359 */
360
361 #define DRAW_FLUSH_STATE_CHANGE 0x8
362 #define DRAW_FLUSH_BACKEND 0x10
363
364
365 void draw_do_flush( struct draw_context *draw, unsigned flags );
366
367
368
369 void *
370 draw_get_rasterizer_no_cull( struct draw_context *draw,
371 boolean scissor,
372 boolean flatshade );
373
374
375 #endif /* DRAW_PRIVATE_H */