Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_context.h
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
6
7 The Weather Channel (TM) funded Tungsten Graphics to develop the
8 initial release of the Radeon 8500 driver under the XFree86 license.
9 This notice must be preserved.
10
11 All Rights Reserved.
12
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
20
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial
23 portions of the Software.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
29 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
33 **************************************************************************/
34
35 /*
36 * Authors:
37 * Gareth Hughes <gareth@valinux.com>
38 * Keith Whitwell <keith@tungstengraphics.com>
39 * Kevin E. Martin <martin@valinux.com>
40 * Nicolai Haehnle <prefect_@gmx.net>
41 */
42
43 #ifndef __RADEON_CONTEXT_H__
44 #define __RADEON_CONTEXT_H__
45
46 #include "main/mtypes.h"
47 #include "main/colormac.h"
48 #include "radeon_screen.h"
49 #include "drm.h"
50 #include "dri_util.h"
51
52 struct radeon_context;
53 typedef struct radeon_context radeonContextRec;
54 typedef struct radeon_context *radeonContextPtr;
55
56 /* Rasterizing fallbacks */
57 /* See correponding strings in r200_swtcl.c */
58 #define RADEON_FALLBACK_TEXTURE 0x0001
59 #define RADEON_FALLBACK_DRAW_BUFFER 0x0002
60 #define RADEON_FALLBACK_STENCIL 0x0004
61 #define RADEON_FALLBACK_RENDER_MODE 0x0008
62 #define RADEON_FALLBACK_BLEND_EQ 0x0010
63 #define RADEON_FALLBACK_BLEND_FUNC 0x0020
64 #define RADEON_FALLBACK_DISABLE 0x0040
65 #define RADEON_FALLBACK_BORDER_MODE 0x0080
66
67 #if R200_MERGED
68 extern void radeonFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
69
70 #define FALLBACK( radeon, bit, mode ) do { \
71 if ( 0 ) fprintf( stderr, "FALLBACK in %s: #%d=%d\n", \
72 __FUNCTION__, bit, mode ); \
73 radeonFallback( (radeon)->glCtx, bit, mode ); \
74 } while (0)
75 #else
76 #define FALLBACK( radeon, bit, mode ) fprintf(stderr, "%s:%s\n", __LINE__, __FILE__);
77 #endif
78
79 /* TCL fallbacks */
80 extern void radeonTclFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
81
82 #define RADEON_TCL_FALLBACK_RASTER 0x0001 /* rasterization */
83 #define RADEON_TCL_FALLBACK_UNFILLED 0x0002 /* unfilled tris */
84 #define RADEON_TCL_FALLBACK_LIGHT_TWOSIDE 0x0004 /* twoside tris */
85 #define RADEON_TCL_FALLBACK_MATERIAL 0x0008 /* material in vb */
86 #define RADEON_TCL_FALLBACK_TEXGEN_0 0x0010 /* texgen, unit 0 */
87 #define RADEON_TCL_FALLBACK_TEXGEN_1 0x0020 /* texgen, unit 1 */
88 #define RADEON_TCL_FALLBACK_TEXGEN_2 0x0040 /* texgen, unit 2 */
89 #define RADEON_TCL_FALLBACK_TEXGEN_3 0x0080 /* texgen, unit 3 */
90 #define RADEON_TCL_FALLBACK_TEXGEN_4 0x0100 /* texgen, unit 4 */
91 #define RADEON_TCL_FALLBACK_TEXGEN_5 0x0200 /* texgen, unit 5 */
92 #define RADEON_TCL_FALLBACK_TCL_DISABLE 0x0400 /* user disable */
93 #define RADEON_TCL_FALLBACK_BITMAP 0x0800 /* draw bitmap with points */
94 #define RADEON_TCL_FALLBACK_VERTEX_PROGRAM 0x1000 /* vertex program active */
95
96 #if R200_MERGED
97 #define TCL_FALLBACK( ctx, bit, mode ) radeonTclFallback( ctx, bit, mode )
98 #else
99 #define TCL_FALLBACK( ctx, bit, mode ) ;
100 #endif
101
102 struct radeon_dri_mirror {
103 __DRIcontextPrivate *context; /* DRI context */
104 __DRIscreenPrivate *screen; /* DRI screen */
105 /**
106 * DRI drawable bound to this context for drawing.
107 */
108 __DRIdrawablePrivate *drawable;
109
110 /**
111 * DRI drawable bound to this context for reading.
112 */
113 __DRIdrawablePrivate *readable;
114
115 drm_context_t hwContext;
116 drm_hw_lock_t *hwLock;
117 int fd;
118 int drmMinor;
119 };
120
121 /**
122 * Derived state for internal purposes.
123 */
124 struct radeon_scissor_state {
125 drm_clip_rect_t rect;
126 GLboolean enabled;
127
128 GLuint numClipRects; /* Cliprects active */
129 GLuint numAllocedClipRects; /* Cliprects available */
130 drm_clip_rect_t *pClipRects;
131 };
132
133 struct radeon_colorbuffer_state {
134 GLuint clear;
135 GLint drawOffset, drawPitch;
136 };
137
138 struct radeon_state {
139 struct radeon_colorbuffer_state color;
140 struct radeon_scissor_state scissor;
141 };
142
143 /**
144 * Common per-context variables shared by R200 and R300.
145 * R200- and R300-specific code "derive" their own context from this
146 * structure.
147 */
148 struct radeon_context {
149 GLcontext *glCtx; /* Mesa context */
150 radeonScreenPtr radeonScreen; /* Screen private DRI data */
151
152 /* Fallback state */
153 GLuint Fallback;
154 GLuint TclFallback;
155
156 /* Page flipping */
157 GLuint doPageFlip;
158
159 /* Drawable, cliprect and scissor information */
160 GLuint numClipRects; /* Cliprects for the draw buffer */
161 drm_clip_rect_t *pClipRects;
162 unsigned int lastStamp;
163 GLboolean lost_context;
164 drm_radeon_sarea_t *sarea; /* Private SAREA data */
165
166 /* Mirrors of some DRI state */
167 struct radeon_dri_mirror dri;
168
169 /* Busy waiting */
170 GLuint do_usleeps;
171 GLuint do_irqs;
172 GLuint irqsEmitted;
173 drm_radeon_irq_wait_t iw;
174
175 /* buffer swap */
176 int64_t swap_ust;
177 int64_t swap_missed_ust;
178
179 GLuint swap_count;
180 GLuint swap_missed_count;
181
182 /* Derived state */
183 struct radeon_state state;
184
185 /* Configuration cache
186 */
187 driOptionCache optionCache;
188 };
189
190 #define RADEON_CONTEXT(glctx) ((radeonContextPtr)(ctx->DriverCtx))
191
192 extern void radeonSwapBuffers(__DRIdrawablePrivate * dPriv);
193 extern void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
194 int x, int y, int w, int h);
195 extern GLboolean radeonInitContext(radeonContextPtr radeon,
196 struct dd_function_table *functions,
197 const __GLcontextModes * glVisual,
198 __DRIcontextPrivate * driContextPriv,
199 void *sharedContextPrivate);
200 extern void radeonCleanupContext(radeonContextPtr radeon);
201 extern GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
202 __DRIdrawablePrivate * driDrawPriv,
203 __DRIdrawablePrivate * driReadPriv);
204 extern GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv);
205
206 /* ================================================================
207 * Debugging:
208 */
209 #define DO_DEBUG 1
210
211 #if DO_DEBUG
212 extern int RADEON_DEBUG;
213 #else
214 #define RADEON_DEBUG 0
215 #endif
216
217 #define DEBUG_TEXTURE 0x0001
218 #define DEBUG_STATE 0x0002
219 #define DEBUG_IOCTL 0x0004
220 #define DEBUG_PRIMS 0x0008
221 #define DEBUG_VERTS 0x0010
222 #define DEBUG_FALLBACKS 0x0020
223 #define DEBUG_VFMT 0x0040
224 #define DEBUG_CODEGEN 0x0080
225 #define DEBUG_VERBOSE 0x0100
226 #define DEBUG_DRI 0x0200
227 #define DEBUG_DMA 0x0400
228 #define DEBUG_SANITY 0x0800
229 #define DEBUG_SYNC 0x1000
230 #define DEBUG_PIXEL 0x2000
231 #define DEBUG_MEMORY 0x4000
232
233 #endif /* __RADEON_CONTEXT_H__ */