1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 
29 #include "main/context.h"
30 #include "main/debug_output.h"
31 #include "program/prog_print.h"
32 
33 #include "pipe/p_state.h"
34 #include "pipe/p_shader_tokens.h"
35 #include "tgsi/tgsi_dump.h"
36 
37 #include "cso_cache/cso_cache.h"
38 
39 #include "st_context.h"
40 #include "st_debug.h"
41 #include "st_program.h"
42 
43 
44 
45 #ifdef DEBUG
46 int ST_DEBUG = 0;
47 
48 static const struct debug_named_value st_debug_flags[] = {
49    { "mesa",     DEBUG_MESA, NULL },
50    { "tgsi",     DEBUG_TGSI, NULL },
51    { "constants",DEBUG_CONSTANTS, NULL },
52    { "pipe",     DEBUG_PIPE, NULL },
53    { "tex",      DEBUG_TEX, NULL },
54    { "fallback", DEBUG_FALLBACK, NULL },
55    { "screen",   DEBUG_SCREEN, NULL },
56    { "query",    DEBUG_QUERY, NULL },
57    { "draw",     DEBUG_DRAW, NULL },
58    { "buffer",   DEBUG_BUFFER, NULL },
59    { "wf",       DEBUG_WIREFRAME, NULL },
60    { "precompile",  DEBUG_PRECOMPILE, NULL },
61    { "gremedy",  DEBUG_GREMEDY, "Enable GREMEDY debug extensions" },
62    { "noreadpixcache", DEBUG_NOREADPIXCACHE, NULL },
63    DEBUG_NAMED_VALUE_END
64 };
65 
66 DEBUG_GET_ONCE_FLAGS_OPTION(st_debug, "ST_DEBUG", st_debug_flags, 0)
67 #endif
68 
69 
70 void
st_debug_init(void)71 st_debug_init(void)
72 {
73 #ifdef DEBUG
74    ST_DEBUG = debug_get_option_st_debug();
75 #endif
76 }
77 
78 
79 
80 /**
81  * Print current state.  May be called from inside gdb to see currently
82  * bound vertex/fragment shaders and associated constants.
83  */
84 void
st_print_current(void)85 st_print_current(void)
86 {
87    GET_CURRENT_CONTEXT(ctx);
88    struct st_context *st = st_context(ctx);
89 
90 #if 0
91    int i;
92 
93    printf("Vertex Transform Inputs:\n");
94    for (i = 0; i < st->vp->state.num_inputs; i++) {
95       printf("  Slot %d:  VERT_ATTRIB_%d\n", i, st->vp->index_to_input[i]);
96    }
97 #endif
98 
99    if (st->vp->variants)
100       tgsi_dump( st->vp->variants[0].tgsi.tokens, 0 );
101    if (st->vp->Base.Parameters)
102       _mesa_print_parameter_list(st->vp->Base.Parameters);
103 
104    tgsi_dump(st->fp->tgsi.tokens, 0);
105    if (st->fp->Base.Parameters)
106       _mesa_print_parameter_list(st->fp->Base.Parameters);
107 }
108 
109 
110 /**
111  * Installed as pipe_debug_callback when GL_DEBUG_OUTPUT is enabled.
112  */
113 static void
st_debug_message(void * data,unsigned * id,enum pipe_debug_type ptype,const char * fmt,va_list args)114 st_debug_message(void *data,
115                  unsigned *id,
116                  enum pipe_debug_type ptype,
117                  const char *fmt,
118                  va_list args)
119 {
120    struct st_context *st = data;
121    enum mesa_debug_source source;
122    enum mesa_debug_type type;
123    enum mesa_debug_severity severity;
124 
125    switch (ptype) {
126    case PIPE_DEBUG_TYPE_OUT_OF_MEMORY:
127       source = MESA_DEBUG_SOURCE_API;
128       type = MESA_DEBUG_TYPE_ERROR;
129       severity = MESA_DEBUG_SEVERITY_MEDIUM;
130       break;
131    case PIPE_DEBUG_TYPE_ERROR:
132       source = MESA_DEBUG_SOURCE_API;
133       type = MESA_DEBUG_TYPE_ERROR;
134       severity = MESA_DEBUG_SEVERITY_MEDIUM;
135       break;
136    case PIPE_DEBUG_TYPE_SHADER_INFO:
137       source = MESA_DEBUG_SOURCE_SHADER_COMPILER;
138       type = MESA_DEBUG_TYPE_OTHER;
139       severity = MESA_DEBUG_SEVERITY_NOTIFICATION;
140       break;
141    case PIPE_DEBUG_TYPE_PERF_INFO:
142       source = MESA_DEBUG_SOURCE_API;
143       type = MESA_DEBUG_TYPE_PERFORMANCE;
144       severity = MESA_DEBUG_SEVERITY_NOTIFICATION;
145       break;
146    case PIPE_DEBUG_TYPE_INFO:
147       source = MESA_DEBUG_SOURCE_API;
148       type = MESA_DEBUG_TYPE_OTHER;
149       severity = MESA_DEBUG_SEVERITY_NOTIFICATION;
150       break;
151    case PIPE_DEBUG_TYPE_FALLBACK:
152       source = MESA_DEBUG_SOURCE_API;
153       type = MESA_DEBUG_TYPE_PERFORMANCE;
154       severity = MESA_DEBUG_SEVERITY_NOTIFICATION;
155       break;
156    case PIPE_DEBUG_TYPE_CONFORMANCE:
157       source = MESA_DEBUG_SOURCE_API;
158       type = MESA_DEBUG_TYPE_OTHER;
159       severity = MESA_DEBUG_SEVERITY_NOTIFICATION;
160       break;
161    default:
162       unreachable("invalid debug type");
163    }
164    _mesa_gl_vdebug(st->ctx, id, source, type, severity, fmt, args);
165 }
166 
167 void
st_update_debug_callback(struct st_context * st)168 st_update_debug_callback(struct st_context *st)
169 {
170    struct pipe_context *pipe = st->pipe;
171 
172    if (!pipe->set_debug_callback)
173       return;
174 
175    if (_mesa_get_debug_state_int(st->ctx, GL_DEBUG_OUTPUT)) {
176       struct pipe_debug_callback cb;
177       memset(&cb, 0, sizeof(cb));
178       cb.async = !_mesa_get_debug_state_int(st->ctx, GL_DEBUG_OUTPUT_SYNCHRONOUS);
179       cb.debug_message = st_debug_message;
180       cb.data = st;
181       pipe->set_debug_callback(pipe, &cb);
182    } else {
183       pipe->set_debug_callback(pipe, NULL);
184    }
185 }
186