Merge branch 'master' of git+ssh://znh@git.freedesktop.org/git/mesa/mesa into 965...
[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 "mtypes.h"
47 #include "radeon_screen.h"
48 #include "drm.h"
49 #include "dri_util.h"
50 #include "colormac.h"
51
52 struct radeon_context;
53 typedef struct radeon_context radeonContextRec;
54 typedef struct radeon_context *radeonContextPtr;
55
56 #define TEX_0 0x1
57 #define TEX_1 0x2
58 #define TEX_2 0x4
59 #define TEX_3 0x8
60 #define TEX_4 0x10
61 #define TEX_5 0x20
62 #define TEX_6 0x40
63 #define TEX_7 0x80
64 #define TEX_ALL 0xff
65
66 /* Rasterizing fallbacks */
67 /* See correponding strings in r200_swtcl.c */
68 #define RADEON_FALLBACK_TEXTURE 0x0001
69 #define RADEON_FALLBACK_DRAW_BUFFER 0x0002
70 #define RADEON_FALLBACK_STENCIL 0x0004
71 #define RADEON_FALLBACK_RENDER_MODE 0x0008
72 #define RADEON_FALLBACK_BLEND_EQ 0x0010
73 #define RADEON_FALLBACK_BLEND_FUNC 0x0020
74 #define RADEON_FALLBACK_DISABLE 0x0040
75 #define RADEON_FALLBACK_BORDER_MODE 0x0080
76
77 #if R200_MERGED
78 extern void radeonFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
79
80 #define FALLBACK( radeon, bit, mode ) do { \
81 if ( 0 ) fprintf( stderr, "FALLBACK in %s: #%d=%d\n", \
82 __FUNCTION__, bit, mode ); \
83 radeonFallback( (radeon)->glCtx, bit, mode ); \
84 } while (0)
85 #else
86 #define FALLBACK( radeon, bit, mode ) fprintf(stderr, "%s:%s\n", __LINE__, __FILE__);
87 #endif
88
89 /* TCL fallbacks */
90 extern void radeonTclFallback(GLcontext * ctx, GLuint bit, GLboolean mode);
91
92 #define RADEON_TCL_FALLBACK_RASTER 0x0001 /* rasterization */
93 #define RADEON_TCL_FALLBACK_UNFILLED 0x0002 /* unfilled tris */
94 #define RADEON_TCL_FALLBACK_LIGHT_TWOSIDE 0x0004 /* twoside tris */
95 #define RADEON_TCL_FALLBACK_MATERIAL 0x0008 /* material in vb */
96 #define RADEON_TCL_FALLBACK_TEXGEN_0 0x0010 /* texgen, unit 0 */
97 #define RADEON_TCL_FALLBACK_TEXGEN_1 0x0020 /* texgen, unit 1 */
98 #define RADEON_TCL_FALLBACK_TEXGEN_2 0x0040 /* texgen, unit 2 */
99 #define RADEON_TCL_FALLBACK_TEXGEN_3 0x0080 /* texgen, unit 3 */
100 #define RADEON_TCL_FALLBACK_TEXGEN_4 0x0100 /* texgen, unit 4 */
101 #define RADEON_TCL_FALLBACK_TEXGEN_5 0x0200 /* texgen, unit 5 */
102 #define RADEON_TCL_FALLBACK_TCL_DISABLE 0x0400 /* user disable */
103 #define RADEON_TCL_FALLBACK_BITMAP 0x0800 /* draw bitmap with points */
104 #define RADEON_TCL_FALLBACK_VERTEX_PROGRAM 0x1000 /* vertex program active */
105
106 #if R200_MERGED
107 #define TCL_FALLBACK( ctx, bit, mode ) radeonTclFallback( ctx, bit, mode )
108 #else
109 #define TCL_FALLBACK( ctx, bit, mode ) ;
110 #endif
111
112 struct radeon_dri_mirror {
113 __DRIcontextPrivate *context; /* DRI context */
114 __DRIscreenPrivate *screen; /* DRI screen */
115 /**
116 * DRI drawable bound to this context for drawing.
117 */
118 __DRIdrawablePrivate *drawable;
119
120 /**
121 * DRI drawable bound to this context for reading.
122 */
123 __DRIdrawablePrivate *readable;
124
125 drm_context_t hwContext;
126 drm_hw_lock_t *hwLock;
127 int fd;
128 int drmMinor;
129 };
130
131 /**
132 * Derived state for internal purposes.
133 */
134 struct radeon_scissor_state {
135 drm_clip_rect_t rect;
136 GLboolean enabled;
137
138 GLuint numClipRects; /* Cliprects active */
139 GLuint numAllocedClipRects; /* Cliprects available */
140 drm_clip_rect_t *pClipRects;
141 };
142
143 struct radeon_colorbuffer_state {
144 GLuint clear;
145 GLint drawOffset, drawPitch;
146 };
147
148 struct radeon_state {
149 struct radeon_colorbuffer_state color;
150 struct radeon_scissor_state scissor;
151 };
152
153 /**
154 * Common per-context variables shared by R200 and R300.
155 * R200- and R300-specific code "derive" their own context from this
156 * structure.
157 */
158 struct radeon_context {
159 GLcontext *glCtx; /* Mesa context */
160 radeonScreenPtr radeonScreen; /* Screen private DRI data */
161
162 /* Fallback state */
163 GLuint Fallback;
164 GLuint TclFallback;
165
166 /* Page flipping */
167 GLuint doPageFlip;
168
169 /* Drawable, cliprect and scissor information */
170 GLuint numClipRects; /* Cliprects for the draw buffer */
171 drm_clip_rect_t *pClipRects;
172 unsigned int lastStamp;
173 GLboolean lost_context;
174 drm_radeon_sarea_t *sarea; /* Private SAREA data */
175
176 /* Mirrors of some DRI state */
177 struct radeon_dri_mirror dri;
178
179 /* Busy waiting */
180 GLuint do_usleeps;
181 GLuint do_irqs;
182 GLuint irqsEmitted;
183 drm_radeon_irq_wait_t iw;
184
185 /* VBI / buffer swap */
186 GLuint vbl_seq;
187 GLuint vblank_flags;
188
189 int64_t swap_ust;
190 int64_t swap_missed_ust;
191
192 GLuint swap_count;
193 GLuint swap_missed_count;
194
195 /* Derived state */
196 struct radeon_state state;
197
198 /* Configuration cache
199 */
200 driOptionCache optionCache;
201 };
202
203 #define RADEON_CONTEXT(glctx) ((radeonContextPtr)(ctx->DriverCtx))
204
205 extern void radeonSwapBuffers(__DRIdrawablePrivate * dPriv);
206 extern void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
207 int x, int y, int w, int h);
208 extern GLboolean radeonInitContext(radeonContextPtr radeon,
209 struct dd_function_table *functions,
210 const __GLcontextModes * glVisual,
211 __DRIcontextPrivate * driContextPriv,
212 void *sharedContextPrivate);
213 extern void radeonCleanupContext(radeonContextPtr radeon);
214 extern GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
215 __DRIdrawablePrivate * driDrawPriv,
216 __DRIdrawablePrivate * driReadPriv);
217 extern GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv);
218
219 /* ================================================================
220 * Debugging:
221 */
222 #define DO_DEBUG 1
223
224 #if DO_DEBUG
225 extern int RADEON_DEBUG;
226 #else
227 #define RADEON_DEBUG 0
228 #endif
229
230 #define DEBUG_TEXTURE 0x0001
231 #define DEBUG_STATE 0x0002
232 #define DEBUG_IOCTL 0x0004
233 #define DEBUG_PRIMS 0x0008
234 #define DEBUG_VERTS 0x0010
235 #define DEBUG_FALLBACKS 0x0020
236 #define DEBUG_VFMT 0x0040
237 #define DEBUG_CODEGEN 0x0080
238 #define DEBUG_VERBOSE 0x0100
239 #define DEBUG_DRI 0x0200
240 #define DEBUG_DMA 0x0400
241 #define DEBUG_SANITY 0x0800
242 #define DEBUG_SYNC 0x1000
243 #define DEBUG_PIXEL 0x2000
244 #define DEBUG_MEMORY 0x4000
245
246 #endif /* __RADEON_CONTEXT_H__ */