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