add special case for flat shaded + separate specular triangles
[mesa.git] / src / mesa / drivers / dri / unichrome / via_context.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 #ifndef _VIACONTEXT_H
27 #define _VIACONTEXT_H
28
29 #include "dri_util.h"
30
31 #include "mtypes.h"
32 #include "drm.h"
33 #include "mm.h"
34 #include "tnl/t_vertex.h"
35
36 #include "via_screen.h"
37 #include "via_tex.h"
38 #include "via_common.h"
39
40 struct via_context;
41
42 /* Chip tags. These are used to group the adapters into
43 * related families.
44 */
45 enum VIACHIPTAGS {
46 VIA_UNKNOWN = 0,
47 VIA_CLE266,
48 VIA_KM400,
49 VIA_K8M800,
50 VIA_PM800,
51 VIA_LAST
52 };
53
54 #define VIA_FALLBACK_TEXTURE 0x1
55 #define VIA_FALLBACK_DRAW_BUFFER 0x2
56 #define VIA_FALLBACK_READ_BUFFER 0x4
57 #define VIA_FALLBACK_COLORMASK 0x8
58 #define VIA_FALLBACK_SPECULAR 0x20
59 #define VIA_FALLBACK_LOGICOP 0x40
60 #define VIA_FALLBACK_RENDERMODE 0x80
61 #define VIA_FALLBACK_STENCIL 0x100
62 #define VIA_FALLBACK_BLEND_EQ 0x200
63 #define VIA_FALLBACK_BLEND_FUNC 0x400
64 #define VIA_FALLBACK_USER_DISABLE 0x800
65 #define VIA_FALLBACK_PROJ_TEXTURE 0x1000
66 #define VIA_FALLBACK_POLY_STIPPLE 0x2000
67
68 #define VIA_DMA_BUFSIZ 4096
69 #define VIA_DMA_HIGHWATER (VIA_DMA_BUFSIZ - 128)
70
71 #define VIA_NO_CLIPRECTS 0x1
72
73
74 /* Use the templated vertex formats:
75 */
76 #define TAG(x) via##x
77 #include "tnl_dd/t_dd_vertex.h"
78 #undef TAG
79
80 typedef void (*via_tri_func)(struct via_context *, viaVertex *, viaVertex *,
81 viaVertex *);
82 typedef void (*via_line_func)(struct via_context *, viaVertex *, viaVertex *);
83 typedef void (*via_point_func)(struct via_context *, viaVertex *);
84
85 struct via_buffer {
86 drm_handle_t handle;
87 drmSize size;
88 GLuint offset;
89 GLuint index;
90 GLuint pitch;
91 GLuint bpp;
92 char *map;
93 GLuint orig; /* The drawing origin,
94 * at (drawX,drawY) in screen space.
95 */
96 char *origMap;
97 };
98
99
100 #define VIA_MAX_TEXLEVELS 10
101
102 struct via_tex_buffer {
103 struct via_tex_buffer *next, *prev;
104 struct via_texture_image *image;
105 GLuint index;
106 GLuint offset;
107 GLuint size;
108 GLuint memType;
109 unsigned char *bufAddr;
110 GLuint texBase;
111 GLuint lastUsed;
112 };
113
114
115
116 struct via_texture_image {
117 struct gl_texture_image image;
118 struct via_tex_buffer *texMem;
119 GLint pitchLog2;
120 };
121
122 struct via_texture_object {
123 struct gl_texture_object obj; /* The "parent" object */
124
125 GLuint texelBytes;
126 GLuint memType;
127
128 GLuint regTexFM;
129 GLuint regTexWidthLog2[2];
130 GLuint regTexHeightLog2[2];
131 GLuint regTexBaseH[4];
132 struct {
133 GLuint baseL;
134 GLuint pitchLog2;
135 } regTexBaseAndPitch[12];
136
137 GLint firstLevel, lastLevel; /* upload tObj->Image[first .. lastLevel] */
138 };
139
140
141
142 struct via_context {
143 GLint refcount;
144 GLcontext *glCtx;
145 GLcontext *shareCtx;
146
147 struct via_buffer front;
148 struct via_buffer back;
149 struct via_buffer depth;
150 struct via_buffer breadcrumb;
151
152 GLboolean hasBack;
153 GLboolean hasDepth;
154 GLboolean hasStencil;
155 GLboolean hasAccum;
156 GLuint depthBits;
157 GLuint stencilBits;
158
159 GLboolean have_hw_stencil;
160 GLuint ClearDepth;
161 GLuint depth_clear_mask;
162 GLuint stencil_clear_mask;
163 GLfloat depth_max;
164 GLfloat polygon_offset_scale;
165
166 GLubyte *dma;
167 viaRegion tex;
168
169 /* Bit flag to keep 0track of fallbacks.
170 */
171 GLuint Fallback;
172
173 /* State for via_tris.c.
174 */
175 GLuint newState; /* _NEW_* flags */
176 GLuint newEmitState; /* _NEW_* flags */
177 GLuint newRenderState; /* _NEW_* flags */
178
179 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
180 GLuint vertex_attr_count;
181
182 GLuint setupIndex;
183 GLuint renderIndex;
184 GLmatrix ViewportMatrix;
185 GLenum renderPrimitive;
186 GLenum hwPrimitive;
187 GLenum hwShadeModel;
188 unsigned char *verts;
189
190 /* drmBufPtr dma_buffer;
191 */
192 GLuint dmaLow;
193 GLuint dmaCliprectAddr;
194 GLuint dmaLastPrim;
195 GLboolean useAgp;
196
197
198 /* Fallback rasterization functions
199 */
200 via_point_func drawPoint;
201 via_line_func drawLine;
202 via_tri_func drawTri;
203
204 /* Hardware register
205 */
206 GLuint regCmdA_End;
207 GLuint regCmdB;
208
209 GLuint regEnable;
210 GLuint regHFBBMSKL;
211 GLuint regHROP;
212
213 GLuint regHZWTMD;
214 GLuint regHSTREF;
215 GLuint regHSTMD;
216
217 GLuint regHATMD;
218 GLuint regHABLCsat;
219 GLuint regHABLCop;
220 GLuint regHABLAsat;
221 GLuint regHABLAop;
222 GLuint regHABLRCa;
223 GLuint regHABLRFCa;
224 GLuint regHABLRCbias;
225 GLuint regHABLRCb;
226 GLuint regHABLRFCb;
227 GLuint regHABLRAa;
228 GLuint regHABLRAb;
229 GLuint regHFogLF;
230 GLuint regHFogCL;
231 GLuint regHFogCH;
232
233 GLuint regHLP;
234 GLuint regHLPRF;
235
236 GLuint regHTXnCLOD[2];
237 GLuint regHTXnTB[2];
238 GLuint regHTXnMPMD[2];
239 GLuint regHTXnTBLCsat[2];
240 GLuint regHTXnTBLCop[2];
241 GLuint regHTXnTBLMPfog[2];
242 GLuint regHTXnTBLAsat[2];
243 GLuint regHTXnTBLRCb[2];
244 GLuint regHTXnTBLRAa[2];
245 GLuint regHTXnTBLRFog[2];
246 GLuint regHTXnTBLRCa[2];
247 GLuint regHTXnTBLRCc[2];
248 GLuint regHTXnTBLRCbias[2];
249 GLuint regHTXnTBC[2];
250 GLuint regHTXnTRAH[2];
251
252 int vertexSize;
253 int hwVertexSize;
254 GLboolean ptexHack;
255 int coloroffset;
256 int specoffset;
257
258 GLint lastStamp;
259
260 GLuint ClearColor;
261 GLuint ClearMask;
262
263 /* DRI stuff
264 */
265 GLboolean doPageFlip;
266
267 struct via_buffer *drawBuffer;
268 struct via_buffer *readBuffer;
269
270 int drawX; /* origin of drawable in draw buffer */
271 int drawY;
272 int drawW;
273 int drawH;
274
275 int drawXoff; /* drawX is 32byte aligned - this is
276 * the delta to the real origin, in
277 * pixel units.
278 */
279
280 GLuint numClipRects; /* cliprects for that buffer */
281 drm_clip_rect_t *pClipRects;
282
283 GLboolean scissor;
284 drm_clip_rect_t drawRect;
285 drm_clip_rect_t scissorRect;
286
287 drm_context_t hHWContext;
288 drm_hw_lock_t *driHwLock;
289 int driFd;
290 __DRInativeDisplay *display;
291
292 __DRIdrawablePrivate *driDrawable;
293 __DRIscreenPrivate *driScreen;
294 viaScreenPrivate *viaScreen;
295 drm_via_sarea_t *sarea;
296 volatile GLuint* regMMIOBase;
297 volatile GLuint* pnGEMode;
298 volatile GLuint* regEngineStatus;
299 volatile GLuint* regTranSet;
300 volatile GLuint* regTranSpace;
301 GLuint* agpBase;
302 GLuint drawType;
303
304 GLuint nDoneFirstFlip;
305 GLuint agpFullCount;
306
307 GLboolean clearTexCache;
308 GLboolean thrashing;
309
310 /* Configuration cache
311 */
312 driOptionCache optionCache;
313
314 GLuint vblank_flags;
315 GLuint vbl_seq;
316
317 int64_t swap_ust;
318 int64_t swap_missed_ust;
319
320 GLuint swap_count;
321 GLuint swap_missed_count;
322
323 PFNGLXGETUSTPROC get_ust;
324
325 GLuint pfCurrentOffset;
326 GLboolean allowPageFlip;
327
328 GLuint lastBreadcrumbRead;
329 GLuint lastBreadcrumbWrite;
330 GLuint lastSwap[2];
331 GLuint lastDma;
332
333 GLuint total_alloc[VIA_MEM_SYSTEM+1];
334
335 struct via_tex_buffer tex_image_list[VIA_MEM_SYSTEM+1];
336 struct via_tex_buffer freed_tex_buffers;
337
338 };
339
340
341
342 #define VIA_CONTEXT(ctx) ((struct via_context *)(ctx->DriverCtx))
343
344
345
346 /* Lock the hardware and validate our state.
347 */
348 #define LOCK_HARDWARE(vmesa) \
349 do { \
350 char __ret = 0; \
351 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
352 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
353 if (__ret) \
354 viaGetLock(vmesa, 0); \
355 } while (0)
356
357
358 /* Release the kernel lock.
359 */
360 #define UNLOCK_HARDWARE(vmesa) \
361 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
362
363
364
365 extern GLuint VIA_DEBUG;
366
367 #define DEBUG_TEXTURE 0x1
368 #define DEBUG_STATE 0x2
369 #define DEBUG_IOCTL 0x4
370 #define DEBUG_PRIMS 0x8
371 #define DEBUG_VERTS 0x10
372 #define DEBUG_FALLBACKS 0x20
373 #define DEBUG_VERBOSE 0x40
374 #define DEBUG_DRI 0x80
375 #define DEBUG_DMA 0x100
376 #define DEBUG_SANITY 0x200
377 #define DEBUG_SYNC 0x400
378 #define DEBUG_SLEEP 0x800
379 #define DEBUG_PIXEL 0x1000
380 #define DEBUG_2D 0x2000
381
382
383 extern void viaGetLock(struct via_context *vmesa, GLuint flags);
384 extern void viaLock(struct via_context *vmesa, GLuint flags);
385 extern void viaUnLock(struct via_context *vmesa, GLuint flags);
386 extern void viaEmitHwStateLocked(struct via_context *vmesa);
387 extern void viaEmitScissorValues(struct via_context *vmesa, int box_nr, int emit);
388 extern void viaXMesaSetBackClipRects(struct via_context *vmesa);
389 extern void viaXMesaSetFrontClipRects(struct via_context *vmesa);
390 extern void viaReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer, GLuint width, GLuint height);
391 extern void viaXMesaWindowMoved(struct via_context *vmesa);
392
393 extern GLboolean viaTexCombineState(struct via_context *vmesa,
394 const struct gl_tex_env_combine_state * combine,
395 unsigned unit );
396
397 /* Via hw already adjusted for GL pixel centers:
398 */
399 #define SUBPIXEL_X 0
400 #define SUBPIXEL_Y 0
401
402 /* TODO XXX _SOLO temp defines to make code compilable */
403 #ifndef GLX_PBUFFER_BIT
404 #define GLX_PBUFFER_BIT 0x00000004
405 #endif
406 #ifndef GLX_WINDOW_BIT
407 #define GLX_WINDOW_BIT 0x00000001
408 #endif
409 #ifndef VERT_BIT_CLIP
410 #define VERT_BIT_CLIP 0x1000000
411 #endif
412
413 #endif