draw: Add vsplit frontend.
[mesa.git] / src / gallium / auxiliary / draw / draw_split_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.9
4 *
5 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Copyright (C) 2010 LunarG Inc.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
25 */
26
27 static void
28 FUNC(FUNC_VARS)
29 {
30 unsigned first, incr;
31 LOCAL_VARS
32
33 /*
34 * prim, start, count, and max_count_{simple,loop,fan} should have been
35 * defined
36 */
37 if (0) {
38 debug_printf("%s: prim 0x%x, start %d, count %d, max_count_simple %d, "
39 "max_count_loop %d, max_count_fan %d\n",
40 __FUNCTION__, prim, start, count, max_count_simple,
41 max_count_loop, max_count_fan);
42 }
43
44 draw_pt_split_prim(prim, &first, &incr);
45 /* sanitize primitive length */
46 count = draw_pt_trim_count(count, first, incr);
47 if (count < first)
48 return;
49
50 /* must be able to at least flush two complete primitives */
51 assert(max_count_simple >= first + incr &&
52 max_count_loop >= first + incr &&
53 max_count_fan >= first + incr);
54
55 /* no splitting required */
56 if (count <= max_count_simple) {
57 SEGMENT_SIMPLE(0x0, start, count);
58 }
59 else {
60 const unsigned rollback = first - incr;
61 unsigned flags = DRAW_SPLIT_AFTER, seg_start = 0, seg_max;
62
63 /*
64 * Both count and seg_max below are explicitly trimmed. Because
65 *
66 * seg_start = N * (seg_max - rollback) = N' * incr,
67 *
68 * we have
69 *
70 * remaining = count - seg_start = first + N'' * incr.
71 *
72 * That is, remaining is implicitly trimmed.
73 */
74 switch (prim) {
75 case PIPE_PRIM_POINTS:
76 case PIPE_PRIM_LINES:
77 case PIPE_PRIM_LINE_STRIP:
78 case PIPE_PRIM_TRIANGLES:
79 case PIPE_PRIM_TRIANGLE_STRIP:
80 case PIPE_PRIM_QUADS:
81 case PIPE_PRIM_QUAD_STRIP:
82 case PIPE_PRIM_LINES_ADJACENCY:
83 case PIPE_PRIM_LINE_STRIP_ADJACENCY:
84 case PIPE_PRIM_TRIANGLES_ADJACENCY:
85 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
86 seg_max =
87 draw_pt_trim_count(MIN2(max_count_simple, count), first, incr);
88 if (prim == PIPE_PRIM_TRIANGLE_STRIP ||
89 prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY) {
90 /* make sure we flush even number of triangles at a time */
91 if (seg_max < count && !(((seg_max - first) / incr) & 1))
92 seg_max -= incr;
93 }
94
95 do {
96 const unsigned remaining = count - seg_start;
97
98 if (remaining > seg_max) {
99 SEGMENT_SIMPLE(flags, start + seg_start, seg_max);
100 seg_start += seg_max - rollback;
101
102 flags |= DRAW_SPLIT_BEFORE;
103 }
104 else {
105 flags &= ~DRAW_SPLIT_AFTER;
106
107 SEGMENT_SIMPLE(flags, start + seg_start, remaining);
108 seg_start += remaining;
109 }
110 } while (seg_start < count);
111 break;
112
113 case PIPE_PRIM_LINE_LOOP:
114 seg_max =
115 draw_pt_trim_count(MIN2(max_count_loop, count), first, incr);
116
117 do {
118 const unsigned remaining = count - seg_start;
119
120 if (remaining > seg_max) {
121 SEGMENT_LOOP(flags, start + seg_start, seg_max, start);
122 seg_start += seg_max - rollback;
123
124 flags |= DRAW_SPLIT_BEFORE;
125 }
126 else {
127 flags &= ~DRAW_SPLIT_AFTER;
128
129 SEGMENT_LOOP(flags, start + seg_start, remaining, start);
130 seg_start += remaining;
131 }
132 } while (seg_start < count);
133 break;
134
135 case PIPE_PRIM_TRIANGLE_FAN:
136 case PIPE_PRIM_POLYGON:
137 seg_max =
138 draw_pt_trim_count(MIN2(max_count_fan, count), first, incr);
139
140 do {
141 const unsigned remaining = count - seg_start;
142
143 if (remaining > seg_max) {
144 SEGMENT_FAN(flags, start + seg_start, seg_max, start);
145 seg_start += seg_max - rollback;
146
147 flags |= DRAW_SPLIT_BEFORE;
148 }
149 else {
150 flags &= ~DRAW_SPLIT_AFTER;
151
152 SEGMENT_FAN(flags, start + seg_start, remaining, start);
153 seg_start += remaining;
154 }
155 } while (seg_start < count);
156 break;
157
158 default:
159 assert(0);
160 break;
161 }
162 }
163 }
164
165 #undef FUNC
166 #undef FUNC_VARS
167 #undef LOCAL_VARS
168
169 #undef SEGMENT_SIMPLE
170 #undef SEGMENT_LOOP
171 #undef SEGMENT_FAN