Converted the Savage driver to the new DRI interface and enabled compilation
[mesa.git] / src / mesa / drivers / dri / savage / savagecontext.h
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 */
24
25
26
27 #ifndef SAVAGECONTEXT_INC
28 #define SAVAGECONTEXT_INC
29
30 typedef struct savage_context_t savageContext;
31 typedef struct savage_context_t *savageContextPtr;
32 typedef struct savage_texture_object_t *savageTextureObjectPtr;
33
34 #include <X11/Xlibint.h>
35 #include "dri_util.h"
36 #include "mtypes.h"
37 #include "xf86drm.h"
38 #include "drm.h"
39 #include "savage_drm.h"
40 #include "savage_init.h"
41 #include "mm.h"
42 #include "tnl/t_vertex.h"
43
44 #include "savagetex.h"
45 #include "savagedma.h"
46
47 /* Reasons to fallback on all primitives.
48 */
49 #define SAVAGE_FALLBACK_TEXTURE 0x1
50 #define SAVAGE_FALLBACK_DRAW_BUFFER 0x2
51 #define SAVAGE_FALLBACK_READ_BUFFER 0x4
52 #define SAVAGE_FALLBACK_COLORMASK 0x8
53 #define SAVAGE_FALLBACK_STIPPLE 0x10
54 #define SAVAGE_FALLBACK_SPECULAR 0x20
55 #define SAVAGE_FALLBACK_LOGICOP 0x40
56 /*frank 2001/11/12 add the stencil fallbak*/
57 #define SAVAGE_FALLBACK_STENCIL 0x80
58 #define SAVAGE_FALLBACK_RENDERMODE 0x100
59 #define SAVAGE_FALLBACK_BLEND_EQ 0x200
60
61
62 #define HW_STENCIL 1
63 #define HW_CULL 1
64
65 /* for savagectx.new_state - manage GL->driver state changes
66 */
67 #define SAVAGE_NEW_TEXTURE 0x1
68 #define SAVAGE_NEW_CULL 0x2
69
70
71 /*define the max numer of vertex in vertex buf*/
72 #define SAVAGE_MAX_VERTEXS 0x10000
73
74 /* Use the templated vertex formats:
75 */
76 #define TAG(x) savage##x
77 #include "tnl_dd/t_dd_vertex.h"
78 #undef TAG
79
80 typedef void (*savage_tri_func)( savageContextPtr, savageVertex *,
81 savageVertex *, savageVertex * );
82 typedef void (*savage_line_func)( savageContextPtr,
83 savageVertex *, savageVertex * );
84 typedef void (*savage_point_func)( savageContextPtr, savageVertex * );
85
86
87 /**************************************************************
88 **************** enums for chip IDs ************************
89 **************************************************************/
90
91 #define CHIP_S3GX3MS1NB 0x8A25
92 #define CHIP_S3GX3MS1NBK 0x8A26
93 #define CHIP_S3TWISTER 0x8D01
94 #define CHIP_S3TWISTERK 0x8D02
95 #define CHIP_S3TWISTER_P4M 0x8D04
96 #define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
97 #define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
98 #define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
99 #define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
100 #define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
101
102 #define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
103 imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
104 imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
105 imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
106 imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
107 imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
108 imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
109 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
110 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
111 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
112
113
114
115
116 struct savage_context_t {
117 GLint refcount;
118
119 GLcontext *glCtx;
120
121 int lastTexHeap;
122 savageTextureObjectPtr CurrentTexObj[2];
123
124 struct savage_texture_object_t TexObjList[SAVAGE_NR_TEX_HEAPS];
125 struct savage_texture_object_t SwappedOut;
126
127 GLuint c_texupload;
128 GLuint c_texusage;
129 GLuint tex_thrash;
130
131 GLuint TextureMode;
132
133
134 /* Hardware state
135 */
136
137 savageRegisters regs, oldRegs, globalRegMask;
138
139 /* Manage our own state */
140 GLuint new_state;
141 GLuint new_gl_state;
142
143 GLuint BCIBase;
144 GLuint MMIO_BASE;
145
146 /* DMA command buffer */
147 DMABuffer_t DMABuf;
148
149 /* aperture base */
150 GLuint apertureBase[5];
151 GLuint aperturePitch;
152 /* Manage hardware state */
153 GLuint dirty;
154 GLboolean lostContext;
155 memHeap_t *texHeap[SAVAGE_NR_TEX_HEAPS];
156 GLuint bTexEn1;
157 /* One of the few bits of hardware state that can't be calculated
158 * completely on the fly:
159 */
160 GLuint LcsCullMode;
161
162 /* Vertex state
163 */
164 GLuint vertex_size;
165 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
166 GLuint vertex_attr_count;
167 char *verts; /* points to tnl->clipspace.vertex_buf */
168
169 /* Rasterization state
170 */
171 GLuint SetupNewInputs;
172 GLuint SetupIndex;
173 GLuint RenderIndex;
174
175 GLuint hw_primitive;
176 GLenum raster_primitive;
177 GLenum render_primitive;
178
179 GLuint DrawPrimitiveCmd;
180
181 /* Fallback rasterization functions
182 */
183 savage_point_func draw_point;
184 savage_line_func draw_line;
185 savage_tri_func draw_tri;
186
187 /* Funny mesa mirrors
188 */
189 GLuint MonoColor;
190 GLuint ClearColor;
191 GLfloat depth_scale;
192 GLfloat hw_viewport[16];
193 /* DRI stuff */
194 drmBufPtr vertex_dma_buffer;
195
196 GLframebuffer *glBuffer;
197
198 /* Two flags to keep track of fallbacks. */
199 GLuint Fallback;
200
201 GLuint needClip;
202
203 /* These refer to the current draw (front vs. back) buffer:
204 */
205 char *drawMap; /* draw buffer address in virtual mem */
206 char *readMap;
207 int drawX; /* origin of drawable in draw buffer */
208 int drawY;
209 GLuint numClipRects; /* cliprects for that buffer */
210 GLint currentClip;
211 drm_clip_rect_t *pClipRects;
212
213 /* use this bit to support single/double buffer */
214 GLuint IsDouble;
215 /* use this to indicate Fullscreen mode */
216 GLuint IsFullScreen; /* FIXME - open/close fullscreen is gone, is this needed? */
217 GLuint backup_frontOffset;
218 GLuint backup_backOffset;
219 GLuint backup_frontBitmapDesc;
220 GLuint toggle;
221 GLuint backup_streamFIFO;
222 GLuint NotFirstFrame;
223
224 GLuint lastSwap;
225 GLuint secondLastSwap;
226 GLuint ctxAge;
227 GLuint dirtyAge;
228 GLuint any_contend; /* throttle me harder */
229
230 GLuint scissor;
231 GLboolean scissorChanged;
232 drm_clip_rect_t draw_rect;
233 drm_clip_rect_t scissor_rect;
234 drm_clip_rect_t tmp_boxes[2][SAVAGE_NR_SAREA_CLIPRECTS];
235 /*Texture aging and DMA based aging*/
236 unsigned int texAge[SAVAGE_NR_TEX_HEAPS];
237
238 drm_context_t hHWContext;
239 drm_hw_lock_t *driHwLock;
240 GLuint driFd;
241
242 __DRIdrawablePrivate *driDrawable;
243 __DRIdrawablePrivate *driReadable;
244
245 /**
246 * Drawable used by Mesa for software fallbacks for reading and
247 * writing. It is set by Mesa's \c SetBuffer callback, and will always be
248 * either \c mga_context_t::driDrawable or \c mga_context_t::driReadable.
249 */
250 __DRIdrawablePrivate *mesa_drawable;
251
252 __DRIscreenPrivate *driScreen;
253 savageScreenPrivate *savageScreen;
254 drm_savage_sarea_t *sarea;
255
256 GLboolean hw_stencil;
257
258 /*shadow pointer*/
259 volatile GLuint *shadowPointer;
260 volatile GLuint *eventTag1;
261 GLuint shadowCounter;
262 GLboolean shadowStatus;
263 };
264
265 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
266
267 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
268 * preprocessor symbol, and equal to zero.
269 */
270 #define SAVAGE_DEBUG 0
271 #ifndef SAVAGE_DEBUG
272 #warning "Debugging enabled - expect reduced performance"
273 extern int SAVAGE_DEBUG;
274 #endif
275
276 #define DEBUG_VERBOSE_2D 0x1
277 #define DEBUG_VERBOSE_RING 0x8
278 #define DEBUG_VERBOSE_OUTREG 0x10
279 #define DEBUG_ALWAYS_SYNC 0x40
280 #define DEBUG_VERBOSE_MSG 0x80
281 #define DEBUG_NO_OUTRING 0x100
282 #define DEBUG_NO_OUTREG 0x200
283 #define DEBUG_VERBOSE_API 0x400
284 #define DEBUG_VALIDATE_RING 0x800
285 #define DEBUG_VERBOSE_LRU 0x1000
286 #define DEBUG_VERBOSE_DRI 0x2000
287 #define DEBUG_VERBOSE_IOCTL 0x4000
288
289 #define TARGET_FRONT 0x0
290 #define TARGET_BACK 0x1
291 #define TARGET_DEPTH 0x2
292
293 #define SAVAGEDEBUG 0
294 #define _SAVAGE_DEBUG
295 /*frank remove the least debug information*/
296 #ifdef _SAVAGE_DEBUG
297 #define fprintf fprintf
298 #else
299 #define fprintf(...)
300 #endif
301
302 #define SUBPIXEL_X -0.5
303 #define SUBPIXEL_Y -0.375
304
305 #endif