draw_private.h revision 62628c4d3d497cbca73fde869c9069fa90e6453e
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
51struct pipe_context;
52struct gallivm_prog;
53struct gallivm_cpu_engine;
54struct draw_vertex_shader;
55struct draw_context;
56struct draw_stage;
57struct vbuf_render;
58
59
60/**
61 * Basic vertex info.
62 * Carry some useful information around with the vertices in the prim pipe.
63 */
64struct 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 * Private context for the drawing module.
83 */
84struct draw_context
85{
86   /** Drawing/primitive pipeline stages */
87   struct {
88      struct draw_stage *first;  /**< one of the following */
89
90      struct draw_stage *validate;
91
92      /* stages (in logical order) */
93      struct draw_stage *flatshade;
94      struct draw_stage *clip;
95      struct draw_stage *cull;
96      struct draw_stage *twoside;
97      struct draw_stage *offset;
98      struct draw_stage *unfilled;
99      struct draw_stage *stipple;
100      struct draw_stage *aapoint;
101      struct draw_stage *aaline;
102      struct draw_stage *pstipple;
103      struct draw_stage *wide_line;
104      struct draw_stage *wide_point;
105      struct draw_stage *rasterize;
106
107      float wide_point_threshold; /**< convert pnts to tris if larger than this */
108      float wide_line_threshold;  /**< convert lines to tris if wider than this */
109      boolean line_stipple;       /**< do line stipple? */
110      boolean point_sprite;       /**< convert points to quads for sprites? */
111
112      /* Temporary storage while the pipeline is being run:
113       */
114      char *verts;
115      unsigned vertex_stride;
116      unsigned vertex_count;
117   } pipeline;
118
119
120   struct vbuf_render *render;
121
122   /* Support prototype passthrough path:
123    */
124   struct {
125      struct {
126         struct draw_pt_middle_end *fetch_emit;
127         struct draw_pt_middle_end *fetch_shade_emit;
128         struct draw_pt_middle_end *general;
129      } middle;
130
131      struct {
132         struct draw_pt_front_end *vcache;
133         struct draw_pt_front_end *varray;
134      } front;
135
136      struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
137      unsigned nr_vertex_buffers;
138
139      struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
140      unsigned nr_vertex_elements;
141
142      /* user-space vertex data, buffers */
143      struct {
144         const unsigned *edgeflag;
145
146         /** vertex element/index buffer (ex: glDrawElements) */
147         const void *elts;
148         /** bytes per index (0, 1, 2 or 4) */
149         unsigned eltSize;
150
151         /** vertex arrays */
152         const void *vbuffer[PIPE_MAX_ATTRIBS];
153
154         /** constant buffer (for vertex shader) */
155         const void *constants;
156      } user;
157
158      boolean test_fse;
159   } pt;
160
161   struct {
162      boolean bypass_clipping;
163   } driver;
164
165   boolean flushing;         /**< debugging/sanity */
166   boolean suspend_flushing; /**< internally set */
167   boolean bypass_clipping;  /**< set if either api or driver bypass_clipping true */
168
169   /* pipe state that we need: */
170   const struct pipe_rasterizer_state *rasterizer;
171   struct pipe_viewport_state viewport;
172   boolean identity_viewport;
173
174   struct {
175      struct draw_vertex_shader *vertex_shader;
176      uint num_vs_outputs;  /**< convenience, from vertex_shader */
177
178
179      /** TGSI program interpreter runtime state */
180      struct tgsi_exec_machine machine;
181
182      /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
183       */
184      struct gallivm_cpu_engine *engine;
185
186      /* Here's another one:
187       */
188      struct aos_machine *aos_machine;
189
190
191      struct translate *fetch;
192      struct translate_cache *fetch_cache;
193      struct translate *emit;
194      struct translate_cache *emit_cache;
195   } vs;
196
197   /* Clip derived state:
198    */
199   float plane[12][4];
200   unsigned nr_planes;
201
202   /* If a prim stage introduces new vertex attributes, they'll be stored here
203    */
204   struct {
205      uint semantic_name;
206      uint semantic_index;
207      int slot;
208   } extra_vp_outputs;
209
210   unsigned reduced_prim;
211
212   void *driver_private;
213};
214
215
216/*******************************************************************************
217 * Vertex shader code:
218 */
219boolean draw_vs_init( struct draw_context *draw );
220void draw_vs_destroy( struct draw_context *draw );
221
222void draw_vs_set_viewport( struct draw_context *,
223                           const struct pipe_viewport_state * );
224
225void draw_vs_set_constants( struct draw_context *,
226                            const float (*constants)[4] );
227
228
229
230
231/*******************************************************************************
232 * Vertex processing (was passthrough) code:
233 */
234boolean draw_pt_init( struct draw_context *draw );
235void draw_pt_destroy( struct draw_context *draw );
236void draw_pt_reset_vertex_ids( struct draw_context *draw );
237
238
239/*******************************************************************************
240 * Primitive processing (pipeline) code:
241 */
242
243boolean draw_pipeline_init( struct draw_context *draw );
244void draw_pipeline_destroy( struct draw_context *draw );
245
246
247
248
249
250/* We use the top few bits in the elts[] parameter to convey a little
251 * API information.  This limits the number of vertices we can address
252 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
253 * draw indices.
254 *
255 * These flags expected at first vertex of lines & triangles when
256 * unfilled and/or line stipple modes are operational.
257 */
258#define DRAW_PIPE_EDGE_FLAG_0   (0x1<<12)
259#define DRAW_PIPE_EDGE_FLAG_1   (0x2<<12)
260#define DRAW_PIPE_EDGE_FLAG_2   (0x4<<12)
261#define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
262#define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
263#define DRAW_PIPE_FLAG_MASK     (0xf<<12)
264
265void draw_pipeline_run( struct draw_context *draw,
266                        unsigned prim,
267                        struct vertex_header *vertices,
268                        unsigned vertex_count,
269                        unsigned stride,
270                        const ushort *elts,
271                        unsigned count );
272
273void draw_pipeline_run_linear( struct draw_context *draw,
274                               unsigned prim,
275                               struct vertex_header *vertices,
276                               unsigned count,
277                               unsigned stride );
278
279
280
281void draw_pipeline_flush( struct draw_context *draw,
282                          unsigned flags );
283
284
285
286/*******************************************************************************
287 * Flushing
288 */
289
290#define DRAW_FLUSH_STATE_CHANGE              0x8
291#define DRAW_FLUSH_BACKEND                   0x10
292
293
294void draw_do_flush( struct draw_context *draw, unsigned flags );
295
296
297
298
299#endif /* DRAW_PRIVATE_H */
300