aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/mach64/mach64_context.h
blob: 03b90a44717443e6ed60d8b8f7eddb1249fde8b8 (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
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
/* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
/*
 * Copyright 2000 Gareth Hughes
 * 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, sublicense,
 * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
 * GARETH HUGHES 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:
 *	Gareth Hughes <gareth@valinux.com>
 *	Leif Delgass <ldelgass@retinalburn.net>
 *	Jos�Fonseca <j_r_fonseca@yahoo.co.uk>
 */

#ifndef __MACH64_CONTEXT_H__
#define __MACH64_CONTEXT_H__

#ifdef GLX_DIRECT_RENDERING

#include "dri_util.h"
#include "drm.h"
#include "xf86drm.h"
#include "mach64_common.h"

#include "mtypes.h"
#include "mm.h"

#include "mach64_reg.h"

#include "texmem.h"

struct mach64_context;
typedef struct mach64_context mach64ContextRec;
typedef struct mach64_context *mach64ContextPtr;

#include "mach64_lock.h"
#include "mach64_screen.h"

/* Experimental driver options */
#define MACH64_CLIENT_STATE_EMITS       0

/* Performace monitoring */
#define ENABLE_PERF_BOXES               1

/* Native vertex format */
#define MACH64_NATIVE_VTXFMT		1

/* Flags for what context state needs to be updated:
 */
#define MACH64_NEW_ALPHA		0x0001
#define MACH64_NEW_DEPTH		0x0002
#define MACH64_NEW_FOG			0x0004
#define MACH64_NEW_CLIP			0x0008
#define MACH64_NEW_CULL			0x0010
#define MACH64_NEW_MASKS		0x0020
#define MACH64_NEW_RENDER_UNUSED	0x0040
#define MACH64_NEW_WINDOW		0x0080
#define MACH64_NEW_TEXTURE		0x0100
#define MACH64_NEW_CONTEXT		0x0200
#define MACH64_NEW_ALL			0x03ff

/* Flags for software fallback cases:
 */
#define MACH64_FALLBACK_TEXTURE		0x0001
#define MACH64_FALLBACK_DRAW_BUFFER	0x0002
#define MACH64_FALLBACK_READ_BUFFER	0x0004
#define MACH64_FALLBACK_STENCIL		0x0008
#define MACH64_FALLBACK_RENDER_MODE	0x0010
#define MACH64_FALLBACK_MULTIDRAW	0x0020
#define MACH64_FALLBACK_LOGICOP		0x0040
#define MACH64_FALLBACK_SEP_SPECULAR	0x0080
#define MACH64_FALLBACK_BLEND_EQ	0x0100
#define MACH64_FALLBACK_BLEND_FUNC	0x0200

#if MACH64_NATIVE_VTXFMT

/* The vertex structures.
 */

#if 0
/* This isn't actually necessary since all accesses to the vertex
 * structure must be made through the LE32_* macros.
 */

typedef struct {
   GLubyte	blue;
   GLubyte	green;
   GLubyte	red;
   GLubyte	alpha;
} mach64_color_t;

typedef struct {
   GLfloat u1, v1, w1;			/* Texture 1 coordinates */
   GLfloat u0, v0, w0;			/* Texture 0 coordinates */
   mach64_color_t specular;		/* Specular color */
   GLuint z;				/* Depth coordinate */
   mach64_color_t color;		/* Diffuse color */
   GLushort y, x;			/* Coordinates in screen space */
} mach64_vertex;
#endif

/* The size of this union is not of relevence:
 */
union mach64_vertex_t {
   GLfloat f[16];
   GLuint ui[16];
   GLushort us2[16][2];
   GLubyte ub4[16][4];
};

typedef union mach64_vertex_t mach64Vertex, *mach64VertexPtr;

#else

/* Use the templated vertex format:
 */
#define TAG(x) mach64##x
#include "tnl_dd/t_dd_vertex.h"
#undef TAG

#endif /* MACH64_NATIVE_VTXFMT */

/* Subpixel offsets for window coordinates:
 * These are enough to fix most glean tests except polygonOffset.
 * There are also still some gaps that show in e.g. the tunnel Mesa demo
 * or the lament xscreensaver hack.
 */
#define SUBPIXEL_X	(0.0125F)
#define SUBPIXEL_Y	(0.15F)


typedef void (*mach64_tri_func)( mach64ContextPtr,
				   mach64Vertex *,
				   mach64Vertex *,
				   mach64Vertex * );

typedef void (*mach64_line_func)( mach64ContextPtr,
				    mach64Vertex *,
				    mach64Vertex * );

typedef void (*mach64_point_func)( mach64ContextPtr,
				     mach64Vertex * );

#ifdef TEXMEM
struct mach64_texture_object {
   driTextureObject   base;

   GLuint offset;

   GLuint dirty;
   GLuint age;

   GLint widthLog2;
   GLint heightLog2;
   GLint maxLog2;

   GLint hasAlpha;
   GLint textureFormat;

   /* Have to keep these separate due to how they are programmed.
    * FIXME: Why don't we just use the tObj values?
    */
   GLboolean BilinearMin;
   GLboolean BilinearMag;
   GLboolean ClampS;
   GLboolean ClampT;
};
#else
struct mach64_texture_object {
   struct mach64_texture_object *next;
   struct mach64_texture_object *prev;
   struct gl_texture_object *tObj;

   PMemBlock memBlock;
   GLuint offset;
   GLuint size;

   GLuint dirty;
   GLuint age;

   GLint bound;
   GLint heap;

   GLint widthLog2;
   GLint heightLog2;
   GLint maxLog2;

   GLint hasAlpha;
   GLint textureFormat;

   /* Have to keep these separate due to how they are programmed.
    * FIXME: Why don't we just use the tObj values?
    */
   GLboolean BilinearMin;
   GLboolean BilinearMag;
   GLboolean ClampS;
   GLboolean ClampT;
};
#endif

typedef struct mach64_texture_object mach64TexObj, *mach64TexObjPtr;


struct mach64_context {
   GLcontext *glCtx;

   /* Driver and hardware state management
    */
   GLuint new_state;
   GLuint dirty;			/* Hardware state to be updated */
   mach64_context_regs_t setup;

   GLuint NewGLState;
   GLuint Fallback;
   GLuint SetupIndex;
   GLuint SetupNewInputs;
   GLuint RenderIndex;
   GLfloat hw_viewport[16];
   GLfloat depth_scale;
   GLuint vertex_size;
   GLuint vertex_stride_shift;
   GLuint vertex_format;
   GLuint num_verts;
   GLubyte *verts;		

   CARD32 Color;			/* Current draw color */
   CARD32 ClearColor;			/* Color used to clear color buffer */
   CARD32 ClearDepth;			/* Value used to clear depth buffer */

   /* Map GL texture units onto hardware
    */
   GLint multitex;
   GLint tmu_source[2];
   GLint tex_dest[2];

   /* Texture object bookkeeping
    */
   mach64TexObjPtr CurrentTexObj[2];
#ifdef TEXMEM
   unsigned nr_heaps;
   driTexHeap * texture_heaps[ R128_NR_TEX_HEAPS ];
   driTextureObject swapped;
#else
   mach64TexObj TexObjList[MACH64_NR_TEX_HEAPS];
   mach64TexObj SwappedOut;
   memHeap_t *texHeap[MACH64_NR_TEX_HEAPS];
   GLuint lastTexAge[MACH64_NR_TEX_HEAPS];
   GLint firstTexHeap, lastTexHeap;
#endif

   /* Fallback rasterization functions
    */
   mach64_point_func draw_point;
   mach64_line_func draw_line;
   mach64_tri_func draw_tri;

   /* Culling */
   GLfloat backface_sign;

   /* DMA buffers
    */
   void *vert_buf;
   size_t vert_total;
   unsigned vert_used;

   GLuint hw_primitive;
   GLenum render_primitive;

   /* Visual, drawable, cliprect and scissor information
    */
   GLint drawOffset, drawPitch;
   GLint drawX, drawY;                  /* origin of drawable in draw buffer */
   GLint readOffset, readPitch;

   GLuint numClipRects;			/* Cliprects for the draw buffer */
   drm_clip_rect_t *pClipRects;

   GLint scissor;
   drm_clip_rect_t ScissorRect;	/* Current software scissor */

   /* 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 */

   drmContext hHWContext;
   drm_hw_lock_t *driHwLock;
   int driFd;

   mach64ScreenPtr mach64Screen;	/* Screen private DRI data */
   ATISAREAPrivPtr sarea;		/* Private SAREA data */

   GLuint hardwareWentIdle;

#if ENABLE_PERF_BOXES
   /* Performance counters
    */
   GLuint boxes;			/* Draw performance boxes */
   GLuint c_clears;
   GLuint c_drawWaits;
   GLuint c_textureSwaps;
   GLuint c_textureBytes;
   GLuint c_agpTextureBytes;
   GLuint c_texsrc_agp;
   GLuint c_texsrc_card;
   GLuint c_vertexBuffers;
#endif

   /* VBI
    */
   GLuint vbl_seq;
   GLuint vblank_flags;
   GLuint do_irqs;

   /* Configuration cache
    */
   driOptionCache optionCache;
};

#define MACH64_CONTEXT(ctx)		((mach64ContextPtr)(ctx->DriverCtx))


extern GLboolean mach64CreateContext( const __GLcontextModes *glVisual,
				      __DRIcontextPrivate *driContextPriv,
                                      void *sharedContextPrivate );

extern void mach64DestroyContext( __DRIcontextPrivate * );

extern GLboolean mach64MakeCurrent( __DRIcontextPrivate *driContextPriv,
                                    __DRIdrawablePrivate *driDrawPriv,
                                    __DRIdrawablePrivate *driReadPriv );

extern GLboolean mach64UnbindContext( __DRIcontextPrivate *driContextPriv );

/* ================================================================
 * Byte ordering
 */
#include "X11/Xarch.h"

#if X_BYTE_ORDER == X_LITTLE_ENDIAN
#define LE32_IN( x )		( *(GLuint *)(x) )
#define LE32_IN_FLOAT( x )	( *(GLfloat *)(x) )
#define LE32_OUT( x, y )	do { *(GLuint *)(x) = (y); } while (0)
#define LE32_OUT_FLOAT( x, y )	do { *(GLfloat *)(x) = (y); } while (0)
#else
#include <byteswap.h>
#define LE32_IN( x )		bswap_32( *(GLuint *)(x) )
#define LE32_IN_FLOAT( x )						\
({									\
   GLuint __tmp = bswap_32( *(GLuint *)(x) );				\
   *(GLfloat *)&__tmp;							\
})
#define LE32_OUT( x, y )	do { *(GLuint *)(x) = bswap_32( y ); } while (0)
#define LE32_OUT_FLOAT( x, y )						\
do {									\
   GLuint __tmp;							\
   *(GLfloat *)&__tmp = (y);						\
   *(GLuint *)(x) = bswap_32( __tmp );					\
} while (0)
#endif

/* ================================================================
 * DMA buffers
 */

#define DMALOCALS       CARD32 *buf=NULL; int requested=0; int outcount=0

/* called while locked for interleaved client-side state emits */
#define DMAGETPTR( dwords )					\
do {								\
   requested = (dwords);					\
   buf = (CARD32 *)mach64AllocDmaLocked( mmesa, ((dwords)*4) );	\
   outcount = 0;						\
} while(0)

#define DMAOUTREG( reg, val )				\
do {							\
   LE32_OUT( &buf[outcount++], ADRINDEX( reg ) );	\
   LE32_OUT( &buf[outcount++], ( val ) );		\
} while(0)

#define DMAADVANCE()						\
do {								\
   if (outcount < requested) {					\
      mmesa->vert_used -= (requested - outcount) * 4;	\
   }								\
} while(0)

/* ================================================================
 * Debugging:
 */

#define DO_DEBUG		1

#if DO_DEBUG
extern int MACH64_DEBUG;
#else
#define MACH64_DEBUG		0
#endif

#define DEBUG_ALWAYS_SYNC	0x001
#define DEBUG_VERBOSE_API	0x002
#define DEBUG_VERBOSE_MSG	0x004
#define DEBUG_VERBOSE_LRU	0x008
#define DEBUG_VERBOSE_DRI	0x010
#define DEBUG_VERBOSE_IOCTL	0x020
#define DEBUG_VERBOSE_PRIMS	0x040
#define DEBUG_VERBOSE_COUNT	0x080
#define DEBUG_NOWAIT		0x100
#endif
#endif /* __MACH64_CONTEXT_H__ */