mesa: additional debug flags for glsl debug/disassembly
[mesa.git] / src / mesa / main / debug.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * 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.
23 */
24
25 #include "mtypes.h"
26 #include "context.h"
27 #include "imports.h"
28 #include "debug.h"
29 #include "get.h"
30
31 /**
32 * Primitive names
33 */
34 const char *_mesa_prim_name[GL_POLYGON+4] = {
35 "GL_POINTS",
36 "GL_LINES",
37 "GL_LINE_LOOP",
38 "GL_LINE_STRIP",
39 "GL_TRIANGLES",
40 "GL_TRIANGLE_STRIP",
41 "GL_TRIANGLE_FAN",
42 "GL_QUADS",
43 "GL_QUAD_STRIP",
44 "GL_POLYGON",
45 "outside begin/end",
46 "inside unkown primitive",
47 "unknown state"
48 };
49
50 void
51 _mesa_print_state( const char *msg, GLuint state )
52 {
53 _mesa_debug(NULL,
54 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
55 msg,
56 state,
57 (state & _NEW_MODELVIEW) ? "ctx->ModelView, " : "",
58 (state & _NEW_PROJECTION) ? "ctx->Projection, " : "",
59 (state & _NEW_TEXTURE_MATRIX) ? "ctx->TextureMatrix, " : "",
60 (state & _NEW_COLOR_MATRIX) ? "ctx->ColorMatrix, " : "",
61 (state & _NEW_ACCUM) ? "ctx->Accum, " : "",
62 (state & _NEW_COLOR) ? "ctx->Color, " : "",
63 (state & _NEW_DEPTH) ? "ctx->Depth, " : "",
64 (state & _NEW_EVAL) ? "ctx->Eval/EvalMap, " : "",
65 (state & _NEW_FOG) ? "ctx->Fog, " : "",
66 (state & _NEW_HINT) ? "ctx->Hint, " : "",
67 (state & _NEW_LIGHT) ? "ctx->Light, " : "",
68 (state & _NEW_LINE) ? "ctx->Line, " : "",
69 (state & _NEW_PIXEL) ? "ctx->Pixel, " : "",
70 (state & _NEW_POINT) ? "ctx->Point, " : "",
71 (state & _NEW_POLYGON) ? "ctx->Polygon, " : "",
72 (state & _NEW_POLYGONSTIPPLE) ? "ctx->PolygonStipple, " : "",
73 (state & _NEW_SCISSOR) ? "ctx->Scissor, " : "",
74 (state & _NEW_TEXTURE) ? "ctx->Texture, " : "",
75 (state & _NEW_TRANSFORM) ? "ctx->Transform, " : "",
76 (state & _NEW_VIEWPORT) ? "ctx->Viewport, " : "",
77 (state & _NEW_PACKUNPACK) ? "ctx->Pack/Unpack, " : "",
78 (state & _NEW_ARRAY) ? "ctx->Array, " : "",
79 (state & _NEW_RENDERMODE) ? "ctx->RenderMode, " : "",
80 (state & _NEW_BUFFERS) ? "ctx->Visual, ctx->DrawBuffer,, " : "");
81 }
82
83
84
85 void
86 _mesa_print_tri_caps( const char *name, GLuint flags )
87 {
88 _mesa_debug(NULL,
89 "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
90 name,
91 flags,
92 (flags & DD_FLATSHADE) ? "flat-shade, " : "",
93 (flags & DD_SEPARATE_SPECULAR) ? "separate-specular, " : "",
94 (flags & DD_TRI_LIGHT_TWOSIDE) ? "tri-light-twoside, " : "",
95 (flags & DD_TRI_TWOSTENCIL) ? "tri-twostencil, " : "",
96 (flags & DD_TRI_UNFILLED) ? "tri-unfilled, " : "",
97 (flags & DD_TRI_STIPPLE) ? "tri-stipple, " : "",
98 (flags & DD_TRI_OFFSET) ? "tri-offset, " : "",
99 (flags & DD_TRI_SMOOTH) ? "tri-smooth, " : "",
100 (flags & DD_LINE_SMOOTH) ? "line-smooth, " : "",
101 (flags & DD_LINE_STIPPLE) ? "line-stipple, " : "",
102 (flags & DD_LINE_WIDTH) ? "line-wide, " : "",
103 (flags & DD_POINT_SMOOTH) ? "point-smooth, " : "",
104 (flags & DD_POINT_SIZE) ? "point-size, " : "",
105 (flags & DD_POINT_ATTEN) ? "point-atten, " : "",
106 (flags & DD_TRI_CULL_FRONT_BACK) ? "cull-all, " : ""
107 );
108 }
109
110
111 /**
112 * Print information about this Mesa version and build options.
113 */
114 void _mesa_print_info( void )
115 {
116 _mesa_debug(NULL, "Mesa GL_VERSION = %s\n",
117 (char *) _mesa_GetString(GL_VERSION));
118 _mesa_debug(NULL, "Mesa GL_RENDERER = %s\n",
119 (char *) _mesa_GetString(GL_RENDERER));
120 _mesa_debug(NULL, "Mesa GL_VENDOR = %s\n",
121 (char *) _mesa_GetString(GL_VENDOR));
122 _mesa_debug(NULL, "Mesa GL_EXTENSIONS = %s\n",
123 (char *) _mesa_GetString(GL_EXTENSIONS));
124 #if defined(THREADS)
125 _mesa_debug(NULL, "Mesa thread-safe: YES\n");
126 #else
127 _mesa_debug(NULL, "Mesa thread-safe: NO\n");
128 #endif
129 #if defined(USE_X86_ASM)
130 _mesa_debug(NULL, "Mesa x86-optimized: YES\n");
131 #else
132 _mesa_debug(NULL, "Mesa x86-optimized: NO\n");
133 #endif
134 #if defined(USE_SPARC_ASM)
135 _mesa_debug(NULL, "Mesa sparc-optimized: YES\n");
136 #else
137 _mesa_debug(NULL, "Mesa sparc-optimized: NO\n");
138 #endif
139 }
140
141
142 /**
143 * Set the debugging flags.
144 *
145 * \param debug debug string
146 *
147 * If compiled with debugging support then search for keywords in \p debug and
148 * enables the verbose debug output of the respective feature.
149 */
150 static void add_debug_flags( const char *debug )
151 {
152 #ifdef DEBUG
153 struct debug_option {
154 const char *name;
155 GLbitfield flag;
156 };
157 static const struct debug_option debug_opt[] = {
158 { "varray", VERBOSE_VARRAY },
159 { "tex", VERBOSE_TEXTURE },
160 { "imm", VERBOSE_IMMEDIATE },
161 { "pipe", VERBOSE_PIPELINE },
162 { "driver", VERBOSE_DRIVER },
163 { "state", VERBOSE_STATE },
164 { "api", VERBOSE_API },
165 { "list", VERBOSE_DISPLAY_LIST },
166 { "lighting", VERBOSE_LIGHTING },
167 { "disassem", VERBOSE_DISASSEM },
168 { "glsl", VERBOSE_GLSL }, /* report GLSL compile/link errors */
169 { "glsl_dump", VERBOSE_GLSL_DUMP } /* print shader GPU instructions */
170 };
171 GLuint i;
172
173 MESA_VERBOSE = 0x0;
174 for (i = 0; i < Elements(debug_opt); i++) {
175 if (_mesa_strstr(debug, debug_opt[i].name))
176 MESA_VERBOSE |= debug_opt[i].flag;
177 }
178
179 /* Debug flag:
180 */
181 if (_mesa_strstr(debug, "flush"))
182 MESA_DEBUG_FLAGS |= DEBUG_ALWAYS_FLUSH;
183
184 #if defined(_FPU_GETCW) && defined(_FPU_SETCW)
185 if (_mesa_strstr(debug, "fpexceptions")) {
186 /* raise FP exceptions */
187 fpu_control_t mask;
188 _FPU_GETCW(mask);
189 mask &= ~(_FPU_MASK_IM | _FPU_MASK_DM | _FPU_MASK_ZM
190 | _FPU_MASK_OM | _FPU_MASK_UM);
191 _FPU_SETCW(mask);
192 }
193 #endif
194
195 #else
196 (void) debug;
197 #endif
198 }
199
200
201 void
202 _mesa_init_debug( GLcontext *ctx )
203 {
204 char *c;
205
206 /* Dither disable */
207 ctx->NoDither = _mesa_getenv("MESA_NO_DITHER") ? GL_TRUE : GL_FALSE;
208 if (ctx->NoDither) {
209 if (_mesa_getenv("MESA_DEBUG")) {
210 _mesa_debug(ctx, "MESA_NO_DITHER set - dithering disabled\n");
211 }
212 ctx->Color.DitherFlag = GL_FALSE;
213 }
214
215 c = _mesa_getenv("MESA_DEBUG");
216 if (c)
217 add_debug_flags(c);
218
219 c = _mesa_getenv("MESA_VERBOSE");
220 if (c)
221 add_debug_flags(c);
222 }
223