aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/pipe/i915simple/i915_debug.c
blob: 8050eb0bf5d7f32638c9068f2a4d8dd7c01e3612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/**************************************************************************
 * 
 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

#include "imports.h"

#include "i915_reg.h"
#include "i915_context.h"
#include "i915_winsys.h"
#include "i915_debug.h"

#define PRINTF( stream, ... ) (stream)->winsys->printf( (stream)->winsys, __VA_ARGS__ )


static GLboolean debug( struct debug_stream *stream, const char *name, GLuint len )
{
   GLuint i;
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   
   if (len == 0) {
      PRINTF( stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0] );
      assert(0);
      return GL_FALSE;
   }

   if (stream->print_addresses)
      PRINTF(stream, "%08x:  ", stream->offset);


   PRINTF(stream, "%s (%d dwords):\n", name, len);
   for (i = 0; i < len; i++)
      PRINTF(stream, "\t\t0x%08x\n",  ptr[i]);   
   PRINTF(stream, "\n");

   stream->offset += len * sizeof(GLuint);
   
   return GL_TRUE;
}


static const char *get_prim_name( GLuint val )
{
   switch (val & PRIM3D_MASK) {
   case PRIM3D_TRILIST: return "TRILIST"; break;
   case PRIM3D_TRISTRIP: return "TRISTRIP"; break;
   case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE"; break;
   case PRIM3D_TRIFAN: return "TRIFAN"; break;
   case PRIM3D_POLY: return "POLY"; break;
   case PRIM3D_LINELIST: return "LINELIST"; break;
   case PRIM3D_LINESTRIP: return "LINESTRIP"; break;
   case PRIM3D_RECTLIST: return "RECTLIST"; break;
   case PRIM3D_POINTLIST: return "POINTLIST"; break;
   case PRIM3D_DIB: return "DIB"; break;
   case PRIM3D_CLEAR_RECT: return "CLEAR_RECT"; break;
   case PRIM3D_ZONE_INIT: return "ZONE_INIT"; break;
   default: return "????"; break;
   }
}

static GLboolean debug_prim( struct debug_stream *stream, const char *name, 
			     GLboolean dump_floats,
			     GLuint len )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   const char *prim = get_prim_name( ptr[0] );
   GLuint i;
   


   PRINTF(stream, "%s %s (%d dwords):\n", name, prim, len);
   PRINTF(stream, "\t\t0x%08x\n",  ptr[0]);   
   for (i = 1; i < len; i++) {
      if (dump_floats)
	 PRINTF(stream, "\t\t0x%08x // %f\n",  ptr[i], *(GLfloat *)&ptr[i]);   
      else
	 PRINTF(stream, "\t\t0x%08x\n",  ptr[i]);   
   }

      
   PRINTF(stream, "\n");

   stream->offset += len * sizeof(GLuint);
   
   return GL_TRUE;
}
   



static GLboolean debug_program( struct debug_stream *stream, const char *name, GLuint len )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);

   if (len == 0) {
      PRINTF(stream, "Error - zero length packet (0x%08x)\n", stream->ptr[0]);
      assert(0);
      return GL_FALSE;
   }

   if (stream->print_addresses)
      PRINTF(stream, "%08x:  ", stream->offset);

   PRINTF(stream, "%s (%d dwords):\n", name, len);
   i915_disassemble_program( stream, ptr, len );

   stream->offset += len * sizeof(GLuint);
   return GL_TRUE;
}


static GLboolean debug_chain( struct debug_stream *stream, const char *name, GLuint len )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   GLuint old_offset = stream->offset + len * sizeof(GLuint);
   GLuint i;

   PRINTF(stream, "%s (%d dwords):\n", name, len);
   for (i = 0; i < len; i++)
      PRINTF(stream, "\t\t0x%08x\n",  ptr[i]);

   stream->offset = ptr[1] & ~0x3;
   
   if (stream->offset < old_offset)
      PRINTF(stream, "\n... skipping backwards from 0x%x --> 0x%x ...\n\n", 
		   old_offset, stream->offset );
   else
      PRINTF(stream, "\n... skipping from 0x%x --> 0x%x ...\n\n", 
		   old_offset, stream->offset );


   return GL_TRUE;
}


static GLboolean debug_variable_length_prim( struct debug_stream *stream )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   const char *prim = get_prim_name( ptr[0] );
   GLuint i, len;

   GLushort *idx = (GLushort *)(ptr+1);
   for (i = 0; idx[i] != 0xffff; i++)
      ;

   len = 1+(i+2)/2;

   PRINTF(stream, "3DPRIM, %s variable length %d indicies (%d dwords):\n", prim, i, len);
   for (i = 0; i < len; i++)
      PRINTF(stream, "\t\t0x%08x\n",  ptr[i]);
   PRINTF(stream, "\n");

   stream->offset += len * sizeof(GLuint);
   return GL_TRUE;
}


static GLboolean debug_load_immediate( struct debug_stream *stream,
				       const char *name,
				       GLuint len )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   GLuint bits = (ptr[0] >> 4) & 0xff;
   GLuint i, j = 0;
   
   PRINTF(stream, "%s (%d dwords, flags: %x):\n", name, len, bits);
   PRINTF(stream, "\t\t0x%08x\n",  ptr[j++]);

   for (i = 0; i < 8; i++) {
      if (bits & (1<<i)) {
	 PRINTF(stream, "\t  LIS%d: 0x%08x\n", i, ptr[j++]);
      }
   }

   PRINTF(stream, "\n");

   assert(j == len);

   stream->offset += len * sizeof(GLuint);
   
   return GL_TRUE;
}
 


static GLboolean debug_load_indirect( struct debug_stream *stream,
				      const char *name,
				      GLuint len )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   GLuint bits = (ptr[0] >> 8) & 0x3f;
   GLuint i, j = 0;
   
   PRINTF(stream, "%s (%d dwords):\n", name, len);
   PRINTF(stream, "\t\t0x%08x\n",  ptr[j++]);

   for (i = 0; i < 6; i++) {
      if (bits & (1<<i)) {
	 switch (1<<(8+i)) {
	 case LI0_STATE_STATIC_INDIRECT:
	    PRINTF(stream, "        STATIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    PRINTF(stream, "                0x%08x\n", ptr[j++]);
	    break;
	 case LI0_STATE_DYNAMIC_INDIRECT:
	    PRINTF(stream, "       DYNAMIC: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    break;
	 case LI0_STATE_SAMPLER:
	    PRINTF(stream, "       SAMPLER: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    PRINTF(stream, "                0x%08x\n", ptr[j++]);
	    break;
	 case LI0_STATE_MAP:
	    PRINTF(stream, "           MAP: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    PRINTF(stream, "                0x%08x\n", ptr[j++]);
	    break;
	 case LI0_STATE_PROGRAM:
	    PRINTF(stream, "       PROGRAM: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    PRINTF(stream, "                0x%08x\n", ptr[j++]);
	    break;
	 case LI0_STATE_CONSTANTS:
	    PRINTF(stream, "     CONSTANTS: 0x%08x | %x\n", ptr[j]&~3, ptr[j]&3); j++;
	    PRINTF(stream, "                0x%08x\n", ptr[j++]);
	    break;
	 default:
	    assert(0);
	    break;
	 }
      }
   }

   if (bits == 0) {
      PRINTF(stream, "\t  DUMMY: 0x%08x\n", ptr[j++]);
   }

   PRINTF(stream, "\n");


   assert(j == len);

   stream->offset += len * sizeof(GLuint);
   
   return GL_TRUE;
}
 		   

static GLboolean i915_debug_packet( struct debug_stream *stream )
{
   GLuint *ptr = (GLuint *)(stream->ptr + stream->offset);
   GLuint cmd = *ptr;
   
   switch (((cmd >> 29) & 0x7)) {
   case 0x0:
      switch ((cmd >> 23) & 0x3f) {
      case 0x0:
	 return debug(stream, "MI_NOOP", 1);
      case 0x3:
	 return debug(stream, "MI_WAIT_FOR_EVENT", 1);
      case 0x4:
	 return debug(stream, "MI_FLUSH", 1);
      case 0xA:
	 debug(stream, "MI_BATCH_BUFFER_END", 1);
	 return GL_FALSE;
      case 0x22:
	 return debug(stream, "MI_LOAD_REGISTER_IMM", 3);
      case 0x31:
	 return debug_chain(stream, "MI_BATCH_BUFFER_START", 2);
      default:
	 break;
      }
      break;
   case 0x1:
      break;
   case 0x2:
      switch ((cmd >> 22) & 0xff) {	 
      case 0x50:
	 return debug(stream, "XY_COLOR_BLT", (cmd & 0xff) + 2);
      case 0x53:
	 return debug(stream, "XY_SRC_COPY_BLT", (cmd & 0xff) + 2);
      default:
	 return debug(stream, "blit command", (cmd & 0xff) + 2);
      }
      break;
   case 0x3:
      switch ((cmd >> 24) & 0x1f) {	 
      case 0x6:
	 return debug(stream, "3DSTATE_ANTI_ALIASING", 1);
      case 0x7:
	 return debug(stream, "3DSTATE_RASTERIZATION_RULES", 1);
      case 0x8:
	 return debug(stream, "3DSTATE_BACKFACE_STENCIL_OPS", 2);
      case 0x9:
	 return debug(stream, "3DSTATE_BACKFACE_STENCIL_MASKS", 1);
      case 0xb:
	 return debug(stream, "3DSTATE_INDEPENDENT_ALPHA_BLEND", 1);
      case 0xc:
	 return debug(stream, "3DSTATE_MODES5", 1);	 
      case 0xd:
	 return debug(stream, "3DSTATE_MODES4", 1);
      case 0x15:
	 return debug(stream, "3DSTATE_FOG_COLOR", 1);
      case 0x16:
	 return debug(stream, "3DSTATE_COORD_SET_BINDINGS", 1);
      case 0x1c:
	 /* 3DState16NP */
	 switch((cmd >> 19) & 0x1f) {
	 case 0x10:
	    return debug(stream, "3DSTATE_SCISSOR_ENABLE", 1);
	 case 0x11:
	    return debug(stream, "3DSTATE_DEPTH_SUBRECTANGLE_DISABLE", 1);
	 default:
	    break;
	 }
	 break;
      case 0x1d:
	 /* 3DStateMW */
	 switch ((cmd >> 16) & 0xff) {
	 case 0x0:
	    return debug(stream, "3DSTATE_MAP_STATE", (cmd & 0x1f) + 2);
	 case 0x1:
	    return debug(stream, "3DSTATE_SAMPLER_STATE", (cmd & 0x1f) + 2);
	 case 0x4:
	    return debug_load_immediate(stream, "3DSTATE_LOAD_STATE_IMMEDIATE", (cmd & 0xf) + 2);
	 case 0x5:
	    return debug_program(stream, "3DSTATE_PIXEL_SHADER_PROGRAM", (cmd & 0x1ff) + 2);
	 case 0x6:
	    return debug(stream, "3DSTATE_PIXEL_SHADER_CONSTANTS", (cmd & 0xff) + 2);
	 case 0x7:
	    return debug_load_indirect(stream, "3DSTATE_LOAD_INDIRECT", (cmd & 0xff) + 2);
	 case 0x80:
	    return debug(stream, "3DSTATE_DRAWING_RECTANGLE", (cmd & 0xffff) + 2);
	 case 0x81:
	    return debug(stream, "3DSTATE_SCISSOR_RECTANGLE", (cmd & 0xffff) + 2);
	 case 0x83:
	    return debug(stream, "3DSTATE_SPAN_STIPPLE", (cmd & 0xffff) + 2);
	 case 0x85:
	    return debug(stream, "3DSTATE_DEST_BUFFER_VARS", (cmd & 0xffff) + 2);
	 case 0x88:
	    return debug(stream, "3DSTATE_CONSTANT_BLEND_COLOR", (cmd & 0xffff) + 2);
	 case 0x89:
	    return debug(stream, "3DSTATE_FOG_MODE", (cmd & 0xffff) + 2);
	 case 0x8e:
	    return debug(stream, "3DSTATE_BUFFER_INFO", (cmd & 0xffff) + 2);
	 case 0x97:
	    return debug(stream, "3DSTATE_DEPTH_OFFSET_SCALE", (cmd & 0xffff) + 2);
	 case 0x98:
	    return debug(stream, "3DSTATE_DEFAULT_Z", (cmd & 0xffff) + 2);
	 case 0x99:
	    return debug(stream, "3DSTATE_DEFAULT_DIFFUSE", (cmd & 0xffff) + 2);
	 case 0x9a:
	    return debug(stream, "3DSTATE_DEFAULT_SPECULAR", (cmd & 0xffff) + 2);
	 case 0x9c:
	    return debug(stream, "3DSTATE_CLEAR_PARAMETERS", (cmd & 0xffff) + 2);
	 default:
	    assert(0);
	    return 0;
	 }
	 break;
      case 0x1e:
	 if (cmd & (1 << 23))
	    return debug(stream, "???", (cmd & 0xffff) + 1);
	 else
	    return debug(stream, "", 1);
	 break;
      case 0x1f:
	 if ((cmd & (1 << 23)) == 0)	
	    return debug_prim(stream, "3DPRIM (inline)", 1, (cmd & 0x1ffff) + 2);
	 else if (cmd & (1 << 17)) 
	 {
	    if ((cmd & 0xffff) == 0)
	       return debug_variable_length_prim(stream);
	    else
	       return debug_prim(stream, "3DPRIM (indexed)", 0, (((cmd & 0xffff) + 1) / 2) + 1);
	 }
	 else
	    return debug_prim(stream, "3DPRIM  (indirect sequential)", 0, 2); 
	 break;
      default:
	 return debug(stream, "", 0);
      }
   default:
      assert(0);
      return 0;
   }

   assert(0);
   return 0;
}



void
i915_dump_batchbuffer( struct i915_context *i915,
		       GLuint *start,
		       GLuint *end )
{
   struct debug_stream stream;
   GLuint bytes = (end - start) * 4;
   GLboolean done = GL_FALSE;

   fprintf(stderr, "\n\nBATCH: (%d)\n", bytes / 4);

   stream.offset = 0;
   stream.ptr = (char *)start;
   stream.print_addresses = 0;
   stream.winsys = i915->pipe.winsys;

   while (!done &&
	  stream.offset < bytes &&
	  stream.offset >= 0)
   {
      if (!i915_debug_packet( &stream ))
	 break;

      assert(stream.offset <= bytes &&
	     stream.offset >= 0);
   }

   fprintf(stderr, "END-BATCH\n\n\n");
}