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"
43 #include "tnl/t_imm_debug.h"
45 #include "radeon_context.h"
46 #include "radeon_state.h"
47 #include "radeon_ioctl.h"
48 #include "radeon_tex.h"
49 #include "radeon_tcl.h"
50 #include "radeon_swtcl.h"
51 #include "radeon_maos.h"
54 #define RADEON_TCL_MAX_SETUP 13
56 union emit_union
{ float f
; GLuint ui
; radeon_color_t specular
; };
59 void (*emit
)( GLcontext
*, GLuint
, GLuint
, void * );
62 } setup_tab
[RADEON_TCL_MAX_SETUP
];
64 #define DO_W (IND & RADEON_CP_VC_FRMT_W0)
65 #define DO_RGBA (IND & RADEON_CP_VC_FRMT_PKCOLOR)
66 #define DO_SPEC (IND & RADEON_CP_VC_FRMT_PKSPEC)
67 #define DO_FOG (IND & RADEON_CP_VC_FRMT_PKSPEC)
68 #define DO_TEX0 (IND & RADEON_CP_VC_FRMT_ST0)
69 #define DO_TEX1 (IND & RADEON_CP_VC_FRMT_ST1)
70 #define DO_PTEX (IND & RADEON_CP_VC_FRMT_Q0)
71 #define DO_NORM (IND & RADEON_CP_VC_FRMT_N0)
76 #define GET_TEXSOURCE(n) n
77 #define GET_UBYTE_COLOR_STORE() &RADEON_CONTEXT(ctx)->UbyteColor
78 #define GET_UBYTE_SPEC_COLOR_STORE() &RADEON_CONTEXT(ctx)->UbyteSecondaryColor
80 #define IMPORT_FLOAT_COLORS radeon_import_float_colors
81 #define IMPORT_FLOAT_SPEC_COLORS radeon_import_float_spec_colors
83 /***********************************************************************
84 * Generate vertex emit functions *
85 ***********************************************************************/
88 /* Defined in order of increasing vertex size:
91 #define IND (RADEON_CP_VC_FRMT_XY| \
92 RADEON_CP_VC_FRMT_Z| \
93 RADEON_CP_VC_FRMT_PKCOLOR)
94 #define TAG(x) x##_rgba
95 #include "radeon_maos_vbtmp.h"
98 #define IND (RADEON_CP_VC_FRMT_XY| \
99 RADEON_CP_VC_FRMT_Z| \
100 RADEON_CP_VC_FRMT_N0)
102 #include "radeon_maos_vbtmp.h"
105 #define IND (RADEON_CP_VC_FRMT_XY| \
106 RADEON_CP_VC_FRMT_Z| \
107 RADEON_CP_VC_FRMT_PKCOLOR| \
108 RADEON_CP_VC_FRMT_ST0)
109 #define TAG(x) x##_rgba_st
110 #include "radeon_maos_vbtmp.h"
113 #define IND (RADEON_CP_VC_FRMT_XY| \
114 RADEON_CP_VC_FRMT_Z| \
115 RADEON_CP_VC_FRMT_PKCOLOR| \
116 RADEON_CP_VC_FRMT_N0)
117 #define TAG(x) x##_rgba_n
118 #include "radeon_maos_vbtmp.h"
121 #define IND (RADEON_CP_VC_FRMT_XY| \
122 RADEON_CP_VC_FRMT_Z| \
123 RADEON_CP_VC_FRMT_ST0| \
124 RADEON_CP_VC_FRMT_N0)
125 #define TAG(x) x##_st_n
126 #include "radeon_maos_vbtmp.h"
129 #define IND (RADEON_CP_VC_FRMT_XY| \
130 RADEON_CP_VC_FRMT_Z| \
131 RADEON_CP_VC_FRMT_PKCOLOR| \
132 RADEON_CP_VC_FRMT_ST0| \
133 RADEON_CP_VC_FRMT_ST1)
134 #define TAG(x) x##_rgba_st_st
135 #include "radeon_maos_vbtmp.h"
138 #define IND (RADEON_CP_VC_FRMT_XY| \
139 RADEON_CP_VC_FRMT_Z| \
140 RADEON_CP_VC_FRMT_PKCOLOR| \
141 RADEON_CP_VC_FRMT_ST0| \
142 RADEON_CP_VC_FRMT_N0)
143 #define TAG(x) x##_rgba_st_n
144 #include "radeon_maos_vbtmp.h"
147 #define IND (RADEON_CP_VC_FRMT_XY| \
148 RADEON_CP_VC_FRMT_Z| \
149 RADEON_CP_VC_FRMT_PKCOLOR| \
150 RADEON_CP_VC_FRMT_PKSPEC| \
151 RADEON_CP_VC_FRMT_ST0| \
152 RADEON_CP_VC_FRMT_ST1)
153 #define TAG(x) x##_rgba_spec_st_st
154 #include "radeon_maos_vbtmp.h"
157 #define IND (RADEON_CP_VC_FRMT_XY| \
158 RADEON_CP_VC_FRMT_Z| \
159 RADEON_CP_VC_FRMT_ST0| \
160 RADEON_CP_VC_FRMT_ST1| \
161 RADEON_CP_VC_FRMT_N0)
162 #define TAG(x) x##_st_st_n
163 #include "radeon_maos_vbtmp.h"
166 #define IND (RADEON_CP_VC_FRMT_XY| \
167 RADEON_CP_VC_FRMT_Z| \
168 RADEON_CP_VC_FRMT_PKCOLOR| \
169 RADEON_CP_VC_FRMT_PKSPEC| \
170 RADEON_CP_VC_FRMT_ST0| \
171 RADEON_CP_VC_FRMT_ST1| \
172 RADEON_CP_VC_FRMT_N0)
173 #define TAG(x) x##_rgpa_spec_st_st_n
174 #include "radeon_maos_vbtmp.h"
177 #define IND (RADEON_CP_VC_FRMT_XY| \
178 RADEON_CP_VC_FRMT_Z| \
179 RADEON_CP_VC_FRMT_PKCOLOR| \
180 RADEON_CP_VC_FRMT_ST0| \
181 RADEON_CP_VC_FRMT_Q0)
182 #define TAG(x) x##_rgba_stq
183 #include "radeon_maos_vbtmp.h"
186 #define IND (RADEON_CP_VC_FRMT_XY| \
187 RADEON_CP_VC_FRMT_Z| \
188 RADEON_CP_VC_FRMT_PKCOLOR| \
189 RADEON_CP_VC_FRMT_ST1| \
190 RADEON_CP_VC_FRMT_Q1| \
191 RADEON_CP_VC_FRMT_ST0| \
192 RADEON_CP_VC_FRMT_Q0)
193 #define TAG(x) x##_rgba_stq_stq
194 #include "radeon_maos_vbtmp.h"
197 #define IND (RADEON_CP_VC_FRMT_XY| \
198 RADEON_CP_VC_FRMT_Z| \
199 RADEON_CP_VC_FRMT_W0| \
200 RADEON_CP_VC_FRMT_PKCOLOR| \
201 RADEON_CP_VC_FRMT_PKSPEC| \
202 RADEON_CP_VC_FRMT_ST0| \
203 RADEON_CP_VC_FRMT_Q0| \
204 RADEON_CP_VC_FRMT_ST1| \
205 RADEON_CP_VC_FRMT_Q1| \
206 RADEON_CP_VC_FRMT_N0)
207 #define TAG(x) x##_w_rgpa_spec_stq_stq_n
208 #include "radeon_maos_vbtmp.h"
214 /***********************************************************************
216 ***********************************************************************/
219 static void init_tcl_verts( void )
228 init_rgba_spec_st_st();
230 init_rgpa_spec_st_st_n();
233 init_w_rgpa_spec_stq_stq_n();
237 void radeonEmitArrays( GLcontext
*ctx
, GLuint inputs
)
239 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
240 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
242 GLuint vtx
= (rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &
243 ~(RADEON_TCL_VTX_Q0
|RADEON_TCL_VTX_Q1
));
245 static int firsttime
= 1;
253 req
|= RADEON_CP_VC_FRMT_Z
;
254 if (VB
->ObjPtr
->size
== 4) {
255 req
|= RADEON_CP_VC_FRMT_W0
;
259 if (inputs
& VERT_BIT_NORMAL
) {
260 req
|= RADEON_CP_VC_FRMT_N0
;
263 if (inputs
& VERT_BIT_COLOR0
) {
264 req
|= RADEON_CP_VC_FRMT_PKCOLOR
;
267 if (inputs
& VERT_BIT_COLOR1
) {
268 req
|= RADEON_CP_VC_FRMT_PKSPEC
;
271 if (inputs
& VERT_BIT_TEX0
) {
272 req
|= RADEON_CP_VC_FRMT_ST0
;
274 if (VB
->TexCoordPtr
[0]->size
== 4) {
275 req
|= RADEON_CP_VC_FRMT_Q0
;
276 vtx
|= RADEON_TCL_VTX_Q0
;
280 if (inputs
& VERT_BIT_TEX1
) {
281 req
|= RADEON_CP_VC_FRMT_ST1
;
283 if (VB
->TexCoordPtr
[1]->size
== 4) {
284 req
|= RADEON_CP_VC_FRMT_Q1
;
285 vtx
|= RADEON_TCL_VTX_Q1
;
289 if (vtx
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
]) {
290 RADEON_STATECHANGE( rmesa
, tcl
);
291 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] = vtx
;
294 for (i
= 0 ; i
< RADEON_TCL_MAX_SETUP
; i
++)
295 if ((setup_tab
[i
].vertex_format
& req
) == req
)
298 if (rmesa
->tcl
.vertex_format
== setup_tab
[i
].vertex_format
&&
299 rmesa
->tcl
.indexed_verts
.buf
)
302 if (rmesa
->tcl
.indexed_verts
.buf
)
303 radeonReleaseArrays( ctx
, ~0 );
305 radeonAllocDmaRegionVerts( rmesa
,
306 &rmesa
->tcl
.indexed_verts
,
308 setup_tab
[i
].vertex_size
* 4,
311 setup_tab
[i
].emit( ctx
, 0, VB
->Count
,
312 rmesa
->tcl
.indexed_verts
.address
+
313 rmesa
->tcl
.indexed_verts
.start
);
315 rmesa
->tcl
.vertex_format
= setup_tab
[i
].vertex_format
;
316 rmesa
->tcl
.indexed_verts
.aos_start
= GET_START( &rmesa
->tcl
.indexed_verts
);
317 rmesa
->tcl
.indexed_verts
.aos_size
= setup_tab
[i
].vertex_size
;
318 rmesa
->tcl
.indexed_verts
.aos_stride
= setup_tab
[i
].vertex_size
;
320 rmesa
->tcl
.aos_components
[0] = &rmesa
->tcl
.indexed_verts
;
321 rmesa
->tcl
.nr_aos_components
= 1;
326 void radeonReleaseArrays( GLcontext
*ctx
, GLuint newinputs
)
328 radeonContextPtr rmesa
= RADEON_CONTEXT( ctx
);
330 if (RADEON_DEBUG
& DEBUG_VERTS
)
331 _tnl_print_vert_flags( __FUNCTION__
, newinputs
);
334 radeonReleaseDmaRegion( rmesa
, &rmesa
->tcl
.indexed_verts
, __FUNCTION__
);