mesa: allocate gl_debug_state on demand
[mesa.git] / src / mesa / main / errors.c
1 /**
2 * \file errors.c
3 * Mesa debugging and error handling functions.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 *
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31 #include "errors.h"
32 #include "enums.h"
33 #include "imports.h"
34 #include "context.h"
35 #include "dispatch.h"
36 #include "hash.h"
37 #include "mtypes.h"
38 #include "version.h"
39 #include "hash_table.h"
40 #include "glapi/glthread.h"
41
42 #define MESSAGE_LOG 1
43 #define MESSAGE_LOG_ARB 2
44
45 _glthread_DECLARE_STATIC_MUTEX(DynamicIDMutex);
46 static GLuint NextDynamicID = 1;
47
48 struct gl_debug_severity
49 {
50 struct simple_node link;
51 GLuint ID;
52 };
53
54 static char out_of_memory[] = "Debugging error: out of memory";
55
56 static const GLenum debug_source_enums[] = {
57 GL_DEBUG_SOURCE_API,
58 GL_DEBUG_SOURCE_WINDOW_SYSTEM,
59 GL_DEBUG_SOURCE_SHADER_COMPILER,
60 GL_DEBUG_SOURCE_THIRD_PARTY,
61 GL_DEBUG_SOURCE_APPLICATION,
62 GL_DEBUG_SOURCE_OTHER,
63 };
64
65 static const GLenum debug_type_enums[] = {
66 GL_DEBUG_TYPE_ERROR,
67 GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR,
68 GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR,
69 GL_DEBUG_TYPE_PORTABILITY,
70 GL_DEBUG_TYPE_PERFORMANCE,
71 GL_DEBUG_TYPE_OTHER,
72 GL_DEBUG_TYPE_MARKER,
73 GL_DEBUG_TYPE_PUSH_GROUP,
74 GL_DEBUG_TYPE_POP_GROUP,
75 };
76
77 static const GLenum debug_severity_enums[] = {
78 GL_DEBUG_SEVERITY_LOW,
79 GL_DEBUG_SEVERITY_MEDIUM,
80 GL_DEBUG_SEVERITY_HIGH,
81 GL_DEBUG_SEVERITY_NOTIFICATION,
82 };
83
84
85 static enum mesa_debug_source
86 gl_enum_to_debug_source(GLenum e)
87 {
88 int i;
89
90 for (i = 0; i < Elements(debug_source_enums); i++) {
91 if (debug_source_enums[i] == e)
92 break;
93 }
94 return i;
95 }
96
97 static enum mesa_debug_type
98 gl_enum_to_debug_type(GLenum e)
99 {
100 int i;
101
102 for (i = 0; i < Elements(debug_type_enums); i++) {
103 if (debug_type_enums[i] == e)
104 break;
105 }
106 return i;
107 }
108
109 static enum mesa_debug_severity
110 gl_enum_to_debug_severity(GLenum e)
111 {
112 int i;
113
114 for (i = 0; i < Elements(debug_severity_enums); i++) {
115 if (debug_severity_enums[i] == e)
116 break;
117 }
118 return i;
119 }
120
121
122 /**
123 * Handles generating a GL_ARB_debug_output message ID generated by the GL or
124 * GLSL compiler.
125 *
126 * The GL API has this "ID" mechanism, where the intention is to allow a
127 * client to filter in/out messages based on source, type, and ID. Of course,
128 * building a giant enum list of all debug output messages that Mesa might
129 * generate is ridiculous, so instead we have our caller pass us a pointer to
130 * static storage where the ID should get stored. This ID will be shared
131 * across all contexts for that message (which seems like a desirable
132 * property, even if it's not expected by the spec), but note that it won't be
133 * the same between executions if messages aren't generated in the same order.
134 */
135 static void
136 debug_get_id(GLuint *id)
137 {
138 if (!(*id)) {
139 _glthread_LOCK_MUTEX(DynamicIDMutex);
140 if (!(*id))
141 *id = NextDynamicID++;
142 _glthread_UNLOCK_MUTEX(DynamicIDMutex);
143 }
144 }
145
146
147 /*
148 * We store a bitfield in the hash table, with five possible values total.
149 *
150 * The ENABLED_BIT's purpose is self-explanatory.
151 *
152 * The FOUND_BIT is needed to differentiate the value of DISABLED from
153 * the value returned by HashTableLookup() when it can't find the given key.
154 *
155 * The KNOWN_SEVERITY bit is a bit complicated:
156 *
157 * A client may call Control() with an array of IDs, then call Control()
158 * on all message IDs of a certain severity, then Insert() one of the
159 * previously specified IDs, giving us a known severity level, then call
160 * Control() on all message IDs of a certain severity level again.
161 *
162 * After the first call, those IDs will have a FOUND_BIT, but will not
163 * exist in any severity-specific list, so the second call will not
164 * impact them. This is undesirable but unavoidable given the API:
165 * The only entrypoint that gives a severity for a client-defined ID
166 * is the Insert() call.
167 *
168 * For the sake of Control(), we want to maintain the invariant
169 * that an ID will either appear in none of the three severity lists,
170 * or appear once, to minimize pointless duplication and potential surprises.
171 *
172 * Because Insert() is the only place that will learn an ID's severity,
173 * it should insert an ID into the appropriate list, but only if the ID
174 * doesn't exist in it or any other list yet. Because searching all three
175 * lists at O(n) is needlessly expensive, we store KNOWN_SEVERITY.
176 */
177 enum {
178 FOUND_BIT = 1 << 0,
179 ENABLED_BIT = 1 << 1,
180 KNOWN_SEVERITY = 1 << 2,
181
182 /* HashTable reserves zero as a return value meaning 'not found' */
183 NOT_FOUND = 0,
184 DISABLED = FOUND_BIT,
185 ENABLED = ENABLED_BIT | FOUND_BIT
186 };
187
188
189 /**
190 * Return debug state for the context. The debug state will be allocated
191 * and initialized upon the first call.
192 */
193 struct gl_debug_state *
194 _mesa_get_debug_state(struct gl_context *ctx)
195 {
196 if (!ctx->Debug) {
197 ctx->Debug = CALLOC_STRUCT(gl_debug_state);
198 if (!ctx->Debug) {
199 _mesa_error(ctx, GL_OUT_OF_MEMORY, "allocating debug state");
200 }
201 else {
202 struct gl_debug_state *debug = ctx->Debug;
203 int s, t, sev;
204
205 /* Enable all the messages with severity HIGH or MEDIUM by default. */
206 memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH], GL_TRUE,
207 sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH]);
208 memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM], GL_TRUE,
209 sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM]);
210 memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW], GL_FALSE,
211 sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW]);
212
213 /* Initialize state for filtering known debug messages. */
214 for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) {
215 for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) {
216 debug->Namespaces[0][s][t].IDs = _mesa_NewHashTable();
217 assert(debug->Namespaces[0][s][t].IDs);
218
219 for (sev = 0; sev < MESA_DEBUG_SEVERITY_COUNT; sev++) {
220 make_empty_list(&debug->Namespaces[0][s][t].Severity[sev]);
221 }
222 }
223 }
224 }
225 }
226
227 return ctx->Debug;
228 }
229
230
231
232 /**
233 * Returns the state of the given message source/type/ID tuple.
234 */
235 static GLboolean
236 should_log(struct gl_context *ctx,
237 enum mesa_debug_source source,
238 enum mesa_debug_type type,
239 GLuint id,
240 enum mesa_debug_severity severity)
241 {
242 struct gl_debug_state *debug;
243 uintptr_t state = 0;
244
245 if (!ctx->Debug) {
246 /* no debug state set so far */
247 return GL_FALSE;
248 }
249
250 debug = _mesa_get_debug_state(ctx);
251 if (debug) {
252 const GLint gstack = debug->GroupStackDepth;
253 struct gl_debug_namespace *nspace =
254 &debug->Namespaces[gstack][source][type];
255
256 if (!debug->DebugOutput)
257 return GL_FALSE;
258
259 /* In addition to not being able to store zero as a value, HashTable also
260 * can't use zero as a key.
261 */
262 if (id)
263 state = (uintptr_t)_mesa_HashLookup(nspace->IDs, id);
264 else
265 state = nspace->ZeroID;
266
267 /* Only do this once for each ID. This makes sure the ID exists in,
268 * at most, one list, and does not pointlessly appear multiple times.
269 */
270 if (!(state & KNOWN_SEVERITY)) {
271 struct gl_debug_severity *entry;
272
273 if (state == NOT_FOUND) {
274 if (debug->Defaults[gstack][severity][source][type])
275 state = ENABLED;
276 else
277 state = DISABLED;
278 }
279
280 entry = malloc(sizeof *entry);
281 if (!entry)
282 goto out;
283
284 state |= KNOWN_SEVERITY;
285
286 if (id)
287 _mesa_HashInsert(nspace->IDs, id, (void*)state);
288 else
289 nspace->ZeroID = state;
290
291 entry->ID = id;
292 insert_at_tail(&nspace->Severity[severity], &entry->link);
293 }
294 }
295 out:
296 return !!(state & ENABLED_BIT);
297 }
298
299
300 /**
301 * Sets the state of the given message source/type/ID tuple.
302 */
303 static void
304 set_message_state(struct gl_context *ctx,
305 enum mesa_debug_source source,
306 enum mesa_debug_type type,
307 GLuint id, GLboolean enabled)
308 {
309 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
310
311 if (debug) {
312 GLint gstack = debug->GroupStackDepth;
313 struct gl_debug_namespace *nspace =
314 &debug->Namespaces[gstack][source][type];
315 uintptr_t state;
316
317 /* In addition to not being able to store zero as a value, HashTable also
318 * can't use zero as a key.
319 */
320 if (id)
321 state = (uintptr_t)_mesa_HashLookup(nspace->IDs, id);
322 else
323 state = nspace->ZeroID;
324
325 if (state == NOT_FOUND)
326 state = enabled ? ENABLED : DISABLED;
327 else {
328 if (enabled)
329 state |= ENABLED_BIT;
330 else
331 state &= ~ENABLED_BIT;
332 }
333
334 if (id)
335 _mesa_HashInsert(nspace->IDs, id, (void*)state);
336 else
337 nspace->ZeroID = state;
338 }
339 }
340
341
342 static void
343 store_message_details(struct gl_debug_msg *emptySlot,
344 enum mesa_debug_source source,
345 enum mesa_debug_type type, GLuint id,
346 enum mesa_debug_severity severity, GLint len,
347 const char *buf)
348 {
349 assert(!emptySlot->message && !emptySlot->length);
350
351 emptySlot->message = malloc(len+1);
352 if (emptySlot->message) {
353 (void) strncpy(emptySlot->message, buf, (size_t)len);
354 emptySlot->message[len] = '\0';
355
356 emptySlot->length = len+1;
357 emptySlot->source = source;
358 emptySlot->type = type;
359 emptySlot->id = id;
360 emptySlot->severity = severity;
361 } else {
362 static GLuint oom_msg_id = 0;
363 debug_get_id(&oom_msg_id);
364
365 /* malloc failed! */
366 emptySlot->message = out_of_memory;
367 emptySlot->length = strlen(out_of_memory)+1;
368 emptySlot->source = MESA_DEBUG_SOURCE_OTHER;
369 emptySlot->type = MESA_DEBUG_TYPE_ERROR;
370 emptySlot->id = oom_msg_id;
371 emptySlot->severity = MESA_DEBUG_SEVERITY_HIGH;
372 }
373 }
374
375
376 /**
377 * Remap any type exclusive to KHR_debug to something suitable
378 * for ARB_debug_output
379 */
380 inline static int
381 remap_type(GLenum type) {
382
383 switch(type) {
384 case GL_DEBUG_TYPE_MARKER:
385 case GL_DEBUG_TYPE_PUSH_GROUP:
386 case GL_DEBUG_TYPE_POP_GROUP:
387 type = GL_DEBUG_TYPE_OTHER;
388 default:
389 ;
390 }
391
392 return type;
393 }
394
395
396 /**
397 * Remap severity exclusive to KHR_debug to something suitable
398 * for ARB_debug_output
399 */
400 inline static int
401 remap_severity(GLenum severity) {
402
403 if (GL_DEBUG_SEVERITY_NOTIFICATION == severity)
404 severity = GL_DEBUG_SEVERITY_LOW;
405
406 return severity;
407 }
408
409
410 /**
411 * 'buf' is not necessarily a null-terminated string. When logging, copy
412 * 'len' characters from it, store them in a new, null-terminated string,
413 * and remember the number of bytes used by that string, *including*
414 * the null terminator this time.
415 */
416 static void
417 log_msg(struct gl_context *ctx, enum mesa_debug_source source,
418 enum mesa_debug_type type, GLuint id,
419 enum mesa_debug_severity severity, GLint len, const char *buf)
420 {
421 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
422 GLint nextEmpty;
423 struct gl_debug_msg *emptySlot;
424
425 if (!debug)
426 return;
427
428 assert(len >= 0 && len < MAX_DEBUG_MESSAGE_LENGTH);
429
430 if (!should_log(ctx, source, type, id, severity))
431 return;
432
433 if (debug->Callback) {
434 GLenum gl_type = debug_type_enums[type];
435 GLenum gl_severity = debug_severity_enums[severity];
436
437 if (debug->ARBCallback) {
438 gl_severity = remap_severity(gl_severity);
439 gl_type = remap_type(gl_type);
440 }
441 debug->Callback(debug_source_enums[source], gl_type, id, gl_severity,
442 len, buf, debug->CallbackData);
443 return;
444 }
445
446 if (debug->NumMessages == MAX_DEBUG_LOGGED_MESSAGES)
447 return;
448
449 nextEmpty = (debug->NextMsg + debug->NumMessages)
450 % MAX_DEBUG_LOGGED_MESSAGES;
451 emptySlot = &debug->Log[nextEmpty];
452
453 store_message_details(emptySlot, source, type, id, severity, len, buf);
454
455 if (debug->NumMessages == 0)
456 debug->NextMsgLength = debug->Log[debug->NextMsg].length;
457
458 debug->NumMessages++;
459 }
460
461
462 /**
463 * Pop the oldest debug message out of the log.
464 * Writes the message string, including the null terminator, into 'buf',
465 * using up to 'bufSize' bytes. If 'bufSize' is too small, or
466 * if 'buf' is NULL, nothing is written.
467 *
468 * Returns the number of bytes written on success, or when 'buf' is NULL,
469 * the number that would have been written. A return value of 0
470 * indicates failure.
471 */
472 static GLsizei
473 get_msg(struct gl_context *ctx, GLenum *source, GLenum *type,
474 GLuint *id, GLenum *severity, GLsizei bufSize, char *buf,
475 unsigned caller)
476 {
477 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
478 struct gl_debug_msg *msg;
479 GLsizei length;
480
481 if (!debug || debug->NumMessages == 0)
482 return 0;
483
484 msg = &debug->Log[debug->NextMsg];
485 length = msg->length;
486
487 assert(length > 0 && length == debug->NextMsgLength);
488
489 if (bufSize < length && buf != NULL)
490 return 0;
491
492 if (severity) {
493 *severity = debug_severity_enums[msg->severity];
494 if (caller == MESSAGE_LOG_ARB)
495 *severity = remap_severity(*severity);
496 }
497
498 if (source) {
499 *source = debug_source_enums[msg->source];
500 }
501
502 if (type) {
503 *type = debug_type_enums[msg->type];
504 if (caller == MESSAGE_LOG_ARB)
505 *type = remap_type(*type);
506 }
507
508 if (id) {
509 *id = msg->id;
510 }
511
512 if (buf) {
513 assert(msg->message[length-1] == '\0');
514 (void) strncpy(buf, msg->message, (size_t)length);
515 }
516
517 if (msg->message != (char*)out_of_memory)
518 free(msg->message);
519 msg->message = NULL;
520 msg->length = 0;
521
522 debug->NumMessages--;
523 debug->NextMsg++;
524 debug->NextMsg %= MAX_DEBUG_LOGGED_MESSAGES;
525 debug->NextMsgLength = debug->Log[debug->NextMsg].length;
526
527 return length;
528 }
529
530
531 /**
532 * Verify that source, type, and severity are valid enums.
533 * glDebugMessageInsertARB only accepts two values for 'source',
534 * and glDebugMessageControlARB will additionally accept GL_DONT_CARE
535 * in any parameter, so handle those cases specially.
536 *
537 * There is also special cases for handling values available in
538 * GL_KHR_debug that are not avaliable in GL_ARB_debug_output
539 */
540 static GLboolean
541 validate_params(struct gl_context *ctx, unsigned caller,
542 const char *callerstr, GLenum source, GLenum type,
543 GLenum severity)
544 {
545 #define INSERT 1
546 #define CONTROL 2
547 #define INSERT_ARB 3
548 #define CONTROL_ARB 4
549 switch(source) {
550 case GL_DEBUG_SOURCE_APPLICATION_ARB:
551 case GL_DEBUG_SOURCE_THIRD_PARTY_ARB:
552 break;
553 case GL_DEBUG_SOURCE_API_ARB:
554 case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB:
555 case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB:
556 case GL_DEBUG_SOURCE_OTHER_ARB:
557 if (caller != INSERT || caller == INSERT_ARB)
558 break;
559 case GL_DONT_CARE:
560 if (caller == CONTROL || caller == CONTROL_ARB)
561 break;
562 default:
563 goto error;
564 }
565
566 switch(type) {
567 case GL_DEBUG_TYPE_ERROR_ARB:
568 case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB:
569 case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB:
570 case GL_DEBUG_TYPE_PERFORMANCE_ARB:
571 case GL_DEBUG_TYPE_PORTABILITY_ARB:
572 case GL_DEBUG_TYPE_OTHER_ARB:
573 break;
574 case GL_DEBUG_TYPE_MARKER:
575 /* this value is only valid for GL_KHR_debug functions */
576 if (caller == CONTROL || caller == INSERT)
577 break;
578 case GL_DONT_CARE:
579 if (caller == CONTROL || caller == CONTROL_ARB)
580 break;
581 default:
582 goto error;
583 }
584
585 switch(severity) {
586 case GL_DEBUG_SEVERITY_HIGH_ARB:
587 case GL_DEBUG_SEVERITY_MEDIUM_ARB:
588 case GL_DEBUG_SEVERITY_LOW_ARB:
589 break;
590 case GL_DEBUG_SEVERITY_NOTIFICATION:
591 /* this value is only valid for GL_KHR_debug functions */
592 if (caller == CONTROL || caller == INSERT)
593 break;
594 case GL_DONT_CARE:
595 if (caller == CONTROL || caller == CONTROL_ARB)
596 break;
597 default:
598 goto error;
599 }
600 return GL_TRUE;
601
602 error:
603 _mesa_error(ctx, GL_INVALID_ENUM, "bad values passed to %s"
604 "(source=0x%x, type=0x%x, severity=0x%x)", callerstr,
605 source, type, severity);
606
607 return GL_FALSE;
608 }
609
610
611 /**
612 * Set the state of all message IDs found in the given intersection of
613 * 'source', 'type', and 'severity'. The _COUNT enum can be used for
614 * GL_DONT_CARE (include all messages in the class).
615 *
616 * This requires both setting the state of all previously seen message
617 * IDs in the hash table, and setting the default state for all
618 * applicable combinations of source/type/severity, so that all the
619 * yet-unknown message IDs that may be used in the future will be
620 * impacted as if they were already known.
621 */
622 static void
623 control_messages(struct gl_context *ctx,
624 enum mesa_debug_source source,
625 enum mesa_debug_type type,
626 enum mesa_debug_severity severity,
627 GLboolean enabled)
628 {
629 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
630 int s, t, sev, smax, tmax, sevmax;
631 const GLint gstack = debug ? debug->GroupStackDepth : 0;
632
633 if (!debug)
634 return;
635
636 if (source == MESA_DEBUG_SOURCE_COUNT) {
637 source = 0;
638 smax = MESA_DEBUG_SOURCE_COUNT;
639 } else {
640 smax = source+1;
641 }
642
643 if (type == MESA_DEBUG_TYPE_COUNT) {
644 type = 0;
645 tmax = MESA_DEBUG_TYPE_COUNT;
646 } else {
647 tmax = type+1;
648 }
649
650 if (severity == MESA_DEBUG_SEVERITY_COUNT) {
651 severity = 0;
652 sevmax = MESA_DEBUG_SEVERITY_COUNT;
653 } else {
654 sevmax = severity+1;
655 }
656
657 for (sev = severity; sev < sevmax; sev++) {
658 for (s = source; s < smax; s++) {
659 for (t = type; t < tmax; t++) {
660 struct simple_node *node;
661 struct gl_debug_severity *entry;
662
663 /* change the default for IDs we've never seen before. */
664 debug->Defaults[gstack][sev][s][t] = enabled;
665
666 /* Now change the state of IDs we *have* seen... */
667 foreach(node, &debug->Namespaces[gstack][s][t].Severity[sev]) {
668 entry = (struct gl_debug_severity *)node;
669 set_message_state(ctx, s, t, entry->ID, enabled);
670 }
671 }
672 }
673 }
674 }
675
676
677 /**
678 * Debugging-message namespaces with the source APPLICATION or THIRD_PARTY
679 * require special handling, since the IDs in them are controlled by clients,
680 * not the OpenGL implementation.
681 *
682 * 'count' is the length of the array 'ids'. If 'count' is nonzero, all
683 * the given IDs in the namespace defined by 'esource' and 'etype'
684 * will be affected.
685 *
686 * If 'count' is zero, this sets the state of all IDs that match
687 * the combination of 'esource', 'etype', and 'eseverity'.
688 */
689 static void
690 control_app_messages(struct gl_context *ctx, GLenum esource, GLenum etype,
691 GLenum eseverity, GLsizei count, const GLuint *ids,
692 GLboolean enabled)
693 {
694 GLsizei i;
695 enum mesa_debug_source source = gl_enum_to_debug_source(esource);
696 enum mesa_debug_type type = gl_enum_to_debug_type(etype);
697 enum mesa_debug_severity severity = gl_enum_to_debug_severity(eseverity);
698
699 for (i = 0; i < count; i++)
700 set_message_state(ctx, source, type, ids[i], enabled);
701
702 if (count)
703 return;
704
705 control_messages(ctx, source, type, severity, enabled);
706 }
707
708
709 /**
710 * This is a generic message control function for use by both
711 * glDebugMessageControlARB and glDebugMessageControl.
712 */
713 static void
714 message_control(GLenum gl_source, GLenum gl_type,
715 GLenum gl_severity,
716 GLsizei count, const GLuint *ids,
717 GLboolean enabled,
718 unsigned caller, const char *callerstr)
719 {
720 GET_CURRENT_CONTEXT(ctx);
721
722 if (count < 0) {
723 _mesa_error(ctx, GL_INVALID_VALUE,
724 "%s(count=%d : count must not be negative)", callerstr,
725 count);
726 return;
727 }
728
729 if (!validate_params(ctx, caller, callerstr, gl_source, gl_type,
730 gl_severity))
731 return; /* GL_INVALID_ENUM */
732
733 if (count && (gl_severity != GL_DONT_CARE || gl_type == GL_DONT_CARE
734 || gl_source == GL_DONT_CARE)) {
735 _mesa_error(ctx, GL_INVALID_OPERATION,
736 "%s(When passing an array of ids, severity must be"
737 " GL_DONT_CARE, and source and type must not be GL_DONT_CARE.",
738 callerstr);
739 return;
740 }
741
742 control_app_messages(ctx, gl_source, gl_type, gl_severity,
743 count, ids, enabled);
744 }
745
746
747 /**
748 * This is a generic message insert function.
749 * Validation of source, type and severity parameters should be done
750 * before calling this funtion.
751 */
752 static void
753 message_insert(GLenum source, GLenum type, GLuint id,
754 GLenum severity, GLint length, const GLchar *buf,
755 const char *callerstr)
756 {
757 GET_CURRENT_CONTEXT(ctx);
758
759 if (length < 0)
760 length = strlen(buf);
761
762 if (length >= MAX_DEBUG_MESSAGE_LENGTH) {
763 _mesa_error(ctx, GL_INVALID_VALUE,
764 "%s(length=%d, which is not less than "
765 "GL_MAX_DEBUG_MESSAGE_LENGTH=%d)", callerstr, length,
766 MAX_DEBUG_MESSAGE_LENGTH);
767 return;
768 }
769
770 log_msg(ctx,
771 gl_enum_to_debug_source(source),
772 gl_enum_to_debug_type(type), id,
773 gl_enum_to_debug_severity(severity), length, buf);
774 }
775
776
777 /**
778 * This is a generic message insert function for use by both
779 * glGetDebugMessageLogARB and glGetDebugMessageLog.
780 */
781 static GLuint
782 get_message_log(GLuint count, GLsizei logSize, GLenum *sources,
783 GLenum *types, GLenum *ids, GLenum *severities,
784 GLsizei *lengths, GLchar *messageLog,
785 unsigned caller, const char *callerstr)
786 {
787 GET_CURRENT_CONTEXT(ctx);
788 GLuint ret;
789
790 if (!messageLog)
791 logSize = 0;
792
793 if (logSize < 0) {
794 _mesa_error(ctx, GL_INVALID_VALUE,
795 "%s(logSize=%d : logSize must not be negative)", callerstr,
796 logSize);
797 return 0;
798 }
799
800 for (ret = 0; ret < count; ret++) {
801 GLsizei written = get_msg(ctx, sources, types, ids, severities,
802 logSize, messageLog, caller);
803 if (!written)
804 break;
805
806 if (messageLog) {
807 messageLog += written;
808 logSize -= written;
809 }
810 if (lengths) {
811 *lengths = written;
812 lengths++;
813 }
814
815 if (severities)
816 severities++;
817 if (sources)
818 sources++;
819 if (types)
820 types++;
821 if (ids)
822 ids++;
823 }
824
825 return ret;
826 }
827
828
829 static void
830 do_nothing(GLuint key, void *data, void *userData)
831 {
832 }
833
834
835 /**
836 * Free context state pertaining to error/debug state for the given stack
837 * depth.
838 */
839 static void
840 free_errors_data(struct gl_context *ctx, GLint gstack)
841 {
842 struct gl_debug_state *debug = ctx->Debug;
843 enum mesa_debug_type t;
844 enum mesa_debug_source s;
845 enum mesa_debug_severity sev;
846
847 assert(debug);
848
849 /* Tear down state for filtering debug messages. */
850 for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) {
851 for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) {
852 _mesa_HashDeleteAll(debug->Namespaces[gstack][s][t].IDs,
853 do_nothing, NULL);
854 _mesa_DeleteHashTable(debug->Namespaces[gstack][s][t].IDs);
855 for (sev = 0; sev < MESA_DEBUG_SEVERITY_COUNT; sev++) {
856 struct simple_node *node, *tmp;
857 struct gl_debug_severity *entry;
858
859 foreach_s(node, tmp,
860 &debug->Namespaces[gstack][s][t].Severity[sev]) {
861 entry = (struct gl_debug_severity *)node;
862 free(entry);
863 }
864 }
865 }
866 }
867 }
868
869
870 void GLAPIENTRY
871 _mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id,
872 GLenum severity, GLint length,
873 const GLchar *buf)
874 {
875 const char *callerstr = "glDebugMessageInsert";
876
877 GET_CURRENT_CONTEXT(ctx);
878
879 if (!validate_params(ctx, INSERT, callerstr, source, type, severity))
880 return; /* GL_INVALID_ENUM */
881
882 message_insert(source, type, id, severity, length, buf, callerstr);
883 }
884
885
886 GLuint GLAPIENTRY
887 _mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum *sources,
888 GLenum *types, GLenum *ids, GLenum *severities,
889 GLsizei *lengths, GLchar *messageLog)
890 {
891 const char *callerstr = "glGetDebugMessageLog";
892
893 return get_message_log(count, logSize, sources, types, ids, severities,
894 lengths, messageLog, MESSAGE_LOG, callerstr);
895 }
896
897
898 void GLAPIENTRY
899 _mesa_DebugMessageControl(GLenum source, GLenum type, GLenum severity,
900 GLsizei count, const GLuint *ids,
901 GLboolean enabled)
902 {
903 const char *callerstr = "glDebugMessageControl";
904
905 message_control(source, type, severity, count, ids,
906 enabled, CONTROL, callerstr);
907 }
908
909
910 void GLAPIENTRY
911 _mesa_DebugMessageCallback(GLDEBUGPROC callback, const void *userParam)
912 {
913 GET_CURRENT_CONTEXT(ctx);
914 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
915 if (debug) {
916 debug->Callback = callback;
917 debug->CallbackData = userParam;
918 debug->ARBCallback = GL_FALSE;
919 }
920 }
921
922
923 void GLAPIENTRY
924 _mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length,
925 const GLchar *message)
926 {
927 GET_CURRENT_CONTEXT(ctx);
928 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
929 const char *callerstr = "glPushDebugGroup";
930 int s, t, sev;
931 GLint prevStackDepth;
932 GLint currStackDepth;
933 struct gl_debug_msg *emptySlot;
934
935 if (!debug)
936 return;
937
938 if (debug->GroupStackDepth >= MAX_DEBUG_GROUP_STACK_DEPTH-1) {
939 _mesa_error(ctx, GL_STACK_OVERFLOW, "%s", callerstr);
940 return;
941 }
942
943 switch(source) {
944 case GL_DEBUG_SOURCE_APPLICATION:
945 case GL_DEBUG_SOURCE_THIRD_PARTY:
946 break;
947 default:
948 _mesa_error(ctx, GL_INVALID_ENUM, "bad value passed to %s"
949 "(source=0x%x)", callerstr, source);
950 return;
951 }
952
953 message_insert(source, GL_DEBUG_TYPE_PUSH_GROUP, id,
954 GL_DEBUG_SEVERITY_NOTIFICATION, length,
955 message, callerstr);
956
957 prevStackDepth = debug->GroupStackDepth;
958 debug->GroupStackDepth++;
959 currStackDepth = debug->GroupStackDepth;
960
961 /* pop reuses the message details from push so we store this */
962 if (length < 0)
963 length = strlen(message);
964 emptySlot = &debug->DebugGroupMsgs[debug->GroupStackDepth];
965 store_message_details(emptySlot, gl_enum_to_debug_source(source),
966 gl_enum_to_debug_type(GL_DEBUG_TYPE_PUSH_GROUP),
967 id,
968 gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION),
969 length, message);
970
971 /* inherit the control volume of the debug group previously residing on
972 * the top of the debug group stack
973 */
974 for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) {
975 for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) {
976 /* copy id settings */
977 debug->Namespaces[currStackDepth][s][t].IDs =
978 _mesa_HashClone(debug->Namespaces[prevStackDepth][s][t].IDs);
979
980 for (sev = 0; sev < MESA_DEBUG_SEVERITY_COUNT; sev++) {
981 struct gl_debug_severity *entry, *prevEntry;
982 struct simple_node *node;
983
984 /* copy default settings for unknown ids */
985 debug->Defaults[currStackDepth][sev][s][t] =
986 debug->Defaults[prevStackDepth][sev][s][t];
987
988 /* copy known id severity settings */
989 make_empty_list(&debug->Namespaces[currStackDepth][s][t].Severity[sev]);
990 foreach(node, &debug->Namespaces[prevStackDepth][s][t].Severity[sev]) {
991 prevEntry = (struct gl_debug_severity *)node;
992 entry = malloc(sizeof *entry);
993 if (!entry)
994 return;
995
996 entry->ID = prevEntry->ID;
997 insert_at_tail(&debug->Namespaces[currStackDepth][s][t].Severity[sev], &entry->link);
998 }
999 }
1000 }
1001 }
1002 }
1003
1004
1005 void GLAPIENTRY
1006 _mesa_PopDebugGroup(void)
1007 {
1008 GET_CURRENT_CONTEXT(ctx);
1009 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
1010 const char *callerstr = "glPopDebugGroup";
1011 struct gl_debug_msg *gdmessage;
1012 GLint prevStackDepth;
1013
1014 if (!debug)
1015 return;
1016
1017 if (debug->GroupStackDepth <= 0) {
1018 _mesa_error(ctx, GL_STACK_UNDERFLOW, "%s", callerstr);
1019 return;
1020 }
1021
1022 prevStackDepth = debug->GroupStackDepth;
1023 debug->GroupStackDepth--;
1024
1025 gdmessage = &debug->DebugGroupMsgs[prevStackDepth];
1026 /* using log_msg() directly here as verification of parameters
1027 * already done in push
1028 */
1029 log_msg(ctx, gdmessage->source,
1030 gl_enum_to_debug_type(GL_DEBUG_TYPE_POP_GROUP),
1031 gdmessage->id,
1032 gl_enum_to_debug_severity(GL_DEBUG_SEVERITY_NOTIFICATION),
1033 gdmessage->length, gdmessage->message);
1034
1035 if (gdmessage->message != (char*)out_of_memory)
1036 free(gdmessage->message);
1037 gdmessage->message = NULL;
1038 gdmessage->length = 0;
1039
1040 /* free popped debug group data */
1041 free_errors_data(ctx, prevStackDepth);
1042 }
1043
1044
1045 void GLAPIENTRY
1046 _mesa_DebugMessageInsertARB(GLenum source, GLenum type, GLuint id,
1047 GLenum severity, GLint length,
1048 const GLcharARB *buf)
1049 {
1050 const char *callerstr = "glDebugMessageInsertARB";
1051
1052 GET_CURRENT_CONTEXT(ctx);
1053
1054 if (!validate_params(ctx, INSERT_ARB, callerstr, source, type, severity))
1055 return; /* GL_INVALID_ENUM */
1056
1057 message_insert(source, type, id, severity, length, buf, callerstr);
1058 }
1059
1060
1061 GLuint GLAPIENTRY
1062 _mesa_GetDebugMessageLogARB(GLuint count, GLsizei logSize, GLenum *sources,
1063 GLenum *types, GLenum *ids, GLenum *severities,
1064 GLsizei *lengths, GLcharARB *messageLog)
1065 {
1066 const char *callerstr = "glGetDebugMessageLogARB";
1067
1068 return get_message_log(count, logSize, sources, types, ids, severities,
1069 lengths, messageLog, MESSAGE_LOG_ARB, callerstr);
1070 }
1071
1072
1073 void GLAPIENTRY
1074 _mesa_DebugMessageControlARB(GLenum gl_source, GLenum gl_type,
1075 GLenum gl_severity,
1076 GLsizei count, const GLuint *ids,
1077 GLboolean enabled)
1078 {
1079 const char *callerstr = "glDebugMessageControlARB";
1080
1081 message_control(gl_source, gl_type, gl_severity, count, ids,
1082 enabled, CONTROL_ARB, callerstr);
1083 }
1084
1085
1086 void GLAPIENTRY
1087 _mesa_DebugMessageCallbackARB(GLDEBUGPROCARB callback, const void *userParam)
1088 {
1089 GET_CURRENT_CONTEXT(ctx);
1090 struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
1091 if (debug) {
1092 debug->Callback = callback;
1093 debug->CallbackData = userParam;
1094 debug->ARBCallback = GL_TRUE;
1095 }
1096 }
1097
1098
1099 void
1100 _mesa_init_errors(struct gl_context *ctx)
1101 {
1102 /* no-op */
1103 }
1104
1105
1106 /**
1107 * Loop through debug group stack tearing down states for
1108 * filtering debug messages.
1109 */
1110 void
1111 _mesa_free_errors_data(struct gl_context *ctx)
1112 {
1113 if (ctx->Debug) {
1114 GLint i;
1115
1116 for (i = 0; i <= ctx->Debug->GroupStackDepth; i++) {
1117 free_errors_data(ctx, i);
1118 }
1119 }
1120 }
1121
1122
1123 /**********************************************************************/
1124 /** \name Diagnostics */
1125 /*@{*/
1126
1127 static void
1128 output_if_debug(const char *prefixString, const char *outputString,
1129 GLboolean newline)
1130 {
1131 static int debug = -1;
1132 static FILE *fout = NULL;
1133
1134 /* Init the local 'debug' var once.
1135 * Note: the _mesa_init_debug() function should have been called
1136 * by now so MESA_DEBUG_FLAGS will be initialized.
1137 */
1138 if (debug == -1) {
1139 /* If MESA_LOG_FILE env var is set, log Mesa errors, warnings,
1140 * etc to the named file. Otherwise, output to stderr.
1141 */
1142 const char *logFile = _mesa_getenv("MESA_LOG_FILE");
1143 if (logFile)
1144 fout = fopen(logFile, "w");
1145 if (!fout)
1146 fout = stderr;
1147 #ifdef DEBUG
1148 /* in debug builds, print messages unless MESA_DEBUG="silent" */
1149 if (MESA_DEBUG_FLAGS & DEBUG_SILENT)
1150 debug = 0;
1151 else
1152 debug = 1;
1153 #else
1154 /* in release builds, be silent unless MESA_DEBUG is set */
1155 debug = _mesa_getenv("MESA_DEBUG") != NULL;
1156 #endif
1157 }
1158
1159 /* Now only print the string if we're required to do so. */
1160 if (debug) {
1161 fprintf(fout, "%s: %s", prefixString, outputString);
1162 if (newline)
1163 fprintf(fout, "\n");
1164 fflush(fout);
1165
1166 #if defined(_WIN32) && !defined(_WIN32_WCE)
1167 /* stderr from windows applications without console is not usually
1168 * visible, so communicate with the debugger instead */
1169 {
1170 char buf[4096];
1171 _mesa_snprintf(buf, sizeof(buf), "%s: %s%s", prefixString, outputString, newline ? "\n" : "");
1172 OutputDebugStringA(buf);
1173 }
1174 #endif
1175 }
1176 }
1177
1178
1179 /**
1180 * When a new type of error is recorded, print a message describing
1181 * previous errors which were accumulated.
1182 */
1183 static void
1184 flush_delayed_errors( struct gl_context *ctx )
1185 {
1186 char s[MAX_DEBUG_MESSAGE_LENGTH];
1187
1188 if (ctx->ErrorDebugCount) {
1189 _mesa_snprintf(s, MAX_DEBUG_MESSAGE_LENGTH, "%d similar %s errors",
1190 ctx->ErrorDebugCount,
1191 _mesa_lookup_enum_by_nr(ctx->ErrorValue));
1192
1193 output_if_debug("Mesa", s, GL_TRUE);
1194
1195 ctx->ErrorDebugCount = 0;
1196 }
1197 }
1198
1199
1200 /**
1201 * Report a warning (a recoverable error condition) to stderr if
1202 * either DEBUG is defined or the MESA_DEBUG env var is set.
1203 *
1204 * \param ctx GL context.
1205 * \param fmtString printf()-like format string.
1206 */
1207 void
1208 _mesa_warning( struct gl_context *ctx, const char *fmtString, ... )
1209 {
1210 char str[MAX_DEBUG_MESSAGE_LENGTH];
1211 va_list args;
1212 va_start( args, fmtString );
1213 (void) _mesa_vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
1214 va_end( args );
1215
1216 if (ctx)
1217 flush_delayed_errors( ctx );
1218
1219 output_if_debug("Mesa warning", str, GL_TRUE);
1220 }
1221
1222
1223 /**
1224 * Report an internal implementation problem.
1225 * Prints the message to stderr via fprintf().
1226 *
1227 * \param ctx GL context.
1228 * \param fmtString problem description string.
1229 */
1230 void
1231 _mesa_problem( const struct gl_context *ctx, const char *fmtString, ... )
1232 {
1233 va_list args;
1234 char str[MAX_DEBUG_MESSAGE_LENGTH];
1235 static int numCalls = 0;
1236
1237 (void) ctx;
1238
1239 if (numCalls < 50) {
1240 numCalls++;
1241
1242 va_start( args, fmtString );
1243 _mesa_vsnprintf( str, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args );
1244 va_end( args );
1245 fprintf(stderr, "Mesa %s implementation error: %s\n",
1246 PACKAGE_VERSION, str);
1247 fprintf(stderr, "Please report at " PACKAGE_BUGREPORT "\n");
1248 }
1249 }
1250
1251
1252 static GLboolean
1253 should_output(struct gl_context *ctx, GLenum error, const char *fmtString)
1254 {
1255 static GLint debug = -1;
1256
1257 /* Check debug environment variable only once:
1258 */
1259 if (debug == -1) {
1260 const char *debugEnv = _mesa_getenv("MESA_DEBUG");
1261
1262 #ifdef DEBUG
1263 if (debugEnv && strstr(debugEnv, "silent"))
1264 debug = GL_FALSE;
1265 else
1266 debug = GL_TRUE;
1267 #else
1268 if (debugEnv)
1269 debug = GL_TRUE;
1270 else
1271 debug = GL_FALSE;
1272 #endif
1273 }
1274
1275 if (debug) {
1276 if (ctx->ErrorValue != error ||
1277 ctx->ErrorDebugFmtString != fmtString) {
1278 flush_delayed_errors( ctx );
1279 ctx->ErrorDebugFmtString = fmtString;
1280 ctx->ErrorDebugCount = 0;
1281 return GL_TRUE;
1282 }
1283 ctx->ErrorDebugCount++;
1284 }
1285 return GL_FALSE;
1286 }
1287
1288
1289 void
1290 _mesa_gl_debug(struct gl_context *ctx,
1291 GLuint *id,
1292 enum mesa_debug_type type,
1293 enum mesa_debug_severity severity,
1294 const char *fmtString, ...)
1295 {
1296 char s[MAX_DEBUG_MESSAGE_LENGTH];
1297 int len;
1298 va_list args;
1299
1300 debug_get_id(id);
1301
1302 va_start(args, fmtString);
1303 len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
1304 va_end(args);
1305
1306 log_msg(ctx, MESA_DEBUG_SOURCE_API, type, *id, severity, len, s);
1307 }
1308
1309
1310 /**
1311 * Record an OpenGL state error. These usually occur when the user
1312 * passes invalid parameters to a GL function.
1313 *
1314 * If debugging is enabled (either at compile-time via the DEBUG macro, or
1315 * run-time via the MESA_DEBUG environment variable), report the error with
1316 * _mesa_debug().
1317 *
1318 * \param ctx the GL context.
1319 * \param error the error value.
1320 * \param fmtString printf() style format string, followed by optional args
1321 */
1322 void
1323 _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
1324 {
1325 GLboolean do_output, do_log;
1326 /* Ideally this would be set up by the caller, so that we had proper IDs
1327 * per different message.
1328 */
1329 static GLuint error_msg_id = 0;
1330
1331 debug_get_id(&error_msg_id);
1332
1333 do_output = should_output(ctx, error, fmtString);
1334 do_log = should_log(ctx,
1335 MESA_DEBUG_SOURCE_API,
1336 MESA_DEBUG_TYPE_ERROR,
1337 error_msg_id,
1338 MESA_DEBUG_SEVERITY_HIGH);
1339
1340 if (do_output || do_log) {
1341 char s[MAX_DEBUG_MESSAGE_LENGTH], s2[MAX_DEBUG_MESSAGE_LENGTH];
1342 int len;
1343 va_list args;
1344
1345 va_start(args, fmtString);
1346 len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
1347 va_end(args);
1348
1349 if (len >= MAX_DEBUG_MESSAGE_LENGTH) {
1350 /* Too long error message. Whoever calls _mesa_error should use
1351 * shorter strings.
1352 */
1353 ASSERT(0);
1354 return;
1355 }
1356
1357 len = _mesa_snprintf(s2, MAX_DEBUG_MESSAGE_LENGTH, "%s in %s",
1358 _mesa_lookup_enum_by_nr(error), s);
1359 if (len >= MAX_DEBUG_MESSAGE_LENGTH) {
1360 /* Same as above. */
1361 ASSERT(0);
1362 return;
1363 }
1364
1365 /* Print the error to stderr if needed. */
1366 if (do_output) {
1367 output_if_debug("Mesa: User error", s2, GL_TRUE);
1368 }
1369
1370 /* Log the error via ARB_debug_output if needed.*/
1371 if (do_log) {
1372 log_msg(ctx, MESA_DEBUG_SOURCE_API, MESA_DEBUG_TYPE_ERROR,
1373 error_msg_id, MESA_DEBUG_SEVERITY_HIGH, len, s2);
1374 }
1375 }
1376
1377 /* Set the GL context error state for glGetError. */
1378 _mesa_record_error(ctx, error);
1379 }
1380
1381
1382 /**
1383 * Report debug information. Print error message to stderr via fprintf().
1384 * No-op if DEBUG mode not enabled.
1385 *
1386 * \param ctx GL context.
1387 * \param fmtString printf()-style format string, followed by optional args.
1388 */
1389 void
1390 _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
1391 {
1392 #ifdef DEBUG
1393 char s[MAX_DEBUG_MESSAGE_LENGTH];
1394 va_list args;
1395 va_start(args, fmtString);
1396 _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
1397 va_end(args);
1398 output_if_debug("Mesa", s, GL_FALSE);
1399 #endif /* DEBUG */
1400 (void) ctx;
1401 (void) fmtString;
1402 }
1403
1404
1405 /**
1406 * Report debug information from the shader compiler via GL_ARB_debug_output.
1407 *
1408 * \param ctx GL context.
1409 * \param type The namespace to which this message belongs.
1410 * \param id The message ID within the given namespace.
1411 * \param msg The message to output. Need not be null-terminated.
1412 * \param len The length of 'msg'. If negative, 'msg' must be null-terminated.
1413 */
1414 void
1415 _mesa_shader_debug( struct gl_context *ctx, GLenum type, GLuint *id,
1416 const char *msg, int len )
1417 {
1418 enum mesa_debug_source source = MESA_DEBUG_SOURCE_SHADER_COMPILER;
1419 enum mesa_debug_severity severity = MESA_DEBUG_SEVERITY_HIGH;
1420
1421 debug_get_id(id);
1422
1423 if (len < 0)
1424 len = strlen(msg);
1425
1426 /* Truncate the message if necessary. */
1427 if (len >= MAX_DEBUG_MESSAGE_LENGTH)
1428 len = MAX_DEBUG_MESSAGE_LENGTH - 1;
1429
1430 log_msg(ctx, source, type, *id, severity, len, msg);
1431 }
1432
1433 /*@}*/