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 generate(nr, map(buffer))
124 struct pipe_resource
*buffer
;
128 /** Max number of primitives per draw call */
129 #define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES
132 struct svga_winsys_context
*swc
;
134 /* vertex layout info */
135 SVGA3dVertexDecl vdecl
[SVGA3D_INPUTREG_MAX
];
136 unsigned vdecl_count
;
137 SVGA3dElementLayoutId vdecl_layout_id
;
138 unsigned vdecl_buffer_index
[SVGA3D_INPUTREG_MAX
];
140 /* vertex buffer info */
141 struct pipe_vertex_buffer vbufs
[SVGA3D_INPUTREG_MAX
];
144 SVGA3dPrimitiveRange prim
[QSZ
];
145 struct pipe_resource
*prim_ib
[QSZ
];
146 unsigned prim_count
; /**< number of primitives for this draw */
147 unsigned min_index
[QSZ
];
148 unsigned max_index
[QSZ
];
151 #define IDX_CACHE_MAX 8
154 struct svga_context
*svga
;
155 struct u_upload_mgr
*upload_ib
;
157 /* Additional negative index bias due to partial buffer uploads
158 * This is compensated for in the offset associated with all
163 /* Provoking vertex information (for flat shading). */
164 unsigned api_pv
; /**< app-requested PV mode (PV_FIRST or PV_LAST) */
165 unsigned hw_pv
; /**< device-supported PV mode (PV_FIRST or PV_LAST) */
167 /* The triangle fillmode for the device (one of PIPE_POLYGON_MODE_{FILL,
168 * LINE,POINT}). If the polygon front mode matches the back mode,
169 * api_fillmode will be that mode. Otherwise, api_fillmode will be
170 * PIPE_POLYGON_MODE_FILL.
172 unsigned api_fillmode
;
174 /* Cache the results of running a particular generate func on each
177 struct index_cache index_cache
[PIPE_PRIM_MAX
][IDX_CACHE_MAX
];
179 /* Try to build the maximal draw command packet before emitting:
187 * Do we need to use the gallium 'indices' helper to render unfilled
190 static inline boolean
191 svga_need_unfilled_fallback(const struct svga_hwtnl
*hwtnl
,
192 enum pipe_prim_type prim
)
194 if (u_reduced_prim(prim
) != PIPE_PRIM_TRIANGLES
) {
195 /* if we're drawing points or lines, no fallback needed */
199 if ((prim
== PIPE_PRIM_QUADS
||
200 prim
== PIPE_PRIM_QUAD_STRIP
||
201 prim
== PIPE_PRIM_POLYGON
) &&
202 hwtnl
->api_fillmode
== PIPE_POLYGON_MODE_LINE
) {
203 /* We can't directly render quads or polygons. They're
204 * converted to triangles. If we let the device draw the triangle
205 * outlines we'll get an extra, stray lines in the interiors.
206 * So, to draw unfilled quads correctly, we need the fallback.
215 svga_hwtnl_prim(struct svga_hwtnl
*hwtnl
,
216 const SVGA3dPrimitiveRange
*range
,
220 struct pipe_resource
*ib
,
221 unsigned start_instance
, unsigned instance_count
);
224 svga_hwtnl_simple_draw_range_elements(struct svga_hwtnl
*hwtnl
,
225 struct pipe_resource
*indexBuffer
,
230 enum pipe_prim_type prim
,
233 unsigned start_instance
,
234 unsigned instance_count
);