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
|
/**************************************************************************
Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
Copyright 2003 Eric Anholt
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
on 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
ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP 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$ */
/*
* Authors:
* Sung-Ching Lin <sclin@sis.com.tw>
* Eric Anholt <anholt@FreeBSD.org>
*/
#ifndef _sis_ctx_h_
#define _sis_ctx_h_
#include "context.h"
#include "dri_util.h"
#include "drm.h"
#include "drm_sarea.h"
#include "xmlconfig.h"
#include "tnl/t_vertex.h"
#include "sis_screen.h"
#include "sis_common2.h"
#include "sis_dri.h"
/* for GLboolean */
#include <GL/gl.h>
#define PCI_CHIP_SIS300 0x0300
#define PCI_CHIP_SIS630 0x6300
#define PCI_CHIP_SIS540 0x5300
#define NEW_TEXTURING 0x1
#define NEW_TEXTURE_ENV 0x2
/* Flags for software fallback cases:
*/
#define SIS_FALLBACK_TEXTURE 0x0001
#define SIS_FALLBACK_TEXTURE0 0x0002
#define SIS_FALLBACK_TEXTURE1 0x0004
#define SIS_FALLBACK_TEXENV0 0x0008
#define SIS_FALLBACK_TEXENV1 0x0010
#define SIS_FALLBACK_DRAW_BUFFER 0x0020
#define SIS_FALLBACK_STENCIL 0x0040
#define SIS_FALLBACK_FORCE 0x8000
/* Flags for hardware state that needs to be updated */
#define GFLAG_ENABLESETTING 0x00000001
#define GFLAG_ENABLESETTING2 0x00000002
#define GFLAG_ZSETTING 0x00000004
#define GFLAG_ALPHASETTING 0x00000008
#define GFLAG_DESTSETTING 0x00000010
#define GFLAG_LINESETTING 0x00000020
#define GFLAG_STENCILSETTING 0x00000040
#define GFLAG_FOGSETTING 0x00000080
#define GFLAG_DSTBLEND 0x00000100
#define GFLAG_CLIPPING 0x00000200
#define CFLAG_TEXTURERESET 0x00000400
#define GFLAG_TEXTUREMIPMAP 0x00000800
#define GFLAG_TEXBORDERCOLOR 0x00001000
#define GFLAG_TEXTUREADDRESS 0x00002000
#define GFLAG_TEXTUREENV 0x00004000
#define CFLAG_TEXTURERESET_1 0x00008000
#define GFLAG_TEXTUREMIPMAP_1 0x00010000
#define GFLAG_TEXBORDERCOLOR_1 0x00020000
#define GFLAG_TEXTUREADDRESS_1 0x00040000
#define GFLAG_TEXTUREENV_1 0x00080000
#define GFLAG_ALL 0x000fffff
#define GFLAG_TEXTURE_STATES (CFLAG_TEXTURERESET | GFLAG_TEXTUREMIPMAP | \
GFLAG_TEXBORDERCOLOR | GFLAG_TEXTUREADDRESS | \
CFLAG_TEXTURERESET_1 | GFLAG_TEXTUREMIPMAP_1 | \
GFLAG_TEXBORDERCOLOR_1 | \
GFLAG_TEXTUREADDRESS_1 | \
GFLAG_TEXTUREENV | GFLAG_TEXTUREENV_1)
#define GFLAG_RENDER_STATES (GFLAG_ENABLESETTING | GFLAG_ENABLESETTING2 | \
GFLAG_ZSETTING | GFLAG_ALPHASETTING | \
GFLAG_DESTSETTING | GFLAG_FOGSETTING | \
GFLAG_STENCILSETTING | GFLAG_DSTBLEND | \
GFLAG_CLIPPING)
/* Use the templated vertex format:
*/
#define TAG(x) sis##x
#include "tnl_dd/t_dd_vertex.h"
#undef TAG
/* Subpixel offsets for window coordinates (triangles):
*/
#define SUBPIXEL_X (-0.5F)
#define SUBPIXEL_Y (-0.5F)
#define SIS_MAX_TEXTURE_LEVELS 11
typedef struct {
GLubyte *Data; /* Pointer to texture in offscreen */
GLuint memType; /* VIDEO_TYPE or AGP_TYPE */
void *handle; /* Handle for sisFree*() */
GLuint pitch;
GLuint size;
} sisTexImage;
typedef struct sis_tex_obj {
sisTexImage image[SIS_MAX_TEXTURE_LEVELS]; /* Image data for each mipmap
* level */
GLenum format; /* One of GL_ALPHA, GL_INTENSITY, GL_LUMINANCE,
* GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA */
GLint hwformat; /* One of the TEXEL_ defines */
GLint numImages; /* Number of images loaded into .image */
} sisTexObj, *sisTexObjPtr;
/*
** Device dependent context state
*/
typedef struct __GLSiSTextureRec
{
GLint hwTextureSet;
GLint hwTextureMip;
GLint hwTextureClrHigh;
GLint hwTextureClrLow;
GLint hwTextureBorderColor;
GLint texOffset0;
GLint texOffset1;
GLint texOffset2;
GLint texOffset3;
GLint texOffset4;
GLint texOffset5;
GLint texOffset6;
GLint texOffset7;
GLint texOffset8;
GLint texOffset9;
GLint texOffset10;
GLint texOffset11;
GLint texPitch01;
GLint texPitch23;
GLint texPitch45;
GLint texPitch67;
GLint texPitch89;
GLint texPitch10;
} __GLSiSTexture;
typedef struct __GLSiSHardwareRec
{
GLint hwCapEnable, hwCapEnable2; /* Enable Setting */
GLint hwOffsetZ, hwZ; /* Z Setting */
GLint hwZBias, hwZMask; /* Z Setting */
GLint hwAlpha; /* Alpha Setting */
GLint hwDstSet, hwDstMask; /* Destination Setting */
GLint hwOffsetDest; /* Destination Setting */
GLint hwLinePattern; /* Line Setting */
GLint hwFog; /* Fog Setting */
GLint hwFogFar, hwFogInverse; /* Fog Distance setting */
GLint hwFogDensity; /* Fog factor & density */
GLint hwStSetting, hwStSetting2; /* Stencil Setting */
GLint hwStOffset; /* Stencil Setting */
GLint hwDstSrcBlend; /* Blending mode Setting */
GLint clipTopBottom; /* Clip for Top & Bottom */
GLint clipLeftRight; /* Clip for Left & Right */
struct __GLSiSTextureRec texture[2];
GLint hwTexEnvColor; /* Texture Blending Setting */
GLint hwTexBlendColor0;
GLint hwTexBlendColor1;
GLint hwTexBlendAlpha0;
GLint hwTexBlendAlpha1;
}
__GLSiSHardware;
typedef struct sis_context sisContextRec;
typedef struct sis_context *sisContextPtr;
typedef void (*sis_quad_func)( sisContextPtr,
sisVertex *,
sisVertex *,
sisVertex *,
sisVertex * );
typedef void (*sis_tri_func)( sisContextPtr,
sisVertex *,
sisVertex *,
sisVertex * );
typedef void (*sis_line_func)( sisContextPtr,
sisVertex *,
sisVertex * );
typedef void (*sis_point_func)( sisContextPtr,
sisVertex * );
/* Device dependent context state */
struct sis_context
{
/* This must be first in this structure */
GLcontext *glCtx;
/* Vertex state */
GLuint vertex_size;
struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
GLuint vertex_attr_count;
char *verts; /* points to tnl->clipspace.vertex_buf */
/* Vertex buffer (in system memory or AGP) state. */
unsigned char *vb; /* Beginning of vertex buffer */
unsigned char *vb_cur; /* Current write location in vertex buffer */
unsigned char *vb_last; /* Last written location in vertex buffer */
unsigned char *vb_end; /* End of vertex buffer */
void *vb_agp_handle;
GLuint vb_agp_offset;
GLboolean using_agp;
GLuint NewGLState;
GLuint Fallback;
GLuint RenderIndex;
GLfloat hw_viewport[16];
GLfloat depth_scale;
unsigned int virtualX, virtualY;
unsigned int bytesPerPixel;
unsigned char *IOBase;
unsigned char *FbBase;
unsigned int displayWidth;
unsigned int frontOffset;
unsigned int frontPitch;
/* HW RGBA layout */
unsigned int redMask, greenMask, blueMask, alphaMask;
unsigned int colorFormat;
/* Z format */
unsigned int zFormat;
/* Clear patterns, 4 bytes */
unsigned int clearColorPattern;
unsigned int clearZStencilPattern;
/* Fallback rasterization functions
*/
sis_point_func draw_point;
sis_line_func draw_line;
sis_tri_func draw_tri;
sis_quad_func draw_quad;
GLuint hw_primitive;
GLenum raster_primitive;
GLenum render_primitive;
/* DRM fd */
int driFd;
/* AGP Memory */
unsigned int AGPSize;
unsigned char *AGPBase;
unsigned int AGPAddr;
/* register 0x89F4 */
GLint AGPParseSet;
/* register 0x89F8 */
GLint dwPrimitiveSet;
__GLSiSHardware prev, current;
int Chipset;
GLint drawableID;
/* SGRAM block write */
GLboolean blockWrite;
GLint GlobalFlag;
GLuint last_tcl_state;
/* Stereo */
GLboolean useStereo;
GLboolean stereoEnabled;
int stereo_drawIndex;
int stereo_drawSide;
GLboolean irqEnabled;
GLboolean clearTexCache;
GLuint TexStates[SIS_MAX_TEXTURES];
GLuint PrevTexFormat[SIS_MAX_TEXTURES];
int *CurrentQueueLenPtr;
unsigned int *FrameCountPtr;
/* Front/back/depth buffer info */
GLuint width, height; /* size of buffers */
GLint bottom; /* used for FLIP macro */
GLvoid *backbuffer;
unsigned int backOffset;
unsigned int backPitch;
GLvoid *depthbuffer;
unsigned int depthOffset;
unsigned int depthPitch;
void *zbFree, *bbFree; /* Cookies for freeing buffers */
ENGPACKET zClearPacket, cbClearPacket;
/* Drawable, cliprect and scissor information
*/
GLint drawOffset, drawPitch;
GLint readOffset, readPitch;
/* Mirrors of some DRI state
*/
__DRIcontextPrivate *driContext; /* DRI context */
__DRIscreenPrivate *driScreen; /* DRI screen */
__DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
unsigned int lastStamp; /* mirror driDrawable->lastStamp */
drm_context_t hHWContext;
drm_hw_lock_t *driHwLock;
sisScreenPtr sisScreen; /* Screen private DRI data */
SISSAREAPrivPtr sarea; /* Private SAREA data */
/* Configuration cache */
driOptionCache optionCache;
};
#define SIS_CONTEXT(ctx) ((sisContextPtr)(ctx->DriverCtx))
/* Macros */
#define GET_IOBase(x) ((x)->IOBase)
#define Y_FLIP(Y) (smesa->bottom - (Y))
#define SISPACKCOLOR565( r, g, b ) \
((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
#define SISPACKCOLOR8888( r, g, b, a ) \
(((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
#define SIS_VERBOSE 0
#define MMIO(reg, value) \
{\
*(volatile GLint *)(smesa->IOBase + (reg)) = value; \
}
#define MMIO_READ(reg) *(volatile GLint *)(smesa->IOBase + (reg))
#define MMIO_READf(reg) *(volatile GLfloat *)(smesa->IOBase + (reg))
#define mEndPrimitive() \
{ \
*(volatile GLubyte *)(smesa->IOBase + REG_3D_EndPrimitiveList) = 0xff; \
*(volatile GLuint *)(smesa->IOBase + 0x8b60) = 0xffffffff; \
}
#define sis_fatal_error(msg) \
do { \
fprintf(stderr, "[%s:%d]: %s", __FILE__, __LINE__, msg); \
exit(-1); \
} while (0)
/* Lock required */
#define mWait3DCmdQueue(wLen) \
/* Update the mirrored queue pointer if it doesn't indicate enough space */ \
if (*(smesa->CurrentQueueLenPtr) < (wLen)) { \
*(smesa->CurrentQueueLenPtr) = \
(*(GLint *)(GET_IOBase(smesa) + REG_CommandQueue) & MASK_QueueLen) - 20; \
/* Spin and wait if the queue is actually too full */ \
if (*(smesa->CurrentQueueLenPtr) < (wLen)) \
WaitingFor3dIdle(smesa, wLen); \
*(smesa->CurrentQueueLenPtr) -= wLen; \
}
enum _sis_verbose {
VERBOSE_SIS_BUFFER = 0x1,
VERBOSE_SIS_MEMORY = 0x2
};
extern GLboolean sisCreateContext( const __GLcontextModes *glVisual,
__DRIcontextPrivate *driContextPriv,
void *sharedContextPrivate );
extern void sisDestroyContext( __DRIcontextPrivate * );
extern GLboolean sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
__DRIdrawablePrivate *driDrawPriv,
__DRIdrawablePrivate *driReadPriv );
extern GLboolean sisUnbindContext( __DRIcontextPrivate *driContextPriv );
void WaitEngIdle (sisContextPtr smesa);
void Wait2DEngIdle (sisContextPtr smesa);
void WaitingFor3dIdle(sisContextPtr smesa, int wLen);
/* update to hw */
extern void sis_update_texture_state( sisContextPtr smesa );
extern void sis_update_render_state( sisContextPtr smesa );
#endif
|