blob: cc1e1f8cbaab726c1d2bd3d175566402b3dfa798 [file] [log] [blame]
Chia-I Wu00b51a82014-09-09 12:07:37 +08001/*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28#include <stdio.h>
29#include <stdarg.h>
30#include "genhw/genhw.h"
31#include "kmd/winsys.h"
32#include "cmd_priv.h"
33
34#define READ(dw, field) (((dw) & field ## __MASK) >> field ## __SHIFT)
35
36static const uint32_t *
37writer_pointer(const struct intel_cmd *cmd,
38 enum intel_cmd_writer_type which,
39 unsigned offset)
40{
41 const struct intel_cmd_writer *writer = &cmd->writers[which];
42 return (const uint32_t *) ((const char *) writer->ptr + offset);
43}
44
45static uint32_t
46writer_dw(const struct intel_cmd *cmd,
47 enum intel_cmd_writer_type which,
48 unsigned offset, unsigned dw_index,
49 const char *format, ...)
50{
51 const uint32_t *dw = writer_pointer(cmd, which, offset);
52 va_list ap;
53 char desc[16];
54 int len;
55
56 fprintf(stderr, "0x%08x: 0x%08x: ",
57 offset + (dw_index << 2), dw[dw_index]);
58
59 va_start(ap, format);
60 len = vsnprintf(desc, sizeof(desc), format, ap);
61 va_end(ap);
62
63 if (len >= sizeof(desc)) {
64 len = sizeof(desc) - 1;
65 desc[len] = '\0';
66 }
67
68 if (desc[len - 1] == '\n') {
69 desc[len - 1] = '\0';
70 fprintf(stderr, "%8s: \n", desc);
71 } else {
72 fprintf(stderr, "%8s: ", desc);
73 }
74
75 return dw[dw_index];
76}
77
78static void
79writer_decode_blob(const struct intel_cmd *cmd,
80 enum intel_cmd_writer_type which,
81 const struct intel_cmd_item *item)
82{
83 const unsigned state_size = sizeof(uint32_t) * 4;
84 const unsigned count = item->size / state_size;
85 unsigned offset = item->offset;
86 unsigned i;
87
88 for (i = 0; i < count; i++) {
89 const uint32_t *dw = writer_pointer(cmd, which, offset);
90
91 writer_dw(cmd, which, offset, 0, "BLOB%d", i);
92 /* output a single line for all four DWords */
93 fprintf(stderr, "(% f, % f, % f, % f) "
94 "(0x%08x, 0x%08x, 0x%08x, 0x%08x)\n",
95 u_uif(dw[0]), u_uif(dw[1]), u_uif(dw[2]), u_uif(dw[3]),
96 dw[0], dw[1], dw[2], dw[3]);
97
98 offset += state_size;
99 }
100}
101
102static void
103writer_decode_clip_viewport(const struct intel_cmd *cmd,
104 enum intel_cmd_writer_type which,
105 const struct intel_cmd_item *item)
106{
107 const unsigned state_size = sizeof(uint32_t) * 4;
108 const unsigned count = item->size / state_size;
109 unsigned offset = item->offset;
110 unsigned i;
111
112 for (i = 0; i < count; i++) {
113 uint32_t dw;
114
115 dw = writer_dw(cmd, which, offset, 0, "CLIP VP%d", i);
116 fprintf(stderr, "xmin = %f\n", u_uif(dw));
117
118 dw = writer_dw(cmd, which, offset, 1, "CLIP VP%d", i);
119 fprintf(stderr, "xmax = %f\n", u_uif(dw));
120
121 dw = writer_dw(cmd, which, offset, 2, "CLIP VP%d", i);
122 fprintf(stderr, "ymin = %f\n", u_uif(dw));
123
124 dw = writer_dw(cmd, which, offset, 3, "CLIP VP%d", i);
125 fprintf(stderr, "ymax = %f\n", u_uif(dw));
126
127 offset += state_size;
128 }
129}
130
131static void
132writer_decode_sf_clip_viewport_gen7(const struct intel_cmd *cmd,
133 enum intel_cmd_writer_type which,
134 const struct intel_cmd_item *item)
135{
136 const unsigned state_size = sizeof(uint32_t) * 16;
137 const unsigned count = item->size / state_size;
138 unsigned offset = item->offset;
139 unsigned i;
140
141 for (i = 0; i < count; i++) {
142 uint32_t dw;
143
144 dw = writer_dw(cmd, which, offset, 0, "SF_CLIP VP%d", i);
145 fprintf(stderr, "m00 = %f\n", u_uif(dw));
146
147 dw = writer_dw(cmd, which, offset, 1, "SF_CLIP VP%d", i);
148 fprintf(stderr, "m11 = %f\n", u_uif(dw));
149
150 dw = writer_dw(cmd, which, offset, 2, "SF_CLIP VP%d", i);
151 fprintf(stderr, "m22 = %f\n", u_uif(dw));
152
153 dw = writer_dw(cmd, which, offset, 3, "SF_CLIP VP%d", i);
154 fprintf(stderr, "m30 = %f\n", u_uif(dw));
155
156 dw = writer_dw(cmd, which, offset, 4, "SF_CLIP VP%d", i);
157 fprintf(stderr, "m31 = %f\n", u_uif(dw));
158
159 dw = writer_dw(cmd, which, offset, 5, "SF_CLIP VP%d", i);
160 fprintf(stderr, "m32 = %f\n", u_uif(dw));
161
162 dw = writer_dw(cmd, which, offset, 8, "SF_CLIP VP%d", i);
163 fprintf(stderr, "guardband xmin = %f\n", u_uif(dw));
164
165 dw = writer_dw(cmd, which, offset, 9, "SF_CLIP VP%d", i);
166 fprintf(stderr, "guardband xmax = %f\n", u_uif(dw));
167
168 dw = writer_dw(cmd, which, offset, 10, "SF_CLIP VP%d", i);
169 fprintf(stderr, "guardband ymin = %f\n", u_uif(dw));
170
171 dw = writer_dw(cmd, which, offset, 11, "SF_CLIP VP%d", i);
172 fprintf(stderr, "guardband ymax = %f\n", u_uif(dw));
173
174 offset += state_size;
175 }
176}
177
178static void
179writer_decode_sf_viewport_gen6(const struct intel_cmd *cmd,
180 enum intel_cmd_writer_type which,
181 const struct intel_cmd_item *item)
182{
183 const unsigned state_size = sizeof(uint32_t) * 8;
184 const unsigned count = item->size / state_size;
185 unsigned offset = item->offset;
186 unsigned i;
187
188 for (i = 0; i < count; i++) {
189 uint32_t dw;
190
191 dw = writer_dw(cmd, which, offset, 0, "SF VP%d", i);
192 fprintf(stderr, "m00 = %f\n", u_uif(dw));
193
194 dw = writer_dw(cmd, which, offset, 1, "SF VP%d", i);
195 fprintf(stderr, "m11 = %f\n", u_uif(dw));
196
197 dw = writer_dw(cmd, which, offset, 2, "SF VP%d", i);
198 fprintf(stderr, "m22 = %f\n", u_uif(dw));
199
200 dw = writer_dw(cmd, which, offset, 3, "SF VP%d", i);
201 fprintf(stderr, "m30 = %f\n", u_uif(dw));
202
203 dw = writer_dw(cmd, which, offset, 4, "SF VP%d", i);
204 fprintf(stderr, "m31 = %f\n", u_uif(dw));
205
206 dw = writer_dw(cmd, which, offset, 5, "SF VP%d", i);
207 fprintf(stderr, "m32 = %f\n", u_uif(dw));
208
209 offset += state_size;
210 }
211}
212
213static void
214writer_decode_sf_viewport(const struct intel_cmd *cmd,
215 enum intel_cmd_writer_type which,
216 const struct intel_cmd_item *item)
217{
218 if (cmd_gen(cmd) >= INTEL_GEN(7))
219 writer_decode_sf_clip_viewport_gen7(cmd, which, item);
220 else
221 writer_decode_sf_viewport_gen6(cmd, which, item);
222}
223
224static void
225writer_decode_scissor_rect(const struct intel_cmd *cmd,
226 enum intel_cmd_writer_type which,
227 const struct intel_cmd_item *item)
228{
229 const unsigned state_size = sizeof(uint32_t) * 2;
230 const unsigned count = item->size / state_size;
231 unsigned offset = item->offset;
232 unsigned i;
233
234 for (i = 0; i < count; i++) {
235 uint32_t dw;
236
237 dw = writer_dw(cmd, which, offset, 0, "SCISSOR%d", i);
238 fprintf(stderr, "xmin %d, ymin %d\n",
239 READ(dw, GEN6_SCISSOR_DW0_MIN_X),
240 READ(dw, GEN6_SCISSOR_DW0_MIN_Y));
241
242 dw = writer_dw(cmd, which, offset, 1, "SCISSOR%d", i);
243 fprintf(stderr, "xmax %d, ymax %d\n",
244 READ(dw, GEN6_SCISSOR_DW1_MAX_X),
245 READ(dw, GEN6_SCISSOR_DW1_MAX_Y));
246
247 offset += state_size;
248 }
249}
250
251static void
252writer_decode_cc_viewport(const struct intel_cmd *cmd,
253 enum intel_cmd_writer_type which,
254 const struct intel_cmd_item *item)
255{
256 const unsigned state_size = sizeof(uint32_t) * 2;
257 const unsigned count = item->size / state_size;
258 unsigned offset = item->offset;
259 unsigned i;
260
261 for (i = 0; i < count; i++) {
262 uint32_t dw;
263
264 dw = writer_dw(cmd, which, offset, 0, "CC VP%d", i);
265 fprintf(stderr, "min_depth = %f\n", u_uif(dw));
266
267 dw = writer_dw(cmd, which, offset, 1, "CC VP%d", i);
268 fprintf(stderr, "max_depth = %f\n", u_uif(dw));
269
270 offset += state_size;
271 }
272}
273
274static void
275writer_decode_color_calc(const struct intel_cmd *cmd,
276 enum intel_cmd_writer_type which,
277 const struct intel_cmd_item *item)
278{
279 uint32_t dw;
280
281 dw = writer_dw(cmd, which, item->offset, 0, "CC");
282 fprintf(stderr, "alpha test format %s, round disable %d, "
283 "stencil ref %d, bf stencil ref %d\n",
284 READ(dw, GEN6_CC_DW0_ALPHATEST) ? "FLOAT32" : "UNORM8",
285 (bool) (dw & GEN6_CC_DW0_ROUND_DISABLE_DISABLE),
286 READ(dw, GEN6_CC_DW0_STENCIL0_REF),
287 READ(dw, GEN6_CC_DW0_STENCIL1_REF));
288
289 writer_dw(cmd, which, item->offset, 1, "CC\n");
290
291 dw = writer_dw(cmd, which, item->offset, 2, "CC");
292 fprintf(stderr, "constant red %f\n", u_uif(dw));
293
294 dw = writer_dw(cmd, which, item->offset, 3, "CC");
295 fprintf(stderr, "constant green %f\n", u_uif(dw));
296
297 dw = writer_dw(cmd, which, item->offset, 4, "CC");
298 fprintf(stderr, "constant blue %f\n", u_uif(dw));
299
300 dw = writer_dw(cmd, which, item->offset, 5, "CC");
301 fprintf(stderr, "constant alpha %f\n", u_uif(dw));
302}
303
304static void
305writer_decode_depth_stencil(const struct intel_cmd *cmd,
306 enum intel_cmd_writer_type which,
307 const struct intel_cmd_item *item)
308{
309 uint32_t dw;
310
311 dw = writer_dw(cmd, which, item->offset, 0, "D_S");
312 fprintf(stderr, "stencil %sable, func %d, write %sable\n",
313 (dw & GEN6_ZS_DW0_STENCIL_TEST_ENABLE) ? "en" : "dis",
314 READ(dw, GEN6_ZS_DW0_STENCIL0_FUNC),
315 (dw & GEN6_ZS_DW0_STENCIL_WRITE_ENABLE) ? "en" : "dis");
316
317 dw = writer_dw(cmd, which, item->offset, 1, "D_S");
318 fprintf(stderr, "stencil test mask 0x%x, write mask 0x%x\n",
319 READ(dw, GEN6_ZS_DW1_STENCIL0_VALUEMASK),
320 READ(dw, GEN6_ZS_DW1_STENCIL0_WRITEMASK));
321
322 dw = writer_dw(cmd, which, item->offset, 2, "D_S");
323 fprintf(stderr, "depth test %sable, func %d, write %sable\n",
324 (dw & GEN6_ZS_DW2_DEPTH_TEST_ENABLE) ? "en" : "dis",
325 READ(dw, GEN6_ZS_DW2_DEPTH_FUNC),
326 (dw & GEN6_ZS_DW2_DEPTH_WRITE_ENABLE) ? "en" : "dis");
327}
328
329static void
330writer_decode_blend(const struct intel_cmd *cmd,
331 enum intel_cmd_writer_type which,
332 const struct intel_cmd_item *item)
333{
334 const unsigned state_size = sizeof(uint32_t) * 2;
335 const unsigned count = item->size / state_size;
336 unsigned offset = item->offset;
337 unsigned i;
338
339 for (i = 0; i < count; i++) {
340 writer_dw(cmd, which, offset, 0, "BLEND%d\n", i);
341 writer_dw(cmd, which, offset, 1, "BLEND%d\n", i);
342
343 offset += state_size;
344 }
345}
346
347static void
348writer_decode_sampler(const struct intel_cmd *cmd,
349 enum intel_cmd_writer_type which,
350 const struct intel_cmd_item *item)
351{
352 const unsigned state_size = sizeof(uint32_t) * 4;
353 const unsigned count = item->size / state_size;
354 unsigned offset = item->offset;
355 unsigned i;
356
357 for (i = 0; i < count; i++) {
358 writer_dw(cmd, which, offset, 0, "WM SAMP%d", i);
359 fprintf(stderr, "filtering\n");
360
361 writer_dw(cmd, which, offset, 1, "WM SAMP%d", i);
362 fprintf(stderr, "wrapping, lod\n");
363
364 writer_dw(cmd, which, offset, 2, "WM SAMP%d", i);
365 fprintf(stderr, "default color pointer\n");
366
367 writer_dw(cmd, which, offset, 3, "WM SAMP%d", i);
368 fprintf(stderr, "chroma key, aniso\n");
369
370 offset += state_size;
371 }
372}
373
374static void
375writer_decode_surface_gen7(const struct intel_cmd *cmd,
376 enum intel_cmd_writer_type which,
377 const struct intel_cmd_item *item)
378{
379 uint32_t dw;
380
381 dw = writer_dw(cmd, which, item->offset, 0, "SURF");
382 fprintf(stderr, "type 0x%x, format 0x%x, tiling %d, %s array\n",
383 READ(dw, GEN7_SURFACE_DW0_TYPE),
384 READ(dw, GEN7_SURFACE_DW0_FORMAT),
385 READ(dw, GEN7_SURFACE_DW0_TILING),
386 (dw & GEN7_SURFACE_DW0_IS_ARRAY) ? "is" : "not");
387
388 writer_dw(cmd, which, item->offset, 1, "SURF");
389 fprintf(stderr, "offset\n");
390
391 dw = writer_dw(cmd, which, item->offset, 2, "SURF");
392 fprintf(stderr, "%dx%d size\n",
393 READ(dw, GEN7_SURFACE_DW2_WIDTH),
394 READ(dw, GEN7_SURFACE_DW2_HEIGHT));
395
396 dw = writer_dw(cmd, which, item->offset, 3, "SURF");
397 fprintf(stderr, "depth %d, pitch %d\n",
398 READ(dw, GEN7_SURFACE_DW3_DEPTH),
399 READ(dw, GEN7_SURFACE_DW3_PITCH));
400
401 dw = writer_dw(cmd, which, item->offset, 4, "SURF");
402 fprintf(stderr, "min array element %d, array extent %d\n",
403 READ(dw, GEN7_SURFACE_DW4_MIN_ARRAY_ELEMENT),
404 READ(dw, GEN7_SURFACE_DW4_RT_VIEW_EXTENT));
405
406 dw = writer_dw(cmd, which, item->offset, 5, "SURF");
407 fprintf(stderr, "mip base %d, mips %d, x,y offset: %d,%d\n",
408 READ(dw, GEN7_SURFACE_DW5_MIN_LOD),
409 READ(dw, GEN7_SURFACE_DW5_MIP_COUNT_LOD),
410 READ(dw, GEN7_SURFACE_DW5_X_OFFSET),
411 READ(dw, GEN7_SURFACE_DW5_Y_OFFSET));
412
413 writer_dw(cmd, which, item->offset, 6, "SURF\n");
414 writer_dw(cmd, which, item->offset, 7, "SURF\n");
415}
416
417static void
418writer_decode_surface_gen6(const struct intel_cmd *cmd,
419 enum intel_cmd_writer_type which,
420 const struct intel_cmd_item *item)
421{
422 uint32_t dw;
423
424 dw = writer_dw(cmd, which, item->offset, 0, "SURF");
425 fprintf(stderr, "type 0x%x, format 0x%x\n",
426 READ(dw, GEN6_SURFACE_DW0_TYPE),
427 READ(dw, GEN6_SURFACE_DW0_FORMAT));
428
429 writer_dw(cmd, which, item->offset, 1, "SURF");
430 fprintf(stderr, "offset\n");
431
432 dw = writer_dw(cmd, which, item->offset, 2, "SURF");
433 fprintf(stderr, "%dx%d size, %d mips\n",
434 READ(dw, GEN6_SURFACE_DW2_WIDTH),
435 READ(dw, GEN6_SURFACE_DW2_HEIGHT),
436 READ(dw, GEN6_SURFACE_DW2_MIP_COUNT_LOD));
437
438 dw = writer_dw(cmd, which, item->offset, 3, "SURF");
439 fprintf(stderr, "pitch %d, tiling %d\n",
440 READ(dw, GEN6_SURFACE_DW3_PITCH),
441 READ(dw, GEN6_SURFACE_DW3_TILING));
442
443 dw = writer_dw(cmd, which, item->offset, 4, "SURF");
444 fprintf(stderr, "mip base %d\n",
445 READ(dw, GEN6_SURFACE_DW4_MIN_LOD));
446
447 dw = writer_dw(cmd, which, item->offset, 5, "SURF");
448 fprintf(stderr, "x,y offset: %d,%d\n",
449 READ(dw, GEN6_SURFACE_DW5_X_OFFSET),
450 READ(dw, GEN6_SURFACE_DW5_Y_OFFSET));
451}
452
453static void
454writer_decode_surface(const struct intel_cmd *cmd,
455 enum intel_cmd_writer_type which,
456 const struct intel_cmd_item *item)
457{
458 if (cmd_gen(cmd) >= INTEL_GEN(7))
459 writer_decode_surface_gen7(cmd, which, item);
460 else
461 writer_decode_surface_gen6(cmd, which, item);
462}
463
464static void
465writer_decode_binding_table(const struct intel_cmd *cmd,
466 enum intel_cmd_writer_type which,
467 const struct intel_cmd_item *item)
468{
469 const unsigned state_size = sizeof(uint32_t) * 1;
470 const unsigned count = item->size / state_size;
471 unsigned offset = item->offset;
472 unsigned i;
473
474 for (i = 0; i < count; i++) {
475 writer_dw(cmd, which, offset, 0, "BIND");
476 fprintf(stderr, "BINDING_TABLE_STATE[%d]\n", i);
477
478 offset += state_size;
479 }
480}
481
482static void
483writer_decode_kernel(const struct intel_cmd *cmd,
484 enum intel_cmd_writer_type which,
485 const struct intel_cmd_item *item)
486{
487}
488
489static const struct {
490 void (*func)(const struct intel_cmd *cmd,
491 enum intel_cmd_writer_type which,
492 const struct intel_cmd_item *item);
493} writer_decode_table[INTEL_CMD_ITEM_COUNT] = {
494 [INTEL_CMD_ITEM_BLOB] = { writer_decode_blob },
495 [INTEL_CMD_ITEM_CLIP_VIEWPORT] = { writer_decode_clip_viewport },
496 [INTEL_CMD_ITEM_SF_VIEWPORT] = { writer_decode_sf_viewport },
497 [INTEL_CMD_ITEM_SCISSOR_RECT] = { writer_decode_scissor_rect },
498 [INTEL_CMD_ITEM_CC_VIEWPORT] = { writer_decode_cc_viewport },
499 [INTEL_CMD_ITEM_COLOR_CALC] = { writer_decode_color_calc },
500 [INTEL_CMD_ITEM_DEPTH_STENCIL] = { writer_decode_depth_stencil },
501 [INTEL_CMD_ITEM_BLEND] = { writer_decode_blend },
502 [INTEL_CMD_ITEM_SAMPLER] = { writer_decode_sampler },
503 [INTEL_CMD_ITEM_SURFACE] = { writer_decode_surface },
504 [INTEL_CMD_ITEM_BINDING_TABLE] = { writer_decode_binding_table },
505 [INTEL_CMD_ITEM_KERNEL] = { writer_decode_kernel },
506};
507
508static void cmd_writer_decode_items(struct intel_cmd *cmd,
509 enum intel_cmd_writer_type which)
510{
511 struct intel_cmd_writer *writer = &cmd->writers[which];
512 int i;
513
514 if (!writer->item_used)
515 return;
516
517 writer->ptr = intel_bo_map(writer->bo, false);
518 if (!writer->ptr)
519 return;
520
521 for (i = 0; i < writer->item_used; i++) {
522 const struct intel_cmd_item *item = &writer->items[i];
523
524 writer_decode_table[item->type].func(cmd, which, item);
525 }
526
527 intel_bo_unmap(writer->bo);
528}
529
530static void cmd_writer_decode(struct intel_cmd *cmd,
531 enum intel_cmd_writer_type which)
532{
533 struct intel_cmd_writer *writer = &cmd->writers[which];
534
535 assert(writer->bo && !writer->ptr);
536
537 switch (which) {
538 case INTEL_CMD_WRITER_BATCH:
539 fprintf(stderr, "decoding batch buffer: %d bytes\n", writer->used);
540 if (writer->used) {
541 intel_winsys_decode_bo(cmd->dev->winsys,
542 writer->bo, writer->used);
543 }
544 break;
545 case INTEL_CMD_WRITER_STATE:
546 fprintf(stderr, "decoding state buffer: %d states\n",
547 writer->item_used);
548 cmd_writer_decode_items(cmd, which);
549 break;
550 case INTEL_CMD_WRITER_INSTRUCTION:
551 if (true) {
552 fprintf(stderr, "skipping instruction buffer: %d kernels\n",
553 writer->item_used);
554 } else {
555 fprintf(stderr, "decoding instruction buffer: %d kernels\n",
556 writer->item_used);
557
558 cmd_writer_decode_items(cmd, which);
559 }
560 break;
561 default:
562 break;
563 }
564}
565
566/**
567 * Decode according to the recorded items. This can be called only after a
568 * successful intel_cmd_end().
569 */
570void intel_cmd_decode(struct intel_cmd *cmd)
571{
572 int i;
573
574 assert(cmd->result == XGL_SUCCESS);
575
576 for (i = 0; i < INTEL_CMD_WRITER_COUNT; i++)
577 cmd_writer_decode(cmd, i);
578}