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"
87 typedef void (*via_tri_func
)(viaContextPtr
, viaVertex
*, viaVertex
*,
89 typedef void (*via_line_func
)(viaContextPtr
, viaVertex
*, viaVertex
*);
90 typedef void (*via_point_func
)(viaContextPtr
, viaVertex
*);
100 } viaBuffer
, *viaBufferPtr
;
108 } viaDmaBuffer
, *viaDmaBufferPtr
;
110 struct via_context_t
{
114 unsigned char* front_base
;
120 GLboolean hasStencil
;
131 viaTextureObjectPtr CurrentTexObj
[2];
132 struct via_texture_object_t TexObjList
;
133 struct via_texture_object_t SwappedOut
;
136 /* Bit flag to keep 0track of fallbacks.
140 /* Temporaries for translating away float colors:
142 struct gl_client_array UbyteColor
;
143 struct gl_client_array UbyteSecondaryColor
;
145 /* State for via_vb.c and via_tris.c.
147 GLuint newState
; /* _NEW_* flags */
148 GLuint setupNewInputs
;
151 GLmatrix ViewportMatrix
;
152 GLenum renderPrimitive
;
153 GLenum reducedPrimitive
;
155 unsigned char *verts
;
157 /* drmBufPtr dma_buffer;
159 unsigned char* dmaAddr
;
166 GLboolean uploadCliprects
;
168 GLuint needUploadAllState
;
169 GLuint primitiveRendered
;
172 /* Fallback rasterization functions
174 via_point_func drawPoint
;
175 via_line_func drawLine
;
176 via_tri_func drawTri
;
199 GLuint regHABLRCbias
;
212 GLuint regHTXnMPMD_0
;
213 GLuint regHTXnTBLCsat_0
;
214 GLuint regHTXnTBLCop_0
;
215 GLuint regHTXnTBLMPfog_0
;
216 GLuint regHTXnTBLAsat_0
;
217 GLuint regHTXnTBLRCb_0
;
218 GLuint regHTXnTBLRAa_0
;
219 GLuint regHTXnTBLRFog_0
;
220 /*=* John Sheng [2003.7.18] texture combine *=*/
221 GLuint regHTXnTBLRCa_0
;
222 GLuint regHTXnTBLRCc_0
;
223 GLuint regHTXnTBLRCbias_0
;
226 GLuint regHTXnMPMD_1
;
227 GLuint regHTXnTBLCsat_1
;
228 GLuint regHTXnTBLCop_1
;
229 GLuint regHTXnTBLMPfog_1
;
230 GLuint regHTXnTBLAsat_1
;
231 GLuint regHTXnTBLRCb_1
;
232 GLuint regHTXnTBLRAa_1
;
233 GLuint regHTXnTBLRFog_1
;
239 int vertexStrideShift
;
241 GLboolean stippleInHw
;
243 GLenum TexEnvImageFmt
[2];
248 GLframebuffer
*glBuffer
;
249 GLboolean doPageFlip
;
250 /*=* John Sheng [2003.5.31] flip *=*/
252 char *drawMap
; /* draw buffer address in virtual mem */
254 int drawX
; /* origin of drawable in draw buffer */
261 XineramaScreenInfo
*xsi
;
264 drm_clip_rect_t
*pSaamRects
;
272 GLuint numClipRects
; /* cliprects for that buffer */
273 drm_clip_rect_t
*pClipRects
;
281 drm_clip_rect_t drawRect
;
282 drm_clip_rect_t scissorRect
;
284 drm_context_t hHWContext
;
285 drm_hw_lock_t
*driHwLock
;
287 __DRInativeDisplay
*display
;
289 __DRIdrawablePrivate
*driDrawable
;
290 __DRIscreenPrivate
*driScreen
;
291 viaScreenPrivate
*viaScreen
;
292 drm_via_sarea_t
*sarea
;
293 volatile GLuint
* regMMIOBase
;
294 volatile GLuint
* pnGEMode
;
295 volatile GLuint
* regEngineStatus
;
296 volatile GLuint
* regTranSet
;
297 volatile GLuint
* regTranSpace
;
300 /*=* John Sheng [2003.12.9] Tuxracer & VQ *=*/
303 /*#define DMA_OFFSET 16*/
304 #define DMA_OFFSET 32
305 /*#define PERFORMANCE_MEASURE*/
307 extern GLuint VIA_PERFORMANCE
;
309 #ifdef PERFORMANCE_MEASURE
310 #define HASH_TABLE_SIZE 1000
311 #define HASH_TABLE_DEPTH 10
316 extern hash_element hash_table
[HASH_TABLE_SIZE
][HASH_TABLE_DEPTH
];
319 GLuint h_index,h_depth; \
320 h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE); \
321 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
322 if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) { \
323 sprintf(hash_table[h_index][h_depth].func, "%s", __FUNCTION__); \
324 hash_table[h_index][h_depth].count++; \
327 else if (!strcmp(hash_table[h_index][h_depth].func, __FUNCTION__)) { \
328 hash_table[h_index][h_depth].count++; \
336 GLuint h_index,h_depth; \
338 strcpy(str, __FUNCTION__); \
339 h_index = (GLuint)(((GLuint) __FUNCTION__)%HASH_TABLE_SIZE); \
340 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
341 if (!strcmp(hash_table[h_index][h_depth].func, "NULL")) { \
342 sprintf(hash_table[h_index][h_depth].func, "%s_X", __FUNCTION__); \
343 hash_table[h_index][h_depth].count++; \
346 else if (!strcmp(hash_table[h_index][h_depth].func, strcat(str, "_X"))) { \
347 hash_table[h_index][h_depth].count++; \
355 GLuint h_size, h_depth; \
356 for (h_size = 0; h_size < HASH_TABLE_SIZE; h_size++) { \
357 for (h_depth = 0; h_depth < HASH_TABLE_DEPTH; h_depth++) { \
358 if (hash_table[h_size][h_depth].count) { \
359 fprintf(stderr, "func:%s count:%d\n", hash_table[h_size][h_depth].func, hash_table[h_size][h_depth].count); \
364 #else /* PERFORMANCE_MEASURE */
370 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
372 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
373 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
376 /* Lock the hardware and validate our state.
379 #define LOCK_HARDWARE(vmesa) \
382 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
383 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
385 viaGetLock(vmesa, 0); \
388 /*=* John Sheng [2003.6.20] fix pci *=*/
389 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
390 #define LOCK_HARDWARE(vmesa) \
394 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
395 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
397 viaGetLock(vmesa, 0); \
404 #define LOCK_HARDWARE(vmesa) \
408 /* Release the kernel lock.
411 #define UNLOCK_HARDWARE(vmesa) \
412 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
414 /*=* John Sheng [2003.6.20] fix pci *=*/
415 /*=* John Sheng [2003.7.25] fix viewperf black shadow *=*/
416 #define UNLOCK_HARDWARE(vmesa) \
418 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext); \
422 #define UNLOCK_HARDWARE(vmesa) \
427 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
431 #define LOCK_HARDWARE_QUIESCENT(vmesa) \
433 LOCK_HARDWARE(vmesa); \
434 viaRegetLockQuiescent(vmesa); \
438 extern GLuint VIA_DEBUG
;
439 extern GLuint DRAW_FRONT
;
440 extern void viaGetLock(viaContextPtr vmesa
, GLuint flags
);
441 extern void viaLock(viaContextPtr vmesa
, GLuint flags
);
442 extern void viaUnLock(viaContextPtr vmesa
, GLuint flags
);
443 extern void viaEmitHwStateLocked(viaContextPtr vmesa
);
444 extern void viaEmitScissorValues(viaContextPtr vmesa
, int box_nr
, int emit
);
445 extern void viaEmitDrawingRectangle(viaContextPtr vmesa
);
446 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa
);
447 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa
);
448 extern void viaReAllocateBuffers(GLframebuffer
*drawbuffer
);
449 extern void viaXMesaWindowMoved(viaContextPtr vmesa
);
451 extern void viaTexCombineState(viaContextPtr vmesa
,
452 const struct gl_tex_env_combine_state
* combine
, unsigned unit
);
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