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