Merge commit 'origin/gallium-0.1'
[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 "main/mtypes.h"
37 #include "xf86drm.h"
38 #include "drm.h"
39 #include "savage_drm.h"
40 #include "savage_init.h"
41 #include "savage_3d_reg.h"
42 #include "main/mm.h"
43 #include "tnl/t_vertex.h"
44
45 #include "texmem.h"
46
47 #include "xmlconfig.h"
48
49 /* Reasons to fallback on all primitives.
50 */
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
63
64
65 #define HW_CULL 1
66
67 /* for savagectx.new_state - manage GL->driver state changes
68 */
69 #define SAVAGE_NEW_TEXTURE 0x1
70 #define SAVAGE_NEW_CULL 0x2
71
72 /* What needs to be changed for the current vertex dma buffer?
73 * This will go away!
74 */
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) */
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
90 /* Use the templated vertex formats:
91 */
92 #define TAG(x) savage##x
93 #include "tnl_dd/t_dd_vertex.h"
94 #undef TAG
95
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 * );
101
102
103 /**************************************************************
104 **************** enums for chip IDs ************************
105 **************************************************************/
106
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*/
117
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 )
128
129
130 struct savage_vtxbuf_t {
131 GLuint total, used, flushed; /* in 32 bit units */
132 GLuint idx; /* for DMA buffers */
133 uint32_t *buf;
134 };
135
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 */
141 };
142
143 struct savage_elt_t {
144 GLuint n; /* number of elts currently allocated */
145 drm_savage_cmd_header_t *cmd; /* the indexed drawing command */
146 };
147
148
149 struct savage_context_t {
150 GLint refcount;
151
152 GLcontext *glCtx;
153
154 int lastTexHeap;
155 driTexHeap *textureHeaps[SAVAGE_NR_TEX_HEAPS];
156 driTextureObject swapped;
157
158 driTextureObject *CurrentTexObj[2];
159
160 /* Hardware state
161 */
162
163 savageRegisters regs, oldRegs, globalRegMask;
164
165 /* Manage our own state */
166 GLuint new_state;
167 GLuint new_gl_state;
168 GLboolean ptexHack;
169
170 /* Command buffer */
171 struct savage_cmdbuf_t cmdBuf;
172
173 /* Elt book-keeping */
174 struct savage_elt_t elts;
175 GLint firstElt;
176
177 /* Vertex buffers */
178 struct savage_vtxbuf_t dmaVtxBuf, clientVtxBuf;
179 struct savage_vtxbuf_t *vtxBuf;
180
181 /* aperture base */
182 GLubyte *apertureBase[5];
183 GLuint aperturePitch;
184 /* Manage hardware state */
185 GLuint dirty;
186 GLboolean lostContext;
187 GLuint bTexEn1;
188 /* One of the few bits of hardware state that can't be calculated
189 * completely on the fly:
190 */
191 GLuint LcsCullMode;
192 GLuint texEnvColor;
193
194 /* Vertex state
195 */
196 GLuint vertex_size;
197 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
198 GLuint vertex_attr_count;
199 char *verts; /* points to tnl->clipspace.vertex_buf */
200
201 /* Rasterization state
202 */
203 GLuint SetupNewInputs;
204 GLuint SetupIndex;
205 GLuint RenderIndex;
206
207 GLuint hw_primitive;
208 GLenum raster_primitive;
209 GLenum render_primitive;
210
211 GLuint skip;
212 GLubyte HwPrim;
213 GLuint HwVertexSize;
214
215 /* Fallback rasterization functions
216 */
217 savage_point_func draw_point;
218 savage_line_func draw_line;
219 savage_tri_func draw_tri;
220
221 /* Funny mesa mirrors
222 */
223 GLuint MonoColor;
224 GLuint ClearColor;
225 GLfloat depth_scale;
226 GLfloat hw_viewport[16];
227 /* DRI stuff */
228 GLuint bufferSize;
229
230 GLframebuffer *glBuffer;
231
232 /* Two flags to keep track of fallbacks. */
233 GLuint Fallback;
234
235 GLuint needClip;
236
237 /* These refer to the current draw (front vs. back) buffer:
238 */
239 int drawX; /* origin of drawable in draw buffer */
240 int drawY;
241 GLuint numClipRects; /* cliprects for that buffer */
242 GLint currentClip;
243 drm_clip_rect_t *pClipRects;
244
245 /* use this bit to support single/double buffer */
246 GLuint IsDouble;
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;
252 GLuint toggle;
253 GLuint backup_streamFIFO;
254 GLuint NotFirstFrame;
255
256 GLboolean inSwap;
257 GLuint lastSwap;
258 GLuint ctxAge;
259 GLuint dirtyAge;
260 GLuint any_contend; /* throttle me harder */
261
262 /* Scissor state needs to be mirrored so buffered commands can be
263 * emitted with the old scissor state when scissor state changes.
264 */
265 struct {
266 GLboolean enabled;
267 GLint x, y;
268 GLsizei w, h;
269 } scissor;
270
271 drm_context_t hHWContext;
272 drm_hw_lock_t *driHwLock;
273 GLuint driFd;
274
275 __DRIdrawablePrivate *driDrawable;
276 __DRIdrawablePrivate *driReadable;
277
278 __DRIscreenPrivate *driScreen;
279 savageScreenPrivate *savageScreen;
280 drm_savage_sarea_t *sarea;
281
282 GLboolean hw_stencil;
283
284 /* Performance counters
285 */
286 GLuint c_textureSwaps;
287
288 /* Configuration cache
289 */
290 driOptionCache optionCache;
291 GLint texture_depth;
292 GLboolean no_rast;
293 GLboolean float_depth;
294 GLboolean enable_fastpath;
295 GLboolean enable_vdma;
296 GLboolean sync_frames;
297 };
298
299 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
300
301 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
302 * preprocessor symbol, and equal to zero.
303 */
304 #ifndef SAVAGE_DEBUG
305 extern int SAVAGE_DEBUG;
306 #endif
307
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
314
315 #define TARGET_FRONT 0x0
316 #define TARGET_BACK 0x1
317 #define TARGET_DEPTH 0x2
318
319 #define SUBPIXEL_X -0.5
320 #define SUBPIXEL_Y -0.375
321
322 #endif