Get PolygonStipple working.. (or seemingly too). It seems to do the right
[mesa.git] / src / mesa / drivers / dri / unichrome / via_context.h
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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, sub license,
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 (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #ifndef _VIACONTEXT_H
27 #define _VIACONTEXT_H
28
29 typedef struct via_context_t viaContext;
30 typedef struct via_context_t *viaContextPtr;
31 typedef struct via_texture_object_t *viaTextureObjectPtr;
32
33 #include "dri_util.h"
34
35 #include "mtypes.h"
36 #include "drm.h"
37 #include "mm.h"
38 #include "tnl/t_vertex.h"
39
40 #include "via_screen.h"
41 #include "via_tex.h"
42 #include "via_common.h"
43
44 /* Chip tags. These are used to group the adapters into
45 * related families.
46 */
47 enum VIACHIPTAGS {
48 VIA_UNKNOWN = 0,
49 VIA_CLE266,
50 VIA_KM400,
51 VIA_K8M800,
52 VIA_PM800,
53 VIA_LAST
54 };
55
56 #define VIA_FALLBACK_TEXTURE 0x1
57 #define VIA_FALLBACK_DRAW_BUFFER 0x2
58 #define VIA_FALLBACK_READ_BUFFER 0x4
59 #define VIA_FALLBACK_COLORMASK 0x8
60 #define VIA_FALLBACK_SPECULAR 0x20
61 #define VIA_FALLBACK_LOGICOP 0x40
62 #define VIA_FALLBACK_RENDERMODE 0x80
63 #define VIA_FALLBACK_STENCIL 0x100
64 #define VIA_FALLBACK_BLEND_EQ 0x200
65 #define VIA_FALLBACK_BLEND_FUNC 0x400
66 #define VIA_FALLBACK_USER_DISABLE 0x800
67 #define VIA_FALLBACK_PROJ_TEXTURE 0x1000
68 #define VIA_FALLBACK_STIPPLE 0x2000
69
70 #define VIA_DMA_BUFSIZ 4096
71 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
72
73 #define VIA_NO_CLIPRECTS 0x1
74
75
76 /* Use the templated vertex formats:
77 */
78 #define TAG(x) via##x
79 #include "tnl_dd/t_dd_vertex.h"
80 #undef TAG
81
82 typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
83 viaVertex *);
84 typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
85 typedef void (*via_point_func)(viaContextPtr, viaVertex *);
86
87 typedef struct {
88 drm_handle_t handle;
89 drmSize size;
90 GLuint offset;
91 GLuint index;
92 GLuint pitch;
93 GLuint bpp;
94 char *map;
95 GLuint orig; /* The drawing origin,
96 * at (drawX,drawY) in screen space.
97 */
98 char *origMap;
99 } viaBuffer, *viaBufferPtr;
100
101
102 struct via_context_t {
103 GLint refcount;
104 GLcontext *glCtx;
105 GLcontext *shareCtx;
106 viaBuffer front;
107 viaBuffer back;
108 viaBuffer depth;
109 GLboolean hasBack;
110 GLboolean hasDepth;
111 GLboolean hasStencil;
112 GLboolean hasAccum;
113 GLuint depthBits;
114 GLuint stencilBits;
115
116 GLboolean have_hw_stencil;
117 GLuint ClearDepth;
118 GLuint depth_clear_mask;
119 GLuint stencil_clear_mask;
120 GLfloat depth_max;
121 GLfloat polygon_offset_scale;
122
123 GLubyte *dma;
124 viaRegion tex;
125
126 GLuint isAGP;
127
128 /* Textures
129 */
130 viaTextureObjectPtr CurrentTexObj[2];
131 struct via_texture_object_t TexObjList;
132 struct via_texture_object_t SwappedOut;
133 memHeap_t *texHeap;
134
135 /* Bit flag to keep 0track of fallbacks.
136 */
137 GLuint Fallback;
138
139 /* State for via_tris.c.
140 */
141 GLuint newState; /* _NEW_* flags */
142 GLuint newEmitState; /* _NEW_* flags */
143 GLuint newRenderState; /* _NEW_* flags */
144
145 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
146 GLuint vertex_attr_count;
147
148 GLuint setupIndex;
149 GLuint renderIndex;
150 GLmatrix ViewportMatrix;
151 GLenum renderPrimitive;
152 GLenum hwPrimitive;
153 unsigned char *verts;
154
155 /* drmBufPtr dma_buffer;
156 */
157 GLuint dmaLow;
158 GLuint dmaCliprectAddr;
159 GLuint dmaLastPrim;
160 GLboolean useAgp;
161
162
163 /* Fallback rasterization functions
164 */
165 via_point_func drawPoint;
166 via_line_func drawLine;
167 via_tri_func drawTri;
168
169 /* Hardware register
170 */
171 GLuint regCmdA;
172 GLuint regCmdA_End;
173 GLuint regCmdB;
174
175 GLuint regEnable;
176 GLuint regHFBBMSKL;
177 GLuint regHROP;
178
179 GLuint regHZWTMD;
180 GLuint regHSTREF;
181 GLuint regHSTMD;
182
183 GLuint regHATMD;
184 GLuint regHABLCsat;
185 GLuint regHABLCop;
186 GLuint regHABLAsat;
187 GLuint regHABLAop;
188 GLuint regHABLRCa;
189 GLuint regHABLRFCa;
190 GLuint regHABLRCbias;
191 GLuint regHABLRCb;
192 GLuint regHABLRFCb;
193 GLuint regHABLRAa;
194 GLuint regHABLRAb;
195 GLuint regHFogLF;
196 GLuint regHFogCL;
197 GLuint regHFogCH;
198
199 GLuint regHLP;
200 GLuint regHLPRF;
201
202 GLuint regHTXnTB_0;
203 GLuint regHTXnMPMD_0;
204 GLuint regHTXnTBLCsat_0;
205 GLuint regHTXnTBLCop_0;
206 GLuint regHTXnTBLMPfog_0;
207 GLuint regHTXnTBLAsat_0;
208 GLuint regHTXnTBLRCb_0;
209 GLuint regHTXnTBLRAa_0;
210 GLuint regHTXnTBLRFog_0;
211 /*=* John Sheng [2003.7.18] texture combine *=*/
212 GLuint regHTXnTBLRCa_0;
213 GLuint regHTXnTBLRCc_0;
214 GLuint regHTXnTBLRCbias_0;
215
216 GLuint regHTXnTB_1;
217 GLuint regHTXnMPMD_1;
218 GLuint regHTXnTBLCsat_1;
219 GLuint regHTXnTBLCop_1;
220 GLuint regHTXnTBLMPfog_1;
221 GLuint regHTXnTBLAsat_1;
222 GLuint regHTXnTBLRCb_1;
223 GLuint regHTXnTBLRAa_1;
224 GLuint regHTXnTBLRFog_1;
225 GLuint regHTXnTBLRCa_1;
226 GLuint regHTXnTBLRCc_1;
227 GLuint regHTXnTBLRCbias_1;
228
229 int vertexSize;
230 int hwVertexSize;
231 GLboolean ptexHack;
232 int coloroffset;
233 int specoffset;
234
235 GLint lastStamp;
236
237 GLenum TexEnvImageFmt[2];
238 GLuint ClearColor;
239 GLuint ClearMask;
240
241 /* DRI stuff
242 */
243 GLuint needClip;
244 GLframebuffer *glBuffer;
245 GLboolean doPageFlip;
246 /*=* John Sheng [2003.5.31] flip *=*/
247 GLuint currentPage;
248
249 viaBuffer *drawBuffer;
250 viaBuffer *readBuffer;
251 int drawX; /* origin of drawable in draw buffer */
252 int drawY;
253
254 int drawW;
255 int drawH;
256
257 int drawXoff;
258 GLuint numClipRects; /* cliprects for that buffer */
259 drm_clip_rect_t *pClipRects;
260
261 int lastSwap;
262 int texAge;
263 int ctxAge;
264 int dirtyAge;
265
266 GLboolean scissor;
267 drm_clip_rect_t drawRect;
268 drm_clip_rect_t scissorRect;
269
270 drm_context_t hHWContext;
271 drm_hw_lock_t *driHwLock;
272 int driFd;
273 __DRInativeDisplay *display;
274
275 __DRIdrawablePrivate *driDrawable;
276 __DRIscreenPrivate *driScreen;
277 viaScreenPrivate *viaScreen;
278 drm_via_sarea_t *sarea;
279 volatile GLuint* regMMIOBase;
280 volatile GLuint* pnGEMode;
281 volatile GLuint* regEngineStatus;
282 volatile GLuint* regTranSet;
283 volatile GLuint* regTranSpace;
284 GLuint* agpBase;
285 GLuint drawType;
286
287 GLuint nDoneFirstFlip;
288 GLuint agpFullCount;
289
290 GLboolean strictConformance;
291 GLboolean clearTexCache;
292
293 /* Configuration cache
294 */
295 driOptionCache optionCache;
296
297 GLuint vblank_flags;
298 GLuint vbl_seq;
299
300 int64_t swap_ust;
301 int64_t swap_missed_ust;
302
303 GLuint swap_count;
304 GLuint swap_missed_count;
305
306 PFNGLXGETUSTPROC get_ust;
307
308 };
309
310
311
312 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
313
314 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
315 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
316
317
318 /* Lock the hardware and validate our state.
319 */
320 #define LOCK_HARDWARE(vmesa) \
321 do { \
322 char __ret = 0; \
323 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
324 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
325 if (__ret) \
326 viaGetLock(vmesa, 0); \
327 } while (0)
328
329
330 /* Release the kernel lock.
331 */
332 #define UNLOCK_HARDWARE(vmesa) \
333 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
334
335 #define WAIT_IDLE(vmesa) \
336 do { \
337 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
338 break; \
339 } while (1)
340
341
342 #ifdef DEBUG
343 extern GLuint VIA_DEBUG;
344 #else
345 #define VIA_DEBUG 0
346 #endif
347
348
349 extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
350 extern void viaLock(viaContextPtr vmesa, GLuint flags);
351 extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
352 extern void viaEmitHwStateLocked(viaContextPtr vmesa);
353 extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
354 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
355 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
356 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
357 extern void viaXMesaWindowMoved(viaContextPtr vmesa);
358
359 extern void viaTexCombineState(viaContextPtr vmesa,
360 const struct gl_tex_env_combine_state * combine, unsigned unit );
361
362 /* Via hw already adjusted for GL pixel centers:
363 */
364 #define SUBPIXEL_X 0
365 #define SUBPIXEL_Y 0
366
367 /* TODO XXX _SOLO temp defines to make code compilable */
368 #ifndef GLX_PBUFFER_BIT
369 #define GLX_PBUFFER_BIT 0x00000004
370 #endif
371 #ifndef GLX_WINDOW_BIT
372 #define GLX_WINDOW_BIT 0x00000001
373 #endif
374 #ifndef VERT_BIT_CLIP
375 #define VERT_BIT_CLIP 0x1000000
376 #endif
377
378 #endif