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