28da220029dff18b8391445db13ed88cd8627a85
[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_End;
172 GLuint regCmdB;
173
174 GLuint regEnable;
175 GLuint regHFBBMSKL;
176 GLuint regHROP;
177
178 GLuint regHZWTMD;
179 GLuint regHSTREF;
180 GLuint regHSTMD;
181
182 GLuint regHATMD;
183 GLuint regHABLCsat;
184 GLuint regHABLCop;
185 GLuint regHABLAsat;
186 GLuint regHABLAop;
187 GLuint regHABLRCa;
188 GLuint regHABLRFCa;
189 GLuint regHABLRCbias;
190 GLuint regHABLRCb;
191 GLuint regHABLRFCb;
192 GLuint regHABLRAa;
193 GLuint regHABLRAb;
194 GLuint regHFogLF;
195 GLuint regHFogCL;
196 GLuint regHFogCH;
197
198 GLuint regHLP;
199 GLuint regHLPRF;
200
201 GLuint regHTXnTB_0;
202 GLuint regHTXnMPMD_0;
203 GLuint regHTXnTBLCsat_0;
204 GLuint regHTXnTBLCop_0;
205 GLuint regHTXnTBLMPfog_0;
206 GLuint regHTXnTBLAsat_0;
207 GLuint regHTXnTBLRCb_0;
208 GLuint regHTXnTBLRAa_0;
209 GLuint regHTXnTBLRFog_0;
210 /*=* John Sheng [2003.7.18] texture combine *=*/
211 GLuint regHTXnTBLRCa_0;
212 GLuint regHTXnTBLRCc_0;
213 GLuint regHTXnTBLRCbias_0;
214
215 GLuint regHTXnTB_1;
216 GLuint regHTXnMPMD_1;
217 GLuint regHTXnTBLCsat_1;
218 GLuint regHTXnTBLCop_1;
219 GLuint regHTXnTBLMPfog_1;
220 GLuint regHTXnTBLAsat_1;
221 GLuint regHTXnTBLRCb_1;
222 GLuint regHTXnTBLRAa_1;
223 GLuint regHTXnTBLRFog_1;
224 GLuint regHTXnTBLRCa_1;
225 GLuint regHTXnTBLRCc_1;
226 GLuint regHTXnTBLRCbias_1;
227
228 int vertexSize;
229 int hwVertexSize;
230 GLboolean ptexHack;
231 int coloroffset;
232 int specoffset;
233
234 GLint lastStamp;
235
236 GLenum TexEnvImageFmt[2];
237 GLuint ClearColor;
238 GLuint ClearMask;
239
240 /* DRI stuff
241 */
242 GLuint needClip;
243 GLframebuffer *glBuffer;
244 GLboolean doPageFlip;
245 /*=* John Sheng [2003.5.31] flip *=*/
246 GLuint currentPage;
247
248 viaBuffer *drawBuffer;
249 viaBuffer *readBuffer;
250 int drawX; /* origin of drawable in draw buffer */
251 int drawY;
252
253 int drawW;
254 int drawH;
255
256 int drawXoff;
257 GLuint numClipRects; /* cliprects for that buffer */
258 drm_clip_rect_t *pClipRects;
259
260 int lastSwap;
261 int texAge;
262 int ctxAge;
263 int dirtyAge;
264
265 GLboolean scissor;
266 drm_clip_rect_t drawRect;
267 drm_clip_rect_t scissorRect;
268
269 drm_context_t hHWContext;
270 drm_hw_lock_t *driHwLock;
271 int driFd;
272 __DRInativeDisplay *display;
273
274 __DRIdrawablePrivate *driDrawable;
275 __DRIscreenPrivate *driScreen;
276 viaScreenPrivate *viaScreen;
277 drm_via_sarea_t *sarea;
278 volatile GLuint* regMMIOBase;
279 volatile GLuint* pnGEMode;
280 volatile GLuint* regEngineStatus;
281 volatile GLuint* regTranSet;
282 volatile GLuint* regTranSpace;
283 GLuint* agpBase;
284 GLuint drawType;
285
286 GLuint nDoneFirstFlip;
287 GLuint agpFullCount;
288
289 GLboolean strictConformance;
290 GLboolean clearTexCache;
291
292 /* Configuration cache
293 */
294 driOptionCache optionCache;
295
296 GLuint vblank_flags;
297 GLuint vbl_seq;
298
299 int64_t swap_ust;
300 int64_t swap_missed_ust;
301
302 GLuint swap_count;
303 GLuint swap_missed_count;
304
305 PFNGLXGETUSTPROC get_ust;
306
307 };
308
309
310
311 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
312
313 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
314 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
315
316
317 /* Lock the hardware and validate our state.
318 */
319 #define LOCK_HARDWARE(vmesa) \
320 do { \
321 char __ret = 0; \
322 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
323 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
324 if (__ret) \
325 viaGetLock(vmesa, 0); \
326 } while (0)
327
328
329 /* Release the kernel lock.
330 */
331 #define UNLOCK_HARDWARE(vmesa) \
332 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
333
334 #define WAIT_IDLE(vmesa) \
335 do { \
336 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
337 break; \
338 } while (1)
339
340
341 #ifdef DEBUG
342 extern GLuint VIA_DEBUG;
343 #else
344 #define VIA_DEBUG 0
345 #endif
346
347
348 extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
349 extern void viaLock(viaContextPtr vmesa, GLuint flags);
350 extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
351 extern void viaEmitHwStateLocked(viaContextPtr vmesa);
352 extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
353 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
354 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
355 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
356 extern void viaXMesaWindowMoved(viaContextPtr vmesa);
357
358 extern GLboolean viaTexCombineState(viaContextPtr vmesa,
359 const struct gl_tex_env_combine_state * combine,
360 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