1 /* $XFree86: xc/lib/GL/mesa/src/drv/radeon/radeon_maos_verts.c,v 1.1 2002/10/30 12:51:55 alanh Exp $ */
2 /**************************************************************************
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 Tungsten Graphics Inc., Austin, Texas.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
40 #include "array_cache/acache.h"
42 #include "tnl/t_pipeline.h"
44 #include "radeon_context.h"
45 #include "radeon_state.h"
46 #include "radeon_ioctl.h"
47 #include "radeon_tex.h"
48 #include "radeon_tcl.h"
49 #include "radeon_swtcl.h"
50 #include "radeon_maos.h"
53 #define RADEON_TCL_MAX_SETUP 13
55 union emit_union
{ float f
; GLuint ui
; radeon_color_t rgba
; };
58 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void * );
61 } setup_tab
[RADEON_TCL_MAX_SETUP
];
63 #define DO_W (IND & RADEON_CP_VC_FRMT_W0)
64 #define DO_RGBA (IND & RADEON_CP_VC_FRMT_PKCOLOR)
65 #define DO_SPEC (IND & RADEON_CP_VC_FRMT_PKSPEC)
66 #define DO_FOG (IND & RADEON_CP_VC_FRMT_PKSPEC)
67 #define DO_TEX0 (IND & RADEON_CP_VC_FRMT_ST0)
68 #define DO_TEX1 (IND & RADEON_CP_VC_FRMT_ST1)
69 #define DO_PTEX (IND & RADEON_CP_VC_FRMT_Q0)
70 #define DO_NORM (IND & RADEON_CP_VC_FRMT_N0)
75 #define GET_TEXSOURCE(n) n
77 /***********************************************************************
78 * Generate vertex emit functions *
79 ***********************************************************************/
82 /* Defined in order of increasing vertex size:
85 #define IND (RADEON_CP_VC_FRMT_XY| \
86 RADEON_CP_VC_FRMT_Z| \
87 RADEON_CP_VC_FRMT_PKCOLOR)
88 #define TAG(x) x##_rgba
89 #include "radeon_maos_vbtmp.h"
92 #define IND (RADEON_CP_VC_FRMT_XY| \
93 RADEON_CP_VC_FRMT_Z| \
96 #include "radeon_maos_vbtmp.h"
99 #define IND (RADEON_CP_VC_FRMT_XY| \
100 RADEON_CP_VC_FRMT_Z| \
101 RADEON_CP_VC_FRMT_PKCOLOR| \
102 RADEON_CP_VC_FRMT_ST0)
103 #define TAG(x) x##_rgba_st
104 #include "radeon_maos_vbtmp.h"
107 #define IND (RADEON_CP_VC_FRMT_XY| \
108 RADEON_CP_VC_FRMT_Z| \
109 RADEON_CP_VC_FRMT_PKCOLOR| \
110 RADEON_CP_VC_FRMT_N0)
111 #define TAG(x) x##_rgba_n
112 #include "radeon_maos_vbtmp.h"
115 #define IND (RADEON_CP_VC_FRMT_XY| \
116 RADEON_CP_VC_FRMT_Z| \
117 RADEON_CP_VC_FRMT_ST0| \
118 RADEON_CP_VC_FRMT_N0)
119 #define TAG(x) x##_st_n
120 #include "radeon_maos_vbtmp.h"
123 #define IND (RADEON_CP_VC_FRMT_XY| \
124 RADEON_CP_VC_FRMT_Z| \
125 RADEON_CP_VC_FRMT_PKCOLOR| \
126 RADEON_CP_VC_FRMT_ST0| \
127 RADEON_CP_VC_FRMT_ST1)
128 #define TAG(x) x##_rgba_st_st
129 #include "radeon_maos_vbtmp.h"
132 #define IND (RADEON_CP_VC_FRMT_XY| \
133 RADEON_CP_VC_FRMT_Z| \
134 RADEON_CP_VC_FRMT_PKCOLOR| \
135 RADEON_CP_VC_FRMT_ST0| \
136 RADEON_CP_VC_FRMT_N0)
137 #define TAG(x) x##_rgba_st_n
138 #include "radeon_maos_vbtmp.h"
141 #define IND (RADEON_CP_VC_FRMT_XY| \
142 RADEON_CP_VC_FRMT_Z| \
143 RADEON_CP_VC_FRMT_PKCOLOR| \
144 RADEON_CP_VC_FRMT_PKSPEC| \
145 RADEON_CP_VC_FRMT_ST0| \
146 RADEON_CP_VC_FRMT_ST1)
147 #define TAG(x) x##_rgba_spec_st_st
148 #include "radeon_maos_vbtmp.h"
151 #define IND (RADEON_CP_VC_FRMT_XY| \
152 RADEON_CP_VC_FRMT_Z| \
153 RADEON_CP_VC_FRMT_ST0| \
154 RADEON_CP_VC_FRMT_ST1| \
155 RADEON_CP_VC_FRMT_N0)
156 #define TAG(x) x##_st_st_n
157 #include "radeon_maos_vbtmp.h"
160 #define IND (RADEON_CP_VC_FRMT_XY| \
161 RADEON_CP_VC_FRMT_Z| \
162 RADEON_CP_VC_FRMT_PKCOLOR| \
163 RADEON_CP_VC_FRMT_PKSPEC| \
164 RADEON_CP_VC_FRMT_ST0| \
165 RADEON_CP_VC_FRMT_ST1| \
166 RADEON_CP_VC_FRMT_N0)
167 #define TAG(x) x##_rgba_spec_st_st_n
168 #include "radeon_maos_vbtmp.h"
171 #define IND (RADEON_CP_VC_FRMT_XY| \
172 RADEON_CP_VC_FRMT_Z| \
173 RADEON_CP_VC_FRMT_PKCOLOR| \
174 RADEON_CP_VC_FRMT_ST0| \
175 RADEON_CP_VC_FRMT_Q0)
176 #define TAG(x) x##_rgba_stq
177 #include "radeon_maos_vbtmp.h"
180 #define IND (RADEON_CP_VC_FRMT_XY| \
181 RADEON_CP_VC_FRMT_Z| \
182 RADEON_CP_VC_FRMT_PKCOLOR| \
183 RADEON_CP_VC_FRMT_ST1| \
184 RADEON_CP_VC_FRMT_Q1| \
185 RADEON_CP_VC_FRMT_ST0| \
186 RADEON_CP_VC_FRMT_Q0)
187 #define TAG(x) x##_rgba_stq_stq
188 #include "radeon_maos_vbtmp.h"
191 #define IND (RADEON_CP_VC_FRMT_XY| \
192 RADEON_CP_VC_FRMT_Z| \
193 RADEON_CP_VC_FRMT_W0| \
194 RADEON_CP_VC_FRMT_PKCOLOR| \
195 RADEON_CP_VC_FRMT_PKSPEC| \
196 RADEON_CP_VC_FRMT_ST0| \
197 RADEON_CP_VC_FRMT_Q0| \
198 RADEON_CP_VC_FRMT_ST1| \
199 RADEON_CP_VC_FRMT_Q1| \
200 RADEON_CP_VC_FRMT_N0)
201 #define TAG(x) x##_w_rgba_spec_stq_stq_n
202 #include "radeon_maos_vbtmp.h"
208 /***********************************************************************
210 ***********************************************************************/
213 static void init_tcl_verts( void )
222 init_rgba_spec_st_st();
224 init_rgba_spec_st_st_n();
227 init_w_rgba_spec_stq_stq_n();
231 void radeonEmitArrays( GLcontext
*ctx
, GLuint inputs
)
233 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
234 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
236 GLuint vtx
= (rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &
237 ~(RADEON_TCL_VTX_Q0
|RADEON_TCL_VTX_Q1
));
239 static int firsttime
= 1;
247 req
|= RADEON_CP_VC_FRMT_Z
;
248 if (VB
->ObjPtr
->size
== 4) {
249 req
|= RADEON_CP_VC_FRMT_W0
;
253 if (inputs
& VERT_BIT_NORMAL
) {
254 req
|= RADEON_CP_VC_FRMT_N0
;
257 if (inputs
& VERT_BIT_COLOR0
) {
258 req
|= RADEON_CP_VC_FRMT_PKCOLOR
;
261 if (inputs
& VERT_BIT_COLOR1
) {
262 req
|= RADEON_CP_VC_FRMT_PKSPEC
;
265 if (inputs
& VERT_BIT_TEX0
) {
266 req
|= RADEON_CP_VC_FRMT_ST0
;
268 if (VB
->TexCoordPtr
[0]->size
== 4) {
269 req
|= RADEON_CP_VC_FRMT_Q0
;
270 vtx
|= RADEON_TCL_VTX_Q0
;
274 if (inputs
& VERT_BIT_TEX1
) {
275 req
|= RADEON_CP_VC_FRMT_ST1
;
277 if (VB
->TexCoordPtr
[1]->size
== 4) {
278 req
|= RADEON_CP_VC_FRMT_Q1
;
279 vtx
|= RADEON_TCL_VTX_Q1
;
283 if (vtx
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
]) {
284 RADEON_STATECHANGE( rmesa
, tcl
);
285 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] = vtx
;
288 for (i
= 0 ; i
< RADEON_TCL_MAX_SETUP
; i
++)
289 if ((setup_tab
[i
].vertex_format
& req
) == req
)
292 if (rmesa
->tcl
.vertex_format
== setup_tab
[i
].vertex_format
&&
293 rmesa
->tcl
.indexed_verts
.buf
)
296 if (rmesa
->tcl
.indexed_verts
.buf
)
297 radeonReleaseArrays( ctx
, ~0 );
299 radeonAllocDmaRegionVerts( rmesa
,
300 &rmesa
->tcl
.indexed_verts
,
302 setup_tab
[i
].vertex_size
* 4,
305 /* The vertex code expects Obj to be clean to element 3. To fix
306 * this, add more vertex code (for obj-2, obj-3) or preferably move
309 if (VB
->ObjPtr
->size
< 3 ||
310 (VB
->ObjPtr
->size
== 3 &&
311 (setup_tab
[i
].vertex_format
& RADEON_CP_VC_FRMT_W0
))) {
313 _math_trans_4f( rmesa
->tcl
.ObjClean
.data
,
321 switch (VB
->ObjPtr
->size
) {
323 _mesa_vector4f_clean_elem(&rmesa
->tcl
.ObjClean
, VB
->Count
, 1);
325 _mesa_vector4f_clean_elem(&rmesa
->tcl
.ObjClean
, VB
->Count
, 2);
327 if (setup_tab
[i
].vertex_format
& RADEON_CP_VC_FRMT_W0
) {
328 _mesa_vector4f_clean_elem(&rmesa
->tcl
.ObjClean
, VB
->Count
, 3);
335 VB
->ObjPtr
= &rmesa
->tcl
.ObjClean
;
340 setup_tab
[i
].emit( ctx
, 0, VB
->Count
,
341 rmesa
->tcl
.indexed_verts
.address
+
342 rmesa
->tcl
.indexed_verts
.start
);
344 rmesa
->tcl
.vertex_format
= setup_tab
[i
].vertex_format
;
345 rmesa
->tcl
.indexed_verts
.aos_start
= GET_START( &rmesa
->tcl
.indexed_verts
);
346 rmesa
->tcl
.indexed_verts
.aos_size
= setup_tab
[i
].vertex_size
;
347 rmesa
->tcl
.indexed_verts
.aos_stride
= setup_tab
[i
].vertex_size
;
349 rmesa
->tcl
.aos_components
[0] = &rmesa
->tcl
.indexed_verts
;
350 rmesa
->tcl
.nr_aos_components
= 1;
355 void radeonReleaseArrays( GLcontext
*ctx
, GLuint newinputs
)
357 radeonContextPtr rmesa
= RADEON_CONTEXT( ctx
);
360 if (RADEON_DEBUG
& DEBUG_VERTS
)
361 _tnl_print_vert_flags( __FUNCTION__
, newinputs
);
365 radeonReleaseDmaRegion( rmesa
, &rmesa
->tcl
.indexed_verts
, __FUNCTION__
);