- uint64_t addr = p[0] & ~0xfffu;
-
- if (gen_spec_get_gen(spec) >= gen_make_gen(8,0)) {
- /* On Broadwell and above, we have 48-bit addresses which consume two
- * dwords. Some packets require that these get stored in a "canonical
- * form" which means that bit 47 is sign-extended through the upper
- * bits. In order to correctly handle those aub dumps, we need to mask
- * off the top 16 bits.
- */
- addr |= ((uint64_t)p[1] & 0xffff) << 32;
- }
-
- return addr;
-}
-
-static inline uint64_t
-get_offset(uint32_t *p, uint32_t start, uint32_t end)
-{
- assert(start <= end);
- assert(end < 64);
-
- uint64_t mask = (~0ull >> (64 - (end - start + 1))) << start;
-
- uint64_t offset = p[0];
- if (end >= 32)
- offset |= (uint64_t) p[1] << 32;
-
- return offset & mask;
-}
-
-static void
-handle_state_base_address(struct gen_spec *spec, uint32_t *p)
-{
- if (gen_spec_get_gen(spec) >= gen_make_gen(8,0)) {
- if (p[1] & 1)
- general_state_base = get_address(spec, &p[1]);
- if (p[4] & 1)
- surface_state_base = get_address(spec, &p[4]);
- if (p[6] & 1)
- dynamic_state_base = get_address(spec, &p[6]);
- if (p[10] & 1)
- instruction_base = get_address(spec, &p[10]);
- if (p[15] & 1)
- instruction_bound = p[15] & 0xfff;
- } else {
- if (p[2] & 1)
- surface_state_base = get_address(spec, &p[2]);
- if (p[3] & 1)
- dynamic_state_base = get_address(spec, &p[3]);
- if (p[5] & 1)
- instruction_base = get_address(spec, &p[5]);
- if (p[9] & 1)
- instruction_bound = get_address(spec, &p[9]);
- }
-}
-
-static void
-dump_samplers(struct gen_spec *spec, uint32_t offset)
-{
- uint32_t i;
- uint64_t start;
- struct gen_group *sampler_state;
-
- sampler_state = gen_spec_find_struct(spec, "SAMPLER_STATE");
-
- start = dynamic_state_base + offset;
- for (i = 0; i < 4; i++) {
- fprintf(outfile, "sampler state %d\n", i);
- decode_group(spec, sampler_state, gtt + start + i * 16, 0);
- }
-}
-
-static void
-handle_media_interface_descriptor_load(struct gen_spec *spec, uint32_t *p)
-{
- int i, length = p[2] / 32;
- struct gen_group *descriptor_structure;
- uint32_t *descriptors;
- uint64_t start;
- struct brw_instruction *insns;
-
- descriptor_structure =
- gen_spec_find_struct(spec, "INTERFACE_DESCRIPTOR_DATA");
- if (descriptor_structure == NULL) {
- fprintf(outfile, "did not find INTERFACE_DESCRIPTOR_DATA info\n");
- return;
- }
-
- start = dynamic_state_base + p[3];
- descriptors = gtt + start;
- for (i = 0; i < length; i++, descriptors += 8) {
- fprintf(outfile, "descriptor %u: %08x\n", i, *descriptors);
- decode_group(spec, descriptor_structure, descriptors, 0);
-
- start = instruction_base + descriptors[0];
- if (!valid_offset(start)) {
- fprintf(outfile, "kernel: %08"PRIx64" <not valid>\n", start);
- continue;
- } else {
- fprintf(outfile, "kernel: %08"PRIx64"\n", start);
- }
-
- insns = (struct brw_instruction *) (gtt + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
-
- dump_samplers(spec, descriptors[3] & ~0x1f);
- dump_binding_table(spec, descriptors[4] & ~0x1f);
- }
-}
-
-/* Heuristic to determine whether a uint32_t is probably actually a float
- * (http://stackoverflow.com/a/2953466)
- */
-
-static bool
-probably_float(uint32_t bits)
-{
- int exp = ((bits & 0x7f800000U) >> 23) - 127;
- uint32_t mant = bits & 0x007fffff;
-
- /* +- 0.0 */
- if (exp == -127 && mant == 0)
- return true;
-
- /* +- 1 billionth to 1 billion */
- if (-30 <= exp && exp <= 30)
- return true;
-
- /* some value with only a few binary digits */
- if ((mant & 0x0000ffff) == 0)
- return true;
-
- return false;
-}
-
-static void
-handle_3dstate_vertex_buffers(struct gen_spec *spec, uint32_t *p)
-{
- uint32_t *end, *s, *dw, *dwend;
- uint64_t offset;
- int n, i, count, stride;
-
- end = (p[0] & 0xff) + p + 2;
- for (s = &p[1], n = 0; s < end; s += 4, n++) {
- if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
- offset = *(uint64_t *) &s[1];
- dwend = gtt + offset + s[3];
- } else {
- offset = s[1];
- dwend = gtt + s[2] + 1;
- }
-
- stride = field(s[0], 0, 11);
- count = 0;
- fprintf(outfile, "vertex buffer %d, size %d\n", n, s[3]);
- for (dw = gtt + offset, i = 0; dw < dwend && i < 256; dw++) {
- if (count == 0 && count % (8 * 4) == 0)
- fprintf(outfile, " ");
-
- if (probably_float(*dw))
- fprintf(outfile, " %8.2f", *(float *) dw);
- else
- fprintf(outfile, " 0x%08x", *dw);
-
- i++;
- count += 4;
-
- if (count == stride) {
- fprintf(outfile, "\n");
- count = 0;
- } else if (count % (8 * 4) == 0) {
- fprintf(outfile, "\n");
- } else {
- fprintf(outfile, " ");
- }
- }
- if (count > 0 && count % (8 * 4) != 0)
- fprintf(outfile, "\n");
- }
-}
-
-static void
-handle_3dstate_vs(struct gen_spec *spec, uint32_t *p)
-{
- uint64_t start;
- struct brw_instruction *insns;
- int vs_enable;
-
- if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
- start = get_offset(&p[1], 6, 63);
- vs_enable = p[7] & 1;
- } else {
- start = get_offset(&p[1], 6, 31);
- vs_enable = p[5] & 1;
- }
-
- if (vs_enable) {
- fprintf(outfile, "instruction_base %08"PRIx64", start %08"PRIx64"\n",
- instruction_base, start);
-
- insns = (struct brw_instruction *) (gtt + instruction_base + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
- }
-}
-
-static void
-handle_3dstate_hs(struct gen_spec *spec, uint32_t *p)
-{
- uint64_t start;
- struct brw_instruction *insns;
- int hs_enable;
-
- if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
- start = get_offset(&p[3], 6, 63);
- } else {
- start = get_offset(&p[3], 6, 31);
- }
-
- hs_enable = p[2] & 0x80000000;
-
- if (hs_enable) {
- fprintf(outfile, "instruction_base %08"PRIx64", start %08"PRIx64"\n",
- instruction_base, start);
-
- insns = (struct brw_instruction *) (gtt + instruction_base + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
- }
-}
-
-static void
-handle_3dstate_constant(struct gen_spec *spec, uint32_t *p)
-{
- int i, j, length;
- uint32_t *dw;
- float *f;
-
- for (i = 0; i < 4; i++) {
- length = (p[1 + i / 2] >> (i & 1) * 16) & 0xffff;
- f = (float *) (gtt + p[3 + i * 2] + dynamic_state_base);
- dw = (uint32_t *) f;
- for (j = 0; j < length * 8; j++) {
- if (probably_float(dw[j]))
- fprintf(outfile, " %04.3f", f[j]);
- else
- fprintf(outfile, " 0x%08x", dw[j]);
-
- if ((j & 7) == 7)
- fprintf(outfile, "\n");
- }
- }
-}
-
-static void
-handle_3dstate_ps(struct gen_spec *spec, uint32_t *p)
-{
- uint32_t mask = ~((1 << 6) - 1);
- uint64_t start;
- struct brw_instruction *insns;
- static const char unused[] = "unused";
- static const char *pixel_type[3] = {"8 pixel", "16 pixel", "32 pixel"};
- const char *k0, *k1, *k2;
- uint32_t k_mask, k1_offset, k2_offset;
-
- if (gen_spec_get_gen(spec) >= gen_make_gen(8, 0)) {
- k_mask = p[6] & 7;
- k1_offset = 8;
- k2_offset = 10;
- } else {
- k_mask = p[4] & 7;
- k1_offset = 6;
- k2_offset = 7;
- }
-
-#define DISPATCH_8 1
-#define DISPATCH_16 2
-#define DISPATCH_32 4
-
- switch (k_mask) {
- case DISPATCH_8:
- k0 = pixel_type[0];
- k1 = unused;
- k2 = unused;
- break;
- case DISPATCH_16:
- k0 = pixel_type[1];
- k1 = unused;
- k2 = unused;
- break;
- case DISPATCH_8 | DISPATCH_16:
- k0 = pixel_type[0];
- k1 = unused;
- k2 = pixel_type[1];
- break;
- case DISPATCH_32:
- k0 = pixel_type[2];
- k1 = unused;
- k2 = unused;
- break;
- case DISPATCH_16 | DISPATCH_32:
- k0 = unused;
- k1 = pixel_type[2];
- k2 = pixel_type[1];
- break;
- case DISPATCH_8 | DISPATCH_16 | DISPATCH_32:
- k0 = pixel_type[0];
- k1 = pixel_type[2];
- k2 = pixel_type[1];
- break;
- default:
- k0 = unused;
- k1 = unused;
- k2 = unused;
- break;
- }
-
- start = instruction_base + (p[1] & mask);
- fprintf(outfile, " Kernel[0] %s\n", k0);
- if (k0 != unused) {
- insns = (struct brw_instruction *) (gtt + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
- }
-
- start = instruction_base + (p[k1_offset] & mask);
- fprintf(outfile, " Kernel[1] %s\n", k1);
- if (k1 != unused) {
- insns = (struct brw_instruction *) (gtt + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
- }
-
- start = instruction_base + (p[k2_offset] & mask);
- fprintf(outfile, " Kernel[2] %s\n", k2);
- if (k2 != unused) {
- insns = (struct brw_instruction *) (gtt + start);
- gen_disasm_disassemble(disasm, insns, 0, stdout);
- }
-}
-
-static void
-handle_3dstate_binding_table_pointers(struct gen_spec *spec, uint32_t *p)
-{
- dump_binding_table(spec, p[1]);
-}
-
-static void
-handle_3dstate_sampler_state_pointers(struct gen_spec *spec, uint32_t *p)
-{
- dump_samplers(spec, p[1]);
-}
-
-static void
-handle_3dstate_viewport_state_pointers_cc(struct gen_spec *spec, uint32_t *p)
-{
- uint64_t start;
- struct gen_group *cc_viewport;
-
- cc_viewport = gen_spec_find_struct(spec, "CC_VIEWPORT");
-
- start = dynamic_state_base + (p[1] & ~0x1fu);
- for (uint32_t i = 0; i < 4; i++) {
- fprintf(outfile, "viewport %d\n", i);
- decode_group(spec, cc_viewport, gtt + start + i * 8, 0);
- }
-}
-
-static void
-handle_3dstate_viewport_state_pointers_sf_clip(struct gen_spec *spec,
- uint32_t *p)
-{
- uint64_t start;
- struct gen_group *sf_clip_viewport;
-
- sf_clip_viewport = gen_spec_find_struct(spec, "SF_CLIP_VIEWPORT");
-
- start = dynamic_state_base + (p[1] & ~0x3fu);
- for (uint32_t i = 0; i < 4; i++) {
- fprintf(outfile, "viewport %d\n", i);
- decode_group(spec, sf_clip_viewport, gtt + start + i * 64, 0);