1 /* $XFree86: xc/lib/GL/mesa/src/drv/r200/r200_maos_arrays.c,v 1.3 2003/02/23 23:59:01 dawes Exp $ */
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
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>
42 #include "swrast_setup/swrast_setup.h"
43 #include "math/m_translate.h"
45 #include "tnl/t_context.h"
47 #include "r200_context.h"
48 #include "r200_ioctl.h"
49 #include "r200_state.h"
50 #include "r200_swtcl.h"
51 #include "r200_maos.h"
57 * - from r200_tcl_render
58 * - call r200EmitArrays to ensure uptodate arrays in dma
59 * - emit primitives (new type?) which reference the data
60 * -- need to use elts for lineloop, quads, quadstrip/flat
61 * -- other primitives are all well-formed (need tristrip-1,fake-poly)
64 static void emit_ubyte_rgba3( GLcontext
*ctx
,
65 struct r200_dma_region
*rvb
,
71 r200_color_t
*out
= (r200_color_t
*)(rvb
->start
+ rvb
->address
);
73 if (R200_DEBUG
& DEBUG_VERTS
)
74 fprintf(stderr
, "%s count %d stride %d out %p\n",
75 __FUNCTION__
, count
, stride
, (void *)out
);
77 for (i
= 0; i
< count
; i
++) {
79 out
->green
= *(data
+1);
80 out
->blue
= *(data
+2);
87 static void emit_ubyte_rgba4( GLcontext
*ctx
,
88 struct r200_dma_region
*rvb
,
94 int *out
= (int *)(rvb
->address
+ rvb
->start
);
96 if (R200_DEBUG
& DEBUG_VERTS
)
97 fprintf(stderr
, "%s count %d stride %d\n",
98 __FUNCTION__
, count
, stride
);
101 for (i
= 0; i
< count
; i
++)
102 ((int *)out
)[i
] = LE32_TO_CPU(((int *)data
)[i
]);
104 for (i
= 0; i
< count
; i
++) {
105 *(int *)out
++ = LE32_TO_CPU(*(int *)data
);
112 static void emit_ubyte_rgba( GLcontext
*ctx
,
113 struct r200_dma_region
*rvb
,
119 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
121 if (R200_DEBUG
& DEBUG_VERTS
)
122 fprintf(stderr
, "%s %d/%d\n", __FUNCTION__
, count
, size
);
127 r200AllocDmaRegion( rmesa
, rvb
, 4, 4 );
129 rvb
->aos_start
= GET_START(rvb
);
134 r200AllocDmaRegion( rmesa
, rvb
, 4 * count
, 4 ); /* alignment? */
135 rvb
->aos_start
= GET_START(rvb
);
144 emit_ubyte_rgba3( ctx
, rvb
, data
, stride
, count
);
147 emit_ubyte_rgba4( ctx
, rvb
, data
, stride
, count
);
158 #if defined(USE_X86_ASM)
159 #define COPY_DWORDS( dst, src, nr ) \
162 __asm__ __volatile__( "rep ; movsl" \
163 : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
169 #define COPY_DWORDS( dst, src, nr ) \
172 for ( j = 0 ; j < nr ; j++ ) \
173 dst[j] = ((int *)src)[j]; \
179 static void emit_vecfog( GLcontext
*ctx
,
180 struct r200_dma_region
*rvb
,
188 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
190 if (R200_DEBUG
& DEBUG_VERTS
)
191 fprintf(stderr
, "%s count %d stride %d\n",
192 __FUNCTION__
, count
, stride
);
197 r200AllocDmaRegion( rmesa
, rvb
, 4, 4 );
199 rvb
->aos_start
= GET_START(rvb
);
204 r200AllocDmaRegion( rmesa
, rvb
, count
* 4, 4 ); /* alignment? */
205 rvb
->aos_start
= GET_START(rvb
);
212 out
= (GLfloat
*)(rvb
->address
+ rvb
->start
);
213 for (i
= 0; i
< count
; i
++) {
214 out
[0] = r200ComputeFogBlendFactor( ctx
, *(GLfloat
*)data
);
222 static void emit_vec4( GLcontext
*ctx
,
223 struct r200_dma_region
*rvb
,
229 int *out
= (int *)(rvb
->address
+ rvb
->start
);
231 if (R200_DEBUG
& DEBUG_VERTS
)
232 fprintf(stderr
, "%s count %d stride %d\n",
233 __FUNCTION__
, count
, stride
);
236 COPY_DWORDS( out
, data
, count
);
238 for (i
= 0; i
< count
; i
++) {
239 out
[0] = *(int *)data
;
246 static void emit_vec8( GLcontext
*ctx
,
247 struct r200_dma_region
*rvb
,
253 int *out
= (int *)(rvb
->address
+ rvb
->start
);
255 if (R200_DEBUG
& DEBUG_VERTS
)
256 fprintf(stderr
, "%s count %d stride %d\n",
257 __FUNCTION__
, count
, stride
);
260 COPY_DWORDS( out
, data
, count
*2 );
262 for (i
= 0; i
< count
; i
++) {
263 out
[0] = *(int *)data
;
264 out
[1] = *(int *)(data
+4);
270 static void emit_vec12( GLcontext
*ctx
,
271 struct r200_dma_region
*rvb
,
277 int *out
= (int *)(rvb
->address
+ rvb
->start
);
279 if (R200_DEBUG
& DEBUG_VERTS
)
280 fprintf(stderr
, "%s count %d stride %d out %p data %p\n",
281 __FUNCTION__
, count
, stride
, (void *)out
, (void *)data
);
284 COPY_DWORDS( out
, data
, count
*3 );
286 for (i
= 0; i
< count
; i
++) {
287 out
[0] = *(int *)data
;
288 out
[1] = *(int *)(data
+4);
289 out
[2] = *(int *)(data
+8);
295 static void emit_vec16( GLcontext
*ctx
,
296 struct r200_dma_region
*rvb
,
302 int *out
= (int *)(rvb
->address
+ rvb
->start
);
304 if (R200_DEBUG
& DEBUG_VERTS
)
305 fprintf(stderr
, "%s count %d stride %d\n",
306 __FUNCTION__
, count
, stride
);
309 COPY_DWORDS( out
, data
, count
*4 );
311 for (i
= 0; i
< count
; i
++) {
312 out
[0] = *(int *)data
;
313 out
[1] = *(int *)(data
+4);
314 out
[2] = *(int *)(data
+8);
315 out
[3] = *(int *)(data
+12);
322 static void emit_vector( GLcontext
*ctx
,
323 struct r200_dma_region
*rvb
,
329 r200ContextPtr rmesa
= R200_CONTEXT(ctx
);
331 if (R200_DEBUG
& DEBUG_VERTS
)
332 fprintf(stderr
, "%s count %d size %d stride %d\n",
333 __FUNCTION__
, count
, size
, stride
);
338 r200AllocDmaRegion( rmesa
, rvb
, size
* 4, 4 );
340 rvb
->aos_start
= GET_START(rvb
);
342 rvb
->aos_size
= size
;
345 r200AllocDmaRegion( rmesa
, rvb
, size
* count
* 4, 4 ); /* alignment? */
346 rvb
->aos_start
= GET_START(rvb
);
347 rvb
->aos_stride
= size
;
348 rvb
->aos_size
= size
;
355 emit_vec4( ctx
, rvb
, data
, stride
, count
);
358 emit_vec8( ctx
, rvb
, data
, stride
, count
);
361 emit_vec12( ctx
, rvb
, data
, stride
, count
);
364 emit_vec16( ctx
, rvb
, data
, stride
, count
);
376 /* Emit any changed arrays to new GART memory, re-emit a packet to
379 void r200EmitArrays( GLcontext
*ctx
, GLuint inputs
)
381 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
382 struct vertex_buffer
*VB
= &TNL_CONTEXT( ctx
)->vb
;
383 struct r200_dma_region
**component
= rmesa
->tcl
.aos_components
;
385 GLuint vfmt0
= 0, vfmt1
= 0;
386 GLuint count
= VB
->Count
;
390 if (!rmesa
->tcl
.obj
.buf
)
393 (char *)VB
->ObjPtr
->data
,
398 switch( VB
->ObjPtr
->size
) {
399 case 4: vfmt0
|= R200_VTX_W0
;
400 case 3: vfmt0
|= R200_VTX_Z0
;
405 component
[nr
++] = &rmesa
->tcl
.obj
;
409 if (inputs
& VERT_BIT_NORMAL
) {
410 if (!rmesa
->tcl
.norm
.buf
)
413 (char *)VB
->NormalPtr
->data
,
415 VB
->NormalPtr
->stride
,
418 vfmt0
|= R200_VTX_N0
;
419 component
[nr
++] = &rmesa
->tcl
.norm
;
422 if (inputs
& VERT_BIT_FOG
) {
423 if (!rmesa
->tcl
.fog
.buf
)
426 (char *)VB
->FogCoordPtr
->data
,
427 VB
->FogCoordPtr
->stride
,
430 vfmt0
|= R200_VTX_DISCRETE_FOG
;
431 component
[nr
++] = &rmesa
->tcl
.fog
;
434 if (inputs
& VERT_BIT_COLOR0
) {
437 if (VB
->ColorPtr
[0]->size
== 4 &&
438 (VB
->ColorPtr
[0]->stride
!= 0 ||
439 VB
->ColorPtr
[0]->data
[0][3] != 1.0)) {
440 vfmt0
|= R200_VTX_FP_RGBA
<< R200_VTX_COLOR_0_SHIFT
;
444 vfmt0
|= R200_VTX_FP_RGB
<< R200_VTX_COLOR_0_SHIFT
;
448 if (!rmesa
->tcl
.rgba
.buf
)
451 (char *)VB
->ColorPtr
[0]->data
,
453 VB
->ColorPtr
[0]->stride
,
456 component
[nr
++] = &rmesa
->tcl
.rgba
;
460 if (inputs
& VERT_BIT_COLOR1
) {
461 if (!rmesa
->tcl
.spec
.buf
) {
464 (char *)VB
->SecondaryColorPtr
[0]->data
,
466 VB
->SecondaryColorPtr
[0]->stride
,
470 /* How does this work?
472 vfmt0
|= R200_VTX_FP_RGB
<< R200_VTX_COLOR_1_SHIFT
;
473 component
[nr
++] = &rmesa
->tcl
.spec
;
476 for ( i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++ ) {
477 if (inputs
& (VERT_BIT_TEX0
<< i
)) {
478 if (!rmesa
->tcl
.tex
[i
].buf
)
480 &(rmesa
->tcl
.tex
[i
]),
481 (char *)VB
->TexCoordPtr
[i
]->data
,
482 VB
->TexCoordPtr
[i
]->size
,
483 VB
->TexCoordPtr
[i
]->stride
,
486 vfmt1
|= VB
->TexCoordPtr
[i
]->size
<< (i
* 3);
487 component
[nr
++] = &rmesa
->tcl
.tex
[i
];
491 if (vfmt0
!= rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] ||
492 vfmt1
!= rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
]) {
493 R200_STATECHANGE( rmesa
, vtx
);
494 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_0
] = vfmt0
;
495 rmesa
->hw
.vtx
.cmd
[VTX_VTXFMT_1
] = vfmt1
;
498 rmesa
->tcl
.nr_aos_components
= nr
;
499 rmesa
->tcl
.vertex_format
= vfmt0
;
503 void r200ReleaseArrays( GLcontext
*ctx
, GLuint newinputs
)
506 r200ContextPtr rmesa
= R200_CONTEXT( ctx
);
508 /* if (R200_DEBUG & DEBUG_VERTS) */
509 /* _tnl_print_vert_flags( __FUNCTION__, newinputs ); */
511 if (newinputs
& VERT_BIT_POS
)
512 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.obj
, __FUNCTION__
);
514 if (newinputs
& VERT_BIT_NORMAL
)
515 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.norm
, __FUNCTION__
);
517 if (newinputs
& VERT_BIT_FOG
)
518 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.fog
, __FUNCTION__
);
520 if (newinputs
& VERT_BIT_COLOR0
)
521 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.rgba
, __FUNCTION__
);
523 if (newinputs
& VERT_BIT_COLOR1
)
524 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.spec
, __FUNCTION__
);
526 for (unit
= 0 ; unit
< ctx
->Const
.MaxTextureUnits
; unit
++) {
527 if (newinputs
& VERT_BIT_TEX(unit
))
528 r200ReleaseDmaRegion( rmesa
, &rmesa
->tcl
.tex
[unit
], __FUNCTION__
);