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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
/**************************************************************************
Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
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, sub license, 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 NON-INFRINGEMENT.
IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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: xc/lib/GL/mesa/src/drv/sis/sis_render.c,v 1.5 2000/09/26 15:56:49 tsi Exp $ */
/*
* Authors:
* Sung-Ching Lin <sclin@sis.com.tw>
*
*/
#include "sis_ctx.h"
#include "sis_mesa.h"
#define SIS_SMOOTH 0x1
#define SIS_USE_W 0x2
#define SIS_TEXTURE0 0x4
#define SIS_TEXTURE1 0x8
#define SIS_TRI_OFFSET 0x10
#define SIS_USE_Z 0x11
#define SIS_FALLBACK 0x80000000
#define SIS_DEPTH_SCALE 1.0
/*
* TODO: assert(hwcx->AGPCmdBufSize % AGP_ALLOC_SIZE == 0)
* depends on VB_SIZE is better
*/
#define AGP_ALLOC_SIZE 0x10000
/* #define AGP_ALLOC_SIZE (VB_SIZE/3*4 * 9) */
static DWORD AGP_EngineOffset;
static DWORD *AGP_StartPtr;
/* export to sis_fastpath.c */
float *AGP_CurrentPtr;
#define SIS_TAG(x) x##_flat
#define SIS_STATES (0)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth
#define SIS_STATES (SIS_SMOOTH)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_w
#define SIS_STATES (SIS_USE_W)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_w
#define SIS_STATES (SIS_SMOOTH | SIS_USE_W)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_t0
#define SIS_STATES (SIS_TEXTURE0)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_t0
#define SIS_STATES (SIS_SMOOTH | SIS_TEXTURE0)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_w_t0
#define SIS_STATES (SIS_USE_W | SIS_TEXTURE0)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_w_t0
#define SIS_STATES (SIS_SMOOTH | SIS_USE_W | SIS_TEXTURE0)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_t1
#define SIS_STATES (SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_t1
#define SIS_STATES (SIS_SMOOTH | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_w_t1
#define SIS_STATES (SIS_USE_W | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_w_t1
#define SIS_STATES (SIS_SMOOTH | SIS_USE_W | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_t2
#define SIS_STATES (SIS_TEXTURE0 | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_t2
#define SIS_STATES (SIS_SMOOTH | SIS_TEXTURE0 | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_flat_w_t2
#define SIS_STATES (SIS_USE_W | SIS_TEXTURE0 | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
#define SIS_TAG(x) x##_smooth_w_t2
#define SIS_STATES (SIS_SMOOTH | SIS_USE_W | SIS_TEXTURE0 | SIS_TEXTURE1)
#include "sis_linefunc.h"
#include "sis_trifunc.h"
static line_func sis_draw_line_func[32] = {
sis_line_flat,
sis_line_smooth,
sis_line_flat_w,
sis_line_smooth_w,
sis_line_flat_t0,
sis_line_smooth_t0,
sis_line_flat_w_t0,
sis_line_smooth_w_t0,
sis_line_flat_t1,
sis_line_smooth_t1,
sis_line_flat_w_t1,
sis_line_smooth_w_t1,
sis_line_flat_t2,
sis_line_smooth_t2,
sis_line_flat_w_t2,
sis_line_smooth_w_t2,
};
static line_func sis_agp_draw_line_func[32] = {
sis_agp_line_flat,
sis_agp_line_smooth,
sis_agp_line_flat_w,
sis_agp_line_smooth_w,
sis_agp_line_flat_t0,
sis_agp_line_smooth_t0,
sis_agp_line_flat_w_t0,
sis_agp_line_smooth_w_t0,
sis_agp_line_flat_t1,
sis_agp_line_smooth_t1,
sis_agp_line_flat_w_t1,
sis_agp_line_smooth_w_t1,
sis_agp_line_flat_t2,
sis_agp_line_smooth_t2,
sis_agp_line_flat_w_t2,
sis_agp_line_smooth_w_t2,
};
/* TODO: get another path if not clipped */
static void
sis_line_clip (GLcontext * ctx, GLuint vert0, GLuint vert1, GLuint pv)
{
XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
__GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private;
BoxPtr pExtents;
int count;
GLuint x, y;
sis_get_drawable_origin (xmesa, &x, &y);
sis_get_clip_rects (xmesa, &pExtents, &count);
while (count--)
{
DWORD clipTopBottom, clipLeftRight;
clipTopBottom = ((pExtents->y1 - y) << 13) | (pExtents->y2 - y - 1);
clipLeftRight = ((pExtents->x1 - x) << 13) | (pExtents->x2 - x - 1);
mWait3DCmdQueue (5);
MMIO (REG_3D_ClipTopBottom, clipTopBottom);
MMIO (REG_3D_ClipLeftRight, clipLeftRight);
(hwcx->LineFunc) (ctx, vert0, vert1, pv);
mEndPrimitive ();
pExtents++;
}
hwcx->GlobalFlag |= GFLAG_CLIPPING;
}
static triangle_func sis_fill_triangle_func[32] = {
sis_tri_flat,
sis_tri_smooth,
sis_tri_flat_w,
sis_tri_smooth_w,
sis_tri_flat_t0,
sis_tri_smooth_t0,
sis_tri_flat_w_t0,
sis_tri_smooth_w_t0,
sis_tri_flat_t1,
sis_tri_smooth_t1,
sis_tri_flat_w_t1,
sis_tri_smooth_w_t1,
sis_tri_flat_t2,
sis_tri_smooth_t2,
sis_tri_flat_w_t2,
sis_tri_smooth_w_t2,
};
static triangle_func sis_agp_fill_triangle_func[32] = {
sis_agp_tri_flat,
sis_agp_tri_smooth,
sis_agp_tri_flat_w,
sis_agp_tri_smooth_w,
sis_agp_tri_flat_t0,
sis_agp_tri_smooth_t0,
sis_agp_tri_flat_w_t0,
sis_agp_tri_smooth_w_t0,
sis_agp_tri_flat_t1,
sis_agp_tri_smooth_t1,
sis_agp_tri_flat_w_t1,
sis_agp_tri_smooth_w_t1,
sis_agp_tri_flat_t2,
sis_agp_tri_smooth_t2,
sis_agp_tri_flat_w_t2,
sis_agp_tri_smooth_w_t2,
};
#define USE_XYZ 0x08000000
#define USE_W 0x04000000
#define USE_RGB 0x01000000
#define USE_UV1 0x00400000
#define USE_UV2 0x00200000
#define USE_FLAT 0x0001000
#define USE_SMOOTH 0x0004000
static DWORD AGPParsingValues[32] = {
(4 << 28) | USE_XYZ | USE_RGB | USE_FLAT,
(4 << 28) | USE_XYZ | USE_RGB | USE_SMOOTH,
(5 << 28) | USE_XYZ | USE_W | USE_RGB | USE_FLAT,
(5 << 28) | USE_XYZ | USE_W | USE_RGB | USE_SMOOTH,
(6 << 28) | USE_XYZ | USE_RGB | USE_UV1 | USE_FLAT,
(6 << 28) | USE_XYZ | USE_RGB | USE_UV1 | USE_SMOOTH,
(7 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV1 | USE_FLAT,
(7 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV1 | USE_SMOOTH,
(6 << 28) | USE_XYZ | USE_RGB | USE_UV2 | USE_FLAT,
(6 << 28) | USE_XYZ | USE_RGB | USE_UV2 | USE_SMOOTH,
(7 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV2 | USE_FLAT,
(7 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV2 | USE_SMOOTH,
(8 << 28) | USE_XYZ | USE_RGB | USE_UV1 | USE_UV2 | USE_FLAT,
(8 << 28) | USE_XYZ | USE_RGB | USE_UV1 | USE_UV2 | USE_SMOOTH,
(9 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV1 | USE_UV2 | USE_FLAT,
(9 << 28) | USE_XYZ | USE_W | USE_RGB | USE_UV1 | USE_UV2 | USE_SMOOTH,
};
static void
sis_tri_clip (GLcontext * ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv)
{
XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
__GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private;
BoxPtr pExtents;
int count;
GLuint x, y;
sis_get_drawable_origin (xmesa, &x, &y);
sis_get_clip_rects (xmesa, &pExtents, &count);
while (count--)
{
DWORD clipTopBottom, clipLeftRight;
clipTopBottom = ((pExtents->y1 - y) << 13) | (pExtents->y2 - y - 1);
clipLeftRight = ((pExtents->x1 - x) << 13) | (pExtents->x2 - x - 1);
mWait3DCmdQueue (5);
MMIO (REG_3D_ClipTopBottom, clipTopBottom);
MMIO (REG_3D_ClipLeftRight, clipLeftRight);
(hwcx->TriangleFunc) (ctx, v0, v1, v2, pv);
mEndPrimitive ();
pExtents++;
}
hwcx->GlobalFlag |= GFLAG_CLIPPING;
}
void
sis_set_render_func (GLcontext * ctx)
{
XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
__GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private;
GLuint caps = ctx->TriangleCaps;
int line_index = 0;
int tri_index = 0;
if(hwcx->swForceRender){
ctx->Driver.LineFunc = NULL;
ctx->Driver.TriangleFunc = NULL;
return;
}
ctx->IndirectTriangles &= ~(DD_LINE_SW_RASTERIZE | DD_TRI_SW_RASTERIZE);
hwcx->swRenderFlag &= ~(SIS_SW_POINT | SIS_SW_LINE | SIS_SW_TRIANGLE);
/*
* TODO: Mesa 3.3 will set ctx->TriangleCaps to DD_SELECT
*/
#if 0
if ((caps & (DD_SELECT | DD_FEEDBACK))
/* Fixme */
|| (ctx->Texture.ReallyEnabled & (TEXTURE0_3D | TEXTURE1_3D)))
{
line_index |= SIS_FALLBACK;
tri_index |= SIS_FALLBACK;
}
#endif
/* always set */
hwcx->swRenderFlag |= SIS_SW_POINT;
if ((caps & DD_LINE_STIPPLE) || (caps & DD_LINE_WIDTH))
{
line_index |= SIS_FALLBACK;
hwcx->swRenderFlag |= SIS_SW_LINE;
}
if ((caps & DD_TRI_STIPPLE))
{
tri_index |= SIS_FALLBACK;
hwcx->swRenderFlag |= SIS_SW_TRIANGLE;
}
if (ctx->Light.ShadeModel == GL_SMOOTH)
{
line_index |= SIS_SMOOTH;
tri_index |= SIS_SMOOTH;
}
if (ctx->RasterMask & FOG_BIT)
{
line_index |= SIS_USE_W;
tri_index |= SIS_USE_W;
}
if (ctx->Texture.ReallyEnabled)
{
line_index |= SIS_USE_W;
tri_index |= SIS_USE_W;
if (ctx->Texture.ReallyEnabled & TEXTURE0_ANY)
{
line_index |= SIS_TEXTURE0;
tri_index |= SIS_TEXTURE0;
}
if (ctx->Texture.ReallyEnabled & TEXTURE1_ANY)
{
line_index |= SIS_TEXTURE1;
tri_index |= SIS_TEXTURE1;
}
}
/* TODO, use Pick */
hwcx->UseAGPCmdMode = GL_FALSE;
if (line_index & SIS_FALLBACK)
{
ctx->IndirectTriangles |= DD_LINE_SW_RASTERIZE;
hwcx->LineFunc = NULL;
}
else
{
if ((ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) &&
sis_is_window (xmesa))
{
hwcx->LineFunc = sis_draw_line_func[line_index];
ctx->Driver.LineFunc = sis_line_clip;
}
else
{
if (hwcx->AGPCmdModeEnabled)
{
ctx->Driver.LineFunc = sis_agp_draw_line_func[line_index];
hwcx->UseAGPCmdMode = GL_TRUE;
}
else
{
ctx->Driver.LineFunc = sis_draw_line_func[line_index];
}
}
}
if (tri_index & SIS_FALLBACK)
{
ctx->IndirectTriangles |= DD_TRI_SW_RASTERIZE;
hwcx->TriangleFunc = NULL;
}
else
{
if ((ctx->Color.DriverDrawBuffer == GL_FRONT_LEFT) &&
sis_is_window (xmesa))
{
hwcx->TriangleFunc = sis_fill_triangle_func[tri_index];
ctx->Driver.TriangleFunc = sis_tri_clip;
}
else
{
if (hwcx->AGPCmdModeEnabled)
{
ctx->Driver.TriangleFunc = sis_agp_fill_triangle_func[tri_index];
hwcx->UseAGPCmdMode = GL_TRUE;
}
else
{
ctx->Driver.TriangleFunc = sis_fill_triangle_func[tri_index];
}
}
}
/* fast path */
if(!(ctx->TriangleCaps & (DD_TRI_UNFILLED | DD_TRI_LIGHT_TWOSIDE)) &&
(ctx->Driver.TriangleFunc == sis_agp_tri_smooth_w_t2) &&
(ctx->Color.DriverDrawBuffer == GL_BACK_LEFT)){
hwcx->useFastPath = GL_TRUE;
}
else{
hwcx->useFastPath = GL_FALSE;
}
/* TODO: AGP and MMIO use different sis_set_render_state */
hwcx->AGPParseSet &= ~0xffff7000;
hwcx->AGPParseSet |= AGPParsingValues[line_index & ~SIS_FALLBACK];
/* Debug, test sw-render
ctx->Driver.LineFunc = NULL;
ctx->Driver.TriangleFunc = NULL;
hwcx->swRenderFlag = ~0x0;
ctx->Visual->DepthMax = (sizeof(GLdepth)==2)?0xffff:0xffffffff;
ctx->Visual->DepthMaxF = (double)(sizeof(GLdepth)==2)?0xffff:0xffffffff;
*/
}
void
sis_StartAGP (GLcontext * ctx)
{
XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
__GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private;
DWORD start, end;
start = *(hwcx->pAGPCmdBufNext);
end = start + AGP_ALLOC_SIZE;
if (end >= hwcx->AGPCmdBufSize)
{
start = 0;
end = AGP_ALLOC_SIZE;
}
/*
* TODO: use AGP_EngineOffset to get a safe value and not query current
* postion processed every time
* ?? use < instead of <=
*/
do
{
AGP_EngineOffset =
*(DWORD volatile *) (GET_IOBase (hwcx) + REG_3D_AGPCmBase) -
(DWORD) hwcx->AGPCmdBufAddr;
}
while ((AGP_EngineOffset <= end) && (AGP_EngineOffset >= start)
&& ((*(GET_IOBase (hwcx) + 0x8243) & 0xe0) != 0xe0));
AGP_StartPtr = (DWORD *) (start + hwcx->AGPCmdBufBase);
AGP_CurrentPtr = (float *) AGP_StartPtr;
}
void
sis_FlushAGP (GLcontext * ctx)
{
XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
__GLSiScontext *hwcx = (__GLSiScontext *) xmesa->private;
/* TODO: wait queue length */
if((DWORD *)AGP_CurrentPtr == AGP_StartPtr)
{
return;
}
mWait3DCmdQueue (5);
mEndPrimitive ();
MMIO (REG_3D_AGPCmBase, ((DWORD) AGP_StartPtr - (DWORD) hwcx->AGPCmdBufBase)
+ (DWORD) hwcx->AGPCmdBufAddr);
MMIO (REG_3D_AGPTtDwNum,
(((DWORD) AGP_CurrentPtr - (DWORD) AGP_StartPtr) >> 2) | 0x50000000);
MMIO (REG_3D_ParsingSet, hwcx->AGPParseSet);
MMIO (REG_3D_AGPCmFire, (DWORD) (-1));
mEndPrimitive ();
*(hwcx->pAGPCmdBufNext) =
(DWORD) AGP_CurrentPtr - (DWORD) hwcx->AGPCmdBufBase;
*(hwcx->pAGPCmdBufNext) = (*(hwcx->pAGPCmdBufNext) + 0xf) & ~0xf;
}
|