Added support for ELTS to the _savage_render_stage. Requires at least
[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
46 #include "xmlconfig.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_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
62
63
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 /* What needs to be changed for the current vertex dma buffer?
72 * This will go away!
73 */
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 */
82
83 /*define the max numer of vertex in vertex buf*/
84 #define SAVAGE_MAX_VERTEXS 0x10000
85
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
90
91 /* Use the templated vertex formats:
92 */
93 #define TAG(x) savage##x
94 #include "tnl_dd/t_dd_vertex.h"
95 #undef TAG
96
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 * );
102
103
104 /**************************************************************
105 **************** enums for chip IDs ************************
106 **************************************************************/
107
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*/
118
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 )
129
130
131 struct savage_vtxbuf_t {
132 GLuint total, used, flushed; /* in 32 bit units */
133 GLuint idx; /* for DMA buffers */
134 u_int32_t *buf;
135 };
136
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 */
142 };
143
144 struct savage_elt_t {
145 GLuint n; /* number of elts currently allocated */
146 drm_savage_cmd_header_t *cmd; /* the indexed drawing command */
147 };
148
149
150 struct savage_context_t {
151 GLint refcount;
152
153 GLcontext *glCtx;
154
155 int lastTexHeap;
156 savageTextureObjectPtr CurrentTexObj[2];
157
158 struct savage_texture_object_t TexObjList[SAVAGE_NR_TEX_HEAPS];
159 struct savage_texture_object_t SwappedOut;
160
161 GLuint c_texupload;
162 GLuint c_texusage;
163 GLuint tex_thrash;
164
165 GLuint TextureMode;
166
167
168 /* Hardware state
169 */
170
171 savageRegisters regs, oldRegs, globalRegMask;
172
173 /* Manage our own state */
174 GLuint new_state;
175 GLuint new_gl_state;
176 GLboolean ptexHack;
177
178 /* Command buffer */
179 struct savage_cmdbuf_t cmdBuf;
180
181 /* Elt book-keeping */
182 struct savage_elt_t elts;
183 GLint firstElt;
184
185 /* Vertex buffers */
186 struct savage_vtxbuf_t dmaVtxBuf, clientVtxBuf;
187 struct savage_vtxbuf_t *vtxBuf;
188
189 /* aperture base */
190 GLuint apertureBase[5];
191 GLuint aperturePitch;
192 /* Manage hardware state */
193 GLuint dirty;
194 GLboolean lostContext;
195 memHeap_t *texHeap[SAVAGE_NR_TEX_HEAPS];
196 GLuint bTexEn1;
197 /* One of the few bits of hardware state that can't be calculated
198 * completely on the fly:
199 */
200 GLuint LcsCullMode;
201
202 /* Vertex state
203 */
204 GLuint vertex_size;
205 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
206 GLuint vertex_attr_count;
207 char *verts; /* points to tnl->clipspace.vertex_buf */
208
209 /* Rasterization state
210 */
211 GLuint SetupNewInputs;
212 GLuint SetupIndex;
213 GLuint RenderIndex;
214
215 GLuint hw_primitive;
216 GLenum raster_primitive;
217 GLenum render_primitive;
218
219 GLuint skip;
220 GLubyte HwPrim;
221 GLuint HwVertexSize;
222
223 /* Fallback rasterization functions
224 */
225 savage_point_func draw_point;
226 savage_line_func draw_line;
227 savage_tri_func draw_tri;
228
229 /* Funny mesa mirrors
230 */
231 GLuint MonoColor;
232 GLuint ClearColor;
233 GLfloat depth_scale;
234 GLfloat hw_viewport[16];
235 /* DRI stuff */
236 GLuint bufferSize;
237 GLuint vertsPending;
238
239 GLframebuffer *glBuffer;
240
241 /* Two flags to keep track of fallbacks. */
242 GLuint Fallback;
243
244 GLuint needClip;
245
246 /* These refer to the current draw (front vs. back) buffer:
247 */
248 char *drawMap; /* draw buffer address in virtual mem */
249 char *readMap;
250 int drawX; /* origin of drawable in draw buffer */
251 int drawY;
252 GLuint numClipRects; /* cliprects for that buffer */
253 GLint currentClip;
254 drm_clip_rect_t *pClipRects;
255
256 /* use this bit to support single/double buffer */
257 GLuint IsDouble;
258 /* use this to indicate Fullscreen mode */
259 GLuint IsFullScreen; /* FIXME - open/close fullscreen is gone, is this needed? */
260 GLuint backup_frontOffset;
261 GLuint backup_backOffset;
262 GLuint backup_frontBitmapDesc;
263 GLuint toggle;
264 GLuint backup_streamFIFO;
265 GLuint NotFirstFrame;
266
267 GLboolean inSwap;
268 GLuint lastSwap;
269 GLuint ctxAge;
270 GLuint dirtyAge;
271 GLuint any_contend; /* throttle me harder */
272
273 GLuint scissor;
274 GLboolean scissorChanged;
275 drm_clip_rect_t draw_rect;
276 drm_clip_rect_t scissor_rect;
277
278 /*Texture aging and DMA based aging*/
279 unsigned int texAge[SAVAGE_NR_TEX_HEAPS];
280
281 drm_context_t hHWContext;
282 drm_hw_lock_t *driHwLock;
283 GLuint driFd;
284
285 __DRIdrawablePrivate *driDrawable;
286 __DRIdrawablePrivate *driReadable;
287
288 /**
289 * Drawable used by Mesa for software fallbacks for reading and
290 * writing. It is set by Mesa's \c SetBuffer callback, and will always be
291 * either \c mga_context_t::driDrawable or \c mga_context_t::driReadable.
292 */
293 __DRIdrawablePrivate *mesa_drawable;
294
295 __DRIscreenPrivate *driScreen;
296 savageScreenPrivate *savageScreen;
297 drm_savage_sarea_t *sarea;
298
299 GLboolean hw_stencil;
300
301 /* Configuration cache
302 */
303 driOptionCache optionCache;
304 GLint texture_depth;
305 GLboolean no_rast;
306 GLboolean float_depth;
307 };
308
309 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
310
311 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
312 * preprocessor symbol, and equal to zero.
313 */
314 #ifndef SAVAGE_DEBUG
315 extern int SAVAGE_DEBUG;
316 #endif
317
318 #define DEBUG_FALLBACKS 0x001
319 #define DEBUG_VERBOSE_API 0x002
320 #define DEBUG_VERBOSE_LRU 0x004
321 #define DEBUG_VERBOSE_MSG 0x008
322 #define DEBUG_DMA 0x010
323 #define DEBUG_STATE 0x020
324
325 #define TARGET_FRONT 0x0
326 #define TARGET_BACK 0x1
327 #define TARGET_DEPTH 0x2
328
329 #define SUBPIXEL_X -0.5
330 #define SUBPIXEL_Y -0.375
331
332 #endif