gallium/util: fix debug_get_flags_option on 32-bit
[mesa.git] / src / gallium / auxiliary / util / u_debug.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright (c) 2008 VMware, Inc.
5 * 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
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30 #include "pipe/p_config.h"
31
32 #include "pipe/p_compiler.h"
33 #include "util/u_debug.h"
34 #include "pipe/p_format.h"
35 #include "pipe/p_state.h"
36 #include "util/u_inlines.h"
37 #include "util/u_format.h"
38 #include "util/u_memory.h"
39 #include "util/u_string.h"
40 #include "util/u_math.h"
41 #include "util/u_tile.h"
42 #include "util/u_prim.h"
43 #include "util/u_surface.h"
44 #include <inttypes.h>
45
46 #include <stdio.h>
47 #include <limits.h> /* CHAR_BIT */
48 #include <ctype.h> /* isalnum */
49
50 #ifdef _WIN32
51 #include <windows.h>
52 #include <stdlib.h>
53 #endif
54
55
56 void _debug_vprintf(const char *format, va_list ap)
57 {
58 static char buf[4096] = {'\0'};
59 #if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
60 /* We buffer until we find a newline. */
61 size_t len = strlen(buf);
62 int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
63 if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
64 os_log_message(buf);
65 buf[0] = '\0';
66 }
67 #else
68 util_vsnprintf(buf, sizeof(buf), format, ap);
69 os_log_message(buf);
70 #endif
71 }
72
73
74 void
75 debug_disable_error_message_boxes(void)
76 {
77 #ifdef _WIN32
78 /* When Windows' error message boxes are disabled for this process (as is
79 * typically the case when running tests in an automated fashion) we disable
80 * CRT message boxes too.
81 */
82 UINT uMode = SetErrorMode(0);
83 SetErrorMode(uMode);
84 if (uMode & SEM_FAILCRITICALERRORS) {
85 /* Disable assertion failure message box.
86 * http://msdn.microsoft.com/en-us/library/sas1dkb2.aspx
87 */
88 _set_error_mode(_OUT_TO_STDERR);
89 #ifdef _MSC_VER
90 /* Disable abort message box.
91 * http://msdn.microsoft.com/en-us/library/e631wekh.aspx
92 */
93 _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
94 #endif
95 }
96 #endif /* _WIN32 */
97 }
98
99
100 #ifdef DEBUG
101 void debug_print_blob( const char *name,
102 const void *blob,
103 unsigned size )
104 {
105 const unsigned *ublob = (const unsigned *)blob;
106 unsigned i;
107
108 debug_printf("%s (%d dwords%s)\n", name, size/4,
109 size%4 ? "... plus a few bytes" : "");
110
111 for (i = 0; i < size/4; i++) {
112 debug_printf("%d:\t%08x\n", i, ublob[i]);
113 }
114 }
115 #endif
116
117
118 static boolean
119 debug_get_option_should_print(void)
120 {
121 static boolean first = TRUE;
122 static boolean value = FALSE;
123
124 if (!first)
125 return value;
126
127 /* Oh hey this will call into this function,
128 * but its cool since we set first to false
129 */
130 first = FALSE;
131 value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", FALSE);
132 /* XXX should we print this option? Currently it wont */
133 return value;
134 }
135
136 const char *
137 debug_get_option(const char *name, const char *dfault)
138 {
139 const char *result;
140
141 result = os_get_option(name);
142 if(!result)
143 result = dfault;
144
145 if (debug_get_option_should_print())
146 debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
147
148 return result;
149 }
150
151 boolean
152 debug_get_bool_option(const char *name, boolean dfault)
153 {
154 const char *str = os_get_option(name);
155 boolean result;
156
157 if(str == NULL)
158 result = dfault;
159 else if(!util_strcmp(str, "n"))
160 result = FALSE;
161 else if(!util_strcmp(str, "no"))
162 result = FALSE;
163 else if(!util_strcmp(str, "0"))
164 result = FALSE;
165 else if(!util_strcmp(str, "f"))
166 result = FALSE;
167 else if(!util_strcmp(str, "F"))
168 result = FALSE;
169 else if(!util_strcmp(str, "false"))
170 result = FALSE;
171 else if(!util_strcmp(str, "FALSE"))
172 result = FALSE;
173 else
174 result = TRUE;
175
176 if (debug_get_option_should_print())
177 debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
178
179 return result;
180 }
181
182
183 long
184 debug_get_num_option(const char *name, long dfault)
185 {
186 long result;
187 const char *str;
188
189 str = os_get_option(name);
190 if(!str)
191 result = dfault;
192 else {
193 long sign;
194 char c;
195 c = *str++;
196 if(c == '-') {
197 sign = -1;
198 c = *str++;
199 }
200 else {
201 sign = 1;
202 }
203 result = 0;
204 while('0' <= c && c <= '9') {
205 result = result*10 + (c - '0');
206 c = *str++;
207 }
208 result *= sign;
209 }
210
211 if (debug_get_option_should_print())
212 debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
213
214 return result;
215 }
216
217 static boolean str_has_option(const char *str, const char *name)
218 {
219 /* Empty string. */
220 if (!*str) {
221 return FALSE;
222 }
223
224 /* OPTION=all */
225 if (!util_strcmp(str, "all")) {
226 return TRUE;
227 }
228
229 /* Find 'name' in 'str' surrounded by non-alphanumeric characters. */
230 {
231 const char *start = str;
232 unsigned name_len = strlen(name);
233
234 /* 'start' is the beginning of the currently-parsed word,
235 * we increment 'str' each iteration.
236 * if we find either the end of string or a non-alphanumeric character,
237 * we compare 'start' up to 'str-1' with 'name'. */
238
239 while (1) {
240 if (!*str || !(isalnum(*str) || *str == '_')) {
241 if (str-start == name_len &&
242 !memcmp(start, name, name_len)) {
243 return TRUE;
244 }
245
246 if (!*str) {
247 return FALSE;
248 }
249
250 start = str+1;
251 }
252
253 str++;
254 }
255 }
256
257 return FALSE;
258 }
259
260 uint64_t
261 debug_get_flags_option(const char *name,
262 const struct debug_named_value *flags,
263 uint64_t dfault)
264 {
265 uint64_t result;
266 const char *str;
267 const struct debug_named_value *orig = flags;
268 unsigned namealign = 0;
269
270 str = os_get_option(name);
271 if(!str)
272 result = dfault;
273 else if (!util_strcmp(str, "help")) {
274 result = dfault;
275 _debug_printf("%s: help for %s:\n", __FUNCTION__, name);
276 for (; flags->name; ++flags)
277 namealign = MAX2(namealign, strlen(flags->name));
278 for (flags = orig; flags->name; ++flags)
279 _debug_printf("| %*s [0x%0*"PRIu64"]%s%s\n", namealign, flags->name,
280 (int)sizeof(uint64_t)*CHAR_BIT/4, flags->value,
281 flags->desc ? " " : "", flags->desc ? flags->desc : "");
282 }
283 else {
284 result = 0;
285 while( flags->name ) {
286 if (str_has_option(str, flags->name))
287 result |= flags->value;
288 ++flags;
289 }
290 }
291
292 if (debug_get_option_should_print()) {
293 if (str) {
294 debug_printf("%s: %s = 0x%"PRIu64" (%s)\n", __FUNCTION__, name, result, str);
295 } else {
296 debug_printf("%s: %s = 0x%"PRIu64"\n", __FUNCTION__, name, result);
297 }
298 }
299
300 return result;
301 }
302
303
304 void _debug_assert_fail(const char *expr,
305 const char *file,
306 unsigned line,
307 const char *function)
308 {
309 _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
310 os_abort();
311 }
312
313
314 const char *
315 debug_dump_enum(const struct debug_named_value *names,
316 unsigned long value)
317 {
318 static char rest[64];
319
320 while(names->name) {
321 if(names->value == value)
322 return names->name;
323 ++names;
324 }
325
326 util_snprintf(rest, sizeof(rest), "0x%08lx", value);
327 return rest;
328 }
329
330
331 const char *
332 debug_dump_enum_noprefix(const struct debug_named_value *names,
333 const char *prefix,
334 unsigned long value)
335 {
336 static char rest[64];
337
338 while(names->name) {
339 if(names->value == value) {
340 const char *name = names->name;
341 while (*name == *prefix) {
342 name++;
343 prefix++;
344 }
345 return name;
346 }
347 ++names;
348 }
349
350
351
352 util_snprintf(rest, sizeof(rest), "0x%08lx", value);
353 return rest;
354 }
355
356
357 const char *
358 debug_dump_flags(const struct debug_named_value *names,
359 unsigned long value)
360 {
361 static char output[4096];
362 static char rest[256];
363 int first = 1;
364
365 output[0] = '\0';
366
367 while(names->name) {
368 if((names->value & value) == names->value) {
369 if (!first)
370 util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
371 else
372 first = 0;
373 util_strncat(output, names->name, sizeof(output) - strlen(output) - 1);
374 output[sizeof(output) - 1] = '\0';
375 value &= ~names->value;
376 }
377 ++names;
378 }
379
380 if (value) {
381 if (!first)
382 util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
383 else
384 first = 0;
385
386 util_snprintf(rest, sizeof(rest), "0x%08lx", value);
387 util_strncat(output, rest, sizeof(output) - strlen(output) - 1);
388 output[sizeof(output) - 1] = '\0';
389 }
390
391 if(first)
392 return "0";
393
394 return output;
395 }
396
397
398 #ifdef DEBUG
399 void debug_print_format(const char *msg, unsigned fmt )
400 {
401 debug_printf("%s: %s\n", msg, util_format_name(fmt));
402 }
403 #endif
404
405
406 /** Return string name of given primitive type */
407 const char *
408 u_prim_name(unsigned prim)
409 {
410 static const struct debug_named_value names[] = {
411 DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS),
412 DEBUG_NAMED_VALUE(PIPE_PRIM_LINES),
413 DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_LOOP),
414 DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP),
415 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES),
416 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP),
417 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_FAN),
418 DEBUG_NAMED_VALUE(PIPE_PRIM_QUADS),
419 DEBUG_NAMED_VALUE(PIPE_PRIM_QUAD_STRIP),
420 DEBUG_NAMED_VALUE(PIPE_PRIM_POLYGON),
421 DEBUG_NAMED_VALUE(PIPE_PRIM_LINES_ADJACENCY),
422 DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP_ADJACENCY),
423 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES_ADJACENCY),
424 DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY),
425 DEBUG_NAMED_VALUE_END
426 };
427 return debug_dump_enum(names, prim);
428 }
429
430
431
432 #ifdef DEBUG
433 int fl_indent = 0;
434 const char* fl_function[1024];
435
436 int debug_funclog_enter(const char* f, const int line, const char* file)
437 {
438 int i;
439
440 for (i = 0; i < fl_indent; i++)
441 debug_printf(" ");
442 debug_printf("%s\n", f);
443
444 assert(fl_indent < 1023);
445 fl_function[fl_indent++] = f;
446
447 return 0;
448 }
449
450 void debug_funclog_exit(const char* f, const int line, const char* file)
451 {
452 --fl_indent;
453 assert(fl_indent >= 0);
454 assert(fl_function[fl_indent] == f);
455 }
456
457 void debug_funclog_enter_exit(const char* f, const int line, const char* file)
458 {
459 int i;
460 for (i = 0; i < fl_indent; i++)
461 debug_printf(" ");
462 debug_printf("%s\n", f);
463 }
464 #endif
465
466
467
468 #ifdef DEBUG
469 /**
470 * Dump an image to .ppm file.
471 * \param format PIPE_FORMAT_x
472 * \param cpp bytes per pixel
473 * \param width width in pixels
474 * \param height height in pixels
475 * \param stride row stride in bytes
476 */
477 void debug_dump_image(const char *prefix,
478 enum pipe_format format, unsigned cpp,
479 unsigned width, unsigned height,
480 unsigned stride,
481 const void *data)
482 {
483 /* write a ppm file */
484 char filename[256];
485 unsigned char *rgb8;
486 FILE *f;
487
488 util_snprintf(filename, sizeof(filename), "%s.ppm", prefix);
489
490 rgb8 = MALLOC(height * width * 3);
491 if (!rgb8) {
492 return;
493 }
494
495 util_format_translate(
496 PIPE_FORMAT_R8G8B8_UNORM,
497 rgb8, width * 3,
498 0, 0,
499 format,
500 data, stride,
501 0, 0, width, height);
502
503 /* Must be opened in binary mode or DOS line ending causes data
504 * to be read with one byte offset.
505 */
506 f = fopen(filename, "wb");
507 if (f) {
508 fprintf(f, "P6\n");
509 fprintf(f, "# ppm-file created by gallium\n");
510 fprintf(f, "%i %i\n", width, height);
511 fprintf(f, "255\n");
512 fwrite(rgb8, 1, height * width * 3, f);
513 fclose(f);
514 }
515 else {
516 fprintf(stderr, "Can't open %s for writing\n", filename);
517 }
518
519 FREE(rgb8);
520 }
521
522 /* FIXME: dump resources, not surfaces... */
523 void debug_dump_surface(struct pipe_context *pipe,
524 const char *prefix,
525 struct pipe_surface *surface)
526 {
527 struct pipe_resource *texture;
528 struct pipe_transfer *transfer;
529 void *data;
530
531 if (!surface)
532 return;
533
534 /* XXX: this doesn't necessarily work, as the driver may be using
535 * temporary storage for the surface which hasn't been propagated
536 * back into the texture. Need to nail down the semantics of views
537 * and transfers a bit better before we can say if extra work needs
538 * to be done here:
539 */
540 texture = surface->texture;
541
542 data = pipe_transfer_map(pipe, texture, surface->u.tex.level,
543 surface->u.tex.first_layer,
544 PIPE_TRANSFER_READ,
545 0, 0, surface->width, surface->height, &transfer);
546 if(!data)
547 return;
548
549 debug_dump_image(prefix,
550 texture->format,
551 util_format_get_blocksize(texture->format),
552 util_format_get_nblocksx(texture->format, surface->width),
553 util_format_get_nblocksy(texture->format, surface->height),
554 transfer->stride,
555 data);
556
557 pipe->transfer_unmap(pipe, transfer);
558 }
559
560
561 void debug_dump_texture(struct pipe_context *pipe,
562 const char *prefix,
563 struct pipe_resource *texture)
564 {
565 struct pipe_surface *surface, surf_tmpl;
566
567 if (!texture)
568 return;
569
570 /* XXX for now, just dump image for layer=0, level=0 */
571 u_surface_default_template(&surf_tmpl, texture);
572 surface = pipe->create_surface(pipe, texture, &surf_tmpl);
573 if (surface) {
574 debug_dump_surface(pipe, prefix, surface);
575 pipe->surface_destroy(pipe, surface);
576 }
577 }
578
579
580 #pragma pack(push,2)
581 struct bmp_file_header {
582 uint16_t bfType;
583 uint32_t bfSize;
584 uint16_t bfReserved1;
585 uint16_t bfReserved2;
586 uint32_t bfOffBits;
587 };
588 #pragma pack(pop)
589
590 struct bmp_info_header {
591 uint32_t biSize;
592 int32_t biWidth;
593 int32_t biHeight;
594 uint16_t biPlanes;
595 uint16_t biBitCount;
596 uint32_t biCompression;
597 uint32_t biSizeImage;
598 int32_t biXPelsPerMeter;
599 int32_t biYPelsPerMeter;
600 uint32_t biClrUsed;
601 uint32_t biClrImportant;
602 };
603
604 struct bmp_rgb_quad {
605 uint8_t rgbBlue;
606 uint8_t rgbGreen;
607 uint8_t rgbRed;
608 uint8_t rgbAlpha;
609 };
610
611 void
612 debug_dump_surface_bmp(struct pipe_context *pipe,
613 const char *filename,
614 struct pipe_surface *surface)
615 {
616 struct pipe_transfer *transfer;
617 struct pipe_resource *texture = surface->texture;
618 void *ptr;
619
620 ptr = pipe_transfer_map(pipe, texture, surface->u.tex.level,
621 surface->u.tex.first_layer, PIPE_TRANSFER_READ,
622 0, 0, surface->width, surface->height, &transfer);
623
624 debug_dump_transfer_bmp(pipe, filename, transfer, ptr);
625
626 pipe->transfer_unmap(pipe, transfer);
627 }
628
629 void
630 debug_dump_transfer_bmp(struct pipe_context *pipe,
631 const char *filename,
632 struct pipe_transfer *transfer, void *ptr)
633 {
634 float *rgba;
635
636 if (!transfer)
637 goto error1;
638
639 rgba = MALLOC(transfer->box.width *
640 transfer->box.height *
641 transfer->box.depth *
642 4*sizeof(float));
643 if(!rgba)
644 goto error1;
645
646 pipe_get_tile_rgba(transfer, ptr, 0, 0,
647 transfer->box.width, transfer->box.height,
648 rgba);
649
650 debug_dump_float_rgba_bmp(filename,
651 transfer->box.width, transfer->box.height,
652 rgba, transfer->box.width);
653
654 FREE(rgba);
655 error1:
656 ;
657 }
658
659 void
660 debug_dump_float_rgba_bmp(const char *filename,
661 unsigned width, unsigned height,
662 float *rgba, unsigned stride)
663 {
664 FILE *stream;
665 struct bmp_file_header bmfh;
666 struct bmp_info_header bmih;
667 unsigned x, y;
668
669 if(!rgba)
670 goto error1;
671
672 bmfh.bfType = 0x4d42;
673 bmfh.bfSize = 14 + 40 + height*width*4;
674 bmfh.bfReserved1 = 0;
675 bmfh.bfReserved2 = 0;
676 bmfh.bfOffBits = 14 + 40;
677
678 bmih.biSize = 40;
679 bmih.biWidth = width;
680 bmih.biHeight = height;
681 bmih.biPlanes = 1;
682 bmih.biBitCount = 32;
683 bmih.biCompression = 0;
684 bmih.biSizeImage = height*width*4;
685 bmih.biXPelsPerMeter = 0;
686 bmih.biYPelsPerMeter = 0;
687 bmih.biClrUsed = 0;
688 bmih.biClrImportant = 0;
689
690 stream = fopen(filename, "wb");
691 if(!stream)
692 goto error1;
693
694 fwrite(&bmfh, 14, 1, stream);
695 fwrite(&bmih, 40, 1, stream);
696
697 y = height;
698 while(y--) {
699 float *ptr = rgba + (stride * y * 4);
700 for(x = 0; x < width; ++x)
701 {
702 struct bmp_rgb_quad pixel;
703 pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]);
704 pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]);
705 pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]);
706 pixel.rgbAlpha = float_to_ubyte(ptr[x*4 + 3]);
707 fwrite(&pixel, 1, 4, stream);
708 }
709 }
710
711 fclose(stream);
712 error1:
713 ;
714 }
715
716
717 /**
718 * Print PIPE_TRANSFER_x flags with a message.
719 */
720 void
721 debug_print_transfer_flags(const char *msg, unsigned usage)
722 {
723 static const struct debug_named_value names[] = {
724 DEBUG_NAMED_VALUE(PIPE_TRANSFER_READ),
725 DEBUG_NAMED_VALUE(PIPE_TRANSFER_WRITE),
726 DEBUG_NAMED_VALUE(PIPE_TRANSFER_MAP_DIRECTLY),
727 DEBUG_NAMED_VALUE(PIPE_TRANSFER_DISCARD_RANGE),
728 DEBUG_NAMED_VALUE(PIPE_TRANSFER_DONTBLOCK),
729 DEBUG_NAMED_VALUE(PIPE_TRANSFER_UNSYNCHRONIZED),
730 DEBUG_NAMED_VALUE(PIPE_TRANSFER_FLUSH_EXPLICIT),
731 DEBUG_NAMED_VALUE(PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE),
732 DEBUG_NAMED_VALUE(PIPE_TRANSFER_PERSISTENT),
733 DEBUG_NAMED_VALUE(PIPE_TRANSFER_COHERENT),
734 DEBUG_NAMED_VALUE_END
735 };
736
737 debug_printf("%s: %s\n", msg, debug_dump_flags(names, usage));
738 }
739
740
741 /**
742 * Print PIPE_BIND_x flags with a message.
743 */
744 void
745 debug_print_bind_flags(const char *msg, unsigned usage)
746 {
747 static const struct debug_named_value names[] = {
748 DEBUG_NAMED_VALUE(PIPE_BIND_DEPTH_STENCIL),
749 DEBUG_NAMED_VALUE(PIPE_BIND_RENDER_TARGET),
750 DEBUG_NAMED_VALUE(PIPE_BIND_BLENDABLE),
751 DEBUG_NAMED_VALUE(PIPE_BIND_SAMPLER_VIEW),
752 DEBUG_NAMED_VALUE(PIPE_BIND_VERTEX_BUFFER),
753 DEBUG_NAMED_VALUE(PIPE_BIND_INDEX_BUFFER),
754 DEBUG_NAMED_VALUE(PIPE_BIND_CONSTANT_BUFFER),
755 DEBUG_NAMED_VALUE(PIPE_BIND_DISPLAY_TARGET),
756 DEBUG_NAMED_VALUE(PIPE_BIND_TRANSFER_WRITE),
757 DEBUG_NAMED_VALUE(PIPE_BIND_TRANSFER_READ),
758 DEBUG_NAMED_VALUE(PIPE_BIND_STREAM_OUTPUT),
759 DEBUG_NAMED_VALUE(PIPE_BIND_CURSOR),
760 DEBUG_NAMED_VALUE(PIPE_BIND_CUSTOM),
761 DEBUG_NAMED_VALUE(PIPE_BIND_GLOBAL),
762 DEBUG_NAMED_VALUE(PIPE_BIND_SHADER_BUFFER),
763 DEBUG_NAMED_VALUE(PIPE_BIND_SHADER_IMAGE),
764 DEBUG_NAMED_VALUE(PIPE_BIND_COMPUTE_RESOURCE),
765 DEBUG_NAMED_VALUE(PIPE_BIND_COMMAND_ARGS_BUFFER),
766 DEBUG_NAMED_VALUE(PIPE_BIND_SCANOUT),
767 DEBUG_NAMED_VALUE(PIPE_BIND_SHARED),
768 DEBUG_NAMED_VALUE(PIPE_BIND_LINEAR),
769 DEBUG_NAMED_VALUE_END
770 };
771
772 debug_printf("%s: %s\n", msg, debug_dump_flags(names, usage));
773 }
774
775
776 /**
777 * Print PIPE_USAGE_x enum values with a message.
778 */
779 void
780 debug_print_usage_enum(const char *msg, unsigned usage)
781 {
782 static const struct debug_named_value names[] = {
783 DEBUG_NAMED_VALUE(PIPE_USAGE_DEFAULT),
784 DEBUG_NAMED_VALUE(PIPE_USAGE_IMMUTABLE),
785 DEBUG_NAMED_VALUE(PIPE_USAGE_DYNAMIC),
786 DEBUG_NAMED_VALUE(PIPE_USAGE_STREAM),
787 DEBUG_NAMED_VALUE(PIPE_USAGE_STAGING),
788 DEBUG_NAMED_VALUE_END
789 };
790
791 debug_printf("%s: %s\n", msg, debug_dump_enum(names, usage));
792 }
793
794
795 #endif