Push a number of global variables into the viaContext struct.
[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 #ifdef USE_XINERAMA
44 #include "../../../../../include/extensions/Xinerama.h"
45 #endif
46 #define VIA_FALLBACK_TEXTURE 0x1
47 #define VIA_FALLBACK_DRAW_BUFFER 0x2
48 #define VIA_FALLBACK_READ_BUFFER 0x4
49 #define VIA_FALLBACK_COLORMASK 0x8
50 #define VIA_FALLBACK_SPECULAR 0x20
51 #define VIA_FALLBACK_LOGICOP 0x40
52 #define VIA_FALLBACK_RENDERMODE 0x80
53 #define VIA_FALLBACK_STENCIL 0x100
54 #define VIA_FALLBACK_BLEND_EQ 0x200
55 #define VIA_FALLBACK_BLEND_FUNC 0x400
56
57 #define VIA_UPLOAD_NONE 0x0000
58 #define VIA_UPLOAD_ALPHATEST 0x0001
59 #define VIA_UPLOAD_BLEND 0x0002
60 #define VIA_UPLOAD_FOG 0x0004
61 #define VIA_UPLOAD_MASK_ROP 0x0008
62 #define VIA_UPLOAD_LINESTIPPLE 0x0010
63 #define VIA_UPLOAD_POLYGONSTIPPLE 0x0020
64 #define VIA_UPLOAD_DEPTH 0x0040
65 #define VIA_UPLOAD_TEXTURE 0x0080
66 #define VIA_UPLOAD_STENCIL 0x0100
67 #define VIA_UPLOAD_CLIPPING 0x0200
68 #define VIA_UPLOAD_DESTBUFFER 0x0400
69 #define VIA_UPLOAD_DEPTHBUFFER 0x0800
70 #define VIA_UPLOAD_ENABLE 0x0800
71 #define VIA_UPLOAD_ALL 0x1000
72
73 #define VIA_DMA_BUFSIZ 500000
74
75 /* Use the templated vertex formats:
76 */
77 #define TAG(x) via##x
78 #include "tnl_dd/t_dd_vertex.h"
79 #undef TAG
80
81 #define RightOf 1
82 #define LeftOf 2
83 #define Down 4
84 #define Up 8
85 #define S0 16
86 #define S1 32
87 #define P_MASK 0x0f;
88 #define S_MASK 0x30;
89 typedef void (*via_tri_func)(viaContextPtr, viaVertex *, viaVertex *,
90 viaVertex *);
91 typedef void (*via_line_func)(viaContextPtr, viaVertex *, viaVertex *);
92 typedef void (*via_point_func)(viaContextPtr, viaVertex *);
93
94 typedef struct {
95 drm_handle_t handle;
96 drmSize size;
97 GLuint offset;
98 GLuint index;
99 GLuint pitch;
100 GLuint bpp;
101 char *map;
102 } viaBuffer, *viaBufferPtr;
103
104
105 struct via_context_t {
106 GLint refcount;
107 GLcontext *glCtx;
108 GLcontext *shareCtx;
109 unsigned char* front_base;
110 viaBuffer front;
111 viaBuffer back;
112 viaBuffer depth;
113 GLboolean hasBack;
114 GLboolean hasDepth;
115 GLboolean hasStencil;
116 GLboolean hasAccum;
117 GLuint depthBits;
118 GLuint stencilBits;
119 GLuint *dma;
120 viaRegion tex;
121
122 GLuint isAGP;
123
124 /* Textures
125 */
126 viaTextureObjectPtr CurrentTexObj[2];
127 struct via_texture_object_t TexObjList;
128 struct via_texture_object_t SwappedOut;
129 memHeap_t *texHeap;
130
131 /* Bit flag to keep 0track of fallbacks.
132 */
133 GLuint Fallback;
134
135 /* Temporaries for translating away float colors:
136 */
137 struct gl_client_array UbyteColor;
138 struct gl_client_array UbyteSecondaryColor;
139
140 /* State for via_vb.c and via_tris.c.
141 */
142 GLuint newState; /* _NEW_* flags */
143 GLuint setupNewInputs;
144 GLuint setupIndex;
145 GLuint renderIndex;
146 GLmatrix ViewportMatrix;
147 GLenum renderPrimitive;
148 GLenum reducedPrimitive;
149 GLuint hwPrimitive;
150 unsigned char *verts;
151
152 /* drmBufPtr dma_buffer;
153 */
154 unsigned char* dmaAddr;
155 GLuint dmaLow;
156 GLuint dmaHigh;
157 GLuint dmaLastPrim;
158 GLboolean useAgp;
159
160 GLboolean uploadCliprects;
161
162 GLuint needUploadAllState;
163 GLuint primitiveRendered;
164
165
166 /* Fallback rasterization functions
167 */
168 via_point_func drawPoint;
169 via_line_func drawLine;
170 via_tri_func drawTri;
171
172 /* Hardware register
173 */
174 GLuint regCmdA;
175 GLuint regCmdA_End;
176 GLuint regCmdB;
177
178 GLuint regEnable;
179 GLuint regHFBBMSKL;
180 GLuint regHROP;
181
182 GLuint regHZWTMD;
183 GLuint regHSTREF;
184 GLuint regHSTMD;
185
186 GLuint regHATMD;
187 GLuint regHABLCsat;
188 GLuint regHABLCop;
189 GLuint regHABLAsat;
190 GLuint regHABLAop;
191 GLuint regHABLRCa;
192 GLuint regHABLRFCa;
193 GLuint regHABLRCbias;
194 GLuint regHABLRCb;
195 GLuint regHABLRFCb;
196 GLuint regHABLRAa;
197 GLuint regHABLRAb;
198 GLuint regHFogLF;
199 GLuint regHFogCL;
200 GLuint regHFogCH;
201
202 GLuint regHLP;
203 GLuint regHLPRF;
204
205 GLuint regHTXnTB_0;
206 GLuint regHTXnMPMD_0;
207 GLuint regHTXnTBLCsat_0;
208 GLuint regHTXnTBLCop_0;
209 GLuint regHTXnTBLMPfog_0;
210 GLuint regHTXnTBLAsat_0;
211 GLuint regHTXnTBLRCb_0;
212 GLuint regHTXnTBLRAa_0;
213 GLuint regHTXnTBLRFog_0;
214 /*=* John Sheng [2003.7.18] texture combine *=*/
215 GLuint regHTXnTBLRCa_0;
216 GLuint regHTXnTBLRCc_0;
217 GLuint regHTXnTBLRCbias_0;
218
219 GLuint regHTXnTB_1;
220 GLuint regHTXnMPMD_1;
221 GLuint regHTXnTBLCsat_1;
222 GLuint regHTXnTBLCop_1;
223 GLuint regHTXnTBLMPfog_1;
224 GLuint regHTXnTBLAsat_1;
225 GLuint regHTXnTBLRCb_1;
226 GLuint regHTXnTBLRAa_1;
227 GLuint regHTXnTBLRFog_1;
228
229 /* Hardware state
230 */
231 GLuint dirty;
232 int vertexSize;
233 int vertexStrideShift;
234 GLint lastStamp;
235 GLboolean stippleInHw;
236
237 GLenum TexEnvImageFmt[2];
238 GLuint ClearColor;
239 /* DRI stuff
240 */
241 GLuint needClip;
242 GLframebuffer *glBuffer;
243 GLboolean doPageFlip;
244 /*=* John Sheng [2003.5.31] flip *=*/
245 GLuint currentPage;
246 char *drawMap; /* draw buffer address in virtual mem */
247 char *readMap;
248 int drawX; /* origin of drawable in draw buffer */
249 int drawY;
250
251 int drawW;
252 int drawH;
253 GLuint saam;
254 #ifdef USE_XINERAMA
255 XineramaScreenInfo *xsi;
256 #endif
257 int drawXoffSaam;
258 drm_clip_rect_t *pSaamRects;
259 int drawXSaam;
260 int drawYSaam;
261 GLuint numSaamRects;
262
263 int drawPitch;
264 int readPitch;
265 int drawXoff;
266 GLuint numClipRects; /* cliprects for that buffer */
267 drm_clip_rect_t *pClipRects;
268
269 int lastSwap;
270 int texAge;
271 int ctxAge;
272 int dirtyAge;
273
274 GLboolean scissor;
275 drm_clip_rect_t drawRect;
276 drm_clip_rect_t scissorRect;
277
278 drm_context_t hHWContext;
279 drm_hw_lock_t *driHwLock;
280 int driFd;
281 __DRInativeDisplay *display;
282
283 __DRIdrawablePrivate *driDrawable;
284 __DRIscreenPrivate *driScreen;
285 viaScreenPrivate *viaScreen;
286 drm_via_sarea_t *sarea;
287 volatile GLuint* regMMIOBase;
288 volatile GLuint* pnGEMode;
289 volatile GLuint* regEngineStatus;
290 volatile GLuint* regTranSet;
291 volatile GLuint* regTranSpace;
292 GLuint* agpBase;
293 GLuint drawType;
294
295 GLuint nDoneFirstFlip;
296 GLuint agpFullCount;
297
298 /* Configuration cache
299 */
300 driOptionCache optionCache;
301
302 GLuint vblank_flags;
303 GLuint vbl_seq;
304
305 int64_t swap_ust;
306 int64_t swap_missed_ust;
307
308 GLuint swap_count;
309 GLuint swap_missed_count;
310
311 PFNGLXGETUSTPROC get_ust;
312
313 };
314 /*#define DMA_OFFSET 16*/
315 #define DMA_OFFSET 32
316 /*#define PERFORMANCE_MEASURE*/
317
318 extern GLuint VIA_PERFORMANCE;
319
320 #ifdef PERFORMANCE_MEASURE
321 #define HASH_TABLE_SIZE 1000
322 #define HASH_TABLE_DEPTH 10
323 typedef struct {
324 char func[50];
325 GLuint count;
326 } hash_element;
327 extern hash_element hash_table[HASH_TABLE_SIZE][HASH_TABLE_DEPTH];
328 #define P_M \
329 do { \
330 GLuint h_index,h_depth; \
331 h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE); \
332 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
333 if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) { \
334 sprintf(hash_table[h_index][h_depth].func, "%s", __FUNCTION__); \
335 hash_table[h_index][h_depth].count++; \
336 break; \
337 } \
338 else if (!strcmp(hash_table[h_index][h_depth].func, __FUNCTION__)) { \
339 hash_table[h_index][h_depth].count++; \
340 break; \
341 } \
342 } \
343 } while (0)
344
345 #define P_M_X \
346 do { \
347 GLuint h_index,h_depth; \
348 char str[80]; \
349 strcpy(str, __FUNCTION__); \
350 h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE); \
351 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
352 if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) { \
353 sprintf(hash_table[h_index][h_depth].func, "%s_X", __FUNCTION__); \
354 hash_table[h_index][h_depth].count++; \
355 break; \
356 } \
357 else if (!strcmp(hash_table[h_index][h_depth].func, strcat(str, "_X"))) { \
358 hash_table[h_index][h_depth].count++; \
359 break; \
360 } \
361 } \
362 } while (0)
363
364 #define P_M_R \
365 do { \
366 GLuint h_size, h_depth; \
367 for (h_size = 0; h_size < HASH_TABLE_SIZE; h_size++) { \
368 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
369 if (hash_table[h_size][h_depth].count) { \
370 fprintf(stderr, "func:%s count:%d\n", hash_table[h_size][h_depth].func, hash_table[h_size][h_depth].count); \
371 } \
372 } \
373 } \
374 } while (0)
375 #else /* PERFORMANCE_MEASURE */
376 #define P_M {}
377 #define P_M_X {}
378 #define P_M_R {}
379 #endif
380
381 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
382
383 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
384 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
385
386
387 /* Lock the hardware and validate our state.
388 */
389 /*
390 #define LOCK_HARDWARE(vmesa) \
391 do { \
392 char __ret = 0; \
393 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
394 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
395 if (__ret) \
396 viaGetLock(vmesa, 0); \
397 } while (0)
398 */
399 /*=* John Sheng [2003.6.20] fix pci *=*/
400 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
401 #define LOCK_HARDWARE(vmesa) \
402 if(1) \
403 do { \
404 char __ret = 0; \
405 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
406 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
407 if (__ret) \
408 viaGetLock(vmesa, 0); \
409 } while (0); \
410 else \
411 viaLock(vmesa, 0)
412
413
414 /*
415 #define LOCK_HARDWARE(vmesa) \
416 viaLock(vmesa, 0);
417 */
418
419 /* Release the kernel lock.
420 */
421 /*
422 #define UNLOCK_HARDWARE(vmesa) \
423 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
424 */
425 /*=* John Sheng [2003.6.20] fix pci *=*/
426 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
427 #define UNLOCK_HARDWARE(vmesa) \
428 if(1) \
429 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext); \
430 else \
431 viaUnLock(vmesa, 0);
432 /*
433 #define UNLOCK_HARDWARE(vmesa) \
434 viaUnLock(vmesa, 0);
435 */
436 #define WAIT_IDLE \
437 while (1) { \
438 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
439 break; \
440 }
441
442 #define LOCK_HARDWARE_QUIESCENT(vmesa) \
443 do { \
444 LOCK_HARDWARE(vmesa); \
445 viaRegetLockQuiescent(vmesa); \
446 } while (0)
447
448
449 #ifdef DEBUG
450 extern GLuint VIA_DEBUG;
451 #else
452 #define VIA_DEBUG 0
453 #endif
454
455
456 extern GLuint DRAW_FRONT;
457 extern void viaGetLock(viaContextPtr vmesa, GLuint flags);
458 extern void viaLock(viaContextPtr vmesa, GLuint flags);
459 extern void viaUnLock(viaContextPtr vmesa, GLuint flags);
460 extern void viaEmitHwStateLocked(viaContextPtr vmesa);
461 extern void viaEmitScissorValues(viaContextPtr vmesa, int box_nr, int emit);
462 extern void viaEmitDrawingRectangle(viaContextPtr vmesa);
463 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa);
464 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa);
465 extern void viaReAllocateBuffers(GLframebuffer *drawbuffer);
466 extern void viaXMesaWindowMoved(viaContextPtr vmesa);
467
468 extern void viaTexCombineState(viaContextPtr vmesa,
469 const struct gl_tex_env_combine_state * combine, unsigned unit );
470
471 #define SUBPIXEL_X -.5
472 #define SUBPIXEL_Y -.5
473
474 /* TODO XXX _SOLO temp defines to make code compilable */
475 #ifndef GLX_PBUFFER_BIT
476 #define GLX_PBUFFER_BIT 0x00000004
477 #endif
478 #ifndef GLX_WINDOW_BIT
479 #define GLX_WINDOW_BIT 0x00000001
480 #endif
481 #ifndef VERT_BIT_CLIP
482 #define VERT_BIT_CLIP 0x1000000
483 #endif
484
485 #endif