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"
42 #include "tnl/t_vertex.h"
44 #include "savagetex.h"
46 #include "xmlconfig.h"
48 /* Reasons to fallback on all primitives.
50 #define SAVAGE_FALLBACK_TEXTURE 0x1
51 #define SAVAGE_FALLBACK_DRAW_BUFFER 0x2
52 #define SAVAGE_FALLBACK_READ_BUFFER 0x4
53 #define SAVAGE_FALLBACK_COLORMASK 0x8
54 #define SAVAGE_FALLBACK_SPECULAR 0x10
55 #define SAVAGE_FALLBACK_LOGICOP 0x20
56 /*frank 2001/11/12 add the stencil fallbak*/
57 #define SAVAGE_FALLBACK_STENCIL 0x40
58 #define SAVAGE_FALLBACK_RENDERMODE 0x80
59 #define SAVAGE_FALLBACK_BLEND_EQ 0x100
60 #define SAVAGE_FALLBACK_NORAST 0x200
61 #define SAVAGE_FALLBACK_PROJ_TEXTURE 0x400
66 /* for savagectx.new_state - manage GL->driver state changes
68 #define SAVAGE_NEW_TEXTURE 0x1
69 #define SAVAGE_NEW_CULL 0x2
71 /* What needs to be changed for the current vertex dma buffer?
74 #define SAVAGE_UPLOAD_LOCAL 0x1 /* DrawLocalCtrl (S4) or
75 DrawCtrl and ZBufCtrl (S3D) */
76 #define SAVAGE_UPLOAD_TEX0 0x2 /* texture unit 0 */
77 #define SAVAGE_UPLOAD_TEX1 0x4 /* texture unit 1 (S4 only) */
78 #define SAVAGE_UPLOAD_FOGTBL 0x8 /* fog table */
79 #define SAVAGE_UPLOAD_GLOBAL 0x10 /* most global regs */
80 #define SAVAGE_UPLOAD_TEXGLOBAL 0x20 /* TexBlendColor (S4 only) */
81 #define SAVAGE_UPLOAD_CLIPRECTS 0x1000 /* FIXME: get rid of this */
83 /*define the max numer of vertex in vertex buf*/
84 #define SAVAGE_MAX_VERTEXS 0x10000
86 /* Don't make it too big. We don't want to buffer up a whole frame
87 * that would force the application to wait later. */
88 #define SAVAGE_CMDBUF_SIZE 1024
89 #define SAVAGE_MAX_VERTS_PENDING 1024
91 /* Use the templated vertex formats:
93 #define TAG(x) savage##x
94 #include "tnl_dd/t_dd_vertex.h"
97 typedef void (*savage_tri_func
)( savageContextPtr
, savageVertex
*,
98 savageVertex
*, savageVertex
* );
99 typedef void (*savage_line_func
)( savageContextPtr
,
100 savageVertex
*, savageVertex
* );
101 typedef void (*savage_point_func
)( savageContextPtr
, savageVertex
* );
104 /**************************************************************
105 **************** enums for chip IDs ************************
106 **************************************************************/
108 #define CHIP_S3GX3MS1NB 0x8A25
109 #define CHIP_S3GX3MS1NBK 0x8A26
110 #define CHIP_S3TWISTER 0x8D01
111 #define CHIP_S3TWISTERK 0x8D02
112 #define CHIP_S3TWISTER_P4M 0x8D04
113 #define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
114 #define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
115 #define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
116 #define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
117 #define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
119 #define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
120 imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
121 imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
122 imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
123 imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
124 imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
125 imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
126 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
127 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
128 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
131 struct savage_vtxbuf_t
{
132 GLuint total
, used
, flushed
; /* in 32 bit units */
133 GLuint idx
; /* for DMA buffers */
137 struct savage_cmdbuf_t
{
138 GLuint size
; /* size in qwords */
139 drm_savage_cmd_header_t
*base
; /* initial state starts here */
140 drm_savage_cmd_header_t
*start
; /* drawing/state commands start here */
141 drm_savage_cmd_header_t
*write
; /* append stuff here */
145 struct savage_context_t
{
151 savageTextureObjectPtr CurrentTexObj
[2];
153 struct savage_texture_object_t TexObjList
[SAVAGE_NR_TEX_HEAPS
];
154 struct savage_texture_object_t SwappedOut
;
166 savageRegisters regs
, oldRegs
, globalRegMask
;
168 /* Manage our own state */
174 struct savage_cmdbuf_t cmdBuf
;
177 struct savage_vtxbuf_t dmaVtxBuf
, clientVtxBuf
;
178 struct savage_vtxbuf_t
*vtxBuf
;
181 GLuint apertureBase
[5];
182 GLuint aperturePitch
;
183 /* Manage hardware state */
185 GLboolean lostContext
;
186 memHeap_t
*texHeap
[SAVAGE_NR_TEX_HEAPS
];
188 /* One of the few bits of hardware state that can't be calculated
189 * completely on the fly:
196 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
197 GLuint vertex_attr_count
;
198 char *verts
; /* points to tnl->clipspace.vertex_buf */
200 /* Rasterization state
202 GLuint SetupNewInputs
;
207 GLenum raster_primitive
;
208 GLenum render_primitive
;
214 /* Fallback rasterization functions
216 savage_point_func draw_point
;
217 savage_line_func draw_line
;
218 savage_tri_func draw_tri
;
220 /* Funny mesa mirrors
225 GLfloat hw_viewport
[16];
230 GLframebuffer
*glBuffer
;
232 /* Two flags to keep track of fallbacks. */
237 /* These refer to the current draw (front vs. back) buffer:
239 char *drawMap
; /* draw buffer address in virtual mem */
241 int drawX
; /* origin of drawable in draw buffer */
243 GLuint numClipRects
; /* cliprects for that buffer */
245 drm_clip_rect_t
*pClipRects
;
247 /* use this bit to support single/double buffer */
249 /* use this to indicate Fullscreen mode */
250 GLuint IsFullScreen
; /* FIXME - open/close fullscreen is gone, is this needed? */
251 GLuint backup_frontOffset
;
252 GLuint backup_backOffset
;
253 GLuint backup_frontBitmapDesc
;
255 GLuint backup_streamFIFO
;
256 GLuint NotFirstFrame
;
262 GLuint any_contend
; /* throttle me harder */
265 GLboolean scissorChanged
;
266 drm_clip_rect_t draw_rect
;
267 drm_clip_rect_t scissor_rect
;
269 /*Texture aging and DMA based aging*/
270 unsigned int texAge
[SAVAGE_NR_TEX_HEAPS
];
272 drm_context_t hHWContext
;
273 drm_hw_lock_t
*driHwLock
;
276 __DRIdrawablePrivate
*driDrawable
;
277 __DRIdrawablePrivate
*driReadable
;
280 * Drawable used by Mesa for software fallbacks for reading and
281 * writing. It is set by Mesa's \c SetBuffer callback, and will always be
282 * either \c mga_context_t::driDrawable or \c mga_context_t::driReadable.
284 __DRIdrawablePrivate
*mesa_drawable
;
286 __DRIscreenPrivate
*driScreen
;
287 savageScreenPrivate
*savageScreen
;
288 drm_savage_sarea_t
*sarea
;
290 GLboolean hw_stencil
;
292 /* Configuration cache
294 driOptionCache optionCache
;
299 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
301 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
302 * preprocessor symbol, and equal to zero.
305 extern int SAVAGE_DEBUG
;
308 #define DEBUG_FALLBACKS 0x001
309 #define DEBUG_VERBOSE_API 0x002
310 #define DEBUG_VERBOSE_LRU 0x004
311 #define DEBUG_VERBOSE_MSG 0x008
312 #define DEBUG_DMA 0x010
314 #define TARGET_FRONT 0x0
315 #define TARGET_BACK 0x1
316 #define TARGET_DEPTH 0x2
318 #define SUBPIXEL_X -0.5
319 #define SUBPIXEL_Y -0.375