Merge branch 'lp-offset-twoside'
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_dump.c
1 /*
2 * Copyright © 2007 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #include "main/mtypes.h"
29
30 #include "brw_context.h"
31 #include "brw_defines.h"
32
33 /**
34 * Prints out a header, the contents, and the message associated with
35 * the hardware state data given.
36 *
37 * \param name Name of the state object
38 * \param data Pointer to the base of the state object
39 * \param hw_offset Hardware offset of the base of the state data.
40 * \param index Index of the DWORD being output.
41 */
42 static void
43 state_out(const char *name, void *data, uint32_t hw_offset, int index,
44 char *fmt, ...)
45 {
46 va_list va;
47
48 fprintf(stderr, "%8s: 0x%08x: 0x%08x: ",
49 name, hw_offset + index * 4, ((uint32_t *)data)[index]);
50 va_start(va, fmt);
51 vfprintf(stderr, fmt, va);
52 va_end(va);
53 }
54
55 /** Generic, undecoded state buffer debug printout */
56 static void
57 state_struct_out(const char *name, drm_intel_bo *buffer, unsigned int state_size)
58 {
59 int i;
60
61 if (buffer == NULL)
62 return;
63
64 drm_intel_bo_map(buffer, GL_FALSE);
65 for (i = 0; i < state_size / 4; i++) {
66 state_out(name, buffer->virtual, buffer->offset, i,
67 "dword %d\n", i);
68 }
69 drm_intel_bo_unmap(buffer);
70 }
71
72 static const char *
73 get_965_surfacetype(unsigned int surfacetype)
74 {
75 switch (surfacetype) {
76 case 0: return "1D";
77 case 1: return "2D";
78 case 2: return "3D";
79 case 3: return "CUBE";
80 case 4: return "BUFFER";
81 case 7: return "NULL";
82 default: return "unknown";
83 }
84 }
85
86 static const char *
87 get_965_surface_format(unsigned int surface_format)
88 {
89 switch (surface_format) {
90 case 0x000: return "r32g32b32a32_float";
91 case 0x0c1: return "b8g8r8a8_unorm";
92 case 0x100: return "b5g6r5_unorm";
93 case 0x102: return "b5g5r5a1_unorm";
94 case 0x104: return "b4g4r4a4_unorm";
95 default: return "unknown";
96 }
97 }
98
99 static void dump_wm_surface_state(struct brw_context *brw)
100 {
101 int i;
102
103 for (i = 0; i < brw->wm.nr_surfaces; i++) {
104 drm_intel_bo *surf_bo = brw->wm.surf_bo[i];
105 unsigned int surfoff;
106 struct brw_surface_state *surf;
107 char name[20];
108
109 if (surf_bo == NULL) {
110 fprintf(stderr, "WM SURF%d: NULL\n", i);
111 continue;
112 }
113 drm_intel_bo_map(surf_bo, GL_FALSE);
114 surfoff = surf_bo->offset + brw->wm.surf_offset[i];
115 surf = (struct brw_surface_state *)(surf_bo->virtual + brw->wm.surf_offset[i]);
116
117 sprintf(name, "WM SURF%d", i);
118 state_out(name, surf, surfoff, 0, "%s %s\n",
119 get_965_surfacetype(surf->ss0.surface_type),
120 get_965_surface_format(surf->ss0.surface_format));
121 state_out(name, surf, surfoff, 1, "offset\n");
122 state_out(name, surf, surfoff, 2, "%dx%d size, %d mips\n",
123 surf->ss2.width + 1, surf->ss2.height + 1, surf->ss2.mip_count);
124 state_out(name, surf, surfoff, 3, "pitch %d, %stiled\n",
125 surf->ss3.pitch + 1, surf->ss3.tiled_surface ? "" : "not ");
126 state_out(name, surf, surfoff, 4, "mip base %d\n",
127 surf->ss4.min_lod);
128 state_out(name, surf, surfoff, 5, "x,y offset: %d,%d\n",
129 surf->ss5.x_offset, surf->ss5.y_offset);
130
131 drm_intel_bo_unmap(surf_bo);
132 }
133 }
134
135
136 static void dump_wm_sampler_state(struct brw_context *brw)
137 {
138 struct gl_context *ctx = &brw->intel.ctx;
139 int i;
140
141 if (!brw->wm.sampler_bo) {
142 fprintf(stderr, "WM_SAMPLER: NULL\n");
143 return;
144 }
145
146 drm_intel_bo_map(brw->wm.sampler_bo, GL_FALSE);
147 for (i = 0; i < BRW_MAX_TEX_UNIT; i++) {
148 unsigned int offset;
149 struct brw_sampler_state *samp;
150 struct brw_sampler_default_color *sdc;
151 char name[20];
152
153 if (!ctx->Texture.Unit[i]._ReallyEnabled) {
154 fprintf(stderr, "WM SAMP%d: disabled\n", i);
155 continue;
156 }
157
158 offset = brw->wm.sampler_bo->offset +
159 i * sizeof(struct brw_sampler_state);
160 samp = (struct brw_sampler_state *)(brw->wm.sampler_bo->virtual +
161 i * sizeof(struct brw_sampler_state));
162
163 sprintf(name, "WM SAMP%d", i);
164 state_out(name, samp, offset, 0, "filtering\n");
165 state_out(name, samp, offset, 1, "wrapping, lod\n");
166 state_out(name, samp, offset, 2, "default color pointer\n");
167 state_out(name, samp, offset, 3, "chroma key, aniso\n");
168
169 sprintf(name, " WM SDC%d", i);
170
171 drm_intel_bo_map(brw->wm.sdc_bo[i], GL_FALSE);
172 sdc = (struct brw_sampler_default_color *)(brw->wm.sdc_bo[i]->virtual);
173 state_out(name, sdc, brw->wm.sdc_bo[i]->offset, 0, "r\n");
174 state_out(name, sdc, brw->wm.sdc_bo[i]->offset, 1, "g\n");
175 state_out(name, sdc, brw->wm.sdc_bo[i]->offset, 2, "b\n");
176 state_out(name, sdc, brw->wm.sdc_bo[i]->offset, 3, "a\n");
177 drm_intel_bo_unmap(brw->wm.sdc_bo[i]);
178 }
179 drm_intel_bo_unmap(brw->wm.sampler_bo);
180 }
181
182 static void dump_sf_viewport_state(struct brw_context *brw)
183 {
184 const char *name = "SF VP";
185 struct brw_sf_viewport *vp;
186 uint32_t vp_off;
187
188 if (brw->sf.vp_bo == NULL)
189 return;
190
191 drm_intel_bo_map(brw->sf.vp_bo, GL_FALSE);
192
193 vp = brw->sf.vp_bo->virtual;
194 vp_off = brw->sf.vp_bo->offset;
195
196 state_out(name, vp, vp_off, 0, "m00 = %f\n", vp->viewport.m00);
197 state_out(name, vp, vp_off, 1, "m11 = %f\n", vp->viewport.m11);
198 state_out(name, vp, vp_off, 2, "m22 = %f\n", vp->viewport.m22);
199 state_out(name, vp, vp_off, 3, "m30 = %f\n", vp->viewport.m30);
200 state_out(name, vp, vp_off, 4, "m31 = %f\n", vp->viewport.m31);
201 state_out(name, vp, vp_off, 5, "m32 = %f\n", vp->viewport.m32);
202
203 state_out(name, vp, vp_off, 6, "top left = %d,%d\n",
204 vp->scissor.xmin, vp->scissor.ymin);
205 state_out(name, vp, vp_off, 7, "bottom right = %d,%d\n",
206 vp->scissor.xmax, vp->scissor.ymax);
207
208 drm_intel_bo_unmap(brw->sf.vp_bo);
209 }
210
211 static void dump_clip_viewport_state(struct brw_context *brw)
212 {
213 const char *name = "CLIP VP";
214 struct brw_clipper_viewport *vp;
215 uint32_t vp_off;
216
217 if (brw->clip.vp_bo == NULL)
218 return;
219
220 drm_intel_bo_map(brw->clip.vp_bo, GL_FALSE);
221
222 vp = brw->clip.vp_bo->virtual;
223 vp_off = brw->clip.vp_bo->offset;
224
225 state_out(name, vp, vp_off, 0, "xmin = %f\n", vp->xmin);
226 state_out(name, vp, vp_off, 1, "xmax = %f\n", vp->xmax);
227 state_out(name, vp, vp_off, 2, "ymin = %f\n", vp->ymin);
228 state_out(name, vp, vp_off, 3, "ymax = %f\n", vp->ymax);
229 drm_intel_bo_unmap(brw->clip.vp_bo);
230 }
231
232 static void dump_cc_viewport_state(struct brw_context *brw)
233 {
234 const char *name = "CC VP";
235 struct brw_cc_viewport *vp;
236 uint32_t vp_off;
237
238 if (brw->cc.vp_bo == NULL)
239 return;
240
241 drm_intel_bo_map(brw->cc.vp_bo, GL_FALSE);
242
243 vp = brw->cc.vp_bo->virtual;
244 vp_off = brw->cc.vp_bo->offset;
245
246 state_out(name, vp, vp_off, 0, "min_depth = %f\n", vp->min_depth);
247 state_out(name, vp, vp_off, 1, "max_depth = %f\n", vp->max_depth);
248 drm_intel_bo_unmap(brw->cc.vp_bo);
249 }
250
251 static void dump_depth_stencil_state(struct brw_context *brw)
252 {
253 const char *name = "DEPTH STENCIL";
254 struct gen6_depth_stencil_state *ds;
255 uint32_t ds_off;
256
257 if (brw->cc.depth_stencil_state_bo == NULL)
258 return;
259
260 drm_intel_bo_map(brw->cc.depth_stencil_state_bo, GL_FALSE);
261
262 ds = brw->cc.depth_stencil_state_bo->virtual;
263 ds_off = brw->cc.depth_stencil_state_bo->offset;
264
265 state_out(name, ds, ds_off, 0, "stencil %sable, func %d, write %sable\n",
266 ds->ds0.stencil_enable ? "en" : "dis",
267 ds->ds0.stencil_func,
268 ds->ds0.stencil_write_enable ? "en" : "dis");
269 state_out(name, ds, ds_off, 1, "stencil test mask 0x%x, write mask 0x%x\n",
270 ds->ds1.stencil_test_mask, ds->ds1.stencil_write_mask);
271 state_out(name, ds, ds_off, 2, "depth test %sable, func %d, write %sable\n",
272 ds->ds2.depth_test_enable ? "en" : "dis",
273 ds->ds2.depth_test_func,
274 ds->ds2.depth_write_enable ? "en" : "dis");
275 drm_intel_bo_unmap(brw->cc.depth_stencil_state_bo);
276 }
277
278 static void dump_cc_state(struct brw_context *brw)
279 {
280 const char *name = "CC";
281 struct gen6_color_calc_state *cc;
282 uint32_t cc_off;
283
284 if (brw->cc.state_bo == NULL)
285 return;
286
287 drm_intel_bo_map(brw->cc.state_bo, GL_FALSE);
288 cc = brw->cc.state_bo->virtual;
289 cc_off = brw->cc.state_bo->offset;
290
291 state_out(name, cc, cc_off, 0, "alpha test format %s, round disable %d, stencil ref %d,"
292 "bf stencil ref %d\n",
293 cc->cc0.alpha_test_format ? "FLOAT32" : "UNORM8",
294 cc->cc0.round_disable,
295 cc->cc0.stencil_ref,
296 cc->cc0.bf_stencil_ref);
297 state_out(name, cc, cc_off, 1, "\n");
298 state_out(name, cc, cc_off, 2, "constant red %f\n", cc->constant_r);
299 state_out(name, cc, cc_off, 3, "constant green %f\n", cc->constant_g);
300 state_out(name, cc, cc_off, 4, "constant blue %f\n", cc->constant_b);
301 state_out(name, cc, cc_off, 5, "constant alpha %f\n", cc->constant_a);
302
303 drm_intel_bo_unmap(brw->cc.state_bo);
304
305 }
306
307 static void dump_blend_state(struct brw_context *brw)
308 {
309 const char *name = "BLEND";
310 struct gen6_blend_state *blend;
311 uint32_t blend_off;
312
313 if (brw->cc.blend_state_bo == NULL)
314 return;
315
316 drm_intel_bo_map(brw->cc.blend_state_bo, GL_FALSE);
317
318 blend = brw->cc.blend_state_bo->virtual;
319 blend_off = brw->cc.blend_state_bo->offset;
320
321 state_out(name, blend, blend_off, 0, "\n");
322 state_out(name, blend, blend_off, 1, "\n");
323
324 drm_intel_bo_unmap(brw->cc.blend_state_bo);
325
326 }
327
328 static void brw_debug_prog(const char *name, drm_intel_bo *prog)
329 {
330 unsigned int i;
331 uint32_t *data;
332
333 if (prog == NULL)
334 return;
335
336 drm_intel_bo_map(prog, GL_FALSE);
337
338 data = prog->virtual;
339
340 for (i = 0; i < prog->size / 4 / 4; i++) {
341 fprintf(stderr, "%8s: 0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
342 name, (unsigned int)prog->offset + i * 4 * 4,
343 data[i * 4], data[i * 4 + 1], data[i * 4 + 2], data[i * 4 + 3]);
344 /* Stop at the end of the program. It'd be nice to keep track of the actual
345 * intended program size instead of guessing like this.
346 */
347 if (data[i * 4 + 0] == 0 &&
348 data[i * 4 + 1] == 0 &&
349 data[i * 4 + 2] == 0 &&
350 data[i * 4 + 3] == 0)
351 break;
352 }
353
354 drm_intel_bo_unmap(prog);
355 }
356
357
358 /**
359 * Print additional debug information associated with the batchbuffer
360 * when DEBUG_BATCH is set.
361 *
362 * For 965, this means mapping the state buffers that would have been referenced
363 * by the batchbuffer and dumping them.
364 *
365 * The buffer offsets printed rely on the buffer containing the last offset
366 * it was validated at.
367 */
368 void brw_debug_batch(struct intel_context *intel)
369 {
370 struct brw_context *brw = brw_context(&intel->ctx);
371
372 state_struct_out("WM bind", brw->wm.bind_bo, 4 * brw->wm.nr_surfaces);
373 dump_wm_surface_state(brw);
374 dump_wm_sampler_state(brw);
375
376 if (intel->gen < 6)
377 state_struct_out("VS", brw->vs.state_bo, sizeof(struct brw_vs_unit_state));
378 brw_debug_prog("VS prog", brw->vs.prog_bo);
379
380 if (intel->gen < 6)
381 state_struct_out("GS", brw->gs.state_bo, sizeof(struct brw_gs_unit_state));
382 brw_debug_prog("GS prog", brw->gs.prog_bo);
383
384 if (intel->gen < 6) {
385 state_struct_out("SF", brw->sf.state_bo, sizeof(struct brw_sf_unit_state));
386 brw_debug_prog("SF prog", brw->sf.prog_bo);
387 }
388 dump_sf_viewport_state(brw);
389
390 if (intel->gen < 6)
391 state_struct_out("WM", brw->wm.state_bo, sizeof(struct brw_wm_unit_state));
392 brw_debug_prog("WM prog", brw->wm.prog_bo);
393
394 if (intel->gen >= 6) {
395 dump_cc_viewport_state(brw);
396 dump_clip_viewport_state(brw);
397 dump_depth_stencil_state(brw);
398 dump_cc_state(brw);
399 dump_blend_state(brw);
400 }
401 }