1 /**************************************************************************
3 * Copyright 2008-2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 #include "pipe/p_compiler.h"
30 #include "os/os_stream.h"
31 #include "util/u_memory.h"
32 #include "util/u_string.h"
33 #include "util/u_format.h"
34 #include "tgsi/tgsi_dump.h"
44 util_stream_writef(struct os_stream *stream, const char *format, ...)
46 static char buf[1024];
50 len = util_vsnprintf(buf, sizeof(buf), format, ap);
52 os_stream_write(stream, buf, len);
56 util_dump_bool(struct os_stream *stream, int value)
58 util_stream_writef(stream, "%c", value ? '1' : '0');
62 util_dump_int(struct os_stream *stream, long long int value)
64 util_stream_writef(stream, "%lli", value);
68 util_dump_uint(struct os_stream *stream, long long unsigned value)
70 util_stream_writef(stream, "%llu", value);
74 util_dump_float(struct os_stream *stream, double value)
76 util_stream_writef(stream, "%g", value);
80 util_dump_string(struct os_stream *stream, const char *str)
82 os_stream_write_str(stream, "\"");
83 os_stream_write_str(stream, str);
84 os_stream_write_str(stream, "\"");
88 util_dump_enum(struct os_stream *stream, const char *value)
90 os_stream_write_str(stream, value);
94 util_dump_array_begin(struct os_stream *stream)
96 os_stream_write_str(stream, "{");
100 util_dump_array_end(struct os_stream *stream)
102 os_stream_write_str(stream, "}");
106 util_dump_elem_begin(struct os_stream *stream)
111 util_dump_elem_end(struct os_stream *stream)
113 os_stream_write_str(stream, ", ");
117 util_dump_struct_begin(struct os_stream *stream, const char *name)
119 os_stream_write_str(stream, "{");
123 util_dump_struct_end(struct os_stream *stream)
125 os_stream_write_str(stream, "}");
129 util_dump_member_begin(struct os_stream *stream, const char *name)
131 util_stream_writef(stream, "%s = ", name);
135 util_dump_member_end(struct os_stream *stream)
137 os_stream_write_str(stream, ", ");
141 util_dump_null(struct os_stream *stream)
143 os_stream_write_str(stream, "NULL");
147 util_dump_ptr(struct os_stream *stream, const void *value)
150 util_stream_writef(stream, "0x%08lx", (unsigned long)(uintptr_t)value);
152 util_dump_null(stream);
157 * Code saving macros.
160 #define util_dump_arg(_stream, _type, _arg) \
162 util_dump_arg_begin(_stream, #_arg); \
163 util_dump_##_type(_stream, _arg); \
164 util_dump_arg_end(_stream); \
167 #define util_dump_ret(_stream, _type, _arg) \
169 util_dump_ret_begin(_stream); \
170 util_dump_##_type(_stream, _arg); \
171 util_dump_ret_end(_stream); \
174 #define util_dump_array(_stream, _type, _obj, _size) \
177 util_dump_array_begin(_stream); \
178 for(idx = 0; idx < (_size); ++idx) { \
179 util_dump_elem_begin(_stream); \
180 util_dump_##_type(_stream, (_obj)[idx]); \
181 util_dump_elem_end(_stream); \
183 util_dump_array_end(_stream); \
186 #define util_dump_struct_array(_stream, _type, _obj, _size) \
189 util_dump_array_begin(_stream); \
190 for(idx = 0; idx < (_size); ++idx) { \
191 util_dump_elem_begin(_stream); \
192 util_dump_##_type(_stream, &(_obj)[idx]); \
193 util_dump_elem_end(_stream); \
195 util_dump_array_end(_stream); \
198 #define util_dump_member(_stream, _type, _obj, _member) \
200 util_dump_member_begin(_stream, #_member); \
201 util_dump_##_type(_stream, (_obj)->_member); \
202 util_dump_member_end(_stream); \
205 #define util_dump_arg_array(_stream, _type, _arg, _size) \
207 util_dump_arg_begin(_stream, #_arg); \
208 util_dump_array(_stream, _type, _arg, _size); \
209 util_dump_arg_end(_stream); \
212 #define util_dump_member_array(_stream, _type, _obj, _member) \
214 util_dump_member_begin(_stream, #_member); \
215 util_dump_array(_stream, _type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \
216 util_dump_member_end(_stream); \
222 * Wrappers for enum -> string dumpers.
227 util_dump_format(struct os_stream *stream, enum pipe_format format)
229 util_dump_enum(stream, util_format_name(format));
234 util_dump_enum_blend_factor(struct os_stream *stream, unsigned value)
236 util_dump_enum(stream, util_dump_blend_factor(value, TRUE));
240 util_dump_enum_blend_func(struct os_stream *stream, unsigned value)
242 util_dump_enum(stream, util_dump_blend_func(value, TRUE));
246 util_dump_enum_func(struct os_stream *stream, unsigned value)
248 util_dump_enum(stream, util_dump_func(value, TRUE));
258 util_dump_template(struct os_stream *stream, const struct pipe_resource *templat)
261 util_dump_null(stream);
265 util_dump_struct_begin(stream, "pipe_resource");
267 util_dump_member(stream, int, templat, target);
268 util_dump_member(stream, format, templat, format);
270 util_dump_member_begin(stream, "width");
271 util_dump_uint(stream, templat->width0);
272 util_dump_member_end(stream);
274 util_dump_member_begin(stream, "height");
275 util_dump_uint(stream, templat->height0);
276 util_dump_member_end(stream);
278 util_dump_member_begin(stream, "depth");
279 util_dump_uint(stream, templat->depth0);
280 util_dump_member_end(stream);
282 util_dump_member(stream, uint, templat, last_level);
283 util_dump_member(stream, uint, templat, _usage);
284 util_dump_member(stream, uint, templat, bind);
285 util_dump_member(stream, uint, templat, flags);
287 util_dump_struct_end(stream);
292 util_dump_rasterizer_state(struct os_stream *stream, const struct pipe_rasterizer_state *state)
295 util_dump_null(stream);
299 util_dump_struct_begin(stream, "pipe_rasterizer_state");
301 util_dump_member(stream, bool, state, flatshade);
302 util_dump_member(stream, bool, state, light_twoside);
303 util_dump_member(stream, uint, state, front_winding);
304 util_dump_member(stream, uint, state, cull_mode);
305 util_dump_member(stream, uint, state, fill_cw);
306 util_dump_member(stream, uint, state, fill_ccw);
307 util_dump_member(stream, bool, state, offset_cw);
308 util_dump_member(stream, bool, state, offset_ccw);
309 util_dump_member(stream, bool, state, scissor);
310 util_dump_member(stream, bool, state, poly_smooth);
311 util_dump_member(stream, bool, state, poly_stipple_enable);
312 util_dump_member(stream, bool, state, point_smooth);
313 util_dump_member(stream, uint, state, sprite_coord_enable);
314 util_dump_member(stream, bool, state, sprite_coord_mode);
315 util_dump_member(stream, bool, state, point_quad_rasterization);
316 util_dump_member(stream, bool, state, point_size_per_vertex);
317 util_dump_member(stream, bool, state, multisample);
318 util_dump_member(stream, bool, state, line_smooth);
319 util_dump_member(stream, bool, state, line_stipple_enable);
320 util_dump_member(stream, uint, state, line_stipple_factor);
321 util_dump_member(stream, uint, state, line_stipple_pattern);
322 util_dump_member(stream, bool, state, line_last_pixel);
323 util_dump_member(stream, bool, state, flatshade_first);
324 util_dump_member(stream, bool, state, gl_rasterization_rules);
326 util_dump_member(stream, float, state, line_width);
327 util_dump_member(stream, float, state, point_size);
328 util_dump_member(stream, float, state, offset_units);
329 util_dump_member(stream, float, state, offset_scale);
331 util_dump_struct_end(stream);
336 util_dump_poly_stipple(struct os_stream *stream, const struct pipe_poly_stipple *state)
339 util_dump_null(stream);
343 util_dump_struct_begin(stream, "pipe_poly_stipple");
345 util_dump_member_begin(stream, "stipple");
346 util_dump_member_array(stream, uint, state, stipple);
347 util_dump_member_end(stream);
349 util_dump_struct_end(stream);
354 util_dump_viewport_state(struct os_stream *stream, const struct pipe_viewport_state *state)
357 util_dump_null(stream);
361 util_dump_struct_begin(stream, "pipe_viewport_state");
363 util_dump_member_array(stream, float, state, scale);
364 util_dump_member_array(stream, float, state, translate);
366 util_dump_struct_end(stream);
371 util_dump_scissor_state(struct os_stream *stream, const struct pipe_scissor_state *state)
374 util_dump_null(stream);
378 util_dump_struct_begin(stream, "pipe_scissor_state");
380 util_dump_member(stream, uint, state, minx);
381 util_dump_member(stream, uint, state, miny);
382 util_dump_member(stream, uint, state, maxx);
383 util_dump_member(stream, uint, state, maxy);
385 util_dump_struct_end(stream);
390 util_dump_clip_state(struct os_stream *stream, const struct pipe_clip_state *state)
395 util_dump_null(stream);
399 util_dump_struct_begin(stream, "pipe_clip_state");
401 util_dump_member_begin(stream, "ucp");
402 util_dump_array_begin(stream);
403 for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) {
404 util_dump_elem_begin(stream);
405 util_dump_array(stream, float, state->ucp[i], 4);
406 util_dump_elem_end(stream);
408 util_dump_array_end(stream);
409 util_dump_member_end(stream);
411 util_dump_member(stream, uint, state, nr);
413 util_dump_struct_end(stream);
418 util_dump_shader_state(struct os_stream *stream, const struct pipe_shader_state *state)
423 util_dump_null(stream);
427 tgsi_dump_str(state->tokens, 0, str, sizeof(str));
429 util_dump_struct_begin(stream, "pipe_shader_state");
431 util_dump_member_begin(stream, "tokens");
432 util_dump_string(stream, str);
433 util_dump_member_end(stream);
435 util_dump_struct_end(stream);
440 util_dump_depth_stencil_alpha_state(struct os_stream *stream, const struct pipe_depth_stencil_alpha_state *state)
445 util_dump_null(stream);
449 util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");
451 util_dump_member_begin(stream, "depth");
452 util_dump_struct_begin(stream, "pipe_depth_state");
453 util_dump_member(stream, bool, &state->depth, enabled);
454 if (state->depth.enabled) {
455 util_dump_member(stream, bool, &state->depth, writemask);
456 util_dump_member(stream, enum_func, &state->depth, func);
458 util_dump_struct_end(stream);
459 util_dump_member_end(stream);
461 util_dump_member_begin(stream, "stencil");
462 util_dump_array_begin(stream);
463 for(i = 0; i < Elements(state->stencil); ++i) {
464 util_dump_elem_begin(stream);
465 util_dump_struct_begin(stream, "pipe_stencil_state");
466 util_dump_member(stream, bool, &state->stencil[i], enabled);
467 if (state->stencil[i].enabled) {
468 util_dump_member(stream, enum_func, &state->stencil[i], func);
469 util_dump_member(stream, uint, &state->stencil[i], fail_op);
470 util_dump_member(stream, uint, &state->stencil[i], zpass_op);
471 util_dump_member(stream, uint, &state->stencil[i], zfail_op);
472 util_dump_member(stream, uint, &state->stencil[i], valuemask);
473 util_dump_member(stream, uint, &state->stencil[i], writemask);
475 util_dump_struct_end(stream);
476 util_dump_elem_end(stream);
478 util_dump_array_end(stream);
479 util_dump_member_end(stream);
481 util_dump_member_begin(stream, "alpha");
482 util_dump_struct_begin(stream, "pipe_alpha_state");
483 util_dump_member(stream, bool, &state->alpha, enabled);
484 if (state->alpha.enabled) {
485 util_dump_member(stream, enum_func, &state->alpha, func);
486 util_dump_member(stream, float, &state->alpha, ref_value);
488 util_dump_struct_end(stream);
489 util_dump_member_end(stream);
491 util_dump_struct_end(stream);
495 util_dump_rt_blend_state(struct os_stream *stream, const struct pipe_rt_blend_state *state)
497 util_dump_struct_begin(stream, "pipe_rt_blend_state");
499 util_dump_member(stream, uint, state, blend_enable);
500 if (state->blend_enable) {
501 util_dump_member(stream, enum_blend_func, state, rgb_func);
502 util_dump_member(stream, enum_blend_factor, state, rgb_src_factor);
503 util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor);
505 util_dump_member(stream, enum_blend_func, state, alpha_func);
506 util_dump_member(stream, enum_blend_factor, state, alpha_src_factor);
507 util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor);
510 util_dump_member(stream, uint, state, colormask);
512 util_dump_struct_end(stream);
516 util_dump_blend_state(struct os_stream *stream, const struct pipe_blend_state *state)
518 unsigned valid_entries = 1;
521 util_dump_null(stream);
525 util_dump_struct_begin(stream, "pipe_blend_state");
527 util_dump_member(stream, bool, state, dither);
529 util_dump_member(stream, bool, state, logicop_enable);
530 if (state->logicop_enable) {
531 util_dump_member(stream, enum_func, state, logicop_func);
534 util_dump_member(stream, bool, state, independent_blend_enable);
536 util_dump_member_begin(stream, "rt");
537 if (state->independent_blend_enable)
538 valid_entries = PIPE_MAX_COLOR_BUFS;
539 util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries);
540 util_dump_member_end(stream);
543 util_dump_struct_end(stream);
548 util_dump_blend_color(struct os_stream *stream, const struct pipe_blend_color *state)
551 util_dump_null(stream);
555 util_dump_struct_begin(stream, "pipe_blend_color");
557 util_dump_member_array(stream, float, state, color);
559 util_dump_struct_end(stream);
563 util_dump_stencil_ref(struct os_stream *stream, const struct pipe_stencil_ref *state)
566 util_dump_null(stream);
570 util_dump_struct_begin(stream, "pipe_stencil_ref");
572 util_dump_member_array(stream, uint, state, ref_value);
574 util_dump_struct_end(stream);
578 util_dump_framebuffer_state(struct os_stream *stream, const struct pipe_framebuffer_state *state)
580 util_dump_struct_begin(stream, "pipe_framebuffer_state");
582 util_dump_member(stream, uint, state, width);
583 util_dump_member(stream, uint, state, height);
584 util_dump_member(stream, uint, state, nr_cbufs);
585 util_dump_member_array(stream, ptr, state, cbufs);
586 util_dump_member(stream, ptr, state, zsbuf);
588 util_dump_struct_end(stream);
593 util_dump_sampler_state(struct os_stream *stream, const struct pipe_sampler_state *state)
596 util_dump_null(stream);
600 util_dump_struct_begin(stream, "pipe_sampler_state");
602 util_dump_member(stream, uint, state, wrap_s);
603 util_dump_member(stream, uint, state, wrap_t);
604 util_dump_member(stream, uint, state, wrap_r);
605 util_dump_member(stream, uint, state, min_img_filter);
606 util_dump_member(stream, uint, state, min_mip_filter);
607 util_dump_member(stream, uint, state, mag_img_filter);
608 util_dump_member(stream, uint, state, compare_mode);
609 util_dump_member(stream, enum_func, state, compare_func);
610 util_dump_member(stream, bool, state, normalized_coords);
611 util_dump_member(stream, uint, state, max_anisotropy);
612 util_dump_member(stream, float, state, lod_bias);
613 util_dump_member(stream, float, state, min_lod);
614 util_dump_member(stream, float, state, max_lod);
615 util_dump_member_array(stream, float, state, border_color);
617 util_dump_struct_end(stream);
622 util_dump_surface(struct os_stream *stream, const struct pipe_surface *state)
625 util_dump_null(stream);
629 util_dump_struct_begin(stream, "pipe_surface");
631 util_dump_member(stream, format, state, format);
632 util_dump_member(stream, uint, state, width);
633 util_dump_member(stream, uint, state, height);
635 util_dump_member(stream, uint, state, layout);
636 util_dump_member(stream, uint, state, offset);
637 util_dump_member(stream, uint, state, usage);
639 util_dump_member(stream, ptr, state, texture);
640 util_dump_member(stream, uint, state, face);
641 util_dump_member(stream, uint, state, level);
642 util_dump_member(stream, uint, state, zslice);
644 util_dump_struct_end(stream);
649 util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state)
652 util_dump_null(stream);
656 util_dump_struct_begin(stream, "pipe_transfer");
658 util_dump_member(stream, ptr, state, resource);
659 // util_dump_member(stream, uint, state, box);
661 util_dump_member(stream, uint, state, stride);
662 util_dump_member(stream, uint, state, slice_stride);
664 // util_dump_member(stream, ptr, state, data);
666 util_dump_struct_end(stream);
671 util_dump_vertex_buffer(struct os_stream *stream, const struct pipe_vertex_buffer *state)
674 util_dump_null(stream);
678 util_dump_struct_begin(stream, "pipe_vertex_buffer");
680 util_dump_member(stream, uint, state, stride);
681 util_dump_member(stream, uint, state, max_index);
682 util_dump_member(stream, uint, state, buffer_offset);
683 util_dump_member(stream, ptr, state, buffer);
685 util_dump_struct_end(stream);
690 util_dump_vertex_element(struct os_stream *stream, const struct pipe_vertex_element *state)
693 util_dump_null(stream);
697 util_dump_struct_begin(stream, "pipe_vertex_element");
699 util_dump_member(stream, uint, state, src_offset);
701 util_dump_member(stream, uint, state, vertex_buffer_index);
703 util_dump_member(stream, format, state, src_format);
705 util_dump_struct_end(stream);