draw: Add vsplit frontend.
[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 * The fetch elements are indices to the vertices. The draw elements are
56 * indices to the fetched vertices. When both arrays of elements are both
57 * linear, middle->run_linear is called; When only the fetch elements are
58 * linear, middle->run_linear_elts is called; Otherwise, middle->run is
59 * called.
60 *
61 * When the number of the draw elements exceeds max_vertex of the middle end,
62 * the draw elements (as well as the fetch elements) are splitted and the
63 * middle end is called multiple times.
64 *
65 * Currenly there are:
66 * - vcache - catchall implementation, decomposes to TRI/LINE/POINT prims
67 * - vsplit - catchall implementation, splits big prims
68 * Later:
69 * - varray, varray_split
70 * - velement, velement_split
71 *
72 * Currenly only using the vcache version.
73 */
74 struct draw_pt_front_end {
75 void (*prepare)( struct draw_pt_front_end *,
76 unsigned prim,
77 struct draw_pt_middle_end *,
78 unsigned opt );
79
80 void (*run)( struct draw_pt_front_end *,
81 unsigned start,
82 unsigned count );
83
84 void (*finish)( struct draw_pt_front_end * );
85 void (*destroy)( struct draw_pt_front_end * );
86 };
87
88
89 /* The "middle end" - prepares actual hardware vertices for the
90 * hardware backend.
91 *
92 * prim_flags is as defined by pipe_draw_info::flags.
93 *
94 * Currently two versions of this:
95 * - fetch, vertex shade, cliptest, prim-pipeline
96 * - fetch, emit (ie passthrough)
97 */
98 struct draw_pt_middle_end {
99 void (*prepare)( struct draw_pt_middle_end *,
100 unsigned prim,
101 unsigned opt,
102 unsigned *max_vertices );
103
104 void (*run)( struct draw_pt_middle_end *,
105 const unsigned *fetch_elts,
106 unsigned fetch_count,
107 const ushort *draw_elts,
108 unsigned draw_count,
109 unsigned prim_flags );
110
111 void (*run_linear)(struct draw_pt_middle_end *,
112 unsigned start,
113 unsigned count,
114 unsigned prim_flags );
115
116 /* Transform all vertices in a linear range and then draw them with
117 * the supplied element list. May fail and return FALSE.
118 */
119 boolean (*run_linear_elts)( struct draw_pt_middle_end *,
120 unsigned fetch_start,
121 unsigned fetch_count,
122 const ushort *draw_elts,
123 unsigned draw_count,
124 unsigned prim_flags );
125
126 int (*get_max_vertex_count)( struct draw_pt_middle_end * );
127
128 void (*finish)( struct draw_pt_middle_end * );
129 void (*destroy)( struct draw_pt_middle_end * );
130 };
131
132
133 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
134 */
135 struct vbuf_render;
136 struct vertex_header;
137
138
139 /* Helper functions.
140 */
141 pt_elt_func draw_pt_elt_func( struct draw_context *draw );
142 const void *draw_pt_elt_ptr( struct draw_context *draw,
143 unsigned start );
144
145 /* Frontends:
146 *
147 * Currently only the general-purpose vcache implementation, could add
148 * a special case for tiny vertex buffers.
149 */
150 struct draw_pt_front_end *draw_pt_vcache( struct draw_context *draw );
151 struct draw_pt_front_end *draw_pt_varray(struct draw_context *draw);
152 struct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw);
153
154
155 /* Middle-ends:
156 *
157 * Currently one general-purpose case which can do all possibilities,
158 * at the slight expense of creating a vertex_header in some cases
159 * unecessarily.
160 *
161 * The special case fetch_emit code avoids pipeline vertices
162 * altogether and builds hardware vertices directly from API
163 * vertex_elements.
164 */
165 struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw );
166 struct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw );
167 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw);
168 struct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw);
169
170
171
172 /*******************************************************************************
173 * HW vertex emit:
174 */
175 struct pt_emit;
176
177 void draw_pt_emit_prepare( struct pt_emit *emit,
178 unsigned prim,
179 unsigned *max_vertices );
180
181 void draw_pt_emit( struct pt_emit *emit,
182 const struct draw_vertex_info *vert_info,
183 const struct draw_prim_info *prim_info);
184
185 void draw_pt_emit_linear( struct pt_emit *emit,
186 const struct draw_vertex_info *vert_info,
187 const struct draw_prim_info *prim_info);
188
189 void draw_pt_emit_destroy( struct pt_emit *emit );
190
191 struct pt_emit *draw_pt_emit_create( struct draw_context *draw );
192
193 /*******************************************************************************
194 * HW stream output emit:
195 */
196 struct pt_so_emit;
197
198 void draw_pt_so_emit_prepare( struct pt_so_emit *emit );
199
200 void draw_pt_so_emit( struct pt_so_emit *emit,
201 const struct draw_vertex_info *vert_info,
202 const struct draw_prim_info *prim_info );
203
204 void draw_pt_so_emit_destroy( struct pt_so_emit *emit );
205
206 struct pt_so_emit *draw_pt_so_emit_create( struct draw_context *draw );
207
208 /*******************************************************************************
209 * API vertex fetch:
210 */
211
212 struct pt_fetch;
213 void draw_pt_fetch_prepare( struct pt_fetch *fetch,
214 unsigned vertex_input_count,
215 unsigned vertex_size,
216 unsigned instance_id_index );
217
218 void draw_pt_fetch_run( struct pt_fetch *fetch,
219 const unsigned *elts,
220 unsigned count,
221 char *verts );
222
223 void draw_pt_fetch_run_linear( struct pt_fetch *fetch,
224 unsigned start,
225 unsigned count,
226 char *verts );
227
228 void draw_pt_fetch_destroy( struct pt_fetch *fetch );
229
230 struct pt_fetch *draw_pt_fetch_create( struct draw_context *draw );
231
232 /*******************************************************************************
233 * Post-VS: cliptest, rhw, viewport
234 */
235 struct pt_post_vs;
236
237 boolean draw_pt_post_vs_run( struct pt_post_vs *pvs,
238 struct draw_vertex_info *info );
239
240 void draw_pt_post_vs_prepare( struct pt_post_vs *pvs,
241 boolean bypass_clipping,
242 boolean bypass_viewport,
243 boolean opengl,
244 boolean need_edgeflags );
245
246 struct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw );
247
248 void draw_pt_post_vs_destroy( struct pt_post_vs *pvs );
249
250
251 /*******************************************************************************
252 * Utils:
253 */
254 void draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr);
255 unsigned draw_pt_trim_count(unsigned count, unsigned first, unsigned incr);
256
257
258 #endif