1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keithw@vmware.com>
36 #include "pipe/p_compiler.h"
38 struct draw_pt_middle_end
;
40 struct draw_prim_info
;
41 struct draw_vertex_info
;
45 #define PT_CLIPTEST 0x2
46 #define PT_PIPELINE 0x4
47 #define PT_MAX_MIDDLE 0x8
50 /* The "front end" - prepare sets of fetch, draw elements for the
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
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.
64 * - vsplit - catchall implementation, splits big prims
66 struct draw_pt_front_end
{
67 void (*prepare
)( struct draw_pt_front_end
*,
69 struct draw_pt_middle_end
*,
72 void (*run
)( struct draw_pt_front_end
*,
76 void (*flush
)( struct draw_pt_front_end
*, unsigned flags
);
77 void (*destroy
)( struct draw_pt_front_end
* );
81 /* The "middle end" - prepares actual hardware vertices for the
84 * prim_flags is as defined by pipe_draw_info::flags.
86 * Currently two versions of this:
87 * - fetch, vertex shade, cliptest, prim-pipeline
88 * - fetch, emit (ie passthrough)
90 struct draw_pt_middle_end
{
91 void (*prepare
)( struct draw_pt_middle_end
*,
94 unsigned *max_vertices
);
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.
101 void (*bind_parameters
)(struct draw_pt_middle_end
*);
103 void (*run
)( struct draw_pt_middle_end
*,
104 const unsigned *fetch_elts
,
105 unsigned fetch_count
,
106 const ushort
*draw_elts
,
108 unsigned prim_flags
);
110 void (*run_linear
)(struct draw_pt_middle_end
*,
113 unsigned prim_flags
);
115 /* Transform all vertices in a linear range and then draw them with
116 * the supplied element list. May fail and return FALSE.
118 boolean (*run_linear_elts
)( struct draw_pt_middle_end
*,
119 unsigned fetch_start
,
120 unsigned fetch_count
,
121 const ushort
*draw_elts
,
123 unsigned prim_flags
);
125 int (*get_max_vertex_count
)( struct draw_pt_middle_end
* );
127 void (*finish
)( struct draw_pt_middle_end
* );
128 void (*destroy
)( struct draw_pt_middle_end
* );
132 /* The "back end" - supplied by the driver, defined in draw_vbuf.h.
135 struct vertex_header
;
140 * Currently only the general-purpose vsplit implementation.
142 struct draw_pt_front_end
*draw_pt_vsplit(struct draw_context
*draw
);
147 * Currently one general-purpose case which can do all possibilities,
148 * at the slight expense of creating a vertex_header in some cases
151 * The special case fetch_emit code avoids pipeline vertices
152 * altogether and builds hardware vertices directly from API
155 struct draw_pt_middle_end
*draw_pt_fetch_emit( struct draw_context
*draw
);
156 struct draw_pt_middle_end
*draw_pt_middle_fse( struct draw_context
*draw
);
157 struct draw_pt_middle_end
*draw_pt_fetch_pipeline_or_emit(struct draw_context
*draw
);
158 struct draw_pt_middle_end
*draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context
*draw
);
162 /*******************************************************************************
167 void draw_pt_emit_prepare( struct pt_emit
*emit
,
169 unsigned *max_vertices
);
171 void draw_pt_emit( struct pt_emit
*emit
,
172 const struct draw_vertex_info
*vert_info
,
173 const struct draw_prim_info
*prim_info
);
175 void draw_pt_emit_linear( struct pt_emit
*emit
,
176 const struct draw_vertex_info
*vert_info
,
177 const struct draw_prim_info
*prim_info
);
179 void draw_pt_emit_destroy( struct pt_emit
*emit
);
181 struct pt_emit
*draw_pt_emit_create( struct draw_context
*draw
);
183 /*******************************************************************************
184 * HW stream output emit:
188 void draw_pt_so_emit_prepare(struct pt_so_emit
*emit
, boolean use_pre_clip_pos
);
190 void draw_pt_so_emit( struct pt_so_emit
*emit
,
191 const struct draw_vertex_info
*vert_info
,
192 const struct draw_prim_info
*prim_info
);
194 void draw_pt_so_emit_destroy( struct pt_so_emit
*emit
);
196 struct pt_so_emit
*draw_pt_so_emit_create( struct draw_context
*draw
);
198 /*******************************************************************************
203 void draw_pt_fetch_prepare( struct pt_fetch
*fetch
,
204 unsigned vertex_input_count
,
205 unsigned vertex_size
,
206 unsigned instance_id_index
);
208 void draw_pt_fetch_run( struct pt_fetch
*fetch
,
209 const unsigned *elts
,
213 void draw_pt_fetch_run_linear( struct pt_fetch
*fetch
,
218 void draw_pt_fetch_destroy( struct pt_fetch
*fetch
);
220 struct pt_fetch
*draw_pt_fetch_create( struct draw_context
*draw
);
222 /*******************************************************************************
223 * Post-VS: cliptest, rhw, viewport
227 boolean
draw_pt_post_vs_run( struct pt_post_vs
*pvs
,
228 struct draw_vertex_info
*info
,
229 const struct draw_prim_info
*prim_info
);
231 void draw_pt_post_vs_prepare( struct pt_post_vs
*pvs
,
236 boolean bypass_viewport
,
238 boolean need_edgeflags
);
240 struct pt_post_vs
*draw_pt_post_vs_create( struct draw_context
*draw
);
242 void draw_pt_post_vs_destroy( struct pt_post_vs
*pvs
);
245 /*******************************************************************************
248 void draw_pt_split_prim(unsigned prim
, unsigned *first
, unsigned *incr
);
249 unsigned draw_pt_trim_count(unsigned count
, unsigned first
, unsigned incr
);