1 /* -*- mode: c; c-basic-offset: 3 -*- */
3 * Copyright 2000 Gareth Hughes
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:
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
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.
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * Jos�Fonseca <j_r_fonseca@yahoo.co.uk>
32 #ifndef __MACH64_CONTEXT_H__
33 #define __MACH64_CONTEXT_H__
37 #include "mach64_drm.h"
39 #include "main/mtypes.h"
41 #include "mach64_reg.h"
45 struct mach64_context;
46 typedef struct mach64_context mach64ContextRec;
47 typedef struct mach64_context *mach64ContextPtr;
49 #include "mach64_lock.h"
50 #include "mach64_screen.h"
52 /* Experimental driver options */
53 #define MACH64_CLIENT_STATE_EMITS 0
55 /* Performace monitoring */
56 #define ENABLE_PERF_BOXES 1
58 /* Native vertex format */
59 #define MACH64_NATIVE_VTXFMT 1
61 /* Flags for what context state needs to be updated:
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
75 /* Flags for software fallback cases:
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
88 #define CARD32 GLuint /* KW: For building in mesa tree */
90 #if MACH64_NATIVE_VTXFMT
92 /* The vertex structures.
95 /* The size of this union is not of relevence:
97 union mach64_vertex_t {
104 typedef union mach64_vertex_t mach64Vertex, *mach64VertexPtr;
108 /* Use the templated vertex format:
110 #define TAG(x) mach64##x
111 #include "tnl_dd/t_dd_vertex.h"
114 #endif /* MACH64_NATIVE_VTXFMT */
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.
121 #define SUBPIXEL_X (0.0125F)
122 #define SUBPIXEL_Y (0.15F)
125 typedef void (*mach64_tri_func)( mach64ContextPtr,
130 typedef void (*mach64_line_func)( mach64ContextPtr,
134 typedef void (*mach64_point_func)( mach64ContextPtr,
137 struct mach64_texture_object {
138 driTextureObject base;
142 GLint heap; /* same as base.heap->heapId */
144 /* For communicating values from mach64AllocTexObj(), mach64SetTexImages()
145 * to mach64UpdateTextureUnit(). Alternately, we can use the tObj values or
146 * set the context registers directly.
155 GLboolean BilinearMin;
156 GLboolean BilinearMag;
161 typedef struct mach64_texture_object mach64TexObj, *mach64TexObjPtr;
163 struct mach64_context {
164 struct gl_context *glCtx;
166 /* Driver and hardware state management
169 GLuint dirty; /* Hardware state to be updated */
170 drm_mach64_context_regs_t setup;
175 GLuint SetupNewInputs;
177 GLfloat hw_viewport[16];
180 GLuint vertex_stride_shift;
181 GLuint vertex_format;
185 CARD32 Color; /* Current draw color */
186 CARD32 ClearColor; /* Color used to clear color buffer */
187 CARD32 ClearDepth; /* Value used to clear depth buffer */
189 /* Map GL texture units onto hardware
195 /* Texture object bookkeeping
197 mach64TexObjPtr CurrentTexObj[2];
199 GLint firstTexHeap, lastTexHeap;
200 driTexHeap *texture_heaps[MACH64_NR_TEX_HEAPS];
201 driTextureObject swapped;
203 /* Fallback rasterization functions
205 mach64_point_func draw_point;
206 mach64_line_func draw_line;
207 mach64_tri_func draw_tri;
210 GLfloat backface_sign;
219 GLenum render_primitive;
221 /* Visual, drawable, cliprect and scissor information
223 GLint drawOffset, drawPitch;
224 GLint drawX, drawY; /* origin of drawable in draw buffer */
225 GLint readOffset, readPitch;
227 GLuint numClipRects; /* Cliprects for the draw buffer */
228 drm_clip_rect_t *pClipRects;
231 drm_clip_rect_t ScissorRect; /* Current software scissor */
233 /* Mirrors of some DRI state
235 __DRIcontext *driContext; /* DRI context */
236 __DRIscreen *driScreen; /* DRI screen */
237 __DRIdrawable *driDrawable; /* DRI drawable bound to this ctx */
239 unsigned int lastStamp; /* mirror driDrawable->lastStamp */
241 drm_context_t hHWContext;
242 drm_hw_lock_t *driHwLock;
245 mach64ScreenPtr mach64Screen; /* Screen private DRI data */
246 drm_mach64_sarea_t *sarea; /* Private SAREA data */
248 GLuint hardwareWentIdle;
250 #if ENABLE_PERF_BOXES
251 /* Performance counters
253 GLuint boxes; /* Draw performance boxes */
256 GLuint c_textureSwaps;
257 GLuint c_textureBytes;
258 GLuint c_agpTextureBytes;
260 GLuint c_texsrc_card;
261 GLuint c_vertexBuffers;
268 /* Configuration cache
270 driOptionCache optionCache;
273 #define MACH64_CONTEXT(ctx) ((mach64ContextPtr)(ctx->DriverCtx))
276 extern GLboolean mach64CreateContext( gl_api api,
277 const struct gl_config *glVisual,
278 __DRIcontext *driContextPriv,
279 void *sharedContextPrivate );
281 extern void mach64DestroyContext( __DRIcontext * );
283 extern GLboolean mach64MakeCurrent( __DRIcontext *driContextPriv,
284 __DRIdrawable *driDrawPriv,
285 __DRIdrawable *driReadPriv );
287 extern GLboolean mach64UnbindContext( __DRIcontext *driContextPriv );
289 /* ================================================================
292 #if MESA_LITTLE_ENDIAN == 1
293 #define LE32_IN( x ) ( *(GLuint *)(x) )
294 #define LE32_IN_FLOAT( x ) ( *(GLfloat *)(x) )
295 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = (y); } while (0)
296 #define LE32_OUT_FLOAT( x, y ) do { *(GLfloat *)(x) = (y); } while (0)
298 #if defined(__OpenBSD__) || defined(__NetBSD__)
299 #include <machine/endian.h>
300 #define bswap_32 bswap32
302 #include <byteswap.h>
305 #define LE32_IN( x ) bswap_32( *(GLuint *)(x) )
306 #define LE32_IN_FLOAT( x ) \
308 GLuint __tmp = bswap_32( *(GLuint *)(x) ); \
309 *(GLfloat *)&__tmp; \
311 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = bswap_32( y ); } while (0)
312 #define LE32_OUT_FLOAT( x, y ) \
315 *(GLfloat *)&__tmp = (y); \
316 *(GLuint *)(x) = bswap_32( __tmp ); \
320 /* ================================================================
324 #define DMALOCALS CARD32 *buf=NULL; int requested=0; int outcount=0
326 /* called while locked for interleaved client-side state emits */
327 #define DMAGETPTR( dwords ) \
329 requested = (dwords); \
330 buf = (CARD32 *)mach64AllocDmaLocked( mmesa, ((dwords)*4) ); \
334 #define DMAOUTREG( reg, val ) \
336 LE32_OUT( &buf[outcount++], ADRINDEX( reg ) ); \
337 LE32_OUT( &buf[outcount++], ( val ) ); \
340 #define DMAADVANCE() \
342 if (outcount < requested) { \
343 mmesa->vert_used -= (requested - outcount) * 4; \
347 /* ================================================================
354 extern int MACH64_DEBUG;
356 #define MACH64_DEBUG 0
359 #define DEBUG_ALWAYS_SYNC 0x001
360 #define DEBUG_VERBOSE_API 0x002
361 #define DEBUG_VERBOSE_MSG 0x004
362 #define DEBUG_VERBOSE_LRU 0x008
363 #define DEBUG_VERBOSE_DRI 0x010
364 #define DEBUG_VERBOSE_IOCTL 0x020
365 #define DEBUG_VERBOSE_PRIMS 0x040
366 #define DEBUG_VERBOSE_COUNT 0x080
367 #define DEBUG_NOWAIT 0x100
368 #define DEBUG_VERBOSE_FALLBACK 0x200
369 #endif /* __MACH64_CONTEXT_H__ */