* Fixed uploading of textures of certain sizes.
[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 "savage_3d_reg.h"
42 #include "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 #define SAVAGE_UPLOAD_CLIPRECTS 0x1000 /* FIXME: get rid of this */
83
84 /*define the max numer of vertex in vertex buf*/
85 #define SAVAGE_MAX_VERTEXS 0x10000
86
87 /* Don't make it too big. We don't want to buffer up a whole frame
88 * that would force the application to wait later. */
89 #define SAVAGE_CMDBUF_SIZE 1024
90 #define SAVAGE_MAX_VERTS_PENDING 1024
91
92 /* Use the templated vertex formats:
93 */
94 #define TAG(x) savage##x
95 #include "tnl_dd/t_dd_vertex.h"
96 #undef TAG
97
98 typedef void (*savage_tri_func)( savageContextPtr, savageVertex *,
99 savageVertex *, savageVertex * );
100 typedef void (*savage_line_func)( savageContextPtr,
101 savageVertex *, savageVertex * );
102 typedef void (*savage_point_func)( savageContextPtr, savageVertex * );
103
104
105 /**************************************************************
106 **************** enums for chip IDs ************************
107 **************************************************************/
108
109 #define CHIP_S3GX3MS1NB 0x8A25
110 #define CHIP_S3GX3MS1NBK 0x8A26
111 #define CHIP_S3TWISTER 0x8D01
112 #define CHIP_S3TWISTERK 0x8D02
113 #define CHIP_S3TWISTER_P4M 0x8D04
114 #define CHIP_S3PARAMOUNT128 0x8C22 /*SuperSavage 128/MX*/
115 #define CHIP_S3TRISTAR128SDR 0x8C2A /*SuperSavage 128/IX*/
116 #define CHIP_S3TRISTAR64SDRM7 0x8C2C /*SuperSavage/IX M7 Package*/
117 #define CHIP_S3TRISTAR64SDR 0x8C2E /*SuperSavage/IX*/
118 #define CHIP_S3TRISTAR64CDDR 0x8C2F /*SuperSavage/IXC DDR*/
119
120 #define IS_SAVAGE(imesa) (imesa->savageScreen->deviceID == CHIP_S3GX3MS1NB || \
121 imesa->savageScreen->deviceID == CHIP_S3GX3MS1NBK || \
122 imesa->savageScreen->deviceID == CHIP_S3TWISTER || \
123 imesa->savageScreen->deviceID == CHIP_S3TWISTERK || \
124 imesa->savageScreen->deviceID == CHIP_S3TWISTER_P4M || \
125 imesa->savageScreen->deviceID == CHIP_S3PARAMOUNT128 || \
126 imesa->savageScreen->deviceID == CHIP_S3TRISTAR128SDR || \
127 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDRM7 || \
128 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64SDR || \
129 imesa->savageScreen->deviceID == CHIP_S3TRISTAR64CDDR )
130
131
132 struct savage_vtxbuf_t {
133 GLuint total, used, flushed; /* in 32 bit units */
134 GLuint idx; /* for DMA buffers */
135 u_int32_t *buf;
136 };
137
138 struct savage_cmdbuf_t {
139 GLuint size; /* size in qwords */
140 drm_savage_cmd_header_t *base; /* initial state starts here */
141 drm_savage_cmd_header_t *start; /* drawing/state commands start here */
142 drm_savage_cmd_header_t *write; /* append stuff here */
143 };
144
145 struct savage_elt_t {
146 GLuint n; /* number of elts currently allocated */
147 drm_savage_cmd_header_t *cmd; /* the indexed drawing command */
148 };
149
150
151 struct savage_context_t {
152 GLint refcount;
153
154 GLcontext *glCtx;
155
156 int lastTexHeap;
157 driTexHeap *textureHeaps[SAVAGE_NR_TEX_HEAPS];
158 driTextureObject swapped;
159
160 driTextureObject *CurrentTexObj[2];
161
162 /* Hardware state
163 */
164
165 savageRegisters regs, oldRegs, globalRegMask;
166
167 /* Manage our own state */
168 GLuint new_state;
169 GLuint new_gl_state;
170 GLboolean ptexHack;
171
172 /* Command buffer */
173 struct savage_cmdbuf_t cmdBuf;
174
175 /* Elt book-keeping */
176 struct savage_elt_t elts;
177 GLint firstElt;
178
179 /* Vertex buffers */
180 struct savage_vtxbuf_t dmaVtxBuf, clientVtxBuf;
181 struct savage_vtxbuf_t *vtxBuf;
182
183 /* aperture base */
184 GLuint apertureBase[5];
185 GLuint aperturePitch;
186 /* Manage hardware state */
187 GLuint dirty;
188 GLboolean lostContext;
189 GLuint bTexEn1;
190 /* One of the few bits of hardware state that can't be calculated
191 * completely on the fly:
192 */
193 GLuint LcsCullMode;
194
195 /* Vertex state
196 */
197 GLuint vertex_size;
198 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
199 GLuint vertex_attr_count;
200 char *verts; /* points to tnl->clipspace.vertex_buf */
201
202 /* Rasterization state
203 */
204 GLuint SetupNewInputs;
205 GLuint SetupIndex;
206 GLuint RenderIndex;
207
208 GLuint hw_primitive;
209 GLenum raster_primitive;
210 GLenum render_primitive;
211
212 GLuint skip;
213 GLubyte HwPrim;
214 GLuint HwVertexSize;
215
216 /* Fallback rasterization functions
217 */
218 savage_point_func draw_point;
219 savage_line_func draw_line;
220 savage_tri_func draw_tri;
221
222 /* Funny mesa mirrors
223 */
224 GLuint MonoColor;
225 GLuint ClearColor;
226 GLfloat depth_scale;
227 GLfloat hw_viewport[16];
228 /* DRI stuff */
229 GLuint bufferSize;
230 GLuint vertsPending;
231
232 GLframebuffer *glBuffer;
233
234 /* Two flags to keep track of fallbacks. */
235 GLuint Fallback;
236
237 GLuint needClip;
238
239 /* These refer to the current draw (front vs. back) buffer:
240 */
241 char *drawMap; /* draw buffer address in virtual mem */
242 char *readMap;
243 int drawX; /* origin of drawable in draw buffer */
244 int drawY;
245 GLuint numClipRects; /* cliprects for that buffer */
246 GLint currentClip;
247 drm_clip_rect_t *pClipRects;
248
249 /* use this bit to support single/double buffer */
250 GLuint IsDouble;
251 /* use this to indicate Fullscreen mode */
252 GLuint IsFullScreen; /* FIXME - open/close fullscreen is gone, is this needed? */
253 GLuint backup_frontOffset;
254 GLuint backup_backOffset;
255 GLuint backup_frontBitmapDesc;
256 GLuint toggle;
257 GLuint backup_streamFIFO;
258 GLuint NotFirstFrame;
259
260 GLboolean inSwap;
261 GLuint lastSwap;
262 GLuint ctxAge;
263 GLuint dirtyAge;
264 GLuint any_contend; /* throttle me harder */
265
266 GLuint scissor;
267 GLboolean scissorChanged;
268 drm_clip_rect_t draw_rect;
269 drm_clip_rect_t scissor_rect;
270
271 drm_context_t hHWContext;
272 drm_hw_lock_t *driHwLock;
273 GLuint driFd;
274
275 __DRIdrawablePrivate *driDrawable;
276 __DRIdrawablePrivate *driReadable;
277
278 /**
279 * Drawable used by Mesa for software fallbacks for reading and
280 * writing. It is set by Mesa's \c SetBuffer callback, and will always be
281 * either \c mga_context_t::driDrawable or \c mga_context_t::driReadable.
282 */
283 __DRIdrawablePrivate *mesa_drawable;
284
285 __DRIscreenPrivate *driScreen;
286 savageScreenPrivate *savageScreen;
287 drm_savage_sarea_t *sarea;
288
289 GLboolean hw_stencil;
290
291 /* Performance counters
292 */
293 GLuint c_textureSwaps;
294
295 /* Configuration cache
296 */
297 driOptionCache optionCache;
298 GLint texture_depth;
299 GLboolean no_rast;
300 GLboolean float_depth;
301 GLboolean enable_fastpath;
302 GLboolean enable_vdma;
303 };
304
305 #define SAVAGE_CONTEXT(ctx) ((savageContextPtr)(ctx->DriverCtx))
306
307 /* To remove all debugging, make sure SAVAGE_DEBUG is defined as a
308 * preprocessor symbol, and equal to zero.
309 */
310 #ifndef SAVAGE_DEBUG
311 extern int SAVAGE_DEBUG;
312 #endif
313
314 #define DEBUG_FALLBACKS 0x001
315 #define DEBUG_VERBOSE_API 0x002
316 #define DEBUG_VERBOSE_TEX 0x004
317 #define DEBUG_VERBOSE_MSG 0x008
318 #define DEBUG_DMA 0x010
319 #define DEBUG_STATE 0x020
320
321 #define TARGET_FRONT 0x0
322 #define TARGET_BACK 0x1
323 #define TARGET_DEPTH 0x2
324
325 #define SUBPIXEL_X -0.5
326 #define SUBPIXEL_Y -0.375
327
328 #endif