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