2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
29 typedef struct via_context_t viaContext
;
30 typedef struct via_context_t
*viaContextPtr
;
31 typedef struct via_texture_object_t
*viaTextureObjectPtr
;
39 #include "via_screen.h"
41 #include "via_common.h"
42 #include "xf86drmVIA.h"
44 #include "../../../../../include/extensions/Xinerama.h"
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
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
73 /* Use the templated vertex formats:
76 #include "tnl_dd/t_dd_vertex.h"
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)))
90 typedef void (*via_tri_func
)(viaContextPtr
, viaVertex
*, viaVertex
*,
92 typedef void (*via_line_func
)(viaContextPtr
, viaVertex
*, viaVertex
*);
93 typedef void (*via_point_func
)(viaContextPtr
, viaVertex
*);
103 } viaBuffer
, *viaBufferPtr
;
111 } viaDmaBuffer
, *viaDmaBufferPtr
;
113 struct via_context_t
{
117 unsigned char* front_base
;
123 GLboolean hasStencil
;
134 viaTextureObjectPtr CurrentTexObj
[2];
135 struct via_texture_object_t TexObjList
;
136 struct via_texture_object_t SwappedOut
;
139 /* Bit flag to keep 0track of fallbacks.
143 /* Temporaries for translating away float colors:
145 struct gl_client_array UbyteColor
;
146 struct gl_client_array UbyteSecondaryColor
;
148 /* State for via_vb.c and via_tris.c.
150 GLuint newState
; /* _NEW_* flags */
151 GLuint setupNewInputs
;
154 GLmatrix ViewportMatrix
;
155 GLenum renderPrimitive
;
156 GLenum reducedPrimitive
;
158 unsigned char *verts
;
160 /* drmBufPtr dma_buffer;
162 unsigned char* dmaAddr
;
169 GLboolean uploadCliprects
;
171 GLuint needUploadAllState
;
172 GLuint primitiveRendered
;
175 /* Fallback rasterization functions
177 via_point_func drawPoint
;
178 via_line_func drawLine
;
179 via_tri_func drawTri
;
202 GLuint regHABLRCbias
;
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
;
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
;
242 int vertexStrideShift
;
244 GLboolean stippleInHw
;
246 GLenum TexEnvImageFmt
[2];
251 GLframebuffer
*glBuffer
;
252 GLboolean doPageFlip
;
253 /*=* John Sheng [2003.5.31] flip *=*/
255 char *drawMap
; /* draw buffer address in virtual mem */
257 int drawX
; /* origin of drawable in draw buffer */
264 XineramaScreenInfo
*xsi
;
267 drm_clip_rect_t
*pSaamRects
;
275 GLuint numClipRects
; /* cliprects for that buffer */
276 drm_clip_rect_t
*pClipRects
;
284 drm_clip_rect_t drawRect
;
285 drm_clip_rect_t scissorRect
;
287 drm_context_t hHWContext
;
288 drm_hw_lock_t
*driHwLock
;
290 __DRInativeDisplay
*display
;
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
;
303 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
306 /*#define DMA_OFFSET 16*/
307 #define DMA_OFFSET 32
308 /*#define PERFORMANCE_MEASURE*/
310 extern GLuint VIA_PERFORMANCE
;
312 #ifdef PERFORMANCE_MEASURE
313 #define HASH_TABLE_SIZE 1000
314 #define HASH_TABLE_DEPTH 10
319 extern hash_element hash_table
[HASH_TABLE_SIZE
][HASH_TABLE_DEPTH
];
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++; \
330 else if (!strcmp(hash_table[h_index][h_depth].func, __FUNCTION__)) { \
331 hash_table[h_index][h_depth].count++; \
339 GLuint h_index,h_depth; \
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++; \
349 else if (!strcmp(hash_table[h_index][h_depth].func, strcat(str, "_X"))) { \
350 hash_table[h_index][h_depth].count++; \
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); \
367 #else /* PERFORMANCE_MEASURE */
373 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
375 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
376 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
379 /* Lock the hardware and validate our state.
382 #define LOCK_HARDWARE(vmesa) \
385 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
386 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
388 viaGetLock(vmesa, 0); \
391 /*=* John Sheng [2003.6.20] fix pci *=*/
392 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
393 #define LOCK_HARDWARE(vmesa) \
397 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
398 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
400 viaGetLock(vmesa, 0); \
407 #define LOCK_HARDWARE(vmesa) \
411 /* Release the kernel lock.
414 #define UNLOCK_HARDWARE(vmesa) \
415 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
417 /*=* John Sheng [2003.6.20] fix pci *=*/
418 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
419 #define UNLOCK_HARDWARE(vmesa) \
421 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext); \
425 #define UNLOCK_HARDWARE(vmesa) \
430 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
434 #define LOCK_HARDWARE_QUIESCENT(vmesa) \
436 LOCK_HARDWARE(vmesa); \
437 viaRegetLockQuiescent(vmesa); \
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
);
454 #define SUBPIXEL_X -.5
455 #define SUBPIXEL_Y -.5
457 /* TODO XXX _SOLO temp defines to make code compilable */
458 #ifndef GLX_PBUFFER_BIT
459 #define GLX_PBUFFER_BIT 0x00000004
461 #ifndef GLX_WINDOW_BIT
462 #define GLX_WINDOW_BIT 0x00000001
464 #ifndef VERT_BIT_CLIP
465 #define VERT_BIT_CLIP 0x1000000