i965: Introduce state flag for blorp
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_dump.c
1 /*
2 * Copyright © 2007-2015 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 #include "brw_eu.h"
34 #include "brw_state.h"
35
36 static const char *sampler_mip_filter[] = {
37 "NONE",
38 "NEAREST",
39 "RSVD",
40 "LINEAR"
41 };
42
43 static const char *sampler_mag_filter[] = {
44 "NEAREST",
45 "LINEAR",
46 "ANISOTROPIC",
47 "FLEXIBLE (GEN8+)",
48 "RSVD", "RSVD",
49 "MONO",
50 "RSVD"
51 };
52
53 static const char *sampler_addr_mode[] = {
54 "WRAP",
55 "MIRROR",
56 "CLAMP",
57 "CUBE",
58 "CLAMP_BORDER",
59 "MIRROR_ONCE",
60 "HALF_BORDER"
61 };
62
63 static const char *surface_tiling[] = {
64 "LINEAR",
65 "W-tiled",
66 "X-tiled",
67 "Y-tiled"
68 };
69
70 static void
71 batch_out(struct brw_context *brw, const char *name, uint32_t offset,
72 int index, char *fmt, ...) PRINTFLIKE(5, 6);
73
74 static void
75 batch_out(struct brw_context *brw, const char *name, uint32_t offset,
76 int index, char *fmt, ...)
77 {
78 uint32_t *data = brw->batch.bo->virtual + offset;
79 va_list va;
80
81 fprintf(stderr, "0x%08x: 0x%08x: %8s: ",
82 offset + index * 4, data[index], name);
83 va_start(va, fmt);
84 vfprintf(stderr, fmt, va);
85 va_end(va);
86 }
87
88 static void
89 batch_out64(struct brw_context *brw, const char *name, uint32_t offset,
90 int index, char *fmt, ...)
91 {
92 uint32_t *tmp = brw->batch.bo->virtual + offset;
93
94 /* Swap the dwords since we want to handle this as a 64b value, but the data
95 * is typically emitted as dwords.
96 */
97 uint64_t data = ((uint64_t)tmp[index + 1]) << 32 | tmp[index];
98 va_list va;
99
100 fprintf(stderr, "0x%08x: 0x%016" PRIx64 ": %8s: ",
101 offset + index * 4, data, name);
102 va_start(va, fmt);
103 vfprintf(stderr, fmt, va);
104 va_end(va);
105 }
106
107 static const char *
108 get_965_surfacetype(unsigned int surfacetype)
109 {
110 switch (surfacetype) {
111 case 0: return "1D";
112 case 1: return "2D";
113 case 2: return "3D";
114 case 3: return "CUBE";
115 case 4: return "BUFFER";
116 case 7: return "NULL";
117 default: return "unknown";
118 }
119 }
120
121 static void dump_vs_state(struct brw_context *brw, uint32_t offset)
122 {
123 const char *name = "VS_STATE";
124 struct brw_vs_unit_state *vs = brw->batch.bo->virtual + offset;
125
126 batch_out(brw, name, offset, 0, "thread0\n");
127 batch_out(brw, name, offset, 1, "thread1\n");
128 batch_out(brw, name, offset, 2, "thread2\n");
129 batch_out(brw, name, offset, 3, "thread3\n");
130 batch_out(brw, name, offset, 4, "thread4: %d threads\n",
131 vs->thread4.max_threads + 1);
132 batch_out(brw, name, offset, 5, "vs5\n");
133 batch_out(brw, name, offset, 6, "vs6\n");
134 }
135
136 static void dump_gs_state(struct brw_context *brw, uint32_t offset)
137 {
138 const char *name = "GS_STATE";
139 struct brw_gs_unit_state *gs = brw->batch.bo->virtual + offset;
140
141 batch_out(brw, name, offset, 0, "thread0\n");
142 batch_out(brw, name, offset, 1, "thread1\n");
143 batch_out(brw, name, offset, 2, "thread2\n");
144 batch_out(brw, name, offset, 3, "thread3\n");
145 batch_out(brw, name, offset, 4, "thread4: %d threads\n",
146 gs->thread4.max_threads + 1);
147 batch_out(brw, name, offset, 5, "vs5\n");
148 batch_out(brw, name, offset, 6, "vs6\n");
149 }
150
151 static void dump_clip_state(struct brw_context *brw, uint32_t offset)
152 {
153 const char *name = "CLIP_STATE";
154 struct brw_clip_unit_state *clip = brw->batch.bo->virtual + offset;
155
156 batch_out(brw, name, offset, 0, "thread0\n");
157 batch_out(brw, name, offset, 1, "thread1\n");
158 batch_out(brw, name, offset, 2, "thread2\n");
159 batch_out(brw, name, offset, 3, "thread3\n");
160 batch_out(brw, name, offset, 4, "thread4: %d threads\n",
161 clip->thread4.max_threads + 1);
162 batch_out(brw, name, offset, 5, "clip5\n");
163 batch_out(brw, name, offset, 6, "clip6\n");
164 batch_out(brw, name, offset, 7, "vp xmin %f\n", clip->viewport_xmin);
165 batch_out(brw, name, offset, 8, "vp xmax %f\n", clip->viewport_xmax);
166 batch_out(brw, name, offset, 9, "vp ymin %f\n", clip->viewport_ymin);
167 batch_out(brw, name, offset, 10, "vp ymax %f\n", clip->viewport_ymax);
168 }
169
170 static void dump_sf_state(struct brw_context *brw, uint32_t offset)
171 {
172 const char *name = "SF_STATE";
173 struct brw_sf_unit_state *sf = brw->batch.bo->virtual + offset;
174
175 batch_out(brw, name, offset, 0, "thread0\n");
176 batch_out(brw, name, offset, 1, "thread1\n");
177 batch_out(brw, name, offset, 2, "thread2\n");
178 batch_out(brw, name, offset, 3, "thread3\n");
179 batch_out(brw, name, offset, 4, "thread4: %d threads\n",
180 sf->thread4.max_threads + 1);
181 batch_out(brw, name, offset, 5, "sf5: viewport offset\n");
182 batch_out(brw, name, offset, 6, "sf6\n");
183 batch_out(brw, name, offset, 7, "sf7\n");
184 }
185
186 static void dump_wm_state(struct brw_context *brw, uint32_t offset)
187 {
188 const char *name = "WM_STATE";
189 struct brw_wm_unit_state *wm = brw->batch.bo->virtual + offset;
190
191 batch_out(brw, name, offset, 0, "thread0\n");
192 batch_out(brw, name, offset, 1, "thread1\n");
193 batch_out(brw, name, offset, 2, "thread2\n");
194 batch_out(brw, name, offset, 3, "thread3\n");
195 batch_out(brw, name, offset, 4, "wm4\n");
196 batch_out(brw, name, offset, 5, "wm5: %s%s%s%s%s%s, %d threads\n",
197 wm->wm5.enable_8_pix ? "8pix" : "",
198 wm->wm5.enable_16_pix ? "16pix" : "",
199 wm->wm5.program_uses_depth ? ", uses depth" : "",
200 wm->wm5.program_computes_depth ? ", computes depth" : "",
201 wm->wm5.program_uses_killpixel ? ", kills" : "",
202 wm->wm5.thread_dispatch_enable ? "" : ", no dispatch",
203 wm->wm5.max_threads + 1);
204 batch_out(brw, name, offset, 6, "depth offset constant %f\n",
205 wm->global_depth_offset_constant);
206 batch_out(brw, name, offset, 7, "depth offset scale %f\n",
207 wm->global_depth_offset_scale);
208 batch_out(brw, name, offset, 8, "wm8: kernel 1 (gen5+)\n");
209 batch_out(brw, name, offset, 9, "wm9: kernel 2 (gen5+)\n");
210 batch_out(brw, name, offset, 10, "wm10: kernel 3 (gen5+)\n");
211 }
212
213 static void dump_surface_state(struct brw_context *brw, uint32_t offset)
214 {
215 const char *name = "SURF";
216 uint32_t *surf = brw->batch.bo->virtual + offset;
217
218 batch_out(brw, name, offset, 0, "%s %s\n",
219 get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)),
220 brw_surface_format_name(GET_FIELD(surf[0], BRW_SURFACE_FORMAT)));
221 batch_out(brw, name, offset, 1, "offset\n");
222 batch_out(brw, name, offset, 2, "%dx%d size, %d mips\n",
223 GET_FIELD(surf[2], BRW_SURFACE_WIDTH) + 1,
224 GET_FIELD(surf[2], BRW_SURFACE_HEIGHT) + 1,
225 GET_FIELD(surf[2], BRW_SURFACE_LOD));
226 batch_out(brw, name, offset, 3, "pitch %d, %s tiled\n",
227 GET_FIELD(surf[3], BRW_SURFACE_PITCH) + 1,
228 (surf[3] & BRW_SURFACE_TILED) ?
229 ((surf[3] & BRW_SURFACE_TILED_Y) ? "Y" : "X") : "not");
230 batch_out(brw, name, offset, 4, "mip base %d\n",
231 GET_FIELD(surf[4], BRW_SURFACE_MIN_LOD));
232 batch_out(brw, name, offset, 5, "x,y offset: %d,%d\n",
233 GET_FIELD(surf[5], BRW_SURFACE_X_OFFSET),
234 GET_FIELD(surf[5], BRW_SURFACE_Y_OFFSET));
235 }
236
237 static void dump_gen7_surface_state(struct brw_context *brw, uint32_t offset)
238 {
239 const char *name = "SURF";
240 uint32_t *surf = brw->batch.bo->virtual + offset;
241
242 batch_out(brw, name, offset, 0, "%s %s %s\n",
243 get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)),
244 brw_surface_format_name(GET_FIELD(surf[0], BRW_SURFACE_FORMAT)),
245 (surf[0] & GEN7_SURFACE_IS_ARRAY) ? "array" : "");
246 batch_out(brw, name, offset, 1, "offset\n");
247 batch_out(brw, name, offset, 2, "%dx%d size, %d mips, %d slices\n",
248 GET_FIELD(surf[2], GEN7_SURFACE_WIDTH) + 1,
249 GET_FIELD(surf[2], GEN7_SURFACE_HEIGHT) + 1,
250 surf[5] & INTEL_MASK(3, 0),
251 GET_FIELD(surf[3], BRW_SURFACE_DEPTH) + 1);
252 batch_out(brw, name, offset, 3, "pitch %d, %stiled\n",
253 (surf[3] & INTEL_MASK(17, 0)) + 1,
254 (surf[0] & (1 << 14)) ? "" : "not ");
255 batch_out(brw, name, offset, 4, "min array element %d, array extent %d\n",
256 GET_FIELD(surf[4], GEN7_SURFACE_MIN_ARRAY_ELEMENT),
257 GET_FIELD(surf[4], GEN7_SURFACE_RENDER_TARGET_VIEW_EXTENT) + 1);
258 batch_out(brw, name, offset, 5, "mip base %d\n",
259 GET_FIELD(surf[5], GEN7_SURFACE_MIN_LOD));
260 batch_out(brw, name, offset, 6, "x,y offset: %d,%d\n",
261 GET_FIELD(surf[5], BRW_SURFACE_X_OFFSET),
262 GET_FIELD(surf[5], BRW_SURFACE_Y_OFFSET));
263 batch_out(brw, name, offset, 7, "\n");
264 }
265
266 static float q_to_float(uint32_t data, int integer_end, int integer_start,
267 int fractional_end, int fractional_start)
268 {
269 /* Convert the number to floating point. */
270 float n = GET_BITS(data, integer_start, fractional_end);
271
272 /* Multiply by 2^-n */
273 return n * exp2(-(fractional_end - fractional_start + 1));
274 }
275
276 static void
277 dump_gen8_surface_state(struct brw_context *brw, uint32_t offset, int index)
278 {
279 uint32_t *surf = brw->batch.bo->virtual + offset;
280 int aux_mode = surf[6] & INTEL_MASK(2, 0);
281 const char *aux_str;
282 char *name;
283
284 if (brw->gen >= 9 && (aux_mode == 1 || aux_mode == 5)) {
285 bool msrt = GET_BITS(surf[4], 5, 3) > 0;
286 bool compression = GET_FIELD(surf[7], GEN9_SURFACE_RT_COMPRESSION) == 1;
287 aux_str = ralloc_asprintf(NULL, "AUX_CCS_%c (%s, MULTISAMPLE_COUNT%c1)",
288 (aux_mode == 1) ? 'D' : 'E',
289 compression ? "Compressed RT" : "Uncompressed",
290 msrt ? '>' : '=');
291 } else {
292 static const char *surface_aux_mode[] = { "AUX_NONE", "AUX_MCS",
293 "AUX_APPEND", "AUX_HIZ",
294 "RSVD", "RSVD"};
295 aux_str = ralloc_asprintf(NULL, "%s", surface_aux_mode[aux_mode]);
296 }
297
298 name = ralloc_asprintf(NULL, "SURF%03d", index);
299 batch_out(brw, name, offset, 0, "%s %s %s VALIGN%d HALIGN%d %s\n",
300 get_965_surfacetype(GET_FIELD(surf[0], BRW_SURFACE_TYPE)),
301 brw_surface_format_name(GET_FIELD(surf[0], BRW_SURFACE_FORMAT)),
302 (surf[0] & GEN7_SURFACE_IS_ARRAY) ? "array" : "",
303 1 << (GET_BITS(surf[0], 17, 16) + 1), /* VALIGN */
304 1 << (GET_BITS(surf[0], 15, 14) + 1), /* HALIGN */
305 surface_tiling[GET_BITS(surf[0], 13, 12)]);
306 batch_out(brw, name, offset, 1, "MOCS: 0x%x Base MIP: %.1f (%u mips) Surface QPitch: %d\n",
307 GET_FIELD(surf[1], GEN8_SURFACE_MOCS),
308 q_to_float(surf[1], 23, 20, 19, 19),
309 surf[5] & INTEL_MASK(3, 0),
310 GET_FIELD(surf[1], GEN8_SURFACE_QPITCH) << 2);
311 batch_out(brw, name, offset, 2, "%dx%d [%s]\n",
312 GET_FIELD(surf[2], GEN7_SURFACE_WIDTH) + 1,
313 GET_FIELD(surf[2], GEN7_SURFACE_HEIGHT) + 1,
314 aux_str);
315 batch_out(brw, name, offset, 3, "%d slices (depth), pitch: %d\n",
316 GET_FIELD(surf[3], BRW_SURFACE_DEPTH) + 1,
317 (surf[3] & INTEL_MASK(17, 0)) + 1);
318 batch_out(brw, name, offset, 4, "min array element: %d, array extent %d, MULTISAMPLE_%d\n",
319 GET_FIELD(surf[4], GEN7_SURFACE_MIN_ARRAY_ELEMENT),
320 GET_FIELD(surf[4], GEN7_SURFACE_RENDER_TARGET_VIEW_EXTENT) + 1,
321 1 << GET_BITS(surf[4], 5, 3));
322 batch_out(brw, name, offset, 5, "x,y offset: %d,%d, min LOD: %d,"
323 " tr_mode (gen9+): %d, mip tail (gen9+): %d\n",
324 GET_FIELD(surf[5], BRW_SURFACE_X_OFFSET),
325 GET_FIELD(surf[5], BRW_SURFACE_Y_OFFSET),
326 GET_FIELD(surf[5], GEN7_SURFACE_MIN_LOD),
327 GET_FIELD(surf[5], GEN9_SURFACE_TRMODE),
328 GET_FIELD(surf[5], GEN9_SURFACE_MIP_TAIL_START_LOD));
329 batch_out(brw, name, offset, 6, "AUX pitch: %d qpitch: %d\n",
330 GET_FIELD(surf[6], GEN8_SURFACE_AUX_QPITCH) << 2,
331 GET_FIELD(surf[6], GEN8_SURFACE_AUX_PITCH) << 2);
332 if (brw->gen >= 9) {
333 batch_out(brw, name, offset, 7, "Clear color: R(%x)G(%x)B(%x)A(%x)\n",
334 surf[12], surf[13], surf[14], surf[15]);
335 } else {
336 batch_out(brw, name, offset, 7, "Clear color: %c%c%c%c\n",
337 GET_BITS(surf[7], 31, 31) ? 'R' : '-',
338 GET_BITS(surf[7], 30, 30) ? 'G' : '-',
339 GET_BITS(surf[7], 29, 29) ? 'B' : '-',
340 GET_BITS(surf[7], 28, 28) ? 'A' : '-');
341 }
342
343 for (int i = 8; i < 12; i++)
344 batch_out(brw, name, offset, i, "0x%08x\n", surf[i]);
345
346 ralloc_free((void *)aux_str);
347 ralloc_free(name);
348 }
349
350 static void
351 dump_sdc(struct brw_context *brw, uint32_t offset)
352 {
353 const char *name = "SDC";
354
355 if (brw->gen >= 5 && brw->gen <= 6) {
356 struct gen5_sampler_default_color *sdc = (brw->batch.bo->virtual +
357 offset);
358 batch_out(brw, name, offset, 0, "unorm rgba\n");
359 batch_out(brw, name, offset, 1, "r %f\n", sdc->f[0]);
360 batch_out(brw, name, offset, 2, "b %f\n", sdc->f[1]);
361 batch_out(brw, name, offset, 3, "g %f\n", sdc->f[2]);
362 batch_out(brw, name, offset, 4, "a %f\n", sdc->f[3]);
363 batch_out(brw, name, offset, 5, "half float rg\n");
364 batch_out(brw, name, offset, 6, "half float ba\n");
365 batch_out(brw, name, offset, 7, "u16 rg\n");
366 batch_out(brw, name, offset, 8, "u16 ba\n");
367 batch_out(brw, name, offset, 9, "s16 rg\n");
368 batch_out(brw, name, offset, 10, "s16 ba\n");
369 batch_out(brw, name, offset, 11, "s8 rgba\n");
370 } else {
371 float *sdc = brw->batch.bo->virtual + offset;
372 batch_out(brw, name, offset, 0, "r %f\n", sdc[0]);
373 batch_out(brw, name, offset, 1, "g %f\n", sdc[1]);
374 batch_out(brw, name, offset, 2, "b %f\n", sdc[2]);
375 batch_out(brw, name, offset, 3, "a %f\n", sdc[3]);
376 }
377 }
378
379 static void dump_sampler_state(struct brw_context *brw,
380 uint32_t offset, uint32_t size)
381 {
382 unsigned i;
383 uint32_t *samp = brw->batch.bo->virtual + offset;
384
385 for (i = 0; i < size / 16; i++) {
386 char name[20];
387
388 sprintf(name, "WM SAMP%u", i);
389 batch_out(brw, name, offset, 0, "filtering\n");
390 batch_out(brw, name, offset, 1, "wrapping, lod\n");
391 batch_out(brw, name, offset, 2, "default color pointer\n");
392 batch_out(brw, name, offset, 3, "chroma key, aniso\n");
393
394 samp += 4;
395 offset += 4 * sizeof(uint32_t);
396 }
397 }
398
399 static void gen7_dump_sampler_state(struct brw_context *brw,
400 uint32_t offset, uint32_t size)
401 {
402 const uint32_t *samp = brw->batch.bo->virtual + offset;
403 char name[20];
404
405 for (int i = 0; i < size / 16; i++) {
406 sprintf(name, "SAMPLER_STATE %d", i);
407 batch_out(brw, name, offset, i,
408 "Disabled = %s, Base Mip: %u.%u, Mip/Mag/Min Filter: %s/%s/%s, LOD Bias: %d.%d\n",
409 GET_BITS(samp[0], 31, 31) ? "yes" : "no",
410 GET_BITS(samp[0], 26, 23),
411 GET_BITS(samp[0], 22, 22),
412 sampler_mip_filter[GET_FIELD(samp[0], BRW_SAMPLER_MIP_FILTER)],
413 sampler_mag_filter[GET_FIELD(samp[0], BRW_SAMPLER_MAG_FILTER)],
414 /* min filter defs are the same as mag */
415 sampler_mag_filter[GET_FIELD(samp[0], BRW_SAMPLER_MIN_FILTER)],
416 GET_BITS(samp[0], 13, 10),
417 GET_BITS(samp[0], 9, 1)
418 );
419 batch_out(brw, name, offset, i+1, "Min LOD: %u.%u, Max LOD: %u.%u\n",
420 GET_BITS(samp[1], 31, 28),
421 GET_BITS(samp[1], 27, 20),
422 GET_BITS(samp[1], 19, 16),
423 GET_BITS(samp[1], 15, 8)
424 );
425 batch_out(brw, name, offset, i+2, "Border Color\n"); /* FINISHME: gen8+ */
426 batch_out(brw, name, offset, i+3, "Max aniso: RATIO %d:1, TC[XYZ] Address Control: %s|%s|%s, %snormalized coords\n",
427 (GET_FIELD(samp[3], BRW_SAMPLER_MAX_ANISOTROPY) + 1) * 2,
428 sampler_addr_mode[GET_FIELD(samp[3], BRW_SAMPLER_TCX_WRAP_MODE)],
429 sampler_addr_mode[GET_FIELD(samp[3], BRW_SAMPLER_TCY_WRAP_MODE)],
430 sampler_addr_mode[GET_FIELD(samp[3], BRW_SAMPLER_TCZ_WRAP_MODE)],
431 (samp[3] & GEN7_SAMPLER_NON_NORMALIZED_COORDINATES) ? "non-" : ""
432 );
433
434 samp += 4;
435 offset += 4 * sizeof(uint32_t);
436 }
437 }
438
439 static void dump_sf_viewport_state(struct brw_context *brw,
440 uint32_t offset)
441 {
442 const char *name = "SF VP";
443 struct brw_sf_viewport *vp = brw->batch.bo->virtual + offset;
444
445 assert(brw->gen < 7);
446
447 batch_out(brw, name, offset, 0, "m00 = %f\n", vp->viewport.m00);
448 batch_out(brw, name, offset, 1, "m11 = %f\n", vp->viewport.m11);
449 batch_out(brw, name, offset, 2, "m22 = %f\n", vp->viewport.m22);
450 batch_out(brw, name, offset, 3, "m30 = %f\n", vp->viewport.m30);
451 batch_out(brw, name, offset, 4, "m31 = %f\n", vp->viewport.m31);
452 batch_out(brw, name, offset, 5, "m32 = %f\n", vp->viewport.m32);
453
454 batch_out(brw, name, offset, 6, "top left = %d,%d\n",
455 vp->scissor.xmin, vp->scissor.ymin);
456 batch_out(brw, name, offset, 7, "bottom right = %d,%d\n",
457 vp->scissor.xmax, vp->scissor.ymax);
458 }
459
460 static void dump_clip_viewport_state(struct brw_context *brw,
461 uint32_t offset)
462 {
463 const char *name = "CLIP VP";
464 struct brw_clipper_viewport *vp = brw->batch.bo->virtual + offset;
465
466 assert(brw->gen < 7);
467
468 batch_out(brw, name, offset, 0, "xmin = %f\n", vp->xmin);
469 batch_out(brw, name, offset, 1, "xmax = %f\n", vp->xmax);
470 batch_out(brw, name, offset, 2, "ymin = %f\n", vp->ymin);
471 batch_out(brw, name, offset, 3, "ymax = %f\n", vp->ymax);
472 }
473
474 static void dump_sf_clip_viewport_state(struct brw_context *brw,
475 uint32_t offset)
476 {
477 const char *name = "SF_CLIP VP";
478 struct gen7_sf_clip_viewport *vp = brw->batch.bo->virtual + offset;
479
480 assert(brw->gen >= 7);
481
482 batch_out(brw, name, offset, 0, "m00 = %f\n", vp->viewport.m00);
483 batch_out(brw, name, offset, 1, "m11 = %f\n", vp->viewport.m11);
484 batch_out(brw, name, offset, 2, "m22 = %f\n", vp->viewport.m22);
485 batch_out(brw, name, offset, 3, "m30 = %f\n", vp->viewport.m30);
486 batch_out(brw, name, offset, 4, "m31 = %f\n", vp->viewport.m31);
487 batch_out(brw, name, offset, 5, "m32 = %f\n", vp->viewport.m32);
488 batch_out(brw, name, offset, 8, "guardband xmin = %f\n", vp->guardband.xmin);
489 batch_out(brw, name, offset, 9, "guardband xmax = %f\n", vp->guardband.xmax);
490 batch_out(brw, name, offset, 9, "guardband ymin = %f\n", vp->guardband.ymin);
491 batch_out(brw, name, offset, 10, "guardband ymax = %f\n", vp->guardband.ymax);
492 if (brw->gen >= 8) {
493 float *cc_vp = brw->batch.bo->virtual + offset;
494 batch_out(brw, name, offset, 12, "Min extents: %.2fx%.2f\n",
495 cc_vp[12], cc_vp[14]);
496 batch_out(brw, name, offset, 14, "Max extents: %.2fx%.2f\n",
497 cc_vp[13], cc_vp[15]);
498 }
499 }
500
501
502 static void dump_cc_viewport_state(struct brw_context *brw, uint32_t offset)
503 {
504 const char *name = "CC VP";
505 struct brw_cc_viewport *vp = brw->batch.bo->virtual + offset;
506
507 batch_out(brw, name, offset, 0, "min_depth = %f\n", vp->min_depth);
508 batch_out(brw, name, offset, 1, "max_depth = %f\n", vp->max_depth);
509 }
510
511 static void dump_depth_stencil_state(struct brw_context *brw, uint32_t offset)
512 {
513 const char *name = "D_S";
514 struct gen6_depth_stencil_state *ds = brw->batch.bo->virtual + offset;
515
516 batch_out(brw, name, offset, 0,
517 "stencil %sable, func %d, write %sable\n",
518 ds->ds0.stencil_enable ? "en" : "dis",
519 ds->ds0.stencil_func,
520 ds->ds0.stencil_write_enable ? "en" : "dis");
521 batch_out(brw, name, offset, 1,
522 "stencil test mask 0x%x, write mask 0x%x\n",
523 ds->ds1.stencil_test_mask, ds->ds1.stencil_write_mask);
524 batch_out(brw, name, offset, 2,
525 "depth test %sable, func %d, write %sable\n",
526 ds->ds2.depth_test_enable ? "en" : "dis",
527 ds->ds2.depth_test_func,
528 ds->ds2.depth_write_enable ? "en" : "dis");
529 }
530
531 static void dump_cc_state_gen4(struct brw_context *brw, uint32_t offset)
532 {
533 const char *name = "CC";
534
535 batch_out(brw, name, offset, 0, "cc0\n");
536 batch_out(brw, name, offset, 1, "cc1\n");
537 batch_out(brw, name, offset, 2, "cc2\n");
538 batch_out(brw, name, offset, 3, "cc3\n");
539 batch_out(brw, name, offset, 4, "cc4: viewport offset\n");
540 batch_out(brw, name, offset, 5, "cc5\n");
541 batch_out(brw, name, offset, 6, "cc6\n");
542 batch_out(brw, name, offset, 7, "cc7\n");
543 }
544
545 static void dump_cc_state_gen6(struct brw_context *brw, uint32_t offset)
546 {
547 const char *name = "CC";
548 struct gen6_color_calc_state *cc = brw->batch.bo->virtual + offset;
549
550 batch_out(brw, name, offset, 0,
551 "alpha test format %s, round disable %d, stencil ref %d, "
552 "bf stencil ref %d\n",
553 cc->cc0.alpha_test_format ? "FLOAT32" : "UNORM8",
554 cc->cc0.round_disable,
555 cc->cc0.stencil_ref,
556 cc->cc0.bf_stencil_ref);
557 batch_out(brw, name, offset, 1, "\n");
558 batch_out(brw, name, offset, 2, "constant red %f\n", cc->constant_r);
559 batch_out(brw, name, offset, 3, "constant green %f\n", cc->constant_g);
560 batch_out(brw, name, offset, 4, "constant blue %f\n", cc->constant_b);
561 batch_out(brw, name, offset, 5, "constant alpha %f\n", cc->constant_a);
562 }
563
564 static void dump_blend_state(struct brw_context *brw, uint32_t offset)
565 {
566 const char *name = "BLEND";
567
568 batch_out(brw, name, offset, 0, "\n");
569 batch_out(brw, name, offset, 1, "\n");
570 }
571
572 static void
573 gen8_dump_blend_state(struct brw_context *brw, uint32_t offset, uint32_t size)
574 {
575 const uint32_t *blend = brw->batch.bo->virtual + offset;
576 const char *logicop[] =
577 {
578 "LOGICOP_CLEAR (BLACK)",
579 "LOGICOP_NOR",
580 "LOGICOP_AND_INVERTED",
581 "LOGICOP_COPY_INVERTED",
582 "LOGICOP_AND_REVERSE",
583 "LOGICOP_INVERT",
584 "LOGICOP_XOR",
585 "LOGICOP_NAND",
586 "LOGICOP_AND",
587 "LOGICOP_EQUIV",
588 "LOGICOP_NOOP",
589 "LOGICOP_OR_INVERTED",
590 "LOGICOP_COPY",
591 "LOGICOP_OR_REVERSE",
592 "LOGICOP_OR",
593 "LOGICOP_SET (WHITE)"
594 };
595
596 const char *blend_function[] =
597 { "ADD", "SUBTRACT", "REVERSE_SUBTRACT", "MIN", "MAX};" };
598
599 const char *blend_factor[0x1b] =
600 {
601 "RSVD",
602 "ONE",
603 "SRC_COLOR", "SRC_ALPHA",
604 "DST_ALPHA", "DST_COLOR",
605 "SRC_ALPHA_SATURATE",
606 "CONST_COLOR", "CONST_ALPHA",
607 "SRC1_COLOR", "SRC1_ALPHA",
608 "RSVD", "RSVD", "RSVD", "RSVD", "RSVD", "RSVD",
609 "ZERO",
610 "INV_SRC_COLOR", "INV_SRC_ALPHA",
611 "INV_DST_ALPHA", "INV_DST_COLOR",
612 "RSVD",
613 "INV_CONST_COLOR", "INV_CONST_ALPHA",
614 "INV_SRC1_COLOR", "INV_SRC1_ALPHA"
615 };
616
617 batch_out(brw, "BLEND", offset, 0, "Alpha blend/test\n");
618
619 if (((size) % 2) != 0)
620 fprintf(stderr, "Invalid blend state size %d\n", size);
621
622 for (int i = 1; i < size / 4; i += 2) {
623 char name[sizeof("BLEND_ENTRYXXX")];
624 sprintf(name, "BLEND_ENTRY%02d", (i - 1) / 2);
625 if (blend[i + 1] & GEN8_BLEND_LOGIC_OP_ENABLE) {
626 batch_out(brw, name, offset, i + 1, "%s\n",
627 logicop[GET_FIELD(blend[i + 1],
628 GEN8_BLEND_LOGIC_OP_FUNCTION)]);
629 } else if (blend[i] & GEN8_BLEND_COLOR_BUFFER_BLEND_ENABLE) {
630 batch_out64(brw, name, offset, i,
631 "\n\t\t\tColor Buffer Blend factor %s,%s,%s,%s (src,dst,src alpha, dst alpha)"
632 "\n\t\t\tfunction %s,%s (color, alpha), Disables: %c%c%c%c\n",
633 blend_factor[GET_FIELD(blend[i],
634 GEN8_BLEND_SRC_BLEND_FACTOR)],
635 blend_factor[GET_FIELD(blend[i],
636 GEN8_BLEND_DST_BLEND_FACTOR)],
637 blend_factor[GET_FIELD(blend[i],
638 GEN8_BLEND_SRC_ALPHA_BLEND_FACTOR)],
639 blend_factor[GET_FIELD(blend[i],
640 GEN8_BLEND_DST_ALPHA_BLEND_FACTOR)],
641 blend_function[GET_FIELD(blend[i],
642 GEN8_BLEND_COLOR_BLEND_FUNCTION)],
643 blend_function[GET_FIELD(blend[i],
644 GEN8_BLEND_ALPHA_BLEND_FUNCTION)],
645 blend[i] & GEN8_BLEND_WRITE_DISABLE_RED ? 'R' : '-',
646 blend[i] & GEN8_BLEND_WRITE_DISABLE_GREEN ? 'G' : '-',
647 blend[i] & GEN8_BLEND_WRITE_DISABLE_BLUE ? 'B' : '-',
648 blend[i] & GEN8_BLEND_WRITE_DISABLE_ALPHA ? 'A' : '-'
649 );
650 } else if (!blend[i] && (blend[i + 1] == 0xb)) {
651 batch_out64(brw, name, offset, i, "NOP blend state\n");
652 } else {
653 batch_out64(brw, name, offset, i, "????\n");
654 }
655 }
656 }
657
658 static void
659 dump_scissor(struct brw_context *brw, uint32_t offset)
660 {
661 const char *name = "SCISSOR";
662 struct gen6_scissor_rect *scissor = brw->batch.bo->virtual + offset;
663
664 batch_out(brw, name, offset, 0, "xmin %d, ymin %d\n",
665 scissor->xmin, scissor->ymin);
666 batch_out(brw, name, offset, 1, "xmax %d, ymax %d\n",
667 scissor->xmax, scissor->ymax);
668 }
669
670 static void
671 dump_vs_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
672 {
673 const char *name = "VS_CONST";
674 uint32_t *as_uint = brw->batch.bo->virtual + offset;
675 float *as_float = brw->batch.bo->virtual + offset;
676 int i;
677
678 for (i = 0; i < size / 4; i += 4) {
679 batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n",
680 i / 4,
681 as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
682 as_uint[i], as_uint[i + 1], as_uint[i + 2], as_uint[i + 3]);
683 }
684 }
685
686 static void
687 dump_wm_constants(struct brw_context *brw, uint32_t offset, uint32_t size)
688 {
689 const char *name = "WM_CONST";
690 uint32_t *as_uint = brw->batch.bo->virtual + offset;
691 float *as_float = brw->batch.bo->virtual + offset;
692 int i;
693
694 for (i = 0; i < size / 4; i += 4) {
695 batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 0x%08x 0x%08x)\n",
696 i / 4,
697 as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
698 as_uint[i], as_uint[i + 1], as_uint[i + 2], as_uint[i + 3]);
699 }
700 }
701
702 static void dump_binding_table(struct brw_context *brw, uint32_t offset,
703 uint32_t size)
704 {
705 char name[20];
706 int i;
707 uint32_t *data = brw->batch.bo->virtual + offset;
708
709 for (i = 0; i < size / 4; i++) {
710 if (data[i] == 0)
711 continue;
712
713 sprintf(name, "BIND%d", i);
714 batch_out(brw, name, offset, i, "surface state address\n");
715 }
716 }
717
718 static void
719 dump_prog_cache(struct brw_context *brw)
720 {
721 struct brw_cache *cache = &brw->cache;
722 unsigned int b;
723
724 drm_intel_bo_map(brw->cache.bo, false);
725
726 for (b = 0; b < cache->size; b++) {
727 struct brw_cache_item *item;
728
729 for (item = cache->items[b]; item; item = item->next) {
730 const char *name;
731
732 switch (item->cache_id) {
733 case BRW_CACHE_VS_PROG:
734 name = "VS kernel";
735 break;
736 case BRW_CACHE_TCS_PROG:
737 name = "TCS kernel";
738 break;
739 case BRW_CACHE_TES_PROG:
740 name = "TES kernel";
741 break;
742 case BRW_CACHE_FF_GS_PROG:
743 name = "Fixed-function GS kernel";
744 break;
745 case BRW_CACHE_GS_PROG:
746 name = "GS kernel";
747 break;
748 case BRW_CACHE_CLIP_PROG:
749 name = "CLIP kernel";
750 break;
751 case BRW_CACHE_SF_PROG:
752 name = "SF kernel";
753 break;
754 case BRW_CACHE_FS_PROG:
755 name = "FS kernel";
756 break;
757 case BRW_CACHE_CS_PROG:
758 name = "CS kernel";
759 break;
760 default:
761 name = "unknown";
762 break;
763 }
764
765 fprintf(stderr, "%s:\n", name);
766 brw_disassemble(brw->intelScreen->devinfo, brw->cache.bo->virtual,
767 item->offset, item->size, stderr);
768 }
769 }
770
771 drm_intel_bo_unmap(brw->cache.bo);
772 }
773
774 static void
775 dump_state_batch(struct brw_context *brw)
776 {
777 int i;
778
779 for (i = 0; i < brw->state_batch_count; i++) {
780 uint32_t offset = brw->state_batch_list[i].offset;
781 uint32_t size = brw->state_batch_list[i].size;
782
783 switch (brw->state_batch_list[i].type) {
784 case AUB_TRACE_VS_STATE:
785 dump_vs_state(brw, offset);
786 break;
787 case AUB_TRACE_GS_STATE:
788 dump_gs_state(brw, offset);
789 break;
790 case AUB_TRACE_CLIP_STATE:
791 dump_clip_state(brw, offset);
792 break;
793 case AUB_TRACE_SF_STATE:
794 dump_sf_state(brw, offset);
795 break;
796 case AUB_TRACE_WM_STATE:
797 dump_wm_state(brw, offset);
798 break;
799 case AUB_TRACE_CLIP_VP_STATE:
800 dump_clip_viewport_state(brw, offset);
801 break;
802 case AUB_TRACE_SF_VP_STATE:
803 if (brw->gen >= 7) {
804 dump_sf_clip_viewport_state(brw, offset);
805 } else {
806 dump_sf_viewport_state(brw, offset);
807 }
808 break;
809 case AUB_TRACE_CC_VP_STATE:
810 dump_cc_viewport_state(brw, offset);
811 break;
812 case AUB_TRACE_DEPTH_STENCIL_STATE:
813 dump_depth_stencil_state(brw, offset);
814 break;
815 case AUB_TRACE_CC_STATE:
816 if (brw->gen >= 6)
817 dump_cc_state_gen6(brw, offset);
818 else
819 dump_cc_state_gen4(brw, offset);
820 break;
821 case AUB_TRACE_BLEND_STATE:
822 if (brw->gen >= 8)
823 gen8_dump_blend_state(brw, offset, size);
824 else
825 dump_blend_state(brw, offset);
826 break;
827 case AUB_TRACE_BINDING_TABLE:
828 dump_binding_table(brw, offset, size);
829 break;
830 case AUB_TRACE_SURFACE_STATE:
831 if (brw->gen >= 8) {
832 dump_gen8_surface_state(brw, offset,
833 brw->state_batch_list[i].index);
834 } else if (brw->gen >= 7) {
835 dump_gen7_surface_state(brw, offset);
836 } else {
837 dump_surface_state(brw, offset);
838 }
839 break;
840 case AUB_TRACE_SAMPLER_STATE:
841 if (brw->gen >= 7)
842 gen7_dump_sampler_state(brw, offset, size);
843 else
844 dump_sampler_state(brw, offset, size);
845 break;
846 case AUB_TRACE_SAMPLER_DEFAULT_COLOR:
847 dump_sdc(brw, offset);
848 break;
849 case AUB_TRACE_SCISSOR_STATE:
850 dump_scissor(brw, offset);
851 break;
852 case AUB_TRACE_VS_CONSTANTS:
853 dump_vs_constants(brw, offset, size);
854 break;
855 case AUB_TRACE_WM_CONSTANTS:
856 dump_wm_constants(brw, offset, size);
857 break;
858 default:
859 break;
860 }
861 }
862 }
863
864 /**
865 * Print additional debug information associated with the batchbuffer
866 * when DEBUG_BATCH is set.
867 *
868 * For 965, this means mapping the state buffers that would have been referenced
869 * by the batchbuffer and dumping them.
870 *
871 * The buffer offsets printed rely on the buffer containing the last offset
872 * it was validated at.
873 */
874 void brw_debug_batch(struct brw_context *brw)
875 {
876 drm_intel_bo_map(brw->batch.bo, false);
877 dump_state_batch(brw);
878 drm_intel_bo_unmap(brw->batch.bo);
879
880 if (0)
881 dump_prog_cache(brw);
882 }