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