14a49301eSmrg/**************************************************************************
27ec681f3Smrg *
3af69d88dSmrg * Copyright 2003 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
57ec681f3Smrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
137ec681f3Smrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
177ec681f3Smrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
257ec681f3Smrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
284a49301eSmrg#include "i915_debug.h"
297ec681f3Smrg#include "util/log.h"
307ec681f3Smrg#include "util/ralloc.h"
314a49301eSmrg#include "util/u_debug.h"
327ec681f3Smrg#include "i915_batch.h"
337ec681f3Smrg#include "i915_context.h"
347ec681f3Smrg#include "i915_debug_private.h"
357ec681f3Smrg#include "i915_reg.h"
367ec681f3Smrg#include "i915_screen.h"
374a49301eSmrg
387ec681f3Smrgstatic const struct debug_named_value i915_debug_options[] = {
397ec681f3Smrg   {"blit", DBG_BLIT, "Print when using the 2d blitter"},
407ec681f3Smrg   {"emit", DBG_EMIT, "State emit information"},
417ec681f3Smrg   {"atoms", DBG_ATOMS, "Print dirty state atoms"},
427ec681f3Smrg   {"flush", DBG_FLUSH, "Flushing information"},
437ec681f3Smrg   {"texture", DBG_TEXTURE, "Texture information"},
443464ebd5Sriastradh   {"constants", DBG_CONSTANTS, "Constant buffers"},
457ec681f3Smrg   {"fs", DBG_FS, "Dump fragment shaders"},
467ec681f3Smrg   {"vbuf", DBG_VBUF, "Use the WIP vbuf code path"},
477ec681f3Smrg   DEBUG_NAMED_VALUE_END};
483464ebd5Sriastradh
493464ebd5Sriastradhunsigned i915_debug = 0;
503464ebd5Sriastradh
517ec681f3SmrgDEBUG_GET_ONCE_FLAGS_OPTION(i915_debug, "I915_DEBUG", i915_debug_options, 0)
527ec681f3SmrgDEBUG_GET_ONCE_BOOL_OPTION(i915_no_tiling, "I915_NO_TILING", false)
537ec681f3SmrgDEBUG_GET_ONCE_BOOL_OPTION(i915_lie, "I915_LIE", true)
547ec681f3SmrgDEBUG_GET_ONCE_BOOL_OPTION(i915_use_blitter, "I915_USE_BLITTER", true)
553464ebd5Sriastradh
567ec681f3Smrgvoid
577ec681f3Smrgi915_debug_init(struct i915_screen *is)
583464ebd5Sriastradh{
593464ebd5Sriastradh   i915_debug = debug_get_option_i915_debug();
603464ebd5Sriastradh   is->debug.tiling = !debug_get_option_i915_no_tiling();
613464ebd5Sriastradh   is->debug.lie = debug_get_option_i915_lie();
623464ebd5Sriastradh   is->debug.use_blitter = debug_get_option_i915_use_blitter();
633464ebd5Sriastradh}
643464ebd5Sriastradh
653464ebd5Sriastradh/***********************************************************************
663464ebd5Sriastradh * Batchbuffer dumping
673464ebd5Sriastradh */
683464ebd5Sriastradh
697ec681f3Smrgstatic bool
707ec681f3Smrgdebug(struct debug_stream *stream, const char *name, unsigned len)
714a49301eSmrg{
724a49301eSmrg   unsigned i;
734a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
747ec681f3Smrg
754a49301eSmrg   if (len == 0) {
767ec681f3Smrg      mesa_logi("Error - zero length packet (0x%08x)", stream->ptr[0]);
774a49301eSmrg      assert(0);
787ec681f3Smrg      return false;
794a49301eSmrg   }
804a49301eSmrg
814a49301eSmrg   if (stream->print_addresses)
827ec681f3Smrg      mesa_logi("%08x:  ", stream->offset);
834a49301eSmrg
847ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
854a49301eSmrg   for (i = 0; i < len; i++)
867ec681f3Smrg      mesa_logi("\t0x%08x", ptr[i]);
877ec681f3Smrg   mesa_logi("%s", "");
884a49301eSmrg
894a49301eSmrg   stream->offset += len * sizeof(unsigned);
904a49301eSmrg
917ec681f3Smrg   return true;
927ec681f3Smrg}
934a49301eSmrg
947ec681f3Smrgstatic const char *
957ec681f3Smrgget_prim_name(unsigned val)
964a49301eSmrg{
974a49301eSmrg   switch (val & PRIM3D_MASK) {
987ec681f3Smrg   case PRIM3D_TRILIST:
997ec681f3Smrg      return "TRILIST";
1007ec681f3Smrg      break;
1017ec681f3Smrg   case PRIM3D_TRISTRIP:
1027ec681f3Smrg      return "TRISTRIP";
1037ec681f3Smrg      break;
1047ec681f3Smrg   case PRIM3D_TRISTRIP_RVRSE:
1057ec681f3Smrg      return "TRISTRIP_RVRSE";
1067ec681f3Smrg      break;
1077ec681f3Smrg   case PRIM3D_TRIFAN:
1087ec681f3Smrg      return "TRIFAN";
1097ec681f3Smrg      break;
1107ec681f3Smrg   case PRIM3D_POLY:
1117ec681f3Smrg      return "POLY";
1127ec681f3Smrg      break;
1137ec681f3Smrg   case PRIM3D_LINELIST:
1147ec681f3Smrg      return "LINELIST";
1157ec681f3Smrg      break;
1167ec681f3Smrg   case PRIM3D_LINESTRIP:
1177ec681f3Smrg      return "LINESTRIP";
1187ec681f3Smrg      break;
1197ec681f3Smrg   case PRIM3D_RECTLIST:
1207ec681f3Smrg      return "RECTLIST";
1217ec681f3Smrg      break;
1227ec681f3Smrg   case PRIM3D_POINTLIST:
1237ec681f3Smrg      return "POINTLIST";
1247ec681f3Smrg      break;
1257ec681f3Smrg   case PRIM3D_DIB:
1267ec681f3Smrg      return "DIB";
1277ec681f3Smrg      break;
1287ec681f3Smrg   case PRIM3D_CLEAR_RECT:
1297ec681f3Smrg      return "CLEAR_RECT";
1307ec681f3Smrg      break;
1317ec681f3Smrg   case PRIM3D_ZONE_INIT:
1327ec681f3Smrg      return "ZONE_INIT";
1337ec681f3Smrg      break;
1347ec681f3Smrg   default:
1357ec681f3Smrg      return "????";
1367ec681f3Smrg      break;
1374a49301eSmrg   }
1384a49301eSmrg}
1394a49301eSmrg
1407ec681f3Smrgstatic bool
1417ec681f3Smrgdebug_prim(struct debug_stream *stream, const char *name, bool dump_floats,
1427ec681f3Smrg           unsigned len)
1434a49301eSmrg{
1444a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
1457ec681f3Smrg   const char *prim = get_prim_name(ptr[0]);
1464a49301eSmrg   unsigned i;
1474a49301eSmrg
1487ec681f3Smrg   mesa_logi("%s %s (%d dwords):", name, prim, len);
1497ec681f3Smrg   mesa_logi("\t0x%08x", ptr[0]);
1504a49301eSmrg   for (i = 1; i < len; i++) {
1514a49301eSmrg      if (dump_floats)
1527ec681f3Smrg         mesa_logi("\t0x%08x // %f", ptr[i], *(float *)&ptr[i]);
1534a49301eSmrg      else
1547ec681f3Smrg         mesa_logi("\t0x%08x", ptr[i]);
1554a49301eSmrg   }
1564a49301eSmrg
1577ec681f3Smrg   mesa_logi("%s", "");
1584a49301eSmrg
1594a49301eSmrg   stream->offset += len * sizeof(unsigned);
1604a49301eSmrg
1617ec681f3Smrg   return true;
1627ec681f3Smrg}
1634a49301eSmrg
1647ec681f3Smrgstatic bool
1657ec681f3Smrgdebug_program(struct debug_stream *stream, const char *name, unsigned len)
1664a49301eSmrg{
1674a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
1684a49301eSmrg
1694a49301eSmrg   if (len == 0) {
1707ec681f3Smrg      mesa_logi("Error - zero length packet (0x%08x)", stream->ptr[0]);
1714a49301eSmrg      assert(0);
1727ec681f3Smrg      return false;
1734a49301eSmrg   }
1744a49301eSmrg
1754a49301eSmrg   if (stream->print_addresses)
1767ec681f3Smrg      mesa_logi("%08x:  ", stream->offset);
1774a49301eSmrg
1787ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
1797ec681f3Smrg   i915_disassemble_program(ptr, len);
1804a49301eSmrg
1814a49301eSmrg   stream->offset += len * sizeof(unsigned);
1827ec681f3Smrg   return true;
1834a49301eSmrg}
1844a49301eSmrg
1857ec681f3Smrgstatic bool
1867ec681f3Smrgdebug_chain(struct debug_stream *stream, const char *name, unsigned len)
1874a49301eSmrg{
1884a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
1894a49301eSmrg   unsigned old_offset = stream->offset + len * sizeof(unsigned);
1904a49301eSmrg   unsigned i;
1914a49301eSmrg
1927ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
1934a49301eSmrg   for (i = 0; i < len; i++)
1947ec681f3Smrg      mesa_logi("\t0x%08x", ptr[i]);
1954a49301eSmrg
1964a49301eSmrg   stream->offset = ptr[1] & ~0x3;
1977ec681f3Smrg
1984a49301eSmrg   if (stream->offset < old_offset)
1997ec681f3Smrg      mesa_logi("... skipping backwards from 0x%x --> 0x%x ...", old_offset,
2007ec681f3Smrg                stream->offset);
2014a49301eSmrg   else
2027ec681f3Smrg      mesa_logi("... skipping from 0x%x --> 0x%x ...", old_offset,
2037ec681f3Smrg                stream->offset);
2044a49301eSmrg
2057ec681f3Smrg   return true;
2064a49301eSmrg}
2074a49301eSmrg
2087ec681f3Smrgstatic bool
2097ec681f3Smrgdebug_variable_length_prim(struct debug_stream *stream)
2104a49301eSmrg{
2114a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
2127ec681f3Smrg   const char *prim = get_prim_name(ptr[0]);
2134a49301eSmrg   unsigned i, len;
2144a49301eSmrg
2157ec681f3Smrg   ushort *idx = (ushort *)(ptr + 1);
2164a49301eSmrg   for (i = 0; idx[i] != 0xffff; i++)
2174a49301eSmrg      ;
2184a49301eSmrg
2197ec681f3Smrg   len = 1 + (i + 2) / 2;
2204a49301eSmrg
2217ec681f3Smrg   mesa_logi("3DPRIM, %s variable length %d indicies (%d dwords):", prim, i,
2227ec681f3Smrg             len);
2234a49301eSmrg   for (i = 0; i < len; i++)
2247ec681f3Smrg      mesa_logi("\t0x%08x", ptr[i]);
2257ec681f3Smrg   mesa_logi("%s", "");
2264a49301eSmrg
2274a49301eSmrg   stream->offset += len * sizeof(unsigned);
2287ec681f3Smrg   return true;
2294a49301eSmrg}
2304a49301eSmrg
2314a49301eSmrgstatic void
2327ec681f3SmrgBITS(struct debug_stream *stream, unsigned dw, unsigned hi, unsigned lo,
2337ec681f3Smrg     const char *fmt, ...)
2344a49301eSmrg{
2357ec681f3Smrg   va_list args;
236af69d88dSmrg   unsigned himask = 0xFFFFFFFFUL >> (31 - (hi));
2374a49301eSmrg
2387ec681f3Smrg   va_start(args, fmt);
2397ec681f3Smrg   char *out = ralloc_vasprintf(NULL, fmt, args);
2407ec681f3Smrg   va_end(args);
2414a49301eSmrg
2427ec681f3Smrg   mesa_logi("\t\t %s : 0x%x", out, ((dw)&himask) >> (lo));
2434a49301eSmrg
2447ec681f3Smrg   ralloc_free(out);
2454a49301eSmrg}
2464a49301eSmrg
2477ec681f3Smrg#define MBZ(dw, hi, lo)                                                        \
2487ec681f3Smrg   do {                                                                        \
2497ec681f3Smrg      ASSERTED unsigned x = (dw) >> (lo);                                      \
2507ec681f3Smrg      ASSERTED unsigned lomask = (1 << (lo)) - 1;                              \
2517ec681f3Smrg      ASSERTED unsigned himask;                                                \
2527ec681f3Smrg      himask = (1UL << (hi)) - 1;                                              \
2537ec681f3Smrg      assert((x & himask & ~lomask) == 0);                                     \
2547ec681f3Smrg   } while (0)
2554a49301eSmrg
2564a49301eSmrgstatic void
2577ec681f3SmrgFLAG(struct debug_stream *stream, unsigned dw, unsigned bit, const char *fmt,
2587ec681f3Smrg     ...)
2594a49301eSmrg{
2604a49301eSmrg   if (((dw) >> (bit)) & 1) {
2617ec681f3Smrg      va_list args;
2627ec681f3Smrg      va_start(args, fmt);
2637ec681f3Smrg      char *out = ralloc_vasprintf(NULL, fmt, args);
2647ec681f3Smrg      va_end(args);
2654a49301eSmrg
2667ec681f3Smrg      mesa_logi("\t\t %s", out);
2674a49301eSmrg
2687ec681f3Smrg      ralloc_free(out);
2694a49301eSmrg   }
2704a49301eSmrg}
2714a49301eSmrg
2727ec681f3Smrgstatic bool
2737ec681f3Smrgdebug_load_immediate(struct debug_stream *stream, const char *name,
2747ec681f3Smrg                     unsigned len)
2754a49301eSmrg{
2764a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
2774a49301eSmrg   unsigned bits = (ptr[0] >> 4) & 0xff;
2784a49301eSmrg   unsigned j = 0;
2794a49301eSmrg
2807ec681f3Smrg   mesa_logi("%s (%d dwords, flags: %x):", name, len, bits);
2817ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
2827ec681f3Smrg
2837ec681f3Smrg   if (bits & (1 << 0)) {
2847ec681f3Smrg      mesa_logi("\t  LIS0: 0x%08x", ptr[j]);
2857ec681f3Smrg      mesa_logi("\t vb address: 0x%08x", (ptr[j] & ~0x3));
2864a49301eSmrg      BITS(stream, ptr[j], 0, 0, "vb invalidate disable");
2874a49301eSmrg      j++;
2884a49301eSmrg   }
2897ec681f3Smrg   if (bits & (1 << 1)) {
2907ec681f3Smrg      mesa_logi("\t  LIS1: 0x%08x", ptr[j]);
2914a49301eSmrg      BITS(stream, ptr[j], 29, 24, "vb dword width");
2924a49301eSmrg      BITS(stream, ptr[j], 21, 16, "vb dword pitch");
2934a49301eSmrg      BITS(stream, ptr[j], 15, 0, "vb max index");
2944a49301eSmrg      j++;
2954a49301eSmrg   }
2967ec681f3Smrg   if (bits & (1 << 2)) {
2974a49301eSmrg      int i;
2987ec681f3Smrg      mesa_logi("\t  LIS2: 0x%08x", ptr[j]);
2994a49301eSmrg      for (i = 0; i < 8; i++) {
3007ec681f3Smrg         unsigned tc = (ptr[j] >> (i * 4)) & 0xf;
3017ec681f3Smrg         if (tc != 0xf)
3027ec681f3Smrg            BITS(stream, tc, 3, 0, "tex coord %d", i);
3034a49301eSmrg      }
3044a49301eSmrg      j++;
3054a49301eSmrg   }
3067ec681f3Smrg   if (bits & (1 << 3)) {
3077ec681f3Smrg      mesa_logi("\t  LIS3: 0x%08x", ptr[j]);
3084a49301eSmrg      j++;
3094a49301eSmrg   }
3107ec681f3Smrg   if (bits & (1 << 4)) {
3117ec681f3Smrg      mesa_logi("\t  LIS4: 0x%08x", ptr[j]);
3124a49301eSmrg      BITS(stream, ptr[j], 31, 23, "point width");
3134a49301eSmrg      BITS(stream, ptr[j], 22, 19, "line width");
3144a49301eSmrg      FLAG(stream, ptr[j], 18, "alpha flatshade");
3154a49301eSmrg      FLAG(stream, ptr[j], 17, "fog flatshade");
3164a49301eSmrg      FLAG(stream, ptr[j], 16, "spec flatshade");
3174a49301eSmrg      FLAG(stream, ptr[j], 15, "rgb flatshade");
3184a49301eSmrg      BITS(stream, ptr[j], 14, 13, "cull mode");
3194a49301eSmrg      FLAG(stream, ptr[j], 12, "vfmt: point width");
3204a49301eSmrg      FLAG(stream, ptr[j], 11, "vfmt: specular/fog");
3214a49301eSmrg      FLAG(stream, ptr[j], 10, "vfmt: rgba");
3224a49301eSmrg      FLAG(stream, ptr[j], 9, "vfmt: depth offset");
3234a49301eSmrg      BITS(stream, ptr[j], 8, 6, "vfmt: position (2==xyzw)");
3244a49301eSmrg      FLAG(stream, ptr[j], 5, "force dflt diffuse");
3254a49301eSmrg      FLAG(stream, ptr[j], 4, "force dflt specular");
3264a49301eSmrg      FLAG(stream, ptr[j], 3, "local depth offset enable");
3274a49301eSmrg      FLAG(stream, ptr[j], 2, "vfmt: fp32 fog coord");
3284a49301eSmrg      FLAG(stream, ptr[j], 1, "sprite point");
3294a49301eSmrg      FLAG(stream, ptr[j], 0, "antialiasing");
3304a49301eSmrg      j++;
3314a49301eSmrg   }
3327ec681f3Smrg   if (bits & (1 << 5)) {
3337ec681f3Smrg      mesa_logi("\t  LIS5: 0x%08x", ptr[j]);
3344a49301eSmrg      BITS(stream, ptr[j], 31, 28, "rgba write disables");
3357ec681f3Smrg      FLAG(stream, ptr[j], 27, "force dflt point width");
3367ec681f3Smrg      FLAG(stream, ptr[j], 26, "last pixel enable");
3377ec681f3Smrg      FLAG(stream, ptr[j], 25, "global z offset enable");
3387ec681f3Smrg      FLAG(stream, ptr[j], 24, "fog enable");
3394a49301eSmrg      BITS(stream, ptr[j], 23, 16, "stencil ref");
3404a49301eSmrg      BITS(stream, ptr[j], 15, 13, "stencil test");
3414a49301eSmrg      BITS(stream, ptr[j], 12, 10, "stencil fail op");
3427ec681f3Smrg      BITS(stream, ptr[j], 9, 7, "stencil pass z fail op");
3437ec681f3Smrg      BITS(stream, ptr[j], 6, 4, "stencil pass z pass op");
3447ec681f3Smrg      FLAG(stream, ptr[j], 3, "stencil write enable");
3457ec681f3Smrg      FLAG(stream, ptr[j], 2, "stencil test enable");
3467ec681f3Smrg      FLAG(stream, ptr[j], 1, "color dither enable");
3477ec681f3Smrg      FLAG(stream, ptr[j], 0, "logiop enable");
3484a49301eSmrg      j++;
3494a49301eSmrg   }
3507ec681f3Smrg   if (bits & (1 << 6)) {
3517ec681f3Smrg      mesa_logi("\t  LIS6: 0x%08x", ptr[j]);
3527ec681f3Smrg      FLAG(stream, ptr[j], 31, "alpha test enable");
3537ec681f3Smrg      BITS(stream, ptr[j], 30, 28, "alpha func");
3547ec681f3Smrg      BITS(stream, ptr[j], 27, 20, "alpha ref");
3557ec681f3Smrg      FLAG(stream, ptr[j], 19, "depth test enable");
3567ec681f3Smrg      BITS(stream, ptr[j], 18, 16, "depth func");
3577ec681f3Smrg      FLAG(stream, ptr[j], 15, "blend enable");
3587ec681f3Smrg      BITS(stream, ptr[j], 14, 12, "blend func");
3597ec681f3Smrg      BITS(stream, ptr[j], 11, 8, "blend src factor");
3607ec681f3Smrg      BITS(stream, ptr[j], 7, 4, "blend dst factor");
3617ec681f3Smrg      FLAG(stream, ptr[j], 3, "depth write enable");
3627ec681f3Smrg      FLAG(stream, ptr[j], 2, "color write enable");
3637ec681f3Smrg      BITS(stream, ptr[j], 1, 0, "provoking vertex");
3644a49301eSmrg      j++;
3654a49301eSmrg   }
3664a49301eSmrg
3677ec681f3Smrg   mesa_logi("%s", "");
3684a49301eSmrg
3694a49301eSmrg   assert(j == len);
3704a49301eSmrg
3714a49301eSmrg   stream->offset += len * sizeof(unsigned);
3724a49301eSmrg
3737ec681f3Smrg   return true;
3747ec681f3Smrg}
3754a49301eSmrg
3767ec681f3Smrgstatic bool
3777ec681f3Smrgdebug_load_indirect(struct debug_stream *stream, const char *name, unsigned len)
3784a49301eSmrg{
3794a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
3804a49301eSmrg   unsigned bits = (ptr[0] >> 8) & 0x3f;
3814a49301eSmrg   unsigned i, j = 0;
3827ec681f3Smrg
3837ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
3847ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
3854a49301eSmrg
3864a49301eSmrg   for (i = 0; i < 6; i++) {
3877ec681f3Smrg      if (bits & (1 << i)) {
3887ec681f3Smrg         switch (1 << (8 + i)) {
3897ec681f3Smrg         case LI0_STATE_STATIC_INDIRECT:
3907ec681f3Smrg            mesa_logi("        STATIC: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
3917ec681f3Smrg            j++;
3927ec681f3Smrg            mesa_logi("                0x%08x", ptr[j++]);
3937ec681f3Smrg            break;
3947ec681f3Smrg         case LI0_STATE_DYNAMIC_INDIRECT:
3957ec681f3Smrg            mesa_logi("       DYNAMIC: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
3967ec681f3Smrg            j++;
3977ec681f3Smrg            break;
3987ec681f3Smrg         case LI0_STATE_SAMPLER:
3997ec681f3Smrg            mesa_logi("       SAMPLER: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
4007ec681f3Smrg            j++;
4017ec681f3Smrg            mesa_logi("                0x%08x", ptr[j++]);
4027ec681f3Smrg            break;
4037ec681f3Smrg         case LI0_STATE_MAP:
4047ec681f3Smrg            mesa_logi("           MAP: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
4057ec681f3Smrg            j++;
4067ec681f3Smrg            mesa_logi("                0x%08x", ptr[j++]);
4077ec681f3Smrg            break;
4087ec681f3Smrg         case LI0_STATE_PROGRAM:
4097ec681f3Smrg            mesa_logi("       PROGRAM: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
4107ec681f3Smrg            j++;
4117ec681f3Smrg            mesa_logi("                0x%08x", ptr[j++]);
4127ec681f3Smrg            break;
4137ec681f3Smrg         case LI0_STATE_CONSTANTS:
4147ec681f3Smrg            mesa_logi("     CONSTANTS: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
4157ec681f3Smrg            j++;
4167ec681f3Smrg            mesa_logi("                0x%08x", ptr[j++]);
4177ec681f3Smrg            break;
4187ec681f3Smrg         default:
4197ec681f3Smrg            assert(0);
4207ec681f3Smrg            break;
4217ec681f3Smrg         }
4224a49301eSmrg      }
4234a49301eSmrg   }
4244a49301eSmrg
4254a49301eSmrg   if (bits == 0) {
4267ec681f3Smrg      mesa_logi("\t  DUMMY: 0x%08x", ptr[j++]);
4274a49301eSmrg   }
4284a49301eSmrg
4297ec681f3Smrg   mesa_logi("%s", "");
4304a49301eSmrg
4314a49301eSmrg   assert(j == len);
4324a49301eSmrg
4334a49301eSmrg   stream->offset += len * sizeof(unsigned);
4347ec681f3Smrg
4357ec681f3Smrg   return true;
4364a49301eSmrg}
4377ec681f3Smrg
4387ec681f3Smrgstatic void
4397ec681f3SmrgBR13(struct debug_stream *stream, unsigned val)
4404a49301eSmrg{
4417ec681f3Smrg   mesa_logi("\t0x%08x", val);
4424a49301eSmrg   FLAG(stream, val, 30, "clipping enable");
4434a49301eSmrg   BITS(stream, val, 25, 24, "color depth (3==32bpp)");
4444a49301eSmrg   BITS(stream, val, 23, 16, "raster op");
4457ec681f3Smrg   BITS(stream, val, 15, 0, "dest pitch");
4464a49301eSmrg}
4474a49301eSmrg
4487ec681f3Smrgstatic void
4497ec681f3SmrgBR22(struct debug_stream *stream, unsigned val)
4504a49301eSmrg{
4517ec681f3Smrg   mesa_logi("\t0x%08x", val);
4524a49301eSmrg   BITS(stream, val, 31, 16, "dest y1");
4537ec681f3Smrg   BITS(stream, val, 15, 0, "dest x1");
4544a49301eSmrg}
4554a49301eSmrg
4567ec681f3Smrgstatic void
4577ec681f3SmrgBR23(struct debug_stream *stream, unsigned val)
4584a49301eSmrg{
4597ec681f3Smrg   mesa_logi("\t0x%08x", val);
4604a49301eSmrg   BITS(stream, val, 31, 16, "dest y2");
4617ec681f3Smrg   BITS(stream, val, 15, 0, "dest x2");
4624a49301eSmrg}
4634a49301eSmrg
4647ec681f3Smrgstatic void
4657ec681f3SmrgBR09(struct debug_stream *stream, unsigned val)
4664a49301eSmrg{
4677ec681f3Smrg   mesa_logi("\t0x%08x -- dest address", val);
4684a49301eSmrg}
4694a49301eSmrg
4707ec681f3Smrgstatic void
4717ec681f3SmrgBR26(struct debug_stream *stream, unsigned val)
4724a49301eSmrg{
4737ec681f3Smrg   mesa_logi("\t0x%08x", val);
4744a49301eSmrg   BITS(stream, val, 31, 16, "src y1");
4757ec681f3Smrg   BITS(stream, val, 15, 0, "src x1");
4764a49301eSmrg}
4774a49301eSmrg
4787ec681f3Smrgstatic void
4797ec681f3SmrgBR11(struct debug_stream *stream, unsigned val)
4804a49301eSmrg{
4817ec681f3Smrg   mesa_logi("\t0x%08x", val);
4827ec681f3Smrg   BITS(stream, val, 15, 0, "src pitch");
4834a49301eSmrg}
4844a49301eSmrg
4857ec681f3Smrgstatic void
4867ec681f3SmrgBR12(struct debug_stream *stream, unsigned val)
4874a49301eSmrg{
4887ec681f3Smrg   mesa_logi("\t0x%08x -- src address", val);
4894a49301eSmrg}
4904a49301eSmrg
4917ec681f3Smrgstatic void
4927ec681f3SmrgBR16(struct debug_stream *stream, unsigned val)
4934a49301eSmrg{
4947ec681f3Smrg   mesa_logi("\t0x%08x -- color", val);
4954a49301eSmrg}
4967ec681f3Smrg
4977ec681f3Smrgstatic bool
4987ec681f3Smrgdebug_copy_blit(struct debug_stream *stream, const char *name, unsigned len)
4994a49301eSmrg{
5004a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
5014a49301eSmrg   int j = 0;
5024a49301eSmrg
5037ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
5047ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
5057ec681f3Smrg
5064a49301eSmrg   BR13(stream, ptr[j++]);
5074a49301eSmrg   BR22(stream, ptr[j++]);
5084a49301eSmrg   BR23(stream, ptr[j++]);
5094a49301eSmrg   BR09(stream, ptr[j++]);
5104a49301eSmrg   BR26(stream, ptr[j++]);
5114a49301eSmrg   BR11(stream, ptr[j++]);
5124a49301eSmrg   BR12(stream, ptr[j++]);
5134a49301eSmrg
5144a49301eSmrg   stream->offset += len * sizeof(unsigned);
5154a49301eSmrg   assert(j == len);
5167ec681f3Smrg   return true;
5174a49301eSmrg}
5184a49301eSmrg
5197ec681f3Smrgstatic bool
5207ec681f3Smrgdebug_color_blit(struct debug_stream *stream, const char *name, unsigned len)
5214a49301eSmrg{
5224a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
5234a49301eSmrg   int j = 0;
5244a49301eSmrg
5257ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
5267ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
5274a49301eSmrg
5284a49301eSmrg   BR13(stream, ptr[j++]);
5294a49301eSmrg   BR22(stream, ptr[j++]);
5304a49301eSmrg   BR23(stream, ptr[j++]);
5314a49301eSmrg   BR09(stream, ptr[j++]);
5324a49301eSmrg   BR16(stream, ptr[j++]);
5334a49301eSmrg
5344a49301eSmrg   stream->offset += len * sizeof(unsigned);
5354a49301eSmrg   assert(j == len);
5367ec681f3Smrg   return true;
5374a49301eSmrg}
5384a49301eSmrg
5397ec681f3Smrgstatic bool
5407ec681f3Smrgdebug_modes4(struct debug_stream *stream, const char *name, unsigned len)
5414a49301eSmrg{
5424a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
5434a49301eSmrg   int j = 0;
5444a49301eSmrg
5457ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
5467ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j]);
5474a49301eSmrg   BITS(stream, ptr[j], 21, 18, "logicop func");
5484a49301eSmrg   FLAG(stream, ptr[j], 17, "stencil test mask modify-enable");
5494a49301eSmrg   FLAG(stream, ptr[j], 16, "stencil write mask modify-enable");
5504a49301eSmrg   BITS(stream, ptr[j], 15, 8, "stencil test mask");
5517ec681f3Smrg   BITS(stream, ptr[j], 7, 0, "stencil write mask");
5524a49301eSmrg   j++;
5534a49301eSmrg
5544a49301eSmrg   stream->offset += len * sizeof(unsigned);
5554a49301eSmrg   assert(j == len);
5567ec681f3Smrg   return true;
5574a49301eSmrg}
5584a49301eSmrg
5597ec681f3Smrgstatic bool
5607ec681f3Smrgdebug_map_state(struct debug_stream *stream, const char *name, unsigned len)
5614a49301eSmrg{
5624a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
5634a49301eSmrg   unsigned j = 0;
5644a49301eSmrg
5657ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
5667ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
5677ec681f3Smrg
5684a49301eSmrg   {
5697ec681f3Smrg      mesa_logi("\t0x%08x", ptr[j]);
5707ec681f3Smrg      BITS(stream, ptr[j], 15, 0, "map mask");
5714a49301eSmrg      j++;
5724a49301eSmrg   }
5734a49301eSmrg
5744a49301eSmrg   while (j < len) {
5754a49301eSmrg      {
5767ec681f3Smrg         mesa_logi("\t  TMn.0: 0x%08x", ptr[j]);
5777ec681f3Smrg         mesa_logi("\t map address: 0x%08x", (ptr[j] & ~0x3));
5787ec681f3Smrg         FLAG(stream, ptr[j], 1, "vertical line stride");
5797ec681f3Smrg         FLAG(stream, ptr[j], 0, "vertical line stride offset");
5807ec681f3Smrg         j++;
5814a49301eSmrg      }
5824a49301eSmrg
5834a49301eSmrg      {
5847ec681f3Smrg         mesa_logi("\t  TMn.1: 0x%08x", ptr[j]);
5857ec681f3Smrg         BITS(stream, ptr[j], 31, 21, "height");
5867ec681f3Smrg         BITS(stream, ptr[j], 20, 10, "width");
5877ec681f3Smrg         BITS(stream, ptr[j], 9, 7, "surface format");
5887ec681f3Smrg         BITS(stream, ptr[j], 6, 3, "texel format");
5897ec681f3Smrg         FLAG(stream, ptr[j], 2, "use fence regs");
5907ec681f3Smrg         FLAG(stream, ptr[j], 1, "tiled surface");
5917ec681f3Smrg         FLAG(stream, ptr[j], 0, "tile walk ymajor");
5927ec681f3Smrg         j++;
5934a49301eSmrg      }
5944a49301eSmrg      {
5957ec681f3Smrg         mesa_logi("\t  TMn.2: 0x%08x", ptr[j]);
5967ec681f3Smrg         BITS(stream, ptr[j], 31, 21, "dword pitch");
5977ec681f3Smrg         BITS(stream, ptr[j], 20, 15, "cube face enables");
5987ec681f3Smrg         BITS(stream, ptr[j], 14, 9, "max lod");
5997ec681f3Smrg         FLAG(stream, ptr[j], 8, "mip layout right");
6007ec681f3Smrg         BITS(stream, ptr[j], 7, 0, "depth");
6017ec681f3Smrg         j++;
6024a49301eSmrg      }
6034a49301eSmrg   }
6044a49301eSmrg
6054a49301eSmrg   stream->offset += len * sizeof(unsigned);
6064a49301eSmrg   assert(j == len);
6077ec681f3Smrg   return true;
6084a49301eSmrg}
6094a49301eSmrg
6107ec681f3Smrgstatic bool
6117ec681f3Smrgdebug_sampler_state(struct debug_stream *stream, const char *name, unsigned len)
6124a49301eSmrg{
6134a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
6144a49301eSmrg   unsigned j = 0;
6154a49301eSmrg
6167ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
6177ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
6187ec681f3Smrg
6194a49301eSmrg   {
6207ec681f3Smrg      mesa_logi("\t0x%08x", ptr[j]);
6217ec681f3Smrg      BITS(stream, ptr[j], 15, 0, "sampler mask");
6224a49301eSmrg      j++;
6234a49301eSmrg   }
6244a49301eSmrg
6254a49301eSmrg   while (j < len) {
6264a49301eSmrg      {
6277ec681f3Smrg         mesa_logi("\t  TSn.0: 0x%08x", ptr[j]);
6287ec681f3Smrg         FLAG(stream, ptr[j], 31, "reverse gamma");
6297ec681f3Smrg         FLAG(stream, ptr[j], 30, "planar to packed");
6307ec681f3Smrg         FLAG(stream, ptr[j], 29, "yuv->rgb");
6317ec681f3Smrg         BITS(stream, ptr[j], 28, 27, "chromakey index");
6327ec681f3Smrg         BITS(stream, ptr[j], 26, 22, "base mip level");
6337ec681f3Smrg         BITS(stream, ptr[j], 21, 20, "mip mode filter");
6347ec681f3Smrg         BITS(stream, ptr[j], 19, 17, "mag mode filter");
6357ec681f3Smrg         BITS(stream, ptr[j], 16, 14, "min mode filter");
6367ec681f3Smrg         BITS(stream, ptr[j], 13, 5, "lod bias (s4.4)");
6377ec681f3Smrg         FLAG(stream, ptr[j], 4, "shadow enable");
6387ec681f3Smrg         FLAG(stream, ptr[j], 3, "max-aniso-4");
6397ec681f3Smrg         BITS(stream, ptr[j], 2, 0, "shadow func");
6407ec681f3Smrg         j++;
6414a49301eSmrg      }
6424a49301eSmrg
6434a49301eSmrg      {
6447ec681f3Smrg         mesa_logi("\t  TSn.1: 0x%08x", ptr[j]);
6457ec681f3Smrg         BITS(stream, ptr[j], 31, 24, "min lod");
6467ec681f3Smrg         MBZ(ptr[j], 23, 18);
6477ec681f3Smrg         FLAG(stream, ptr[j], 17, "kill pixel enable");
6487ec681f3Smrg         FLAG(stream, ptr[j], 16, "keyed tex filter mode");
6497ec681f3Smrg         FLAG(stream, ptr[j], 15, "chromakey enable");
6507ec681f3Smrg         BITS(stream, ptr[j], 14, 12, "tcx wrap mode");
6517ec681f3Smrg         BITS(stream, ptr[j], 11, 9, "tcy wrap mode");
6527ec681f3Smrg         BITS(stream, ptr[j], 8, 6, "tcz wrap mode");
6537ec681f3Smrg         FLAG(stream, ptr[j], 5, "normalized coords");
6547ec681f3Smrg         BITS(stream, ptr[j], 4, 1, "map (surface) index");
6557ec681f3Smrg         FLAG(stream, ptr[j], 0, "EAST deinterlacer enable");
6567ec681f3Smrg         j++;
6574a49301eSmrg      }
6584a49301eSmrg      {
6597ec681f3Smrg         mesa_logi("\t  TSn.2: 0x%08x  (default color)", ptr[j]);
6607ec681f3Smrg         j++;
6614a49301eSmrg      }
6624a49301eSmrg   }
6634a49301eSmrg
6644a49301eSmrg   stream->offset += len * sizeof(unsigned);
6654a49301eSmrg   assert(j == len);
6667ec681f3Smrg   return true;
6674a49301eSmrg}
6684a49301eSmrg
6697ec681f3Smrgstatic bool
6707ec681f3Smrgdebug_dest_vars(struct debug_stream *stream, const char *name, unsigned len)
6714a49301eSmrg{
6724a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
6734a49301eSmrg   int j = 0;
6744a49301eSmrg
6757ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
6767ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
6774a49301eSmrg
6784a49301eSmrg   {
6797ec681f3Smrg      mesa_logi("\t0x%08x", ptr[j]);
6807ec681f3Smrg      FLAG(stream, ptr[j], 31, "early classic ztest");
6817ec681f3Smrg      FLAG(stream, ptr[j], 30, "opengl tex default color");
6827ec681f3Smrg      FLAG(stream, ptr[j], 29, "bypass iz");
6837ec681f3Smrg      FLAG(stream, ptr[j], 28, "lod preclamp");
6844a49301eSmrg      BITS(stream, ptr[j], 27, 26, "dither pattern");
6857ec681f3Smrg      FLAG(stream, ptr[j], 25, "linear gamma blend");
6867ec681f3Smrg      FLAG(stream, ptr[j], 24, "debug dither");
6874a49301eSmrg      BITS(stream, ptr[j], 23, 20, "dstorg x");
6884a49301eSmrg      BITS(stream, ptr[j], 19, 16, "dstorg y");
6897ec681f3Smrg      MBZ(ptr[j], 15, 15);
6904a49301eSmrg      BITS(stream, ptr[j], 14, 12, "422 write select");
6917ec681f3Smrg      BITS(stream, ptr[j], 11, 8, "cbuf format");
6927ec681f3Smrg      BITS(stream, ptr[j], 3, 2, "zbuf format");
6937ec681f3Smrg      FLAG(stream, ptr[j], 1, "vert line stride");
6947ec681f3Smrg      FLAG(stream, ptr[j], 1, "vert line stride offset");
6954a49301eSmrg      j++;
6964a49301eSmrg   }
6977ec681f3Smrg
6984a49301eSmrg   stream->offset += len * sizeof(unsigned);
6994a49301eSmrg   assert(j == len);
7007ec681f3Smrg   return true;
7014a49301eSmrg}
7024a49301eSmrg
7037ec681f3Smrgstatic bool
7047ec681f3Smrgdebug_buf_info(struct debug_stream *stream, const char *name, unsigned len)
7054a49301eSmrg{
7064a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
7074a49301eSmrg   int j = 0;
7084a49301eSmrg
7097ec681f3Smrg   mesa_logi("%s (%d dwords):", name, len);
7107ec681f3Smrg   mesa_logi("\t0x%08x", ptr[j++]);
7114a49301eSmrg
7124a49301eSmrg   {
7137ec681f3Smrg      mesa_logi("\t0x%08x", ptr[j]);
7144a49301eSmrg      BITS(stream, ptr[j], 28, 28, "aux buffer id");
7154a49301eSmrg      BITS(stream, ptr[j], 27, 24, "buffer id (7=depth, 3=back)");
7167ec681f3Smrg      FLAG(stream, ptr[j], 23, "use fence regs");
7177ec681f3Smrg      FLAG(stream, ptr[j], 22, "tiled surface");
7187ec681f3Smrg      FLAG(stream, ptr[j], 21, "tile walk ymajor");
7197ec681f3Smrg      MBZ(ptr[j], 20, 14);
7207ec681f3Smrg      BITS(stream, ptr[j], 13, 2, "dword pitch");
7217ec681f3Smrg      MBZ(ptr[j], 2, 0);
7224a49301eSmrg      j++;
7234a49301eSmrg   }
7247ec681f3Smrg
7257ec681f3Smrg   mesa_logi("\t0x%08x -- buffer base address", ptr[j++]);
7264a49301eSmrg
7274a49301eSmrg   stream->offset += len * sizeof(unsigned);
7284a49301eSmrg   assert(j == len);
7297ec681f3Smrg   return true;
7304a49301eSmrg}
7314a49301eSmrg
7327ec681f3Smrgstatic bool
7337ec681f3Smrgi915_debug_packet(struct debug_stream *stream)
7344a49301eSmrg{
7354a49301eSmrg   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
7364a49301eSmrg   unsigned cmd = *ptr;
7377ec681f3Smrg
7384a49301eSmrg   switch (((cmd >> 29) & 0x7)) {
7394a49301eSmrg   case 0x0:
7404a49301eSmrg      switch ((cmd >> 23) & 0x3f) {
7414a49301eSmrg      case 0x0:
7427ec681f3Smrg         return debug(stream, "MI_NOOP", 1);
7434a49301eSmrg      case 0x3:
7447ec681f3Smrg         return debug(stream, "MI_WAIT_FOR_EVENT", 1);
7454a49301eSmrg      case 0x4:
7467ec681f3Smrg         return debug(stream, "MI_FLUSH", 1);
7474a49301eSmrg      case 0xA:
7487ec681f3Smrg         debug(stream, "MI_BATCH_BUFFER_END", 1);
7497ec681f3Smrg         return false;
7504a49301eSmrg      case 0x22:
7517ec681f3Smrg         return debug(stream, "MI_LOAD_REGISTER_IMM", 3);
7524a49301eSmrg      case 0x31:
7537ec681f3Smrg         return debug_chain(stream, "MI_BATCH_BUFFER_START", 2);
7544a49301eSmrg      default:
7554a49301eSmrg         (void)debug(stream, "UNKNOWN 0x0 case!", 1);
7564a49301eSmrg         assert(0);
7577ec681f3Smrg         break;
7584a49301eSmrg      }
7594a49301eSmrg      break;
7604a49301eSmrg   case 0x1:
7617ec681f3Smrg      (void)debug(stream, "UNKNOWN 0x1 case!", 1);
7624a49301eSmrg      assert(0);
7634a49301eSmrg      break;
7644a49301eSmrg   case 0x2:
7657ec681f3Smrg      switch ((cmd >> 22) & 0xff) {
7664a49301eSmrg      case 0x50:
7677ec681f3Smrg         return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2);
7684a49301eSmrg      case 0x53:
7697ec681f3Smrg         return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2);
7704a49301eSmrg      default:
7717ec681f3Smrg         return debug(stream, "blit command", (cmd & 0xff) + 2);
7724a49301eSmrg      }
7734a49301eSmrg      break;
7744a49301eSmrg   case 0x3:
7757ec681f3Smrg      switch ((cmd >> 24) & 0x1f) {
7764a49301eSmrg      case 0x6:
7777ec681f3Smrg         return debug(stream, "3DSTATE_ANTI_ALIASING", 1);
7784a49301eSmrg      case 0x7:
7797ec681f3Smrg         return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1);
7804a49301eSmrg      case 0x8:
7817ec681f3Smrg         return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 1);
7824a49301eSmrg      case 0x9:
7837ec681f3Smrg         return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1);
7844a49301eSmrg      case 0xb:
7857ec681f3Smrg         return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1);
7864a49301eSmrg      case 0xc:
7877ec681f3Smrg         return debug(stream, "3DSTATE_MODES5", 1);
7884a49301eSmrg      case 0xd:
7897ec681f3Smrg         return debug_modes4(stream, "3DSTATE_MODES4", 1);
7904a49301eSmrg      case 0x15:
7917ec681f3Smrg         return debug(stream, "3DSTATE_FOG_COLOR", 1);
7924a49301eSmrg      case 0x16:
7937ec681f3Smrg         return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1);
7944a49301eSmrg      case 0x1c:
7957ec681f3Smrg         /* 3DState16NP */
7967ec681f3Smrg         switch ((cmd >> 19) & 0x1f) {
7977ec681f3Smrg         case 0x10:
7987ec681f3Smrg            return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1);
7997ec681f3Smrg         case 0x11:
8007ec681f3Smrg            return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1);
8017ec681f3Smrg         default:
8027ec681f3Smrg            (void)debug(stream, "UNKNOWN 0x1c case!", 1);
8034a49301eSmrg            assert(0);
8047ec681f3Smrg            break;
8057ec681f3Smrg         }
8067ec681f3Smrg         break;
8074a49301eSmrg      case 0x1d:
8087ec681f3Smrg         /* 3DStateMW */
8097ec681f3Smrg         switch ((cmd >> 16) & 0xff) {
8107ec681f3Smrg         case 0x0:
8117ec681f3Smrg            return debug_map_state(stream, "3DSTATE_MAP_STATE",
8127ec681f3Smrg                                   (cmd & 0x1f) + 2);
8137ec681f3Smrg         case 0x1:
8147ec681f3Smrg            return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE",
8157ec681f3Smrg                                       (cmd & 0x1f) + 2);
8167ec681f3Smrg         case 0x4:
8177ec681f3Smrg            return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE",
8187ec681f3Smrg                                        (cmd & 0xf) + 2);
8197ec681f3Smrg         case 0x5:
8207ec681f3Smrg            return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM",
8217ec681f3Smrg                                 (cmd & 0x1ff) + 2);
8227ec681f3Smrg         case 0x6:
8237ec681f3Smrg            return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS",
8247ec681f3Smrg                         (cmd & 0xff) + 2);
8257ec681f3Smrg         case 0x7:
8267ec681f3Smrg            return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT",
8277ec681f3Smrg                                       (cmd & 0xff) + 2);
8287ec681f3Smrg         case 0x80:
8297ec681f3Smrg            return debug(stream, "3DSTATE_DRAWING_RECTANGLE",
8307ec681f3Smrg                         (cmd & 0xffff) + 2);
8317ec681f3Smrg         case 0x81:
8327ec681f3Smrg            return debug(stream, "3DSTATE_SCISSOR_RECTANGLE",
8337ec681f3Smrg                         (cmd & 0xffff) + 2);
8347ec681f3Smrg         case 0x83:
8357ec681f3Smrg            return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2);
8367ec681f3Smrg         case 0x85:
8377ec681f3Smrg            return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS",
8387ec681f3Smrg                                   (cmd & 0xffff) + 2);
8397ec681f3Smrg         case 0x88:
8407ec681f3Smrg            return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR",
8417ec681f3Smrg                         (cmd & 0xffff) + 2);
8427ec681f3Smrg         case 0x89:
8437ec681f3Smrg            return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2);
8447ec681f3Smrg         case 0x8e:
8457ec681f3Smrg            return debug_buf_info(stream, "3DSTATE_BUFFER_INFO",
8467ec681f3Smrg                                  (cmd & 0xffff) + 2);
8477ec681f3Smrg         case 0x97:
8487ec681f3Smrg            return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE",
8497ec681f3Smrg                         (cmd & 0xffff) + 2);
8507ec681f3Smrg         case 0x98:
8517ec681f3Smrg            return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2);
8527ec681f3Smrg         case 0x99:
8537ec681f3Smrg            return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2);
8547ec681f3Smrg         case 0x9a:
8557ec681f3Smrg            return debug(stream, "3DSTATE_DEFAULT_SPECULAR",
8567ec681f3Smrg                         (cmd & 0xffff) + 2);
8577ec681f3Smrg         case 0x9c:
8587ec681f3Smrg            return debug(stream, "3DSTATE_CLEAR_PARAMETERS",
8597ec681f3Smrg                         (cmd & 0xffff) + 2);
8607ec681f3Smrg         default:
8617ec681f3Smrg            assert(0);
8627ec681f3Smrg            return 0;
8637ec681f3Smrg         }
8647ec681f3Smrg         break;
8654a49301eSmrg      case 0x1e:
8667ec681f3Smrg         if (cmd & (1 << 23))
8677ec681f3Smrg            return debug(stream, "???", (cmd & 0xffff) + 1);
8687ec681f3Smrg         else
8697ec681f3Smrg            return debug(stream, "", 1);
8707ec681f3Smrg         break;
8714a49301eSmrg      case 0x1f:
8727ec681f3Smrg         if ((cmd & (1 << 23)) == 0)
8737ec681f3Smrg            return debug_prim(stream, "3DPRIM (inline)", 1,
8747ec681f3Smrg                              (cmd & 0x1ffff) + 2);
8757ec681f3Smrg         else if (cmd & (1 << 17)) {
8767ec681f3Smrg            if ((cmd & 0xffff) == 0)
8777ec681f3Smrg               return debug_variable_length_prim(stream);
8787ec681f3Smrg            else
8797ec681f3Smrg               return debug_prim(stream, "3DPRIM (indexed)", 0,
8807ec681f3Smrg                                 (((cmd & 0xffff) + 1) / 2) + 1);
8817ec681f3Smrg         } else
8827ec681f3Smrg            return debug_prim(stream, "3DPRIM  (indirect sequential)", 0, 2);
8837ec681f3Smrg         break;
8844a49301eSmrg      default:
8857ec681f3Smrg         return debug(stream, "", 0);
8864a49301eSmrg      }
8874a49301eSmrg      break;
8884a49301eSmrg   default:
8894a49301eSmrg      assert(0);
8904a49301eSmrg      return 0;
8914a49301eSmrg   }
8924a49301eSmrg
8934a49301eSmrg   assert(0);
8944a49301eSmrg   return 0;
8954a49301eSmrg}
8964a49301eSmrg
8974a49301eSmrgvoid
8987ec681f3Smrgi915_dump_batchbuffer(struct i915_winsys_batchbuffer *batch)
8994a49301eSmrg{
9004a49301eSmrg   struct debug_stream stream;
9017ec681f3Smrg   unsigned *start = (unsigned *)batch->map;
9027ec681f3Smrg   unsigned *end = (unsigned *)batch->ptr;
9037ec681f3Smrg   unsigned long bytes = (unsigned long)(end - start) * 4;
9047ec681f3Smrg   bool done = false;
9054a49301eSmrg
9064a49301eSmrg   stream.offset = 0;
9074a49301eSmrg   stream.ptr = (char *)start;
9084a49301eSmrg   stream.print_addresses = 0;
9094a49301eSmrg
9104a49301eSmrg   if (!start || !end) {
9117ec681f3Smrg      mesa_logi("BATCH: ???");
9124a49301eSmrg      return;
9134a49301eSmrg   }
914af69d88dSmrg
9157ec681f3Smrg   mesa_logi("BATCH: (%d)", (int)bytes / 4);
9164a49301eSmrg
9177ec681f3Smrg   while (!done && stream.offset < bytes) {
9187ec681f3Smrg      if (!i915_debug_packet(&stream))
9197ec681f3Smrg         break;
9204a49301eSmrg
921af69d88dSmrg      assert(stream.offset <= bytes);
9224a49301eSmrg   }
9234a49301eSmrg
9247ec681f3Smrg   mesa_logi("END-BATCH");
9254a49301eSmrg}
9264a49301eSmrg
9273464ebd5Sriastradh/***********************************************************************
9283464ebd5Sriastradh * Dirty state atom dumping
9293464ebd5Sriastradh */
9303464ebd5Sriastradh
9313464ebd5Sriastradhvoid
9323464ebd5Sriastradhi915_dump_dirty(struct i915_context *i915, const char *func)
9333464ebd5Sriastradh{
9343464ebd5Sriastradh   struct {
9353464ebd5Sriastradh      unsigned dirty;
9363464ebd5Sriastradh      const char *name;
9373464ebd5Sriastradh   } l[] = {
9387ec681f3Smrg      {I915_NEW_VIEWPORT, "viewport"},
9397ec681f3Smrg      {I915_NEW_RASTERIZER, "rasterizer"},
9407ec681f3Smrg      {I915_NEW_FS, "fs"},
9417ec681f3Smrg      {I915_NEW_BLEND, "blend"},
9427ec681f3Smrg      {I915_NEW_CLIP, "clip"},
9437ec681f3Smrg      {I915_NEW_SCISSOR, "scissor"},
9447ec681f3Smrg      {I915_NEW_STIPPLE, "stipple"},
9457ec681f3Smrg      {I915_NEW_FRAMEBUFFER, "framebuffer"},
9467ec681f3Smrg      {I915_NEW_ALPHA_TEST, "alpha_test"},
9473464ebd5Sriastradh      {I915_NEW_DEPTH_STENCIL, "depth_stencil"},
9487ec681f3Smrg      {I915_NEW_SAMPLER, "sampler"},
9497ec681f3Smrg      {I915_NEW_SAMPLER_VIEW, "sampler_view"},
9507ec681f3Smrg      {I915_NEW_VS_CONSTANTS, "vs_const"},
9517ec681f3Smrg      {I915_NEW_FS_CONSTANTS, "fs_const"},
9527ec681f3Smrg      {I915_NEW_VBO, "vbo"},
9537ec681f3Smrg      {I915_NEW_VS, "vs"},
9543464ebd5Sriastradh      {0, NULL},
9553464ebd5Sriastradh   };
9563464ebd5Sriastradh   int i;
9573464ebd5Sriastradh
9587ec681f3Smrg   mesa_logi("%s: ", func);
9593464ebd5Sriastradh   for (i = 0; l[i].name; i++)
9603464ebd5Sriastradh      if (i915->dirty & l[i].dirty)
9617ec681f3Smrg         mesa_logi("%s ", l[i].name);
9627ec681f3Smrg   mesa_logi("%s", "");
9633464ebd5Sriastradh}
9643464ebd5Sriastradh
9653464ebd5Sriastradhvoid
9663464ebd5Sriastradhi915_dump_hardware_dirty(struct i915_context *i915, const char *func)
9673464ebd5Sriastradh{
9683464ebd5Sriastradh   struct {
9693464ebd5Sriastradh      unsigned dirty;
9703464ebd5Sriastradh      const char *name;
9713464ebd5Sriastradh   } l[] = {
9727ec681f3Smrg      {I915_HW_STATIC, "static"},
9737ec681f3Smrg      {I915_HW_DYNAMIC, "dynamic"},
9747ec681f3Smrg      {I915_HW_SAMPLER, "sampler"},
9757ec681f3Smrg      {I915_HW_MAP, "map"},
9767ec681f3Smrg      {I915_HW_PROGRAM, "program"},
9773464ebd5Sriastradh      {I915_HW_CONSTANTS, "constants"},
9783464ebd5Sriastradh      {I915_HW_IMMEDIATE, "immediate"},
9793464ebd5Sriastradh      {I915_HW_INVARIANT, "invariant"},
9803464ebd5Sriastradh      {0, NULL},
9813464ebd5Sriastradh   };
9823464ebd5Sriastradh   int i;
9833464ebd5Sriastradh
9847ec681f3Smrg   mesa_logi("%s: ", func);
9853464ebd5Sriastradh   for (i = 0; l[i].name; i++)
9863464ebd5Sriastradh      if (i915->hardware_dirty & l[i].dirty)
9877ec681f3Smrg         mesa_logi("%s ", l[i].name);
9887ec681f3Smrg   mesa_logi("%s", "");
9893464ebd5Sriastradh}
990