Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / drivers / nouveau / nouveau_util.h
1 #ifndef __NOUVEAU_UTIL_H__
2 #define __NOUVEAU_UTIL_H__
3
4 /* Determine how many vertices can be pushed into the command stream.
5 * Where the remaining space isn't large enough to represent all verices,
6 * split the buffer at primitive boundaries.
7 *
8 * Returns a count of vertices that can be rendered, and an index to
9 * restart drawing at after a flush.
10 */
11 static INLINE unsigned
12 nouveau_vbuf_split(unsigned remaining, unsigned overhead, unsigned vpp,
13 unsigned mode, unsigned start, unsigned count,
14 unsigned *restart)
15 {
16 int max, adj = 0;
17
18 max = remaining - overhead;
19 if (max < 0)
20 return 0;
21
22 max *= vpp;
23 if (max >= count)
24 return count;
25
26 switch (mode) {
27 case PIPE_PRIM_POINTS:
28 break;
29 case PIPE_PRIM_LINES:
30 max = max & 1;
31 break;
32 case PIPE_PRIM_TRIANGLES:
33 max = max - (max % 3);
34 break;
35 case PIPE_PRIM_QUADS:
36 max = max & 3;
37 break;
38 case PIPE_PRIM_LINE_LOOP:
39 case PIPE_PRIM_LINE_STRIP:
40 if (max < 2)
41 max = 0;
42 adj = 1;
43 break;
44 case PIPE_PRIM_POLYGON:
45 case PIPE_PRIM_TRIANGLE_STRIP:
46 case PIPE_PRIM_TRIANGLE_FAN:
47 if (max < 3)
48 max = 0;
49 adj = 2;
50 break;
51 case PIPE_PRIM_QUAD_STRIP:
52 if (max < 4)
53 max = 0;
54 adj = 3;
55 break;
56 default:
57 assert(0);
58 }
59
60 *restart = start + max - adj;
61 return max;
62 }
63
64 #endif