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
;
38 #include "tnl/t_vertex.h"
40 #include "via_screen.h"
42 #include "via_common.h"
43 #include "xf86drmVIA.h"
45 #define VIA_FALLBACK_TEXTURE 0x1
46 #define VIA_FALLBACK_DRAW_BUFFER 0x2
47 #define VIA_FALLBACK_READ_BUFFER 0x4
48 #define VIA_FALLBACK_COLORMASK 0x8
49 #define VIA_FALLBACK_SPECULAR 0x20
50 #define VIA_FALLBACK_LOGICOP 0x40
51 #define VIA_FALLBACK_RENDERMODE 0x80
52 #define VIA_FALLBACK_STENCIL 0x100
53 #define VIA_FALLBACK_BLEND_EQ 0x200
54 #define VIA_FALLBACK_BLEND_FUNC 0x400
55 #define VIA_FALLBACK_USER_DISABLE 0x800
56 #define VIA_FALLBACK_PROJ_TEXTURE 0x1000
58 #define VIA_DMA_BUFSIZ 4096
59 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
61 #define VIA_NO_CLIPRECTS 0x1
64 /* Use the templated vertex formats:
67 #include "tnl_dd/t_dd_vertex.h"
70 typedef void (*via_tri_func
)(viaContextPtr
, viaVertex
*, viaVertex
*,
72 typedef void (*via_line_func
)(viaContextPtr
, viaVertex
*, viaVertex
*);
73 typedef void (*via_point_func
)(viaContextPtr
, viaVertex
*);
83 GLuint orig
; /* The drawing origin,
84 * at (drawX,drawY) in screen space.
87 } viaBuffer
, *viaBufferPtr
;
90 struct via_context_t
{
104 GLboolean have_hw_stencil
;
106 GLuint depth_clear_mask
;
107 GLuint stencil_clear_mask
;
109 GLfloat polygon_offset_scale
;
118 viaTextureObjectPtr CurrentTexObj
[2];
119 struct via_texture_object_t TexObjList
;
120 struct via_texture_object_t SwappedOut
;
123 /* Bit flag to keep 0track of fallbacks.
127 /* State for via_tris.c.
129 GLuint newState
; /* _NEW_* flags */
130 GLuint newEmitState
; /* _NEW_* flags */
131 GLuint newRenderState
; /* _NEW_* flags */
133 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
134 GLuint vertex_attr_count
;
138 GLmatrix ViewportMatrix
;
139 GLenum renderPrimitive
;
141 unsigned char *verts
;
143 /* drmBufPtr dma_buffer;
146 GLuint dmaCliprectAddr
;
151 /* Fallback rasterization functions
153 via_point_func drawPoint
;
154 via_line_func drawLine
;
155 via_tri_func drawTri
;
178 GLuint regHABLRCbias
;
191 GLuint regHTXnMPMD_0
;
192 GLuint regHTXnTBLCsat_0
;
193 GLuint regHTXnTBLCop_0
;
194 GLuint regHTXnTBLMPfog_0
;
195 GLuint regHTXnTBLAsat_0
;
196 GLuint regHTXnTBLRCb_0
;
197 GLuint regHTXnTBLRAa_0
;
198 GLuint regHTXnTBLRFog_0
;
199 /*=* John Sheng [2003.7.18] texture combine *=*/
200 GLuint regHTXnTBLRCa_0
;
201 GLuint regHTXnTBLRCc_0
;
202 GLuint regHTXnTBLRCbias_0
;
205 GLuint regHTXnMPMD_1
;
206 GLuint regHTXnTBLCsat_1
;
207 GLuint regHTXnTBLCop_1
;
208 GLuint regHTXnTBLMPfog_1
;
209 GLuint regHTXnTBLAsat_1
;
210 GLuint regHTXnTBLRCb_1
;
211 GLuint regHTXnTBLRAa_1
;
212 GLuint regHTXnTBLRFog_1
;
222 GLenum TexEnvImageFmt
[2];
229 GLframebuffer
*glBuffer
;
230 GLboolean doPageFlip
;
231 /*=* John Sheng [2003.5.31] flip *=*/
234 viaBuffer
*drawBuffer
;
235 viaBuffer
*readBuffer
;
236 int drawX
; /* origin of drawable in draw buffer */
243 GLuint numClipRects
; /* cliprects for that buffer */
244 drm_clip_rect_t
*pClipRects
;
252 drm_clip_rect_t drawRect
;
253 drm_clip_rect_t scissorRect
;
255 drm_context_t hHWContext
;
256 drm_hw_lock_t
*driHwLock
;
258 __DRInativeDisplay
*display
;
260 __DRIdrawablePrivate
*driDrawable
;
261 __DRIscreenPrivate
*driScreen
;
262 viaScreenPrivate
*viaScreen
;
263 drm_via_sarea_t
*sarea
;
264 volatile GLuint
* regMMIOBase
;
265 volatile GLuint
* pnGEMode
;
266 volatile GLuint
* regEngineStatus
;
267 volatile GLuint
* regTranSet
;
268 volatile GLuint
* regTranSpace
;
272 GLuint nDoneFirstFlip
;
275 /* Configuration cache
277 driOptionCache optionCache
;
283 int64_t swap_missed_ust
;
286 GLuint swap_missed_count
;
288 PFNGLXGETUSTPROC get_ust
;
294 #define VIA_CONTEXT(ctx) ((viaContextPtr)(ctx->DriverCtx))
296 #define GET_DISPATCH_AGE(vmesa) vmesa->sarea->lastDispatch
297 #define GET_ENQUEUE_AGE(vmesa) vmesa->sarea->lastEnqueue
300 /* Lock the hardware and validate our state.
302 #define LOCK_HARDWARE(vmesa) \
305 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
306 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
308 viaGetLock(vmesa, 0); \
312 /* Release the kernel lock.
314 #define UNLOCK_HARDWARE(vmesa) \
315 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
317 #define WAIT_IDLE(vmesa) \
319 if ((((GLuint)*vmesa->regEngineStatus) & 0xFFFEFFFF) == 0x00020000) \
325 extern GLuint VIA_DEBUG
;
331 extern void viaGetLock(viaContextPtr vmesa
, GLuint flags
);
332 extern void viaLock(viaContextPtr vmesa
, GLuint flags
);
333 extern void viaUnLock(viaContextPtr vmesa
, GLuint flags
);
334 extern void viaEmitHwStateLocked(viaContextPtr vmesa
);
335 extern void viaEmitScissorValues(viaContextPtr vmesa
, int box_nr
, int emit
);
336 extern void viaXMesaSetBackClipRects(viaContextPtr vmesa
);
337 extern void viaXMesaSetFrontClipRects(viaContextPtr vmesa
);
338 extern void viaReAllocateBuffers(GLframebuffer
*drawbuffer
);
339 extern void viaXMesaWindowMoved(viaContextPtr vmesa
);
341 extern void viaTexCombineState(viaContextPtr vmesa
,
342 const struct gl_tex_env_combine_state
* combine
, unsigned unit
);
344 /* Via hw already adjusted for GL pixel centers:
349 /* TODO XXX _SOLO temp defines to make code compilable */
350 #ifndef GLX_PBUFFER_BIT
351 #define GLX_PBUFFER_BIT 0x00000004
353 #ifndef GLX_WINDOW_BIT
354 #define GLX_WINDOW_BIT 0x00000001
356 #ifndef VERT_BIT_CLIP
357 #define VERT_BIT_CLIP 0x1000000