Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[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_drm.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 /**
86 * Derived from gl_renderbuffer.
87 */
88 struct via_renderbuffer {
89 struct gl_renderbuffer Base; /* must be first! */
90 drm_handle_t handle;
91 drmSize size;
92 unsigned long offset;
93 unsigned long index;
94 GLuint pitch;
95 GLuint bpp;
96 char *map;
97 GLuint orig; /* The drawing origin,
98 * at (drawX,drawY) in screen space.
99 */
100 char *origMap;
101
102 int drawX; /* origin of drawable in draw buffer */
103 int drawY;
104 int drawW;
105 int drawH;
106
107 __DRIdrawablePrivate *dPriv;
108 };
109
110
111 #define VIA_MAX_TEXLEVELS 10
112
113 struct via_tex_buffer {
114 struct via_tex_buffer *next, *prev;
115 struct via_texture_image *image;
116 unsigned long index;
117 unsigned long offset;
118 GLuint size;
119 GLuint memType;
120 unsigned char *bufAddr;
121 GLuint texBase;
122 GLuint lastUsed;
123 };
124
125
126
127 struct via_texture_image {
128 struct gl_texture_image image;
129 struct via_tex_buffer *texMem;
130 GLint pitchLog2;
131 };
132
133 struct via_texture_object {
134 struct gl_texture_object obj; /* The "parent" object */
135
136 GLuint texelBytes;
137 GLuint memType;
138
139 GLuint regTexFM;
140 GLuint regTexWidthLog2[2];
141 GLuint regTexHeightLog2[2];
142 GLuint regTexBaseH[4];
143 struct {
144 GLuint baseL;
145 GLuint pitchLog2;
146 } regTexBaseAndPitch[12];
147
148 GLint firstLevel, lastLevel; /* upload tObj->Image[first .. lastLevel] */
149 };
150
151
152
153 struct via_context {
154 GLint refcount;
155 GLcontext *glCtx;
156 GLcontext *shareCtx;
157
158 /* XXX These don't belong here. They should be per-drawable state. */
159 struct via_renderbuffer front;
160 struct via_renderbuffer back;
161 struct via_renderbuffer depth;
162 struct via_renderbuffer stencil; /* mirrors depth */
163 struct via_renderbuffer breadcrumb;
164
165 GLboolean hasBack;
166 GLboolean hasDepth;
167 GLboolean hasStencil;
168 GLboolean hasAccum;
169 GLuint depthBits;
170 GLuint stencilBits;
171
172 GLboolean have_hw_stencil;
173 GLuint ClearDepth;
174 GLuint depth_clear_mask;
175 GLuint stencil_clear_mask;
176 GLfloat depth_max;
177 GLfloat polygon_offset_scale;
178
179 GLubyte *dma;
180 viaRegion tex;
181
182 /* Bit flag to keep 0track of fallbacks.
183 */
184 GLuint Fallback;
185
186 /* State for via_tris.c.
187 */
188 GLuint newState; /* _NEW_* flags */
189 GLuint newEmitState; /* _NEW_* flags */
190 GLuint newRenderState; /* _NEW_* flags */
191
192 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
193 GLuint vertex_attr_count;
194
195 GLuint setupIndex;
196 GLuint renderIndex;
197 GLmatrix ViewportMatrix;
198 GLenum renderPrimitive;
199 GLenum hwPrimitive;
200 GLenum hwShadeModel;
201 unsigned char *verts;
202
203 /* drmBufPtr dma_buffer;
204 */
205 GLuint dmaLow;
206 GLuint dmaCliprectAddr;
207 GLuint dmaLastPrim;
208 GLboolean useAgp;
209
210
211 /* Fallback rasterization functions
212 */
213 via_point_func drawPoint;
214 via_line_func drawLine;
215 via_tri_func drawTri;
216
217 /* Hardware register
218 */
219 GLuint regCmdA_End;
220 GLuint regCmdB;
221
222 GLuint regEnable;
223 GLuint regHFBBMSKL;
224 GLuint regHROP;
225
226 GLuint regHZWTMD;
227 GLuint regHSTREF;
228 GLuint regHSTMD;
229
230 GLuint regHATMD;
231 GLuint regHABLCsat;
232 GLuint regHABLCop;
233 GLuint regHABLAsat;
234 GLuint regHABLAop;
235 GLuint regHABLRCa;
236 GLuint regHABLRFCa;
237 GLuint regHABLRCbias;
238 GLuint regHABLRCb;
239 GLuint regHABLRFCb;
240 GLuint regHABLRAa;
241 GLuint regHABLRAb;
242 GLuint regHFogLF;
243 GLuint regHFogCL;
244 GLuint regHFogCH;
245
246 GLuint regHLP;
247 GLuint regHLPRF;
248
249 GLuint regHTXnCLOD[2];
250 GLuint regHTXnTB[2];
251 GLuint regHTXnMPMD[2];
252 GLuint regHTXnTBLCsat[2];
253 GLuint regHTXnTBLCop[2];
254 GLuint regHTXnTBLMPfog[2];
255 GLuint regHTXnTBLAsat[2];
256 GLuint regHTXnTBLRCb[2];
257 GLuint regHTXnTBLRAa[2];
258 GLuint regHTXnTBLRFog[2];
259 GLuint regHTXnTBLRCa[2];
260 GLuint regHTXnTBLRCc[2];
261 GLuint regHTXnTBLRCbias[2];
262 GLuint regHTXnTBC[2];
263 GLuint regHTXnTRAH[2];
264
265 int vertexSize;
266 int hwVertexSize;
267 GLboolean ptexHack;
268 int coloroffset;
269 int specoffset;
270
271 GLint lastStamp;
272
273 GLuint ClearColor;
274 GLuint ClearMask;
275
276 /* DRI stuff
277 */
278 GLboolean doPageFlip;
279
280 struct via_renderbuffer *drawBuffer;
281
282 GLuint numClipRects; /* cliprects for that buffer */
283 drm_clip_rect_t *pClipRects;
284
285 GLboolean scissor;
286 drm_clip_rect_t drawRect;
287 drm_clip_rect_t scissorRect;
288
289 drm_context_t hHWContext;
290 drm_hw_lock_t *driHwLock;
291 int driFd;
292 __DRInativeDisplay *display;
293
294 /**
295 * DRI drawable bound to this context for drawing.
296 */
297 __DRIdrawablePrivate *driDrawable;
298
299 /**
300 * DRI drawable bound to this context for reading.
301 */
302 __DRIdrawablePrivate *driReadable;
303
304 __DRIscreenPrivate *driScreen;
305 viaScreenPrivate *viaScreen;
306 drm_via_sarea_t *sarea;
307 volatile GLuint* regMMIOBase;
308 volatile GLuint* pnGEMode;
309 volatile GLuint* regEngineStatus;
310 volatile GLuint* regTranSet;
311 volatile GLuint* regTranSpace;
312 GLuint agpBase;
313 GLuint drawType;
314
315 GLuint nDoneFirstFlip;
316 GLuint agpFullCount;
317
318 GLboolean clearTexCache;
319 GLboolean thrashing;
320
321 /* Configuration cache
322 */
323 driOptionCache optionCache;
324
325 GLuint vblank_flags;
326 GLuint vbl_seq;
327
328 int64_t swap_ust;
329 int64_t swap_missed_ust;
330
331 GLuint swap_count;
332 GLuint swap_missed_count;
333
334
335 GLuint pfCurrentOffset;
336 GLboolean allowPageFlip;
337
338 GLuint lastBreadcrumbRead;
339 GLuint lastBreadcrumbWrite;
340 GLuint lastSwap[2];
341 GLuint lastDma;
342
343 GLuint total_alloc[VIA_MEM_SYSTEM+1];
344
345 struct via_tex_buffer tex_image_list[VIA_MEM_SYSTEM+1];
346 struct via_tex_buffer freed_tex_buffers;
347
348 };
349
350
351
352 #define VIA_CONTEXT(ctx) ((struct via_context *)(ctx->DriverCtx))
353
354
355
356 /* Lock the hardware and validate our state.
357 */
358 #define LOCK_HARDWARE(vmesa) \
359 do { \
360 char __ret = 0; \
361 DRM_CAS(vmesa->driHwLock, vmesa->hHWContext, \
362 (DRM_LOCK_HELD|vmesa->hHWContext), __ret); \
363 if (__ret) \
364 viaGetLock(vmesa, 0); \
365 } while (0)
366
367
368 /* Release the kernel lock.
369 */
370 #define UNLOCK_HARDWARE(vmesa) \
371 DRM_UNLOCK(vmesa->driFd, vmesa->driHwLock, vmesa->hHWContext);
372
373
374
375 extern GLuint VIA_DEBUG;
376
377 #define DEBUG_TEXTURE 0x1
378 #define DEBUG_STATE 0x2
379 #define DEBUG_IOCTL 0x4
380 #define DEBUG_PRIMS 0x8
381 #define DEBUG_VERTS 0x10
382 #define DEBUG_FALLBACKS 0x20
383 #define DEBUG_VERBOSE 0x40
384 #define DEBUG_DRI 0x80
385 #define DEBUG_DMA 0x100
386 #define DEBUG_SANITY 0x200
387 #define DEBUG_SYNC 0x400
388 #define DEBUG_SLEEP 0x800
389 #define DEBUG_PIXEL 0x1000
390 #define DEBUG_2D 0x2000
391
392
393 extern void viaGetLock(struct via_context *vmesa, GLuint flags);
394 extern void viaLock(struct via_context *vmesa, GLuint flags);
395 extern void viaUnLock(struct via_context *vmesa, GLuint flags);
396 extern void viaEmitHwStateLocked(struct via_context *vmesa);
397 extern void viaEmitScissorValues(struct via_context *vmesa, int box_nr, int emit);
398 extern void viaXMesaSetBackClipRects(struct via_context *vmesa);
399 extern void viaXMesaSetFrontClipRects(struct via_context *vmesa);
400 extern void viaReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer, GLuint width, GLuint height);
401 extern void viaXMesaWindowMoved(struct via_context *vmesa);
402
403 extern GLboolean viaTexCombineState(struct via_context *vmesa,
404 const struct gl_tex_env_combine_state * combine,
405 unsigned unit );
406
407 /* Via hw already adjusted for GL pixel centers:
408 */
409 #define SUBPIXEL_X 0
410 #define SUBPIXEL_Y 0
411
412 /* TODO XXX _SOLO temp defines to make code compilable */
413 #ifndef GLX_PBUFFER_BIT
414 #define GLX_PBUFFER_BIT 0x00000004
415 #endif
416 #ifndef GLX_WINDOW_BIT
417 #define GLX_WINDOW_BIT 0x00000001
418 #endif
419 #ifndef VERT_BIT_CLIP
420 #define VERT_BIT_CLIP 0x1000000
421 #endif
422
423 #endif