• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
31   */
32 
33 #ifndef DRAW_PT_H
34 #define DRAW_PT_H
35 
36 #include "pipe/p_compiler.h"
37 
38 struct draw_pt_middle_end;
39 struct draw_context;
40 struct draw_prim_info;
41 struct draw_vertex_info;
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  * The fetch elements are indices to the vertices.  The draw elements are
54  * indices to the fetched vertices.  When both arrays of elements are both
55  * linear, middle->run_linear is called;  When only the fetch elements are
56  * linear, middle->run_linear_elts is called;  Otherwise, middle->run is
57  * called.
58  *
59  * When the number of the draw elements exceeds max_vertex of the middle end,
60  * the draw elements (as well as the fetch elements) are splitted and the
61  * middle end is called multiple times.
62  *
63  * Currenly there is:
64  *    - vsplit - catchall implementation, splits big prims
65  */
66 struct draw_pt_front_end {
67    void (*prepare)(struct draw_pt_front_end *,
68                    enum pipe_prim_type prim,
69                    struct draw_pt_middle_end *,
70                    unsigned opt);
71 
72    void (*run)(struct draw_pt_front_end *,
73                unsigned start,
74                unsigned count);
75 
76    void (*flush)(struct draw_pt_front_end *, unsigned flags);
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  * prim_flags is as defined by pipe_draw_info::flags.
85  *
86  * Currently two versions of this:
87  *     - fetch, vertex shade, cliptest, prim-pipeline
88  *     - fetch, emit (ie passthrough)
89  */
90 struct draw_pt_middle_end {
91    void (*prepare)(struct draw_pt_middle_end *,
92                    enum pipe_prim_type prim,
93                    unsigned opt,
94                    unsigned *max_vertices);
95 
96    /**
97     * Bind/update parameter state such as constants, viewport dims
98     * and clip planes.  Basically, stuff which isn't "baked" into the
99     * shader or pipeline state.
100     */
101    void (*bind_parameters)(struct draw_pt_middle_end *);
102 
103    void (*run)(struct draw_pt_middle_end *,
104                const unsigned *fetch_elts,
105                unsigned fetch_count,
106                const ushort *draw_elts,
107                unsigned draw_count,
108                unsigned prim_flags);
109 
110    void (*run_linear)(struct draw_pt_middle_end *,
111                       unsigned start,
112                       unsigned count,
113                       unsigned prim_flags);
114 
115    /* Transform all vertices in a linear range and then draw them with
116     * the supplied element list.  May fail and return FALSE.
117     */
118    boolean (*run_linear_elts)(struct draw_pt_middle_end *,
119                               unsigned fetch_start,
120                               unsigned fetch_count,
121                               const ushort *draw_elts,
122                               unsigned draw_count,
123                               unsigned prim_flags);
124 
125    int (*get_max_vertex_count)(struct draw_pt_middle_end *);
126 
127    void (*finish)(struct draw_pt_middle_end *);
128    void (*destroy)(struct draw_pt_middle_end *);
129 };
130 
131 
132 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
133  */
134 struct vbuf_render;
135 struct vertex_header;
136 
137 
138 /* Frontends:
139  *
140  * Currently only the general-purpose vsplit implementation.
141  */
142 struct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw);
143 
144 
145 /* Middle-ends:
146  *
147  * Currently one general-purpose case which can do all possibilities,
148  * at the slight expense of creating a vertex_header in some cases
149  * unecessarily.
150  */
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
163 draw_pt_emit_prepare(struct pt_emit *emit,
164                      enum pipe_prim_type prim,
165                      unsigned *max_vertices);
166 
167 void
168 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
173 draw_pt_emit_linear(struct pt_emit *emit,
174                     const struct draw_vertex_info *vert_info,
175                     const struct draw_prim_info *prim_info);
176 
177 void
178 draw_pt_emit_destroy(struct pt_emit *emit);
179 
180 struct pt_emit *
181 draw_pt_emit_create(struct draw_context *draw);
182 
183 
184 /*******************************************************************************
185  * HW stream output emit:
186  */
187 struct pt_so_emit;
188 
189 void
190 draw_pt_so_emit_prepare(struct pt_so_emit *emit, boolean use_pre_clip_pos);
191 
192 void
193 draw_pt_so_emit(struct pt_so_emit *emit,
194                 int num_vertex_streams,
195                 const struct draw_vertex_info *vert_info,
196                 const struct draw_prim_info *prim_info);
197 
198 void
199 draw_pt_so_emit_destroy(struct pt_so_emit *emit);
200 
201 struct pt_so_emit *
202 draw_pt_so_emit_create(struct draw_context *draw);
203 
204 
205 /*******************************************************************************
206  * API vertex fetch:
207  */
208 
209 struct pt_fetch;
210 
211 void
212 draw_pt_fetch_prepare(struct pt_fetch *fetch,
213                       unsigned vertex_input_count,
214                       unsigned vertex_size,
215                       unsigned instance_id_index);
216 
217 void
218 draw_pt_fetch_run(struct pt_fetch *fetch,
219                   const unsigned *elts,
220                   unsigned count,
221                   char *verts);
222 
223 void
224 draw_pt_fetch_run_linear(struct pt_fetch *fetch,
225                          unsigned start,
226                          unsigned count,
227                          char *verts);
228 
229 void
230 draw_pt_fetch_destroy(struct pt_fetch *fetch);
231 
232 struct pt_fetch *
233 draw_pt_fetch_create(struct draw_context *draw);
234 
235 /*******************************************************************************
236  * Post-VS: cliptest, rhw, viewport
237  */
238 struct pt_post_vs;
239 
240 boolean
241 draw_pt_post_vs_run(struct pt_post_vs *pvs,
242                     struct draw_vertex_info *info,
243                     const struct draw_prim_info *prim_info);
244 
245 void
246 draw_pt_post_vs_prepare(struct pt_post_vs *pvs,
247                         boolean clip_xy,
248                         boolean clip_z,
249                         boolean clip_user,
250                         boolean guard_band,
251                         boolean bypass_viewport,
252                         boolean clip_halfz,
253                         boolean need_edgeflags);
254 
255 struct pt_post_vs *
256 draw_pt_post_vs_create(struct draw_context *draw);
257 
258 void
259 draw_pt_post_vs_destroy(struct pt_post_vs *pvs);
260 
261 
262 /*******************************************************************************
263  * Utils:
264  */
265 void
266 draw_pt_split_prim(enum pipe_prim_type prim, unsigned *first, unsigned *incr);
267 
268 unsigned
269 draw_pt_trim_count(unsigned count, unsigned first, unsigned incr);
270 
271 
272 #endif
273