2 * Mesa 3-D graphics library
5 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Copyright (C) 2010 LunarG Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 #define CONCAT2(name, elt_type) name ## elt_type
28 #define CONCAT(name, elt_type) CONCAT2(name, elt_type)
33 * Fetch all elements in [min_index, max_index] with bias, and use the
34 * (rebased) index buffer as the draw elements.
37 CONCAT(vsplit_segment_fast_
, ELT_TYPE
)(struct vsplit_frontend
*vsplit
,
39 unsigned istart
, unsigned icount
)
41 struct draw_context
*draw
= vsplit
->draw
;
42 const ELT_TYPE
*ib
= (const ELT_TYPE
*) draw
->pt
.user
.elts
;
43 const unsigned min_index
= draw
->pt
.user
.min_index
;
44 const unsigned max_index
= draw
->pt
.user
.max_index
;
45 const int elt_bias
= draw
->pt
.user
.eltBias
;
46 unsigned fetch_start
, fetch_count
;
47 const ushort
*draw_elts
;
50 assert(icount
<= vsplit
->segment_size
);
52 /* this is faster only when we fetch less elements than the normal path */
53 if (max_index
- min_index
> icount
- 1)
56 if (elt_bias
< 0 && min_index
< -elt_bias
)
60 for (i
= 0; i
< draw
->pt
.nr_vertex_elements
; i
++) {
61 if (draw
->pt
.vertex_element
[i
].instance_divisor
)
65 fetch_start
= min_index
+ elt_bias
;
66 fetch_count
= max_index
- min_index
+ 1;
68 if (min_index
== 0 && sizeof(ib
[0]) == sizeof(draw_elts
[0])) {
69 for (i
= 0; i
< icount
; i
++) {
70 ELT_TYPE idx
= ib
[istart
+ i
];
71 assert(idx
>= min_index
&& idx
<= max_index
);
73 draw_elts
= (const ushort
*) ib
;
77 for (i
= 0; i
< icount
; i
++) {
78 ELT_TYPE idx
= ib
[istart
+ i
];
80 assert(idx
>= min_index
&& idx
<= max_index
);
81 vsplit
->draw_elts
[i
] = (ushort
) idx
;
85 for (i
= 0; i
< icount
; i
++) {
86 ELT_TYPE idx
= ib
[istart
+ i
];
88 assert(idx
>= min_index
&& idx
<= max_index
);
89 vsplit
->draw_elts
[i
] = (ushort
) (idx
- min_index
);
93 draw_elts
= vsplit
->draw_elts
;
96 return vsplit
->middle
->run_linear_elts(vsplit
->middle
,
97 fetch_start
, fetch_count
,
98 draw_elts
, icount
, flags
);
102 * Use the cache to prepare the fetch and draw elements, and flush.
104 * When spoken is TRUE, ispoken replaces istart; When close is TRUE, iclose is
108 CONCAT(vsplit_segment_cache_
, ELT_TYPE
)(struct vsplit_frontend
*vsplit
,
110 unsigned istart
, unsigned icount
,
111 boolean spoken
, unsigned ispoken
,
112 boolean close
, unsigned iclose
)
114 struct draw_context
*draw
= vsplit
->draw
;
115 const ELT_TYPE
*ib
= (const ELT_TYPE
*) draw
->pt
.user
.elts
;
116 const int ibias
= draw
->pt
.user
.eltBias
;
119 assert(icount
+ !!close
<= vsplit
->segment_size
);
121 vsplit_clear_cache(vsplit
);
126 ADD_CACHE(vsplit
, ib
[ispoken
]);
128 for (i
= spoken
; i
< icount
; i
++)
129 ADD_CACHE(vsplit
, ib
[istart
+ i
]);
132 ADD_CACHE(vsplit
, ib
[iclose
]);
134 else if (ibias
> 0) {
136 ADD_CACHE(vsplit
, (uint
) ib
[ispoken
] + ibias
);
138 for (i
= spoken
; i
< icount
; i
++)
139 ADD_CACHE(vsplit
, (uint
) ib
[istart
+ i
] + ibias
);
142 ADD_CACHE(vsplit
, (uint
) ib
[iclose
] + ibias
);
146 if (ib
[ispoken
] < -ibias
)
148 ADD_CACHE(vsplit
, ib
[ispoken
] + ibias
);
151 for (i
= spoken
; i
< icount
; i
++) {
152 if (ib
[istart
+ i
] < -ibias
)
154 ADD_CACHE(vsplit
, ib
[istart
+ i
] + ibias
);
158 if (ib
[iclose
] < -ibias
)
160 ADD_CACHE(vsplit
, ib
[iclose
] + ibias
);
164 vsplit_flush_cache(vsplit
, flags
);
168 CONCAT(vsplit_segment_simple_
, ELT_TYPE
)(struct vsplit_frontend
*vsplit
,
173 /* the primitive is not splitted */
175 if (CONCAT(vsplit_segment_fast_
, ELT_TYPE
)(vsplit
,
176 flags
, istart
, icount
))
179 CONCAT(vsplit_segment_cache_
, ELT_TYPE
)(vsplit
,
180 flags
, istart
, icount
, FALSE
, 0, FALSE
, 0);
184 CONCAT(vsplit_segment_loop_
, ELT_TYPE
)(struct vsplit_frontend
*vsplit
,
190 const boolean close_loop
= ((flags
) == DRAW_SPLIT_BEFORE
);
192 CONCAT(vsplit_segment_cache_
, ELT_TYPE
)(vsplit
,
193 flags
, istart
, icount
, FALSE
, 0, close_loop
, i0
);
197 CONCAT(vsplit_segment_fan_
, ELT_TYPE
)(struct vsplit_frontend
*vsplit
,
203 const boolean use_spoken
= (((flags
) & DRAW_SPLIT_BEFORE
) != 0);
205 CONCAT(vsplit_segment_cache_
, ELT_TYPE
)(vsplit
,
206 flags
, istart
, icount
, use_spoken
, i0
, FALSE
, 0);
210 struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \
211 const unsigned prim = vsplit->prim; \
212 const unsigned max_count_simple = vsplit->segment_size; \
213 const unsigned max_count_loop = vsplit->segment_size - 1; \
214 const unsigned max_count_fan = vsplit->segment_size;
219 vsplit_segment_simple_linear(struct vsplit_frontend
*vsplit
, unsigned flags
,
220 unsigned istart
, unsigned icount
)
222 assert(icount
<= vsplit
->max_vertices
);
223 vsplit
->middle
->run_linear(vsplit
->middle
, istart
, icount
, flags
);
227 vsplit_segment_loop_linear(struct vsplit_frontend
*vsplit
, unsigned flags
,
228 unsigned istart
, unsigned icount
, unsigned i0
)
230 boolean close_loop
= (flags
== DRAW_SPLIT_BEFORE
);
233 assert(icount
+ !!close_loop
<= vsplit
->segment_size
);
236 for (nr
= 0; nr
< icount
; nr
++)
237 vsplit
->fetch_elts
[nr
] = istart
+ nr
;
238 vsplit
->fetch_elts
[nr
++] = i0
;
240 vsplit
->middle
->run(vsplit
->middle
, vsplit
->fetch_elts
, nr
,
241 vsplit
->identity_draw_elts
, nr
, flags
);
244 vsplit
->middle
->run_linear(vsplit
->middle
, istart
, icount
, flags
);
249 vsplit_segment_fan_linear(struct vsplit_frontend
*vsplit
, unsigned flags
,
250 unsigned istart
, unsigned icount
, unsigned i0
)
252 boolean use_spoken
= ((flags
& DRAW_SPLIT_BEFORE
) != 0);
255 assert(icount
+ !!use_spoken
<= vsplit
->segment_size
);
258 vsplit
->fetch_elts
[nr
++] = i0
;
259 for (i
= 1 ; i
< icount
; i
++)
260 vsplit
->fetch_elts
[nr
++] = istart
+ i
;
262 vsplit
->middle
->run(vsplit
->middle
, vsplit
->fetch_elts
, nr
,
263 vsplit
->identity_draw_elts
, nr
, flags
);
266 vsplit
->middle
->run_linear(vsplit
->middle
, istart
, icount
, flags
);
271 struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend; \
272 const unsigned prim = vsplit->prim; \
273 const unsigned max_count_simple = vsplit->max_vertices; \
274 const unsigned max_count_loop = vsplit->segment_size - 1; \
275 const unsigned max_count_fan = vsplit->segment_size;
277 #define ELT_TYPE linear
279 #endif /* ELT_TYPE */
282 struct draw_pt_front_end *frontend, \
286 #define SEGMENT_SIMPLE(flags, istart, icount) \
287 CONCAT(vsplit_segment_simple_, ELT_TYPE)(vsplit, flags, istart, icount)
289 #define SEGMENT_LOOP(flags, istart, icount, i0) \
290 CONCAT(vsplit_segment_loop_, ELT_TYPE)(vsplit, flags, istart, icount, i0)
292 #define SEGMENT_FAN(flags, istart, icount, i0) \
293 CONCAT(vsplit_segment_fan_, ELT_TYPE)(vsplit, flags, istart, icount, i0)
295 #include "draw_split_tmp.h"