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 "svga_hw_reg.h"
33 #include "svga3d_shaderdefs.h"
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.
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
));
53 * Translate a gallium PIPE_PRIM_x value to an SVGA3D_PRIMITIVE_x value.
54 * Also, compute the number of primitives that'll be drawn given a
56 * Note that this function doesn't have to handle PIPE_PRIM_LINE_LOOP,
57 * PIPE_PRIM_QUADS, PIPE_PRIM_QUAD_STRIP or PIPE_PRIM_POLYGON. We convert
58 * those to other types of primitives with index/translation code.
60 static INLINE
unsigned
61 svga_translate_prim(unsigned mode
, unsigned vcount
,unsigned *prim_count
)
64 case PIPE_PRIM_POINTS
:
66 return SVGA3D_PRIMITIVE_POINTLIST
;
69 *prim_count
= vcount
/ 2;
70 return SVGA3D_PRIMITIVE_LINELIST
;
72 case PIPE_PRIM_LINE_STRIP
:
73 *prim_count
= vcount
- 1;
74 return SVGA3D_PRIMITIVE_LINESTRIP
;
76 case PIPE_PRIM_TRIANGLES
:
77 *prim_count
= vcount
/ 3;
78 return SVGA3D_PRIMITIVE_TRIANGLELIST
;
80 case PIPE_PRIM_TRIANGLE_STRIP
:
81 *prim_count
= vcount
- 2;
82 return SVGA3D_PRIMITIVE_TRIANGLESTRIP
;
84 case PIPE_PRIM_TRIANGLE_FAN
:
85 *prim_count
= vcount
- 2;
86 return SVGA3D_PRIMITIVE_TRIANGLEFAN
;
97 u_generate_func generate
;
100 /* If non-null, this buffer is filled by calling
101 * generate(nr, map(buffer))
103 struct pipe_resource
*buffer
;
107 /** Max number of primitives per draw call */
108 #define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES
111 struct svga_winsys_context
*swc
;
113 SVGA3dVertexDecl vdecl
[SVGA3D_INPUTREG_MAX
];
114 struct pipe_resource
*vdecl_vb
[SVGA3D_INPUTREG_MAX
];
115 unsigned vdecl_count
;
117 SVGA3dPrimitiveRange prim
[QSZ
];
118 struct pipe_resource
*prim_ib
[QSZ
];
120 unsigned min_index
[QSZ
];
121 unsigned max_index
[QSZ
];
124 #define IDX_CACHE_MAX 8
127 struct svga_context
*svga
;
128 struct u_upload_mgr
*upload_ib
;
130 /* Additional negative index bias due to partial buffer uploads
131 * This is compensated for in the offset associated with all
137 /* Flatshade information:
141 unsigned api_fillmode
;
143 /* Cache the results of running a particular generate func on each
146 struct index_cache index_cache
[PIPE_PRIM_MAX
][IDX_CACHE_MAX
];
148 /* Try to build the maximal draw command packet before emitting:
155 /***********************************************************************
159 svga_hwtnl_prim( struct svga_hwtnl
*hwtnl
,
160 const SVGA3dPrimitiveRange
*range
,
163 struct pipe_resource
*ib
);
166 svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl
*hwtnl
,
167 struct pipe_resource
*indexBuffer
,