• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2008-2010 VMware, Inc.
4  * All Rights Reserved.
5  *
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:
13  *
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.
17  *
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.
25  *
26  **************************************************************************/
27 
28 
29 #include "pipe/p_compiler.h"
30 #include "util/u_memory.h"
31 #include "util/u_string.h"
32 #include "util/u_format.h"
33 #include "tgsi/tgsi_dump.h"
34 
35 #include "u_dump.h"
36 
37 
38 /*
39  * Dump primitives
40  */
41 
42 static inline void
util_stream_writef(FILE * stream,const char * format,...)43 util_stream_writef(FILE *stream, const char *format, ...)
44 {
45    static char buf[1024];
46    unsigned len;
47    va_list ap;
48    va_start(ap, format);
49    len = util_vsnprintf(buf, sizeof(buf), format, ap);
50    va_end(ap);
51    fwrite(buf, len, 1, stream);
52 }
53 
54 static void
util_dump_bool(FILE * stream,int value)55 util_dump_bool(FILE *stream, int value)
56 {
57    util_stream_writef(stream, "%c", value ? '1' : '0');
58 }
59 
60 static void
util_dump_int(FILE * stream,long long int value)61 util_dump_int(FILE *stream, long long int value)
62 {
63    util_stream_writef(stream, "%lli", value);
64 }
65 
66 static void
util_dump_uint(FILE * stream,long long unsigned value)67 util_dump_uint(FILE *stream, long long unsigned value)
68 {
69    util_stream_writef(stream, "%llu", value);
70 }
71 
72 static void
util_dump_float(FILE * stream,double value)73 util_dump_float(FILE *stream, double value)
74 {
75    util_stream_writef(stream, "%g", value);
76 }
77 
78 static void
util_dump_string(FILE * stream,const char * str)79 util_dump_string(FILE *stream, const char *str)
80 {
81    fputs("\"", stream);
82    fputs(str, stream);
83    fputs("\"", stream);
84 }
85 
86 static void
util_dump_enum(FILE * stream,const char * value)87 util_dump_enum(FILE *stream, const char *value)
88 {
89    fputs(value, stream);
90 }
91 
92 static void
util_dump_array_begin(FILE * stream)93 util_dump_array_begin(FILE *stream)
94 {
95    fputs("{", stream);
96 }
97 
98 static void
util_dump_array_end(FILE * stream)99 util_dump_array_end(FILE *stream)
100 {
101    fputs("}", stream);
102 }
103 
104 static void
util_dump_elem_begin(FILE * stream)105 util_dump_elem_begin(FILE *stream)
106 {
107 }
108 
109 static void
util_dump_elem_end(FILE * stream)110 util_dump_elem_end(FILE *stream)
111 {
112    fputs(", ", stream);
113 }
114 
115 static void
util_dump_struct_begin(FILE * stream,const char * name)116 util_dump_struct_begin(FILE *stream, const char *name)
117 {
118    fputs("{", stream);
119 }
120 
121 static void
util_dump_struct_end(FILE * stream)122 util_dump_struct_end(FILE *stream)
123 {
124    fputs("}", stream);
125 }
126 
127 static void
util_dump_member_begin(FILE * stream,const char * name)128 util_dump_member_begin(FILE *stream, const char *name)
129 {
130    util_stream_writef(stream, "%s = ", name);
131 }
132 
133 static void
util_dump_member_end(FILE * stream)134 util_dump_member_end(FILE *stream)
135 {
136    fputs(", ", stream);
137 }
138 
139 static void
util_dump_null(FILE * stream)140 util_dump_null(FILE *stream)
141 {
142    fputs("NULL", stream);
143 }
144 
145 static void
util_dump_ptr(FILE * stream,const void * value)146 util_dump_ptr(FILE *stream, const void *value)
147 {
148    if(value)
149       util_stream_writef(stream, "0x%08lx", (unsigned long)(uintptr_t)value);
150    else
151       util_dump_null(stream);
152 }
153 
154 
155 /*
156  * Code saving macros.
157  */
158 
159 #define util_dump_arg(_stream, _type, _arg) \
160    do { \
161       util_dump_arg_begin(_stream, #_arg); \
162       util_dump_##_type(_stream, _arg); \
163       util_dump_arg_end(_stream); \
164    } while(0)
165 
166 #define util_dump_ret(_stream, _type, _arg) \
167    do { \
168       util_dump_ret_begin(_stream); \
169       util_dump_##_type(_stream, _arg); \
170       util_dump_ret_end(_stream); \
171    } while(0)
172 
173 #define util_dump_array(_stream, _type, _obj, _size) \
174    do { \
175       size_t idx; \
176       util_dump_array_begin(_stream); \
177       for(idx = 0; idx < (_size); ++idx) { \
178          util_dump_elem_begin(_stream); \
179          util_dump_##_type(_stream, (_obj)[idx]); \
180          util_dump_elem_end(_stream); \
181       } \
182       util_dump_array_end(_stream); \
183    } while(0)
184 
185 #define util_dump_struct_array(_stream, _type, _obj, _size) \
186    do { \
187       size_t idx; \
188       util_dump_array_begin(_stream); \
189       for(idx = 0; idx < (_size); ++idx) { \
190          util_dump_elem_begin(_stream); \
191          util_dump_##_type(_stream, &(_obj)[idx]); \
192          util_dump_elem_end(_stream); \
193       } \
194       util_dump_array_end(_stream); \
195    } while(0)
196 
197 #define util_dump_member(_stream, _type, _obj, _member) \
198    do { \
199       util_dump_member_begin(_stream, #_member); \
200       util_dump_##_type(_stream, (_obj)->_member); \
201       util_dump_member_end(_stream); \
202    } while(0)
203 
204 #define util_dump_arg_array(_stream, _type, _arg, _size) \
205    do { \
206       util_dump_arg_begin(_stream, #_arg); \
207       util_dump_array(_stream, _type, _arg, _size); \
208       util_dump_arg_end(_stream); \
209    } while(0)
210 
211 #define util_dump_member_array(_stream, _type, _obj, _member) \
212    do { \
213       util_dump_member_begin(_stream, #_member); \
214       util_dump_array(_stream, _type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \
215       util_dump_member_end(_stream); \
216    } while(0)
217 
218 
219 
220 /*
221  * Wrappers for enum -> string dumpers.
222  */
223 
224 
225 static void
util_dump_format(FILE * stream,enum pipe_format format)226 util_dump_format(FILE *stream, enum pipe_format format)
227 {
228    util_dump_enum(stream, util_format_name(format));
229 }
230 
231 
232 static void
util_dump_enum_blend_factor(FILE * stream,unsigned value)233 util_dump_enum_blend_factor(FILE *stream, unsigned value)
234 {
235    util_dump_enum(stream, util_dump_blend_factor(value, TRUE));
236 }
237 
238 static void
util_dump_enum_blend_func(FILE * stream,unsigned value)239 util_dump_enum_blend_func(FILE *stream, unsigned value)
240 {
241    util_dump_enum(stream, util_dump_blend_func(value, TRUE));
242 }
243 
244 static void
util_dump_enum_func(FILE * stream,unsigned value)245 util_dump_enum_func(FILE *stream, unsigned value)
246 {
247    util_dump_enum(stream, util_dump_func(value, TRUE));
248 }
249 
250 static void
util_dump_enum_prim_mode(FILE * stream,unsigned value)251 util_dump_enum_prim_mode(FILE *stream, unsigned value)
252 {
253    util_dump_enum(stream, util_dump_prim_mode(value, TRUE));
254 }
255 
256 static void
util_dump_enum_tex_target(FILE * stream,unsigned value)257 util_dump_enum_tex_target(FILE *stream, unsigned value)
258 {
259    util_dump_enum(stream, util_dump_tex_target(value, TRUE));
260 }
261 
262 static void
util_dump_enum_tex_filter(FILE * stream,unsigned value)263 util_dump_enum_tex_filter(FILE *stream, unsigned value)
264 {
265    util_dump_enum(stream, util_dump_tex_filter(value, TRUE));
266 }
267 
268 static void
util_dump_enum_tex_mipfilter(FILE * stream,unsigned value)269 util_dump_enum_tex_mipfilter(FILE *stream, unsigned value)
270 {
271    util_dump_enum(stream, util_dump_tex_mipfilter(value, TRUE));
272 }
273 
274 static void
util_dump_enum_tex_wrap(FILE * stream,unsigned value)275 util_dump_enum_tex_wrap(FILE *stream, unsigned value)
276 {
277    util_dump_enum(stream, util_dump_tex_wrap(value, TRUE));
278 }
279 
280 static void
util_dump_enum_stencil_op(FILE * stream,unsigned value)281 util_dump_enum_stencil_op(FILE *stream, unsigned value)
282 {
283    util_dump_enum(stream, util_dump_stencil_op(value, TRUE));
284 }
285 
286 
287 /*
288  * Public functions
289  */
290 
291 
292 void
util_dump_resource(FILE * stream,const struct pipe_resource * state)293 util_dump_resource(FILE *stream, const struct pipe_resource *state)
294 {
295    if (!state) {
296       util_dump_null(stream);
297       return;
298    }
299 
300    util_dump_struct_begin(stream, "pipe_resource");
301 
302    util_dump_member(stream, enum_tex_target, state, target);
303    util_dump_member(stream, format, state, format);
304 
305    util_dump_member(stream, uint, state, width0);
306    util_dump_member(stream, uint, state, height0);
307    util_dump_member(stream, uint, state, depth0);
308    util_dump_member(stream, uint, state, array_size);
309 
310    util_dump_member(stream, uint, state, last_level);
311    util_dump_member(stream, uint, state, nr_samples);
312    util_dump_member(stream, uint, state, usage);
313    util_dump_member(stream, uint, state, bind);
314    util_dump_member(stream, uint, state, flags);
315 
316    util_dump_struct_end(stream);
317 }
318 
319 
320 void
util_dump_rasterizer_state(FILE * stream,const struct pipe_rasterizer_state * state)321 util_dump_rasterizer_state(FILE *stream, const struct pipe_rasterizer_state *state)
322 {
323    if (!state) {
324       util_dump_null(stream);
325       return;
326    }
327 
328    util_dump_struct_begin(stream, "pipe_rasterizer_state");
329 
330    util_dump_member(stream, bool, state, flatshade);
331    util_dump_member(stream, bool, state, light_twoside);
332    util_dump_member(stream, bool, state, clamp_vertex_color);
333    util_dump_member(stream, bool, state, clamp_fragment_color);
334    util_dump_member(stream, uint, state, front_ccw);
335    util_dump_member(stream, uint, state, cull_face);
336    util_dump_member(stream, uint, state, fill_front);
337    util_dump_member(stream, uint, state, fill_back);
338    util_dump_member(stream, bool, state, offset_point);
339    util_dump_member(stream, bool, state, offset_line);
340    util_dump_member(stream, bool, state, offset_tri);
341    util_dump_member(stream, bool, state, scissor);
342    util_dump_member(stream, bool, state, poly_smooth);
343    util_dump_member(stream, bool, state, poly_stipple_enable);
344    util_dump_member(stream, bool, state, point_smooth);
345    util_dump_member(stream, uint, state, sprite_coord_enable);
346    util_dump_member(stream, bool, state, sprite_coord_mode);
347    util_dump_member(stream, bool, state, point_quad_rasterization);
348    util_dump_member(stream, bool, state, point_tri_clip);
349    util_dump_member(stream, bool, state, point_size_per_vertex);
350    util_dump_member(stream, bool, state, multisample);
351    util_dump_member(stream, bool, state, line_smooth);
352    util_dump_member(stream, bool, state, line_stipple_enable);
353    util_dump_member(stream, uint, state, line_stipple_factor);
354    util_dump_member(stream, uint, state, line_stipple_pattern);
355    util_dump_member(stream, bool, state, line_last_pixel);
356    util_dump_member(stream, bool, state, flatshade_first);
357    util_dump_member(stream, bool, state, half_pixel_center);
358    util_dump_member(stream, bool, state, bottom_edge_rule);
359    util_dump_member(stream, bool, state, rasterizer_discard);
360    util_dump_member(stream, bool, state, depth_clip);
361    util_dump_member(stream, bool, state, clip_halfz);
362    util_dump_member(stream, uint, state, clip_plane_enable);
363 
364    util_dump_member(stream, float, state, line_width);
365    util_dump_member(stream, float, state, point_size);
366    util_dump_member(stream, float, state, offset_units);
367    util_dump_member(stream, float, state, offset_scale);
368    util_dump_member(stream, float, state, offset_clamp);
369 
370    util_dump_struct_end(stream);
371 }
372 
373 
374 void
util_dump_poly_stipple(FILE * stream,const struct pipe_poly_stipple * state)375 util_dump_poly_stipple(FILE *stream, const struct pipe_poly_stipple *state)
376 {
377    if (!state) {
378       util_dump_null(stream);
379       return;
380    }
381 
382    util_dump_struct_begin(stream, "pipe_poly_stipple");
383 
384    util_dump_member_begin(stream, "stipple");
385    util_dump_member_array(stream, uint, state, stipple);
386    util_dump_member_end(stream);
387 
388    util_dump_struct_end(stream);
389 }
390 
391 
392 void
util_dump_viewport_state(FILE * stream,const struct pipe_viewport_state * state)393 util_dump_viewport_state(FILE *stream, const struct pipe_viewport_state *state)
394 {
395    if (!state) {
396       util_dump_null(stream);
397       return;
398    }
399 
400    util_dump_struct_begin(stream, "pipe_viewport_state");
401 
402    util_dump_member_array(stream, float, state, scale);
403    util_dump_member_array(stream, float, state, translate);
404 
405    util_dump_struct_end(stream);
406 }
407 
408 
409 void
util_dump_scissor_state(FILE * stream,const struct pipe_scissor_state * state)410 util_dump_scissor_state(FILE *stream, const struct pipe_scissor_state *state)
411 {
412    if (!state) {
413       util_dump_null(stream);
414       return;
415    }
416 
417    util_dump_struct_begin(stream, "pipe_scissor_state");
418 
419    util_dump_member(stream, uint, state, minx);
420    util_dump_member(stream, uint, state, miny);
421    util_dump_member(stream, uint, state, maxx);
422    util_dump_member(stream, uint, state, maxy);
423 
424    util_dump_struct_end(stream);
425 }
426 
427 
428 void
util_dump_clip_state(FILE * stream,const struct pipe_clip_state * state)429 util_dump_clip_state(FILE *stream, const struct pipe_clip_state *state)
430 {
431    unsigned i;
432 
433    if (!state) {
434       util_dump_null(stream);
435       return;
436    }
437 
438    util_dump_struct_begin(stream, "pipe_clip_state");
439 
440    util_dump_member_begin(stream, "ucp");
441    util_dump_array_begin(stream);
442    for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) {
443       util_dump_elem_begin(stream);
444       util_dump_array(stream, float, state->ucp[i], 4);
445       util_dump_elem_end(stream);
446    }
447    util_dump_array_end(stream);
448    util_dump_member_end(stream);
449 
450    util_dump_struct_end(stream);
451 }
452 
453 
454 void
util_dump_shader_state(FILE * stream,const struct pipe_shader_state * state)455 util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
456 {
457    unsigned i;
458 
459    if (!state) {
460       util_dump_null(stream);
461       return;
462    }
463 
464    util_dump_struct_begin(stream, "pipe_shader_state");
465 
466    util_dump_member_begin(stream, "tokens");
467    fprintf(stream, "\"\n");
468    tgsi_dump_to_file(state->tokens, 0, stream);
469    fprintf(stream, "\"");
470    util_dump_member_end(stream);
471 
472    if (state->stream_output.num_outputs) {
473       util_dump_member_begin(stream, "stream_output");
474       util_dump_struct_begin(stream, "pipe_stream_output_info");
475       util_dump_member(stream, uint, &state->stream_output, num_outputs);
476       util_dump_array(stream, uint, state->stream_output.stride,
477                       ARRAY_SIZE(state->stream_output.stride));
478       util_dump_array_begin(stream);
479       for(i = 0; i < state->stream_output.num_outputs; ++i) {
480          util_dump_elem_begin(stream);
481          util_dump_struct_begin(stream, ""); /* anonymous */
482          util_dump_member(stream, uint, &state->stream_output.output[i], register_index);
483          util_dump_member(stream, uint, &state->stream_output.output[i], start_component);
484          util_dump_member(stream, uint, &state->stream_output.output[i], num_components);
485          util_dump_member(stream, uint, &state->stream_output.output[i], output_buffer);
486          util_dump_struct_end(stream);
487          util_dump_elem_end(stream);
488       }
489       util_dump_array_end(stream);
490       util_dump_struct_end(stream);
491       util_dump_member_end(stream);
492    }
493 
494    util_dump_struct_end(stream);
495 }
496 
497 
498 void
util_dump_depth_stencil_alpha_state(FILE * stream,const struct pipe_depth_stencil_alpha_state * state)499 util_dump_depth_stencil_alpha_state(FILE *stream, const struct pipe_depth_stencil_alpha_state *state)
500 {
501    unsigned i;
502 
503    if (!state) {
504       util_dump_null(stream);
505       return;
506    }
507 
508    util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");
509 
510    util_dump_member_begin(stream, "depth");
511    util_dump_struct_begin(stream, "pipe_depth_state");
512    util_dump_member(stream, bool, &state->depth, enabled);
513    if (state->depth.enabled) {
514       util_dump_member(stream, bool, &state->depth, writemask);
515       util_dump_member(stream, enum_func, &state->depth, func);
516    }
517    util_dump_struct_end(stream);
518    util_dump_member_end(stream);
519 
520    util_dump_member_begin(stream, "stencil");
521    util_dump_array_begin(stream);
522    for(i = 0; i < ARRAY_SIZE(state->stencil); ++i) {
523       util_dump_elem_begin(stream);
524       util_dump_struct_begin(stream, "pipe_stencil_state");
525       util_dump_member(stream, bool, &state->stencil[i], enabled);
526       if (state->stencil[i].enabled) {
527          util_dump_member(stream, enum_func, &state->stencil[i], func);
528          util_dump_member(stream, enum_stencil_op,
529                           &state->stencil[i], fail_op);
530          util_dump_member(stream, enum_stencil_op,
531                           &state->stencil[i], zpass_op);
532          util_dump_member(stream, enum_stencil_op,
533                           &state->stencil[i], zfail_op);
534          util_dump_member(stream, uint, &state->stencil[i], valuemask);
535          util_dump_member(stream, uint, &state->stencil[i], writemask);
536       }
537       util_dump_struct_end(stream);
538       util_dump_elem_end(stream);
539    }
540    util_dump_array_end(stream);
541    util_dump_member_end(stream);
542 
543    util_dump_member_begin(stream, "alpha");
544    util_dump_struct_begin(stream, "pipe_alpha_state");
545    util_dump_member(stream, bool, &state->alpha, enabled);
546    if (state->alpha.enabled) {
547       util_dump_member(stream, enum_func, &state->alpha, func);
548       util_dump_member(stream, float, &state->alpha, ref_value);
549    }
550    util_dump_struct_end(stream);
551    util_dump_member_end(stream);
552 
553    util_dump_struct_end(stream);
554 }
555 
556 void
util_dump_rt_blend_state(FILE * stream,const struct pipe_rt_blend_state * state)557 util_dump_rt_blend_state(FILE *stream, const struct pipe_rt_blend_state *state)
558 {
559    util_dump_struct_begin(stream, "pipe_rt_blend_state");
560 
561    util_dump_member(stream, uint, state, blend_enable);
562    if (state->blend_enable) {
563       util_dump_member(stream, enum_blend_func, state, rgb_func);
564       util_dump_member(stream, enum_blend_factor, state, rgb_src_factor);
565       util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor);
566 
567       util_dump_member(stream, enum_blend_func, state, alpha_func);
568       util_dump_member(stream, enum_blend_factor, state, alpha_src_factor);
569       util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor);
570    }
571 
572    util_dump_member(stream, uint, state, colormask);
573 
574    util_dump_struct_end(stream);
575 }
576 
577 void
util_dump_blend_state(FILE * stream,const struct pipe_blend_state * state)578 util_dump_blend_state(FILE *stream, const struct pipe_blend_state *state)
579 {
580    unsigned valid_entries = 1;
581 
582    if (!state) {
583       util_dump_null(stream);
584       return;
585    }
586 
587    util_dump_struct_begin(stream, "pipe_blend_state");
588 
589    util_dump_member(stream, bool, state, dither);
590    util_dump_member(stream, bool, state, alpha_to_coverage);
591    util_dump_member(stream, bool, state, alpha_to_one);
592 
593    util_dump_member(stream, bool, state, logicop_enable);
594    if (state->logicop_enable) {
595       util_dump_member(stream, enum_func, state, logicop_func);
596    }
597    else {
598       util_dump_member(stream, bool, state, independent_blend_enable);
599 
600       util_dump_member_begin(stream, "rt");
601       if (state->independent_blend_enable)
602          valid_entries = PIPE_MAX_COLOR_BUFS;
603       util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries);
604       util_dump_member_end(stream);
605    }
606 
607    util_dump_struct_end(stream);
608 }
609 
610 
611 void
util_dump_blend_color(FILE * stream,const struct pipe_blend_color * state)612 util_dump_blend_color(FILE *stream, const struct pipe_blend_color *state)
613 {
614    if (!state) {
615       util_dump_null(stream);
616       return;
617    }
618 
619    util_dump_struct_begin(stream, "pipe_blend_color");
620 
621    util_dump_member_array(stream, float, state, color);
622 
623    util_dump_struct_end(stream);
624 }
625 
626 void
util_dump_stencil_ref(FILE * stream,const struct pipe_stencil_ref * state)627 util_dump_stencil_ref(FILE *stream, const struct pipe_stencil_ref *state)
628 {
629    if (!state) {
630       util_dump_null(stream);
631       return;
632    }
633 
634    util_dump_struct_begin(stream, "pipe_stencil_ref");
635 
636    util_dump_member_array(stream, uint, state, ref_value);
637 
638    util_dump_struct_end(stream);
639 }
640 
641 void
util_dump_framebuffer_state(FILE * stream,const struct pipe_framebuffer_state * state)642 util_dump_framebuffer_state(FILE *stream, const struct pipe_framebuffer_state *state)
643 {
644    util_dump_struct_begin(stream, "pipe_framebuffer_state");
645 
646    util_dump_member(stream, uint, state, width);
647    util_dump_member(stream, uint, state, height);
648    util_dump_member(stream, uint, state, samples);
649    util_dump_member(stream, uint, state, layers);
650    util_dump_member(stream, uint, state, nr_cbufs);
651    util_dump_member_array(stream, ptr, state, cbufs);
652    util_dump_member(stream, ptr, state, zsbuf);
653 
654    util_dump_struct_end(stream);
655 }
656 
657 
658 void
util_dump_sampler_state(FILE * stream,const struct pipe_sampler_state * state)659 util_dump_sampler_state(FILE *stream, const struct pipe_sampler_state *state)
660 {
661    if (!state) {
662       util_dump_null(stream);
663       return;
664    }
665 
666    util_dump_struct_begin(stream, "pipe_sampler_state");
667 
668    util_dump_member(stream, enum_tex_wrap, state, wrap_s);
669    util_dump_member(stream, enum_tex_wrap, state, wrap_t);
670    util_dump_member(stream, enum_tex_wrap, state, wrap_r);
671    util_dump_member(stream, enum_tex_filter, state, min_img_filter);
672    util_dump_member(stream, enum_tex_mipfilter, state, min_mip_filter);
673    util_dump_member(stream, enum_tex_filter, state, mag_img_filter);
674    util_dump_member(stream, uint, state, compare_mode);
675    util_dump_member(stream, enum_func, state, compare_func);
676    util_dump_member(stream, bool, state, normalized_coords);
677    util_dump_member(stream, uint, state, max_anisotropy);
678    util_dump_member(stream, bool, state, seamless_cube_map);
679    util_dump_member(stream, float, state, lod_bias);
680    util_dump_member(stream, float, state, min_lod);
681    util_dump_member(stream, float, state, max_lod);
682    util_dump_member_array(stream, float, state, border_color.f);
683 
684    util_dump_struct_end(stream);
685 }
686 
687 
688 void
util_dump_surface(FILE * stream,const struct pipe_surface * state)689 util_dump_surface(FILE *stream, const struct pipe_surface *state)
690 {
691    if (!state) {
692       util_dump_null(stream);
693       return;
694    }
695 
696    util_dump_struct_begin(stream, "pipe_surface");
697 
698    util_dump_member(stream, format, state, format);
699    util_dump_member(stream, uint, state, width);
700    util_dump_member(stream, uint, state, height);
701 
702    util_dump_member(stream, ptr, state, texture);
703    util_dump_member(stream, uint, state, u.tex.level);
704    util_dump_member(stream, uint, state, u.tex.first_layer);
705    util_dump_member(stream, uint, state, u.tex.last_layer);
706 
707    util_dump_struct_end(stream);
708 }
709 
710 
711 void
util_dump_image_view(FILE * stream,const struct pipe_image_view * state)712 util_dump_image_view(FILE *stream, const struct pipe_image_view *state)
713 {
714    if (!state) {
715       util_dump_null(stream);
716       return;
717    }
718 
719    util_dump_struct_begin(stream, "pipe_image_view");
720 
721    util_dump_member(stream, ptr, state, resource);
722    util_dump_member(stream, format, state, format);
723 
724    if (state->resource->target == PIPE_BUFFER) {
725       util_dump_member(stream, uint, state, u.buf.offset);
726       util_dump_member(stream, uint, state, u.buf.size);
727    }
728    else {
729       util_dump_member(stream, uint, state, u.tex.first_layer);
730       util_dump_member(stream, uint, state, u.tex.last_layer);
731       util_dump_member(stream, uint, state, u.tex.level);
732    }
733 
734    util_dump_struct_end(stream);
735 }
736 
737 
738 void
util_dump_shader_buffer(FILE * stream,const struct pipe_shader_buffer * state)739 util_dump_shader_buffer(FILE *stream, const struct pipe_shader_buffer *state)
740 {
741    if (!state) {
742       util_dump_null(stream);
743       return;
744    }
745 
746    util_dump_struct_begin(stream, "pipe_shader_buffer");
747 
748    util_dump_member(stream, ptr, state, buffer);
749    util_dump_member(stream, uint, state, buffer_offset);
750    util_dump_member(stream, uint, state, buffer_size);
751 
752    util_dump_struct_end(stream);
753 
754 }
755 
756 
757 void
util_dump_sampler_view(FILE * stream,const struct pipe_sampler_view * state)758 util_dump_sampler_view(FILE *stream, const struct pipe_sampler_view *state)
759 {
760    if (!state) {
761       util_dump_null(stream);
762       return;
763    }
764 
765    util_dump_struct_begin(stream, "pipe_sampler_view");
766 
767    util_dump_member(stream, enum_tex_target, state, target);
768    util_dump_member(stream, format, state, format);
769    util_dump_member(stream, ptr, state, texture);
770 
771    if (state->target == PIPE_BUFFER) {
772       util_dump_member(stream, uint, state, u.buf.offset);
773       util_dump_member(stream, uint, state, u.buf.size);
774    }
775    else {
776       util_dump_member(stream, uint, state, u.tex.first_layer);
777       util_dump_member(stream, uint, state, u.tex.last_layer);
778       util_dump_member(stream, uint, state, u.tex.last_level);
779       util_dump_member(stream, uint, state, u.tex.last_level);
780    }
781 
782    util_dump_member(stream, uint, state, swizzle_r);
783    util_dump_member(stream, uint, state, swizzle_g);
784    util_dump_member(stream, uint, state, swizzle_b);
785    util_dump_member(stream, uint, state, swizzle_a);
786 
787    util_dump_struct_end(stream);
788 }
789 
790 
791 void
util_dump_transfer(FILE * stream,const struct pipe_transfer * state)792 util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
793 {
794    if (!state) {
795       util_dump_null(stream);
796       return;
797    }
798 
799    util_dump_struct_begin(stream, "pipe_transfer");
800 
801    util_dump_member(stream, ptr, state, resource);
802    util_dump_member(stream, uint, state, level);
803    util_dump_member(stream, uint, state, usage);
804    util_dump_member_begin(stream, "box");
805    util_dump_box(stream, &state->box);
806    util_dump_member_end(stream);
807    util_dump_member(stream, uint, state, stride);
808    util_dump_member(stream, uint, state, layer_stride);
809 
810    util_dump_struct_end(stream);
811 }
812 
813 
814 void
util_dump_constant_buffer(FILE * stream,const struct pipe_constant_buffer * state)815 util_dump_constant_buffer(FILE *stream,
816                           const struct pipe_constant_buffer *state)
817 {
818    if (!state) {
819       util_dump_null(stream);
820       return;
821    }
822 
823    util_dump_struct_begin(stream, "pipe_constant_buffer");
824 
825    util_dump_member(stream, ptr, state, buffer);
826    util_dump_member(stream, uint, state, buffer_offset);
827    util_dump_member(stream, uint, state, buffer_size);
828    util_dump_member(stream, ptr, state, user_buffer);
829 
830    util_dump_struct_end(stream);
831 }
832 
833 
834 void
util_dump_index_buffer(FILE * stream,const struct pipe_index_buffer * state)835 util_dump_index_buffer(FILE *stream, const struct pipe_index_buffer *state)
836 {
837    if (!state) {
838       util_dump_null(stream);
839       return;
840    }
841 
842    util_dump_struct_begin(stream, "pipe_index_buffer");
843 
844    util_dump_member(stream, uint, state, index_size);
845    util_dump_member(stream, uint, state, offset);
846    util_dump_member(stream, ptr, state, buffer);
847    util_dump_member(stream, ptr, state, user_buffer);
848 
849    util_dump_struct_end(stream);
850 }
851 
852 
853 void
util_dump_vertex_buffer(FILE * stream,const struct pipe_vertex_buffer * state)854 util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state)
855 {
856    if (!state) {
857       util_dump_null(stream);
858       return;
859    }
860 
861    util_dump_struct_begin(stream, "pipe_vertex_buffer");
862 
863    util_dump_member(stream, uint, state, stride);
864    util_dump_member(stream, uint, state, buffer_offset);
865    util_dump_member(stream, ptr, state, buffer);
866    util_dump_member(stream, ptr, state, user_buffer);
867 
868    util_dump_struct_end(stream);
869 }
870 
871 
872 void
util_dump_vertex_element(FILE * stream,const struct pipe_vertex_element * state)873 util_dump_vertex_element(FILE *stream, const struct pipe_vertex_element *state)
874 {
875    if (!state) {
876       util_dump_null(stream);
877       return;
878    }
879 
880    util_dump_struct_begin(stream, "pipe_vertex_element");
881 
882    util_dump_member(stream, uint, state, src_offset);
883    util_dump_member(stream, uint, state, instance_divisor);
884    util_dump_member(stream, uint, state, vertex_buffer_index);
885    util_dump_member(stream, format, state, src_format);
886 
887    util_dump_struct_end(stream);
888 }
889 
890 
891 void
util_dump_stream_output_target(FILE * stream,const struct pipe_stream_output_target * state)892 util_dump_stream_output_target(FILE *stream,
893                                const struct pipe_stream_output_target *state)
894 {
895    if (!state) {
896       util_dump_null(stream);
897       return;
898    }
899 
900    util_dump_struct_begin(stream, "pipe_stream_output_target");
901 
902    util_dump_member(stream, ptr, state, buffer);
903    util_dump_member(stream, uint, state, buffer_offset);
904    util_dump_member(stream, uint, state, buffer_size);
905 
906    util_dump_struct_end(stream);
907 }
908 
909 
910 void
util_dump_draw_info(FILE * stream,const struct pipe_draw_info * state)911 util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
912 {
913    if (!state) {
914       util_dump_null(stream);
915       return;
916    }
917 
918    util_dump_struct_begin(stream, "pipe_draw_info");
919 
920    util_dump_member(stream, bool, state, indexed);
921 
922    util_dump_member(stream, enum_prim_mode, state, mode);
923    util_dump_member(stream, uint, state, start);
924    util_dump_member(stream, uint, state, count);
925 
926    util_dump_member(stream, uint, state, start_instance);
927    util_dump_member(stream, uint, state, instance_count);
928 
929    util_dump_member(stream, uint, state, vertices_per_patch);
930 
931    util_dump_member(stream, int,  state, index_bias);
932    util_dump_member(stream, uint, state, min_index);
933    util_dump_member(stream, uint, state, max_index);
934 
935    util_dump_member(stream, bool, state, primitive_restart);
936    util_dump_member(stream, uint, state, restart_index);
937 
938    util_dump_member(stream, ptr, state, count_from_stream_output);
939 
940    util_dump_member(stream, ptr, state, indirect);
941    util_dump_member(stream, uint, state, indirect_offset);
942 
943    util_dump_struct_end(stream);
944 }
945 
util_dump_box(FILE * stream,const struct pipe_box * box)946 void util_dump_box(FILE *stream, const struct pipe_box *box)
947 {
948    if (!box) {
949       util_dump_null(stream);
950       return;
951    }
952 
953    util_dump_struct_begin(stream, "pipe_box");
954 
955    util_dump_member(stream, int, box, x);
956    util_dump_member(stream, int, box, y);
957    util_dump_member(stream, int, box, z);
958    util_dump_member(stream, int, box, width);
959    util_dump_member(stream, int, box, height);
960    util_dump_member(stream, int, box, depth);
961 
962    util_dump_struct_end(stream);
963 }
964 
util_dump_blit_info(FILE * stream,const struct pipe_blit_info * info)965 void util_dump_blit_info(FILE *stream, const struct pipe_blit_info *info)
966 {
967    char mask[7];
968 
969    if (!info) {
970       util_dump_null(stream);
971       return;
972    }
973 
974    util_dump_struct_begin(stream, "pipe_blit_info");
975 
976    util_dump_member_begin(stream, "dst");
977    util_dump_struct_begin(stream, "dst");
978    util_dump_member(stream, ptr, &info->dst, resource);
979    util_dump_member(stream, uint, &info->dst, level);
980    util_dump_member(stream, format, &info->dst, format);
981    util_dump_member_begin(stream, "box");
982    util_dump_box(stream, &info->dst.box);
983    util_dump_member_end(stream);
984    util_dump_struct_end(stream);
985    util_dump_member_end(stream);
986 
987    util_dump_member_begin(stream, "src");
988    util_dump_struct_begin(stream, "src");
989    util_dump_member(stream, ptr, &info->src, resource);
990    util_dump_member(stream, uint, &info->src, level);
991    util_dump_member(stream, format, &info->src, format);
992    util_dump_member_begin(stream, "box");
993    util_dump_box(stream, &info->src.box);
994    util_dump_member_end(stream);
995    util_dump_struct_end(stream);
996    util_dump_member_end(stream);
997 
998    mask[0] = (info->mask & PIPE_MASK_R) ? 'R' : '-';
999    mask[1] = (info->mask & PIPE_MASK_G) ? 'G' : '-';
1000    mask[2] = (info->mask & PIPE_MASK_B) ? 'B' : '-';
1001    mask[3] = (info->mask & PIPE_MASK_A) ? 'A' : '-';
1002    mask[4] = (info->mask & PIPE_MASK_Z) ? 'Z' : '-';
1003    mask[5] = (info->mask & PIPE_MASK_S) ? 'S' : '-';
1004    mask[6] = 0;
1005 
1006    util_dump_member_begin(stream, "mask");
1007    util_dump_string(stream, mask);
1008    util_dump_member_end(stream);
1009    util_dump_member(stream, enum_tex_filter, info, filter);
1010 
1011    util_dump_member(stream, bool, info, scissor_enable);
1012    util_dump_member_begin(stream, "scissor");
1013    util_dump_scissor_state(stream, &info->scissor);
1014    util_dump_member_end(stream);
1015 
1016    util_dump_member(stream, bool, info, render_condition_enable);
1017 
1018    util_dump_struct_end(stream);
1019 }
1020