i965/gen6: Move the SF VP to state streaming.
[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 #include "intel_batchbuffer.h"
30
31 #include "brw_context.h"
32 #include "brw_defines.h"
33
34 /**
35 * Prints out a header, the contents, and the message associated with
36 * the hardware state data given.
37 *
38 * \param name Name of the state object
39 * \param data Pointer to the base of the state object
40 * \param hw_offset Hardware offset of the base of the state data.
41 * \param index Index of the DWORD being output.
42 */
43 static void
44 state_out(const char *name, void *data, uint32_t hw_offset, int index,
45 char *fmt, ...)
46 {
47 va_list va;
48
49 fprintf(stderr, "%8s: 0x%08x: 0x%08x: ",
50 name, hw_offset + index * 4, ((uint32_t *)data)[index]);
51 va_start(va, fmt);
52 vfprintf(stderr, fmt, va);
53 va_end(va);
54 }
55
56 /** Generic, undecoded state buffer debug printout */
57 static void
58 state_struct_out(const char *name, drm_intel_bo *buffer,
59 unsigned int offset, unsigned int size)
60 {
61 int i;
62
63 if (buffer == NULL)
64 return;
65
66 drm_intel_bo_map(buffer, GL_FALSE);
67 for (i = 0; i < size / 4; i++) {
68 state_out(name, buffer->virtual + offset, buffer->offset + offset, i,
69 "dword %d\n", i);
70 }
71 drm_intel_bo_unmap(buffer);
72 }
73
74 static const char *
75 get_965_surfacetype(unsigned int surfacetype)
76 {
77 switch (surfacetype) {
78 case 0: return "1D";
79 case 1: return "2D";
80 case 2: return "3D";
81 case 3: return "CUBE";
82 case 4: return "BUFFER";
83 case 7: return "NULL";
84 default: return "unknown";
85 }
86 }
87
88 static const char *
89 get_965_surface_format(unsigned int surface_format)
90 {
91 switch (surface_format) {
92 case 0x000: return "r32g32b32a32_float";
93 case 0x0c1: return "b8g8r8a8_unorm";
94 case 0x100: return "b5g6r5_unorm";
95 case 0x102: return "b5g5r5a1_unorm";
96 case 0x104: return "b4g4r4a4_unorm";
97 default: return "unknown";
98 }
99 }
100
101 static void dump_wm_surface_state(struct brw_context *brw)
102 {
103 dri_bo *bo;
104 GLubyte *base;
105 int i;
106
107 bo = brw->intel.batch.bo;
108 drm_intel_bo_map(bo, GL_FALSE);
109 base = bo->virtual;
110
111 for (i = 0; i < brw->wm.nr_surfaces; i++) {
112 unsigned int surfoff;
113 struct brw_surface_state *surf;
114 char name[20];
115
116 if (brw->wm.surf_offset[i] == 0) {
117 fprintf(stderr, "WM SURF%d: NULL\n", i);
118 continue;
119 }
120 surfoff = bo->offset + brw->wm.surf_offset[i];
121 surf = (struct brw_surface_state *)(base + brw->wm.surf_offset[i]);
122
123 sprintf(name, "WM SURF%d", i);
124 state_out(name, surf, surfoff, 0, "%s %s\n",
125 get_965_surfacetype(surf->ss0.surface_type),
126 get_965_surface_format(surf->ss0.surface_format));
127 state_out(name, surf, surfoff, 1, "offset\n");
128 state_out(name, surf, surfoff, 2, "%dx%d size, %d mips\n",
129 surf->ss2.width + 1, surf->ss2.height + 1, surf->ss2.mip_count);
130 state_out(name, surf, surfoff, 3, "pitch %d, %stiled\n",
131 surf->ss3.pitch + 1, surf->ss3.tiled_surface ? "" : "not ");
132 state_out(name, surf, surfoff, 4, "mip base %d\n",
133 surf->ss4.min_lod);
134 state_out(name, surf, surfoff, 5, "x,y offset: %d,%d\n",
135 surf->ss5.x_offset, surf->ss5.y_offset);
136 }
137 drm_intel_bo_unmap(bo);
138 }
139
140
141 static void dump_wm_sampler_state(struct brw_context *brw)
142 {
143 struct intel_context *intel = &brw->intel;
144 struct gl_context *ctx = &brw->intel.ctx;
145 int i;
146
147 if (!brw->wm.sampler_bo) {
148 fprintf(stderr, "WM_SAMPLER: NULL\n");
149 return;
150 }
151
152 drm_intel_bo_map(brw->wm.sampler_bo, GL_FALSE);
153 for (i = 0; i < BRW_MAX_TEX_UNIT; i++) {
154 unsigned int offset;
155 uint32_t sdc_offset;
156 struct brw_sampler_state *samp;
157 char name[20];
158
159 if (!ctx->Texture.Unit[i]._ReallyEnabled) {
160 fprintf(stderr, "WM SAMP%d: disabled\n", i);
161 continue;
162 }
163
164 offset = brw->wm.sampler_bo->offset +
165 i * sizeof(struct brw_sampler_state);
166 samp = (struct brw_sampler_state *)(brw->wm.sampler_bo->virtual +
167 i * sizeof(struct brw_sampler_state));
168
169 sprintf(name, "WM SAMP%d", i);
170 state_out(name, samp, offset, 0, "filtering\n");
171 state_out(name, samp, offset, 1, "wrapping, lod\n");
172 state_out(name, samp, offset, 2, "default color pointer\n");
173 state_out(name, samp, offset, 3, "chroma key, aniso\n");
174
175 sprintf(name, " WM SDC%d", i);
176
177 drm_intel_bo_map(brw->wm.sdc_bo[i], GL_FALSE);
178 sdc_offset = brw->wm.sdc_bo[i]->offset;
179 if (intel->gen >= 5) {
180 struct gen5_sampler_default_color *sdc = brw->wm.sdc_bo[i]->virtual;
181 state_out(name, sdc, sdc_offset, 0, "unorm rgba\n");
182 state_out(name, sdc, sdc_offset, 1, "r %f\n", sdc->f[0]);
183 state_out(name, sdc, sdc_offset, 2, "b %f\n", sdc->f[1]);
184 state_out(name, sdc, sdc_offset, 3, "g %f\n", sdc->f[2]);
185 state_out(name, sdc, sdc_offset, 4, "a %f\n", sdc->f[3]);
186 state_out(name, sdc, sdc_offset, 5, "half float rg\n");
187 state_out(name, sdc, sdc_offset, 6, "half float ba\n");
188 state_out(name, sdc, sdc_offset, 7, "u16 rg\n");
189 state_out(name, sdc, sdc_offset, 8, "u16 ba\n");
190 state_out(name, sdc, sdc_offset, 9, "s16 rg\n");
191 state_out(name, sdc, sdc_offset, 10, "s16 ba\n");
192 state_out(name, sdc, sdc_offset, 11, "s8 rgba\n");
193 } else {
194 struct brw_sampler_default_color *sdc = brw->wm.sdc_bo[i]->virtual;
195 state_out(name, sdc, sdc_offset, 0, "r %f\n", sdc->color[0]);
196 state_out(name, sdc, sdc_offset, 1, "g %f\n", sdc->color[1]);
197 state_out(name, sdc, sdc_offset, 2, "b %f\n", sdc->color[2]);
198 state_out(name, sdc, sdc_offset, 3, "a %f\n", sdc->color[3]);
199 }
200 drm_intel_bo_unmap(brw->wm.sdc_bo[i]);
201 }
202 drm_intel_bo_unmap(brw->wm.sampler_bo);
203 }
204
205 static void dump_sf_viewport_state(struct brw_context *brw)
206 {
207 struct intel_context *intel = &brw->intel;
208 const char *name = "SF VP";
209 struct brw_sf_viewport *vp;
210 uint32_t vp_off;
211
212 drm_intel_bo_map(intel->batch.bo, GL_FALSE);
213
214 vp = intel->batch.bo->virtual + brw->sf.vp_offset;
215 vp_off = intel->batch.bo->offset + brw->sf.vp_offset;
216
217 state_out(name, vp, vp_off, 0, "m00 = %f\n", vp->viewport.m00);
218 state_out(name, vp, vp_off, 1, "m11 = %f\n", vp->viewport.m11);
219 state_out(name, vp, vp_off, 2, "m22 = %f\n", vp->viewport.m22);
220 state_out(name, vp, vp_off, 3, "m30 = %f\n", vp->viewport.m30);
221 state_out(name, vp, vp_off, 4, "m31 = %f\n", vp->viewport.m31);
222 state_out(name, vp, vp_off, 5, "m32 = %f\n", vp->viewport.m32);
223
224 state_out(name, vp, vp_off, 6, "top left = %d,%d\n",
225 vp->scissor.xmin, vp->scissor.ymin);
226 state_out(name, vp, vp_off, 7, "bottom right = %d,%d\n",
227 vp->scissor.xmax, vp->scissor.ymax);
228
229 drm_intel_bo_unmap(intel->batch.bo);
230 }
231
232 static void dump_clip_viewport_state(struct brw_context *brw)
233 {
234 struct intel_context *intel = &brw->intel;
235 const char *name = "CLIP VP";
236 struct brw_clipper_viewport *vp;
237 uint32_t vp_off;
238
239 drm_intel_bo_map(intel->batch.bo, GL_FALSE);
240
241 vp = intel->batch.bo->virtual + brw->clip.vp_offset;
242 vp_off = intel->batch.bo->offset + brw->clip.vp_offset;
243
244 state_out(name, vp, vp_off, 0, "xmin = %f\n", vp->xmin);
245 state_out(name, vp, vp_off, 1, "xmax = %f\n", vp->xmax);
246 state_out(name, vp, vp_off, 2, "ymin = %f\n", vp->ymin);
247 state_out(name, vp, vp_off, 3, "ymax = %f\n", vp->ymax);
248 drm_intel_bo_unmap(intel->batch.bo);
249 }
250
251 static void dump_cc_viewport_state(struct brw_context *brw)
252 {
253 const char *name = "CC VP";
254 struct brw_cc_viewport *vp;
255 uint32_t vp_off;
256
257 if (brw->cc.vp_bo == NULL)
258 return;
259
260 drm_intel_bo_map(brw->cc.vp_bo, GL_FALSE);
261
262 vp = brw->cc.vp_bo->virtual;
263 vp_off = brw->cc.vp_bo->offset;
264
265 state_out(name, vp, vp_off, 0, "min_depth = %f\n", vp->min_depth);
266 state_out(name, vp, vp_off, 1, "max_depth = %f\n", vp->max_depth);
267 drm_intel_bo_unmap(brw->cc.vp_bo);
268 }
269
270 static void dump_depth_stencil_state(struct brw_context *brw)
271 {
272 const char *name = "DEPTH STENCIL";
273 struct gen6_depth_stencil_state *ds;
274 uint32_t ds_off;
275
276 if (brw->cc.depth_stencil_state_bo == NULL)
277 return;
278
279 drm_intel_bo_map(brw->cc.depth_stencil_state_bo, GL_FALSE);
280
281 ds = brw->cc.depth_stencil_state_bo->virtual;
282 ds_off = brw->cc.depth_stencil_state_bo->offset;
283
284 state_out(name, ds, ds_off, 0, "stencil %sable, func %d, write %sable\n",
285 ds->ds0.stencil_enable ? "en" : "dis",
286 ds->ds0.stencil_func,
287 ds->ds0.stencil_write_enable ? "en" : "dis");
288 state_out(name, ds, ds_off, 1, "stencil test mask 0x%x, write mask 0x%x\n",
289 ds->ds1.stencil_test_mask, ds->ds1.stencil_write_mask);
290 state_out(name, ds, ds_off, 2, "depth test %sable, func %d, write %sable\n",
291 ds->ds2.depth_test_enable ? "en" : "dis",
292 ds->ds2.depth_test_func,
293 ds->ds2.depth_write_enable ? "en" : "dis");
294 drm_intel_bo_unmap(brw->cc.depth_stencil_state_bo);
295 }
296
297 static void dump_cc_state(struct brw_context *brw)
298 {
299 const char *name = "CC";
300 struct gen6_color_calc_state *cc;
301 uint32_t cc_off;
302 dri_bo *bo = brw->intel.batch.bo;
303
304 if (brw->cc.state_offset == 0)
305 return;
306
307 drm_intel_bo_map(bo, GL_FALSE);
308 cc = bo->virtual;
309 cc_off = bo->offset;
310
311 state_out(name, cc, cc_off, 0, "alpha test format %s, round disable %d, stencil ref %d,"
312 "bf stencil ref %d\n",
313 cc->cc0.alpha_test_format ? "FLOAT32" : "UNORM8",
314 cc->cc0.round_disable,
315 cc->cc0.stencil_ref,
316 cc->cc0.bf_stencil_ref);
317 state_out(name, cc, cc_off, 1, "\n");
318 state_out(name, cc, cc_off, 2, "constant red %f\n", cc->constant_r);
319 state_out(name, cc, cc_off, 3, "constant green %f\n", cc->constant_g);
320 state_out(name, cc, cc_off, 4, "constant blue %f\n", cc->constant_b);
321 state_out(name, cc, cc_off, 5, "constant alpha %f\n", cc->constant_a);
322
323 drm_intel_bo_unmap(bo);
324
325 }
326
327 static void dump_blend_state(struct brw_context *brw)
328 {
329 const char *name = "BLEND";
330 struct gen6_blend_state *blend;
331 uint32_t blend_off;
332
333 if (brw->cc.blend_state_bo == NULL)
334 return;
335
336 drm_intel_bo_map(brw->cc.blend_state_bo, GL_FALSE);
337
338 blend = brw->cc.blend_state_bo->virtual;
339 blend_off = brw->cc.blend_state_bo->offset;
340
341 state_out(name, blend, blend_off, 0, "\n");
342 state_out(name, blend, blend_off, 1, "\n");
343
344 drm_intel_bo_unmap(brw->cc.blend_state_bo);
345
346 }
347
348 static void brw_debug_prog(const char *name, drm_intel_bo *prog)
349 {
350 unsigned int i;
351 uint32_t *data;
352
353 if (prog == NULL)
354 return;
355
356 drm_intel_bo_map(prog, GL_FALSE);
357
358 data = prog->virtual;
359
360 for (i = 0; i < prog->size / 4 / 4; i++) {
361 fprintf(stderr, "%8s: 0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
362 name, (unsigned int)prog->offset + i * 4 * 4,
363 data[i * 4], data[i * 4 + 1], data[i * 4 + 2], data[i * 4 + 3]);
364 /* Stop at the end of the program. It'd be nice to keep track of the actual
365 * intended program size instead of guessing like this.
366 */
367 if (data[i * 4 + 0] == 0 &&
368 data[i * 4 + 1] == 0 &&
369 data[i * 4 + 2] == 0 &&
370 data[i * 4 + 3] == 0)
371 break;
372 }
373
374 drm_intel_bo_unmap(prog);
375 }
376
377
378 /**
379 * Print additional debug information associated with the batchbuffer
380 * when DEBUG_BATCH is set.
381 *
382 * For 965, this means mapping the state buffers that would have been referenced
383 * by the batchbuffer and dumping them.
384 *
385 * The buffer offsets printed rely on the buffer containing the last offset
386 * it was validated at.
387 */
388 void brw_debug_batch(struct intel_context *intel)
389 {
390 struct brw_context *brw = brw_context(&intel->ctx);
391
392 state_struct_out("WM bind",
393 brw->intel.batch.bo,
394 brw->wm.bind_bo_offset,
395 4 * brw->wm.nr_surfaces);
396 dump_wm_surface_state(brw);
397 dump_wm_sampler_state(brw);
398
399 if (intel->gen < 6)
400 state_struct_out("VS", brw->vs.state_bo, 0, sizeof(struct brw_vs_unit_state));
401 brw_debug_prog("VS prog", brw->vs.prog_bo);
402
403 if (intel->gen < 6)
404 state_struct_out("GS", brw->gs.state_bo, 0, sizeof(struct brw_gs_unit_state));
405 brw_debug_prog("GS prog", brw->gs.prog_bo);
406
407 if (intel->gen < 6) {
408 state_struct_out("SF", brw->sf.state_bo, 0, sizeof(struct brw_sf_unit_state));
409 brw_debug_prog("SF prog", brw->sf.prog_bo);
410 }
411 dump_sf_viewport_state(brw);
412
413 if (intel->gen < 6)
414 state_struct_out("WM", brw->wm.state_bo, 0, sizeof(struct brw_wm_unit_state));
415 brw_debug_prog("WM prog", brw->wm.prog_bo);
416
417 if (intel->gen >= 6) {
418 dump_cc_viewport_state(brw);
419 dump_clip_viewport_state(brw);
420 dump_depth_stencil_state(brw);
421 dump_cc_state(brw);
422 dump_blend_state(brw);
423 }
424 }