u_dump_state.c 29.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/**************************************************************************
 *
 * Copyright 2008-2010 VMware, Inc.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/


#include "pipe/p_compiler.h"
#include "util/u_memory.h"
#include "util/u_string.h"
32
#include "util/format/u_format.h"
33 34
#include "tgsi/tgsi_dump.h"

35 36
#include <inttypes.h>

37 38 39 40 41 42 43
#include "u_dump.h"


/*
 * Dump primitives
 */

44
static inline void
45
util_stream_writef(FILE *stream, const char *format, ...)
46 47 48 49 50
{
   static char buf[1024];
   unsigned len;
   va_list ap;
   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
57
util_dump_bool(FILE *stream, int value)
58 59 60 61 62
{
   util_stream_writef(stream, "%c", value ? '1' : '0');
}

static void
63
util_dump_int(FILE *stream, long long int value)
64 65 66 67 68
{
   util_stream_writef(stream, "%lli", value);
}

static void
69
util_dump_uint(FILE *stream, long long unsigned value)
70 71 72 73 74
{
   util_stream_writef(stream, "%llu", value);
}

static void
75
util_dump_float(FILE *stream, double value)
76 77 78 79
{
   util_stream_writef(stream, "%g", value);
}

80 81 82 83 84 85 86 87
void
util_dump_ns(FILE *f, uint64_t time)
{
   uint64_t secs = time / (1000*1000*1000);
   unsigned usecs = (time % (1000*1000*1000)) / 1000;
   fprintf(f, "%"PRIu64".%06us", secs, usecs);
}

88
static void
89
util_dump_string(FILE *stream, const char *str)
90
{
91 92 93
   fputs("\"", stream);
   fputs(str, stream);
   fputs("\"", stream);
94 95 96
}

static void
97
util_dump_enum(FILE *stream, const char *value)
98
{
99
   fputs(value, stream);
100 101 102
}

static void
103
util_dump_array_begin(FILE *stream)
104
{
105
   fputs("{", stream);
106 107 108
}

static void
109
util_dump_array_end(FILE *stream)
110
{
111
   fputs("}", stream);
112 113 114
}

static void
115
util_dump_elem_begin(UNUSED FILE *stream)
116 117 118 119
{
}

static void
120
util_dump_elem_end(FILE *stream)
121
{
122
   fputs(", ", stream);
123 124 125
}

static void
126
util_dump_struct_begin(FILE *stream, UNUSED const char *name)
127
{
128
   fputs("{", stream);
129 130 131
}

static void
132
util_dump_struct_end(FILE *stream)
133
{
134
   fputs("}", stream);
135 136 137
}

static void
138
util_dump_member_begin(FILE *stream, const char *name)
139 140 141 142 143
{
   util_stream_writef(stream, "%s = ", name);
}

static void
144
util_dump_member_end(FILE *stream)
145
{
146
   fputs(", ", stream);
147 148 149
}

static void
150
util_dump_null(FILE *stream)
151
{
152
   fputs("NULL", stream);
153 154
}

155
void
156
util_dump_ptr(FILE *stream, const void *value)
157 158
{
   if(value)
159
      util_stream_writef(stream, "%p", value);
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
   else
      util_dump_null(stream);
}


/*
 * Code saving macros.
 */

#define util_dump_arg(_stream, _type, _arg) \
   do { \
      util_dump_arg_begin(_stream, #_arg); \
      util_dump_##_type(_stream, _arg); \
      util_dump_arg_end(_stream); \
   } while(0)

#define util_dump_ret(_stream, _type, _arg) \
   do { \
      util_dump_ret_begin(_stream); \
      util_dump_##_type(_stream, _arg); \
      util_dump_ret_end(_stream); \
   } while(0)

#define util_dump_array(_stream, _type, _obj, _size) \
   do { \
      size_t idx; \
      util_dump_array_begin(_stream); \
      for(idx = 0; idx < (_size); ++idx) { \
         util_dump_elem_begin(_stream); \
         util_dump_##_type(_stream, (_obj)[idx]); \
         util_dump_elem_end(_stream); \
      } \
      util_dump_array_end(_stream); \
   } while(0)

#define util_dump_struct_array(_stream, _type, _obj, _size) \
   do { \
      size_t idx; \
      util_dump_array_begin(_stream); \
      for(idx = 0; idx < (_size); ++idx) { \
         util_dump_elem_begin(_stream); \
         util_dump_##_type(_stream, &(_obj)[idx]); \
         util_dump_elem_end(_stream); \
      } \
      util_dump_array_end(_stream); \
   } while(0)

#define util_dump_member(_stream, _type, _obj, _member) \
   do { \
      util_dump_member_begin(_stream, #_member); \
      util_dump_##_type(_stream, (_obj)->_member); \
      util_dump_member_end(_stream); \
   } while(0)

#define util_dump_arg_array(_stream, _type, _arg, _size) \
   do { \
      util_dump_arg_begin(_stream, #_arg); \
      util_dump_array(_stream, _type, _arg, _size); \
      util_dump_arg_end(_stream); \
   } while(0)

#define util_dump_member_array(_stream, _type, _obj, _member) \
   do { \
      util_dump_member_begin(_stream, #_member); \
      util_dump_array(_stream, _type, (_obj)->_member, sizeof((_obj)->_member)/sizeof((_obj)->_member[0])); \
      util_dump_member_end(_stream); \
   } while(0)



/*
 * Wrappers for enum -> string dumpers.
 */


static void
236
util_dump_format(FILE *stream, enum pipe_format format)
237 238 239 240 241 242
{
   util_dump_enum(stream, util_format_name(format));
}


static void
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
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
255
util_dump_enum_func(FILE *stream, unsigned value)
256
{
257
   util_dump_enum(stream, util_str_func(value, TRUE));
258 259
}

260 261 262
static void
util_dump_enum_prim_mode(FILE *stream, unsigned value)
{
263
   util_dump_enum(stream, util_str_prim_mode(value, TRUE));
264 265 266 267 268
}

static void
util_dump_enum_tex_target(FILE *stream, unsigned value)
{
269
   util_dump_enum(stream, util_str_tex_target(value, TRUE));
270 271 272 273 274
}

static void
util_dump_enum_tex_filter(FILE *stream, unsigned value)
{
275
   util_dump_enum(stream, util_str_tex_filter(value, TRUE));
276 277 278 279 280
}

static void
util_dump_enum_tex_mipfilter(FILE *stream, unsigned value)
{
281
   util_dump_enum(stream, util_str_tex_mipfilter(value, TRUE));
282 283 284 285 286
}

static void
util_dump_enum_tex_wrap(FILE *stream, unsigned value)
{
287
   util_dump_enum(stream, util_str_tex_wrap(value, TRUE));
288 289 290 291 292
}

static void
util_dump_enum_stencil_op(FILE *stream, unsigned value)
{
293
   util_dump_enum(stream, util_str_stencil_op(value, TRUE));
294 295
}

296 297 298 299 300 301 302

/*
 * Public functions
 */


void
303
util_dump_resource(FILE *stream, const struct pipe_resource *state)
304
{
305
   if (!state) {
306 307 308 309
      util_dump_null(stream);
      return;
   }

310
   util_dump_struct_begin(stream, "pipe_resource");
311

312 313
   util_dump_member(stream, enum_tex_target, state, target);
   util_dump_member(stream, format, state, format);
314

315 316 317 318
   util_dump_member(stream, uint, state, width0);
   util_dump_member(stream, uint, state, height0);
   util_dump_member(stream, uint, state, depth0);
   util_dump_member(stream, uint, state, array_size);
319

320 321
   util_dump_member(stream, uint, state, last_level);
   util_dump_member(stream, uint, state, nr_samples);
322
   util_dump_member(stream, uint, state, nr_storage_samples);
323 324 325
   util_dump_member(stream, uint, state, usage);
   util_dump_member(stream, uint, state, bind);
   util_dump_member(stream, uint, state, flags);
326 327 328 329 330 331

   util_dump_struct_end(stream);
}


void
332
util_dump_rasterizer_state(FILE *stream, const struct pipe_rasterizer_state *state)
333
{
334
   if (!state) {
335 336 337 338 339 340 341 342
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_rasterizer_state");

   util_dump_member(stream, bool, state, flatshade);
   util_dump_member(stream, bool, state, light_twoside);
343 344
   util_dump_member(stream, bool, state, clamp_vertex_color);
   util_dump_member(stream, bool, state, clamp_fragment_color);
345 346 347 348 349 350 351
   util_dump_member(stream, uint, state, front_ccw);
   util_dump_member(stream, uint, state, cull_face);
   util_dump_member(stream, uint, state, fill_front);
   util_dump_member(stream, uint, state, fill_back);
   util_dump_member(stream, bool, state, offset_point);
   util_dump_member(stream, bool, state, offset_line);
   util_dump_member(stream, bool, state, offset_tri);
352 353 354 355 356 357 358
   util_dump_member(stream, bool, state, scissor);
   util_dump_member(stream, bool, state, poly_smooth);
   util_dump_member(stream, bool, state, poly_stipple_enable);
   util_dump_member(stream, bool, state, point_smooth);
   util_dump_member(stream, uint, state, sprite_coord_enable);
   util_dump_member(stream, bool, state, sprite_coord_mode);
   util_dump_member(stream, bool, state, point_quad_rasterization);
359
   util_dump_member(stream, bool, state, point_tri_clip);
360 361 362 363 364 365 366 367
   util_dump_member(stream, bool, state, point_size_per_vertex);
   util_dump_member(stream, bool, state, multisample);
   util_dump_member(stream, bool, state, line_smooth);
   util_dump_member(stream, bool, state, line_stipple_enable);
   util_dump_member(stream, uint, state, line_stipple_factor);
   util_dump_member(stream, uint, state, line_stipple_pattern);
   util_dump_member(stream, bool, state, line_last_pixel);
   util_dump_member(stream, bool, state, flatshade_first);
368 369
   util_dump_member(stream, bool, state, half_pixel_center);
   util_dump_member(stream, bool, state, bottom_edge_rule);
370
   util_dump_member(stream, bool, state, rasterizer_discard);
371 372
   util_dump_member(stream, bool, state, depth_clip_near);
   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 377 378 379

   util_dump_member(stream, float, state, line_width);
   util_dump_member(stream, float, state, point_size);
   util_dump_member(stream, float, state, offset_units);
   util_dump_member(stream, float, state, offset_scale);
380
   util_dump_member(stream, float, state, offset_clamp);
381 382 383 384 385 386

   util_dump_struct_end(stream);
}


void
387
util_dump_poly_stipple(FILE *stream, const struct pipe_poly_stipple *state)
388
{
389
   if (!state) {
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_poly_stipple");

   util_dump_member_begin(stream, "stipple");
   util_dump_member_array(stream, uint, state, stipple);
   util_dump_member_end(stream);

   util_dump_struct_end(stream);
}


void
405
util_dump_viewport_state(FILE *stream, const struct pipe_viewport_state *state)
406
{
407
   if (!state) {
408 409 410 411 412 413 414 415 416 417 418 419 420 421
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_viewport_state");

   util_dump_member_array(stream, float, state, scale);
   util_dump_member_array(stream, float, state, translate);

   util_dump_struct_end(stream);
}


void
422
util_dump_scissor_state(FILE *stream, const struct pipe_scissor_state *state)
423
{
424
   if (!state) {
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_scissor_state");

   util_dump_member(stream, uint, state, minx);
   util_dump_member(stream, uint, state, miny);
   util_dump_member(stream, uint, state, maxx);
   util_dump_member(stream, uint, state, maxy);

   util_dump_struct_end(stream);
}


void
441
util_dump_clip_state(FILE *stream, const struct pipe_clip_state *state)
442 443 444
{
   unsigned i;

445
   if (!state) {
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_clip_state");

   util_dump_member_begin(stream, "ucp");
   util_dump_array_begin(stream);
   for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) {
      util_dump_elem_begin(stream);
      util_dump_array(stream, float, state->ucp[i], 4);
      util_dump_elem_end(stream);
   }
   util_dump_array_end(stream);
   util_dump_member_end(stream);

   util_dump_struct_end(stream);
}


void
467
util_dump_shader_state(FILE *stream, const struct pipe_shader_state *state)
468
{
469
   unsigned i;
470

471
   if (!state) {
472 473 474 475 476 477
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_shader_state");

478 479 480 481 482 483 484
   if (state->type == PIPE_SHADER_IR_TGSI) {
      util_dump_member_begin(stream, "tokens");
      fprintf(stream, "\"\n");
      tgsi_dump_to_file(state->tokens, 0, stream);
      fprintf(stream, "\"");
      util_dump_member_end(stream);
   }
485

486 487 488 489 490
   if (state->stream_output.num_outputs) {
      util_dump_member_begin(stream, "stream_output");
      util_dump_struct_begin(stream, "pipe_stream_output_info");
      util_dump_member(stream, uint, &state->stream_output, num_outputs);
      util_dump_array(stream, uint, state->stream_output.stride,
491
                      ARRAY_SIZE(state->stream_output.stride));
492 493 494 495 496 497 498 499 500 501 502 503
      util_dump_array_begin(stream);
      for(i = 0; i < state->stream_output.num_outputs; ++i) {
         util_dump_elem_begin(stream);
         util_dump_struct_begin(stream, ""); /* anonymous */
         util_dump_member(stream, uint, &state->stream_output.output[i], register_index);
         util_dump_member(stream, uint, &state->stream_output.output[i], start_component);
         util_dump_member(stream, uint, &state->stream_output.output[i], num_components);
         util_dump_member(stream, uint, &state->stream_output.output[i], output_buffer);
         util_dump_struct_end(stream);
         util_dump_elem_end(stream);
      }
      util_dump_array_end(stream);
504
      util_dump_struct_end(stream);
505
      util_dump_member_end(stream);
506 507
   }

508 509 510 511 512
   util_dump_struct_end(stream);
}


void
513
util_dump_depth_stencil_alpha_state(FILE *stream, const struct pipe_depth_stencil_alpha_state *state)
514 515 516
{
   unsigned i;

517
   if (!state) {
518 519 520 521 522 523 524 525 526
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_depth_stencil_alpha_state");

   util_dump_member_begin(stream, "depth");
   util_dump_struct_begin(stream, "pipe_depth_state");
   util_dump_member(stream, bool, &state->depth, enabled);
527 528 529 530
   if (state->depth.enabled) {
      util_dump_member(stream, bool, &state->depth, writemask);
      util_dump_member(stream, enum_func, &state->depth, func);
   }
531 532 533 534 535
   util_dump_struct_end(stream);
   util_dump_member_end(stream);

   util_dump_member_begin(stream, "stencil");
   util_dump_array_begin(stream);
536
   for(i = 0; i < ARRAY_SIZE(state->stencil); ++i) {
537 538 539
      util_dump_elem_begin(stream);
      util_dump_struct_begin(stream, "pipe_stencil_state");
      util_dump_member(stream, bool, &state->stencil[i], enabled);
540 541
      if (state->stencil[i].enabled) {
         util_dump_member(stream, enum_func, &state->stencil[i], func);
542 543 544 545 546 547
         util_dump_member(stream, enum_stencil_op,
                          &state->stencil[i], fail_op);
         util_dump_member(stream, enum_stencil_op,
                          &state->stencil[i], zpass_op);
         util_dump_member(stream, enum_stencil_op,
                          &state->stencil[i], zfail_op);
548 549 550
         util_dump_member(stream, uint, &state->stencil[i], valuemask);
         util_dump_member(stream, uint, &state->stencil[i], writemask);
      }
551 552 553 554 555 556 557 558 559
      util_dump_struct_end(stream);
      util_dump_elem_end(stream);
   }
   util_dump_array_end(stream);
   util_dump_member_end(stream);

   util_dump_member_begin(stream, "alpha");
   util_dump_struct_begin(stream, "pipe_alpha_state");
   util_dump_member(stream, bool, &state->alpha, enabled);
560 561 562 563
   if (state->alpha.enabled) {
      util_dump_member(stream, enum_func, &state->alpha, func);
      util_dump_member(stream, float, &state->alpha, ref_value);
   }
564 565 566 567 568 569 570
   util_dump_struct_end(stream);
   util_dump_member_end(stream);

   util_dump_struct_end(stream);
}

void
571
util_dump_rt_blend_state(FILE *stream, const struct pipe_rt_blend_state *state)
572 573 574 575
{
   util_dump_struct_begin(stream, "pipe_rt_blend_state");

   util_dump_member(stream, uint, state, blend_enable);
576 577 578 579 580 581 582 583 584
   if (state->blend_enable) {
      util_dump_member(stream, enum_blend_func, state, rgb_func);
      util_dump_member(stream, enum_blend_factor, state, rgb_src_factor);
      util_dump_member(stream, enum_blend_factor, state, rgb_dst_factor);

      util_dump_member(stream, enum_blend_func, state, alpha_func);
      util_dump_member(stream, enum_blend_factor, state, alpha_src_factor);
      util_dump_member(stream, enum_blend_factor, state, alpha_dst_factor);
   }
585 586 587 588 589 590 591

   util_dump_member(stream, uint, state, colormask);

   util_dump_struct_end(stream);
}

void
592
util_dump_blend_state(FILE *stream, const struct pipe_blend_state *state)
593 594 595
{
   unsigned valid_entries = 1;

596
   if (!state) {
597 598 599 600 601 602 603
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_blend_state");

   util_dump_member(stream, bool, state, dither);
604 605
   util_dump_member(stream, bool, state, alpha_to_coverage);
   util_dump_member(stream, bool, state, alpha_to_one);
606
   util_dump_member(stream, uint, state, max_rt);
607 608

   util_dump_member(stream, bool, state, logicop_enable);
609 610 611 612 613 614 615 616
   if (state->logicop_enable) {
      util_dump_member(stream, enum_func, state, logicop_func);
   }
   else {
      util_dump_member(stream, bool, state, independent_blend_enable);

      util_dump_member_begin(stream, "rt");
      if (state->independent_blend_enable)
617
         valid_entries = state->max_rt + 1;
618 619 620
      util_dump_struct_array(stream, rt_blend_state, state->rt, valid_entries);
      util_dump_member_end(stream);
   }
621 622 623 624 625 626

   util_dump_struct_end(stream);
}


void
627
util_dump_blend_color(FILE *stream, const struct pipe_blend_color *state)
628
{
629
   if (!state) {
630 631 632 633 634 635 636 637 638 639 640 641
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_blend_color");

   util_dump_member_array(stream, float, state, color);

   util_dump_struct_end(stream);
}

void
642
util_dump_stencil_ref(FILE *stream, const struct pipe_stencil_ref *state)
643
{
644
   if (!state) {
645 646 647 648 649 650 651 652 653 654 655 656
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_stencil_ref");

   util_dump_member_array(stream, uint, state, ref_value);

   util_dump_struct_end(stream);
}

void
657
util_dump_framebuffer_state(FILE *stream, const struct pipe_framebuffer_state *state)
658 659 660 661 662
{
   util_dump_struct_begin(stream, "pipe_framebuffer_state");

   util_dump_member(stream, uint, state, width);
   util_dump_member(stream, uint, state, height);
663 664
   util_dump_member(stream, uint, state, samples);
   util_dump_member(stream, uint, state, layers);
665 666 667 668 669 670 671 672 673
   util_dump_member(stream, uint, state, nr_cbufs);
   util_dump_member_array(stream, ptr, state, cbufs);
   util_dump_member(stream, ptr, state, zsbuf);

   util_dump_struct_end(stream);
}


void
674
util_dump_sampler_state(FILE *stream, const struct pipe_sampler_state *state)
675
{
676
   if (!state) {
677 678 679 680 681 682
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_sampler_state");

683 684 685 686 687 688
   util_dump_member(stream, enum_tex_wrap, state, wrap_s);
   util_dump_member(stream, enum_tex_wrap, state, wrap_t);
   util_dump_member(stream, enum_tex_wrap, state, wrap_r);
   util_dump_member(stream, enum_tex_filter, state, min_img_filter);
   util_dump_member(stream, enum_tex_mipfilter, state, min_mip_filter);
   util_dump_member(stream, enum_tex_filter, state, mag_img_filter);
689
   util_dump_member(stream, uint, state, compare_mode);
690
   util_dump_member(stream, enum_func, state, compare_func);
691 692
   util_dump_member(stream, bool, state, normalized_coords);
   util_dump_member(stream, uint, state, max_anisotropy);
693
   util_dump_member(stream, bool, state, seamless_cube_map);
694 695 696
   util_dump_member(stream, float, state, lod_bias);
   util_dump_member(stream, float, state, min_lod);
   util_dump_member(stream, float, state, max_lod);
697
   util_dump_member_array(stream, float, state, border_color.f);
698 699 700 701 702 703

   util_dump_struct_end(stream);
}


void
704
util_dump_surface(FILE *stream, const struct pipe_surface *state)
705
{
706
   if (!state) {
707 708 709 710 711 712 713 714 715 716 717
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_surface");

   util_dump_member(stream, format, state, format);
   util_dump_member(stream, uint, state, width);
   util_dump_member(stream, uint, state, height);

   util_dump_member(stream, ptr, state, texture);
718 719 720
   util_dump_member(stream, uint, state, u.tex.level);
   util_dump_member(stream, uint, state, u.tex.first_layer);
   util_dump_member(stream, uint, state, u.tex.last_layer);
721 722 723 724 725

   util_dump_struct_end(stream);
}


726 727 728 729 730 731 732 733 734 735 736 737 738 739
void
util_dump_image_view(FILE *stream, const struct pipe_image_view *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_image_view");

   util_dump_member(stream, ptr, state, resource);
   util_dump_member(stream, format, state, format);

   if (state->resource->target == PIPE_BUFFER) {
740 741
      util_dump_member(stream, uint, state, u.buf.offset);
      util_dump_member(stream, uint, state, u.buf.size);
742 743 744 745 746 747 748 749 750 751 752
   }
   else {
      util_dump_member(stream, uint, state, u.tex.first_layer);
      util_dump_member(stream, uint, state, u.tex.last_layer);
      util_dump_member(stream, uint, state, u.tex.level);
   }

   util_dump_struct_end(stream);
}


753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
void
util_dump_shader_buffer(FILE *stream, const struct pipe_shader_buffer *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_shader_buffer");

   util_dump_member(stream, ptr, state, buffer);
   util_dump_member(stream, uint, state, buffer_offset);
   util_dump_member(stream, uint, state, buffer_size);

   util_dump_struct_end(stream);

}


772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
void
util_dump_sampler_view(FILE *stream, const struct pipe_sampler_view *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_sampler_view");

   util_dump_member(stream, enum_tex_target, state, target);
   util_dump_member(stream, format, state, format);
   util_dump_member(stream, ptr, state, texture);

   if (state->target == PIPE_BUFFER) {
787 788
      util_dump_member(stream, uint, state, u.buf.offset);
      util_dump_member(stream, uint, state, u.buf.size);
789 790 791 792
   }
   else {
      util_dump_member(stream, uint, state, u.tex.first_layer);
      util_dump_member(stream, uint, state, u.tex.last_layer);
793
      util_dump_member(stream, uint, state, u.tex.first_level);
794 795 796 797 798 799 800 801 802 803 804 805
      util_dump_member(stream, uint, state, u.tex.last_level);
   }

   util_dump_member(stream, uint, state, swizzle_r);
   util_dump_member(stream, uint, state, swizzle_g);
   util_dump_member(stream, uint, state, swizzle_b);
   util_dump_member(stream, uint, state, swizzle_a);

   util_dump_struct_end(stream);
}


806
void
807
util_dump_transfer(FILE *stream, const struct pipe_transfer *state)
808
{
809
   if (!state) {
810 811 812 813 814 815
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_transfer");

816
   util_dump_member(stream, ptr, state, resource);
817
   util_dump_member(stream, uint, state, level);
818
   util_dump_member(stream, transfer_usage, state, usage);
819 820 821
   util_dump_member_begin(stream, "box");
   util_dump_box(stream, &state->box);
   util_dump_member_end(stream);
822
   util_dump_member(stream, uint, state, stride);
823
   util_dump_member(stream, uint, state, layer_stride);
824 825 826 827 828

   util_dump_struct_end(stream);
}


829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
void
util_dump_constant_buffer(FILE *stream,
                          const struct pipe_constant_buffer *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_constant_buffer");

   util_dump_member(stream, ptr, state, buffer);
   util_dump_member(stream, uint, state, buffer_offset);
   util_dump_member(stream, uint, state, buffer_size);
   util_dump_member(stream, ptr, state, user_buffer);

   util_dump_struct_end(stream);
}


849
void
850
util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state)
851
{
852
   if (!state) {
853 854 855 856 857 858 859
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_vertex_buffer");

   util_dump_member(stream, uint, state, stride);
860
   util_dump_member(stream, bool, state, is_user_buffer);
861
   util_dump_member(stream, uint, state, buffer_offset);
862
   util_dump_member(stream, ptr, state, buffer.resource);
863 864 865 866 867 868

   util_dump_struct_end(stream);
}


void
869
util_dump_vertex_element(FILE *stream, const struct pipe_vertex_element *state)
870
{
871
   if (!state) {
872 873 874 875 876 877 878
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_vertex_element");

   util_dump_member(stream, uint, state, src_offset);
879
   util_dump_member(stream, uint, state, instance_divisor);
880 881 882 883 884
   util_dump_member(stream, uint, state, vertex_buffer_index);
   util_dump_member(stream, format, state, src_format);

   util_dump_struct_end(stream);
}
885 886


887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
void
util_dump_stream_output_target(FILE *stream,
                               const struct pipe_stream_output_target *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_stream_output_target");

   util_dump_member(stream, ptr, state, buffer);
   util_dump_member(stream, uint, state, buffer_offset);
   util_dump_member(stream, uint, state, buffer_size);

   util_dump_struct_end(stream);
}


906 907 908
void
util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
{
909
   if (!state) {
910 911 912 913 914 915
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_draw_info");

916 917
   util_dump_member(stream, uint, state, index_size);
   util_dump_member(stream, uint, state, has_user_indices);
918

919
   util_dump_member(stream, enum_prim_mode, state, mode);
920 921 922 923 924 925
   util_dump_member(stream, uint, state, start);
   util_dump_member(stream, uint, state, count);

   util_dump_member(stream, uint, state, start_instance);
   util_dump_member(stream, uint, state, instance_count);

926 927
   util_dump_member(stream, uint, state, drawid);

928 929
   util_dump_member(stream, uint, state, vertices_per_patch);

930 931 932 933 934
   util_dump_member(stream, int,  state, index_bias);
   util_dump_member(stream, uint, state, min_index);
   util_dump_member(stream, uint, state, max_index);

   util_dump_member(stream, bool, state, primitive_restart);
935 936
   if (state->primitive_restart)
      util_dump_member(stream, uint, state, restart_index);
937

938 939 940 941 942 943
   if (state->index_size) {
      if (state->has_user_indices)
         util_dump_member(stream, ptr, state, index.user);
      else
         util_dump_member(stream, ptr, state, index.resource);
   }
944

945 946 947 948 949 950 951 952 953
   if (!state->indirect) {
      util_dump_member(stream, ptr, state, indirect);
   } else {
      util_dump_member(stream, uint, state, indirect->offset);
      util_dump_member(stream, uint, state, indirect->stride);
      util_dump_member(stream, uint, state, indirect->draw_count);
      util_dump_member(stream, uint, state, indirect->indirect_draw_count_offset);
      util_dump_member(stream, ptr, state, indirect->buffer);
      util_dump_member(stream, ptr, state, indirect->indirect_draw_count);
954
      util_dump_member(stream, ptr, state, indirect->count_from_stream_output);
955
   }
956

957 958
   util_dump_struct_end(stream);
}
959

960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
void util_dump_grid_info(FILE *stream, const struct pipe_grid_info *state)
{
   if (!state) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_grid_info");

   util_dump_member(stream, uint, state, pc);
   util_dump_member(stream, ptr, state, input);
   util_dump_member(stream, uint, state, work_dim);

   util_dump_member_begin(stream, "block");
   util_dump_array(stream, uint, state->block, ARRAY_SIZE(state->block));
   util_dump_member_end(stream);

   util_dump_member_begin(stream, "grid");
   util_dump_array(stream, uint, state->grid, ARRAY_SIZE(state->grid));
   util_dump_member_end(stream);

   util_dump_member(stream, ptr, state, indirect);
   util_dump_member(stream, uint, state, indirect_offset);

   util_dump_struct_end(stream);
}

987 988
void util_dump_box(FILE *stream, const struct pipe_box *box)
{
989
   if (!box) {
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_box");

   util_dump_member(stream, int, box, x);
   util_dump_member(stream, int, box, y);
   util_dump_member(stream, int, box, z);
   util_dump_member(stream, int, box, width);
   util_dump_member(stream, int, box, height);
   util_dump_member(stream, int, box, depth);

   util_dump_struct_end(stream);
}

void util_dump_blit_info(FILE *stream, const struct pipe_blit_info *info)
{
   char mask[7];

   if (!info) {
      util_dump_null(stream);
      return;
   }

   util_dump_struct_begin(stream, "pipe_blit_info");

   util_dump_member_begin(stream, "dst");
   util_dump_struct_begin(stream, "dst");
   util_dump_member(stream, ptr, &info->dst, resource);
   util_dump_member(stream, uint, &info->dst, level);
   util_dump_member(stream, format, &info->dst, format);
   util_dump_member_begin(stream, "box");
   util_dump_box(stream, &info->dst.box);
   util_dump_member_end(stream);
   util_dump_struct_end(stream);
   util_dump_member_end(stream);

   util_dump_member_begin(stream, "src");
   util_dump_struct_begin(stream, "src");
   util_dump_member(stream, ptr, &info->src, resource);
   util_dump_member(stream, uint, &info->src, level);
   util_dump_member(stream, format, &info->src, format);
   util_dump_member_begin(stream, "box");
   util_dump_box(stream, &info->src.box);
   util_dump_member_end(stream);
   util_dump_struct_end(stream);
   util_dump_member_end(stream);

   mask[0] = (info->mask & PIPE_MASK_R) ? 'R' : '-';
   mask[1] = (info->mask & PIPE_MASK_G) ? 'G' : '-';
   mask[2] = (info->mask & PIPE_MASK_B) ? 'B' : '-';
   mask[3] = (info->mask & PIPE_MASK_A) ? 'A' : '-';
   mask[4] = (info->mask & PIPE_MASK_Z) ? 'Z' : '-';
   mask[5] = (info->mask & PIPE_MASK_S) ? 'S' : '-';
   mask[6] = 0;

   util_dump_member_begin(stream, "mask");
   util_dump_string(stream, mask);
   util_dump_member_end(stream);
1050
   util_dump_member(stream, enum_tex_filter, info, filter);
1051 1052 1053 1054 1055 1056

   util_dump_member(stream, bool, info, scissor_enable);
   util_dump_member_begin(stream, "scissor");
   util_dump_scissor_state(stream, &info->scissor);
   util_dump_member_end(stream);

1057 1058
   util_dump_member(stream, bool, info, render_condition_enable);

1059 1060
   util_dump_struct_end(stream);
}