summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/r128/r128_context.h
blob: 800cc17545d941213feb28b46ccf86e2e3a0f9be (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
/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_context.h,v 1.8 2001/04/10 17:53:07 dawes Exp $ */
/**************************************************************************

Copyright 1999, 2000 ATI Technologies Inc. and 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
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
ATI, PRECISION INSIGHT AND/OR THEIR 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:
 *   Kevin E. Martin <martin@valinux.com>
 *   Gareth Hughes <gareth@valinux.com>
 *
 */

#ifndef __R128_CONTEXT_H__
#define __R128_CONTEXT_H__

#ifdef GLX_DIRECT_RENDERING

#include <X11/Xlibint.h>

#include "dri_mesaint.h"
#include "dri_tmm.h"

#include "xf86drm.h"
#include "xf86drmR128.h"

#include "types.h"

#include "r128_sarea.h"
#include "r128_reg.h"

struct r128_context;
typedef struct r128_context r128ContextRec;
typedef struct r128_context *r128ContextPtr;

#include "r128_lock.h"
#include "r128_texobj.h"
#include "r128_screen.h"

/* Flags for what context state needs to be updated:
 */
#define R128_NEW_ALPHA		0x0001
#define R128_NEW_DEPTH		0x0002
#define R128_NEW_FOG		0x0004
#define R128_NEW_CLIP		0x0008
#define R128_NEW_CULL		0x0010
#define R128_NEW_MASKS		0x0020
#define R128_NEW_RENDER_NOT	0x0040
#define R128_NEW_WINDOW		0x0080
#define R128_NEW_TEXTURE	0x0100
#define R128_NEW_CONTEXT	0x0200
#define R128_NEW_ALL		0x03ff

/* Flags for software fallback cases:
 */
#define R128_FALLBACK_TEXTURE		0x0001
#define R128_FALLBACK_DRAW_BUFFER	0x0002
#define R128_FALLBACK_READ_BUFFER	0x0004
#define R128_FALLBACK_STENCIL		0x0008
#define R128_FALLBACK_RENDER_MODE	0x0010
#define R128_FALLBACK_MULTIDRAW		0x0020
#define R128_FALLBACK_LOGICOP		0x0040

/* Reasons why the GL_BLEND fallback mightn't work:
 */
#define R128_BLEND_ENV_COLOR	0x1
#define R128_BLEND_MULTITEX	0x2

/* Subpixel offsets for window coordinates (triangles):
 */
#define SUBPIXEL_X  (0.0F)
#define SUBPIXEL_Y  (0.125F)

/* Offset for points:
 */
#define PNT_X_OFFSET  ( 0.125F)
#define PNT_Y_OFFSET  (-0.125F)


typedef void (*r128_interp_func)( GLfloat t,
				  GLfloat *result,
				  const GLfloat *in,
				  const GLfloat *out );

struct r128_elt_tab {
   void (*emit_unclipped_verts)( struct vertex_buffer *VB );

   void (*build_tri_verts)( r128ContextPtr rmesa,
			    struct vertex_buffer *VB,
			    GLfloat *O, GLuint *elt );

   void (*interp)( GLfloat t, GLfloat *O,
		   const GLfloat *I, const GLfloat *J );

   void (*project_and_emit_verts)( r128ContextPtr rmesa,
				   const GLfloat *verts,
				   GLuint *elts,
				   GLuint nr );
};

struct r128_context {
   GLcontext *glCtx;			/* Mesa context */

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

   GLuint vertsize;
   GLuint vc_format;
   GLfloat depth_scale;

   GLuint Color;			/* Current draw color */
   GLuint ClearColor;			/* Color used to clear color buffer */
   GLuint ClearDepth;			/* Value used to clear depth buffer */
   GLuint ClearStencil;			/* Value used to clear stencil */
   GLuint DepthMask;
   GLuint StencilMask;

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

   /* Texture object bookkeeping
    */
   r128TexObjPtr CurrentTexObj[2];
   r128TexObj TexObjList[R128_NR_TEX_HEAPS];
   r128TexObj SwappedOut;
   memHeap_t *texHeap[R128_NR_TEX_HEAPS];
   GLint lastTexAge[R128_NR_TEX_HEAPS];
   GLint lastTexHeap;

   /* Current rendering state, fallbacks
    */
   points_func   PointsFunc;
   line_func     LineFunc;
   triangle_func TriangleFunc;
   quad_func     QuadFunc;

   GLuint IndirectTriangles;
   GLuint Fallback;

   /* Fast path
    */
   GLuint SetupIndex;
   GLuint SetupDone;
   GLuint RenderIndex;
   GLuint OnFastPath;
   r128_interp_func interp;
   GLfloat *tmp_matrix;

   /* Vertex buffers
    */
   drmBufPtr vert_buf;
   GLuint num_verts;

   /* Elt path
    */
   drmBufPtr elt_buf, retained_buf;
   GLushort *first_elt, *next_elt;
   GLfloat *next_vert, *vert_heap;
   GLushort next_vert_index;
   GLushort first_vert_index;
   GLuint elt_vertsize;
   struct r128_elt_tab *elt_tab;
   GLfloat device_matrix[16];

   /* Page flipping
    */
   GLuint doPageFlip;
   GLuint currentPage;

   /* Drawable, cliprect and scissor information
    */
   GLenum DrawBuffer;			/* Optimize draw buffer update */
   GLint drawOffset, drawPitch;
   GLint readOffset, readPitch;

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

   GLuint scissor;
   XF86DRIClipRectRec ScissorRect;	/* Current software scissor */

   /* Mirrors of some DRI state
    */
   Display *display;			/* X server display */

   __DRIcontextPrivate	*driContext;	/* DRI context */
   __DRIscreenPrivate	*driScreen;	/* DRI screen */
   __DRIdrawablePrivate	*driDrawable;	/* DRI drawable bound to this ctx */

   int lastStamp;		        /* mirror driDrawable->lastStamp */

   drmContext hHWContext;
   drmLock *driHwLock;
   int driFd;

   r128ScreenPtr r128Screen;		/* Screen private DRI data */
   R128SAREAPrivPtr sarea;		/* Private SAREA data */

   /* Performance counters
    */
   GLuint boxes;			/* Draw performance boxes */
   GLuint hardwareWentIdle;
   GLuint c_clears;
   GLuint c_drawWaits;
   GLuint c_textureSwaps;
   GLuint c_textureBytes;
   GLuint c_vertexBuffers;
};

#define R128_CONTEXT(ctx)		((r128ContextPtr)(ctx->DriverCtx))

#define R128_IS_PLAIN( rmesa ) \
		(rmesa->r128Screen->chipset == R128_CARD_TYPE_R128)
#define R128_IS_PRO( rmesa ) \
		(rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_PRO)
#define R128_IS_MOBILITY( rmesa ) \
		(rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)


extern GLboolean r128CreateContext( Display *dpy, GLvisual *glVisual,
				    __DRIcontextPrivate *driContextPriv );
extern void r128DestroyContext( r128ContextPtr rmesa );
extern r128ContextPtr r128MakeCurrent( r128ContextPtr oldCtx,
				       r128ContextPtr newCtx,
				       __DRIdrawablePrivate *dPriv );

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

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

/* ================================================================
 * Debugging:
 */
#define DO_DEBUG		0
#define ENABLE_PERF_BOXES	0

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

#define DEBUG_ALWAYS_SYNC	0x01
#define DEBUG_VERBOSE_API	0x02
#define DEBUG_VERBOSE_MSG	0x04
#define DEBUG_VERBOSE_LRU	0x08
#define DEBUG_VERBOSE_DRI	0x10
#define DEBUG_VERBOSE_IOCTL	0x20
#define DEBUG_VERBOSE_2D	0x40

#endif
#endif /* __R128_CONTEXT_H__ */