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
|
/**************************************************************************
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
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.
**************************************************************************/
/*
* Authors:
* Keith Whitwell <keithw@precisioninsight.com>
*
*/
#ifdef GLX_DIRECT_RENDERING
#include <X11/Xlibint.h>
#include <stdio.h>
#include "drm.h"
#include "mga_xmesa.h"
#include "context.h"
#include "vbxform.h"
#include "matrix.h"
#include "mmath.h"
#include "simple_list.h"
#include "mgadd.h"
#include "mgastate.h"
#include "mgatex.h"
#include "mgaspan.h"
#include "mgadepth.h"
#include "mgatris.h"
#include "mgapipeline.h"
#include "mgabuffers.h"
#include "xf86dri.h"
#include "mga_xmesa.h"
#include "mga_dri.h"
#ifndef MGA_DEBUG
int MGA_DEBUG = (0
/* | DEBUG_ALWAYS_SYNC */
/* | DEBUG_VERBOSE_MSG */
/* | DEBUG_VERBOSE_LRU */
/* | DEBUG_VERBOSE_DRI */
/* | DEBUG_VERBOSE_IOCTL */
/* | DEBUG_VERBOSE_2D */
);
#endif
static mgaContextPtr mgaCtx = 0;
mgaGlx_t mgaglx;
/* These functions are accessed externally to the driver:
*
* XMesaInitDriver
* XMesaResetDriver
* XMesaCreateVisual
* XMesaDestroyVisual
* XMesaCreateContext
* XMesaDestroyContext
* XMesaCreateWindowBuffer
* XMesaCreatePixmapBuffer
* XMesaDestroyBuffer
* XMesaSwapBuffers
* XMesaMakeCurrent
*
*/
GLboolean XMesaInitDriver(__DRIscreenPrivate *sPriv)
{
mgaScreenPrivate *mgaScreen;
MGADRIPtr serverInfo = (MGADRIPtr)sPriv->pDevPriv;
/* Allocate the private area */
mgaScreen = (mgaScreenPrivate *)Xmalloc(sizeof(mgaScreenPrivate));
if (!mgaScreen) return GL_FALSE;
mgaScreen->sPriv = sPriv;
sPriv->private = (void *)mgaScreen;
/*
fprintf(stderr, "serverInfo->chipset: %d\n", serverInfo->chipset);
*/
if (serverInfo->chipset != MGA_CARD_TYPE_G200 &&
serverInfo->chipset != MGA_CARD_TYPE_G400)
return GL_FALSE;
mgaScreen->chipset = serverInfo->chipset;
mgaScreen->width = serverInfo->width;
mgaScreen->height = serverInfo->height;
mgaScreen->mem = serverInfo->mem;
mgaScreen->cpp = serverInfo->cpp;
mgaScreen->frontPitch = serverInfo->frontPitch;
mgaScreen->frontOffset = serverInfo->frontOffset;
mgaScreen->backOffset = serverInfo->backOffset;
mgaScreen->backPitch = serverInfo->backPitch;
mgaScreen->depthOffset = serverInfo->depthOffset;
mgaScreen->depthPitch = serverInfo->depthPitch;
mgaScreen->agp.handle = serverInfo->agp;
mgaScreen->agp.size = serverInfo->agpSize;
if (drmMap(sPriv->fd,
mgaScreen->agp.handle,
mgaScreen->agp.size,
(drmAddress *)&mgaScreen->agp.map) != 0)
{
Xfree(mgaScreen);
return GL_FALSE;
}
mgaScreen->textureOffset[MGA_CARD_HEAP] = serverInfo->textureOffset;
mgaScreen->textureOffset[MGA_AGP_HEAP] = (serverInfo->agpTextureOffset |
PDEA_pagpxfer_enable | 1);
/*
fprintf(stderr, "CARD texture size %x, granul %d --> %x\n",
serverInfo->textureSize, serverInfo->logTextureGranularity,
1<<serverInfo->logTextureGranularity);
*/
mgaScreen->textureSize[MGA_CARD_HEAP] = serverInfo->textureSize;
mgaScreen->textureSize[MGA_AGP_HEAP] = serverInfo->agpTextureSize;
mgaScreen->logTextureGranularity[MGA_CARD_HEAP] =
serverInfo->logTextureGranularity;
mgaScreen->logTextureGranularity[MGA_AGP_HEAP] =
serverInfo->logAgpTextureGranularity;
mgaScreen->texVirtual[MGA_CARD_HEAP] = (mgaScreen->sPriv->pFB +
serverInfo->textureOffset);
mgaScreen->texVirtual[MGA_AGP_HEAP] = (mgaScreen->agp.map +
serverInfo->agpTextureOffset);
mgaScreen->mAccess = serverInfo->mAccess;
/* For calculating setupdma addresses.
*/
mgaScreen->dmaOffset = serverInfo->agpBufferOffset;
/*
fprintf(stderr, "\n\n\nbackOffset: %x pitch %x\n",
mgaScreen->backOffset,
mgaScreen->backPitch);
*/
mgaScreen->Attrib = MGA_PF_565;
mgaScreen->bufs = drmMapBufs(sPriv->fd);
/* Other mgaglx stuff, too??
*/
memset(&mgaglx, 0, sizeof(mgaglx));
mgaDDFastPathInit();
mgaDDEltPathInit();
mgaDDTrifuncInit();
mgaDDSetupInit();
return GL_TRUE;
}
/* Accessed by dlsym from dri_mesa_init.c
*/
void XMesaResetDriver(__DRIscreenPrivate *sPriv)
{
Xfree(sPriv->private);
}
GLvisual *XMesaCreateVisual(Display *dpy,
__DRIscreenPrivate *driScrnPriv,
const XVisualInfo *visinfo,
const __GLXvisualConfig *config)
{
/* Drivers may change the args to _mesa_create_visual() in order to
* setup special visuals.
*/
return _mesa_create_visual( config->rgba,
config->doubleBuffer,
config->stereo,
_mesa_bitcount(visinfo->red_mask),
_mesa_bitcount(visinfo->green_mask),
_mesa_bitcount(visinfo->blue_mask),
config->alphaSize,
0, /* index bits */
config->depthSize,
config->stencilSize,
config->accumRedSize,
config->accumGreenSize,
config->accumBlueSize,
config->accumAlphaSize,
0 /* num samples */ );
}
GLboolean XMesaCreateContext( Display *dpy, GLvisual *mesaVis,
__DRIcontextPrivate *driContextPriv )
{
int i;
GLcontext *ctx;
mgaContextPtr mmesa;
__DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
mgaScreenPrivate *mgaScreen = (mgaScreenPrivate *)sPriv->private;
drm_mga_sarea_t *saPriv=(drm_mga_sarea_t*)(((char*)sPriv->pSAREA)+
sizeof(XF86DRISAREARec));
/*fprintf(stderr, "XMesaCreateContext\n");*/
mmesa = (mgaContextPtr)Xcalloc(sizeof(mgaContext), 1);
if (!mmesa) {
return GL_FALSE;
}
ctx = driContextPriv->mesaContext;
mmesa->display = dpy;
mmesa->hHWContext = driContextPriv->hHWContext;
mmesa->driFd = sPriv->fd;
mmesa->driHwLock = &sPriv->pSAREA->lock;
mmesa->mgaScreen = mgaScreen;
mmesa->driScreen = sPriv;
mmesa->sarea = saPriv;
mmesa->glBuffer = NULL;
make_empty_list(&mmesa->SwappedOut);
mmesa->lastTexHeap = mgaScreen->texVirtual[MGA_AGP_HEAP] ? 2 : 1;
for (i = 0 ; i < mmesa->lastTexHeap ; i++) {
mmesa->texHeap[i] = mmInit( 0, mgaScreen->textureSize[i]);
make_empty_list(&mmesa->TexObjList[i]);
}
mmesa->renderindex = -1; /* impossible value */
mmesa->new_state = ~0;
mmesa->dirty = ~0;
mmesa->warp_pipe = 0;
mmesa->CurrentTexObj[0] = 0;
mmesa->CurrentTexObj[1] = 0;
mmesa->texAge[0] = 0;
mmesa->texAge[1] = 0;
ctx->DriverCtx = (void *) mmesa;
mmesa->glCtx = ctx;
mgaDDExtensionsInit( ctx );
mgaDDInitStateFuncs( ctx );
mgaDDInitTextureFuncs( ctx );
mgaDDInitSpanFuncs( ctx );
mgaDDInitDriverFuncs( ctx );
mgaDDInitIoctlFuncs( ctx );
ctx->Driver.TriangleCaps = (DD_TRI_CULL|
DD_TRI_LIGHT_TWOSIDE|
DD_TRI_STIPPLE|
DD_TRI_OFFSET);
/* Ask mesa to clip fog coordinates for us.
*/
ctx->TriangleCaps |= DD_CLIP_FOG_COORD;
ctx->Shared->DefaultD[2][0].DriverData = 0;
ctx->Shared->DefaultD[2][1].DriverData = 0;
if (ctx->VB)
mgaDDRegisterVB( ctx->VB );
if (ctx->NrPipelineStages)
ctx->NrPipelineStages =
mgaDDRegisterPipelineStages(ctx->PipelineStage,
ctx->PipelineStage,
ctx->NrPipelineStages);
mgaInitState( mmesa );
driContextPriv->driverPrivate = (void *) mmesa;
return GL_TRUE;
}
void XMesaDestroyContext(__DRIcontextPrivate *driContextPriv)
{
mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
if (mmesa) {
/* mgaTextureObjectPtr next_t, t; */
/* foreach_s (t, next_t, &(mmesa->TexObjList)) */
/* mgaDestroyTexObj(mmesa, t); */
/* foreach_s (t, next_t, &(mmesa->SwappedOut)) */
/* mgaDestroyTexObj(mmesa, t); */
Xfree(mmesa);
driContextPriv->driverPrivate = NULL;
}
}
GLframebuffer *XMesaCreateWindowBuffer( Display *dpy,
__DRIscreenPrivate *driScrnPriv,
__DRIdrawablePrivate *driDrawPriv,
GLvisual *mesaVis)
{
return gl_create_framebuffer(mesaVis,
GL_FALSE, /* software depth buffer? */
mesaVis->StencilBits > 0,
mesaVis->AccumRedBits > 0,
mesaVis->AlphaBits > 0
);
}
GLframebuffer *XMesaCreatePixmapBuffer( Display *dpy,
__DRIscreenPrivate *driScrnPriv,
__DRIdrawablePrivate *driDrawPriv,
GLvisual *mesaVis)
{
#if 0
/* Different drivers may have different combinations of hardware and
* software ancillary buffers.
*/
return gl_create_framebuffer(mesaVis,
GL_FALSE, /* software depth buffer? */
mesaVis->StencilBits > 0,
mesaVis->AccumRedBits > 0,
mesaVis->AlphaBits > 0
);
#else
return NULL; /* not implemented yet */
#endif
}
void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
{
/* XXX should do swap according to the buffer, not the context! */
mgaContextPtr mmesa = mgaCtx;
FLUSH_VB( mmesa->glCtx, "swap buffers" );
mgaSwapBuffers(mmesa);
}
GLboolean XMesaUnbindContext(__DRIcontextPrivate *driContextPriv)
{
mgaContextPtr mmesa = (mgaContextPtr) driContextPriv->driverPrivate;
if (mmesa)
mmesa->dirty = ~0;
return GL_TRUE;
}
/* This looks buggy to me - the 'b' variable isn't used anywhere...
* Hmm - It seems that the drawable is already hooked in to
* driDrawablePriv.
*
* But why are we doing context initialization here???
*/
GLboolean XMesaMakeCurrent(__DRIcontextPrivate *driContextPriv,
__DRIdrawablePrivate *driDrawPriv,
__DRIdrawablePrivate *driReadPriv)
{
if (driContextPriv) {
mgaCtx = (mgaContextPtr) driContextPriv->driverPrivate;
gl_make_current2(mgaCtx->glCtx, driDrawPriv->mesaBuffer, driReadPriv->mesaBuffer);
mgaCtx->driDrawable = driDrawPriv;
mgaCtx->dirty = ~0;
mgaCtx->dirty_cliprects = (MGA_FRONT|MGA_BACK);
if (!mgaCtx->glCtx->Viewport.Width)
gl_Viewport(mgaCtx->glCtx, 0, 0, driDrawPriv->w, driDrawPriv->h);
}
else {
gl_make_current(0,0);
mgaCtx = NULL;
}
return GL_TRUE;
}
void mgaGetLock( mgaContextPtr mmesa, GLuint flags )
{
__DRIdrawablePrivate *dPriv = mmesa->driDrawable;
drm_mga_sarea_t *sarea = mmesa->sarea;
int me = mmesa->hHWContext;
int i;
drmGetLock(mmesa->driFd, mmesa->hHWContext, flags);
if (*(dPriv->pStamp) != dPriv->lastStamp) {
mmesa->setupdone = 0;
mmesa->dirty_cliprects = (MGA_FRONT|MGA_BACK);
mgaUpdateRects( mmesa, (MGA_FRONT|MGA_BACK) );
}
mmesa->dirty |= MGA_UPLOAD_CTX | MGA_UPLOAD_CLIPRECTS;
mmesa->sarea->dirty |= MGA_UPLOAD_CTX;
if (sarea->ctxOwner != me) {
mmesa->dirty |= (MGA_UPLOAD_CTX | MGA_UPLOAD_TEX0 |
MGA_UPLOAD_TEX1 | MGA_UPLOAD_PIPE);
sarea->ctxOwner=me;
}
for (i = 0 ; i < mmesa->lastTexHeap ; i++)
if (sarea->texAge[i] != mmesa->texAge[i])
mgaAgeTextures( mmesa, i );
sarea->last_quiescent = -1; /* just kill it for now */
}
#endif
|