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
|
/*
* Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2003 S3 Graphics, Inc. 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
* VIA, S3 GRAPHICS, 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.
*/
#ifndef _VIACONTEXT_H
#define _VIACONTEXT_H
typedef struct via_context_t viaContext;
typedef struct via_context_t *viaContextPtr;
typedef struct via_texture_object_t *viaTextureObjectPtr;
#include "dri_util.h"
#include "mtypes.h"
#include "drm.h"
#include "mm.h"
#include "via_screen.h"
#include "via_tex.h"
#include "via_common.h"
#include "xf86drmVIA.h"
#define VIA_FALLBACK_TEXTURE 0x1
#define VIA_FALLBACK_DRAW_BUFFER 0x2
#define VIA_FALLBACK_READ_BUFFER 0x4
#define VIA_FALLBACK_COLORMASK 0x8
#define VIA_FALLBACK_SPECULAR 0x20
#define VIA_FALLBACK_LOGICOP 0x40
#define VIA_FALLBACK_RENDERMODE 0x80
#define VIA_FALLBACK_STENCIL 0x100
#define VIA_FALLBACK_BLEND_EQ 0x200
#define VIA_FALLBACK_BLEND_FUNC 0x400
#define VIA_FALLBACK_USER_DISABLE 0x800
#define VIA_DMA_BUFSIZ 5000
#define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 256)
#define VIA_NO_CLIPRECTS 0x1
/* Use the templated vertex formats:
*/
#define TAG(x) via##x
#include "tnl_dd/t_dd_vertex.h"
#undef TAG
typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
viaVertex *);
typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
typedef void (*via_point_func)(viaContextPtr, viaVertex *);
typedef struct {
drm_handle_t handle;
drmSize size;
GLuint offset;
GLuint index;
GLuint pitch;
GLuint bpp;
char *map;
GLuint orig; /* The drawing origin,
* at (drawX,drawY) in screen space.
*/
char *origMap;
} viaBuffer, *viaBufferPtr;
struct via_context_t {
GLint refcount;
GLcontext *glCtx;
GLcontext *shareCtx;
viaBuffer front;
viaBuffer back;
viaBuffer depth;
GLboolean hasBack;
GLboolean hasDepth;
GLboolean hasStencil;
GLboolean hasAccum;
GLuint depthBits;
GLuint stencilBits;
GLboolean have_hw_stencil;
GLuint ClearDepth;
GLuint depth_clear_mask;
GLuint stencil_clear_mask;
GLfloat depth_max;
GLubyte *dma;
viaRegion tex;
GLuint isAGP;
/* Textures
*/
viaTextureObjectPtr CurrentTexObj[2];
struct via_texture_object_t TexObjList;
struct via_texture_object_t SwappedOut;
memHeap_t *texHeap;
/* Bit flag to keep 0track of fallbacks.
*/
GLuint Fallback;
/* State for via_vb.c and via_tris.c.
*/
GLuint newState; /* _NEW_* flags */
GLuint setupNewInputs;
GLuint setupIndex;
GLuint renderIndex;
GLmatrix ViewportMatrix;
GLenum renderPrimitive;
GLenum hwPrimitive;
unsigned char *verts;
/* drmBufPtr dma_buffer;
*/
GLuint dmaLow;
GLuint dmaCliprectAddr;
GLuint dmaLastPrim;
GLboolean useAgp;
/* Fallback rasterization functions
*/
via_point_func drawPoint;
via_line_func drawLine;
via_tri_func drawTri;
/* Hardware register
*/
GLuint regCmdA;
GLuint regCmdA_End;
GLuint regCmdB;
GLuint regEnable;
GLuint regHFBBMSKL;
GLuint regHROP;
GLuint regHZWTMD;
GLuint regHSTREF;
GLuint regHSTMD;
GLuint regHATMD;
GLuint regHABLCsat;
GLuint regHABLCop;
GLuint regHABLAsat;
GLuint regHABLAop;
GLuint regHABLRCa;
GLuint regHABLRFCa;
GLuint regHABLRCbias;
GLuint regHABLRCb;
GLuint regHABLRFCb;
GLuint regHABLRAa;
GLuint regHABLRAb;
GLuint regHFogLF;
GLuint regHFogCL;
GLuint regHFogCH;
GLuint regHLP;
GLuint regHLPRF;
GLuint regHTXnTB_0;
GLuint regHTXnMPMD_0;
GLuint regHTXnTBLCsat_0;
GLuint regHTXnTBLCop_0;
GLuint regHTXnTBLMPfog_0;
GLuint regHTXnTBLAsat_0;
GLuint regHTXnTBLRCb_0;
GLuint regHTXnTBLRAa_0;
GLuint regHTXnTBLRFog_0;
/*=* John Sheng [2003.7.18] texture combine *=*/
GLuint regHTXnTBLRCa_0;
GLuint regHTXnTBLRCc_0;
GLuint regHTXnTBLRCbias_0;
GLuint regHTXnTB_1;
GLuint regHTXnMPMD_1;
GLuint regHTXnTBLCsat_1;
GLuint regHTXnTBLCop_1;
GLuint regHTXnTBLMPfog_1;
GLuint regHTXnTBLAsat_1;
GLuint regHTXnTBLRCb_1;
GLuint regHTXnTBLRAa_1;
GLuint regHTXnTBLRFog_1;
/* Hardware state
*/
GLuint dirty;
int vertexSize;
int vertexFormat;
GLint lastStamp;
GLenum TexEnvImageFmt[2];
GLuint ClearColor;
/* DRI stuff
*/
GLuint needClip;
GLframebuffer *glBuffer;
GLboolean doPageFlip;
/*=* John Sheng [2003.5.31] flip *=*/
GLuint currentPage;
viaBuffer *drawBuffer;
viaBuffer *readBuffer;
int drawX; /* origin of drawable in draw buffer */
int drawY;
int drawW;
int drawH;
int drawXoff;
GLuint numClipRects; /* cliprects for that buffer */
drm_clip_rect_t *pClipRects;
int lastSwap;
int texAge;
int ctxAge;
int dirtyAge;
GLboolean scissor;
drm_clip_rect_t drawRect;
drm_clip_rect_t scissorRect;
drm_context_t hHWContext;
drm_hw_lock_t *driHwLock;
int driFd;
__DRInativeDisplay *display;
__DRIdrawablePrivate *driDrawable;
__DRIscreenPrivate *driScreen;
viaScreenPrivate *viaScreen;
drm_via_sarea_t *sarea;
volatile GLuint* regMMIOBase;
volatile GLuint* pnGEMode;
volatile GLuint* regEngineStatus;
volatile GLuint* regTranSet;
volatile GLuint* regTranSpace;
GLuint* agpBase;
GLuint drawType;
GLuint nDoneFirstFlip;
GLuint agpFullCount;
/* Configuration cache
*/
driOptionCache optionCache;
GLuint vblank_flags;
GLuint vbl_seq;
int64_t swap_ust;
int64_t swap_missed_ust;
GLuint swap_count;
GLuint swap_missed_count;
PFNGLXGETUSTPROC get_ust;
};
#define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
#define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
#define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
/* Lock the hardware and validate our state.
*/
#define LOCK_HARDWARE(vmesa) \
do { \
char __ret = 0; \
DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
(DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
if (__ret) \
viaGetLock(vmesa, 0); \
} while (0)
/* Release the kernel lock.
*/
#define UNLOCK_HARDWARE(vmesa) \
DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
#define WAIT_IDLE(vmesa) \
do { \
if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
break; \
} while (1)
#ifdef DEBUG
extern GLuint VIA_DEBUG;
#else
#define VIA_DEBUG 0
#endif
extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
extern void viaLock(viaContextPtr vmesa, GLuint flags);
extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
extern void viaEmitHwStateLocked(viaContextPtr vmesa);
extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
extern void viaXMesaWindowMoved(viaContextPtr vmesa);
extern void viaTexCombineState(viaContextPtr vmesa,
const struct gl_tex_env_combine_state * combine, unsigned unit );
/* Via hw already adjusted for GL pixel centers:
*/
#define SUBPIXEL_X 0
#define SUBPIXEL_Y 0
/* TODO XXX _SOLO temp defines to make code compilable */
#ifndef GLX_PBUFFER_BIT
#define GLX_PBUFFER_BIT 0x00000004
#endif
#ifndef GLX_WINDOW_BIT
#define GLX_WINDOW_BIT 0x00000001
#endif
#ifndef VERT_BIT_CLIP
#define VERT_BIT_CLIP 0x1000000
#endif
#endif
|