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