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