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