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