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