1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2003 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "i915_debug.h"
29bf215546Sopenharmony_ci#include "util/log.h"
30bf215546Sopenharmony_ci#include "util/ralloc.h"
31bf215546Sopenharmony_ci#include "util/u_debug.h"
32bf215546Sopenharmony_ci#include "i915_batch.h"
33bf215546Sopenharmony_ci#include "i915_context.h"
34bf215546Sopenharmony_ci#include "i915_debug_private.h"
35bf215546Sopenharmony_ci#include "i915_reg.h"
36bf215546Sopenharmony_ci#include "i915_screen.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistatic const struct debug_named_value i915_debug_options[] = {
39bf215546Sopenharmony_ci   {"blit", DBG_BLIT, "Print when using the 2d blitter"},
40bf215546Sopenharmony_ci   {"emit", DBG_EMIT, "State emit information"},
41bf215546Sopenharmony_ci   {"atoms", DBG_ATOMS, "Print dirty state atoms"},
42bf215546Sopenharmony_ci   {"flush", DBG_FLUSH, "Flushing information"},
43bf215546Sopenharmony_ci   {"texture", DBG_TEXTURE, "Texture information"},
44bf215546Sopenharmony_ci   {"constants", DBG_CONSTANTS, "Constant buffers"},
45bf215546Sopenharmony_ci   {"fs", DBG_FS, "Dump fragment shaders"},
46bf215546Sopenharmony_ci   {"vbuf", DBG_VBUF, "Use the WIP vbuf code path"},
47bf215546Sopenharmony_ci   DEBUG_NAMED_VALUE_END};
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ciunsigned i915_debug = 0;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ciDEBUG_GET_ONCE_FLAGS_OPTION(i915_debug, "I915_DEBUG", i915_debug_options, 0)
52bf215546Sopenharmony_ciDEBUG_GET_ONCE_BOOL_OPTION(i915_no_tiling, "I915_NO_TILING", false)
53bf215546Sopenharmony_ciDEBUG_GET_ONCE_BOOL_OPTION(i915_use_blitter, "I915_USE_BLITTER", true)
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_civoid
56bf215546Sopenharmony_cii915_debug_init(struct i915_screen *is)
57bf215546Sopenharmony_ci{
58bf215546Sopenharmony_ci   i915_debug = debug_get_option_i915_debug();
59bf215546Sopenharmony_ci   is->debug.tiling = !debug_get_option_i915_no_tiling();
60bf215546Sopenharmony_ci   is->debug.use_blitter = debug_get_option_i915_use_blitter();
61bf215546Sopenharmony_ci}
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci/***********************************************************************
64bf215546Sopenharmony_ci * Batchbuffer dumping
65bf215546Sopenharmony_ci */
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistatic bool
68bf215546Sopenharmony_cidebug(struct debug_stream *stream, const char *name, unsigned len)
69bf215546Sopenharmony_ci{
70bf215546Sopenharmony_ci   unsigned i;
71bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   if (len == 0) {
74bf215546Sopenharmony_ci      mesa_logi("Error - zero length packet (0x%08x)", stream->ptr[0]);
75bf215546Sopenharmony_ci      assert(0);
76bf215546Sopenharmony_ci      return false;
77bf215546Sopenharmony_ci   }
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   if (stream->print_addresses)
80bf215546Sopenharmony_ci      mesa_logi("%08x:  ", stream->offset);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
83bf215546Sopenharmony_ci   for (i = 0; i < len; i++)
84bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[i]);
85bf215546Sopenharmony_ci   mesa_logi("%s", "");
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci   return true;
90bf215546Sopenharmony_ci}
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_cistatic const char *
93bf215546Sopenharmony_ciget_prim_name(unsigned val)
94bf215546Sopenharmony_ci{
95bf215546Sopenharmony_ci   switch (val & PRIM3D_MASK) {
96bf215546Sopenharmony_ci   case PRIM3D_TRILIST:
97bf215546Sopenharmony_ci      return "TRILIST";
98bf215546Sopenharmony_ci      break;
99bf215546Sopenharmony_ci   case PRIM3D_TRISTRIP:
100bf215546Sopenharmony_ci      return "TRISTRIP";
101bf215546Sopenharmony_ci      break;
102bf215546Sopenharmony_ci   case PRIM3D_TRISTRIP_RVRSE:
103bf215546Sopenharmony_ci      return "TRISTRIP_RVRSE";
104bf215546Sopenharmony_ci      break;
105bf215546Sopenharmony_ci   case PRIM3D_TRIFAN:
106bf215546Sopenharmony_ci      return "TRIFAN";
107bf215546Sopenharmony_ci      break;
108bf215546Sopenharmony_ci   case PRIM3D_POLY:
109bf215546Sopenharmony_ci      return "POLY";
110bf215546Sopenharmony_ci      break;
111bf215546Sopenharmony_ci   case PRIM3D_LINELIST:
112bf215546Sopenharmony_ci      return "LINELIST";
113bf215546Sopenharmony_ci      break;
114bf215546Sopenharmony_ci   case PRIM3D_LINESTRIP:
115bf215546Sopenharmony_ci      return "LINESTRIP";
116bf215546Sopenharmony_ci      break;
117bf215546Sopenharmony_ci   case PRIM3D_RECTLIST:
118bf215546Sopenharmony_ci      return "RECTLIST";
119bf215546Sopenharmony_ci      break;
120bf215546Sopenharmony_ci   case PRIM3D_POINTLIST:
121bf215546Sopenharmony_ci      return "POINTLIST";
122bf215546Sopenharmony_ci      break;
123bf215546Sopenharmony_ci   case PRIM3D_DIB:
124bf215546Sopenharmony_ci      return "DIB";
125bf215546Sopenharmony_ci      break;
126bf215546Sopenharmony_ci   case PRIM3D_CLEAR_RECT:
127bf215546Sopenharmony_ci      return "CLEAR_RECT";
128bf215546Sopenharmony_ci      break;
129bf215546Sopenharmony_ci   case PRIM3D_ZONE_INIT:
130bf215546Sopenharmony_ci      return "ZONE_INIT";
131bf215546Sopenharmony_ci      break;
132bf215546Sopenharmony_ci   default:
133bf215546Sopenharmony_ci      return "????";
134bf215546Sopenharmony_ci      break;
135bf215546Sopenharmony_ci   }
136bf215546Sopenharmony_ci}
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_cistatic bool
139bf215546Sopenharmony_cidebug_prim(struct debug_stream *stream, const char *name, bool dump_floats,
140bf215546Sopenharmony_ci           unsigned len)
141bf215546Sopenharmony_ci{
142bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
143bf215546Sopenharmony_ci   const char *prim = get_prim_name(ptr[0]);
144bf215546Sopenharmony_ci   unsigned i;
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci   mesa_logi("%s %s (%d dwords):", name, prim, len);
147bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[0]);
148bf215546Sopenharmony_ci   for (i = 1; i < len; i++) {
149bf215546Sopenharmony_ci      if (dump_floats)
150bf215546Sopenharmony_ci         mesa_logi("\t0x%08x // %f", ptr[i], *(float *)&ptr[i]);
151bf215546Sopenharmony_ci      else
152bf215546Sopenharmony_ci         mesa_logi("\t0x%08x", ptr[i]);
153bf215546Sopenharmony_ci   }
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci   mesa_logi("%s", "");
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   return true;
160bf215546Sopenharmony_ci}
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_cistatic bool
163bf215546Sopenharmony_cidebug_program(struct debug_stream *stream, const char *name, unsigned len)
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci   if (len == 0) {
168bf215546Sopenharmony_ci      mesa_logi("Error - zero length packet (0x%08x)", stream->ptr[0]);
169bf215546Sopenharmony_ci      assert(0);
170bf215546Sopenharmony_ci      return false;
171bf215546Sopenharmony_ci   }
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   if (stream->print_addresses)
174bf215546Sopenharmony_ci      mesa_logi("%08x:  ", stream->offset);
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
177bf215546Sopenharmony_ci   i915_disassemble_program(ptr, len);
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
180bf215546Sopenharmony_ci   return true;
181bf215546Sopenharmony_ci}
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_cistatic bool
184bf215546Sopenharmony_cidebug_chain(struct debug_stream *stream, const char *name, unsigned len)
185bf215546Sopenharmony_ci{
186bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
187bf215546Sopenharmony_ci   unsigned old_offset = stream->offset + len * sizeof(unsigned);
188bf215546Sopenharmony_ci   unsigned i;
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
191bf215546Sopenharmony_ci   for (i = 0; i < len; i++)
192bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[i]);
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci   stream->offset = ptr[1] & ~0x3;
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_ci   if (stream->offset < old_offset)
197bf215546Sopenharmony_ci      mesa_logi("... skipping backwards from 0x%x --> 0x%x ...", old_offset,
198bf215546Sopenharmony_ci                stream->offset);
199bf215546Sopenharmony_ci   else
200bf215546Sopenharmony_ci      mesa_logi("... skipping from 0x%x --> 0x%x ...", old_offset,
201bf215546Sopenharmony_ci                stream->offset);
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci   return true;
204bf215546Sopenharmony_ci}
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_cistatic bool
207bf215546Sopenharmony_cidebug_variable_length_prim(struct debug_stream *stream)
208bf215546Sopenharmony_ci{
209bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
210bf215546Sopenharmony_ci   const char *prim = get_prim_name(ptr[0]);
211bf215546Sopenharmony_ci   unsigned i, len;
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   ushort *idx = (ushort *)(ptr + 1);
214bf215546Sopenharmony_ci   for (i = 0; idx[i] != 0xffff; i++)
215bf215546Sopenharmony_ci      ;
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci   len = 1 + (i + 2) / 2;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   mesa_logi("3DPRIM, %s variable length %d indicies (%d dwords):", prim, i,
220bf215546Sopenharmony_ci             len);
221bf215546Sopenharmony_ci   for (i = 0; i < len; i++)
222bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[i]);
223bf215546Sopenharmony_ci   mesa_logi("%s", "");
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
226bf215546Sopenharmony_ci   return true;
227bf215546Sopenharmony_ci}
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_cistatic void
230bf215546Sopenharmony_ciBITS(struct debug_stream *stream, unsigned dw, unsigned hi, unsigned lo,
231bf215546Sopenharmony_ci     const char *fmt, ...)
232bf215546Sopenharmony_ci{
233bf215546Sopenharmony_ci   va_list args;
234bf215546Sopenharmony_ci   unsigned himask = 0xFFFFFFFFUL >> (31 - (hi));
235bf215546Sopenharmony_ci
236bf215546Sopenharmony_ci   va_start(args, fmt);
237bf215546Sopenharmony_ci   char *out = ralloc_vasprintf(NULL, fmt, args);
238bf215546Sopenharmony_ci   va_end(args);
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci   mesa_logi("\t\t %s : 0x%x", out, ((dw)&himask) >> (lo));
241bf215546Sopenharmony_ci
242bf215546Sopenharmony_ci   ralloc_free(out);
243bf215546Sopenharmony_ci}
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci#define MBZ(dw, hi, lo)                                                        \
246bf215546Sopenharmony_ci   do {                                                                        \
247bf215546Sopenharmony_ci      ASSERTED unsigned x = (dw) >> (lo);                                      \
248bf215546Sopenharmony_ci      ASSERTED unsigned lomask = (1 << (lo)) - 1;                              \
249bf215546Sopenharmony_ci      ASSERTED unsigned himask;                                                \
250bf215546Sopenharmony_ci      himask = (1UL << (hi)) - 1;                                              \
251bf215546Sopenharmony_ci      assert((x & himask & ~lomask) == 0);                                     \
252bf215546Sopenharmony_ci   } while (0)
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_cistatic void
255bf215546Sopenharmony_ciFLAG(struct debug_stream *stream, unsigned dw, unsigned bit, const char *fmt,
256bf215546Sopenharmony_ci     ...)
257bf215546Sopenharmony_ci{
258bf215546Sopenharmony_ci   if (((dw) >> (bit)) & 1) {
259bf215546Sopenharmony_ci      va_list args;
260bf215546Sopenharmony_ci      va_start(args, fmt);
261bf215546Sopenharmony_ci      char *out = ralloc_vasprintf(NULL, fmt, args);
262bf215546Sopenharmony_ci      va_end(args);
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci      mesa_logi("\t\t %s", out);
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci      ralloc_free(out);
267bf215546Sopenharmony_ci   }
268bf215546Sopenharmony_ci}
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_cistatic bool
271bf215546Sopenharmony_cidebug_load_immediate(struct debug_stream *stream, const char *name,
272bf215546Sopenharmony_ci                     unsigned len)
273bf215546Sopenharmony_ci{
274bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
275bf215546Sopenharmony_ci   unsigned bits = (ptr[0] >> 4) & 0xff;
276bf215546Sopenharmony_ci   unsigned j = 0;
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords, flags: %x):", name, len, bits);
279bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   if (bits & (1 << 0)) {
282bf215546Sopenharmony_ci      mesa_logi("\t  LIS0: 0x%08x", ptr[j]);
283bf215546Sopenharmony_ci      mesa_logi("\t vb address: 0x%08x", (ptr[j] & ~0x3));
284bf215546Sopenharmony_ci      BITS(stream, ptr[j], 0, 0, "vb invalidate disable");
285bf215546Sopenharmony_ci      j++;
286bf215546Sopenharmony_ci   }
287bf215546Sopenharmony_ci   if (bits & (1 << 1)) {
288bf215546Sopenharmony_ci      mesa_logi("\t  LIS1: 0x%08x", ptr[j]);
289bf215546Sopenharmony_ci      BITS(stream, ptr[j], 29, 24, "vb dword width");
290bf215546Sopenharmony_ci      BITS(stream, ptr[j], 21, 16, "vb dword pitch");
291bf215546Sopenharmony_ci      BITS(stream, ptr[j], 15, 0, "vb max index");
292bf215546Sopenharmony_ci      j++;
293bf215546Sopenharmony_ci   }
294bf215546Sopenharmony_ci   if (bits & (1 << 2)) {
295bf215546Sopenharmony_ci      int i;
296bf215546Sopenharmony_ci      mesa_logi("\t  LIS2: 0x%08x", ptr[j]);
297bf215546Sopenharmony_ci      for (i = 0; i < 8; i++) {
298bf215546Sopenharmony_ci         unsigned tc = (ptr[j] >> (i * 4)) & 0xf;
299bf215546Sopenharmony_ci         if (tc != 0xf)
300bf215546Sopenharmony_ci            BITS(stream, tc, 3, 0, "tex coord %d", i);
301bf215546Sopenharmony_ci      }
302bf215546Sopenharmony_ci      j++;
303bf215546Sopenharmony_ci   }
304bf215546Sopenharmony_ci   if (bits & (1 << 3)) {
305bf215546Sopenharmony_ci      mesa_logi("\t  LIS3: 0x%08x", ptr[j]);
306bf215546Sopenharmony_ci      j++;
307bf215546Sopenharmony_ci   }
308bf215546Sopenharmony_ci   if (bits & (1 << 4)) {
309bf215546Sopenharmony_ci      mesa_logi("\t  LIS4: 0x%08x", ptr[j]);
310bf215546Sopenharmony_ci      BITS(stream, ptr[j], 31, 23, "point width");
311bf215546Sopenharmony_ci      BITS(stream, ptr[j], 22, 19, "line width");
312bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 18, "alpha flatshade");
313bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 17, "fog flatshade");
314bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 16, "spec flatshade");
315bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 15, "rgb flatshade");
316bf215546Sopenharmony_ci      BITS(stream, ptr[j], 14, 13, "cull mode");
317bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 12, "vfmt: point width");
318bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 11, "vfmt: specular/fog");
319bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 10, "vfmt: rgba");
320bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 9, "vfmt: depth offset");
321bf215546Sopenharmony_ci      BITS(stream, ptr[j], 8, 6, "vfmt: position (2==xyzw)");
322bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 5, "force dflt diffuse");
323bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 4, "force dflt specular");
324bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 3, "local depth offset enable");
325bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 2, "vfmt: fp32 fog coord");
326bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 1, "sprite point");
327bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 0, "antialiasing");
328bf215546Sopenharmony_ci      j++;
329bf215546Sopenharmony_ci   }
330bf215546Sopenharmony_ci   if (bits & (1 << 5)) {
331bf215546Sopenharmony_ci      mesa_logi("\t  LIS5: 0x%08x", ptr[j]);
332bf215546Sopenharmony_ci      BITS(stream, ptr[j], 31, 28, "rgba write disables");
333bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 27, "force dflt point width");
334bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 26, "last pixel enable");
335bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 25, "global z offset enable");
336bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 24, "fog enable");
337bf215546Sopenharmony_ci      BITS(stream, ptr[j], 23, 16, "stencil ref");
338bf215546Sopenharmony_ci      BITS(stream, ptr[j], 15, 13, "stencil test");
339bf215546Sopenharmony_ci      BITS(stream, ptr[j], 12, 10, "stencil fail op");
340bf215546Sopenharmony_ci      BITS(stream, ptr[j], 9, 7, "stencil pass z fail op");
341bf215546Sopenharmony_ci      BITS(stream, ptr[j], 6, 4, "stencil pass z pass op");
342bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 3, "stencil write enable");
343bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 2, "stencil test enable");
344bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 1, "color dither enable");
345bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 0, "logiop enable");
346bf215546Sopenharmony_ci      j++;
347bf215546Sopenharmony_ci   }
348bf215546Sopenharmony_ci   if (bits & (1 << 6)) {
349bf215546Sopenharmony_ci      mesa_logi("\t  LIS6: 0x%08x", ptr[j]);
350bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 31, "alpha test enable");
351bf215546Sopenharmony_ci      BITS(stream, ptr[j], 30, 28, "alpha func");
352bf215546Sopenharmony_ci      BITS(stream, ptr[j], 27, 20, "alpha ref");
353bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 19, "depth test enable");
354bf215546Sopenharmony_ci      BITS(stream, ptr[j], 18, 16, "depth func");
355bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 15, "blend enable");
356bf215546Sopenharmony_ci      BITS(stream, ptr[j], 14, 12, "blend func");
357bf215546Sopenharmony_ci      BITS(stream, ptr[j], 11, 8, "blend src factor");
358bf215546Sopenharmony_ci      BITS(stream, ptr[j], 7, 4, "blend dst factor");
359bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 3, "depth write enable");
360bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 2, "color write enable");
361bf215546Sopenharmony_ci      BITS(stream, ptr[j], 1, 0, "provoking vertex");
362bf215546Sopenharmony_ci      j++;
363bf215546Sopenharmony_ci   }
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci   mesa_logi("%s", "");
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_ci   assert(j == len);
368bf215546Sopenharmony_ci
369bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ci   return true;
372bf215546Sopenharmony_ci}
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_cistatic bool
375bf215546Sopenharmony_cidebug_load_indirect(struct debug_stream *stream, const char *name, unsigned len)
376bf215546Sopenharmony_ci{
377bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
378bf215546Sopenharmony_ci   unsigned bits = (ptr[0] >> 8) & 0x3f;
379bf215546Sopenharmony_ci   unsigned i, j = 0;
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
382bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci   for (i = 0; i < 6; i++) {
385bf215546Sopenharmony_ci      if (bits & (1 << i)) {
386bf215546Sopenharmony_ci         switch (1 << (8 + i)) {
387bf215546Sopenharmony_ci         case LI0_STATE_STATIC_INDIRECT:
388bf215546Sopenharmony_ci            mesa_logi("        STATIC: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
389bf215546Sopenharmony_ci            j++;
390bf215546Sopenharmony_ci            mesa_logi("                0x%08x", ptr[j++]);
391bf215546Sopenharmony_ci            break;
392bf215546Sopenharmony_ci         case LI0_STATE_DYNAMIC_INDIRECT:
393bf215546Sopenharmony_ci            mesa_logi("       DYNAMIC: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
394bf215546Sopenharmony_ci            j++;
395bf215546Sopenharmony_ci            break;
396bf215546Sopenharmony_ci         case LI0_STATE_SAMPLER:
397bf215546Sopenharmony_ci            mesa_logi("       SAMPLER: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
398bf215546Sopenharmony_ci            j++;
399bf215546Sopenharmony_ci            mesa_logi("                0x%08x", ptr[j++]);
400bf215546Sopenharmony_ci            break;
401bf215546Sopenharmony_ci         case LI0_STATE_MAP:
402bf215546Sopenharmony_ci            mesa_logi("           MAP: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
403bf215546Sopenharmony_ci            j++;
404bf215546Sopenharmony_ci            mesa_logi("                0x%08x", ptr[j++]);
405bf215546Sopenharmony_ci            break;
406bf215546Sopenharmony_ci         case LI0_STATE_PROGRAM:
407bf215546Sopenharmony_ci            mesa_logi("       PROGRAM: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
408bf215546Sopenharmony_ci            j++;
409bf215546Sopenharmony_ci            mesa_logi("                0x%08x", ptr[j++]);
410bf215546Sopenharmony_ci            break;
411bf215546Sopenharmony_ci         case LI0_STATE_CONSTANTS:
412bf215546Sopenharmony_ci            mesa_logi("     CONSTANTS: 0x%08x | %x", ptr[j] & ~3, ptr[j] & 3);
413bf215546Sopenharmony_ci            j++;
414bf215546Sopenharmony_ci            mesa_logi("                0x%08x", ptr[j++]);
415bf215546Sopenharmony_ci            break;
416bf215546Sopenharmony_ci         default:
417bf215546Sopenharmony_ci            assert(0);
418bf215546Sopenharmony_ci            break;
419bf215546Sopenharmony_ci         }
420bf215546Sopenharmony_ci      }
421bf215546Sopenharmony_ci   }
422bf215546Sopenharmony_ci
423bf215546Sopenharmony_ci   if (bits == 0) {
424bf215546Sopenharmony_ci      mesa_logi("\t  DUMMY: 0x%08x", ptr[j++]);
425bf215546Sopenharmony_ci   }
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci   mesa_logi("%s", "");
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci   assert(j == len);
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci   return true;
434bf215546Sopenharmony_ci}
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_cistatic void
437bf215546Sopenharmony_ciBR13(struct debug_stream *stream, unsigned val)
438bf215546Sopenharmony_ci{
439bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", val);
440bf215546Sopenharmony_ci   FLAG(stream, val, 30, "clipping enable");
441bf215546Sopenharmony_ci   BITS(stream, val, 25, 24, "color depth (3==32bpp)");
442bf215546Sopenharmony_ci   BITS(stream, val, 23, 16, "raster op");
443bf215546Sopenharmony_ci   BITS(stream, val, 15, 0, "dest pitch");
444bf215546Sopenharmony_ci}
445bf215546Sopenharmony_ci
446bf215546Sopenharmony_cistatic void
447bf215546Sopenharmony_ciBR22(struct debug_stream *stream, unsigned val)
448bf215546Sopenharmony_ci{
449bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", val);
450bf215546Sopenharmony_ci   BITS(stream, val, 31, 16, "dest y1");
451bf215546Sopenharmony_ci   BITS(stream, val, 15, 0, "dest x1");
452bf215546Sopenharmony_ci}
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_cistatic void
455bf215546Sopenharmony_ciBR23(struct debug_stream *stream, unsigned val)
456bf215546Sopenharmony_ci{
457bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", val);
458bf215546Sopenharmony_ci   BITS(stream, val, 31, 16, "dest y2");
459bf215546Sopenharmony_ci   BITS(stream, val, 15, 0, "dest x2");
460bf215546Sopenharmony_ci}
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_cistatic void
463bf215546Sopenharmony_ciBR09(struct debug_stream *stream, unsigned val)
464bf215546Sopenharmony_ci{
465bf215546Sopenharmony_ci   mesa_logi("\t0x%08x -- dest address", val);
466bf215546Sopenharmony_ci}
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_cistatic void
469bf215546Sopenharmony_ciBR26(struct debug_stream *stream, unsigned val)
470bf215546Sopenharmony_ci{
471bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", val);
472bf215546Sopenharmony_ci   BITS(stream, val, 31, 16, "src y1");
473bf215546Sopenharmony_ci   BITS(stream, val, 15, 0, "src x1");
474bf215546Sopenharmony_ci}
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_cistatic void
477bf215546Sopenharmony_ciBR11(struct debug_stream *stream, unsigned val)
478bf215546Sopenharmony_ci{
479bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", val);
480bf215546Sopenharmony_ci   BITS(stream, val, 15, 0, "src pitch");
481bf215546Sopenharmony_ci}
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_cistatic void
484bf215546Sopenharmony_ciBR12(struct debug_stream *stream, unsigned val)
485bf215546Sopenharmony_ci{
486bf215546Sopenharmony_ci   mesa_logi("\t0x%08x -- src address", val);
487bf215546Sopenharmony_ci}
488bf215546Sopenharmony_ci
489bf215546Sopenharmony_cistatic void
490bf215546Sopenharmony_ciBR16(struct debug_stream *stream, unsigned val)
491bf215546Sopenharmony_ci{
492bf215546Sopenharmony_ci   mesa_logi("\t0x%08x -- color", val);
493bf215546Sopenharmony_ci}
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_cistatic bool
496bf215546Sopenharmony_cidebug_copy_blit(struct debug_stream *stream, const char *name, unsigned len)
497bf215546Sopenharmony_ci{
498bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
499bf215546Sopenharmony_ci   int j = 0;
500bf215546Sopenharmony_ci
501bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
502bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
503bf215546Sopenharmony_ci
504bf215546Sopenharmony_ci   BR13(stream, ptr[j++]);
505bf215546Sopenharmony_ci   BR22(stream, ptr[j++]);
506bf215546Sopenharmony_ci   BR23(stream, ptr[j++]);
507bf215546Sopenharmony_ci   BR09(stream, ptr[j++]);
508bf215546Sopenharmony_ci   BR26(stream, ptr[j++]);
509bf215546Sopenharmony_ci   BR11(stream, ptr[j++]);
510bf215546Sopenharmony_ci   BR12(stream, ptr[j++]);
511bf215546Sopenharmony_ci
512bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
513bf215546Sopenharmony_ci   assert(j == len);
514bf215546Sopenharmony_ci   return true;
515bf215546Sopenharmony_ci}
516bf215546Sopenharmony_ci
517bf215546Sopenharmony_cistatic bool
518bf215546Sopenharmony_cidebug_color_blit(struct debug_stream *stream, const char *name, unsigned len)
519bf215546Sopenharmony_ci{
520bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
521bf215546Sopenharmony_ci   int j = 0;
522bf215546Sopenharmony_ci
523bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
524bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
525bf215546Sopenharmony_ci
526bf215546Sopenharmony_ci   BR13(stream, ptr[j++]);
527bf215546Sopenharmony_ci   BR22(stream, ptr[j++]);
528bf215546Sopenharmony_ci   BR23(stream, ptr[j++]);
529bf215546Sopenharmony_ci   BR09(stream, ptr[j++]);
530bf215546Sopenharmony_ci   BR16(stream, ptr[j++]);
531bf215546Sopenharmony_ci
532bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
533bf215546Sopenharmony_ci   assert(j == len);
534bf215546Sopenharmony_ci   return true;
535bf215546Sopenharmony_ci}
536bf215546Sopenharmony_ci
537bf215546Sopenharmony_cistatic bool
538bf215546Sopenharmony_cidebug_modes4(struct debug_stream *stream, const char *name, unsigned len)
539bf215546Sopenharmony_ci{
540bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
541bf215546Sopenharmony_ci   int j = 0;
542bf215546Sopenharmony_ci
543bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
544bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j]);
545bf215546Sopenharmony_ci   BITS(stream, ptr[j], 21, 18, "logicop func");
546bf215546Sopenharmony_ci   FLAG(stream, ptr[j], 17, "stencil test mask modify-enable");
547bf215546Sopenharmony_ci   FLAG(stream, ptr[j], 16, "stencil write mask modify-enable");
548bf215546Sopenharmony_ci   BITS(stream, ptr[j], 15, 8, "stencil test mask");
549bf215546Sopenharmony_ci   BITS(stream, ptr[j], 7, 0, "stencil write mask");
550bf215546Sopenharmony_ci   j++;
551bf215546Sopenharmony_ci
552bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
553bf215546Sopenharmony_ci   assert(j == len);
554bf215546Sopenharmony_ci   return true;
555bf215546Sopenharmony_ci}
556bf215546Sopenharmony_ci
557bf215546Sopenharmony_cistatic bool
558bf215546Sopenharmony_cidebug_map_state(struct debug_stream *stream, const char *name, unsigned len)
559bf215546Sopenharmony_ci{
560bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
561bf215546Sopenharmony_ci   unsigned j = 0;
562bf215546Sopenharmony_ci
563bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
564bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
565bf215546Sopenharmony_ci
566bf215546Sopenharmony_ci   {
567bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[j]);
568bf215546Sopenharmony_ci      BITS(stream, ptr[j], 15, 0, "map mask");
569bf215546Sopenharmony_ci      j++;
570bf215546Sopenharmony_ci   }
571bf215546Sopenharmony_ci
572bf215546Sopenharmony_ci   while (j < len) {
573bf215546Sopenharmony_ci      {
574bf215546Sopenharmony_ci         mesa_logi("\t  TMn.0: 0x%08x", ptr[j]);
575bf215546Sopenharmony_ci         mesa_logi("\t map address: 0x%08x", (ptr[j] & ~0x3));
576bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 1, "vertical line stride");
577bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 0, "vertical line stride offset");
578bf215546Sopenharmony_ci         j++;
579bf215546Sopenharmony_ci      }
580bf215546Sopenharmony_ci
581bf215546Sopenharmony_ci      {
582bf215546Sopenharmony_ci         mesa_logi("\t  TMn.1: 0x%08x", ptr[j]);
583bf215546Sopenharmony_ci         BITS(stream, ptr[j], 31, 21, "height");
584bf215546Sopenharmony_ci         BITS(stream, ptr[j], 20, 10, "width");
585bf215546Sopenharmony_ci         BITS(stream, ptr[j], 9, 7, "surface format");
586bf215546Sopenharmony_ci         BITS(stream, ptr[j], 6, 3, "texel format");
587bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 2, "use fence regs");
588bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 1, "tiled surface");
589bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 0, "tile walk ymajor");
590bf215546Sopenharmony_ci         j++;
591bf215546Sopenharmony_ci      }
592bf215546Sopenharmony_ci      {
593bf215546Sopenharmony_ci         mesa_logi("\t  TMn.2: 0x%08x", ptr[j]);
594bf215546Sopenharmony_ci         BITS(stream, ptr[j], 31, 21, "dword pitch");
595bf215546Sopenharmony_ci         BITS(stream, ptr[j], 20, 15, "cube face enables");
596bf215546Sopenharmony_ci         BITS(stream, ptr[j], 14, 9, "max lod");
597bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 8, "mip layout right");
598bf215546Sopenharmony_ci         BITS(stream, ptr[j], 7, 0, "depth");
599bf215546Sopenharmony_ci         j++;
600bf215546Sopenharmony_ci      }
601bf215546Sopenharmony_ci   }
602bf215546Sopenharmony_ci
603bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
604bf215546Sopenharmony_ci   assert(j == len);
605bf215546Sopenharmony_ci   return true;
606bf215546Sopenharmony_ci}
607bf215546Sopenharmony_ci
608bf215546Sopenharmony_cistatic bool
609bf215546Sopenharmony_cidebug_sampler_state(struct debug_stream *stream, const char *name, unsigned len)
610bf215546Sopenharmony_ci{
611bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
612bf215546Sopenharmony_ci   unsigned j = 0;
613bf215546Sopenharmony_ci
614bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
615bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
616bf215546Sopenharmony_ci
617bf215546Sopenharmony_ci   {
618bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[j]);
619bf215546Sopenharmony_ci      BITS(stream, ptr[j], 15, 0, "sampler mask");
620bf215546Sopenharmony_ci      j++;
621bf215546Sopenharmony_ci   }
622bf215546Sopenharmony_ci
623bf215546Sopenharmony_ci   while (j < len) {
624bf215546Sopenharmony_ci      {
625bf215546Sopenharmony_ci         mesa_logi("\t  TSn.0: 0x%08x", ptr[j]);
626bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 31, "reverse gamma");
627bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 30, "planar to packed");
628bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 29, "yuv->rgb");
629bf215546Sopenharmony_ci         BITS(stream, ptr[j], 28, 27, "chromakey index");
630bf215546Sopenharmony_ci         BITS(stream, ptr[j], 26, 22, "base mip level");
631bf215546Sopenharmony_ci         BITS(stream, ptr[j], 21, 20, "mip mode filter");
632bf215546Sopenharmony_ci         BITS(stream, ptr[j], 19, 17, "mag mode filter");
633bf215546Sopenharmony_ci         BITS(stream, ptr[j], 16, 14, "min mode filter");
634bf215546Sopenharmony_ci         BITS(stream, ptr[j], 13, 5, "lod bias (s4.4)");
635bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 4, "shadow enable");
636bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 3, "max-aniso-4");
637bf215546Sopenharmony_ci         BITS(stream, ptr[j], 2, 0, "shadow func");
638bf215546Sopenharmony_ci         j++;
639bf215546Sopenharmony_ci      }
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci      {
642bf215546Sopenharmony_ci         mesa_logi("\t  TSn.1: 0x%08x", ptr[j]);
643bf215546Sopenharmony_ci         BITS(stream, ptr[j], 31, 24, "min lod");
644bf215546Sopenharmony_ci         MBZ(ptr[j], 23, 18);
645bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 17, "kill pixel enable");
646bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 16, "keyed tex filter mode");
647bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 15, "chromakey enable");
648bf215546Sopenharmony_ci         BITS(stream, ptr[j], 14, 12, "tcx wrap mode");
649bf215546Sopenharmony_ci         BITS(stream, ptr[j], 11, 9, "tcy wrap mode");
650bf215546Sopenharmony_ci         BITS(stream, ptr[j], 8, 6, "tcz wrap mode");
651bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 5, "normalized coords");
652bf215546Sopenharmony_ci         BITS(stream, ptr[j], 4, 1, "map (surface) index");
653bf215546Sopenharmony_ci         FLAG(stream, ptr[j], 0, "EAST deinterlacer enable");
654bf215546Sopenharmony_ci         j++;
655bf215546Sopenharmony_ci      }
656bf215546Sopenharmony_ci      {
657bf215546Sopenharmony_ci         mesa_logi("\t  TSn.2: 0x%08x  (default color)", ptr[j]);
658bf215546Sopenharmony_ci         j++;
659bf215546Sopenharmony_ci      }
660bf215546Sopenharmony_ci   }
661bf215546Sopenharmony_ci
662bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
663bf215546Sopenharmony_ci   assert(j == len);
664bf215546Sopenharmony_ci   return true;
665bf215546Sopenharmony_ci}
666bf215546Sopenharmony_ci
667bf215546Sopenharmony_cistatic bool
668bf215546Sopenharmony_cidebug_dest_vars(struct debug_stream *stream, const char *name, unsigned len)
669bf215546Sopenharmony_ci{
670bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
671bf215546Sopenharmony_ci   int j = 0;
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
674bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
675bf215546Sopenharmony_ci
676bf215546Sopenharmony_ci   {
677bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[j]);
678bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 31, "early classic ztest");
679bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 30, "opengl tex default color");
680bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 29, "bypass iz");
681bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 28, "lod preclamp");
682bf215546Sopenharmony_ci      BITS(stream, ptr[j], 27, 26, "dither pattern");
683bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 25, "linear gamma blend");
684bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 24, "debug dither");
685bf215546Sopenharmony_ci      BITS(stream, ptr[j], 23, 20, "dstorg x");
686bf215546Sopenharmony_ci      BITS(stream, ptr[j], 19, 16, "dstorg y");
687bf215546Sopenharmony_ci      MBZ(ptr[j], 15, 15);
688bf215546Sopenharmony_ci      BITS(stream, ptr[j], 14, 12, "422 write select");
689bf215546Sopenharmony_ci      BITS(stream, ptr[j], 11, 8, "cbuf format");
690bf215546Sopenharmony_ci      BITS(stream, ptr[j], 3, 2, "zbuf format");
691bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 1, "vert line stride");
692bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 1, "vert line stride offset");
693bf215546Sopenharmony_ci      j++;
694bf215546Sopenharmony_ci   }
695bf215546Sopenharmony_ci
696bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
697bf215546Sopenharmony_ci   assert(j == len);
698bf215546Sopenharmony_ci   return true;
699bf215546Sopenharmony_ci}
700bf215546Sopenharmony_ci
701bf215546Sopenharmony_cistatic bool
702bf215546Sopenharmony_cidebug_buf_info(struct debug_stream *stream, const char *name, unsigned len)
703bf215546Sopenharmony_ci{
704bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
705bf215546Sopenharmony_ci   int j = 0;
706bf215546Sopenharmony_ci
707bf215546Sopenharmony_ci   mesa_logi("%s (%d dwords):", name, len);
708bf215546Sopenharmony_ci   mesa_logi("\t0x%08x", ptr[j++]);
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_ci   {
711bf215546Sopenharmony_ci      mesa_logi("\t0x%08x", ptr[j]);
712bf215546Sopenharmony_ci      BITS(stream, ptr[j], 28, 28, "aux buffer id");
713bf215546Sopenharmony_ci      BITS(stream, ptr[j], 27, 24, "buffer id (7=depth, 3=back)");
714bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 23, "use fence regs");
715bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 22, "tiled surface");
716bf215546Sopenharmony_ci      FLAG(stream, ptr[j], 21, "tile walk ymajor");
717bf215546Sopenharmony_ci      MBZ(ptr[j], 20, 14);
718bf215546Sopenharmony_ci      BITS(stream, ptr[j], 13, 2, "dword pitch");
719bf215546Sopenharmony_ci      MBZ(ptr[j], 2, 0);
720bf215546Sopenharmony_ci      j++;
721bf215546Sopenharmony_ci   }
722bf215546Sopenharmony_ci
723bf215546Sopenharmony_ci   mesa_logi("\t0x%08x -- buffer base address", ptr[j++]);
724bf215546Sopenharmony_ci
725bf215546Sopenharmony_ci   stream->offset += len * sizeof(unsigned);
726bf215546Sopenharmony_ci   assert(j == len);
727bf215546Sopenharmony_ci   return true;
728bf215546Sopenharmony_ci}
729bf215546Sopenharmony_ci
730bf215546Sopenharmony_cistatic bool
731bf215546Sopenharmony_cii915_debug_packet(struct debug_stream *stream)
732bf215546Sopenharmony_ci{
733bf215546Sopenharmony_ci   unsigned *ptr = (unsigned *)(stream->ptr + stream->offset);
734bf215546Sopenharmony_ci   unsigned cmd = *ptr;
735bf215546Sopenharmony_ci
736bf215546Sopenharmony_ci   switch (((cmd >> 29) & 0x7)) {
737bf215546Sopenharmony_ci   case 0x0:
738bf215546Sopenharmony_ci      switch ((cmd >> 23) & 0x3f) {
739bf215546Sopenharmony_ci      case 0x0:
740bf215546Sopenharmony_ci         return debug(stream, "MI_NOOP", 1);
741bf215546Sopenharmony_ci      case 0x3:
742bf215546Sopenharmony_ci         return debug(stream, "MI_WAIT_FOR_EVENT", 1);
743bf215546Sopenharmony_ci      case 0x4:
744bf215546Sopenharmony_ci         return debug(stream, "MI_FLUSH", 1);
745bf215546Sopenharmony_ci      case 0xA:
746bf215546Sopenharmony_ci         debug(stream, "MI_BATCH_BUFFER_END", 1);
747bf215546Sopenharmony_ci         return false;
748bf215546Sopenharmony_ci      case 0x22:
749bf215546Sopenharmony_ci         return debug(stream, "MI_LOAD_REGISTER_IMM", 3);
750bf215546Sopenharmony_ci      case 0x31:
751bf215546Sopenharmony_ci         return debug_chain(stream, "MI_BATCH_BUFFER_START", 2);
752bf215546Sopenharmony_ci      default:
753bf215546Sopenharmony_ci         (void)debug(stream, "UNKNOWN 0x0 case!", 1);
754bf215546Sopenharmony_ci         assert(0);
755bf215546Sopenharmony_ci         break;
756bf215546Sopenharmony_ci      }
757bf215546Sopenharmony_ci      break;
758bf215546Sopenharmony_ci   case 0x1:
759bf215546Sopenharmony_ci      (void)debug(stream, "UNKNOWN 0x1 case!", 1);
760bf215546Sopenharmony_ci      assert(0);
761bf215546Sopenharmony_ci      break;
762bf215546Sopenharmony_ci   case 0x2:
763bf215546Sopenharmony_ci      switch ((cmd >> 22) & 0xff) {
764bf215546Sopenharmony_ci      case 0x50:
765bf215546Sopenharmony_ci         return debug_color_blit(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2);
766bf215546Sopenharmony_ci      case 0x53:
767bf215546Sopenharmony_ci         return debug_copy_blit(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2);
768bf215546Sopenharmony_ci      default:
769bf215546Sopenharmony_ci         return debug(stream, "blit command", (cmd & 0xff) + 2);
770bf215546Sopenharmony_ci      }
771bf215546Sopenharmony_ci      break;
772bf215546Sopenharmony_ci   case 0x3:
773bf215546Sopenharmony_ci      switch ((cmd >> 24) & 0x1f) {
774bf215546Sopenharmony_ci      case 0x6:
775bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_ANTI_ALIASING", 1);
776bf215546Sopenharmony_ci      case 0x7:
777bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1);
778bf215546Sopenharmony_ci      case 0x8:
779bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 1);
780bf215546Sopenharmony_ci      case 0x9:
781bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1);
782bf215546Sopenharmony_ci      case 0xb:
783bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1);
784bf215546Sopenharmony_ci      case 0xc:
785bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_MODES5", 1);
786bf215546Sopenharmony_ci      case 0xd:
787bf215546Sopenharmony_ci         return debug_modes4(stream, "3DSTATE_MODES4", 1);
788bf215546Sopenharmony_ci      case 0x15:
789bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_FOG_COLOR", 1);
790bf215546Sopenharmony_ci      case 0x16:
791bf215546Sopenharmony_ci         return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1);
792bf215546Sopenharmony_ci      case 0x1c:
793bf215546Sopenharmony_ci         /* 3DState16NP */
794bf215546Sopenharmony_ci         switch ((cmd >> 19) & 0x1f) {
795bf215546Sopenharmony_ci         case 0x10:
796bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1);
797bf215546Sopenharmony_ci         case 0x11:
798bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1);
799bf215546Sopenharmony_ci         default:
800bf215546Sopenharmony_ci            (void)debug(stream, "UNKNOWN 0x1c case!", 1);
801bf215546Sopenharmony_ci            assert(0);
802bf215546Sopenharmony_ci            break;
803bf215546Sopenharmony_ci         }
804bf215546Sopenharmony_ci         break;
805bf215546Sopenharmony_ci      case 0x1d:
806bf215546Sopenharmony_ci         /* 3DStateMW */
807bf215546Sopenharmony_ci         switch ((cmd >> 16) & 0xff) {
808bf215546Sopenharmony_ci         case 0x0:
809bf215546Sopenharmony_ci            return debug_map_state(stream, "3DSTATE_MAP_STATE",
810bf215546Sopenharmony_ci                                   (cmd & 0x1f) + 2);
811bf215546Sopenharmony_ci         case 0x1:
812bf215546Sopenharmony_ci            return debug_sampler_state(stream, "3DSTATE_SAMPLER_STATE",
813bf215546Sopenharmony_ci                                       (cmd & 0x1f) + 2);
814bf215546Sopenharmony_ci         case 0x4:
815bf215546Sopenharmony_ci            return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE",
816bf215546Sopenharmony_ci                                        (cmd & 0xf) + 2);
817bf215546Sopenharmony_ci         case 0x5:
818bf215546Sopenharmony_ci            return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM",
819bf215546Sopenharmony_ci                                 (cmd & 0x1ff) + 2);
820bf215546Sopenharmony_ci         case 0x6:
821bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS",
822bf215546Sopenharmony_ci                         (cmd & 0xff) + 2);
823bf215546Sopenharmony_ci         case 0x7:
824bf215546Sopenharmony_ci            return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT",
825bf215546Sopenharmony_ci                                       (cmd & 0xff) + 2);
826bf215546Sopenharmony_ci         case 0x80:
827bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DRAWING_RECTANGLE",
828bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
829bf215546Sopenharmony_ci         case 0x81:
830bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_SCISSOR_RECTANGLE",
831bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
832bf215546Sopenharmony_ci         case 0x83:
833bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2);
834bf215546Sopenharmony_ci         case 0x85:
835bf215546Sopenharmony_ci            return debug_dest_vars(stream, "3DSTATE_DEST_BUFFER_VARS",
836bf215546Sopenharmony_ci                                   (cmd & 0xffff) + 2);
837bf215546Sopenharmony_ci         case 0x88:
838bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR",
839bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
840bf215546Sopenharmony_ci         case 0x89:
841bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2);
842bf215546Sopenharmony_ci         case 0x8e:
843bf215546Sopenharmony_ci            return debug_buf_info(stream, "3DSTATE_BUFFER_INFO",
844bf215546Sopenharmony_ci                                  (cmd & 0xffff) + 2);
845bf215546Sopenharmony_ci         case 0x97:
846bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE",
847bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
848bf215546Sopenharmony_ci         case 0x98:
849bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2);
850bf215546Sopenharmony_ci         case 0x99:
851bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2);
852bf215546Sopenharmony_ci         case 0x9a:
853bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_DEFAULT_SPECULAR",
854bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
855bf215546Sopenharmony_ci         case 0x9c:
856bf215546Sopenharmony_ci            return debug(stream, "3DSTATE_CLEAR_PARAMETERS",
857bf215546Sopenharmony_ci                         (cmd & 0xffff) + 2);
858bf215546Sopenharmony_ci         default:
859bf215546Sopenharmony_ci            assert(0);
860bf215546Sopenharmony_ci            return 0;
861bf215546Sopenharmony_ci         }
862bf215546Sopenharmony_ci         break;
863bf215546Sopenharmony_ci      case 0x1e:
864bf215546Sopenharmony_ci         if (cmd & (1 << 23))
865bf215546Sopenharmony_ci            return debug(stream, "???", (cmd & 0xffff) + 1);
866bf215546Sopenharmony_ci         else
867bf215546Sopenharmony_ci            return debug(stream, "", 1);
868bf215546Sopenharmony_ci         break;
869bf215546Sopenharmony_ci      case 0x1f:
870bf215546Sopenharmony_ci         if ((cmd & (1 << 23)) == 0)
871bf215546Sopenharmony_ci            return debug_prim(stream, "3DPRIM (inline)", 1,
872bf215546Sopenharmony_ci                              (cmd & 0x1ffff) + 2);
873bf215546Sopenharmony_ci         else if (cmd & (1 << 17)) {
874bf215546Sopenharmony_ci            if ((cmd & 0xffff) == 0)
875bf215546Sopenharmony_ci               return debug_variable_length_prim(stream);
876bf215546Sopenharmony_ci            else
877bf215546Sopenharmony_ci               return debug_prim(stream, "3DPRIM (indexed)", 0,
878bf215546Sopenharmony_ci                                 (((cmd & 0xffff) + 1) / 2) + 1);
879bf215546Sopenharmony_ci         } else
880bf215546Sopenharmony_ci            return debug_prim(stream, "3DPRIM  (indirect sequential)", 0, 2);
881bf215546Sopenharmony_ci         break;
882bf215546Sopenharmony_ci      default:
883bf215546Sopenharmony_ci         return debug(stream, "", 0);
884bf215546Sopenharmony_ci      }
885bf215546Sopenharmony_ci      break;
886bf215546Sopenharmony_ci   default:
887bf215546Sopenharmony_ci      assert(0);
888bf215546Sopenharmony_ci      return 0;
889bf215546Sopenharmony_ci   }
890bf215546Sopenharmony_ci
891bf215546Sopenharmony_ci   assert(0);
892bf215546Sopenharmony_ci   return 0;
893bf215546Sopenharmony_ci}
894bf215546Sopenharmony_ci
895bf215546Sopenharmony_civoid
896bf215546Sopenharmony_cii915_dump_batchbuffer(struct i915_winsys_batchbuffer *batch)
897bf215546Sopenharmony_ci{
898bf215546Sopenharmony_ci   struct debug_stream stream;
899bf215546Sopenharmony_ci   unsigned *start = (unsigned *)batch->map;
900bf215546Sopenharmony_ci   unsigned *end = (unsigned *)batch->ptr;
901bf215546Sopenharmony_ci   unsigned long bytes = (unsigned long)(end - start) * 4;
902bf215546Sopenharmony_ci   bool done = false;
903bf215546Sopenharmony_ci
904bf215546Sopenharmony_ci   stream.offset = 0;
905bf215546Sopenharmony_ci   stream.ptr = (char *)start;
906bf215546Sopenharmony_ci   stream.print_addresses = 0;
907bf215546Sopenharmony_ci
908bf215546Sopenharmony_ci   if (!start || !end) {
909bf215546Sopenharmony_ci      mesa_logi("BATCH: ???");
910bf215546Sopenharmony_ci      return;
911bf215546Sopenharmony_ci   }
912bf215546Sopenharmony_ci
913bf215546Sopenharmony_ci   mesa_logi("BATCH: (%d)", (int)bytes / 4);
914bf215546Sopenharmony_ci
915bf215546Sopenharmony_ci   while (!done && stream.offset < bytes) {
916bf215546Sopenharmony_ci      if (!i915_debug_packet(&stream))
917bf215546Sopenharmony_ci         break;
918bf215546Sopenharmony_ci
919bf215546Sopenharmony_ci      assert(stream.offset <= bytes);
920bf215546Sopenharmony_ci   }
921bf215546Sopenharmony_ci
922bf215546Sopenharmony_ci   mesa_logi("END-BATCH");
923bf215546Sopenharmony_ci}
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ci/***********************************************************************
926bf215546Sopenharmony_ci * Dirty state atom dumping
927bf215546Sopenharmony_ci */
928bf215546Sopenharmony_ci
929bf215546Sopenharmony_civoid
930bf215546Sopenharmony_cii915_dump_dirty(struct i915_context *i915, const char *func)
931bf215546Sopenharmony_ci{
932bf215546Sopenharmony_ci   struct {
933bf215546Sopenharmony_ci      unsigned dirty;
934bf215546Sopenharmony_ci      const char *name;
935bf215546Sopenharmony_ci   } l[] = {
936bf215546Sopenharmony_ci      {I915_NEW_VIEWPORT, "viewport"},
937bf215546Sopenharmony_ci      {I915_NEW_RASTERIZER, "rasterizer"},
938bf215546Sopenharmony_ci      {I915_NEW_FS, "fs"},
939bf215546Sopenharmony_ci      {I915_NEW_BLEND, "blend"},
940bf215546Sopenharmony_ci      {I915_NEW_CLIP, "clip"},
941bf215546Sopenharmony_ci      {I915_NEW_SCISSOR, "scissor"},
942bf215546Sopenharmony_ci      {I915_NEW_STIPPLE, "stipple"},
943bf215546Sopenharmony_ci      {I915_NEW_FRAMEBUFFER, "framebuffer"},
944bf215546Sopenharmony_ci      {I915_NEW_ALPHA_TEST, "alpha_test"},
945bf215546Sopenharmony_ci      {I915_NEW_DEPTH_STENCIL, "depth_stencil"},
946bf215546Sopenharmony_ci      {I915_NEW_SAMPLER, "sampler"},
947bf215546Sopenharmony_ci      {I915_NEW_SAMPLER_VIEW, "sampler_view"},
948bf215546Sopenharmony_ci      {I915_NEW_VS_CONSTANTS, "vs_const"},
949bf215546Sopenharmony_ci      {I915_NEW_FS_CONSTANTS, "fs_const"},
950bf215546Sopenharmony_ci      {I915_NEW_VBO, "vbo"},
951bf215546Sopenharmony_ci      {I915_NEW_VS, "vs"},
952bf215546Sopenharmony_ci      {0, NULL},
953bf215546Sopenharmony_ci   };
954bf215546Sopenharmony_ci   int i;
955bf215546Sopenharmony_ci
956bf215546Sopenharmony_ci   mesa_logi("%s: ", func);
957bf215546Sopenharmony_ci   for (i = 0; l[i].name; i++)
958bf215546Sopenharmony_ci      if (i915->dirty & l[i].dirty)
959bf215546Sopenharmony_ci         mesa_logi("%s ", l[i].name);
960bf215546Sopenharmony_ci   mesa_logi("%s", "");
961bf215546Sopenharmony_ci}
962bf215546Sopenharmony_ci
963bf215546Sopenharmony_civoid
964bf215546Sopenharmony_cii915_dump_hardware_dirty(struct i915_context *i915, const char *func)
965bf215546Sopenharmony_ci{
966bf215546Sopenharmony_ci   struct {
967bf215546Sopenharmony_ci      unsigned dirty;
968bf215546Sopenharmony_ci      const char *name;
969bf215546Sopenharmony_ci   } l[] = {
970bf215546Sopenharmony_ci      {I915_HW_STATIC, "static"},
971bf215546Sopenharmony_ci      {I915_HW_DYNAMIC, "dynamic"},
972bf215546Sopenharmony_ci      {I915_HW_SAMPLER, "sampler"},
973bf215546Sopenharmony_ci      {I915_HW_MAP, "map"},
974bf215546Sopenharmony_ci      {I915_HW_PROGRAM, "program"},
975bf215546Sopenharmony_ci      {I915_HW_CONSTANTS, "constants"},
976bf215546Sopenharmony_ci      {I915_HW_IMMEDIATE, "immediate"},
977bf215546Sopenharmony_ci      {I915_HW_INVARIANT, "invariant"},
978bf215546Sopenharmony_ci      {0, NULL},
979bf215546Sopenharmony_ci   };
980bf215546Sopenharmony_ci   int i;
981bf215546Sopenharmony_ci
982bf215546Sopenharmony_ci   mesa_logi("%s: ", func);
983bf215546Sopenharmony_ci   for (i = 0; l[i].name; i++)
984bf215546Sopenharmony_ci      if (i915->hardware_dirty & l[i].dirty)
985bf215546Sopenharmony_ci         mesa_logi("%s ", l[i].name);
986bf215546Sopenharmony_ci   mesa_logi("%s", "");
987bf215546Sopenharmony_ci}
988