f82dd01c697385d709195bfcfffca2b73df27365
[profile/ivi/mesa.git] / src / gallium / drivers / trace / tr_dump_state.c
1 /**************************************************************************
2  *
3  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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_format.h"
32 #include "tgsi/tgsi_dump.h"
33
34 #include "tr_dump.h"
35 #include "tr_dump_state.h"
36
37
38 void trace_dump_format(enum pipe_format format)
39 {
40    if (!trace_dumping_enabled_locked())
41       return;
42
43    trace_dump_enum(util_format_name(format) );
44 }
45
46
47 void trace_dump_template(const struct pipe_texture *templat)
48 {
49    if (!trace_dumping_enabled_locked())
50       return;
51
52    if(!templat) {
53       trace_dump_null();
54       return;
55    }
56
57    trace_dump_struct_begin("pipe_texture");
58
59    trace_dump_member(int, templat, target);
60    trace_dump_member(format, templat, format);
61
62    trace_dump_member_begin("width");
63    trace_dump_uint(templat->width0);
64    trace_dump_member_end();
65
66    trace_dump_member_begin("height");
67    trace_dump_uint(templat->height0);
68    trace_dump_member_end();
69
70    trace_dump_member_begin("depth");
71    trace_dump_uint(templat->depth0);
72    trace_dump_member_end();
73
74    trace_dump_member(uint, templat, last_level);
75    trace_dump_member(uint, templat, tex_usage);
76
77    trace_dump_struct_end();
78 }
79
80
81 void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state)
82 {
83    if (!trace_dumping_enabled_locked())
84       return;
85
86    if(!state) {
87       trace_dump_null();
88       return;
89    }
90
91    trace_dump_struct_begin("pipe_rasterizer_state");
92
93    trace_dump_member(bool, state, flatshade);
94    trace_dump_member(bool, state, light_twoside);
95    trace_dump_member(uint, state, front_winding);
96    trace_dump_member(uint, state, cull_mode);
97    trace_dump_member(uint, state, fill_cw);
98    trace_dump_member(uint, state, fill_ccw);
99    trace_dump_member(bool, state, offset_cw);
100    trace_dump_member(bool, state, offset_ccw);
101    trace_dump_member(bool, state, scissor);
102    trace_dump_member(bool, state, poly_smooth);
103    trace_dump_member(bool, state, poly_stipple_enable);
104    trace_dump_member(bool, state, point_smooth);
105    trace_dump_member(uint, state, sprite_coord_enable);
106    trace_dump_member(bool, state, sprite_coord_mode);
107    trace_dump_member(bool, state, point_quad_rasterization);
108    trace_dump_member(bool, state, point_size_per_vertex);
109    trace_dump_member(bool, state, multisample);
110    trace_dump_member(bool, state, line_smooth);
111    trace_dump_member(bool, state, line_stipple_enable);
112    trace_dump_member(uint, state, line_stipple_factor);
113    trace_dump_member(uint, state, line_stipple_pattern);
114    trace_dump_member(bool, state, line_last_pixel);
115    trace_dump_member(bool, state, flatshade_first);
116    trace_dump_member(bool, state, gl_rasterization_rules);
117
118    trace_dump_member(float, state, line_width);
119    trace_dump_member(float, state, point_size);
120    trace_dump_member(float, state, offset_units);
121    trace_dump_member(float, state, offset_scale);
122
123    trace_dump_struct_end();
124 }
125
126
127 void trace_dump_poly_stipple(const struct pipe_poly_stipple *state)
128 {
129    if (!trace_dumping_enabled_locked())
130       return;
131
132    if(!state) {
133       trace_dump_null();
134       return;
135    }
136
137    trace_dump_struct_begin("pipe_poly_stipple");
138
139    trace_dump_member_begin("stipple");
140    trace_dump_array(uint,
141                     state->stipple,
142                     Elements(state->stipple));
143    trace_dump_member_end();
144
145    trace_dump_struct_end();
146 }
147
148
149 void trace_dump_viewport_state(const struct pipe_viewport_state *state)
150 {
151    if (!trace_dumping_enabled_locked())
152       return;
153
154    if(!state) {
155       trace_dump_null();
156       return;
157    }
158
159    trace_dump_struct_begin("pipe_viewport_state");
160
161    trace_dump_member_array(float, state, scale);
162    trace_dump_member_array(float, state, translate);
163
164    trace_dump_struct_end();
165 }
166
167
168 void trace_dump_scissor_state(const struct pipe_scissor_state *state)
169 {
170    if (!trace_dumping_enabled_locked())
171       return;
172
173    if(!state) {
174       trace_dump_null();
175       return;
176    }
177
178    trace_dump_struct_begin("pipe_scissor_state");
179
180    trace_dump_member(uint, state, minx);
181    trace_dump_member(uint, state, miny);
182    trace_dump_member(uint, state, maxx);
183    trace_dump_member(uint, state, maxy);
184
185    trace_dump_struct_end();
186 }
187
188
189 void trace_dump_clip_state(const struct pipe_clip_state *state)
190 {
191    unsigned i;
192
193    if (!trace_dumping_enabled_locked())
194       return;
195
196    if(!state) {
197       trace_dump_null();
198       return;
199    }
200
201    trace_dump_struct_begin("pipe_clip_state");
202
203    trace_dump_member_begin("ucp");
204    trace_dump_array_begin();
205    for(i = 0; i < PIPE_MAX_CLIP_PLANES; ++i) {
206       trace_dump_elem_begin();
207       trace_dump_array(float, state->ucp[i], 4);
208       trace_dump_elem_end();
209    }
210    trace_dump_array_end();
211    trace_dump_member_end();
212
213    trace_dump_member(uint, state, nr);
214
215    trace_dump_struct_end();
216 }
217
218
219 void trace_dump_shader_state(const struct pipe_shader_state *state)
220 {
221    static char str[8192];
222
223    if (!trace_dumping_enabled_locked())
224       return;
225
226    if(!state) {
227       trace_dump_null();
228       return;
229    }
230
231    tgsi_dump_str(state->tokens, 0, str, sizeof(str));
232
233    trace_dump_struct_begin("pipe_shader_state");
234
235    trace_dump_member_begin("tokens");
236    trace_dump_string(str);
237    trace_dump_member_end();
238
239    trace_dump_struct_end();
240 }
241
242
243 void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_state *state)
244 {
245    unsigned i;
246
247    if (!trace_dumping_enabled_locked())
248       return;
249
250    if(!state) {
251       trace_dump_null();
252       return;
253    }
254
255    trace_dump_struct_begin("pipe_depth_stencil_alpha_state");
256
257    trace_dump_member_begin("depth");
258    trace_dump_struct_begin("pipe_depth_state");
259    trace_dump_member(bool, &state->depth, enabled);
260    trace_dump_member(bool, &state->depth, writemask);
261    trace_dump_member(uint, &state->depth, func);
262    trace_dump_struct_end();
263    trace_dump_member_end();
264
265    trace_dump_member_begin("stencil");
266    trace_dump_array_begin();
267    for(i = 0; i < Elements(state->stencil); ++i) {
268       trace_dump_elem_begin();
269       trace_dump_struct_begin("pipe_stencil_state");
270       trace_dump_member(bool, &state->stencil[i], enabled);
271       trace_dump_member(uint, &state->stencil[i], func);
272       trace_dump_member(uint, &state->stencil[i], fail_op);
273       trace_dump_member(uint, &state->stencil[i], zpass_op);
274       trace_dump_member(uint, &state->stencil[i], zfail_op);
275       trace_dump_member(uint, &state->stencil[i], valuemask);
276       trace_dump_member(uint, &state->stencil[i], writemask);
277       trace_dump_struct_end();
278       trace_dump_elem_end();
279    }
280    trace_dump_array_end();
281    trace_dump_member_end();
282
283    trace_dump_member_begin("alpha");
284    trace_dump_struct_begin("pipe_alpha_state");
285    trace_dump_member(bool, &state->alpha, enabled);
286    trace_dump_member(uint, &state->alpha, func);
287    trace_dump_member(float, &state->alpha, ref_value);
288    trace_dump_struct_end();
289    trace_dump_member_end();
290
291    trace_dump_struct_end();
292 }
293
294 void trace_dump_blend_state(const struct pipe_blend_state *state)
295 {
296    if (!trace_dumping_enabled_locked())
297       return;
298
299    if(!state) {
300       trace_dump_null();
301       return;
302    }
303
304    trace_dump_bytes(state, sizeof *state);
305 }
306
307
308 void trace_dump_blend_color(const struct pipe_blend_color *state)
309 {
310    if (!trace_dumping_enabled_locked())
311       return;
312
313    if(!state) {
314       trace_dump_null();
315       return;
316    }
317
318    trace_dump_struct_begin("pipe_blend_color");
319
320    trace_dump_member_array(float, state, color);
321
322    trace_dump_struct_end();
323 }
324
325 void trace_dump_stencil_ref(const struct pipe_stencil_ref *state)
326 {
327    if (!trace_dumping_enabled_locked())
328       return;
329
330    if(!state) {
331       trace_dump_null();
332       return;
333    }
334
335    trace_dump_struct_begin("pipe_stencil_ref");
336
337    trace_dump_member_array(uint, state, ref_value);
338
339    trace_dump_struct_end();
340 }
341
342 void trace_dump_framebuffer_state(const struct pipe_framebuffer_state *state)
343 {
344    if (!trace_dumping_enabled_locked())
345       return;
346
347    trace_dump_struct_begin("pipe_framebuffer_state");
348
349    trace_dump_member(uint, state, width);
350    trace_dump_member(uint, state, height);
351    trace_dump_member(uint, state, nr_cbufs);
352    trace_dump_member_array(ptr, state, cbufs);
353    trace_dump_member(ptr, state, zsbuf);
354
355    trace_dump_struct_end();
356 }
357
358
359 void trace_dump_sampler_state(const struct pipe_sampler_state *state)
360 {
361    if (!trace_dumping_enabled_locked())
362       return;
363
364    if(!state) {
365       trace_dump_null();
366       return;
367    }
368
369    trace_dump_struct_begin("pipe_sampler_state");
370
371    trace_dump_member(uint, state, wrap_s);
372    trace_dump_member(uint, state, wrap_t);
373    trace_dump_member(uint, state, wrap_r);
374    trace_dump_member(uint, state, min_img_filter);
375    trace_dump_member(uint, state, min_mip_filter);
376    trace_dump_member(uint, state, mag_img_filter);
377    trace_dump_member(uint, state, compare_mode);
378    trace_dump_member(uint, state, compare_func);
379    trace_dump_member(bool, state, normalized_coords);
380    trace_dump_member(uint, state, max_anisotropy);
381    trace_dump_member(float, state, lod_bias);
382    trace_dump_member(float, state, min_lod);
383    trace_dump_member(float, state, max_lod);
384    trace_dump_member_array(float, state, border_color);
385
386    trace_dump_struct_end();
387 }
388
389
390 void trace_dump_surface(const struct pipe_surface *state)
391 {
392    if (!trace_dumping_enabled_locked())
393       return;
394
395    if(!state) {
396       trace_dump_null();
397       return;
398    }
399
400    trace_dump_struct_begin("pipe_surface");
401
402    trace_dump_member(format, state, format);
403    trace_dump_member(uint, state, width);
404    trace_dump_member(uint, state, height);
405
406    trace_dump_member(uint, state, layout);
407    trace_dump_member(uint, state, offset);
408    trace_dump_member(uint, state, usage);
409
410    trace_dump_member(ptr, state, texture);
411    trace_dump_member(uint, state, face);
412    trace_dump_member(uint, state, level);
413    trace_dump_member(uint, state, zslice);
414
415    trace_dump_struct_end();
416 }
417
418
419 void trace_dump_transfer(const struct pipe_transfer *state)
420 {
421    if (!trace_dumping_enabled_locked())
422       return;
423
424    if(!state) {
425       trace_dump_null();
426       return;
427    }
428
429    trace_dump_struct_begin("pipe_transfer");
430
431    trace_dump_member(uint, state, width);
432    trace_dump_member(uint, state, height);
433
434    trace_dump_member(uint, state, stride);
435    trace_dump_member(uint, state, usage);
436
437    trace_dump_member(ptr, state, texture);
438    trace_dump_member(uint, state, face);
439    trace_dump_member(uint, state, level);
440    trace_dump_member(uint, state, zslice);
441
442    trace_dump_struct_end();
443 }
444
445
446 void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state)
447 {
448    if (!trace_dumping_enabled_locked())
449       return;
450
451    if(!state) {
452       trace_dump_null();
453       return;
454    }
455
456    trace_dump_struct_begin("pipe_vertex_buffer");
457
458    trace_dump_member(uint, state, stride);
459    trace_dump_member(uint, state, max_index);
460    trace_dump_member(uint, state, buffer_offset);
461    trace_dump_member(buffer_ptr, state, buffer);
462
463    trace_dump_struct_end();
464 }
465
466
467 void trace_dump_vertex_element(const struct pipe_vertex_element *state)
468 {
469    if (!trace_dumping_enabled_locked())
470       return;
471
472    if(!state) {
473       trace_dump_null();
474       return;
475    }
476
477    trace_dump_struct_begin("pipe_vertex_element");
478
479    trace_dump_member(uint, state, src_offset);
480
481    trace_dump_member(uint, state, vertex_buffer_index);
482
483    trace_dump_member(format, state, src_format);
484
485    trace_dump_struct_end();
486 }