summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/mga/mgarender.c
blob: 6f406db2dac8e3a9ec4e8ac3922c003107485710 (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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include <stdio.h>
#include "mgadd.h"
#include "mgavb.h"
#include "mgadma.h"
#include "mgalib.h"
#include "mgatris.h"
#include "mgastate.h"
#include "xsmesaP.h"
#include "enums.h"

#define POINT(x) mga_draw_point(&gWin[x], psize)
#define LINE(x,y) mga_draw_line(&gWin[x], &gWin[y], lwidth)
#define TRI(x,y,z) mga_draw_triangle(&gWin[x], &gWin[y], &gWin[z])


/* Direct, and no clipping required.  I haven't written the clip funcs
 * yet, so this is only useful for the fast path, which does its own
 * clipping.
 */
#define RENDER_POINTS( start, count )		\
do {						\
   GLuint e;					\
   for(e=start;e<=count;e++)			\
     POINT(elt[e]);				\
} while (0)

#define RENDER_LINE( i1, i )			\
do {						\
   GLuint e1 = elt[i1], e = elt[i];		\
   LINE( e1, e );				\
} while (0)


#define RENDER_TRI( i2, i1, i, pv, parity)		\
do {							\
{  GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i];	\
  if (parity) {GLuint tmp = e2; e2 = e1; e1 = tmp;}	\
  TRI(e2, e1, e);					\
}} while (0)


#define RENDER_QUAD( i3, i2, i1, i, pv)				\
do {								\
  GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];	\
  TRI(e3, e2, e);						\
  TRI(e2, e1, e);						\
} while (0)

#define LOCAL_VARS					\
   mgaVertexPtr gWin = MGA_DRIVER_DATA(VB)->verts;	\
   const GLuint *elt = VB->EltPtr->data;		\
   const GLfloat lwidth = VB->ctx->Line.Width;		\
   const GLfloat psize = VB->ctx->Point.Size;		\
   GLcontext *ctx = VB->ctx; \
   (void) lwidth; (void)psize; (void)ctx; (void) gWin;


#define TAG(x) x##_mga_smooth_indirect
#include "render_tmp.h"




#define RENDER_POINTS( start, count )		\
do {						\
   GLuint e;					\
   for(e=start;e<=count;e++)			\
     POINT(e);					\
} while (0)

#define RENDER_LINE( i1, i )			\
do {						\
   LINE( i1, i );				\
} while (0)


#define RENDER_TRI( i2, i1, i, pv, parity)		\
do {							\
  GLuint e2 = i2, e1 = i1;				\
  if (parity) {GLuint tmp = e2; e2 = e1; e1 = tmp;}	\
  TRI(e2, e1, i);					\
} while (0)


#define RENDER_QUAD( i3, i2, i1, i, pv)		\
do {						\
  TRI(i3, i2, i);				\
  TRI(i2, i1, i);				\
} while (0)

#define LOCAL_VARS					\
   mgaVertexPtr gWin = MGA_DRIVER_DATA(VB)->verts;	\
   const GLfloat lwidth = VB->ctx->Line.Width;		\
   const GLfloat psize = VB->ctx->Point.Size;		\
   GLcontext *ctx = VB->ctx; \
   (void) lwidth; (void)psize; (void)ctx; (void) gWin;

#define TAG(x) x##_mga_smooth_direct
#include "render_tmp.h"





/* Vertex array rendering via. the SetupDma function - no clipping required. 
 */
#define RENDER_POINTS( start, count )		\
do {						\
    FatalError("Dead code in mgarender.c\n");	\
} while (0)

#define RENDER_LINE( i1, i )			\
do {						\
    FatalError("Dead code in mgarender.c\n");	\
} while (0)


#define RENDER_TRI( i2, i1, i, pv, parity)		\
do {							\
   GLuint e2 = elt[i2], e1 = elt[i1], e = elt[i];	\
   if (/*parity*/0) {GLuint tmp = e2; e2 = e1; e1 = tmp;}	\
   TRI(e2, e1, e);		\
} while (0)

#define RENDER_QUAD( i3, i2, i1, i, pv)				\
do {								\
  GLuint e3 = elt[i3], e2 = elt[i2], e1 = elt[i1], e = elt[i];	\
  TRI(e3, e2, e);			\
  TRI(e2, e1, e);			\
} while (0)

#define LOCAL_VARS					\
   mgaVertexBufferPtr mgaVB = MGA_DRIVER_DATA(VB);	\
   mgaUI32 phys = mgaVB->vert_phys_start;		\
   const GLuint *elt = VB->EltPtr->data;		\
   (void) phys; (void) elt;

#define PRESERVE_VB_DEFS
#undef TRI
#define VERT_ADDR_10( phys, elt ) ( phys + elt * 48 )
#define TRI( ee0, ee1, ee2 )				\
{							\
   mgaVB->elt_buf[0] = VERT_ADDR_10(phys, ee0);		\
   mgaVB->elt_buf[1] = VERT_ADDR_10(phys, ee1);		\
   mgaVB->elt_buf[2] = VERT_ADDR_10(phys, ee2);		\
   mgaVB->elt_buf += 3;					\
}
#define TAG(x) x##_mga_elt_10
#include "render_tmp.h"


#define TAG(x) x##_mga_elt_8
#undef TRI
#define VERT_ADDR_8( phys, elt ) ( phys + elt * 32 )
#define TRI( ee0, ee1, ee2 )			\
{						\
   mgaVB->elt_buf[0] = VERT_ADDR_8(phys, ee0);	\
   mgaVB->elt_buf[1] = VERT_ADDR_8(phys, ee1);	\
   mgaVB->elt_buf[2] = VERT_ADDR_8(phys, ee2);	\
   mgaVB->elt_buf += 3;				\
}
#include "render_tmp.h"




/* Currently only used on the fast path - need a set of render funcs
 * for clipped primitives.
 */
void mgaDDRenderElementsDirect( struct vertex_buffer *VB )
{
   mgaVertexBufferPtr mgaVB = MGA_DRIVER_DATA(VB);
   GLcontext *ctx = VB->ctx;
   mgaContextPtr mmesa = MGA_CONTEXT( ctx );
   GLenum prim = ctx->CVA.elt_mode;
   GLuint nr = VB->EltPtr->count;
   render_func func = render_tab_mga_smooth_indirect[prim];
   GLuint p = 0;
   mgaUI32 *start = mgaVB->elt_buf;
   
   struct vertex_buffer *saved_vb = ctx->VB;

   if (mmesa->new_state)
      mgaDDUpdateHwState( ctx );

   /* Are we using Setup DMA?
    */
   if (start) {
      switch (MGA_CONTEXT(ctx)->vertsize) {
      case 10:
	 func = render_tab_mga_elt_10[prim];
	 break;
      case 8:
	 func = render_tab_mga_elt_8[prim];
	 break;
      default:
      }
   }

   ctx->VB = VB;

   do {
      func( VB, 0, nr, 0 );
   } while (ctx->Driver.MultipassFunc &&
	    ctx->Driver.MultipassFunc( VB, ++p ));

   ctx->VB = saved_vb;


   if (start && nr) {
      if (0)
	 fprintf(stderr, "%d/%d elts\n", nr, mgaVB->elt_buf-start);
      mgaSetupDma( start, mgaVB->elt_buf - start );
      mgaVB->elt_buf = mgaVB->vert_buf = 0;
   }
}


void mgaDDRenderElementsImmediate( struct vertex_buffer *VB )
{
   GLcontext *ctx = VB->ctx;
   mgaContextPtr mmesa = MGA_CONTEXT( ctx );
   GLuint nr = VB->EltPtr->count;
   render_func *tab = render_tab_mga_smooth_indirect;
   GLuint parity = VB->Parity;
   GLuint p = 0;
   GLuint i, next;

   if (mmesa->new_state)
      mgaDDUpdateHwState( ctx );

   do {
      for ( i= VB->CopyStart ; i < nr ; parity = 0, i = next ) 
      {
	 GLenum prim = VB->Primitive[i];
	 next = VB->NextPrimitive[i];
	 tab[prim]( VB, i, next, parity );
      }
   } while (ctx->Driver.MultipassFunc &&
	    ctx->Driver.MultipassFunc( VB, ++p ));
}


void mgaDDRenderDirect( struct vertex_buffer *VB )
{
   GLcontext *ctx = VB->ctx;
   mgaContextPtr mmesa = MGA_CONTEXT( ctx );
   GLuint nr = VB->Count;
   render_func *tab = render_tab_mga_smooth_direct;
   GLuint parity = VB->Parity;
   GLuint p = 0;
   GLuint i, next;

   if (mmesa->new_state)
      mgaDDUpdateHwState( ctx );

   do {
      for ( i= VB->CopyStart ; i < nr ; parity = 0, i = next ) 
      {
	 GLenum prim = VB->Primitive[i];
	 next = VB->NextPrimitive[i];
	 tab[prim]( VB, i, next, parity );
      }
   } while (ctx->Driver.MultipassFunc &&
	    ctx->Driver.MultipassFunc( VB, ++p ));
}


static void optimized_render_vb_triangle_mga_smooth_indirect(struct vertex_buffer *VB,
							    GLuint start,
							    GLuint count,
							    GLuint parity)
{
   mgaVertexPtr gWin = MGA_DRIVER_DATA(VB)->verts;
   const GLuint *elt = VB->EltPtr->data;
   GLcontext *ctx = VB->ctx;
   mgaContextPtr mmesa = MGA_CONTEXT( ctx );

   mgaUI32 vertsize = mmesa->vertsize;

   /* We know how many dwords we need so we can allocate all of it
    * in one call */
   mgaUI32 *wv = mgaAllocSecondaryBuffer( count * vertsize );

   int vertex;

   (void)ctx; (void) gWin; (void) parity;


   for(vertex=start+2;vertex<count;vertex+=3){
      GLuint e2=elt[vertex-2],e1=elt[vertex-1],e=elt[vertex];
      mgaUI32 *src;

      int j;

      if(parity){
         GLuint tmp=e2;
         e2=e1;
	 e1=tmp;
      }

      src=&gWin[e2].ui[0];
      
      for(j=vertsize;j;j--){
	 *wv++=*src++;
      }
      
      src=&gWin[e1].ui[0];
      for(j=vertsize;j;j--){
	 *wv++=*src++;
      }
      
      src=&gWin[e].ui[0];
      for(j=vertsize;j;j--){
	 *wv++=*src++;
      }
   }
   
}


void mgaDDRenderInit()
{

   render_init_mga_smooth_indirect();
   render_init_mga_smooth_direct();
   render_init_mga_elt_10();
   render_init_mga_elt_8();
   
   render_tab_mga_smooth_indirect[GL_TRIANGLES] =
      optimized_render_vb_triangle_mga_smooth_indirect; 
}