Add fallback debugging (R128_DEBUG=fall) output, and set DO_DEBUG=1 by default
[mesa.git] / src / mesa / drivers / dri / r128 / r128_context.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_context.h,v 1.12 2002/12/16 16:18:52 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Kevin E. Martin <martin@valinux.com>
32 * Gareth Hughes <gareth@valinux.com>
33 *
34 */
35
36 #ifndef __R128_CONTEXT_H__
37 #define __R128_CONTEXT_H__
38
39 #ifdef GLX_DIRECT_RENDERING
40
41 #include "dri_util.h"
42 #include "drm.h"
43 #include "r128_drm.h"
44
45 #include "mtypes.h"
46 #include "tnl/t_vertex.h"
47
48 #include "r128_reg.h"
49
50 #include "texmem.h"
51
52 struct r128_context;
53 typedef struct r128_context r128ContextRec;
54 typedef struct r128_context *r128ContextPtr;
55
56 #include "r128_lock.h"
57 #include "r128_texobj.h"
58 #include "r128_screen.h"
59
60 /* Flags for what context state needs to be updated:
61 */
62 #define R128_NEW_ALPHA 0x0001
63 #define R128_NEW_DEPTH 0x0002
64 #define R128_NEW_FOG 0x0004
65 #define R128_NEW_CLIP 0x0008
66 #define R128_NEW_CULL 0x0010
67 #define R128_NEW_MASKS 0x0020
68 #define R128_NEW_RENDER_NOT 0x0040
69 #define R128_NEW_WINDOW 0x0080
70 #define R128_NEW_CONTEXT 0x0100
71 #define R128_NEW_ALL 0x01ff
72
73 /* Flags for software fallback cases:
74 */
75 #define R128_FALLBACK_TEXTURE 0x0001
76 #define R128_FALLBACK_DRAW_BUFFER 0x0002
77 #define R128_FALLBACK_READ_BUFFER 0x0004
78 #define R128_FALLBACK_STENCIL 0x0008
79 #define R128_FALLBACK_RENDER_MODE 0x0010
80 #define R128_FALLBACK_LOGICOP 0x0020
81 #define R128_FALLBACK_SEP_SPECULAR 0x0040
82 #define R128_FALLBACK_BLEND_EQ 0x0080
83 #define R128_FALLBACK_BLEND_FUNC 0x0100
84 #define R128_FALLBACK_PROJTEX 0x0200
85 #define R128_FALLBACK_DISABLE 0x0400
86
87
88 /* Use the templated vertex format:
89 */
90 #define TAG(x) r128##x
91 #include "tnl_dd/t_dd_vertex.h"
92 #undef TAG
93
94 /* Reasons why the GL_BLEND fallback mightn't work:
95 */
96 #define R128_BLEND_ENV_COLOR 0x1
97 #define R128_BLEND_MULTITEX 0x2
98
99 /* Subpixel offsets for window coordinates (triangles):
100 */
101 #define SUBPIXEL_X (0.0F)
102 #define SUBPIXEL_Y (0.125F)
103
104
105 typedef void (*r128_tri_func)( r128ContextPtr,
106 r128Vertex *,
107 r128Vertex *,
108 r128Vertex * );
109
110 typedef void (*r128_line_func)( r128ContextPtr,
111 r128Vertex *,
112 r128Vertex * );
113
114 typedef void (*r128_point_func)( r128ContextPtr,
115 r128Vertex * );
116
117
118 struct r128_context {
119 GLcontext *glCtx; /* Mesa context */
120
121 /* Driver and hardware state management
122 */
123 GLuint new_state;
124 GLuint dirty; /* Hardware state to be updated */
125 drm_r128_context_regs_t setup;
126
127 /* Vertex state */
128 GLuint vertex_size;
129 GLuint vertex_format;
130 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
131 GLuint vertex_attr_count;
132 char *verts; /* points to tnl->clipspace.vertex_buf */
133 GLuint num_verts;
134 int coloroffset, specoffset;
135 int tnl_state; /* tnl->render_inputs for this _tnl_install_attrs */
136
137 GLuint NewGLState;
138 GLuint Fallback;
139 GLuint RenderIndex;
140 GLfloat hw_viewport[16];
141 GLfloat depth_scale;
142
143 uint32_t ClearColor; /* Color used to clear color buffer */
144 uint32_t ClearDepth; /* Value used to clear depth buffer */
145 uint32_t ClearStencil; /* Value used to clear stencil */
146
147 /* Map GL texture units onto hardware
148 */
149 GLint multitex;
150 GLint tmu_source[2];
151 GLuint tex_combine[2];
152 GLuint blend_flags;
153 GLuint env_color;
154
155 /* Texture object bookkeeping
156 */
157 unsigned nr_heaps;
158 driTexHeap * texture_heaps[ R128_NR_TEX_HEAPS ];
159 driTextureObject swapped;
160
161 r128TexObjPtr CurrentTexObj[2];
162
163 int texture_depth;
164
165 /* Fallback rasterization functions
166 */
167 r128_point_func draw_point;
168 r128_line_func draw_line;
169 r128_tri_func draw_tri;
170
171 /* Vertex buffers
172 */
173 drmBufPtr vert_buf;
174
175 GLuint hw_primitive;
176 GLenum render_primitive;
177
178 /* Page flipping
179 */
180 GLuint doPageFlip;
181
182 /* Drawable, cliprect and scissor information
183 */
184 GLint drawOffset, drawPitch;
185 GLint readOffset, readPitch;
186
187 GLuint numClipRects; /* Cliprects for the draw buffer */
188 drm_clip_rect_t *pClipRects;
189
190 GLuint scissor;
191 drm_clip_rect_t ScissorRect; /* Current software scissor */
192
193 /* Mirrors of some DRI state
194 */
195 __DRIcontextPrivate *driContext; /* DRI context */
196 __DRIscreenPrivate *driScreen; /* DRI screen */
197 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
198
199 unsigned int lastStamp; /* mirror driDrawable->lastStamp */
200
201 drm_context_t hHWContext;
202 drm_hw_lock_t *driHwLock;
203 int driFd;
204
205 r128ScreenPtr r128Screen; /* Screen private DRI data */
206 drm_r128_sarea_t *sarea; /* Private SAREA data */
207
208 /* Performance counters
209 */
210 GLuint boxes; /* Draw performance boxes */
211 GLuint hardwareWentIdle;
212 GLuint c_clears;
213 GLuint c_drawWaits;
214 GLuint c_textureSwaps;
215 GLuint c_textureBytes;
216 GLuint c_vertexBuffers;
217
218 /* VBI
219 */
220 GLuint vbl_seq;
221 GLuint vblank_flags;
222
223 /* Configuration cache
224 */
225 driOptionCache optionCache;
226 };
227
228 #define R128_CONTEXT(ctx) ((r128ContextPtr)(ctx->DriverCtx))
229
230 #define R128_IS_PLAIN( rmesa ) \
231 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128)
232 #define R128_IS_PRO( rmesa ) \
233 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_PRO)
234 #define R128_IS_MOBILITY( rmesa ) \
235 (rmesa->r128Screen->chipset == R128_CARD_TYPE_R128_MOBILITY)
236
237
238 extern GLboolean r128CreateContext( const __GLcontextModes *glVisual,
239 __DRIcontextPrivate *driContextPriv,
240 void *sharedContextPrivate );
241
242 extern void r128DestroyContext( __DRIcontextPrivate * );
243
244 extern GLboolean r128MakeCurrent( __DRIcontextPrivate *driContextPriv,
245 __DRIdrawablePrivate *driDrawPriv,
246 __DRIdrawablePrivate *driReadPriv );
247
248 extern GLboolean r128UnbindContext( __DRIcontextPrivate *driContextPriv );
249
250 /* ================================================================
251 * Debugging:
252 */
253 #define DO_DEBUG 1
254 #define ENABLE_PERF_BOXES 0
255
256 #if DO_DEBUG
257 extern int R128_DEBUG;
258 #else
259 #define R128_DEBUG 0
260 #endif
261
262 #define DEBUG_ALWAYS_SYNC 0x01
263 #define DEBUG_VERBOSE_API 0x02
264 #define DEBUG_VERBOSE_MSG 0x04
265 #define DEBUG_VERBOSE_LRU 0x08
266 #define DEBUG_VERBOSE_DRI 0x10
267 #define DEBUG_VERBOSE_IOCTL 0x20
268 #define DEBUG_VERBOSE_2D 0x40
269 #define DEBUG_VERBOSE_FALL 0x80
270
271 #endif
272 #endif /* __R128_CONTEXT_H__ */