Merge branch '7.8'
[mesa.git] / src / gallium / drivers / svga / svga_draw_private.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #ifndef SVGA_DRAW_H_
27 #define SVGA_DRAW_H_
28
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_defines.h"
31 #include "indices/u_indices.h"
32 #include "svga_hw_reg.h"
33 #include "svga3d_shaderdefs.h"
34
35 struct svga_context;
36 struct u_upload_mgr;
37
38 /* Should include polygon?
39 */
40 static const unsigned svga_hw_prims =
41 ((1 << PIPE_PRIM_POINTS) |
42 (1 << PIPE_PRIM_LINES) |
43 (1 << PIPE_PRIM_LINE_STRIP) |
44 (1 << PIPE_PRIM_TRIANGLES) |
45 (1 << PIPE_PRIM_TRIANGLE_STRIP) |
46 (1 << PIPE_PRIM_TRIANGLE_FAN));
47
48
49 static INLINE unsigned svga_translate_prim(unsigned mode,
50 unsigned count,
51 unsigned *out_count)
52 {
53 switch (mode) {
54 case PIPE_PRIM_POINTS:
55 *out_count = count;
56 return SVGA3D_PRIMITIVE_POINTLIST;
57
58 case PIPE_PRIM_LINES:
59 *out_count = count / 2;
60 return SVGA3D_PRIMITIVE_LINELIST;
61
62 case PIPE_PRIM_LINE_STRIP:
63 *out_count = count - 1;
64 return SVGA3D_PRIMITIVE_LINESTRIP;
65
66 case PIPE_PRIM_TRIANGLES:
67 *out_count = count / 3;
68 return SVGA3D_PRIMITIVE_TRIANGLELIST;
69
70 case PIPE_PRIM_TRIANGLE_STRIP:
71 *out_count = count - 2;
72 return SVGA3D_PRIMITIVE_TRIANGLESTRIP;
73
74 case PIPE_PRIM_TRIANGLE_FAN:
75 *out_count = count - 2;
76 return SVGA3D_PRIMITIVE_TRIANGLEFAN;
77
78 default:
79 assert(0);
80 *out_count = 0;
81 return 0;
82 }
83 }
84
85
86 struct index_cache {
87 u_generate_func generate;
88 unsigned gen_nr;
89
90 /* If non-null, this buffer is filled by calling
91 * generate(nr, map(buffer))
92 */
93 struct pipe_resource *buffer;
94 };
95
96 #define QSZ 32
97
98 struct draw_cmd {
99 struct svga_winsys_context *swc;
100
101 SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX];
102 struct pipe_resource *vdecl_vb[SVGA3D_INPUTREG_MAX];
103 unsigned vdecl_count;
104
105 SVGA3dPrimitiveRange prim[QSZ];
106 struct pipe_resource *prim_ib[QSZ];
107 unsigned prim_count;
108 unsigned min_index[QSZ];
109 unsigned max_index[QSZ];
110 };
111
112 #define IDX_CACHE_MAX 8
113
114 struct svga_hwtnl {
115 struct svga_context *svga;
116 struct u_upload_mgr *upload_ib;
117
118 /* Flatshade information:
119 */
120 unsigned api_pv;
121 unsigned hw_pv;
122 unsigned api_fillmode;
123
124 /* Cache the results of running a particular generate func on each
125 * primitive type.
126 */
127 struct index_cache index_cache[PIPE_PRIM_MAX][IDX_CACHE_MAX];
128
129 /* Try to build the maximal draw command packet before emitting:
130 */
131 struct draw_cmd cmd;
132 };
133
134
135
136 /***********************************************************************
137 * Internal functions
138 */
139 enum pipe_error
140 svga_hwtnl_prim( struct svga_hwtnl *hwtnl,
141 const SVGA3dPrimitiveRange *range,
142 unsigned min_index,
143 unsigned max_index,
144 struct pipe_resource *ib );
145
146 enum pipe_error
147 svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl,
148 struct pipe_resource *indexBuffer,
149 unsigned index_size,
150 unsigned min_index,
151 unsigned max_index,
152 unsigned prim,
153 unsigned start,
154 unsigned count,
155 unsigned bias );
156
157
158 #endif