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