Remove the many aliases for 'struct mem_block' in mm.h
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_context.h
1 /* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * Jos�Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #ifndef __MACH64_CONTEXT_H__
33 #define __MACH64_CONTEXT_H__
34
35 #include "dri_util.h"
36 #include "drm.h"
37 #include "mach64_drm.h"
38
39 #include "mtypes.h"
40
41 #include "mach64_reg.h"
42
43 #include "texmem.h"
44
45 struct mach64_context;
46 typedef struct mach64_context mach64ContextRec;
47 typedef struct mach64_context *mach64ContextPtr;
48
49 #include "mach64_lock.h"
50 #include "mach64_screen.h"
51
52 /* Experimental driver options */
53 #define MACH64_CLIENT_STATE_EMITS 0
54
55 /* Performace monitoring */
56 #define ENABLE_PERF_BOXES 1
57
58 /* Native vertex format */
59 #define MACH64_NATIVE_VTXFMT 1
60
61 /* Flags for what context state needs to be updated:
62 */
63 #define MACH64_NEW_ALPHA 0x0001
64 #define MACH64_NEW_DEPTH 0x0002
65 #define MACH64_NEW_FOG 0x0004
66 #define MACH64_NEW_CLIP 0x0008
67 #define MACH64_NEW_CULL 0x0010
68 #define MACH64_NEW_MASKS 0x0020
69 #define MACH64_NEW_RENDER_UNUSED 0x0040
70 #define MACH64_NEW_WINDOW 0x0080
71 #define MACH64_NEW_TEXTURE 0x0100
72 #define MACH64_NEW_CONTEXT 0x0200
73 #define MACH64_NEW_ALL 0x03ff
74
75 /* Flags for software fallback cases:
76 */
77 #define MACH64_FALLBACK_TEXTURE 0x0001
78 #define MACH64_FALLBACK_DRAW_BUFFER 0x0002
79 #define MACH64_FALLBACK_READ_BUFFER 0x0004
80 #define MACH64_FALLBACK_STENCIL 0x0008
81 #define MACH64_FALLBACK_RENDER_MODE 0x0010
82 #define MACH64_FALLBACK_LOGICOP 0x0020
83 #define MACH64_FALLBACK_SEP_SPECULAR 0x0040
84 #define MACH64_FALLBACK_BLEND_EQ 0x0080
85 #define MACH64_FALLBACK_BLEND_FUNC 0x0100
86 #define MACH64_FALLBACK_DISABLE 0x0200
87
88 #define CARD32 GLuint /* KW: For building in mesa tree */
89
90 #if MACH64_NATIVE_VTXFMT
91
92 /* The vertex structures.
93 */
94
95 /* The size of this union is not of relevence:
96 */
97 union mach64_vertex_t {
98 GLfloat f[16];
99 GLuint ui[16];
100 GLushort us2[16][2];
101 GLubyte ub4[16][4];
102 };
103
104 typedef union mach64_vertex_t mach64Vertex, *mach64VertexPtr;
105
106 #else
107
108 /* Use the templated vertex format:
109 */
110 #define TAG(x) mach64##x
111 #include "tnl_dd/t_dd_vertex.h"
112 #undef TAG
113
114 #endif /* MACH64_NATIVE_VTXFMT */
115
116 /* Subpixel offsets for window coordinates:
117 * These are enough to fix most glean tests except polygonOffset.
118 * There are also still some gaps that show in e.g. the tunnel Mesa demo
119 * or the lament xscreensaver hack.
120 */
121 #define SUBPIXEL_X (0.0125F)
122 #define SUBPIXEL_Y (0.15F)
123
124
125 typedef void (*mach64_tri_func)( mach64ContextPtr,
126 mach64Vertex *,
127 mach64Vertex *,
128 mach64Vertex * );
129
130 typedef void (*mach64_line_func)( mach64ContextPtr,
131 mach64Vertex *,
132 mach64Vertex * );
133
134 typedef void (*mach64_point_func)( mach64ContextPtr,
135 mach64Vertex * );
136
137 #ifdef TEXMEM
138 struct mach64_texture_object {
139 driTextureObject base;
140
141 GLuint offset;
142
143 GLuint dirty;
144 GLuint age;
145
146 GLint widthLog2;
147 GLint heightLog2;
148 GLint maxLog2;
149
150 GLint hasAlpha;
151 GLint textureFormat;
152
153 /* Have to keep these separate due to how they are programmed.
154 * FIXME: Why don't we just use the tObj values?
155 */
156 GLboolean BilinearMin;
157 GLboolean BilinearMag;
158 GLboolean ClampS;
159 GLboolean ClampT;
160 };
161 #else
162 struct mach64_texture_object {
163 struct mach64_texture_object *next;
164 struct mach64_texture_object *prev;
165 struct gl_texture_object *tObj;
166
167 struct mem_block *memBlock;
168 GLuint offset;
169 GLuint size;
170
171 GLuint dirty;
172 GLuint age;
173
174 GLint bound;
175 GLint heap;
176
177 GLint widthLog2;
178 GLint heightLog2;
179 GLint maxLog2;
180
181 GLint hasAlpha;
182 GLint textureFormat;
183
184 /* Have to keep these separate due to how they are programmed.
185 * FIXME: Why don't we just use the tObj values?
186 */
187 GLboolean BilinearMin;
188 GLboolean BilinearMag;
189 GLboolean ClampS;
190 GLboolean ClampT;
191 };
192 #endif
193
194 typedef struct mach64_texture_object mach64TexObj, *mach64TexObjPtr;
195
196
197 struct mach64_context {
198 GLcontext *glCtx;
199
200 /* Driver and hardware state management
201 */
202 GLuint new_state;
203 GLuint dirty; /* Hardware state to be updated */
204 drm_mach64_context_regs_t setup;
205
206 GLuint NewGLState;
207 GLuint Fallback;
208 GLuint SetupIndex;
209 GLuint SetupNewInputs;
210 GLuint RenderIndex;
211 GLfloat hw_viewport[16];
212 GLfloat depth_scale;
213 GLuint vertex_size;
214 GLuint vertex_stride_shift;
215 GLuint vertex_format;
216 GLuint num_verts;
217 GLubyte *verts;
218
219 CARD32 Color; /* Current draw color */
220 CARD32 ClearColor; /* Color used to clear color buffer */
221 CARD32 ClearDepth; /* Value used to clear depth buffer */
222
223 /* Map GL texture units onto hardware
224 */
225 GLint multitex;
226 GLint tmu_source[2];
227 GLint tex_dest[2];
228
229 /* Texture object bookkeeping
230 */
231 mach64TexObjPtr CurrentTexObj[2];
232 #ifdef TEXMEM
233 unsigned nr_heaps;
234 driTexHeap * texture_heaps[ R128_NR_TEX_HEAPS ];
235 driTextureObject swapped;
236 #else
237 mach64TexObj TexObjList[MACH64_NR_TEX_HEAPS];
238 mach64TexObj SwappedOut;
239 struct mem_block *texHeap[MACH64_NR_TEX_HEAPS];
240 GLuint lastTexAge[MACH64_NR_TEX_HEAPS];
241 GLint firstTexHeap, lastTexHeap;
242 #endif
243
244 /* Fallback rasterization functions
245 */
246 mach64_point_func draw_point;
247 mach64_line_func draw_line;
248 mach64_tri_func draw_tri;
249
250 /* Culling */
251 GLfloat backface_sign;
252
253 /* DMA buffers
254 */
255 void *vert_buf;
256 size_t vert_total;
257 unsigned vert_used;
258
259 GLuint hw_primitive;
260 GLenum render_primitive;
261
262 /* Visual, drawable, cliprect and scissor information
263 */
264 GLint drawOffset, drawPitch;
265 GLint drawX, drawY; /* origin of drawable in draw buffer */
266 GLint readOffset, readPitch;
267
268 GLuint numClipRects; /* Cliprects for the draw buffer */
269 drm_clip_rect_t *pClipRects;
270
271 GLint scissor;
272 drm_clip_rect_t ScissorRect; /* Current software scissor */
273
274 /* Mirrors of some DRI state
275 */
276 __DRIcontextPrivate *driContext; /* DRI context */
277 __DRIscreenPrivate *driScreen; /* DRI screen */
278 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
279
280 unsigned int lastStamp; /* mirror driDrawable->lastStamp */
281
282 drm_context_t hHWContext;
283 drm_hw_lock_t *driHwLock;
284 int driFd;
285
286 mach64ScreenPtr mach64Screen; /* Screen private DRI data */
287 drm_mach64_sarea_t *sarea; /* Private SAREA data */
288
289 GLuint hardwareWentIdle;
290
291 #if ENABLE_PERF_BOXES
292 /* Performance counters
293 */
294 GLuint boxes; /* Draw performance boxes */
295 GLuint c_clears;
296 GLuint c_drawWaits;
297 GLuint c_textureSwaps;
298 GLuint c_textureBytes;
299 GLuint c_agpTextureBytes;
300 GLuint c_texsrc_agp;
301 GLuint c_texsrc_card;
302 GLuint c_vertexBuffers;
303 #endif
304
305 /* VBI
306 */
307 GLuint vbl_seq;
308 GLuint vblank_flags;
309 GLuint do_irqs;
310
311 /* Configuration cache
312 */
313 driOptionCache optionCache;
314 };
315
316 #define MACH64_CONTEXT(ctx) ((mach64ContextPtr)(ctx->DriverCtx))
317
318
319 extern GLboolean mach64CreateContext( const __GLcontextModes *glVisual,
320 __DRIcontextPrivate *driContextPriv,
321 void *sharedContextPrivate );
322
323 extern void mach64DestroyContext( __DRIcontextPrivate * );
324
325 extern GLboolean mach64MakeCurrent( __DRIcontextPrivate *driContextPriv,
326 __DRIdrawablePrivate *driDrawPriv,
327 __DRIdrawablePrivate *driReadPriv );
328
329 extern GLboolean mach64UnbindContext( __DRIcontextPrivate *driContextPriv );
330
331 /* ================================================================
332 * Byte ordering
333 */
334 #if MESA_LITTLE_ENDIAN == 1
335 #define LE32_IN( x ) ( *(GLuint *)(x) )
336 #define LE32_IN_FLOAT( x ) ( *(GLfloat *)(x) )
337 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = (y); } while (0)
338 #define LE32_OUT_FLOAT( x, y ) do { *(GLfloat *)(x) = (y); } while (0)
339 #else
340 #include <byteswap.h>
341 #define LE32_IN( x ) bswap_32( *(GLuint *)(x) )
342 #define LE32_IN_FLOAT( x ) \
343 ({ \
344 GLuint __tmp = bswap_32( *(GLuint *)(x) ); \
345 *(GLfloat *)&__tmp; \
346 })
347 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = bswap_32( y ); } while (0)
348 #define LE32_OUT_FLOAT( x, y ) \
349 do { \
350 GLuint __tmp; \
351 *(GLfloat *)&__tmp = (y); \
352 *(GLuint *)(x) = bswap_32( __tmp ); \
353 } while (0)
354 #endif
355
356 /* ================================================================
357 * DMA buffers
358 */
359
360 #define DMALOCALS CARD32 *buf=NULL; int requested=0; int outcount=0
361
362 /* called while locked for interleaved client-side state emits */
363 #define DMAGETPTR( dwords ) \
364 do { \
365 requested = (dwords); \
366 buf = (CARD32 *)mach64AllocDmaLocked( mmesa, ((dwords)*4) ); \
367 outcount = 0; \
368 } while(0)
369
370 #define DMAOUTREG( reg, val ) \
371 do { \
372 LE32_OUT( &buf[outcount++], ADRINDEX( reg ) ); \
373 LE32_OUT( &buf[outcount++], ( val ) ); \
374 } while(0)
375
376 #define DMAADVANCE() \
377 do { \
378 if (outcount < requested) { \
379 mmesa->vert_used -= (requested - outcount) * 4; \
380 } \
381 } while(0)
382
383 /* ================================================================
384 * Debugging:
385 */
386
387 #define DO_DEBUG 1
388
389 #if DO_DEBUG
390 extern int MACH64_DEBUG;
391 #else
392 #define MACH64_DEBUG 0
393 #endif
394
395 #define DEBUG_ALWAYS_SYNC 0x001
396 #define DEBUG_VERBOSE_API 0x002
397 #define DEBUG_VERBOSE_MSG 0x004
398 #define DEBUG_VERBOSE_LRU 0x008
399 #define DEBUG_VERBOSE_DRI 0x010
400 #define DEBUG_VERBOSE_IOCTL 0x020
401 #define DEBUG_VERBOSE_PRIMS 0x040
402 #define DEBUG_VERBOSE_COUNT 0x080
403 #define DEBUG_NOWAIT 0x100
404 #define DEBUG_VERBOSE_FALLBACK 0x200
405 #endif /* __MACH64_CONTEXT_H__ */