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) */
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
90 /* Use the templated vertex formats:
92 #define TAG(x) savage##x
93 #include "tnl_dd/t_dd_vertex.h"
96 typedef void (*savage_tri_func
)( savageContextPtr
, savageVertex
*,
97 savageVertex
*, savageVertex
* );
98 typedef void (*savage_line_func
)( savageContextPtr
,
99 savageVertex
*, savageVertex
* );
100 typedef void (*savage_point_func
)( savageContextPtr
, savageVertex
* );
103 /**************************************************************
104 **************** enums for chip IDs ************************
105 **************************************************************/
107 #define CHIP_S3GX3MS1NB 0x8A25
108 #define CHIP_S3GX3MS1NBK 0x8A26
109 #define CHIP_S3TWISTER 0x8D01
110 #define CHIP_S3TWISTERK 0x8D02
111 #define CHIP_S3TWISTER_P4M 0x8D04
112 #define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
113 #define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
114 #define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
115 #define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
116 #define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
118 #define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
119 imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
120 imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
121 imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
122 imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
123 imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
124 imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
125 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
126 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
127 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
130 struct savage_vtxbuf_t
{
131 GLuint total
, used
, flushed
; /* in 32 bit units */
132 GLuint idx
; /* for DMA buffers */
136 struct savage_cmdbuf_t
{
137 GLuint size
; /* size in qwords */
138 drm_savage_cmd_header_t
*base
; /* initial state starts here */
139 drm_savage_cmd_header_t
*start
; /* drawing/state commands start here */
140 drm_savage_cmd_header_t
*write
; /* append stuff here */
143 struct savage_elt_t
{
144 GLuint n
; /* number of elts currently allocated */
145 drm_savage_cmd_header_t
*cmd
; /* the indexed drawing command */
149 struct savage_context_t
{
155 driTexHeap
*textureHeaps
[SAVAGE_NR_TEX_HEAPS
];
156 driTextureObject swapped
;
158 driTextureObject
*CurrentTexObj
[2];
163 savageRegisters regs
, oldRegs
, globalRegMask
;
165 /* Manage our own state */
171 struct savage_cmdbuf_t cmdBuf
;
173 /* Elt book-keeping */
174 struct savage_elt_t elts
;
178 struct savage_vtxbuf_t dmaVtxBuf
, clientVtxBuf
;
179 struct savage_vtxbuf_t
*vtxBuf
;
182 GLubyte
*apertureBase
[5];
183 GLuint aperturePitch
;
184 /* Manage hardware state */
186 GLboolean lostContext
;
188 /* One of the few bits of hardware state that can't be calculated
189 * completely on the fly:
197 struct tnl_attr_map vertex_attrs
[VERT_ATTRIB_MAX
];
198 GLuint vertex_attr_count
;
199 char *verts
; /* points to tnl->clipspace.vertex_buf */
201 /* Rasterization state
203 GLuint SetupNewInputs
;
208 GLenum raster_primitive
;
209 GLenum render_primitive
;
215 /* Fallback rasterization functions
217 savage_point_func draw_point
;
218 savage_line_func draw_line
;
219 savage_tri_func draw_tri
;
221 /* Funny mesa mirrors
226 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 int drawX
; /* origin of drawable in draw buffer */
241 GLuint numClipRects
; /* cliprects for that buffer */
243 drm_clip_rect_t
*pClipRects
;
245 /* use this bit to support single/double buffer */
247 /* use this to indicate Fullscreen mode */
248 GLuint IsFullScreen
; /* FIXME - open/close fullscreen is gone, is this needed? */
249 GLuint backup_frontOffset
;
250 GLuint backup_backOffset
;
251 GLuint backup_frontBitmapDesc
;
253 GLuint backup_streamFIFO
;
254 GLuint NotFirstFrame
;
260 GLuint any_contend
; /* throttle me harder */
262 /* Scissor state needs to be mirrored so buffered commands can be
263 * emitted with the old scissor state when scissor state changes.
271 drm_context_t hHWContext
;
272 drm_hw_lock_t
*driHwLock
;
275 __DRIdrawablePrivate
*driDrawable
;
276 __DRIdrawablePrivate
*driReadable
;
278 __DRIscreenPrivate
*driScreen
;
279 savageScreenPrivate
*savageScreen
;
280 drm_savage_sarea_t
*sarea
;
282 GLboolean hw_stencil
;
284 /* Performance counters
286 GLuint c_textureSwaps
;
288 /* Configuration cache
290 driOptionCache optionCache
;
293 GLboolean float_depth
;
294 GLboolean enable_fastpath
;
295 GLboolean enable_vdma
;
296 GLboolean sync_frames
;
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_TEX 0x004
311 #define DEBUG_VERBOSE_MSG 0x008
312 #define DEBUG_DMA 0x010
313 #define DEBUG_STATE 0x020
315 #define TARGET_FRONT 0x0
316 #define TARGET_BACK 0x1
317 #define TARGET_DEPTH 0x2
319 #define SUBPIXEL_X -0.5
320 #define SUBPIXEL_Y -0.375