1 /*
2 Copyright (C) The Weather Channel, Inc.  2002.  All Rights Reserved.
3 
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7 
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:
15 
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.
19 
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.
27 
28 **************************************************************************/
29 
30 /*
31  * Authors:
32  *   Keith Whitwell <keithw@vmware.com>
33  */
34 
35 #include "main/glheader.h"
36 #include "main/mtypes.h"
37 
38 #include "main/macros.h"
39 #include "main/state.h"
40 
41 #include "swrast_setup/swrast_setup.h"
42 #include "math/m_translate.h"
43 #include "tnl/tnl.h"
44 #include "tnl/t_context.h"
45 
46 #include "r200_context.h"
47 #include "r200_ioctl.h"
48 #include "r200_state.h"
49 #include "r200_swtcl.h"
50 #include "r200_maos.h"
51 #include "r200_tcl.h"
52 
53 #if defined(USE_X86_ASM)
54 #define COPY_DWORDS( dst, src, nr )					\
55 do {									\
56 	int __tmp;							\
57 	__asm__ __volatile__( "rep ; movsl"				\
58 			      : "=%c" (__tmp), "=D" (dst), "=S" (__tmp)	\
59 			      : "0" (nr),				\
60 			        "D" ((long)dst),			\
61 			        "S" ((long)src) );			\
62 } while (0)
63 #else
64 #define COPY_DWORDS( dst, src, nr )		\
65 do {						\
66    int j;					\
67    for ( j = 0 ; j < nr ; j++ )			\
68       dst[j] = ((int *)src)[j];			\
69    dst += nr;					\
70 } while (0)
71 #endif
72 
73 /* Emit any changed arrays to new GART memory, re-emit a packet to
74  * update the arrays.
75  */
r200EmitArrays(struct gl_context * ctx,GLubyte * vimap_rev)76 void r200EmitArrays( struct gl_context *ctx, GLubyte *vimap_rev )
77 {
78    r200ContextPtr rmesa = R200_CONTEXT( ctx );
79    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
80    GLuint nr = 0;
81    GLuint vfmt0 = 0, vfmt1 = 0;
82    GLuint count = VB->Count;
83    GLuint i, emitsize;
84 
85    //   fprintf(stderr,"emit arrays\n");
86    for ( i = 0; i < 15; i++ ) {
87       GLubyte attrib = vimap_rev[i];
88       if (attrib != 255) {
89 	 switch (i) {
90 	 case 0:
91 	    emitsize = (VB->AttribPtr[attrib]->size);
92 	    switch (emitsize) {
93 	    case 4:
94 	       vfmt0 |= R200_VTX_W0;
95 	       FALLTHROUGH;
96 	    case 3:
97 	       vfmt0 |= R200_VTX_Z0;
98 	       break;
99 	    case 2:
100 	       break;
101 	    default: assert(0);
102 	    }
103 	    break;
104 	 case 1:
105             unreachable("r200: vertex weight attrib unsupported");
106 	    break;
107 	 case 2:
108 	    assert(attrib == VERT_ATTRIB_NORMAL);
109 	    emitsize = 3;
110 	    vfmt0 |= R200_VTX_N0;
111 	    break;
112 	 case 3:
113 	    /* special handling to fix up fog. Will get us into trouble with vbos...*/
114 	    assert(attrib == VERT_ATTRIB_FOG);
115 	    if (!rmesa->radeon.tcl.aos[i].bo) {
116 	       if (_mesa_arb_vertex_program_enabled(ctx))
117 		  rcommon_emit_vector( ctx,
118 				       &(rmesa->radeon.tcl.aos[nr]),
119 				       (char *)VB->AttribPtr[attrib]->data,
120 				       1,
121 				       VB->AttribPtr[attrib]->stride,
122 				       count);
123 	       else
124 		 rcommon_emit_vecfog( ctx,
125 				      &(rmesa->radeon.tcl.aos[nr]),
126 				      (char *)VB->AttribPtr[attrib]->data,
127 				      VB->AttribPtr[attrib]->stride,
128 				      count);
129 	    }
130 	    vfmt0 |= R200_VTX_DISCRETE_FOG;
131 	    goto after_emit;
132 	    break;
133 	 case 4:
134 	 case 5:
135 	 case 6:
136 	 case 7:
137 	    if (VB->AttribPtr[attrib]->size == 4 &&
138 	       (VB->AttribPtr[attrib]->stride != 0 ||
139 		VB->AttribPtr[attrib]->data[0][3] != 1.0)) emitsize = 4;
140 	    else emitsize = 3;
141 	    if (emitsize == 4)
142 	       vfmt0 |= R200_VTX_FP_RGBA << (R200_VTX_COLOR_0_SHIFT + (i - 4) * 2);
143 	    else {
144 	       vfmt0 |= R200_VTX_FP_RGB << (R200_VTX_COLOR_0_SHIFT + (i - 4) * 2);
145 	    }
146 	    break;
147 	 case 8:
148 	 case 9:
149 	 case 10:
150 	 case 11:
151 	 case 12:
152 	 case 13:
153 	    emitsize = VB->AttribPtr[attrib]->size;
154 	    vfmt1 |= emitsize << (R200_VTX_TEX0_COMP_CNT_SHIFT + (i - 8) * 3);
155 	    break;
156 	 case 14:
157 	    emitsize = VB->AttribPtr[attrib]->size >= 2 ? VB->AttribPtr[attrib]->size : 2;
158 	    switch (emitsize) {
159 	    case 2:
160 	       vfmt0 |= R200_VTX_XY1;
161 	       FALLTHROUGH;
162 	    case 3:
163 	       vfmt0 |= R200_VTX_Z1;
164 	       FALLTHROUGH;
165 	    case 4:
166 	       vfmt0 |= R200_VTX_W1;
167 	    }
168 	    break;
169 	 default:
170 	    assert(0);
171 	    emitsize = 0;
172 	 }
173 	 if (!rmesa->radeon.tcl.aos[nr].bo) {
174 	   rcommon_emit_vector( ctx,
175 				&(rmesa->radeon.tcl.aos[nr]),
176 				(char *)VB->AttribPtr[attrib]->data,
177 				emitsize,
178 				VB->AttribPtr[attrib]->stride,
179 				count );
180 	 }
181 after_emit:
182 	 assert(nr < 12);
183 	 nr++;
184       }
185    }
186 
187    if (vfmt0 != rmesa->hw.vtx.cmd[VTX_VTXFMT_0] ||
188        vfmt1 != rmesa->hw.vtx.cmd[VTX_VTXFMT_1]) {
189       R200_STATECHANGE( rmesa, vtx );
190       rmesa->hw.vtx.cmd[VTX_VTXFMT_0] = vfmt0;
191       rmesa->hw.vtx.cmd[VTX_VTXFMT_1] = vfmt1;
192    }
193 
194    rmesa->radeon.tcl.aos_count = nr;
195 }
196 
197