revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / gallium / auxiliary / util / u_dump_state.c
blob5ecf8cbb0674cc8ac598a2dcc0fce30c3057c1f4
1 /**************************************************************************
3 * Copyright 2008-2010 VMware, Inc.
4 * All Rights Reserved.
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
16 * of the Software.
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"
36 #include "u_dump.h"
40 * Dump primitives
43 static INLINE void
44 util_stream_writef(struct os_stream *stream, const char *format, ...)
46 static char buf[1024];
47 unsigned len;
48 va_list ap;
49 va_start(ap, format);
50 len = util_vsnprintf(buf, sizeof(buf), format, ap);
51 va_end(ap);
52 os_stream_write(stream, buf, len);
55 static void
56 util_dump_bool(struct os_stream *stream, int value)
58 util_stream_writef(stream, "%c", value ? '1' : '0');
61 static void
62 util_dump_int(struct os_stream *stream, long long int value)
64 util_stream_writef(stream, "%lli", value);
67 static void
68 util_dump_uint(struct os_stream *stream, long long unsigned value)
70 util_stream_writef(stream, "%llu", value);
73 static void
74 util_dump_float(struct os_stream *stream, double value)
76 util_stream_writef(stream, "%g", value);
79 static void
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, "\"");
87 static void
88 util_dump_enum(struct os_stream *stream, const char *value)
90 os_stream_write_str(stream, value);
93 static void
94 util_dump_array_begin(struct os_stream *stream)
96 os_stream_write_str(stream, "{");
99 static void
100 util_dump_array_end(struct os_stream *stream)
102 os_stream_write_str(stream, "}");
105 static void
106 util_dump_elem_begin(struct os_stream *stream)
110 static void
111 util_dump_elem_end(struct os_stream *stream)
113 os_stream_write_str(stream, ", ");
116 static void
117 util_dump_struct_begin(struct os_stream *stream, const char *name)
119 os_stream_write_str(stream, "{");
122 static void
123 util_dump_struct_end(struct os_stream *stream)
125 os_stream_write_str(stream, "}");
128 static void
129 util_dump_member_begin(struct os_stream *stream, const char *name)
131 util_stream_writef(stream, "%s = ", name);
134 static void
135 util_dump_member_end(struct os_stream *stream)
137 os_stream_write_str(stream, ", ");
140 static void
141 util_dump_null(struct os_stream *stream)
143 os_stream_write_str(stream, "NULL");
146 static void
147 util_dump_ptr(struct os_stream *stream, const void *value)
149 if(value)
150 util_stream_writef(stream, "0x%08lx", (unsigned long)(uintptr_t)value);
151 else
152 util_dump_null(stream);
157 * Code saving macros.
160 #define util_dump_arg(_stream, _type, _arg) \
161 do { \
162 util_dump_arg_begin(_stream, #_arg); \
163 util_dump_##_type(_stream, _arg); \
164 util_dump_arg_end(_stream); \
165 } while(0)
167 #define util_dump_ret(_stream, _type, _arg) \
168 do { \
169 util_dump_ret_begin(_stream); \
170 util_dump_##_type(_stream, _arg); \
171 util_dump_ret_end(_stream); \
172 } while(0)
174 #define util_dump_array(_stream, _type, _obj, _size) \
175 do { \
176 size_t idx; \
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); \
184 } while(0)
186 #define util_dump_struct_array(_stream, _type, _obj, _size) \
187 do { \
188 size_t idx; \
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); \
196 } while(0)
198 #define util_dump_member(_stream, _type, _obj, _member) \
199 do { \
200 util_dump_member_begin(_stream, #_member); \
201 util_dump_##_type(_stream, (_obj)->_member); \
202 util_dump_member_end(_stream); \
203 } while(0)
205 #define util_dump_arg_array(_stream, _type, _arg, _size) \
206 do { \
207 util_dump_arg_begin(_stream, #_arg); \
208 util_dump_array(_stream, _type, _arg, _size); \
209 util_dump_arg_end(_stream); \
210 } while(0)
212 #define util_dump_member_array(_stream, _type, _obj, _member) \
213 do { \
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); \
217 } while(0)
222 * Wrappers for enum -> string dumpers.
226 static void
227 util_dump_format(struct os_stream *stream, enum pipe_format format)
229 util_dump_enum(stream, util_format_name(format));
233 static void
234 util_dump_enum_blend_factor(struct os_stream *stream, unsigned value)
236 util_dump_enum(stream, util_dump_blend_factor(value, TRUE));
239 static void
240 util_dump_enum_blend_func(struct os_stream *stream, unsigned value)
242 util_dump_enum(stream, util_dump_blend_func(value, TRUE));
245 static void
246 util_dump_enum_func(struct os_stream *stream, unsigned value)
248 util_dump_enum(stream, util_dump_func(value, TRUE));
253 * Public functions
257 void
258 util_dump_template(struct os_stream *stream, const struct pipe_resource *templat)
260 if(!templat) {
261 util_dump_null(stream);
262 return;
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);
295 void
296 util_dump_rasterizer_state(struct os_stream *stream, const struct pipe_rasterizer_state *state)
298 if(!state) {
299 util_dump_null(stream);
300 return;
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);
340 void
341 util_dump_poly_stipple(struct os_stream *stream, const struct pipe_poly_stipple *state)
343 if(!state) {
344 util_dump_null(stream);
345 return;
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);
358 void
359 util_dump_viewport_state(struct os_stream *stream, const struct pipe_viewport_state *state)
361 if(!state) {
362 util_dump_null(stream);
363 return;
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);
375 void
376 util_dump_scissor_state(struct os_stream *stream, const struct pipe_scissor_state *state)
378 if(!state) {
379 util_dump_null(stream);
380 return;
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);
394 void
395 util_dump_clip_state(struct os_stream *stream, const struct pipe_clip_state *state)
397 unsigned i;
399 if(!state) {
400 util_dump_null(stream);
401 return;
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);
422 void
423 util_dump_shader_state(struct os_stream *stream, const struct pipe_shader_state *state)
425 char str[8192];
427 if(!state) {
428 util_dump_null(stream);
429 return;
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);
444 void
445 util_dump_depth_stencil_alpha_state(struct os_stream *stream, const struct pipe_depth_stencil_alpha_state *state)
447 unsigned i;
449 if(!state) {
450 util_dump_null(stream);
451 return;
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);
499 void
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);
520 void
521 util_dump_blend_state(struct os_stream *stream, const struct pipe_blend_state *state)
523 unsigned valid_entries = 1;
525 if(!state) {
526 util_dump_null(stream);
527 return;
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);
538 else {
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);
552 void
553 util_dump_blend_color(struct os_stream *stream, const struct pipe_blend_color *state)
555 if(!state) {
556 util_dump_null(stream);
557 return;
560 util_dump_struct_begin(stream, "pipe_blend_color");
562 util_dump_member_array(stream, float, state, color);
564 util_dump_struct_end(stream);
567 void
568 util_dump_stencil_ref(struct os_stream *stream, const struct pipe_stencil_ref *state)
570 if(!state) {
571 util_dump_null(stream);
572 return;
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);
582 void
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);
597 void
598 util_dump_sampler_state(struct os_stream *stream, const struct pipe_sampler_state *state)
600 if(!state) {
601 util_dump_null(stream);
602 return;
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);
626 void
627 util_dump_surface(struct os_stream *stream, const struct pipe_surface *state)
629 if(!state) {
630 util_dump_null(stream);
631 return;
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);
651 void
652 util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state)
654 if(!state) {
655 util_dump_null(stream);
656 return;
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);
673 void
674 util_dump_vertex_buffer(struct os_stream *stream, const struct pipe_vertex_buffer *state)
676 if(!state) {
677 util_dump_null(stream);
678 return;
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);
691 void
692 util_dump_vertex_element(struct os_stream *stream, const struct pipe_vertex_element *state)
694 if(!state) {
695 util_dump_null(stream);
696 return;
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);