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 <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 = util_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, usage);
323 util_dump_member(stream, uint, state, bind);
324 util_dump_member(stream, uint, state, flags);
325
326 util_dump_struct_end(stream);
327 }
328
329
330 void
util_dump_rasterizer_state(FILE * stream,const struct pipe_rasterizer_state * state)331 util_dump_rasterizer_state(FILE *stream, const struct pipe_rasterizer_state *state)
332 {
333 if (!state) {
334 util_dump_null(stream);
335 return;
336 }
337
338 util_dump_struct_begin(stream, "pipe_rasterizer_state");
339
340 util_dump_member(stream, bool, state, flatshade);
341 util_dump_member(stream, bool, state, light_twoside);
342 util_dump_member(stream, bool, state, clamp_vertex_color);
343 util_dump_member(stream, bool, state, clamp_fragment_color);
344 util_dump_member(stream, uint, state, front_ccw);
345 util_dump_member(stream, uint, state, cull_face);
346 util_dump_member(stream, uint, state, fill_front);
347 util_dump_member(stream, uint, state, fill_back);
348 util_dump_member(stream, bool, state, offset_point);
349 util_dump_member(stream, bool, state, offset_line);
350 util_dump_member(stream, bool, state, offset_tri);
351 util_dump_member(stream, bool, state, scissor);
352 util_dump_member(stream, bool, state, poly_smooth);
353 util_dump_member(stream, bool, state, poly_stipple_enable);
354 util_dump_member(stream, bool, state, point_smooth);
355 util_dump_member(stream, uint, state, sprite_coord_enable);
356 util_dump_member(stream, bool, state, sprite_coord_mode);
357 util_dump_member(stream, bool, state, point_quad_rasterization);
358 util_dump_member(stream, bool, state, point_tri_clip);
359 util_dump_member(stream, bool, state, point_size_per_vertex);
360 util_dump_member(stream, bool, state, multisample);
361 util_dump_member(stream, bool, state, line_smooth);
362 util_dump_member(stream, bool, state, line_stipple_enable);
363 util_dump_member(stream, uint, state, line_stipple_factor);
364 util_dump_member(stream, uint, state, line_stipple_pattern);
365 util_dump_member(stream, bool, state, line_last_pixel);
366 util_dump_member(stream, bool, state, flatshade_first);
367 util_dump_member(stream, bool, state, half_pixel_center);
368 util_dump_member(stream, bool, state, bottom_edge_rule);
369 util_dump_member(stream, bool, state, rasterizer_discard);
370 util_dump_member(stream, bool, state, depth_clip);
371 util_dump_member(stream, bool, state, clip_halfz);
372 util_dump_member(stream, uint, state, clip_plane_enable);
373
374 util_dump_member(stream, float, state, line_width);
375 util_dump_member(stream, float, state, point_size);
376 util_dump_member(stream, float, state, offset_units);
377 util_dump_member(stream, float, state, offset_scale);
378 util_dump_member(stream, float, state, offset_clamp);
379
380 util_dump_struct_end(stream);
381 }
382
383
384 void
util_dump_poly_stipple(FILE * stream,const struct pipe_poly_stipple * state)385 util_dump_poly_stipple(FILE *stream, const struct pipe_poly_stipple *state)
386 {
387 if (!state) {
388 util_dump_null(stream);
389 return;
390 }
391
392 util_dump_struct_begin(stream, "pipe_poly_stipple");
393
394 util_dump_member_begin(stream, "stipple");
395 util_dump_member_array(stream, uint, state, stipple);
396 util_dump_member_end(stream);
397
398 util_dump_struct_end(stream);
399 }
400
401
402 void
util_dump_viewport_state(FILE * stream,const struct pipe_viewport_state * state)403 util_dump_viewport_state(FILE *stream, const struct pipe_viewport_state *state)
404 {
405 if (!state) {
406 util_dump_null(stream);
407 return;
408 }
409
410 util_dump_struct_begin(stream, "pipe_viewport_state");
411
412 util_dump_member_array(stream, float, state, scale);
413 util_dump_member_array(stream, float, state, translate);
414
415 util_dump_struct_end(stream);
416 }
417
418
419 void
util_dump_scissor_state(FILE * stream,const struct pipe_scissor_state * state)420 util_dump_scissor_state(FILE *stream, const struct pipe_scissor_state *state)
421 {
422 if (!state) {
423 util_dump_null(stream);
424 return;
425 }
426
427 util_dump_struct_begin(stream, "pipe_scissor_state");
428
429 util_dump_member(stream, uint, state, minx);
430 util_dump_member(stream, uint, state, miny);
431 util_dump_member(stream, uint, state, maxx);
432 util_dump_member(stream, uint, state, maxy);
433
434 util_dump_struct_end(stream);
435 }
436
437
438 void
util_dump_clip_state(FILE * stream,const struct pipe_clip_state * state)439 util_dump_clip_state(FILE *stream, const struct pipe_clip_state *state)
440 {
441 unsigned i;
442
443 if (!state) {
444 util_dump_null(stream);
445 return;
446 }
447
448 util_dump_struct_begin(stream, "pipe_clip_state");
449
450 util_dump_member_begin(stream, "ucp");
451 util_dump_array_begin(stream);
452 for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) {
453 util_dump_elem_begin(stream);
454 util_dump_array(stream, float, state->ucp[i], 4);
455 util_dump_elem_end(stream);
456 }
457 util_dump_array_end(stream);
458 util_dump_member_end(stream);
459
460 util_dump_struct_end(stream);
461 }
462
463
464 void
util_dump_shader_state(FILE * stream,const struct pipe_shader_state * state)465 util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
466 {
467 unsigned i;
468
469 if (!state) {
470 util_dump_null(stream);
471 return;
472 }
473
474 util_dump_struct_begin(stream, "pipe_shader_state");
475
476 if (state->type == PIPE_SHADER_IR_TGSI) {
477 util_dump_member_begin(stream, "tokens");
478 fprintf(stream, "\"\n");
479 tgsi_dump_to_file(state->tokens, 0, stream);
480 fprintf(stream, "\"");
481 util_dump_member_end(stream);
482 }
483
484 if (state->stream_output.num_outputs) {
485 util_dump_member_begin(stream, "stream_output");
486 util_dump_struct_begin(stream, "pipe_stream_output_info");
487 util_dump_member(stream, uint, &state->stream_output, num_outputs);
488 util_dump_array(stream, uint, state->stream_output.stride,
489 ARRAY_SIZE(state->stream_output.stride));
490 util_dump_array_begin(stream);
491 for(i = 0; i < state->stream_output.num_outputs; ++i) {
492 util_dump_elem_begin(stream);
493 util_dump_struct_begin(stream, ""); /* anonymous */
494 util_dump_member(stream, uint, &state->stream_output.output[i], register_index);
495 util_dump_member(stream, uint, &state->stream_output.output[i], start_component);
496 util_dump_member(stream, uint, &state->stream_output.output[i], num_components);
497 util_dump_member(stream, uint, &state->stream_output.output[i], output_buffer);
498 util_dump_struct_end(stream);
499 util_dump_elem_end(stream);
500 }
501 util_dump_array_end(stream);
502 util_dump_struct_end(stream);
503 util_dump_member_end(stream);
504 }
505
506 util_dump_struct_end(stream);
507 }
508
509
510 void
util_dump_depth_stencil_alpha_state(FILE * stream,const struct pipe_depth_stencil_alpha_state * state)511 util_dump_depth_stencil_alpha_state(FILE *stream, const struct pipe_depth_stencil_alpha_state *state)
512 {
513 unsigned i;
514
515 if (!state) {
516 util_dump_null(stream);
517 return;
518 }
519
520 util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");
521
522 util_dump_member_begin(stream, "depth");
523 util_dump_struct_begin(stream, "pipe_depth_state");
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 util_dump_struct_end(stream);
530 util_dump_member_end(stream);
531
532 util_dump_member_begin(stream, "stencil");
533 util_dump_array_begin(stream);
534 for(i = 0; i < ARRAY_SIZE(state->stencil); ++i) {
535 util_dump_elem_begin(stream);
536 util_dump_struct_begin(stream, "pipe_stencil_state");
537 util_dump_member(stream, bool, &state->stencil[i], enabled);
538 if (state->stencil[i].enabled) {
539 util_dump_member(stream, enum_func, &state->stencil[i], func);
540 util_dump_member(stream, enum_stencil_op,
541 &state->stencil[i], fail_op);
542 util_dump_member(stream, enum_stencil_op,
543 &state->stencil[i], zpass_op);
544 util_dump_member(stream, enum_stencil_op,
545 &state->stencil[i], zfail_op);
546 util_dump_member(stream, uint, &state->stencil[i], valuemask);
547 util_dump_member(stream, uint, &state->stencil[i], writemask);
548 }
549 util_dump_struct_end(stream);
550 util_dump_elem_end(stream);
551 }
552 util_dump_array_end(stream);
553 util_dump_member_end(stream);
554
555 util_dump_member_begin(stream, "alpha");
556 util_dump_struct_begin(stream, "pipe_alpha_state");
557 util_dump_member(stream, bool, &state->alpha, enabled);
558 if (state->alpha.enabled) {
559 util_dump_member(stream, enum_func, &state->alpha, func);
560 util_dump_member(stream, float, &state->alpha, ref_value);
561 }
562 util_dump_struct_end(stream);
563 util_dump_member_end(stream);
564
565 util_dump_struct_end(stream);
566 }
567
568 void
util_dump_rt_blend_state(FILE * stream,const struct pipe_rt_blend_state * state)569 util_dump_rt_blend_state(FILE *stream, const struct pipe_rt_blend_state *state)
570 {
571 util_dump_struct_begin(stream, "pipe_rt_blend_state");
572
573 util_dump_member(stream, uint, state, blend_enable);
574 if (state->blend_enable) {
575 util_dump_member(stream, enum_blend_func, state, rgb_func);
576 util_dump_member(stream, enum_blend_factor, state, rgb_src_factor);
577 util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor);
578
579 util_dump_member(stream, enum_blend_func, state, alpha_func);
580 util_dump_member(stream, enum_blend_factor, state, alpha_src_factor);
581 util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor);
582 }
583
584 util_dump_member(stream, uint, state, colormask);
585
586 util_dump_struct_end(stream);
587 }
588
589 void
util_dump_blend_state(FILE * stream,const struct pipe_blend_state * state)590 util_dump_blend_state(FILE *stream, const struct pipe_blend_state *state)
591 {
592 unsigned valid_entries = 1;
593
594 if (!state) {
595 util_dump_null(stream);
596 return;
597 }
598
599 util_dump_struct_begin(stream, "pipe_blend_state");
600
601 util_dump_member(stream, bool, state, dither);
602 util_dump_member(stream, bool, state, alpha_to_coverage);
603 util_dump_member(stream, bool, state, alpha_to_one);
604
605 util_dump_member(stream, bool, state, logicop_enable);
606 if (state->logicop_enable) {
607 util_dump_member(stream, enum_func, state, logicop_func);
608 }
609 else {
610 util_dump_member(stream, bool, state, independent_blend_enable);
611
612 util_dump_member_begin(stream, "rt");
613 if (state->independent_blend_enable)
614 valid_entries = PIPE_MAX_COLOR_BUFS;
615 util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries);
616 util_dump_member_end(stream);
617 }
618
619 util_dump_struct_end(stream);
620 }
621
622
623 void
util_dump_blend_color(FILE * stream,const struct pipe_blend_color * state)624 util_dump_blend_color(FILE *stream, const struct pipe_blend_color *state)
625 {
626 if (!state) {
627 util_dump_null(stream);
628 return;
629 }
630
631 util_dump_struct_begin(stream, "pipe_blend_color");
632
633 util_dump_member_array(stream, float, state, color);
634
635 util_dump_struct_end(stream);
636 }
637
638 void
util_dump_stencil_ref(FILE * stream,const struct pipe_stencil_ref * state)639 util_dump_stencil_ref(FILE *stream, const struct pipe_stencil_ref *state)
640 {
641 if (!state) {
642 util_dump_null(stream);
643 return;
644 }
645
646 util_dump_struct_begin(stream, "pipe_stencil_ref");
647
648 util_dump_member_array(stream, uint, state, ref_value);
649
650 util_dump_struct_end(stream);
651 }
652
653 void
util_dump_framebuffer_state(FILE * stream,const struct pipe_framebuffer_state * state)654 util_dump_framebuffer_state(FILE *stream, const struct pipe_framebuffer_state *state)
655 {
656 util_dump_struct_begin(stream, "pipe_framebuffer_state");
657
658 util_dump_member(stream, uint, state, width);
659 util_dump_member(stream, uint, state, height);
660 util_dump_member(stream, uint, state, samples);
661 util_dump_member(stream, uint, state, layers);
662 util_dump_member(stream, uint, state, nr_cbufs);
663 util_dump_member_array(stream, ptr, state, cbufs);
664 util_dump_member(stream, ptr, state, zsbuf);
665
666 util_dump_struct_end(stream);
667 }
668
669
670 void
util_dump_sampler_state(FILE * stream,const struct pipe_sampler_state * state)671 util_dump_sampler_state(FILE *stream, const struct pipe_sampler_state *state)
672 {
673 if (!state) {
674 util_dump_null(stream);
675 return;
676 }
677
678 util_dump_struct_begin(stream, "pipe_sampler_state");
679
680 util_dump_member(stream, enum_tex_wrap, state, wrap_s);
681 util_dump_member(stream, enum_tex_wrap, state, wrap_t);
682 util_dump_member(stream, enum_tex_wrap, state, wrap_r);
683 util_dump_member(stream, enum_tex_filter, state, min_img_filter);
684 util_dump_member(stream, enum_tex_mipfilter, state, min_mip_filter);
685 util_dump_member(stream, enum_tex_filter, state, mag_img_filter);
686 util_dump_member(stream, uint, state, compare_mode);
687 util_dump_member(stream, enum_func, state, compare_func);
688 util_dump_member(stream, bool, state, normalized_coords);
689 util_dump_member(stream, uint, state, max_anisotropy);
690 util_dump_member(stream, bool, state, seamless_cube_map);
691 util_dump_member(stream, float, state, lod_bias);
692 util_dump_member(stream, float, state, min_lod);
693 util_dump_member(stream, float, state, max_lod);
694 util_dump_member_array(stream, float, state, border_color.f);
695
696 util_dump_struct_end(stream);
697 }
698
699
700 void
util_dump_surface(FILE * stream,const struct pipe_surface * state)701 util_dump_surface(FILE *stream, const struct pipe_surface *state)
702 {
703 if (!state) {
704 util_dump_null(stream);
705 return;
706 }
707
708 util_dump_struct_begin(stream, "pipe_surface");
709
710 util_dump_member(stream, format, state, format);
711 util_dump_member(stream, uint, state, width);
712 util_dump_member(stream, uint, state, height);
713
714 util_dump_member(stream, ptr, state, texture);
715 util_dump_member(stream, uint, state, u.tex.level);
716 util_dump_member(stream, uint, state, u.tex.first_layer);
717 util_dump_member(stream, uint, state, u.tex.last_layer);
718
719 util_dump_struct_end(stream);
720 }
721
722
723 void
util_dump_image_view(FILE * stream,const struct pipe_image_view * state)724 util_dump_image_view(FILE *stream, const struct pipe_image_view *state)
725 {
726 if (!state) {
727 util_dump_null(stream);
728 return;
729 }
730
731 util_dump_struct_begin(stream, "pipe_image_view");
732
733 util_dump_member(stream, ptr, state, resource);
734 util_dump_member(stream, format, state, format);
735
736 if (state->resource->target == PIPE_BUFFER) {
737 util_dump_member(stream, uint, state, u.buf.offset);
738 util_dump_member(stream, uint, state, u.buf.size);
739 }
740 else {
741 util_dump_member(stream, uint, state, u.tex.first_layer);
742 util_dump_member(stream, uint, state, u.tex.last_layer);
743 util_dump_member(stream, uint, state, u.tex.level);
744 }
745
746 util_dump_struct_end(stream);
747 }
748
749
750 void
util_dump_shader_buffer(FILE * stream,const struct pipe_shader_buffer * state)751 util_dump_shader_buffer(FILE *stream, const struct pipe_shader_buffer *state)
752 {
753 if (!state) {
754 util_dump_null(stream);
755 return;
756 }
757
758 util_dump_struct_begin(stream, "pipe_shader_buffer");
759
760 util_dump_member(stream, ptr, state, buffer);
761 util_dump_member(stream, uint, state, buffer_offset);
762 util_dump_member(stream, uint, state, buffer_size);
763
764 util_dump_struct_end(stream);
765
766 }
767
768
769 void
util_dump_sampler_view(FILE * stream,const struct pipe_sampler_view * state)770 util_dump_sampler_view(FILE *stream, const struct pipe_sampler_view *state)
771 {
772 if (!state) {
773 util_dump_null(stream);
774 return;
775 }
776
777 util_dump_struct_begin(stream, "pipe_sampler_view");
778
779 util_dump_member(stream, enum_tex_target, state, target);
780 util_dump_member(stream, format, state, format);
781 util_dump_member(stream, ptr, state, texture);
782
783 if (state->target == PIPE_BUFFER) {
784 util_dump_member(stream, uint, state, u.buf.offset);
785 util_dump_member(stream, uint, state, u.buf.size);
786 }
787 else {
788 util_dump_member(stream, uint, state, u.tex.first_layer);
789 util_dump_member(stream, uint, state, u.tex.last_layer);
790 util_dump_member(stream, uint, state, u.tex.last_level);
791 util_dump_member(stream, uint, state, u.tex.last_level);
792 }
793
794 util_dump_member(stream, uint, state, swizzle_r);
795 util_dump_member(stream, uint, state, swizzle_g);
796 util_dump_member(stream, uint, state, swizzle_b);
797 util_dump_member(stream, uint, state, swizzle_a);
798
799 util_dump_struct_end(stream);
800 }
801
802
803 void
util_dump_transfer(FILE * stream,const struct pipe_transfer * state)804 util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
805 {
806 if (!state) {
807 util_dump_null(stream);
808 return;
809 }
810
811 util_dump_struct_begin(stream, "pipe_transfer");
812
813 util_dump_member(stream, ptr, state, resource);
814 util_dump_member(stream, uint, state, level);
815 util_dump_member(stream, transfer_usage, state, usage);
816 util_dump_member_begin(stream, "box");
817 util_dump_box(stream, &state->box);
818 util_dump_member_end(stream);
819 util_dump_member(stream, uint, state, stride);
820 util_dump_member(stream, uint, state, layer_stride);
821
822 util_dump_struct_end(stream);
823 }
824
825
826 void
util_dump_constant_buffer(FILE * stream,const struct pipe_constant_buffer * state)827 util_dump_constant_buffer(FILE *stream,
828 const struct pipe_constant_buffer *state)
829 {
830 if (!state) {
831 util_dump_null(stream);
832 return;
833 }
834
835 util_dump_struct_begin(stream, "pipe_constant_buffer");
836
837 util_dump_member(stream, ptr, state, buffer);
838 util_dump_member(stream, uint, state, buffer_offset);
839 util_dump_member(stream, uint, state, buffer_size);
840 util_dump_member(stream, ptr, state, user_buffer);
841
842 util_dump_struct_end(stream);
843 }
844
845
846 void
util_dump_vertex_buffer(FILE * stream,const struct pipe_vertex_buffer * state)847 util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state)
848 {
849 if (!state) {
850 util_dump_null(stream);
851 return;
852 }
853
854 util_dump_struct_begin(stream, "pipe_vertex_buffer");
855
856 util_dump_member(stream, uint, state, stride);
857 util_dump_member(stream, bool, state, is_user_buffer);
858 util_dump_member(stream, uint, state, buffer_offset);
859 util_dump_member(stream, ptr, state, buffer.resource);
860
861 util_dump_struct_end(stream);
862 }
863
864
865 void
util_dump_vertex_element(FILE * stream,const struct pipe_vertex_element * state)866 util_dump_vertex_element(FILE *stream, const struct pipe_vertex_element *state)
867 {
868 if (!state) {
869 util_dump_null(stream);
870 return;
871 }
872
873 util_dump_struct_begin(stream, "pipe_vertex_element");
874
875 util_dump_member(stream, uint, state, src_offset);
876 util_dump_member(stream, uint, state, instance_divisor);
877 util_dump_member(stream, uint, state, vertex_buffer_index);
878 util_dump_member(stream, format, state, src_format);
879
880 util_dump_struct_end(stream);
881 }
882
883
884 void
util_dump_stream_output_target(FILE * stream,const struct pipe_stream_output_target * state)885 util_dump_stream_output_target(FILE *stream,
886 const struct pipe_stream_output_target *state)
887 {
888 if (!state) {
889 util_dump_null(stream);
890 return;
891 }
892
893 util_dump_struct_begin(stream, "pipe_stream_output_target");
894
895 util_dump_member(stream, ptr, state, buffer);
896 util_dump_member(stream, uint, state, buffer_offset);
897 util_dump_member(stream, uint, state, buffer_size);
898
899 util_dump_struct_end(stream);
900 }
901
902
903 void
util_dump_draw_info(FILE * stream,const struct pipe_draw_info * state)904 util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
905 {
906 if (!state) {
907 util_dump_null(stream);
908 return;
909 }
910
911 util_dump_struct_begin(stream, "pipe_draw_info");
912
913 util_dump_member(stream, uint, state, index_size);
914 util_dump_member(stream, uint, state, has_user_indices);
915
916 util_dump_member(stream, enum_prim_mode, state, mode);
917 util_dump_member(stream, uint, state, start);
918 util_dump_member(stream, uint, state, count);
919
920 util_dump_member(stream, uint, state, start_instance);
921 util_dump_member(stream, uint, state, instance_count);
922
923 util_dump_member(stream, uint, state, drawid);
924
925 util_dump_member(stream, uint, state, vertices_per_patch);
926
927 util_dump_member(stream, int, state, index_bias);
928 util_dump_member(stream, uint, state, min_index);
929 util_dump_member(stream, uint, state, max_index);
930
931 util_dump_member(stream, bool, state, primitive_restart);
932 if (state->primitive_restart)
933 util_dump_member(stream, uint, state, restart_index);
934
935 if (state->index_size) {
936 if (state->has_user_indices)
937 util_dump_member(stream, ptr, state, index.user);
938 else
939 util_dump_member(stream, ptr, state, index.resource);
940 }
941 util_dump_member(stream, ptr, state, count_from_stream_output);
942
943 if (!state->indirect) {
944 util_dump_member(stream, ptr, state, indirect);
945 } else {
946 util_dump_member(stream, uint, state, indirect->offset);
947 util_dump_member(stream, uint, state, indirect->stride);
948 util_dump_member(stream, uint, state, indirect->draw_count);
949 util_dump_member(stream, uint, state, indirect->indirect_draw_count_offset);
950 util_dump_member(stream, ptr, state, indirect->buffer);
951 util_dump_member(stream, ptr, state, indirect->indirect_draw_count);
952 }
953
954 util_dump_struct_end(stream);
955 }
956
util_dump_grid_info(FILE * stream,const struct pipe_grid_info * state)957 void util_dump_grid_info(FILE *stream, const struct pipe_grid_info *state)
958 {
959 if (!state) {
960 util_dump_null(stream);
961 return;
962 }
963
964 util_dump_struct_begin(stream, "pipe_grid_info");
965
966 util_dump_member(stream, uint, state, pc);
967 util_dump_member(stream, ptr, state, input);
968 util_dump_member(stream, uint, state, work_dim);
969
970 util_dump_member_begin(stream, "block");
971 util_dump_array(stream, uint, state->block, ARRAY_SIZE(state->block));
972 util_dump_member_end(stream);
973
974 util_dump_member_begin(stream, "grid");
975 util_dump_array(stream, uint, state->grid, ARRAY_SIZE(state->grid));
976 util_dump_member_end(stream);
977
978 util_dump_member(stream, ptr, state, indirect);
979 util_dump_member(stream, uint, state, indirect_offset);
980
981 util_dump_struct_end(stream);
982 }
983
util_dump_box(FILE * stream,const struct pipe_box * box)984 void util_dump_box(FILE *stream, const struct pipe_box *box)
985 {
986 if (!box) {
987 util_dump_null(stream);
988 return;
989 }
990
991 util_dump_struct_begin(stream, "pipe_box");
992
993 util_dump_member(stream, int, box, x);
994 util_dump_member(stream, int, box, y);
995 util_dump_member(stream, int, box, z);
996 util_dump_member(stream, int, box, width);
997 util_dump_member(stream, int, box, height);
998 util_dump_member(stream, int, box, depth);
999
1000 util_dump_struct_end(stream);
1001 }
1002
util_dump_blit_info(FILE * stream,const struct pipe_blit_info * info)1003 void util_dump_blit_info(FILE *stream, const struct pipe_blit_info *info)
1004 {
1005 char mask[7];
1006
1007 if (!info) {
1008 util_dump_null(stream);
1009 return;
1010 }
1011
1012 util_dump_struct_begin(stream, "pipe_blit_info");
1013
1014 util_dump_member_begin(stream, "dst");
1015 util_dump_struct_begin(stream, "dst");
1016 util_dump_member(stream, ptr, &info->dst, resource);
1017 util_dump_member(stream, uint, &info->dst, level);
1018 util_dump_member(stream, format, &info->dst, format);
1019 util_dump_member_begin(stream, "box");
1020 util_dump_box(stream, &info->dst.box);
1021 util_dump_member_end(stream);
1022 util_dump_struct_end(stream);
1023 util_dump_member_end(stream);
1024
1025 util_dump_member_begin(stream, "src");
1026 util_dump_struct_begin(stream, "src");
1027 util_dump_member(stream, ptr, &info->src, resource);
1028 util_dump_member(stream, uint, &info->src, level);
1029 util_dump_member(stream, format, &info->src, format);
1030 util_dump_member_begin(stream, "box");
1031 util_dump_box(stream, &info->src.box);
1032 util_dump_member_end(stream);
1033 util_dump_struct_end(stream);
1034 util_dump_member_end(stream);
1035
1036 mask[0] = (info->mask & PIPE_MASK_R) ? 'R' : '-';
1037 mask[1] = (info->mask & PIPE_MASK_G) ? 'G' : '-';
1038 mask[2] = (info->mask & PIPE_MASK_B) ? 'B' : '-';
1039 mask[3] = (info->mask & PIPE_MASK_A) ? 'A' : '-';
1040 mask[4] = (info->mask & PIPE_MASK_Z) ? 'Z' : '-';
1041 mask[5] = (info->mask & PIPE_MASK_S) ? 'S' : '-';
1042 mask[6] = 0;
1043
1044 util_dump_member_begin(stream, "mask");
1045 util_dump_string(stream, mask);
1046 util_dump_member_end(stream);
1047 util_dump_member(stream, enum_tex_filter, info, filter);
1048
1049 util_dump_member(stream, bool, info, scissor_enable);
1050 util_dump_member_begin(stream, "scissor");
1051 util_dump_scissor_state(stream, &info->scissor);
1052 util_dump_member_end(stream);
1053
1054 util_dump_member(stream, bool, info, render_condition_enable);
1055
1056 util_dump_struct_end(stream);
1057 }
1058