Adjustments to make everything use IOCTL/sarea defines in DRM instead
[mesa.git] / src / mesa / drivers / dri / i810 / i810context.h
1 /*
2 * GLX Hardware Device Driver for Intel i810
3 * Copyright (C) 1999 Keith Whitwell
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 /* $XFree86: xc/lib/GL/mesa/src/drv/i810/i810context.h,v 1.9 2002/12/16 16:18:51 dawes Exp $ */
25
26 #ifndef I810CONTEXT_INC
27 #define I810CONTEXT_INC
28
29 typedef struct i810_context_t i810Context;
30 typedef struct i810_context_t *i810ContextPtr;
31 typedef struct i810_texture_object_t *i810TextureObjectPtr;
32
33 #include "mtypes.h"
34 #include "mm.h"
35
36 #include "i810screen.h"
37 #include "i810tex.h"
38
39
40 /* Reasons to disable hardware rasterization.
41 */
42 #define I810_FALLBACK_TEXTURE 0x1
43 #define I810_FALLBACK_DRAW_BUFFER 0x2
44 #define I810_FALLBACK_READ_BUFFER 0x4
45 #define I810_FALLBACK_COLORMASK 0x8
46 #define I810_FALLBACK_SPECULAR 0x20
47 #define I810_FALLBACK_LOGICOP 0x40
48 #define I810_FALLBACK_RENDERMODE 0x80
49 #define I810_FALLBACK_STENCIL 0x100
50 #define I810_FALLBACK_BLEND_EQ 0x200
51 #define I810_FALLBACK_BLEND_FUNC 0x400
52
53
54 #ifndef PCI_CHIP_I810
55 #define PCI_CHIP_I810 0x7121
56 #define PCI_CHIP_I810_DC100 0x7123
57 #define PCI_CHIP_I810_E 0x7125
58 #define PCI_CHIP_I815 0x1132
59 #endif
60
61 #define IS_I810(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I810 || \
62 imesa->i810Screen->deviceID == PCI_CHIP_I810_DC100 || \
63 imesa->i810Screen->deviceID == PCI_CHIP_I810_E)
64 #define IS_I815(imesa) (imesa->i810Screen->deviceID == PCI_CHIP_I815)
65
66
67 #define I810_UPLOAD_TEX(i) (I810_UPLOAD_TEX0<<(i))
68
69 /* Use the templated vertex formats:
70 */
71 #define TAG(x) i810##x
72 #include "tnl_dd/t_dd_vertex.h"
73 #undef TAG
74
75 typedef void (*i810_tri_func)( i810ContextPtr, i810Vertex *, i810Vertex *,
76 i810Vertex * );
77 typedef void (*i810_line_func)( i810ContextPtr, i810Vertex *, i810Vertex * );
78 typedef void (*i810_point_func)( i810ContextPtr, i810Vertex * );
79
80 struct i810_context_t {
81 GLint refcount;
82 GLcontext *glCtx;
83
84 /* Texture object bookkeeping
85 */
86 unsigned nr_heaps;
87 driTexHeap * texture_heaps[1];
88 driTextureObject swapped;
89
90 struct i810_texture_object_t *CurrentTexObj[2];
91
92
93 /* Bit flag to keep track of fallbacks.
94 */
95 GLuint Fallback;
96
97 /* State for i810vb.c and i810tris.c.
98 */
99 GLuint new_state; /* _NEW_* flags */
100 GLuint SetupNewInputs;
101 GLuint SetupIndex;
102 GLuint RenderIndex;
103 GLmatrix ViewportMatrix;
104 GLenum render_primitive;
105 GLenum reduced_primitive;
106 GLuint hw_primitive;
107 GLubyte *verts;
108
109 drmBufPtr vertex_buffer;
110 char *vertex_addr;
111 GLuint vertex_low;
112 GLuint vertex_high;
113 GLuint vertex_last_prim;
114
115 GLboolean upload_cliprects;
116
117
118 /* Fallback rasterization functions
119 */
120 i810_point_func draw_point;
121 i810_line_func draw_line;
122 i810_tri_func draw_tri;
123
124 /* Hardware state
125 */
126 GLuint dirty; /* I810_UPLOAD_* */
127 GLuint Setup[I810_CTX_SETUP_SIZE];
128 GLuint BufferSetup[I810_DEST_SETUP_SIZE];
129 int vertex_size;
130 int vertex_stride_shift;
131 unsigned int lastStamp;
132 GLboolean stipple_in_hw;
133
134 GLenum TexEnvImageFmt[2];
135
136 /* State which can't be computed completely on the fly:
137 */
138 GLuint LcsCullMode;
139 GLuint LcsLineWidth;
140 GLuint LcsPointSize;
141
142 /* Funny mesa mirrors
143 */
144 GLushort ClearColor;
145
146 /* DRI stuff
147 */
148 GLuint needClip;
149 GLframebuffer *glBuffer;
150 GLboolean doPageFlip;
151
152 /* These refer to the current draw (front vs. back) buffer:
153 */
154 char *drawMap; /* draw buffer address in virtual mem */
155 char *readMap;
156 int drawX; /* origin of drawable in draw buffer */
157 int drawY;
158 GLuint numClipRects; /* cliprects for that buffer */
159 drm_clip_rect_t *pClipRects;
160
161 int lastSwap;
162 int texAge;
163 int ctxAge;
164 int dirtyAge;
165
166
167 GLboolean scissor;
168 drm_clip_rect_t draw_rect;
169 drm_clip_rect_t scissor_rect;
170
171 drmContext hHWContext;
172 drm_hw_lock_t *driHwLock;
173 int driFd;
174
175 __DRIdrawablePrivate *driDrawable;
176 __DRIscreenPrivate *driScreen;
177 i810ScreenPrivate *i810Screen;
178 I810SAREAPtr sarea;
179 };
180
181
182 #define I810_CONTEXT(ctx) ((i810ContextPtr)(ctx->DriverCtx))
183
184 #define GET_DISPATCH_AGE( imesa ) imesa->sarea->last_dispatch
185 #define GET_ENQUEUE_AGE( imesa ) imesa->sarea->last_enqueue
186
187
188 /* Lock the hardware and validate our state.
189 */
190 #define LOCK_HARDWARE( imesa ) \
191 do { \
192 char __ret=0; \
193 DRM_CAS(imesa->driHwLock, imesa->hHWContext, \
194 (DRM_LOCK_HELD|imesa->hHWContext), __ret); \
195 if (__ret) \
196 i810GetLock( imesa, 0 ); \
197 } while (0)
198
199
200
201 /* Release the kernel lock.
202 */
203 #define UNLOCK_HARDWARE(imesa) \
204 DRM_UNLOCK(imesa->driFd, imesa->driHwLock, imesa->hHWContext);
205
206
207 /* This is the wrong way to do it, I'm sure. Otherwise the drm
208 * bitches that I've already got the heavyweight lock. At worst,
209 * this is 3 ioctls. The best solution probably only gets me down
210 * to 2 ioctls in the worst case.
211 */
212 #define LOCK_HARDWARE_QUIESCENT( imesa ) do { \
213 LOCK_HARDWARE( imesa ); \
214 i810RegetLockQuiescent( imesa ); \
215 } while(0)
216
217
218 extern void i810GetLock( i810ContextPtr imesa, GLuint flags );
219 extern void i810EmitHwStateLocked( i810ContextPtr imesa );
220 extern void i810EmitScissorValues( i810ContextPtr imesa, int box_nr, int emit );
221 extern void i810EmitDrawingRectangle( i810ContextPtr imesa );
222 extern void i810XMesaSetBackClipRects( i810ContextPtr imesa );
223 extern void i810XMesaSetFrontClipRects( i810ContextPtr imesa );
224
225 #define SUBPIXEL_X -.5
226 #define SUBPIXEL_Y -.5
227
228 /* ================================================================
229 * Debugging:
230 */
231 #define DO_DEBUG 1
232 #if DO_DEBUG
233 extern int I810_DEBUG;
234 #else
235 #define I810_DEBUG 0
236 #endif
237
238 #define DEBUG_TEXTURE 0x1
239 #define DEBUG_STATE 0x2
240 #define DEBUG_IOCTL 0x4
241 #define DEBUG_PRIMS 0x8
242 #define DEBUG_VERTS 0x10
243 #define DEBUG_FALLBACKS 0x20
244 #define DEBUG_VERBOSE 0x40
245 #define DEBUG_DRI 0x80
246 #define DEBUG_DMA 0x100
247 #define DEBUG_SANITY 0x200
248 #define DEBUG_SYNC 0x400
249 #define DEBUG_SLEEP 0x800
250
251 #endif