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.
33 #include "main/mtypes.h"
35 #include "tnl/t_vertex.h"
37 #include "via_screen.h"
43 /* Chip tags. These are used to group the adapters into
55 #define VIA_FALLBACK_TEXTURE 0x1
56 #define VIA_FALLBACK_DRAW_BUFFER 0x2
57 #define VIA_FALLBACK_READ_BUFFER 0x4
58 #define VIA_FALLBACK_COLORMASK 0x8
59 #define VIA_FALLBACK_SPECULAR 0x20
60 #define VIA_FALLBACK_LOGICOP 0x40
61 #define VIA_FALLBACK_RENDERMODE 0x80
62 #define VIA_FALLBACK_STENCIL 0x100
63 #define VIA_FALLBACK_BLEND_EQ 0x200
64 #define VIA_FALLBACK_BLEND_FUNC 0x400
65 #define VIA_FALLBACK_USER_DISABLE 0x800
66 #define VIA_FALLBACK_PROJ_TEXTURE 0x1000
67 #define VIA_FALLBACK_POLY_STIPPLE 0x2000
69 #define VIA_DMA_BUFSIZ 4096
70 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
72 #define VIA_NO_CLIPRECTS 0x1
75 /* Use the templated vertex formats:
78 #include "tnl_dd/t_dd_vertex.h"
81 typedef void (*via_tri_func
)(struct via_context
*, viaVertex
*, viaVertex
*,
83 typedef void (*via_line_func
)(struct via_context
*, viaVertex
*, viaVertex
*);
84 typedef void (*via_point_func
)(struct via_context
*, viaVertex
*);
87 * Derived from gl_renderbuffer.
89 struct via_renderbuffer
{
90 struct gl_renderbuffer Base
; /* must be first! */
98 GLuint orig
; /* The drawing origin,
99 * at (drawX,drawY) in screen space.
103 int drawX
; /* origin of drawable in draw buffer */
108 __DRIdrawable
*dPriv
;
112 #define VIA_MAX_TEXLEVELS 10
114 struct via_tex_buffer
{
115 struct via_tex_buffer
*next
, *prev
;
116 struct via_texture_image
*image
;
118 unsigned long offset
;
121 unsigned char *bufAddr
;
128 struct via_texture_image
{
129 struct gl_texture_image image
;
130 struct via_tex_buffer
*texMem
;
134 struct via_texture_object
{
135 struct gl_texture_object obj
; /* The "parent" object */
141 GLuint regTexWidthLog2
[2];
142 GLuint regTexHeightLog2
[2];
143 GLuint regTexBaseH
[4];
147 } regTexBaseAndPitch
[12];
149 GLint firstLevel
, lastLevel
; /* upload tObj->Image[first .. lastLevel] */
156 struct gl_context
*glCtx
;
157 struct gl_context
*shareCtx
;
159 /* XXX These don't belong here. They should be per-drawable state. */
160 struct via_renderbuffer front
;
161 struct via_renderbuffer back
;
162 struct via_renderbuffer depth
;
163 struct via_renderbuffer stencil
; /* mirrors depth */
164 struct via_renderbuffer breadcrumb
;
168 GLboolean hasStencil
;
173 GLboolean have_hw_stencil
;
175 GLuint depth_clear_mask
;
176 GLuint stencil_clear_mask
;
178 GLfloat polygon_offset_scale
;
183 /* Bit flag to keep 0track of fallbacks.
187 /* State for via_tris.c.
189 GLuint newState
; /* _NEW_* flags */
190 GLuint newEmitState
; /* _NEW_* flags */
191 GLuint newRenderState
; /* _NEW_* flags */
193 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
194 GLuint vertex_attr_count
;
198 GLmatrix ViewportMatrix
;
199 GLenum renderPrimitive
;
202 unsigned char *verts
;
204 /* drmBufPtr dma_buffer;
207 GLuint dmaCliprectAddr
;
212 /* Fallback rasterization functions
214 via_point_func drawPoint
;
215 via_line_func drawLine
;
216 via_tri_func drawTri
;
238 GLuint regHABLRCbias
;
250 GLuint regHTXnCLOD
[2];
252 GLuint regHTXnMPMD
[2];
253 GLuint regHTXnTBLCsat
[2];
254 GLuint regHTXnTBLCop
[2];
255 GLuint regHTXnTBLMPfog
[2];
256 GLuint regHTXnTBLAsat
[2];
257 GLuint regHTXnTBLRCb
[2];
258 GLuint regHTXnTBLRAa
[2];
259 GLuint regHTXnTBLRFog
[2];
260 GLuint regHTXnTBLRCa
[2];
261 GLuint regHTXnTBLRCc
[2];
262 GLuint regHTXnTBLRCbias
[2];
263 GLuint regHTXnTBC
[2];
264 GLuint regHTXnTRAH
[2];
279 GLboolean doPageFlip
;
281 struct via_renderbuffer
*drawBuffer
;
283 GLuint numClipRects
; /* cliprects for that buffer */
284 drm_clip_rect_t
*pClipRects
;
287 drm_clip_rect_t drawRect
;
288 drm_clip_rect_t scissorRect
;
290 drm_context_t hHWContext
;
291 drm_hw_lock_t
*driHwLock
;
295 * DRI drawable bound to this context for drawing.
297 __DRIdrawable
*driDrawable
;
300 * DRI drawable bound to this context for reading.
302 __DRIdrawable
*driReadable
;
304 __DRIscreen
*driScreen
;
305 viaScreenPrivate
*viaScreen
;
306 drm_via_sarea_t
*sarea
;
307 volatile GLuint
* regMMIOBase
;
308 volatile GLuint
* pnGEMode
;
309 volatile GLuint
* regEngineStatus
;
310 volatile GLuint
* regTranSet
;
311 volatile GLuint
* regTranSpace
;
315 GLuint nDoneFirstFlip
;
318 GLboolean clearTexCache
;
321 /* Configuration cache
323 driOptionCache optionCache
;
326 int64_t swap_missed_ust
;
329 GLuint swap_missed_count
;
332 GLuint pfCurrentOffset
;
333 GLboolean allowPageFlip
;
335 GLuint lastBreadcrumbRead
;
336 GLuint lastBreadcrumbWrite
;
340 GLuint total_alloc
[VIA_MEM_SYSTEM
+1];
342 struct via_tex_buffer tex_image_list
[VIA_MEM_SYSTEM
+1];
343 struct via_tex_buffer freed_tex_buffers
;
349 #define VIA_CONTEXT(ctx) ((struct via_context *)(ctx->DriverCtx))
353 /* Lock the hardware and validate our state.
355 #define LOCK_HARDWARE(vmesa) \
358 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
359 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
361 viaGetLock(vmesa, 0); \
365 /* Release the kernel lock.
367 #define UNLOCK_HARDWARE(vmesa) \
368 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
372 extern GLuint VIA_DEBUG
;
374 #define DEBUG_TEXTURE 0x1
375 #define DEBUG_STATE 0x2
376 #define DEBUG_IOCTL 0x4
377 #define DEBUG_PRIMS 0x8
378 #define DEBUG_VERTS 0x10
379 #define DEBUG_FALLBACKS 0x20
380 #define DEBUG_VERBOSE 0x40
381 #define DEBUG_DRI 0x80
382 #define DEBUG_DMA 0x100
383 #define DEBUG_SANITY 0x200
384 #define DEBUG_SYNC 0x400
385 #define DEBUG_SLEEP 0x800
386 #define DEBUG_PIXEL 0x1000
387 #define DEBUG_2D 0x2000
390 extern void viaGetLock(struct via_context
*vmesa
, GLuint flags
);
391 extern void viaLock(struct via_context
*vmesa
, GLuint flags
);
392 extern void viaUnLock(struct via_context
*vmesa
, GLuint flags
);
393 extern void viaEmitHwStateLocked(struct via_context
*vmesa
);
394 extern void viaEmitScissorValues(struct via_context
*vmesa
, int box_nr
, int emit
);
395 extern void viaXMesaSetBackClipRects(struct via_context
*vmesa
);
396 extern void viaXMesaSetFrontClipRects(struct via_context
*vmesa
);
397 extern void viaReAllocateBuffers(struct gl_context
*ctx
, struct gl_framebuffer
*drawbuffer
, GLuint width
, GLuint height
);
398 extern void viaXMesaWindowMoved(struct via_context
*vmesa
);
400 extern GLboolean
viaTexCombineState(struct via_context
*vmesa
,
401 const struct gl_tex_env_combine_state
* combine
,
404 /* Via hw already adjusted for GL pixel centers:
409 /* TODO XXX _SOLO temp defines to make code compilable */
410 #ifndef GLX_PBUFFER_BIT
411 #define GLX_PBUFFER_BIT 0x00000004
413 #ifndef GLX_WINDOW_BIT
414 #define GLX_WINDOW_BIT 0x00000001
416 #ifndef VERT_BIT_CLIP
417 #define VERT_BIT_CLIP 0x1000000