svga: update driver for version 10 GPU interface
[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 /**
39 * Mask indicating which types of gallium primitives are actually
40 * handled by the svga device. Other types will be converted to
41 * these types by the index/translation code.
42 */
43 static const unsigned svga_hw_prims =
44 ((1 << PIPE_PRIM_POINTS) |
45 (1 << PIPE_PRIM_LINES) |
46 (1 << PIPE_PRIM_LINE_STRIP) |
47 (1 << PIPE_PRIM_TRIANGLES) |
48 (1 << PIPE_PRIM_TRIANGLE_STRIP) |
49 (1 << PIPE_PRIM_TRIANGLE_FAN) |
50 (1 << PIPE_PRIM_LINES_ADJACENCY) |
51 (1 << PIPE_PRIM_LINE_STRIP_ADJACENCY) |
52 (1 << PIPE_PRIM_TRIANGLES_ADJACENCY) |
53 (1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY));
54
55
56 /**
57 * Translate a gallium PIPE_PRIM_x value to an SVGA3D_PRIMITIVE_x value.
58 * Also, compute the number of primitives that'll be drawn given a
59 * vertex count.
60 * Note that this function doesn't have to handle PIPE_PRIM_LINE_LOOP,
61 * PIPE_PRIM_QUADS, PIPE_PRIM_QUAD_STRIP or PIPE_PRIM_POLYGON. We convert
62 * those to other types of primitives with index/translation code.
63 */
64 static inline SVGA3dPrimitiveType
65 svga_translate_prim(unsigned mode, unsigned vcount, unsigned *prim_count)
66 {
67 switch (mode) {
68 case PIPE_PRIM_POINTS:
69 *prim_count = vcount;
70 return SVGA3D_PRIMITIVE_POINTLIST;
71
72 case PIPE_PRIM_LINES:
73 *prim_count = vcount / 2;
74 return SVGA3D_PRIMITIVE_LINELIST;
75
76 case PIPE_PRIM_LINE_STRIP:
77 *prim_count = vcount - 1;
78 return SVGA3D_PRIMITIVE_LINESTRIP;
79
80 case PIPE_PRIM_TRIANGLES:
81 *prim_count = vcount / 3;
82 return SVGA3D_PRIMITIVE_TRIANGLELIST;
83
84 case PIPE_PRIM_TRIANGLE_STRIP:
85 *prim_count = vcount - 2;
86 return SVGA3D_PRIMITIVE_TRIANGLESTRIP;
87
88 case PIPE_PRIM_TRIANGLE_FAN:
89 *prim_count = vcount - 2;
90 return SVGA3D_PRIMITIVE_TRIANGLEFAN;
91
92 case PIPE_PRIM_LINES_ADJACENCY:
93 *prim_count = vcount / 4;
94 return SVGA3D_PRIMITIVE_LINELIST_ADJ;
95
96 case PIPE_PRIM_LINE_STRIP_ADJACENCY:
97 *prim_count = vcount - 3;
98 return SVGA3D_PRIMITIVE_LINESTRIP_ADJ;
99
100 case PIPE_PRIM_TRIANGLES_ADJACENCY:
101 *prim_count = vcount / 6;
102 return SVGA3D_PRIMITIVE_TRIANGLELIST_ADJ;
103
104 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
105 *prim_count = vcount / 2 - 2 ;
106 return SVGA3D_PRIMITIVE_TRIANGLESTRIP_ADJ;
107
108 default:
109 assert(0);
110 *prim_count = 0;
111 return 0;
112 }
113 }
114
115
116 struct index_cache {
117 u_generate_func generate;
118 unsigned gen_nr;
119
120 /* If non-null, this buffer is filled by calling
121 * generate(nr, map(buffer))
122 */
123 struct pipe_resource *buffer;
124 };
125
126
127 /** Max number of primitives per draw call */
128 #define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES
129
130 struct draw_cmd {
131 struct svga_winsys_context *swc;
132
133 /* vertex layout info */
134 SVGA3dVertexDecl vdecl[SVGA3D_INPUTREG_MAX];
135 unsigned vdecl_count;
136 SVGA3dElementLayoutId vdecl_layout_id;
137 unsigned vdecl_buffer_index[SVGA3D_INPUTREG_MAX];
138
139 /* vertex buffer info */
140 struct pipe_vertex_buffer vbufs[SVGA3D_INPUTREG_MAX];
141 unsigned vbuf_count;
142
143 SVGA3dPrimitiveRange prim[QSZ];
144 struct pipe_resource *prim_ib[QSZ];
145 unsigned prim_count; /**< number of primitives for this draw */
146 unsigned min_index[QSZ];
147 unsigned max_index[QSZ];
148 };
149
150 #define IDX_CACHE_MAX 8
151
152 struct svga_hwtnl {
153 struct svga_context *svga;
154 struct u_upload_mgr *upload_ib;
155
156 /* Additional negative index bias due to partial buffer uploads
157 * This is compensated for in the offset associated with all
158 * vertex buffers.
159 */
160
161 int index_bias;
162
163 /* Flatshade information:
164 */
165 unsigned api_pv;
166 unsigned hw_pv;
167 unsigned api_fillmode;
168
169 /* Cache the results of running a particular generate func on each
170 * primitive type.
171 */
172 struct index_cache index_cache[PIPE_PRIM_MAX][IDX_CACHE_MAX];
173
174 /* Try to build the maximal draw command packet before emitting:
175 */
176 struct draw_cmd cmd;
177 };
178
179
180
181 /***********************************************************************
182 * Internal functions
183 */
184 enum pipe_error
185 svga_hwtnl_prim( struct svga_hwtnl *hwtnl,
186 const SVGA3dPrimitiveRange *range,
187 unsigned vcount,
188 unsigned min_index,
189 unsigned max_index,
190 struct pipe_resource *ib,
191 unsigned start_instance, unsigned instance_count);
192
193 enum pipe_error
194 svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl *hwtnl,
195 struct pipe_resource *indexBuffer,
196 unsigned index_size,
197 int index_bias,
198 unsigned min_index,
199 unsigned max_index,
200 unsigned prim,
201 unsigned start,
202 unsigned count,
203 unsigned start_instance,
204 unsigned instance_count);
205
206
207 #endif