draw: finish the new pipeline setup
[mesa.git] / src / gallium / auxiliary / draw / draw_pt.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 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #ifndef DRAW_PT_H
34 #define DRAW_PT_H
35
36 #include "pipe/p_compiler.h"
37
38 typedef unsigned (*pt_elt_func)( const void *elts, unsigned idx );
39
40 struct draw_pt_middle_end;
41 struct draw_context;
42 struct draw_prim_info;
43 struct draw_vertex_info;
44
45
46 #define PT_SHADE 0x1
47 #define PT_CLIPTEST 0x2
48 #define PT_PIPELINE 0x4
49 #define PT_MAX_MIDDLE 0x8
50
51
52 /* The "front end" - prepare sets of fetch, draw elements for the
53 * middle end.
54 *
55 * Currenly one version of this:
56 * - vcache - catchall implementation, decomposes to TRI/LINE/POINT prims
57 * Later:
58 * - varray, varray_split
59 * - velement, velement_split
60 *
61 * Currenly only using the vcache version.
62 */
63 struct draw_pt_front_end {
64 void (*prepare)( struct draw_pt_front_end *,
65 unsigned input_prim,
66 unsigned output_prim,
67 struct draw_pt_middle_end *,
68 unsigned opt );
69
70 void (*run)( struct draw_pt_front_end *,
71 pt_elt_func elt_func,
72 const void *elt_ptr,
73 int elt_bias,
74 unsigned count );
75
76 void (*finish)( struct draw_pt_front_end * );
77 void (*destroy)( struct draw_pt_front_end * );
78 };
79
80
81 /* The "middle end" - prepares actual hardware vertices for the
82 * hardware backend.
83 *
84 * Currently two versions of this:
85 * - fetch, vertex shade, cliptest, prim-pipeline
86 * - fetch, emit (ie passthrough)
87 */
88 struct draw_pt_middle_end {
89 void (*prepare)( struct draw_pt_middle_end *,
90 unsigned input_prim,
91 unsigned output_prim,
92 unsigned opt,
93 unsigned *max_vertices );
94
95 void (*run)( struct draw_pt_middle_end *,
96 const unsigned *fetch_elts,
97 unsigned fetch_count,
98 const ushort *draw_elts,
99 unsigned draw_count );
100
101 void (*run_linear)(struct draw_pt_middle_end *,
102 unsigned start,
103 unsigned count);
104
105 /* Transform all vertices in a linear range and then draw them with
106 * the supplied element list. May fail and return FALSE.
107 */
108 boolean (*run_linear_elts)( struct draw_pt_middle_end *,
109 unsigned fetch_start,
110 unsigned fetch_count,
111 const ushort *draw_elts,
112 unsigned draw_count );
113
114 int (*get_max_vertex_count)( struct draw_pt_middle_end * );
115
116 void (*finish)( struct draw_pt_middle_end * );
117 void (*destroy)( struct draw_pt_middle_end * );
118 };
119
120
121 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
122 */
123 struct vbuf_render;
124 struct vertex_header;
125
126
127 /* Helper functions.
128 */
129 pt_elt_func draw_pt_elt_func( struct draw_context *draw );
130 const void *draw_pt_elt_ptr( struct draw_context *draw,
131 unsigned start );
132
133 /* Frontends:
134 *
135 * Currently only the general-purpose vcache implementation, could add
136 * a special case for tiny vertex buffers.
137 */
138 struct draw_pt_front_end *draw_pt_vcache( struct draw_context *draw );
139 struct draw_pt_front_end *draw_pt_varray(struct draw_context *draw);
140
141
142 /* Middle-ends:
143 *
144 * Currently one general-purpose case which can do all possibilities,
145 * at the slight expense of creating a vertex_header in some cases
146 * unecessarily.
147 *
148 * The special case fetch_emit code avoids pipeline vertices
149 * altogether and builds hardware vertices directly from API
150 * vertex_elements.
151 */
152 struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw );
153 struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw );
154 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw);
155 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw);
156
157
158
159 /*******************************************************************************
160 * HW vertex emit:
161 */
162 struct pt_emit;
163
164 void draw_pt_emit_prepare( struct pt_emit *emit,
165 unsigned prim,
166 unsigned *max_vertices );
167
168 void draw_pt_emit( struct pt_emit *emit,
169 const struct draw_vertex_info *vert_info,
170 const struct draw_prim_info *prim_info);
171
172 void draw_pt_emit_linear( struct pt_emit *emit,
173 const struct draw_vertex_info *vert_info,
174 const struct draw_prim_info *prim_info);
175
176 void draw_pt_emit_destroy( struct pt_emit *emit );
177
178 struct pt_emit *draw_pt_emit_create( struct draw_context *draw );
179
180 /*******************************************************************************
181 * HW stream output emit:
182 */
183 struct pt_so_emit;
184
185 void draw_pt_so_emit_prepare( struct pt_so_emit *emit,
186 unsigned prim );
187
188 void draw_pt_so_emit( struct pt_so_emit *emit,
189 const struct draw_vertex_info *vert_info,
190 const struct draw_prim_info *prim_info );
191
192 void draw_pt_so_emit_destroy( struct pt_so_emit *emit );
193
194 struct pt_so_emit *draw_pt_so_emit_create( struct draw_context *draw );
195
196 /*******************************************************************************
197 * API vertex fetch:
198 */
199
200 struct pt_fetch;
201 void draw_pt_fetch_prepare( struct pt_fetch *fetch,
202 unsigned vertex_input_count,
203 unsigned vertex_size,
204 unsigned instance_id_index );
205
206 void draw_pt_fetch_run( struct pt_fetch *fetch,
207 const unsigned *elts,
208 unsigned count,
209 char *verts );
210
211 void draw_pt_fetch_run_linear( struct pt_fetch *fetch,
212 unsigned start,
213 unsigned count,
214 char *verts );
215
216 void draw_pt_fetch_destroy( struct pt_fetch *fetch );
217
218 struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw );
219
220 /*******************************************************************************
221 * Post-VS: cliptest, rhw, viewport
222 */
223 struct pt_post_vs;
224
225 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
226 struct draw_vertex_info *info );
227
228 void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
229 boolean bypass_clipping,
230 boolean bypass_viewport,
231 boolean opengl,
232 boolean need_edgeflags );
233
234 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
235
236 void draw_pt_post_vs_destroy( struct pt_post_vs *pvs );
237
238
239 /*******************************************************************************
240 * Utils:
241 */
242 void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr);
243
244
245 #endif