1 /* $XFree86$ */ /* -*- 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__
35 #ifdef GLX_DIRECT_RENDERING
40 #include "mach64_common.h"
45 #include "mach64_reg.h"
49 struct mach64_context
;
50 typedef struct mach64_context mach64ContextRec
;
51 typedef struct mach64_context
*mach64ContextPtr
;
53 #include "mach64_lock.h"
54 #include "mach64_screen.h"
56 /* Experimental driver options */
57 #define MACH64_CLIENT_STATE_EMITS 0
59 /* Performace monitoring */
60 #define ENABLE_PERF_BOXES 1
62 /* Native vertex format */
63 #define MACH64_NATIVE_VTXFMT 1
65 /* Flags for what context state needs to be updated:
67 #define MACH64_NEW_ALPHA 0x0001
68 #define MACH64_NEW_DEPTH 0x0002
69 #define MACH64_NEW_FOG 0x0004
70 #define MACH64_NEW_CLIP 0x0008
71 #define MACH64_NEW_CULL 0x0010
72 #define MACH64_NEW_MASKS 0x0020
73 #define MACH64_NEW_RENDER_UNUSED 0x0040
74 #define MACH64_NEW_WINDOW 0x0080
75 #define MACH64_NEW_TEXTURE 0x0100
76 #define MACH64_NEW_CONTEXT 0x0200
77 #define MACH64_NEW_ALL 0x03ff
79 /* Flags for software fallback cases:
81 #define MACH64_FALLBACK_TEXTURE 0x0001
82 #define MACH64_FALLBACK_DRAW_BUFFER 0x0002
83 #define MACH64_FALLBACK_READ_BUFFER 0x0004
84 #define MACH64_FALLBACK_STENCIL 0x0008
85 #define MACH64_FALLBACK_RENDER_MODE 0x0010
86 #define MACH64_FALLBACK_MULTIDRAW 0x0020
87 #define MACH64_FALLBACK_LOGICOP 0x0040
88 #define MACH64_FALLBACK_SEP_SPECULAR 0x0080
89 #define MACH64_FALLBACK_BLEND_EQ 0x0100
90 #define MACH64_FALLBACK_BLEND_FUNC 0x0200
92 #if MACH64_NATIVE_VTXFMT
94 /* The vertex structures.
98 /* This isn't actually necessary since all accesses to the vertex
99 * structure must be made through the LE32_* macros.
110 GLfloat u1
, v1
, w1
; /* Texture 1 coordinates */
111 GLfloat u0
, v0
, w0
; /* Texture 0 coordinates */
112 mach64_color_t specular
; /* Specular color */
113 GLuint z
; /* Depth coordinate */
114 mach64_color_t color
; /* Diffuse color */
115 GLushort y
, x
; /* Coordinates in screen space */
119 /* The size of this union is not of relevence:
121 union mach64_vertex_t
{
128 typedef union mach64_vertex_t mach64Vertex
, *mach64VertexPtr
;
132 /* Use the templated vertex format:
134 #define TAG(x) mach64##x
135 #include "tnl_dd/t_dd_vertex.h"
138 #endif /* MACH64_NATIVE_VTXFMT */
140 /* Subpixel offsets for window coordinates:
141 * These are enough to fix most glean tests except polygonOffset.
142 * There are also still some gaps that show in e.g. the tunnel Mesa demo
143 * or the lament xscreensaver hack.
145 #define SUBPIXEL_X (0.0125F)
146 #define SUBPIXEL_Y (0.15F)
149 typedef void (*mach64_tri_func
)( mach64ContextPtr
,
154 typedef void (*mach64_line_func
)( mach64ContextPtr
,
158 typedef void (*mach64_point_func
)( mach64ContextPtr
,
162 struct mach64_texture_object
{
163 driTextureObject base
;
177 /* Have to keep these separate due to how they are programmed.
178 * FIXME: Why don't we just use the tObj values?
180 GLboolean BilinearMin
;
181 GLboolean BilinearMag
;
186 struct mach64_texture_object
{
187 struct mach64_texture_object
*next
;
188 struct mach64_texture_object
*prev
;
189 struct gl_texture_object
*tObj
;
208 /* Have to keep these separate due to how they are programmed.
209 * FIXME: Why don't we just use the tObj values?
211 GLboolean BilinearMin
;
212 GLboolean BilinearMag
;
218 typedef struct mach64_texture_object mach64TexObj
, *mach64TexObjPtr
;
221 struct mach64_context
{
224 /* Driver and hardware state management
227 GLuint dirty
; /* Hardware state to be updated */
228 mach64_context_regs_t setup
;
233 GLuint SetupNewInputs
;
235 GLfloat hw_viewport
[16];
238 GLuint vertex_stride_shift
;
239 GLuint vertex_format
;
243 CARD32 Color
; /* Current draw color */
244 CARD32 ClearColor
; /* Color used to clear color buffer */
245 CARD32 ClearDepth
; /* Value used to clear depth buffer */
247 /* Map GL texture units onto hardware
253 /* Texture object bookkeeping
255 mach64TexObjPtr CurrentTexObj
[2];
258 driTexHeap
* texture_heaps
[ R128_NR_TEX_HEAPS
];
259 driTextureObject swapped
;
261 mach64TexObj TexObjList
[MACH64_NR_TEX_HEAPS
];
262 mach64TexObj SwappedOut
;
263 memHeap_t
*texHeap
[MACH64_NR_TEX_HEAPS
];
264 GLuint lastTexAge
[MACH64_NR_TEX_HEAPS
];
265 GLint firstTexHeap
, lastTexHeap
;
268 /* Fallback rasterization functions
270 mach64_point_func draw_point
;
271 mach64_line_func draw_line
;
272 mach64_tri_func draw_tri
;
275 GLfloat backface_sign
;
284 GLenum render_primitive
;
286 /* Visual, drawable, cliprect and scissor information
288 GLint drawOffset
, drawPitch
;
289 GLint drawX
, drawY
; /* origin of drawable in draw buffer */
290 GLint readOffset
, readPitch
;
292 GLuint numClipRects
; /* Cliprects for the draw buffer */
293 drm_clip_rect_t
*pClipRects
;
296 drm_clip_rect_t ScissorRect
; /* Current software scissor */
298 /* Mirrors of some DRI state
300 __DRIcontextPrivate
*driContext
; /* DRI context */
301 __DRIscreenPrivate
*driScreen
; /* DRI screen */
302 __DRIdrawablePrivate
*driDrawable
; /* DRI drawable bound to this ctx */
304 unsigned int lastStamp
; /* mirror driDrawable->lastStamp */
306 drmContext hHWContext
;
307 drm_hw_lock_t
*driHwLock
;
310 mach64ScreenPtr mach64Screen
; /* Screen private DRI data */
311 ATISAREAPrivPtr sarea
; /* Private SAREA data */
313 GLuint hardwareWentIdle
;
315 #if ENABLE_PERF_BOXES
316 /* Performance counters
318 GLuint boxes
; /* Draw performance boxes */
321 GLuint c_textureSwaps
;
322 GLuint c_textureBytes
;
323 GLuint c_agpTextureBytes
;
325 GLuint c_texsrc_card
;
326 GLuint c_vertexBuffers
;
335 /* Configuration cache
337 driOptionCache optionCache
;
340 #define MACH64_CONTEXT(ctx) ((mach64ContextPtr)(ctx->DriverCtx))
343 extern GLboolean
mach64CreateContext( const __GLcontextModes
*glVisual
,
344 __DRIcontextPrivate
*driContextPriv
,
345 void *sharedContextPrivate
);
347 extern void mach64DestroyContext( __DRIcontextPrivate
* );
349 extern GLboolean
mach64MakeCurrent( __DRIcontextPrivate
*driContextPriv
,
350 __DRIdrawablePrivate
*driDrawPriv
,
351 __DRIdrawablePrivate
*driReadPriv
);
353 extern GLboolean
mach64UnbindContext( __DRIcontextPrivate
*driContextPriv
);
355 /* ================================================================
358 #include "X11/Xarch.h"
360 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
361 #define LE32_IN( x ) ( *(GLuint *)(x) )
362 #define LE32_IN_FLOAT( x ) ( *(GLfloat *)(x) )
363 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = (y); } while (0)
364 #define LE32_OUT_FLOAT( x, y ) do { *(GLfloat *)(x) = (y); } while (0)
366 #include <byteswap.h>
367 #define LE32_IN( x ) bswap_32( *(GLuint *)(x) )
368 #define LE32_IN_FLOAT( x ) \
370 GLuint __tmp = bswap_32( *(GLuint *)(x) ); \
371 *(GLfloat *)&__tmp; \
373 #define LE32_OUT( x, y ) do { *(GLuint *)(x) = bswap_32( y ); } while (0)
374 #define LE32_OUT_FLOAT( x, y ) \
377 *(GLfloat *)&__tmp = (y); \
378 *(GLuint *)(x) = bswap_32( __tmp ); \
382 /* ================================================================
386 #define DMALOCALS CARD32 *buf=NULL; int requested=0; int outcount=0
388 /* called while locked for interleaved client-side state emits */
389 #define DMAGETPTR( dwords ) \
391 requested = (dwords); \
392 buf = (CARD32 *)mach64AllocDmaLocked( mmesa, ((dwords)*4) ); \
396 #define DMAOUTREG( reg, val ) \
398 LE32_OUT( &buf[outcount++], ADRINDEX( reg ) ); \
399 LE32_OUT( &buf[outcount++], ( val ) ); \
402 #define DMAADVANCE() \
404 if (outcount < requested) { \
405 mmesa->vert_used -= (requested - outcount) * 4; \
409 /* ================================================================
416 extern int MACH64_DEBUG
;
418 #define MACH64_DEBUG 0
421 #define DEBUG_ALWAYS_SYNC 0x001
422 #define DEBUG_VERBOSE_API 0x002
423 #define DEBUG_VERBOSE_MSG 0x004
424 #define DEBUG_VERBOSE_LRU 0x008
425 #define DEBUG_VERBOSE_DRI 0x010
426 #define DEBUG_VERBOSE_IOCTL 0x020
427 #define DEBUG_VERBOSE_PRIMS 0x040
428 #define DEBUG_VERBOSE_COUNT 0x080
429 #define DEBUG_NOWAIT 0x100
431 #endif /* __MACH64_CONTEXT_H__ */