1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Keith Whitwell <keithw@vmware.com>
35 #include "main/glheader.h"
36 #include "main/mtypes.h"
37 #include "main/macros.h"
39 #include "swrast_setup/swrast_setup.h"
40 #include "math/m_translate.h"
43 #include "radeon_context.h"
44 #include "radeon_ioctl.h"
45 #include "radeon_state.h"
46 #include "radeon_swtcl.h"
47 #include "radeon_maos.h"
48 #include "radeon_tcl.h"
50 static void emit_s0_vec(uint32_t *out
, GLvoid
*data
, int stride
, int count
)
53 if (RADEON_DEBUG
& RADEON_VERTS
)
54 fprintf(stderr
, "%s count %d stride %d\n",
55 __func__
, count
, stride
);
57 for (i
= 0; i
< count
; i
++) {
58 out
[0] = *(int *)data
;
65 static void emit_stq_vec(uint32_t *out
, GLvoid
*data
, int stride
, int count
)
69 if (RADEON_DEBUG
& RADEON_VERTS
)
70 fprintf(stderr
, "%s count %d stride %d\n",
71 __func__
, count
, stride
);
73 for (i
= 0; i
< count
; i
++) {
74 out
[0] = *(int *)data
;
75 out
[1] = *(int *)(data
+4);
76 out
[2] = *(int *)(data
+12);
82 static void emit_tex_vector(struct gl_context
*ctx
, struct radeon_aos
*aos
,
83 GLvoid
*data
, int size
, int stride
, int count
)
85 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
89 if (RADEON_DEBUG
& RADEON_VERTS
)
90 fprintf(stderr
, "%s %d/%d\n", __func__
, count
, size
);
93 case 4: emitsize
= 3; break;
94 case 3: emitsize
= 3; break;
95 default: emitsize
= 2; break;
100 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, emitsize
* 4, 32);
105 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, emitsize
* count
* 4, 32);
106 aos
->stride
= emitsize
;
109 aos
->components
= emitsize
;
114 radeon_bo_map(aos
->bo
, 1);
115 out
= (uint32_t*)((char*)aos
->bo
->ptr
+ aos
->offset
);
118 emit_s0_vec( out
, data
, stride
, count
);
121 radeonEmitVec8( out
, data
, stride
, count
);
124 radeonEmitVec12( out
, data
, stride
, count
);
127 emit_stq_vec( out
, data
, stride
, count
);
134 radeon_bo_unmap(aos
->bo
);
140 /* Emit any changed arrays to new GART memory, re-emit a packet to
143 void radeonEmitArrays( struct gl_context
*ctx
, GLuint inputs
)
145 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
146 struct vertex_buffer
*VB
= &TNL_CONTEXT( ctx
)->vb
;
149 GLuint count
= VB
->Count
;
153 if (RADEON_DEBUG
& RADEON_VERTS
)
154 _tnl_print_vert_flags( __func__
, inputs
);
158 if (!rmesa
->tcl
.obj
.buf
)
159 rcommon_emit_vector( ctx
,
160 &(rmesa
->tcl
.aos
[nr
]),
161 (char *)VB
->AttribPtr
[_TNL_ATTRIB_POS
]->data
,
162 VB
->AttribPtr
[_TNL_ATTRIB_POS
]->size
,
163 VB
->AttribPtr
[_TNL_ATTRIB_POS
]->stride
,
166 switch( VB
->AttribPtr
[_TNL_ATTRIB_POS
]->size
) {
167 case 4: vfmt
|= RADEON_CP_VC_FRMT_W0
;
168 case 3: vfmt
|= RADEON_CP_VC_FRMT_Z
;
169 case 2: vfmt
|= RADEON_CP_VC_FRMT_XY
;
177 if (inputs
& VERT_BIT_NORMAL
) {
178 if (!rmesa
->tcl
.norm
.buf
)
179 rcommon_emit_vector( ctx
,
180 &(rmesa
->tcl
.aos
[nr
]),
181 (char *)VB
->AttribPtr
[_TNL_ATTRIB_NORMAL
]->data
,
183 VB
->AttribPtr
[_TNL_ATTRIB_NORMAL
]->stride
,
186 vfmt
|= RADEON_CP_VC_FRMT_N0
;
190 if (inputs
& VERT_BIT_COLOR0
) {
192 if (VB
->AttribPtr
[_TNL_ATTRIB_COLOR0
]->size
== 4 &&
193 (VB
->AttribPtr
[_TNL_ATTRIB_COLOR0
]->stride
!= 0 ||
194 VB
->AttribPtr
[_TNL_ATTRIB_COLOR0
]->data
[0][3] != 1.0)) {
195 vfmt
|= RADEON_CP_VC_FRMT_FPCOLOR
| RADEON_CP_VC_FRMT_FPALPHA
;
200 vfmt
|= RADEON_CP_VC_FRMT_FPCOLOR
;
204 if (!rmesa
->tcl
.rgba
.buf
)
205 rcommon_emit_vector( ctx
,
206 &(rmesa
->tcl
.aos
[nr
]),
207 (char *)VB
->AttribPtr
[_TNL_ATTRIB_COLOR0
]->data
,
209 VB
->AttribPtr
[_TNL_ATTRIB_COLOR0
]->stride
,
216 if (inputs
& VERT_BIT_COLOR1
) {
217 if (!rmesa
->tcl
.spec
.buf
) {
219 rcommon_emit_vector( ctx
,
220 &(rmesa
->tcl
.aos
[nr
]),
221 (char *)VB
->AttribPtr
[_TNL_ATTRIB_COLOR1
]->data
,
223 VB
->AttribPtr
[_TNL_ATTRIB_COLOR1
]->stride
,
227 vfmt
|= RADEON_CP_VC_FRMT_FPSPEC
;
231 /* FIXME: not sure if this is correct. May need to stitch this together with
232 secondary color. It seems odd that for primary color color and alpha values
233 are emitted together but for secondary color not. */
234 if (inputs
& VERT_BIT_FOG
) {
235 if (!rmesa
->tcl
.fog
.buf
)
236 rcommon_emit_vecfog( ctx
,
237 &(rmesa
->tcl
.aos
[nr
]),
238 (char *)VB
->AttribPtr
[_TNL_ATTRIB_FOG
]->data
,
239 VB
->AttribPtr
[_TNL_ATTRIB_FOG
]->stride
,
242 vfmt
|= RADEON_CP_VC_FRMT_FPFOG
;
247 vtx
= (rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &
248 ~(RADEON_TCL_VTX_Q0
|RADEON_TCL_VTX_Q1
|RADEON_TCL_VTX_Q2
));
250 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
251 if (inputs
& VERT_BIT_TEX(unit
)) {
252 if (!rmesa
->tcl
.tex
[unit
].buf
)
253 emit_tex_vector( ctx
,
254 &(rmesa
->tcl
.aos
[nr
]),
255 (char *)VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->data
,
256 VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->size
,
257 VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->stride
,
261 vfmt
|= RADEON_ST_BIT(unit
);
262 /* assume we need the 3rd coord if texgen is active for r/q OR at least
263 3 coords are submitted. This may not be 100% correct */
264 if (VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->size
>= 3) {
265 vtx
|= RADEON_Q_BIT(unit
);
266 vfmt
|= RADEON_Q_BIT(unit
);
268 if ( (ctx
->Texture
.Unit
[unit
].TexGenEnabled
& (R_BIT
| Q_BIT
)) )
269 vtx
|= RADEON_Q_BIT(unit
);
270 else if ((VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->size
>= 3) &&
271 (!ctx
->Texture
.Unit
[unit
]._Current
||
272 ctx
->Texture
.Unit
[unit
]._Current
->Target
!= GL_TEXTURE_CUBE_MAP
)) {
273 GLuint swaptexmatcol
= (VB
->AttribPtr
[_TNL_ATTRIB_TEX0
+ unit
]->size
- 3);
274 if (((rmesa
->NeedTexMatrix
>> unit
) & 1) &&
275 (swaptexmatcol
!= ((rmesa
->TexMatColSwap
>> unit
) & 1)))
276 radeonUploadTexMatrix( rmesa
, unit
, swaptexmatcol
) ;
281 if (vtx
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
]) {
282 RADEON_STATECHANGE( rmesa
, tcl
);
283 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] = vtx
;
286 rmesa
->tcl
.nr_aos_components
= nr
;
287 rmesa
->tcl
.vertex_format
= vfmt
;