draw: put pipeline flushing behind a new interface
[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/exec/tgsi_exec.h"
48 #include "tgsi/util/tgsi_scan.h"
49
50
51 struct pipe_context;
52 struct gallivm_prog;
53 struct gallivm_cpu_engine;
54 struct draw_vertex_shader;
55 struct draw_context;
56 struct draw_stage;
57 struct vbuf_render;
58
59
60 /**
61 * Basic vertex info.
62 * Carry some useful information around with the vertices in the prim pipe.
63 */
64 struct vertex_header {
65 unsigned clipmask:12;
66 unsigned edgeflag:1;
67 unsigned pad:3;
68 unsigned vertex_id:16;
69
70 float clip[4];
71
72 /* This will probably become float (*data)[4] soon:
73 */
74 float data[][4];
75 };
76
77 /* NOTE: It should match vertex_id size above */
78 #define UNDEFINED_VERTEX_ID 0xffff
79
80
81 /**
82 * Basic info for a point/line/triangle primitive.
83 */
84 struct prim_header {
85 float det; /**< front/back face determinant */
86 unsigned reset_line_stipple:1;
87 unsigned edgeflags:3;
88 unsigned pad:28;
89 struct vertex_header *v[3]; /**< 1 to 3 vertex pointers */
90 };
91
92
93
94
95 #define PT_SHADE 0x1
96 #define PT_CLIPTEST 0x2
97 #define PT_PIPELINE 0x4
98 #define PT_MAX_MIDDLE 0x8
99
100 /**
101 * Private context for the drawing module.
102 */
103 struct draw_context
104 {
105 /** Drawing/primitive pipeline stages */
106 struct {
107 struct draw_stage *first; /**< one of the following */
108
109 struct draw_stage *validate;
110
111 /* stages (in logical order) */
112 struct draw_stage *flatshade;
113 struct draw_stage *clip;
114 struct draw_stage *cull;
115 struct draw_stage *twoside;
116 struct draw_stage *offset;
117 struct draw_stage *unfilled;
118 struct draw_stage *stipple;
119 struct draw_stage *aapoint;
120 struct draw_stage *aaline;
121 struct draw_stage *pstipple;
122 struct draw_stage *wide_line;
123 struct draw_stage *wide_point;
124 struct draw_stage *rasterize;
125
126 float wide_point_threshold; /**< convert pnts to tris if larger than this */
127 float wide_line_threshold; /**< convert lines to tris if wider than this */
128 boolean line_stipple; /**< do line stipple? */
129 boolean point_sprite; /**< convert points to quads for sprites? */
130
131 /* Temporary storage while the pipeline is being run:
132 */
133 char *verts;
134 unsigned vertex_stride;
135 unsigned vertex_count;
136 } pipeline;
137
138
139 struct vbuf_render *render;
140
141 /* Support prototype passthrough path:
142 */
143 struct {
144 struct {
145 struct draw_pt_middle_end *fetch_emit;
146 struct draw_pt_middle_end *general;
147 } middle;
148
149 struct {
150 struct draw_pt_front_end *vcache;
151 } front;
152 } pt;
153
154 boolean flushing;
155
156 /* pipe state that we need: */
157 const struct pipe_rasterizer_state *rasterizer;
158 struct pipe_viewport_state viewport;
159
160 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
161 unsigned nr_vertex_buffers;
162
163 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
164 unsigned nr_vertex_elements;
165
166 struct draw_vertex_shader *vertex_shader;
167
168 boolean identity_viewport;
169
170 uint num_vs_outputs; /**< convenience, from vertex_shader */
171
172 /* user-space vertex data, buffers */
173 struct {
174 const unsigned *edgeflag;
175
176 /** vertex element/index buffer (ex: glDrawElements) */
177 const void *elts;
178 /** bytes per index (0, 1, 2 or 4) */
179 unsigned eltSize;
180
181 /** vertex arrays */
182 const void *vbuffer[PIPE_MAX_ATTRIBS];
183
184 /** constant buffer (for vertex shader) */
185 const void *constants;
186 } user;
187
188 /* Clip derived state:
189 */
190 float plane[12][4];
191 unsigned nr_planes;
192
193 boolean use_sse;
194
195 /* If a prim stage introduces new vertex attributes, they'll be stored here
196 */
197 struct {
198 uint semantic_name;
199 uint semantic_index;
200 int slot;
201 } extra_vp_outputs;
202
203 unsigned reduced_prim;
204
205 /** TGSI program interpreter runtime state */
206 struct tgsi_exec_machine machine;
207
208 /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
209 */
210 struct gallivm_cpu_engine *engine;
211 void *driver_private;
212 };
213
214
215
216
217 extern void draw_reset_vertex_ids( struct draw_context *draw );
218
219
220
221 /*******************************************************************************
222 * Vertex processing (was passthrough) code:
223 */
224 boolean draw_pt_init( struct draw_context *draw );
225 void draw_pt_destroy( struct draw_context *draw );
226 void draw_pt_reset_vertex_ids( struct draw_context *draw );
227
228
229 /*******************************************************************************
230 * Primitive processing (pipeline) code:
231 */
232
233 boolean draw_pipeline_init( struct draw_context *draw );
234 void draw_pipeline_destroy( struct draw_context *draw );
235
236 void draw_pipeline_run( struct draw_context *draw,
237 unsigned prim,
238 struct vertex_header *vertices,
239 unsigned vertex_count,
240 unsigned stride,
241 const ushort *elts,
242 unsigned count );
243
244 void draw_pipeline_flush( struct draw_context *draw,
245 unsigned flags );
246
247 boolean draw_need_pipeline(const struct draw_context *draw,
248 unsigned prim );
249
250
251 /*******************************************************************************
252 * Flushing
253 */
254
255 #define DRAW_FLUSH_STATE_CHANGE 0x8
256 #define DRAW_FLUSH_BACKEND 0x10
257
258
259 void draw_do_flush( struct draw_context *draw, unsigned flags );
260
261 boolean draw_get_edgeflag( struct draw_context *draw,
262 unsigned idx );
263
264
265
266
267 #endif /* DRAW_PRIVATE_H */