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