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