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 void
util_dump_stream_output_info(FILE * stream,const struct pipe_stream_output_info * state)466 util_dump_stream_output_info(FILE *stream,
467 const struct pipe_stream_output_info *state)
468 {
469 if (!state) {
470 util_dump_null(stream);
471 return;
472 }
473
474 util_dump_struct_begin(stream, "pipe_stream_output_info");
475 util_dump_member(stream, uint, state, num_outputs);
476 util_dump_array(stream, uint, state->stride,
477 ARRAY_SIZE(state->stride));
478 util_dump_array_begin(stream);
479 for (unsigned i = 0; i < state->num_outputs; ++i) {
480 util_dump_elem_begin(stream);
481 util_dump_struct_begin(stream, ""); /* anonymous */
482 util_dump_member(stream, uint, &state->output[i], register_index);
483 util_dump_member(stream, uint, &state->output[i], start_component);
484 util_dump_member(stream, uint, &state->output[i], num_components);
485 util_dump_member(stream, uint, &state->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 }
492
493 void
util_dump_shader_state(FILE * stream,const struct pipe_shader_state * state)494 util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
495 {
496 if (!state) {
497 util_dump_null(stream);
498 return;
499 }
500
501 util_dump_struct_begin(stream, "pipe_shader_state");
502
503 if (state->type == PIPE_SHADER_IR_TGSI) {
504 util_dump_member_begin(stream, "tokens");
505 fprintf(stream, "\"\n");
506 tgsi_dump_to_file(state->tokens, 0, stream);
507 fprintf(stream, "\"");
508 util_dump_member_end(stream);
509 }
510
511 if (state->stream_output.num_outputs) {
512 util_dump_member_begin(stream, "stream_output");
513 util_dump_stream_output_info(stream, &state->stream_output);
514 util_dump_member_end(stream);
515 }
516
517 util_dump_struct_end(stream);
518 }
519
520
521 void
util_dump_depth_stencil_alpha_state(FILE * stream,const struct pipe_depth_stencil_alpha_state * state)522 util_dump_depth_stencil_alpha_state(FILE *stream, const struct pipe_depth_stencil_alpha_state *state)
523 {
524 unsigned i;
525
526 if (!state) {
527 util_dump_null(stream);
528 return;
529 }
530
531 util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");
532
533 util_dump_member(stream, bool, state, depth_enabled);
534 if (state->depth_enabled) {
535 util_dump_member(stream, bool, state, depth_writemask);
536 util_dump_member(stream, enum_func, state, depth_func);
537 }
538
539 util_dump_member_begin(stream, "stencil");
540 util_dump_array_begin(stream);
541 for(i = 0; i < ARRAY_SIZE(state->stencil); ++i) {
542 util_dump_elem_begin(stream);
543 util_dump_struct_begin(stream, "pipe_stencil_state");
544 util_dump_member(stream, bool, &state->stencil[i], enabled);
545 if (state->stencil[i].enabled) {
546 util_dump_member(stream, enum_func, &state->stencil[i], func);
547 util_dump_member(stream, enum_stencil_op,
548 &state->stencil[i], fail_op);
549 util_dump_member(stream, enum_stencil_op,
550 &state->stencil[i], zpass_op);
551 util_dump_member(stream, enum_stencil_op,
552 &state->stencil[i], zfail_op);
553 util_dump_member(stream, uint, &state->stencil[i], valuemask);
554 util_dump_member(stream, uint, &state->stencil[i], writemask);
555 }
556 util_dump_struct_end(stream);
557 util_dump_elem_end(stream);
558 }
559 util_dump_array_end(stream);
560 util_dump_member_end(stream);
561
562 util_dump_member(stream, bool, state, alpha_enabled);
563 if (state->alpha_enabled) {
564 util_dump_member(stream, enum_func, state, alpha_func);
565 util_dump_member(stream, float, state, alpha_ref_value);
566 }
567
568 util_dump_struct_end(stream);
569 }
570
571 void
util_dump_rt_blend_state(FILE * stream,const struct pipe_rt_blend_state * state)572 util_dump_rt_blend_state(FILE *stream, const struct pipe_rt_blend_state *state)
573 {
574 util_dump_struct_begin(stream, "pipe_rt_blend_state");
575
576 util_dump_member(stream, uint, state, blend_enable);
577 if (state->blend_enable) {
578 util_dump_member(stream, enum_blend_func, state, rgb_func);
579 util_dump_member(stream, enum_blend_factor, state, rgb_src_factor);
580 util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor);
581
582 util_dump_member(stream, enum_blend_func, state, alpha_func);
583 util_dump_member(stream, enum_blend_factor, state, alpha_src_factor);
584 util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor);
585 }
586
587 util_dump_member(stream, uint, state, colormask);
588
589 util_dump_struct_end(stream);
590 }
591
592 void
util_dump_blend_state(FILE * stream,const struct pipe_blend_state * state)593 util_dump_blend_state(FILE *stream, const struct pipe_blend_state *state)
594 {
595 unsigned valid_entries = 1;
596
597 if (!state) {
598 util_dump_null(stream);
599 return;
600 }
601
602 util_dump_struct_begin(stream, "pipe_blend_state");
603
604 util_dump_member(stream, bool, state, dither);
605 util_dump_member(stream, bool, state, alpha_to_coverage);
606 util_dump_member(stream, bool, state, alpha_to_one);
607 util_dump_member(stream, uint, state, max_rt);
608
609 util_dump_member(stream, bool, state, logicop_enable);
610 if (state->logicop_enable) {
611 util_dump_member(stream, enum_func, state, logicop_func);
612 }
613 else {
614 util_dump_member(stream, bool, state, independent_blend_enable);
615
616 util_dump_member_begin(stream, "rt");
617 if (state->independent_blend_enable)
618 valid_entries = state->max_rt + 1;
619 util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries);
620 util_dump_member_end(stream);
621 }
622
623 util_dump_struct_end(stream);
624 }
625
626
627 void
util_dump_blend_color(FILE * stream,const struct pipe_blend_color * state)628 util_dump_blend_color(FILE *stream, const struct pipe_blend_color *state)
629 {
630 if (!state) {
631 util_dump_null(stream);
632 return;
633 }
634
635 util_dump_struct_begin(stream, "pipe_blend_color");
636
637 util_dump_member_array(stream, float, state, color);
638
639 util_dump_struct_end(stream);
640 }
641
642 void
util_dump_stencil_ref(FILE * stream,const struct pipe_stencil_ref * state)643 util_dump_stencil_ref(FILE *stream, const struct pipe_stencil_ref *state)
644 {
645 if (!state) {
646 util_dump_null(stream);
647 return;
648 }
649
650 util_dump_struct_begin(stream, "pipe_stencil_ref");
651
652 util_dump_member_array(stream, uint, state, ref_value);
653
654 util_dump_struct_end(stream);
655 }
656
657 void
util_dump_framebuffer_state(FILE * stream,const struct pipe_framebuffer_state * state)658 util_dump_framebuffer_state(FILE *stream, const struct pipe_framebuffer_state *state)
659 {
660 util_dump_struct_begin(stream, "pipe_framebuffer_state");
661
662 util_dump_member(stream, uint, state, width);
663 util_dump_member(stream, uint, state, height);
664 util_dump_member(stream, uint, state, samples);
665 util_dump_member(stream, uint, state, layers);
666 util_dump_member(stream, uint, state, nr_cbufs);
667 util_dump_member_array(stream, ptr, state, cbufs);
668 util_dump_member(stream, ptr, state, zsbuf);
669
670 util_dump_struct_end(stream);
671 }
672
673
674 void
util_dump_sampler_state(FILE * stream,const struct pipe_sampler_state * state)675 util_dump_sampler_state(FILE *stream, const struct pipe_sampler_state *state)
676 {
677 if (!state) {
678 util_dump_null(stream);
679 return;
680 }
681
682 util_dump_struct_begin(stream, "pipe_sampler_state");
683
684 util_dump_member(stream, enum_tex_wrap, state, wrap_s);
685 util_dump_member(stream, enum_tex_wrap, state, wrap_t);
686 util_dump_member(stream, enum_tex_wrap, state, wrap_r);
687 util_dump_member(stream, enum_tex_filter, state, min_img_filter);
688 util_dump_member(stream, enum_tex_mipfilter, state, min_mip_filter);
689 util_dump_member(stream, enum_tex_filter, state, mag_img_filter);
690 util_dump_member(stream, uint, state, compare_mode);
691 util_dump_member(stream, enum_func, state, compare_func);
692 util_dump_member(stream, bool, state, normalized_coords);
693 util_dump_member(stream, uint, state, max_anisotropy);
694 util_dump_member(stream, bool, state, seamless_cube_map);
695 util_dump_member(stream, float, state, lod_bias);
696 util_dump_member(stream, float, state, min_lod);
697 util_dump_member(stream, float, state, max_lod);
698 util_dump_member_array(stream, float, state, border_color.f);
699
700 util_dump_struct_end(stream);
701 }
702
703
704 void
util_dump_surface(FILE * stream,const struct pipe_surface * state)705 util_dump_surface(FILE *stream, const struct pipe_surface *state)
706 {
707 if (!state) {
708 util_dump_null(stream);
709 return;
710 }
711
712 util_dump_struct_begin(stream, "pipe_surface");
713
714 util_dump_member(stream, format, state, format);
715 util_dump_member(stream, uint, state, width);
716 util_dump_member(stream, uint, state, height);
717
718 util_dump_member(stream, ptr, state, texture);
719 util_dump_member(stream, uint, state, u.tex.level);
720 util_dump_member(stream, uint, state, u.tex.first_layer);
721 util_dump_member(stream, uint, state, u.tex.last_layer);
722
723 util_dump_struct_end(stream);
724 }
725
726
727 void
util_dump_image_view(FILE * stream,const struct pipe_image_view * state)728 util_dump_image_view(FILE *stream, const struct pipe_image_view *state)
729 {
730 if (!state) {
731 util_dump_null(stream);
732 return;
733 }
734
735 util_dump_struct_begin(stream, "pipe_image_view");
736
737 util_dump_member(stream, ptr, state, resource);
738 util_dump_member(stream, format, state, format);
739
740 if (state->resource->target == PIPE_BUFFER) {
741 util_dump_member(stream, uint, state, u.buf.offset);
742 util_dump_member(stream, uint, state, u.buf.size);
743 }
744 else {
745 util_dump_member(stream, uint, state, u.tex.first_layer);
746 util_dump_member(stream, uint, state, u.tex.last_layer);
747 util_dump_member(stream, uint, state, u.tex.level);
748 }
749
750 util_dump_struct_end(stream);
751 }
752
753
754 void
util_dump_shader_buffer(FILE * stream,const struct pipe_shader_buffer * state)755 util_dump_shader_buffer(FILE *stream, const struct pipe_shader_buffer *state)
756 {
757 if (!state) {
758 util_dump_null(stream);
759 return;
760 }
761
762 util_dump_struct_begin(stream, "pipe_shader_buffer");
763
764 util_dump_member(stream, ptr, state, buffer);
765 util_dump_member(stream, uint, state, buffer_offset);
766 util_dump_member(stream, uint, state, buffer_size);
767
768 util_dump_struct_end(stream);
769
770 }
771
772
773 void
util_dump_sampler_view(FILE * stream,const struct pipe_sampler_view * state)774 util_dump_sampler_view(FILE *stream, const struct pipe_sampler_view *state)
775 {
776 if (!state) {
777 util_dump_null(stream);
778 return;
779 }
780
781 util_dump_struct_begin(stream, "pipe_sampler_view");
782
783 util_dump_member(stream, enum_tex_target, state, target);
784 util_dump_member(stream, format, state, format);
785 util_dump_member(stream, ptr, state, texture);
786
787 if (state->target == PIPE_BUFFER) {
788 util_dump_member(stream, uint, state, u.buf.offset);
789 util_dump_member(stream, uint, state, u.buf.size);
790 }
791 else {
792 util_dump_member(stream, uint, state, u.tex.first_layer);
793 util_dump_member(stream, uint, state, u.tex.last_layer);
794 util_dump_member(stream, uint, state, u.tex.first_level);
795 util_dump_member(stream, uint, state, u.tex.last_level);
796 }
797
798 util_dump_member(stream, uint, state, swizzle_r);
799 util_dump_member(stream, uint, state, swizzle_g);
800 util_dump_member(stream, uint, state, swizzle_b);
801 util_dump_member(stream, uint, state, swizzle_a);
802
803 util_dump_struct_end(stream);
804 }
805
806
807 void
util_dump_transfer(FILE * stream,const struct pipe_transfer * state)808 util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
809 {
810 if (!state) {
811 util_dump_null(stream);
812 return;
813 }
814
815 util_dump_struct_begin(stream, "pipe_transfer");
816
817 util_dump_member(stream, ptr, state, resource);
818 util_dump_member(stream, uint, state, level);
819 util_dump_member(stream, transfer_usage, state, usage);
820 util_dump_member_begin(stream, "box");
821 util_dump_box(stream, &state->box);
822 util_dump_member_end(stream);
823 util_dump_member(stream, uint, state, stride);
824 util_dump_member(stream, uint, state, layer_stride);
825
826 util_dump_struct_end(stream);
827 }
828
829
830 void
util_dump_constant_buffer(FILE * stream,const struct pipe_constant_buffer * state)831 util_dump_constant_buffer(FILE *stream,
832 const struct pipe_constant_buffer *state)
833 {
834 if (!state) {
835 util_dump_null(stream);
836 return;
837 }
838
839 util_dump_struct_begin(stream, "pipe_constant_buffer");
840
841 util_dump_member(stream, ptr, state, buffer);
842 util_dump_member(stream, uint, state, buffer_offset);
843 util_dump_member(stream, uint, state, buffer_size);
844 util_dump_member(stream, ptr, state, user_buffer);
845
846 util_dump_struct_end(stream);
847 }
848
849
850 void
util_dump_vertex_buffer(FILE * stream,const struct pipe_vertex_buffer * state)851 util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state)
852 {
853 if (!state) {
854 util_dump_null(stream);
855 return;
856 }
857
858 util_dump_struct_begin(stream, "pipe_vertex_buffer");
859
860 util_dump_member(stream, uint, state, stride);
861 util_dump_member(stream, bool, state, is_user_buffer);
862 util_dump_member(stream, uint, state, buffer_offset);
863 util_dump_member(stream, ptr, state, buffer.resource);
864
865 util_dump_struct_end(stream);
866 }
867
868
869 void
util_dump_vertex_element(FILE * stream,const struct pipe_vertex_element * state)870 util_dump_vertex_element(FILE *stream, const struct pipe_vertex_element *state)
871 {
872 if (!state) {
873 util_dump_null(stream);
874 return;
875 }
876
877 util_dump_struct_begin(stream, "pipe_vertex_element");
878
879 util_dump_member(stream, uint, state, src_offset);
880 util_dump_member(stream, uint, state, instance_divisor);
881 util_dump_member(stream, uint, state, vertex_buffer_index);
882 util_dump_member(stream, format, state, src_format);
883
884 util_dump_struct_end(stream);
885 }
886
887
888 void
util_dump_stream_output_target(FILE * stream,const struct pipe_stream_output_target * state)889 util_dump_stream_output_target(FILE *stream,
890 const struct pipe_stream_output_target *state)
891 {
892 if (!state) {
893 util_dump_null(stream);
894 return;
895 }
896
897 util_dump_struct_begin(stream, "pipe_stream_output_target");
898
899 util_dump_member(stream, ptr, state, buffer);
900 util_dump_member(stream, uint, state, buffer_offset);
901 util_dump_member(stream, uint, state, buffer_size);
902
903 util_dump_struct_end(stream);
904 }
905
906
907 void
util_dump_draw_info(FILE * stream,const struct pipe_draw_info * state)908 util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
909 {
910 if (!state) {
911 util_dump_null(stream);
912 return;
913 }
914
915 util_dump_struct_begin(stream, "pipe_draw_info");
916
917 util_dump_member(stream, uint, state, index_size);
918 util_dump_member(stream, uint, state, has_user_indices);
919
920 util_dump_member(stream, enum_prim_mode, state, mode);
921
922 util_dump_member(stream, uint, state, start_instance);
923 util_dump_member(stream, uint, state, instance_count);
924
925 util_dump_member(stream, uint, state, min_index);
926 util_dump_member(stream, uint, state, max_index);
927
928 util_dump_member(stream, bool, state, primitive_restart);
929 if (state->primitive_restart)
930 util_dump_member(stream, uint, state, restart_index);
931
932 if (state->index_size) {
933 if (state->has_user_indices)
934 util_dump_member(stream, ptr, state, index.user);
935 else
936 util_dump_member(stream, ptr, state, index.resource);
937 }
938 util_dump_struct_end(stream);
939 }
940
941 void
util_dump_draw_start_count_bias(FILE * stream,const struct pipe_draw_start_count_bias * state)942 util_dump_draw_start_count_bias(FILE *stream, const struct pipe_draw_start_count_bias *state)
943 {
944 util_dump_struct_begin(stream, "pipe_draw_start_count_bias");
945 util_dump_member(stream, uint, state, start);
946 util_dump_member(stream, uint, state, count);
947 util_dump_member(stream, int, state, index_bias);
948 util_dump_struct_end(stream);
949 }
950
951 void
util_dump_draw_indirect_info(FILE * stream,const struct pipe_draw_indirect_info * state)952 util_dump_draw_indirect_info(FILE *stream,
953 const struct pipe_draw_indirect_info *state)
954 {
955 if (!state) {
956 util_dump_null(stream);
957 return;
958 }
959
960 util_dump_struct_begin(stream, "pipe_draw_indirect_info");
961 util_dump_member(stream, uint, state, offset);
962 util_dump_member(stream, uint, state, stride);
963 util_dump_member(stream, uint, state, draw_count);
964 util_dump_member(stream, uint, state, indirect_draw_count_offset);
965 util_dump_member(stream, ptr, state, buffer);
966 util_dump_member(stream, ptr, state, indirect_draw_count);
967 util_dump_member(stream, ptr, state, count_from_stream_output);
968 util_dump_struct_end(stream);
969 }
970
util_dump_grid_info(FILE * stream,const struct pipe_grid_info * state)971 void util_dump_grid_info(FILE *stream, const struct pipe_grid_info *state)
972 {
973 if (!state) {
974 util_dump_null(stream);
975 return;
976 }
977
978 util_dump_struct_begin(stream, "pipe_grid_info");
979
980 util_dump_member(stream, uint, state, pc);
981 util_dump_member(stream, ptr, state, input);
982 util_dump_member(stream, uint, state, work_dim);
983
984 util_dump_member_begin(stream, "block");
985 util_dump_array(stream, uint, state->block, ARRAY_SIZE(state->block));
986 util_dump_member_end(stream);
987
988 util_dump_member_begin(stream, "grid");
989 util_dump_array(stream, uint, state->grid, ARRAY_SIZE(state->grid));
990 util_dump_member_end(stream);
991
992 util_dump_member(stream, ptr, state, indirect);
993 util_dump_member(stream, uint, state, indirect_offset);
994
995 util_dump_struct_end(stream);
996 }
997
util_dump_box(FILE * stream,const struct pipe_box * box)998 void util_dump_box(FILE *stream, const struct pipe_box *box)
999 {
1000 if (!box) {
1001 util_dump_null(stream);
1002 return;
1003 }
1004
1005 util_dump_struct_begin(stream, "pipe_box");
1006
1007 util_dump_member(stream, int, box, x);
1008 util_dump_member(stream, int, box, y);
1009 util_dump_member(stream, int, box, z);
1010 util_dump_member(stream, int, box, width);
1011 util_dump_member(stream, int, box, height);
1012 util_dump_member(stream, int, box, depth);
1013
1014 util_dump_struct_end(stream);
1015 }
1016
util_dump_blit_info(FILE * stream,const struct pipe_blit_info * info)1017 void util_dump_blit_info(FILE *stream, const struct pipe_blit_info *info)
1018 {
1019 char mask[7];
1020
1021 if (!info) {
1022 util_dump_null(stream);
1023 return;
1024 }
1025
1026 util_dump_struct_begin(stream, "pipe_blit_info");
1027
1028 util_dump_member_begin(stream, "dst");
1029 util_dump_struct_begin(stream, "dst");
1030 util_dump_member(stream, ptr, &info->dst, resource);
1031 util_dump_member(stream, uint, &info->dst, level);
1032 util_dump_member(stream, format, &info->dst, format);
1033 util_dump_member_begin(stream, "box");
1034 util_dump_box(stream, &info->dst.box);
1035 util_dump_member_end(stream);
1036 util_dump_struct_end(stream);
1037 util_dump_member_end(stream);
1038
1039 util_dump_member_begin(stream, "src");
1040 util_dump_struct_begin(stream, "src");
1041 util_dump_member(stream, ptr, &info->src, resource);
1042 util_dump_member(stream, uint, &info->src, level);
1043 util_dump_member(stream, format, &info->src, format);
1044 util_dump_member_begin(stream, "box");
1045 util_dump_box(stream, &info->src.box);
1046 util_dump_member_end(stream);
1047 util_dump_struct_end(stream);
1048 util_dump_member_end(stream);
1049
1050 mask[0] = (info->mask & PIPE_MASK_R) ? 'R' : '-';
1051 mask[1] = (info->mask & PIPE_MASK_G) ? 'G' : '-';
1052 mask[2] = (info->mask & PIPE_MASK_B) ? 'B' : '-';
1053 mask[3] = (info->mask & PIPE_MASK_A) ? 'A' : '-';
1054 mask[4] = (info->mask & PIPE_MASK_Z) ? 'Z' : '-';
1055 mask[5] = (info->mask & PIPE_MASK_S) ? 'S' : '-';
1056 mask[6] = 0;
1057
1058 util_dump_member_begin(stream, "mask");
1059 util_dump_string(stream, mask);
1060 util_dump_member_end(stream);
1061 util_dump_member(stream, enum_tex_filter, info, filter);
1062
1063 util_dump_member(stream, bool, info, scissor_enable);
1064 util_dump_member_begin(stream, "scissor");
1065 util_dump_scissor_state(stream, &info->scissor);
1066 util_dump_member_end(stream);
1067
1068 util_dump_member(stream, bool, info, render_condition_enable);
1069
1070 util_dump_struct_end(stream);
1071 }
1072