1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci /*
29bf215546Sopenharmony_ci  * Authors:
30bf215546Sopenharmony_ci  *   Keith Whitwell <keithw@vmware.com>
31bf215546Sopenharmony_ci  */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#ifndef DRAW_PT_H
34bf215546Sopenharmony_ci#define DRAW_PT_H
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct draw_pt_middle_end;
39bf215546Sopenharmony_cistruct draw_context;
40bf215546Sopenharmony_cistruct draw_prim_info;
41bf215546Sopenharmony_cistruct draw_vertex_info;
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci#define PT_SHADE      0x1
45bf215546Sopenharmony_ci#define PT_CLIPTEST   0x2
46bf215546Sopenharmony_ci#define PT_PIPELINE   0x4
47bf215546Sopenharmony_ci#define PT_MAX_MIDDLE 0x8
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/* The "front end" - prepare sets of fetch, draw elements for the
51bf215546Sopenharmony_ci * middle end.
52bf215546Sopenharmony_ci *
53bf215546Sopenharmony_ci * The fetch elements are indices to the vertices.  The draw elements are
54bf215546Sopenharmony_ci * indices to the fetched vertices.  When both arrays of elements are both
55bf215546Sopenharmony_ci * linear, middle->run_linear is called;  When only the fetch elements are
56bf215546Sopenharmony_ci * linear, middle->run_linear_elts is called;  Otherwise, middle->run is
57bf215546Sopenharmony_ci * called.
58bf215546Sopenharmony_ci *
59bf215546Sopenharmony_ci * When the number of the draw elements exceeds max_vertex of the middle end,
60bf215546Sopenharmony_ci * the draw elements (as well as the fetch elements) are splitted and the
61bf215546Sopenharmony_ci * middle end is called multiple times.
62bf215546Sopenharmony_ci *
63bf215546Sopenharmony_ci * Currenly there is:
64bf215546Sopenharmony_ci *    - vsplit - catchall implementation, splits big prims
65bf215546Sopenharmony_ci */
66bf215546Sopenharmony_cistruct draw_pt_front_end {
67bf215546Sopenharmony_ci   void (*prepare)(struct draw_pt_front_end *,
68bf215546Sopenharmony_ci                   enum pipe_prim_type prim,
69bf215546Sopenharmony_ci                   struct draw_pt_middle_end *,
70bf215546Sopenharmony_ci                   unsigned opt);
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   void (*run)(struct draw_pt_front_end *,
73bf215546Sopenharmony_ci               unsigned start,
74bf215546Sopenharmony_ci               unsigned count);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   void (*flush)(struct draw_pt_front_end *, unsigned flags);
77bf215546Sopenharmony_ci   void (*destroy)(struct draw_pt_front_end *);
78bf215546Sopenharmony_ci};
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci/* The "middle end" - prepares actual hardware vertices for the
82bf215546Sopenharmony_ci * hardware backend.
83bf215546Sopenharmony_ci *
84bf215546Sopenharmony_ci * prim_flags is as defined by pipe_draw_info::flags.
85bf215546Sopenharmony_ci *
86bf215546Sopenharmony_ci * Currently two versions of this:
87bf215546Sopenharmony_ci *     - fetch, vertex shade, cliptest, prim-pipeline
88bf215546Sopenharmony_ci *     - fetch, emit (ie passthrough)
89bf215546Sopenharmony_ci */
90bf215546Sopenharmony_cistruct draw_pt_middle_end {
91bf215546Sopenharmony_ci   void (*prepare)(struct draw_pt_middle_end *,
92bf215546Sopenharmony_ci                   enum pipe_prim_type prim,
93bf215546Sopenharmony_ci                   unsigned opt,
94bf215546Sopenharmony_ci                   unsigned *max_vertices);
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   /**
97bf215546Sopenharmony_ci    * Bind/update parameter state such as constants, viewport dims
98bf215546Sopenharmony_ci    * and clip planes.  Basically, stuff which isn't "baked" into the
99bf215546Sopenharmony_ci    * shader or pipeline state.
100bf215546Sopenharmony_ci    */
101bf215546Sopenharmony_ci   void (*bind_parameters)(struct draw_pt_middle_end *);
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   void (*run)(struct draw_pt_middle_end *,
104bf215546Sopenharmony_ci               const unsigned *fetch_elts,
105bf215546Sopenharmony_ci               unsigned fetch_count,
106bf215546Sopenharmony_ci               const ushort *draw_elts,
107bf215546Sopenharmony_ci               unsigned draw_count,
108bf215546Sopenharmony_ci               unsigned prim_flags);
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   void (*run_linear)(struct draw_pt_middle_end *,
111bf215546Sopenharmony_ci                      unsigned start,
112bf215546Sopenharmony_ci                      unsigned count,
113bf215546Sopenharmony_ci                      unsigned prim_flags);
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   /* Transform all vertices in a linear range and then draw them with
116bf215546Sopenharmony_ci    * the supplied element list.  May fail and return FALSE.
117bf215546Sopenharmony_ci    */
118bf215546Sopenharmony_ci   boolean (*run_linear_elts)(struct draw_pt_middle_end *,
119bf215546Sopenharmony_ci                              unsigned fetch_start,
120bf215546Sopenharmony_ci                              unsigned fetch_count,
121bf215546Sopenharmony_ci                              const ushort *draw_elts,
122bf215546Sopenharmony_ci                              unsigned draw_count,
123bf215546Sopenharmony_ci                              unsigned prim_flags);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci   int (*get_max_vertex_count)(struct draw_pt_middle_end *);
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   void (*finish)(struct draw_pt_middle_end *);
128bf215546Sopenharmony_ci   void (*destroy)(struct draw_pt_middle_end *);
129bf215546Sopenharmony_ci};
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci/* The "back end" - supplied by the driver, defined in draw_vbuf.h.
133bf215546Sopenharmony_ci */
134bf215546Sopenharmony_cistruct vbuf_render;
135bf215546Sopenharmony_cistruct vertex_header;
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci/* Frontends:
139bf215546Sopenharmony_ci *
140bf215546Sopenharmony_ci * Currently only the general-purpose vsplit implementation.
141bf215546Sopenharmony_ci */
142bf215546Sopenharmony_cistruct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw);
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_ci/* Middle-ends:
146bf215546Sopenharmony_ci *
147bf215546Sopenharmony_ci * Currently one general-purpose case which can do all possibilities,
148bf215546Sopenharmony_ci * at the slight expense of creating a vertex_header in some cases
149bf215546Sopenharmony_ci * unecessarily.
150bf215546Sopenharmony_ci */
151bf215546Sopenharmony_cistruct draw_pt_middle_end *draw_pt_middle_fse(struct draw_context *draw);
152bf215546Sopenharmony_cistruct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw);
153bf215546Sopenharmony_cistruct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw);
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci/*******************************************************************************
158bf215546Sopenharmony_ci * HW vertex emit:
159bf215546Sopenharmony_ci */
160bf215546Sopenharmony_cistruct pt_emit;
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_civoid
163bf215546Sopenharmony_cidraw_pt_emit_prepare(struct pt_emit *emit,
164bf215546Sopenharmony_ci                     enum pipe_prim_type prim,
165bf215546Sopenharmony_ci                     unsigned *max_vertices);
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_civoid
168bf215546Sopenharmony_cidraw_pt_emit(struct pt_emit *emit,
169bf215546Sopenharmony_ci             const struct draw_vertex_info *vert_info,
170bf215546Sopenharmony_ci             const struct draw_prim_info *prim_info);
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_civoid
173bf215546Sopenharmony_cidraw_pt_emit_linear(struct pt_emit *emit,
174bf215546Sopenharmony_ci                    const struct draw_vertex_info *vert_info,
175bf215546Sopenharmony_ci                    const struct draw_prim_info *prim_info);
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_civoid
178bf215546Sopenharmony_cidraw_pt_emit_destroy(struct pt_emit *emit);
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_cistruct pt_emit *
181bf215546Sopenharmony_cidraw_pt_emit_create(struct draw_context *draw);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci/*******************************************************************************
185bf215546Sopenharmony_ci * HW stream output emit:
186bf215546Sopenharmony_ci */
187bf215546Sopenharmony_cistruct pt_so_emit;
188bf215546Sopenharmony_ci
189bf215546Sopenharmony_civoid
190bf215546Sopenharmony_cidraw_pt_so_emit_prepare(struct pt_so_emit *emit, boolean use_pre_clip_pos);
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_civoid
193bf215546Sopenharmony_cidraw_pt_so_emit(struct pt_so_emit *emit,
194bf215546Sopenharmony_ci                int num_vertex_streams,
195bf215546Sopenharmony_ci                const struct draw_vertex_info *vert_info,
196bf215546Sopenharmony_ci                const struct draw_prim_info *prim_info);
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_civoid
199bf215546Sopenharmony_cidraw_pt_so_emit_destroy(struct pt_so_emit *emit);
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_cistruct pt_so_emit *
202bf215546Sopenharmony_cidraw_pt_so_emit_create(struct draw_context *draw);
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci/*******************************************************************************
206bf215546Sopenharmony_ci * API vertex fetch:
207bf215546Sopenharmony_ci */
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_cistruct pt_fetch;
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_civoid
212bf215546Sopenharmony_cidraw_pt_fetch_prepare(struct pt_fetch *fetch,
213bf215546Sopenharmony_ci                      unsigned vertex_input_count,
214bf215546Sopenharmony_ci                      unsigned vertex_size,
215bf215546Sopenharmony_ci                      unsigned instance_id_index);
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_civoid
218bf215546Sopenharmony_cidraw_pt_fetch_run(struct pt_fetch *fetch,
219bf215546Sopenharmony_ci                  const unsigned *elts,
220bf215546Sopenharmony_ci                  unsigned count,
221bf215546Sopenharmony_ci                  char *verts);
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_civoid
224bf215546Sopenharmony_cidraw_pt_fetch_run_linear(struct pt_fetch *fetch,
225bf215546Sopenharmony_ci                         unsigned start,
226bf215546Sopenharmony_ci                         unsigned count,
227bf215546Sopenharmony_ci                         char *verts);
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_civoid
230bf215546Sopenharmony_cidraw_pt_fetch_destroy(struct pt_fetch *fetch);
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_cistruct pt_fetch *
233bf215546Sopenharmony_cidraw_pt_fetch_create(struct draw_context *draw);
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci/*******************************************************************************
236bf215546Sopenharmony_ci * Post-VS: cliptest, rhw, viewport
237bf215546Sopenharmony_ci */
238bf215546Sopenharmony_cistruct pt_post_vs;
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ciboolean
241bf215546Sopenharmony_cidraw_pt_post_vs_run(struct pt_post_vs *pvs,
242bf215546Sopenharmony_ci                    struct draw_vertex_info *info,
243bf215546Sopenharmony_ci                    const struct draw_prim_info *prim_info);
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_civoid
246bf215546Sopenharmony_cidraw_pt_post_vs_prepare(struct pt_post_vs *pvs,
247bf215546Sopenharmony_ci                        boolean clip_xy,
248bf215546Sopenharmony_ci                        boolean clip_z,
249bf215546Sopenharmony_ci                        boolean clip_user,
250bf215546Sopenharmony_ci                        boolean guard_band,
251bf215546Sopenharmony_ci                        boolean bypass_viewport,
252bf215546Sopenharmony_ci                        boolean clip_halfz,
253bf215546Sopenharmony_ci                        boolean need_edgeflags);
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_cistruct pt_post_vs *
256bf215546Sopenharmony_cidraw_pt_post_vs_create(struct draw_context *draw);
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_civoid
259bf215546Sopenharmony_cidraw_pt_post_vs_destroy(struct pt_post_vs *pvs);
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci/*******************************************************************************
263bf215546Sopenharmony_ci * Utils:
264bf215546Sopenharmony_ci */
265bf215546Sopenharmony_civoid
266bf215546Sopenharmony_cidraw_pt_split_prim(enum pipe_prim_type prim, unsigned *first, unsigned *incr);
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_ciunsigned
269bf215546Sopenharmony_cidraw_pt_trim_count(unsigned count, unsigned first, unsigned incr);
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_ci#endif
273