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_begin(stream
, "array_size");
283 util_dump_uint(stream
, templat
->array_size
);
284 util_dump_member_end(stream
);
286 util_dump_member(stream
, uint
, templat
, last_level
);
287 util_dump_member(stream
, uint
, templat
, usage
);
288 util_dump_member(stream
, uint
, templat
, bind
);
289 util_dump_member(stream
, uint
, templat
, flags
);
291 util_dump_struct_end(stream
);
296 util_dump_rasterizer_state(struct os_stream
*stream
, const struct pipe_rasterizer_state
*state
)
299 util_dump_null(stream
);
303 util_dump_struct_begin(stream
, "pipe_rasterizer_state");
305 util_dump_member(stream
, bool, state
, flatshade
);
306 util_dump_member(stream
, bool, state
, light_twoside
);
307 util_dump_member(stream
, uint
, state
, front_ccw
);
308 util_dump_member(stream
, uint
, state
, cull_face
);
309 util_dump_member(stream
, uint
, state
, fill_front
);
310 util_dump_member(stream
, uint
, state
, fill_back
);
311 util_dump_member(stream
, bool, state
, offset_point
);
312 util_dump_member(stream
, bool, state
, offset_line
);
313 util_dump_member(stream
, bool, state
, offset_tri
);
314 util_dump_member(stream
, bool, state
, scissor
);
315 util_dump_member(stream
, bool, state
, poly_smooth
);
316 util_dump_member(stream
, bool, state
, poly_stipple_enable
);
317 util_dump_member(stream
, bool, state
, point_smooth
);
318 util_dump_member(stream
, uint
, state
, sprite_coord_enable
);
319 util_dump_member(stream
, bool, state
, sprite_coord_mode
);
320 util_dump_member(stream
, bool, state
, point_quad_rasterization
);
321 util_dump_member(stream
, bool, state
, point_size_per_vertex
);
322 util_dump_member(stream
, bool, state
, multisample
);
323 util_dump_member(stream
, bool, state
, line_smooth
);
324 util_dump_member(stream
, bool, state
, line_stipple_enable
);
325 util_dump_member(stream
, uint
, state
, line_stipple_factor
);
326 util_dump_member(stream
, uint
, state
, line_stipple_pattern
);
327 util_dump_member(stream
, bool, state
, line_last_pixel
);
328 util_dump_member(stream
, bool, state
, flatshade_first
);
329 util_dump_member(stream
, bool, state
, gl_rasterization_rules
);
331 util_dump_member(stream
, float, state
, line_width
);
332 util_dump_member(stream
, float, state
, point_size
);
333 util_dump_member(stream
, float, state
, offset_units
);
334 util_dump_member(stream
, float, state
, offset_scale
);
336 util_dump_struct_end(stream
);
341 util_dump_poly_stipple(struct os_stream
*stream
, const struct pipe_poly_stipple
*state
)
344 util_dump_null(stream
);
348 util_dump_struct_begin(stream
, "pipe_poly_stipple");
350 util_dump_member_begin(stream
, "stipple");
351 util_dump_member_array(stream
, uint
, state
, stipple
);
352 util_dump_member_end(stream
);
354 util_dump_struct_end(stream
);
359 util_dump_viewport_state(struct os_stream
*stream
, const struct pipe_viewport_state
*state
)
362 util_dump_null(stream
);
366 util_dump_struct_begin(stream
, "pipe_viewport_state");
368 util_dump_member_array(stream
, float, state
, scale
);
369 util_dump_member_array(stream
, float, state
, translate
);
371 util_dump_struct_end(stream
);
376 util_dump_scissor_state(struct os_stream
*stream
, const struct pipe_scissor_state
*state
)
379 util_dump_null(stream
);
383 util_dump_struct_begin(stream
, "pipe_scissor_state");
385 util_dump_member(stream
, uint
, state
, minx
);
386 util_dump_member(stream
, uint
, state
, miny
);
387 util_dump_member(stream
, uint
, state
, maxx
);
388 util_dump_member(stream
, uint
, state
, maxy
);
390 util_dump_struct_end(stream
);
395 util_dump_clip_state(struct os_stream
*stream
, const struct pipe_clip_state
*state
)
400 util_dump_null(stream
);
404 util_dump_struct_begin(stream
, "pipe_clip_state");
406 util_dump_member_begin(stream
, "ucp");
407 util_dump_array_begin(stream
);
408 for(i
= 0; i
< PIPE_MAX_CLIP_PLANES
; ++i
) {
409 util_dump_elem_begin(stream
);
410 util_dump_array(stream
, float, state
->ucp
[i
], 4);
411 util_dump_elem_end(stream
);
413 util_dump_array_end(stream
);
414 util_dump_member_end(stream
);
416 util_dump_member(stream
, uint
, state
, nr
);
418 util_dump_struct_end(stream
);
423 util_dump_shader_state(struct os_stream
*stream
, const struct pipe_shader_state
*state
)
428 util_dump_null(stream
);
432 tgsi_dump_str(state
->tokens
, 0, str
, sizeof(str
));
434 util_dump_struct_begin(stream
, "pipe_shader_state");
436 util_dump_member_begin(stream
, "tokens");
437 util_dump_string(stream
, str
);
438 util_dump_member_end(stream
);
440 util_dump_struct_end(stream
);
445 util_dump_depth_stencil_alpha_state(struct os_stream
*stream
, const struct pipe_depth_stencil_alpha_state
*state
)
450 util_dump_null(stream
);
454 util_dump_struct_begin(stream
, "pipe_depth_stencil_alpha_state");
456 util_dump_member_begin(stream
, "depth");
457 util_dump_struct_begin(stream
, "pipe_depth_state");
458 util_dump_member(stream
, bool, &state
->depth
, enabled
);
459 if (state
->depth
.enabled
) {
460 util_dump_member(stream
, bool, &state
->depth
, writemask
);
461 util_dump_member(stream
, enum_func
, &state
->depth
, func
);
463 util_dump_struct_end(stream
);
464 util_dump_member_end(stream
);
466 util_dump_member_begin(stream
, "stencil");
467 util_dump_array_begin(stream
);
468 for(i
= 0; i
< Elements(state
->stencil
); ++i
) {
469 util_dump_elem_begin(stream
);
470 util_dump_struct_begin(stream
, "pipe_stencil_state");
471 util_dump_member(stream
, bool, &state
->stencil
[i
], enabled
);
472 if (state
->stencil
[i
].enabled
) {
473 util_dump_member(stream
, enum_func
, &state
->stencil
[i
], func
);
474 util_dump_member(stream
, uint
, &state
->stencil
[i
], fail_op
);
475 util_dump_member(stream
, uint
, &state
->stencil
[i
], zpass_op
);
476 util_dump_member(stream
, uint
, &state
->stencil
[i
], zfail_op
);
477 util_dump_member(stream
, uint
, &state
->stencil
[i
], valuemask
);
478 util_dump_member(stream
, uint
, &state
->stencil
[i
], writemask
);
480 util_dump_struct_end(stream
);
481 util_dump_elem_end(stream
);
483 util_dump_array_end(stream
);
484 util_dump_member_end(stream
);
486 util_dump_member_begin(stream
, "alpha");
487 util_dump_struct_begin(stream
, "pipe_alpha_state");
488 util_dump_member(stream
, bool, &state
->alpha
, enabled
);
489 if (state
->alpha
.enabled
) {
490 util_dump_member(stream
, enum_func
, &state
->alpha
, func
);
491 util_dump_member(stream
, float, &state
->alpha
, ref_value
);
493 util_dump_struct_end(stream
);
494 util_dump_member_end(stream
);
496 util_dump_struct_end(stream
);
500 util_dump_rt_blend_state(struct os_stream
*stream
, const struct pipe_rt_blend_state
*state
)
502 util_dump_struct_begin(stream
, "pipe_rt_blend_state");
504 util_dump_member(stream
, uint
, state
, blend_enable
);
505 if (state
->blend_enable
) {
506 util_dump_member(stream
, enum_blend_func
, state
, rgb_func
);
507 util_dump_member(stream
, enum_blend_factor
, state
, rgb_src_factor
);
508 util_dump_member(stream
, enum_blend_factor
, state
, rgb_dst_factor
);
510 util_dump_member(stream
, enum_blend_func
, state
, alpha_func
);
511 util_dump_member(stream
, enum_blend_factor
, state
, alpha_src_factor
);
512 util_dump_member(stream
, enum_blend_factor
, state
, alpha_dst_factor
);
515 util_dump_member(stream
, uint
, state
, colormask
);
517 util_dump_struct_end(stream
);
521 util_dump_blend_state(struct os_stream
*stream
, const struct pipe_blend_state
*state
)
523 unsigned valid_entries
= 1;
526 util_dump_null(stream
);
530 util_dump_struct_begin(stream
, "pipe_blend_state");
532 util_dump_member(stream
, bool, state
, dither
);
534 util_dump_member(stream
, bool, state
, logicop_enable
);
535 if (state
->logicop_enable
) {
536 util_dump_member(stream
, enum_func
, state
, logicop_func
);
539 util_dump_member(stream
, bool, state
, independent_blend_enable
);
541 util_dump_member_begin(stream
, "rt");
542 if (state
->independent_blend_enable
)
543 valid_entries
= PIPE_MAX_COLOR_BUFS
;
544 util_dump_struct_array(stream
, rt_blend_state
, state
->rt
, valid_entries
);
545 util_dump_member_end(stream
);
548 util_dump_struct_end(stream
);
553 util_dump_blend_color(struct os_stream
*stream
, const struct pipe_blend_color
*state
)
556 util_dump_null(stream
);
560 util_dump_struct_begin(stream
, "pipe_blend_color");
562 util_dump_member_array(stream
, float, state
, color
);
564 util_dump_struct_end(stream
);
568 util_dump_stencil_ref(struct os_stream
*stream
, const struct pipe_stencil_ref
*state
)
571 util_dump_null(stream
);
575 util_dump_struct_begin(stream
, "pipe_stencil_ref");
577 util_dump_member_array(stream
, uint
, state
, ref_value
);
579 util_dump_struct_end(stream
);
583 util_dump_framebuffer_state(struct os_stream
*stream
, const struct pipe_framebuffer_state
*state
)
585 util_dump_struct_begin(stream
, "pipe_framebuffer_state");
587 util_dump_member(stream
, uint
, state
, width
);
588 util_dump_member(stream
, uint
, state
, height
);
589 util_dump_member(stream
, uint
, state
, nr_cbufs
);
590 util_dump_member_array(stream
, ptr
, state
, cbufs
);
591 util_dump_member(stream
, ptr
, state
, zsbuf
);
593 util_dump_struct_end(stream
);
598 util_dump_sampler_state(struct os_stream
*stream
, const struct pipe_sampler_state
*state
)
601 util_dump_null(stream
);
605 util_dump_struct_begin(stream
, "pipe_sampler_state");
607 util_dump_member(stream
, uint
, state
, wrap_s
);
608 util_dump_member(stream
, uint
, state
, wrap_t
);
609 util_dump_member(stream
, uint
, state
, wrap_r
);
610 util_dump_member(stream
, uint
, state
, min_img_filter
);
611 util_dump_member(stream
, uint
, state
, min_mip_filter
);
612 util_dump_member(stream
, uint
, state
, mag_img_filter
);
613 util_dump_member(stream
, uint
, state
, compare_mode
);
614 util_dump_member(stream
, enum_func
, state
, compare_func
);
615 util_dump_member(stream
, bool, state
, normalized_coords
);
616 util_dump_member(stream
, uint
, state
, max_anisotropy
);
617 util_dump_member(stream
, float, state
, lod_bias
);
618 util_dump_member(stream
, float, state
, min_lod
);
619 util_dump_member(stream
, float, state
, max_lod
);
620 util_dump_member_array(stream
, float, state
, border_color
);
622 util_dump_struct_end(stream
);
627 util_dump_surface(struct os_stream
*stream
, const struct pipe_surface
*state
)
630 util_dump_null(stream
);
634 util_dump_struct_begin(stream
, "pipe_surface");
636 util_dump_member(stream
, format
, state
, format
);
637 util_dump_member(stream
, uint
, state
, width
);
638 util_dump_member(stream
, uint
, state
, height
);
640 util_dump_member(stream
, uint
, state
, usage
);
642 util_dump_member(stream
, ptr
, state
, texture
);
643 util_dump_member(stream
, uint
, state
, u
.tex
.level
);
644 util_dump_member(stream
, uint
, state
, u
.tex
.first_layer
);
645 util_dump_member(stream
, uint
, state
, u
.tex
.last_layer
);
647 util_dump_struct_end(stream
);
652 util_dump_transfer(struct os_stream
*stream
, const struct pipe_transfer
*state
)
655 util_dump_null(stream
);
659 util_dump_struct_begin(stream
, "pipe_transfer");
661 util_dump_member(stream
, ptr
, state
, resource
);
662 /*util_dump_member(stream, uint, state, box);*/
664 util_dump_member(stream
, uint
, state
, stride
);
665 util_dump_member(stream
, uint
, state
, layer_stride
);
667 /*util_dump_member(stream, ptr, state, data);*/
669 util_dump_struct_end(stream
);
674 util_dump_vertex_buffer(struct os_stream
*stream
, const struct pipe_vertex_buffer
*state
)
677 util_dump_null(stream
);
681 util_dump_struct_begin(stream
, "pipe_vertex_buffer");
683 util_dump_member(stream
, uint
, state
, stride
);
684 util_dump_member(stream
, uint
, state
, buffer_offset
);
685 util_dump_member(stream
, ptr
, state
, buffer
);
687 util_dump_struct_end(stream
);
692 util_dump_vertex_element(struct os_stream
*stream
, const struct pipe_vertex_element
*state
)
695 util_dump_null(stream
);
699 util_dump_struct_begin(stream
, "pipe_vertex_element");
701 util_dump_member(stream
, uint
, state
, src_offset
);
703 util_dump_member(stream
, uint
, state
, vertex_buffer_index
);
705 util_dump_member(stream
, format
, state
, src_format
);
707 util_dump_struct_end(stream
);