Calculate DEPTH_SCALE correctly for polygon offset.
[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
39 #include "via_screen.h"
40 #include "via_tex.h"
41 #include "via_common.h"
42 #include "xf86drmVIA.h"
43 #define VIA_FALLBACK_TEXTURE 0x1
44 #define VIA_FALLBACK_DRAW_BUFFER 0x2
45 #define VIA_FALLBACK_READ_BUFFER 0x4
46 #define VIA_FALLBACK_COLORMASK 0x8
47 #define VIA_FALLBACK_SPECULAR 0x20
48 #define VIA_FALLBACK_LOGICOP 0x40
49 #define VIA_FALLBACK_RENDERMODE 0x80
50 #define VIA_FALLBACK_STENCIL 0x100
51 #define VIA_FALLBACK_BLEND_EQ 0x200
52 #define VIA_FALLBACK_BLEND_FUNC 0x400
53 #define VIA_FALLBACK_USER_DISABLE 0x800
54
55 #define VIA_DMA_BUFSIZ 5000
56 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 256)
57
58 #define VIA_NO_CLIPRECTS 0x1
59
60
61 /* Use the templated vertex formats:
62 */
63 #define TAG(x) via##x
64 #include "tnl_dd/t_dd_vertex.h"
65 #undef TAG
66
67 typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
68 viaVertex *);
69 typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
70 typedef void (*via_point_func)(viaContextPtr, viaVertex *);
71
72 typedef struct {
73 drm_handle_t handle;
74 drmSize size;
75 GLuint offset;
76 GLuint index;
77 GLuint pitch;
78 GLuint bpp;
79 char *map;
80 GLuint orig; /* The drawing origin,
81 * at (drawX,drawY) in screen space.
82 */
83 char *origMap;
84 } viaBuffer, *viaBufferPtr;
85
86
87 struct via_context_t {
88 GLint refcount;
89 GLcontext *glCtx;
90 GLcontext *shareCtx;
91 viaBuffer front;
92 viaBuffer back;
93 viaBuffer depth;
94 GLboolean hasBack;
95 GLboolean hasDepth;
96 GLboolean hasStencil;
97 GLboolean hasAccum;
98 GLuint depthBits;
99 GLuint stencilBits;
100
101 GLboolean have_hw_stencil;
102 GLuint ClearDepth;
103 GLuint depth_clear_mask;
104 GLuint stencil_clear_mask;
105 GLfloat depth_max;
106 GLfloat polygon_offset_scale;
107
108 GLubyte *dma;
109 viaRegion tex;
110
111 GLuint isAGP;
112
113 /* Textures
114 */
115 viaTextureObjectPtr CurrentTexObj[2];
116 struct via_texture_object_t TexObjList;
117 struct via_texture_object_t SwappedOut;
118 memHeap_t *texHeap;
119
120 /* Bit flag to keep 0track of fallbacks.
121 */
122 GLuint Fallback;
123
124 /* State for via_vb.c and via_tris.c.
125 */
126 GLuint newState; /* _NEW_* flags */
127 GLuint newEmitState; /* _NEW_* flags */
128 GLuint setupNewInputs;
129 GLuint setupIndex;
130 GLuint renderIndex;
131 GLmatrix ViewportMatrix;
132 GLenum renderPrimitive;
133 GLenum hwPrimitive;
134 unsigned char *verts;
135
136 /* drmBufPtr dma_buffer;
137 */
138 GLuint dmaLow;
139 GLuint dmaCliprectAddr;
140 GLuint dmaLastPrim;
141 GLboolean useAgp;
142
143
144 /* Fallback rasterization functions
145 */
146 via_point_func drawPoint;
147 via_line_func drawLine;
148 via_tri_func drawTri;
149
150 /* Hardware register
151 */
152 GLuint regCmdA;
153 GLuint regCmdA_End;
154 GLuint regCmdB;
155
156 GLuint regEnable;
157 GLuint regHFBBMSKL;
158 GLuint regHROP;
159
160 GLuint regHZWTMD;
161 GLuint regHSTREF;
162 GLuint regHSTMD;
163
164 GLuint regHATMD;
165 GLuint regHABLCsat;
166 GLuint regHABLCop;
167 GLuint regHABLAsat;
168 GLuint regHABLAop;
169 GLuint regHABLRCa;
170 GLuint regHABLRFCa;
171 GLuint regHABLRCbias;
172 GLuint regHABLRCb;
173 GLuint regHABLRFCb;
174 GLuint regHABLRAa;
175 GLuint regHABLRAb;
176 GLuint regHFogLF;
177 GLuint regHFogCL;
178 GLuint regHFogCH;
179
180 GLuint regHLP;
181 GLuint regHLPRF;
182
183 GLuint regHTXnTB_0;
184 GLuint regHTXnMPMD_0;
185 GLuint regHTXnTBLCsat_0;
186 GLuint regHTXnTBLCop_0;
187 GLuint regHTXnTBLMPfog_0;
188 GLuint regHTXnTBLAsat_0;
189 GLuint regHTXnTBLRCb_0;
190 GLuint regHTXnTBLRAa_0;
191 GLuint regHTXnTBLRFog_0;
192 /*=* John Sheng [2003.7.18] texture combine *=*/
193 GLuint regHTXnTBLRCa_0;
194 GLuint regHTXnTBLRCc_0;
195 GLuint regHTXnTBLRCbias_0;
196
197 GLuint regHTXnTB_1;
198 GLuint regHTXnMPMD_1;
199 GLuint regHTXnTBLCsat_1;
200 GLuint regHTXnTBLCop_1;
201 GLuint regHTXnTBLMPfog_1;
202 GLuint regHTXnTBLAsat_1;
203 GLuint regHTXnTBLRCb_1;
204 GLuint regHTXnTBLRAa_1;
205 GLuint regHTXnTBLRFog_1;
206
207 /* Hardware state
208 */
209 GLuint dirty;
210 int vertexSize;
211 int vertexFormat;
212 GLint lastStamp;
213
214 GLenum TexEnvImageFmt[2];
215 GLuint ClearColor;
216 GLuint ClearMask;
217
218 /* DRI stuff
219 */
220 GLuint needClip;
221 GLframebuffer *glBuffer;
222 GLboolean doPageFlip;
223 /*=* John Sheng [2003.5.31] flip *=*/
224 GLuint currentPage;
225
226 viaBuffer *drawBuffer;
227 viaBuffer *readBuffer;
228 int drawX; /* origin of drawable in draw buffer */
229 int drawY;
230
231 int drawW;
232 int drawH;
233
234 int drawXoff;
235 GLuint numClipRects; /* cliprects for that buffer */
236 drm_clip_rect_t *pClipRects;
237
238 int lastSwap;
239 int texAge;
240 int ctxAge;
241 int dirtyAge;
242
243 GLboolean scissor;
244 drm_clip_rect_t drawRect;
245 drm_clip_rect_t scissorRect;
246
247 drm_context_t hHWContext;
248 drm_hw_lock_t *driHwLock;
249 int driFd;
250 __DRInativeDisplay *display;
251
252 __DRIdrawablePrivate *driDrawable;
253 __DRIscreenPrivate *driScreen;
254 viaScreenPrivate *viaScreen;
255 drm_via_sarea_t *sarea;
256 volatile GLuint* regMMIOBase;
257 volatile GLuint* pnGEMode;
258 volatile GLuint* regEngineStatus;
259 volatile GLuint* regTranSet;
260 volatile GLuint* regTranSpace;
261 GLuint* agpBase;
262 GLuint drawType;
263
264 GLuint nDoneFirstFlip;
265 GLuint agpFullCount;
266
267 /* Configuration cache
268 */
269 driOptionCache optionCache;
270
271 GLuint vblank_flags;
272 GLuint vbl_seq;
273
274 int64_t swap_ust;
275 int64_t swap_missed_ust;
276
277 GLuint swap_count;
278 GLuint swap_missed_count;
279
280 PFNGLXGETUSTPROC get_ust;
281
282 };
283
284
285
286 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
287
288 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
289 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
290
291
292 /* Lock the hardware and validate our state.
293 */
294 #define LOCK_HARDWARE(vmesa) \
295 do { \
296 char __ret = 0; \
297 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
298 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
299 if (__ret) \
300 viaGetLock(vmesa, 0); \
301 } while (0)
302
303
304 /* Release the kernel lock.
305 */
306 #define UNLOCK_HARDWARE(vmesa) \
307 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
308
309 #define WAIT_IDLE(vmesa) \
310 do { \
311 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
312 break; \
313 } while (1)
314
315
316 #ifdef DEBUG
317 extern GLuint VIA_DEBUG;
318 #else
319 #define VIA_DEBUG 0
320 #endif
321
322
323 extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
324 extern void viaLock(viaContextPtr vmesa, GLuint flags);
325 extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
326 extern void viaEmitHwStateLocked(viaContextPtr vmesa);
327 extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
328 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
329 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
330 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
331 extern void viaXMesaWindowMoved(viaContextPtr vmesa);
332
333 extern void viaTexCombineState(viaContextPtr vmesa,
334 const struct gl_tex_env_combine_state * combine, unsigned unit );
335
336 /* Via hw already adjusted for GL pixel centers:
337 */
338 #define SUBPIXEL_X 0
339 #define SUBPIXEL_Y 0
340
341 /* TODO XXX _SOLO temp defines to make code compilable */
342 #ifndef GLX_PBUFFER_BIT
343 #define GLX_PBUFFER_BIT 0x00000004
344 #endif
345 #ifndef GLX_WINDOW_BIT
346 #define GLX_WINDOW_BIT 0x00000001
347 #endif
348 #ifndef VERT_BIT_CLIP
349 #define VERT_BIT_CLIP 0x1000000
350 #endif
351
352 #endif