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.
27 #ifndef SAVAGECONTEXT_INC
28 #define SAVAGECONTEXT_INC
30 typedef struct savage_context_t savageContext
;
31 typedef struct savage_context_t
*savageContextPtr
;
32 typedef struct savage_texture_object_t
*savageTextureObjectPtr
;
34 #include <X11/Xlibint.h>
39 #include "savage_drm.h"
40 #include "savage_init.h"
41 #include "savage_3d_reg.h"
43 #include "tnl/t_vertex.h"
47 #include "xmlconfig.h"
49 /* Reasons to fallback on all primitives.
51 #define SAVAGE_FALLBACK_TEXTURE 0x1
52 #define SAVAGE_FALLBACK_DRAW_BUFFER 0x2
53 #define SAVAGE_FALLBACK_READ_BUFFER 0x4
54 #define SAVAGE_FALLBACK_COLORMASK 0x8
55 #define SAVAGE_FALLBACK_SPECULAR 0x10
56 #define SAVAGE_FALLBACK_LOGICOP 0x20
57 /*frank 2001/11/12 add the stencil fallbak*/
58 #define SAVAGE_FALLBACK_STENCIL 0x40
59 #define SAVAGE_FALLBACK_RENDERMODE 0x80
60 #define SAVAGE_FALLBACK_BLEND_EQ 0x100
61 #define SAVAGE_FALLBACK_NORAST 0x200
62 #define SAVAGE_FALLBACK_PROJ_TEXTURE 0x400
67 /* for savagectx.new_state - manage GL->driver state changes
69 #define SAVAGE_NEW_TEXTURE 0x1
70 #define SAVAGE_NEW_CULL 0x2
72 /* What needs to be changed for the current vertex dma buffer?
75 #define SAVAGE_UPLOAD_LOCAL 0x1 /* DrawLocalCtrl (S4) or
76 DrawCtrl and ZBufCtrl (S3D) */
77 #define SAVAGE_UPLOAD_TEX0 0x2 /* texture unit 0 */
78 #define SAVAGE_UPLOAD_TEX1 0x4 /* texture unit 1 (S4 only) */
79 #define SAVAGE_UPLOAD_FOGTBL 0x8 /* fog table */
80 #define SAVAGE_UPLOAD_GLOBAL 0x10 /* most global regs */
81 #define SAVAGE_UPLOAD_TEXGLOBAL 0x20 /* TexBlendColor (S4 only) */
82 #define SAVAGE_UPLOAD_CLIPRECTS 0x1000 /* FIXME: get rid of this */
84 /*define the max numer of vertex in vertex buf*/
85 #define SAVAGE_MAX_VERTEXS 0x10000
87 /* Don't make it too big. We don't want to buffer up a whole frame
88 * that would force the application to wait later. */
89 #define SAVAGE_CMDBUF_SIZE 1024
90 #define SAVAGE_MAX_VERTS_PENDING 1024
92 /* Use the templated vertex formats:
94 #define TAG(x) savage##x
95 #include "tnl_dd/t_dd_vertex.h"
98 typedef void (*savage_tri_func
)( savageContextPtr
, savageVertex
*,
99 savageVertex
*, savageVertex
* );
100 typedef void (*savage_line_func
)( savageContextPtr
,
101 savageVertex
*, savageVertex
* );
102 typedef void (*savage_point_func
)( savageContextPtr
, savageVertex
* );
105 /**************************************************************
106 **************** enums for chip IDs ************************
107 **************************************************************/
109 #define CHIP_S3GX3MS1NB 0x8A25
110 #define CHIP_S3GX3MS1NBK 0x8A26
111 #define CHIP_S3TWISTER 0x8D01
112 #define CHIP_S3TWISTERK 0x8D02
113 #define CHIP_S3TWISTER_P4M 0x8D04
114 #define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
115 #define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
116 #define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
117 #define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
118 #define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
120 #define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
121 imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
122 imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
123 imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
124 imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
125 imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
126 imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
127 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
128 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
129 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
132 struct savage_vtxbuf_t
{
133 GLuint total
, used
, flushed
; /* in 32 bit units */
134 GLuint idx
; /* for DMA buffers */
138 struct savage_cmdbuf_t
{
139 GLuint size
; /* size in qwords */
140 drm_savage_cmd_header_t
*base
; /* initial state starts here */
141 drm_savage_cmd_header_t
*start
; /* drawing/state commands start here */
142 drm_savage_cmd_header_t
*write
; /* append stuff here */
145 struct savage_elt_t
{
146 GLuint n
; /* number of elts currently allocated */
147 drm_savage_cmd_header_t
*cmd
; /* the indexed drawing command */
151 struct savage_context_t
{
157 driTexHeap
*textureHeaps
[SAVAGE_NR_TEX_HEAPS
];
158 driTextureObject swapped
;
160 driTextureObject
*CurrentTexObj
[2];
165 savageRegisters regs
, oldRegs
, globalRegMask
;
167 /* Manage our own state */
173 struct savage_cmdbuf_t cmdBuf
;
175 /* Elt book-keeping */
176 struct savage_elt_t elts
;
180 struct savage_vtxbuf_t dmaVtxBuf
, clientVtxBuf
;
181 struct savage_vtxbuf_t
*vtxBuf
;
184 GLuint apertureBase
[5];
185 GLuint aperturePitch
;
186 /* Manage hardware state */
188 GLboolean lostContext
;
190 /* One of the few bits of hardware state that can't be calculated
191 * completely on the fly:
198 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
199 GLuint vertex_attr_count
;
200 char *verts
; /* points to tnl->clipspace.vertex_buf */
202 /* Rasterization state
204 GLuint SetupNewInputs
;
209 GLenum raster_primitive
;
210 GLenum render_primitive
;
216 /* Fallback rasterization functions
218 savage_point_func draw_point
;
219 savage_line_func draw_line
;
220 savage_tri_func draw_tri
;
222 /* Funny mesa mirrors
227 GLfloat hw_viewport
[16];
232 GLframebuffer
*glBuffer
;
234 /* Two flags to keep track of fallbacks. */
239 /* These refer to the current draw (front vs. back) buffer:
241 char *drawMap
; /* draw buffer address in virtual mem */
243 int drawX
; /* origin of drawable in draw buffer */
245 GLuint numClipRects
; /* cliprects for that buffer */
247 drm_clip_rect_t
*pClipRects
;
249 /* use this bit to support single/double buffer */
251 /* use this to indicate Fullscreen mode */
252 GLuint IsFullScreen
; /* FIXME - open/close fullscreen is gone, is this needed? */
253 GLuint backup_frontOffset
;
254 GLuint backup_backOffset
;
255 GLuint backup_frontBitmapDesc
;
257 GLuint backup_streamFIFO
;
258 GLuint NotFirstFrame
;
264 GLuint any_contend
; /* throttle me harder */
267 GLboolean scissorChanged
;
268 drm_clip_rect_t draw_rect
;
269 drm_clip_rect_t scissor_rect
;
271 drm_context_t hHWContext
;
272 drm_hw_lock_t
*driHwLock
;
275 __DRIdrawablePrivate
*driDrawable
;
276 __DRIdrawablePrivate
*driReadable
;
279 * Drawable used by Mesa for software fallbacks for reading and
280 * writing. It is set by Mesa's \c SetBuffer callback, and will always be
281 * either \c mga_context_t::driDrawable or \c mga_context_t::driReadable.
283 __DRIdrawablePrivate
*mesa_drawable
;
285 __DRIscreenPrivate
*driScreen
;
286 savageScreenPrivate
*savageScreen
;
287 drm_savage_sarea_t
*sarea
;
289 GLboolean hw_stencil
;
291 /* Performance counters
293 GLuint c_textureSwaps
;
295 /* Configuration cache
297 driOptionCache optionCache
;
300 GLboolean float_depth
;
301 GLboolean enable_fastpath
;
302 GLboolean enable_vdma
;
305 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
307 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
308 * preprocessor symbol, and equal to zero.
311 extern int SAVAGE_DEBUG
;
314 #define DEBUG_FALLBACKS 0x001
315 #define DEBUG_VERBOSE_API 0x002
316 #define DEBUG_VERBOSE_LRU 0x004
317 #define DEBUG_VERBOSE_MSG 0x008
318 #define DEBUG_DMA 0x010
319 #define DEBUG_STATE 0x020
321 #define TARGET_FRONT 0x0
322 #define TARGET_BACK 0x1
323 #define TARGET_DEPTH 0x2
325 #define SUBPIXEL_X -0.5
326 #define SUBPIXEL_Y -0.375