1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 Tungsten Graphics Inc., Cedar Park, Texas.
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 <keith@tungstengraphics.com>
35 #include "main/glheader.h"
36 #include "main/imports.h"
37 #include "main/mtypes.h"
38 #include "main/macros.h"
40 #include "swrast_setup/swrast_setup.h"
41 #include "math/m_translate.h"
44 #include "radeon_context.h"
45 #include "radeon_ioctl.h"
46 #include "radeon_state.h"
47 #include "radeon_swtcl.h"
48 #include "radeon_maos.h"
49 #include "radeon_tcl.h"
51 static void emit_vecfog(GLcontext
*ctx
, struct radeon_aos
*aos
,
52 GLvoid
*data
, int stride
, int count
)
57 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
59 if (RADEON_DEBUG
& DEBUG_VERTS
)
60 fprintf(stderr
, "%s count %d stride %d\n",
61 __FUNCTION__
, count
, stride
);
64 radeonAllocDmaRegion( rmesa
, &aos
->bo
, &aos
->offset
, size
* 4, 32 );
69 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, size
* 4, 32);
73 aos
->components
= size
;
79 out
= (uint32_t*)((char*)aos
->bo
->ptr
+ aos
->offset
);
80 for (i
= 0; i
< count
; i
++) {
81 out
[0] = radeonComputeFogBlendFactor( ctx
, *(GLfloat
*)data
);
87 static void emit_s0_vec(uint32_t *out
, GLvoid
*data
, int stride
, int count
)
90 if (RADEON_DEBUG
& DEBUG_VERTS
)
91 fprintf(stderr
, "%s count %d stride %d\n",
92 __FUNCTION__
, count
, stride
);
94 for (i
= 0; i
< count
; i
++) {
95 out
[0] = *(int *)data
;
102 static void emit_stq_vec(uint32_t *out
, GLvoid
*data
, int stride
, int count
)
106 if (RADEON_DEBUG
& DEBUG_VERTS
)
107 fprintf(stderr
, "%s count %d stride %d\n",
108 __FUNCTION__
, count
, stride
);
110 for (i
= 0; i
< count
; i
++) {
111 out
[0] = *(int *)data
;
112 out
[1] = *(int *)(data
+4);
113 out
[2] = *(int *)(data
+12);
122 static void emit_tex_vector(GLcontext
*ctx
, struct radeon_aos
*aos
,
123 GLvoid
*data
, int size
, int stride
, int count
)
125 radeonContextPtr rmesa
= RADEON_CONTEXT(ctx
);
129 if (RADEON_DEBUG
& DEBUG_VERTS
)
130 fprintf(stderr
, "%s %d/%d\n", __FUNCTION__
, count
, size
);
133 case 4: emitsize
= 3; break;
134 case 3: emitsize
= 3; break;
135 default: emitsize
= 2; break;
140 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, emitsize
* 4, 32);
145 radeonAllocDmaRegion(rmesa
, &aos
->bo
, &aos
->offset
, emitsize
* count
* 4, 32);
146 aos
->stride
= emitsize
;
149 aos
->components
= emitsize
;
154 out
= (uint32_t*)((char*)aos
->bo
->ptr
+ aos
->offset
);
157 emit_s0_vec( out
, data
, stride
, count
);
160 radeonEmitVec8( out
, data
, stride
, count
);
163 radeonEmitVec12( out
, data
, stride
, count
);
166 emit_stq_vec( out
, data
, stride
, count
);
178 /* Emit any changed arrays to new GART memory, re-emit a packet to
181 void radeonEmitArrays( GLcontext
*ctx
, GLuint inputs
)
183 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
184 struct vertex_buffer
*VB
= &TNL_CONTEXT( ctx
)->vb
;
187 GLuint count
= VB
->Count
;
191 if (RADEON_DEBUG
& DEBUG_VERTS
)
192 _tnl_print_vert_flags( __FUNCTION__
, inputs
);
196 if (!rmesa
->tcl
.obj
.buf
)
197 rcommon_emit_vector( ctx
,
198 &(rmesa
->tcl
.aos
[nr
]),
199 (char *)VB
->ObjPtr
->data
,
204 switch( VB
->ObjPtr
->size
) {
205 case 4: vfmt
|= RADEON_CP_VC_FRMT_W0
;
206 case 3: vfmt
|= RADEON_CP_VC_FRMT_Z
;
207 case 2: vfmt
|= RADEON_CP_VC_FRMT_XY
;
215 if (inputs
& VERT_BIT_NORMAL
) {
216 if (!rmesa
->tcl
.norm
.buf
)
217 rcommon_emit_vector( ctx
,
218 &(rmesa
->tcl
.aos
[nr
]),
219 (char *)VB
->NormalPtr
->data
,
221 VB
->NormalPtr
->stride
,
224 vfmt
|= RADEON_CP_VC_FRMT_N0
;
228 if (inputs
& VERT_BIT_COLOR0
) {
230 if (VB
->ColorPtr
[0]->size
== 4 &&
231 (VB
->ColorPtr
[0]->stride
!= 0 ||
232 VB
->ColorPtr
[0]->data
[0][3] != 1.0)) {
233 vfmt
|= RADEON_CP_VC_FRMT_FPCOLOR
| RADEON_CP_VC_FRMT_FPALPHA
;
238 vfmt
|= RADEON_CP_VC_FRMT_FPCOLOR
;
242 if (!rmesa
->tcl
.rgba
.buf
)
243 rcommon_emit_vector( ctx
,
244 &(rmesa
->tcl
.aos
[nr
]),
245 (char *)VB
->ColorPtr
[0]->data
,
247 VB
->ColorPtr
[0]->stride
,
254 if (inputs
& VERT_BIT_COLOR1
) {
255 if (!rmesa
->tcl
.spec
.buf
) {
257 rcommon_emit_vector( ctx
,
258 &(rmesa
->tcl
.aos
[nr
]),
259 (char *)VB
->SecondaryColorPtr
[0]->data
,
261 VB
->SecondaryColorPtr
[0]->stride
,
265 vfmt
|= RADEON_CP_VC_FRMT_FPSPEC
;
269 /* FIXME: not sure if this is correct. May need to stitch this together with
270 secondary color. It seems odd that for primary color color and alpha values
271 are emitted together but for secondary color not. */
272 if (inputs
& VERT_BIT_FOG
) {
273 if (!rmesa
->tcl
.fog
.buf
)
275 &(rmesa
->tcl
.aos
[nr
]),
276 (char *)VB
->FogCoordPtr
->data
,
277 VB
->FogCoordPtr
->stride
,
280 vfmt
|= RADEON_CP_VC_FRMT_FPFOG
;
285 vtx
= (rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] &
286 ~(RADEON_TCL_VTX_Q0
|RADEON_TCL_VTX_Q1
|RADEON_TCL_VTX_Q2
));
288 for (unit
= 0; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
289 if (inputs
& VERT_BIT_TEX(unit
)) {
290 if (!rmesa
->tcl
.tex
[unit
].buf
)
291 emit_tex_vector( ctx
,
292 &(rmesa
->tcl
.aos
[nr
]),
293 (char *)VB
->TexCoordPtr
[unit
]->data
,
294 VB
->TexCoordPtr
[unit
]->size
,
295 VB
->TexCoordPtr
[unit
]->stride
,
299 vfmt
|= RADEON_ST_BIT(unit
);
300 /* assume we need the 3rd coord if texgen is active for r/q OR at least
301 3 coords are submitted. This may not be 100% correct */
302 if (VB
->TexCoordPtr
[unit
]->size
>= 3) {
303 vtx
|= RADEON_Q_BIT(unit
);
304 vfmt
|= RADEON_Q_BIT(unit
);
306 if ( (ctx
->Texture
.Unit
[unit
].TexGenEnabled
& (R_BIT
| Q_BIT
)) )
307 vtx
|= RADEON_Q_BIT(unit
);
308 else if ((VB
->TexCoordPtr
[unit
]->size
>= 3) &&
309 ((ctx
->Texture
.Unit
[unit
]._ReallyEnabled
& (TEXTURE_CUBE_BIT
)) == 0)) {
310 GLuint swaptexmatcol
= (VB
->TexCoordPtr
[unit
]->size
- 3);
311 if (((rmesa
->NeedTexMatrix
>> unit
) & 1) &&
312 (swaptexmatcol
!= ((rmesa
->TexMatColSwap
>> unit
) & 1)))
313 radeonUploadTexMatrix( rmesa
, unit
, swaptexmatcol
) ;
318 if (vtx
!= rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
]) {
319 RADEON_STATECHANGE( rmesa
, tcl
);
320 rmesa
->hw
.tcl
.cmd
[TCL_OUTPUT_VTXFMT
] = vtx
;
323 rmesa
->tcl
.nr_aos_components
= nr
;
324 rmesa
->tcl
.vertex_format
= vfmt
;
328 void radeonReleaseArrays( GLcontext
*ctx
, GLuint newinputs
)
330 r100ContextPtr rmesa
= R100_CONTEXT( ctx
);
333 for (i
= 0; i
< rmesa
->tcl
.nr_aos_components
; i
++) {
334 if (rmesa
->tcl
.aos
[i
].bo
) {
335 radeon_bo_unref(rmesa
->tcl
.aos
[i
].bo
);
336 rmesa
->tcl
.aos
[i
].bo
= NULL
;