1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_defines.h"
31 #include "indices/u_indices.h"
32 #include "util/u_prim.h"
33 #include "svga_context.h"
34 #include "svga_hw_reg.h"
35 #include "svga3d_shaderdefs.h"
41 * Mask indicating which types of gallium primitives are actually
42 * handled by the svga device. Other types will be converted to
43 * these types by the index/translation code.
45 static const unsigned svga_hw_prims
=
46 ((1 << PIPE_PRIM_POINTS
) |
47 (1 << PIPE_PRIM_LINES
) |
48 (1 << PIPE_PRIM_LINE_STRIP
) |
49 (1 << PIPE_PRIM_TRIANGLES
) |
50 (1 << PIPE_PRIM_TRIANGLE_STRIP
) |
51 (1 << PIPE_PRIM_TRIANGLE_FAN
) |
52 (1 << PIPE_PRIM_LINES_ADJACENCY
) |
53 (1 << PIPE_PRIM_LINE_STRIP_ADJACENCY
) |
54 (1 << PIPE_PRIM_TRIANGLES_ADJACENCY
) |
55 (1 << PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
));
59 * Translate a gallium PIPE_PRIM_x value to an SVGA3D_PRIMITIVE_x value.
60 * Also, compute the number of primitives that'll be drawn given a
62 * Note that this function doesn't have to handle PIPE_PRIM_LINE_LOOP,
63 * PIPE_PRIM_QUADS, PIPE_PRIM_QUAD_STRIP or PIPE_PRIM_POLYGON. We convert
64 * those to other types of primitives with index/translation code.
66 static inline SVGA3dPrimitiveType
67 svga_translate_prim(unsigned mode
, unsigned vcount
, unsigned *prim_count
)
70 case PIPE_PRIM_POINTS
:
72 return SVGA3D_PRIMITIVE_POINTLIST
;
75 *prim_count
= vcount
/ 2;
76 return SVGA3D_PRIMITIVE_LINELIST
;
78 case PIPE_PRIM_LINE_STRIP
:
79 *prim_count
= vcount
- 1;
80 return SVGA3D_PRIMITIVE_LINESTRIP
;
82 case PIPE_PRIM_TRIANGLES
:
83 *prim_count
= vcount
/ 3;
84 return SVGA3D_PRIMITIVE_TRIANGLELIST
;
86 case PIPE_PRIM_TRIANGLE_STRIP
:
87 *prim_count
= vcount
- 2;
88 return SVGA3D_PRIMITIVE_TRIANGLESTRIP
;
90 case PIPE_PRIM_TRIANGLE_FAN
:
91 *prim_count
= vcount
- 2;
92 return SVGA3D_PRIMITIVE_TRIANGLEFAN
;
94 case PIPE_PRIM_LINES_ADJACENCY
:
95 *prim_count
= vcount
/ 4;
96 return SVGA3D_PRIMITIVE_LINELIST_ADJ
;
98 case PIPE_PRIM_LINE_STRIP_ADJACENCY
:
99 *prim_count
= vcount
- 3;
100 return SVGA3D_PRIMITIVE_LINESTRIP_ADJ
;
102 case PIPE_PRIM_TRIANGLES_ADJACENCY
:
103 *prim_count
= vcount
/ 6;
104 return SVGA3D_PRIMITIVE_TRIANGLELIST_ADJ
;
106 case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
:
107 *prim_count
= vcount
/ 2 - 2 ;
108 return SVGA3D_PRIMITIVE_TRIANGLESTRIP_ADJ
;
119 u_generate_func generate
;
122 /* If non-null, this buffer is filled by calling
123 * generate(nr, map(buffer))
125 struct pipe_resource
*buffer
;
129 /** Max number of primitives per draw call */
130 #define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES
133 struct svga_winsys_context
*swc
;
135 /* vertex layout info */
136 SVGA3dVertexDecl vdecl
[SVGA3D_INPUTREG_MAX
];
137 unsigned vdecl_count
;
138 SVGA3dElementLayoutId vdecl_layout_id
;
139 unsigned vdecl_buffer_index
[SVGA3D_INPUTREG_MAX
];
141 /* vertex buffer info */
142 struct pipe_vertex_buffer vbufs
[SVGA3D_INPUTREG_MAX
];
145 SVGA3dPrimitiveRange prim
[QSZ
];
146 struct pipe_resource
*prim_ib
[QSZ
];
147 unsigned prim_count
; /**< number of primitives for this draw */
148 unsigned min_index
[QSZ
];
149 unsigned max_index
[QSZ
];
152 #define IDX_CACHE_MAX 8
155 struct svga_context
*svga
;
156 struct u_upload_mgr
*upload_ib
;
158 /* Additional negative index bias due to partial buffer uploads
159 * This is compensated for in the offset associated with all
164 /* Provoking vertex information (for flat shading). */
165 unsigned api_pv
; /**< app-requested PV mode (PV_FIRST or PV_LAST) */
166 unsigned hw_pv
; /**< device-supported PV mode (PV_FIRST or PV_LAST) */
168 /* The triangle fillmode for the device (one of PIPE_POLYGON_MODE_{FILL,
169 * LINE,POINT}). If the polygon front mode matches the back mode,
170 * api_fillmode will be that mode. Otherwise, api_fillmode will be
171 * PIPE_POLYGON_MODE_FILL.
173 unsigned api_fillmode
;
175 /* Cache the results of running a particular generate func on each
178 struct index_cache index_cache
[PIPE_PRIM_MAX
][IDX_CACHE_MAX
];
180 /* Try to build the maximal draw command packet before emitting:
188 * Do we need to use the gallium 'indices' helper to render unfilled
191 static inline boolean
192 svga_need_unfilled_fallback(const struct svga_hwtnl
*hwtnl
,
193 enum pipe_prim_type prim
)
195 const struct svga_context
*svga
= hwtnl
->svga
;
197 if (u_reduced_prim(prim
) != PIPE_PRIM_TRIANGLES
) {
198 /* if we're drawing points or lines, no fallback needed */
202 if (svga_have_vgpu10(svga
)) {
203 /* vgpu10 supports polygon fill and line modes */
204 if ((prim
== PIPE_PRIM_QUADS
||
205 prim
== PIPE_PRIM_QUAD_STRIP
||
206 prim
== PIPE_PRIM_POLYGON
) &&
207 hwtnl
->api_fillmode
== PIPE_POLYGON_MODE_LINE
) {
208 /* VGPU10 doesn't directly render quads or polygons. They're
209 * converted to triangles. If we let the device draw the triangle
210 * outlines we'll get an extra, stray lines in the interiors.
211 * So, to draw unfilled quads correctly, we need the fallback.
215 return hwtnl
->api_fillmode
== PIPE_POLYGON_MODE_POINT
;
217 /* vgpu9 doesn't support line or point fill modes */
218 return hwtnl
->api_fillmode
!= PIPE_POLYGON_MODE_FILL
;
224 svga_hwtnl_prim( struct svga_hwtnl
*hwtnl
,
225 const SVGA3dPrimitiveRange
*range
,
229 struct pipe_resource
*ib
,
230 unsigned start_instance
, unsigned instance_count
);
233 svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl
*hwtnl
,
234 struct pipe_resource
*indexBuffer
,
239 enum pipe_prim_type prim
,
242 unsigned start_instance
,
243 unsigned instance_count
);