Add flag to clear texture caches after texture upload.
[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 #define VIA_FALLBACK_ALPHATEST 0x4000
70
71 #define VIA_DMA_BUFSIZ 4096
72 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
73
74 #define VIA_NO_CLIPRECTS 0x1
75
76
77 /* Use the templated vertex formats:
78 */
79 #define TAG(x) via##x
80 #include "tnl_dd/t_dd_vertex.h"
81 #undef TAG
82
83 typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
84 viaVertex *);
85 typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
86 typedef void (*via_point_func)(viaContextPtr, viaVertex *);
87
88 typedef struct {
89 drm_handle_t handle;
90 drmSize size;
91 GLuint offset;
92 GLuint index;
93 GLuint pitch;
94 GLuint bpp;
95 char *map;
96 GLuint orig; /* The drawing origin,
97 * at (drawX,drawY) in screen space.
98 */
99 char *origMap;
100 } viaBuffer, *viaBufferPtr;
101
102
103 struct via_context_t {
104 GLint refcount;
105 GLcontext *glCtx;
106 GLcontext *shareCtx;
107 viaBuffer front;
108 viaBuffer back;
109 viaBuffer depth;
110 GLboolean hasBack;
111 GLboolean hasDepth;
112 GLboolean hasStencil;
113 GLboolean hasAccum;
114 GLuint depthBits;
115 GLuint stencilBits;
116
117 GLboolean have_hw_stencil;
118 GLuint ClearDepth;
119 GLuint depth_clear_mask;
120 GLuint stencil_clear_mask;
121 GLfloat depth_max;
122 GLfloat polygon_offset_scale;
123
124 GLubyte *dma;
125 viaRegion tex;
126
127 GLuint isAGP;
128
129 /* Textures
130 */
131 viaTextureObjectPtr CurrentTexObj[2];
132 struct via_texture_object_t TexObjList;
133 struct via_texture_object_t SwappedOut;
134 memHeap_t *texHeap;
135
136 /* Bit flag to keep 0track of fallbacks.
137 */
138 GLuint Fallback;
139
140 /* State for via_tris.c.
141 */
142 GLuint newState; /* _NEW_* flags */
143 GLuint newEmitState; /* _NEW_* flags */
144 GLuint newRenderState; /* _NEW_* flags */
145
146 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
147 GLuint vertex_attr_count;
148
149 GLuint setupIndex;
150 GLuint renderIndex;
151 GLmatrix ViewportMatrix;
152 GLenum renderPrimitive;
153 GLenum hwPrimitive;
154 unsigned char *verts;
155
156 /* drmBufPtr dma_buffer;
157 */
158 GLuint dmaLow;
159 GLuint dmaCliprectAddr;
160 GLuint dmaLastPrim;
161 GLboolean useAgp;
162
163
164 /* Fallback rasterization functions
165 */
166 via_point_func drawPoint;
167 via_line_func drawLine;
168 via_tri_func drawTri;
169
170 /* Hardware register
171 */
172 GLuint regCmdA;
173 GLuint regCmdA_End;
174 GLuint regCmdB;
175
176 GLuint regEnable;
177 GLuint regHFBBMSKL;
178 GLuint regHROP;
179
180 GLuint regHZWTMD;
181 GLuint regHSTREF;
182 GLuint regHSTMD;
183
184 GLuint regHATMD;
185 GLuint regHABLCsat;
186 GLuint regHABLCop;
187 GLuint regHABLAsat;
188 GLuint regHABLAop;
189 GLuint regHABLRCa;
190 GLuint regHABLRFCa;
191 GLuint regHABLRCbias;
192 GLuint regHABLRCb;
193 GLuint regHABLRFCb;
194 GLuint regHABLRAa;
195 GLuint regHABLRAb;
196 GLuint regHFogLF;
197 GLuint regHFogCL;
198 GLuint regHFogCH;
199
200 GLuint regHLP;
201 GLuint regHLPRF;
202
203 GLuint regHTXnTB_0;
204 GLuint regHTXnMPMD_0;
205 GLuint regHTXnTBLCsat_0;
206 GLuint regHTXnTBLCop_0;
207 GLuint regHTXnTBLMPfog_0;
208 GLuint regHTXnTBLAsat_0;
209 GLuint regHTXnTBLRCb_0;
210 GLuint regHTXnTBLRAa_0;
211 GLuint regHTXnTBLRFog_0;
212 /*=* John Sheng [2003.7.18] texture combine *=*/
213 GLuint regHTXnTBLRCa_0;
214 GLuint regHTXnTBLRCc_0;
215 GLuint regHTXnTBLRCbias_0;
216
217 GLuint regHTXnTB_1;
218 GLuint regHTXnMPMD_1;
219 GLuint regHTXnTBLCsat_1;
220 GLuint regHTXnTBLCop_1;
221 GLuint regHTXnTBLMPfog_1;
222 GLuint regHTXnTBLAsat_1;
223 GLuint regHTXnTBLRCb_1;
224 GLuint regHTXnTBLRAa_1;
225 GLuint regHTXnTBLRFog_1;
226
227 int vertexSize;
228 int hwVertexSize;
229 GLboolean ptexHack;
230 int coloroffset;
231 int specoffset;
232
233 GLint lastStamp;
234
235 GLenum TexEnvImageFmt[2];
236 GLuint ClearColor;
237 GLuint ClearMask;
238
239 /* DRI stuff
240 */
241 GLuint needClip;
242 GLframebuffer *glBuffer;
243 GLboolean doPageFlip;
244 /*=* John Sheng [2003.5.31] flip *=*/
245 GLuint currentPage;
246
247 viaBuffer *drawBuffer;
248 viaBuffer *readBuffer;
249 int drawX; /* origin of drawable in draw buffer */
250 int drawY;
251
252 int drawW;
253 int drawH;
254
255 int drawXoff;
256 GLuint numClipRects; /* cliprects for that buffer */
257 drm_clip_rect_t *pClipRects;
258
259 int lastSwap;
260 int texAge;
261 int ctxAge;
262 int dirtyAge;
263
264 GLboolean scissor;
265 drm_clip_rect_t drawRect;
266 drm_clip_rect_t scissorRect;
267
268 drm_context_t hHWContext;
269 drm_hw_lock_t *driHwLock;
270 int driFd;
271 __DRInativeDisplay *display;
272
273 __DRIdrawablePrivate *driDrawable;
274 __DRIscreenPrivate *driScreen;
275 viaScreenPrivate *viaScreen;
276 drm_via_sarea_t *sarea;
277 volatile GLuint* regMMIOBase;
278 volatile GLuint* pnGEMode;
279 volatile GLuint* regEngineStatus;
280 volatile GLuint* regTranSet;
281 volatile GLuint* regTranSpace;
282 GLuint* agpBase;
283 GLuint drawType;
284
285 GLuint nDoneFirstFlip;
286 GLuint agpFullCount;
287
288 GLboolean strictConformance;
289 GLboolean clearTexCache;
290
291 /* Configuration cache
292 */
293 driOptionCache optionCache;
294
295 GLuint vblank_flags;
296 GLuint vbl_seq;
297
298 int64_t swap_ust;
299 int64_t swap_missed_ust;
300
301 GLuint swap_count;
302 GLuint swap_missed_count;
303
304 GLuint stipple[32];
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