summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/tdfx/tdfx_fasttmp.h
blob: 24abcb4eb8e0332b2ee322e24048e94b1f2a0f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* -*- mode: c; c-basic-offset: 3 -*-
 *
 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
 *
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
/* $XFree86$ */

/*
 * Original rewrite:
 *	Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
 *
 * Authors:
 *	Gareth Hughes <gareth@valinux.com>
 *	Keith Whitwell <keithw@valinux.com>
 *
 */

/* The first part of setup is applied to all vertices, clipped or
 * unclipped.  This data will be used for clipping, and then all
 * vertices with a zero clipmask will be projected to device space.
 *
 * This could be split into several loops, but - it seems that the
 * large stride of the fxVertices makes cache issues the big
 * performance factor, and that multiple loops mean multiple cache
 * misses....
 */

static void TAG(tdfx_setup_full)( struct vertex_buffer *VB,
				  GLuint do_cliptest )
{
   tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB);
   GLcontext *ctx = VB->ctx;
   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
   const GLfloat * const m = ctx->ModelProjectMatrix.m;
   GLuint start = VB->CopyStart;
   GLuint count = VB->Count;

   if (0) fprintf(stderr, "%s\n", __FUNCTION__);

   gl_xform_points3_v16_general( TDFX_DRIVER_DATA(VB)->verts[start].f,
				 m,
				 VB->ObjPtr->start,
				 VB->ObjPtr->stride,
				 count - start );

   if ( do_cliptest ) {
      VB->ClipAndMask = ~0;
      VB->ClipOrMask = 0;
      gl_cliptest_points4_v16( fxVB->verts[start].f,
			       fxVB->verts[count].f,
			       &(VB->ClipOrMask),
			       &(VB->ClipAndMask),
			       VB->ClipMask + start );
   }

   /* These branches are all resolved at compile time.  Hopefully all
    * the pointers are valid addresses even when not enabled.
    */
   if ( TYPE ) {
      GLubyte *color = VB->ColorPtr->start;
      GLfloat *tex0_data = VB->TexCoordPtr[fxMesa->tmu_source[0]]->start;
      GLfloat *tex1_data = VB->TexCoordPtr[fxMesa->tmu_source[1]]->start;

      const GLuint color_stride = VB->ColorPtr->stride;
      const GLuint tex0_stride = VB->TexCoordPtr[fxMesa->tmu_source[0]]->stride;
      const GLuint tex1_stride = VB->TexCoordPtr[fxMesa->tmu_source[1]]->stride;

      GLfloat *f = fxVB->verts[start].f;
      GLfloat *end = f + (16 * (count - start));

      while ( f != end ) {
	 if ( TYPE & TDFX_RGBA_BIT ) {
#if defined(USE_X86_ASM)
	    __asm__ (
	    "movl (%%edx),%%eax   \n"
	    "bswap %%eax          \n"
	    "rorl $8,%%eax        \n"
	    "movl %%eax,16(%%edi) \n"
	    :
	    : "d" (color), "D" (f)
	    : "%eax" );
#else
	    GLubyte *col = color;
	    GLubyte *b = (GLubyte *)&f[CLIP_UBYTE_COLOR];
	    b[CLIP_UBYTE_B] = col[2];
	    b[CLIP_UBYTE_G] = col[1];
	    b[CLIP_UBYTE_R] = col[0];
	    b[CLIP_UBYTE_A] = col[3];
#endif
	 }
	 if (TYPE & TDFX_TEX0_BIT) {
#if defined (USE_X86_ASM)
	    __asm__ (
	    "movl (%%ecx), %%eax    \n"
	    "movl %%eax, 24(%%edi)  \n"
	    "movl 4(%%ecx), %%eax   \n"
	    "movl %%eax, 28(%%edi)"
	    :
	    : "c" (tex0_data), "D" (f)
	    : "%eax");
#else
	    *(unsigned int *)(f+CLIP_S0) = *(unsigned int *)tex0_data;
	    *(unsigned int *)(f+CLIP_T0) = *(unsigned int *)(tex0_data+1);
#endif
	 }
	 if (TYPE & TDFX_TEX1_BIT) {
	    /* Hits a second cache line.
	     */
#if defined (USE_X86_ASM)
	    __asm__ (
	    "movl (%%esi), %%eax    \n"
	    "movl %%eax, 32(%%edi)  \n"
	    "movl 4(%%esi), %%eax   \n"
	    "movl %%eax, 36(%%edi)"
	    :
	    : "S" (tex1_data), "D" (f)
	    : "%eax");
#else
	    *(unsigned int *)(f+CLIP_S1) = *(unsigned int *)tex1_data;
	    *(unsigned int *)(f+CLIP_T1) = *(unsigned int *)(tex1_data+1);
#endif
	 }
	 if ( TYPE & TDFX_RGBA_BIT ) color += color_stride;
	 if ( TYPE & TDFX_TEX0_BIT ) STRIDE_F( tex0_data, tex0_stride );
	 if ( TYPE & TDFX_TEX1_BIT ) STRIDE_F( tex1_data, tex1_stride );
	 f += 16;
      }
   }

   fxVB->clipped_elements.count = start;
   fxVB->last_vert = count;
}


/* Changed to just put the interp func instead of the whole clip
 * routine into the header.  Less code and better chance of doing some
 * of this stuff in assembly.
 */
static void TAG(tdfx_interp_vert)( GLfloat t,
				   GLfloat *O,
				   const GLfloat *I,
				   const GLfloat *J )
{
   O[0] = LINTERP( t, I[0], J[0] );
   O[1] = LINTERP( t, I[1], J[1] );
   O[2] = LINTERP( t, I[2], J[2] );
   O[3] = LINTERP( t, I[3], J[3] );

   if ( TYPE & TDFX_RGBA_BIT ) {
      INTERP_RGBA( t,
		   ((GLubyte *)&(O[4])),
		   ((GLubyte *)&(I[4])),
		   ((GLubyte *)&(J[4])) );
   }

   if ( TYPE & TDFX_TEX0_BIT ) {
      O[6] = LINTERP( t, I[6], J[6] );
      O[7] = LINTERP( t, I[7], J[7] );
   }

   if ( TYPE & TDFX_TEX1_BIT ) {
      O[8] = LINTERP( t, I[8], J[8] );
      O[9] = LINTERP( t, I[9], J[9] );
   }
}



static void TAG(tdfx_project_vertices)( struct vertex_buffer *VB )
{
   GLcontext *ctx = VB->ctx;
   GLmatrix *mat = &ctx->Viewport.WindowMap;
   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
   tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB);
   GLfloat *first = fxVB->verts[VB->CopyStart].f;
   GLfloat *last = fxVB->verts[fxVB->last_vert].f;
   GLfloat m[16];
   GLfloat *f;

   m[MAT_SX] = mat->m[MAT_SX];
   m[MAT_TX] = mat->m[MAT_TX] + fxMesa->x_offset + TRI_X_OFFSET;
   m[MAT_SY] = mat->m[MAT_SY];
   m[MAT_TY] = mat->m[MAT_TY] + fxMesa->y_delta + TRI_Y_OFFSET;
   m[MAT_SZ] = mat->m[MAT_SZ];
   m[MAT_TZ] = mat->m[MAT_TZ];

   gl_project_v16( first, last, m, 16 * 4 );

   /* V3 at least requires texcoords to be multiplied by 1/w:
    */
   if ( TYPE & (TDFX_TEX0_BIT|TDFX_TEX1_BIT) ) {

      const GLfloat sScale0 = fxMesa->sScale0;
      const GLfloat tScale0 = fxMesa->tScale0;
      const GLfloat sScale1 = fxMesa->sScale1;
      const GLfloat tScale1 = fxMesa->tScale1;


      for ( f = first ; f != last ; f += 16) {
	 const GLfloat oow = f[3];

	 if (TYPE & TDFX_TEX0_BIT) {
	    f[CLIP_S0] *= sScale0 * oow;
	    f[CLIP_T0] *= tScale0 * oow;
	 }

	 if (TYPE & TDFX_TEX1_BIT) {
	    f[CLIP_S1] *= sScale1 * oow;
	    f[CLIP_T1] *= tScale1 * oow;
	 }
      }
   }
}

static void TAG(tdfx_project_clipped_vertices)( struct vertex_buffer *VB )
{
   GLfloat *f;

   GLcontext *ctx = VB->ctx;
   GLmatrix *mat = &ctx->Viewport.WindowMap;
   tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
   tdfxVertexBufferPtr fxVB = TDFX_DRIVER_DATA(VB);
   GLfloat *first = fxVB->verts[VB->CopyStart].f;
   GLfloat *last = fxVB->verts[fxVB->last_vert].f;
   const GLubyte *mask = VB->ClipMask + VB->CopyStart;
   GLfloat m[16];

   m[MAT_SX] = mat->m[MAT_SX];
   m[MAT_TX] = mat->m[MAT_TX] + fxMesa->x_offset + TRI_X_OFFSET;
   m[MAT_SY] = mat->m[MAT_SY];
   m[MAT_TY] = mat->m[MAT_TY] + fxMesa->y_delta + TRI_Y_OFFSET;
   m[MAT_SZ] = mat->m[MAT_SZ];
   m[MAT_TZ] = mat->m[MAT_TZ];

   gl_project_clipped_v16( first, last, m, 16 * 4, mask );

   /* V3 at least requires texcoords to be multiplied by 1/w:
    */
   if ( TYPE & (TDFX_TEX0_BIT|TDFX_TEX1_BIT) ) {

      const GLfloat sScale0 = fxMesa->sScale0;
      const GLfloat tScale0 = fxMesa->tScale0;
      const GLfloat sScale1 = fxMesa->sScale1;
      const GLfloat tScale1 = fxMesa->tScale1;

      for ( f = first ; f != last ; f += 16, mask++) {
	 if (!*mask) {
	    const GLfloat oow = f[3];
	    if (TYPE & TDFX_TEX0_BIT) {
	       f[CLIP_S0] *= sScale0 * oow;
	       f[CLIP_T0] *= tScale0 * oow;
	    }

	    if (TYPE & TDFX_TEX1_BIT) {
	       f[CLIP_S1] *= sScale1 * oow;
	       f[CLIP_T1] *= tScale1 * oow;
	    }
	 }
      }
   }
}

static void TAG(tdfx_init_fastpath)( struct tdfx_fast_tab *tab )
{
   tab->build_vertices	= TAG(tdfx_setup_full);
   tab->interp		= TAG(tdfx_interp_vert);
   tab->project_vertices = TAG(tdfx_project_vertices);
   tab->project_clipped_vertices = TAG(tdfx_project_clipped_vertices);
}

#undef TYPE
#undef TAG
#undef SIZE