1 /**************************************************************************
3 Copyright 2001 2d3d Inc., Delray Beach, FL
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_debug.c,v 1.3 2002/12/10 01:26:53 dawes Exp $ */
32 * Jeff Hartmann <jhartmann@2d3d.com>
43 #include "i830_screen.h"
46 #include "i830_context.h"
47 #include "i830_state.h"
50 #include "i830_tris.h"
51 #include "i830_ioctl.h"
52 #include "i830_debug.h"
54 #include "swrast/swrast.h"
55 #include "array_cache/acache.h"
57 #include "swrast_setup/swrast_setup.h"
59 #include "tnl/t_pipeline.h"
62 #define TINY_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
63 VRTX_TEX_COORD_COUNT(0) | \
67 #define NOTEX_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
68 VRTX_TEX_COORD_COUNT(0) | \
73 #define TEX0_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
74 VRTX_TEX_COORD_COUNT(1) | \
79 #define TEX1_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
80 VRTX_TEX_COORD_COUNT(2) | \
85 #define PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
86 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_3D) | \
87 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_3D) | \
88 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_3D) | \
89 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_3D))
91 #define NON_PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
92 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_2D) | \
93 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_2D) | \
94 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_2D) | \
95 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_2D))
97 void i830DumpContextState( i830ContextPtr imesa
)
99 GLuint
*Context
= imesa
->Setup
;
101 fprintf(stderr
, "%s\n", __FUNCTION__
);
102 fprintf(stderr
, "STATE1 : 0x%08x\n", Context
[I830_CTXREG_STATE1
]);
103 fprintf(stderr
, "STATE2 : 0x%08x\n", Context
[I830_CTXREG_STATE2
]);
104 fprintf(stderr
, "STATE3 : 0x%08x\n", Context
[I830_CTXREG_STATE3
]);
105 fprintf(stderr
, "STATE4 : 0x%08x\n", Context
[I830_CTXREG_STATE4
]);
106 fprintf(stderr
, "STATE5 : 0x%08x\n", Context
[I830_CTXREG_STATE5
]);
107 fprintf(stderr
, "IALPHAB : 0x%08x\n", Context
[I830_CTXREG_IALPHAB
]);
108 fprintf(stderr
, "STENCILTST : 0x%08x\n", Context
[I830_CTXREG_STENCILTST
]);
109 fprintf(stderr
, "ENABLES_1 : 0x%08x\n", Context
[I830_CTXREG_ENABLES_1
]);
110 fprintf(stderr
, "ENABLES_2 : 0x%08x\n", Context
[I830_CTXREG_ENABLES_2
]);
111 fprintf(stderr
, "AA : 0x%08x\n", Context
[I830_CTXREG_AA
]);
112 fprintf(stderr
, "FOGCOLOR : 0x%08x\n", Context
[I830_CTXREG_FOGCOLOR
]);
113 fprintf(stderr
, "BCOLOR0 : 0x%08x\n", Context
[I830_CTXREG_BLENDCOLR0
]);
114 fprintf(stderr
, "BCOLOR : 0x%08x\n", Context
[I830_CTXREG_BLENDCOLR
]);
115 fprintf(stderr
, "VF : 0x%08x\n", Context
[I830_CTXREG_VF
]);
116 fprintf(stderr
, "VF2 : 0x%08x\n", Context
[I830_CTXREG_VF2
]);
117 fprintf(stderr
, "MCSB0 : 0x%08x\n", Context
[I830_CTXREG_MCSB0
]);
118 fprintf(stderr
, "MCSB1 : 0x%08x\n", Context
[I830_CTXREG_MCSB1
]);
121 void i830DumpBufferState( i830ContextPtr imesa
)
123 GLuint
*Buffer
= imesa
->BufferSetup
;
125 fprintf(stderr
, "%s\n", __FUNCTION__
);
126 fprintf(stderr
, "CBUFADDR : 0x%08x\n", Buffer
[I830_DESTREG_CBUFADDR
]);
127 fprintf(stderr
, "DBUFADDR : 0x%08x\n", Buffer
[I830_DESTREG_DBUFADDR
]);
128 fprintf(stderr
, "DV0 : 0x%08x\n", Buffer
[I830_DESTREG_DV0
]);
129 fprintf(stderr
, "DV1 : 0x%08x\n", Buffer
[I830_DESTREG_DV1
]);
130 fprintf(stderr
, "SENABLE : 0x%08x\n", Buffer
[I830_DESTREG_SENABLE
]);
131 fprintf(stderr
, "SR0 : 0x%08x\n", Buffer
[I830_DESTREG_SR0
]);
132 fprintf(stderr
, "SR1 : 0x%08x\n", Buffer
[I830_DESTREG_SR1
]);
133 fprintf(stderr
, "SR2 : 0x%08x\n", Buffer
[I830_DESTREG_SR2
]);
134 fprintf(stderr
, "DR0 : 0x%08x\n", Buffer
[I830_DESTREG_DR0
]);
135 fprintf(stderr
, "DR1 : 0x%08x\n", Buffer
[I830_DESTREG_DR1
]);
136 fprintf(stderr
, "DR2 : 0x%08x\n", Buffer
[I830_DESTREG_DR2
]);
137 fprintf(stderr
, "DR3 : 0x%08x\n", Buffer
[I830_DESTREG_DR3
]);
138 fprintf(stderr
, "DR4 : 0x%08x\n", Buffer
[I830_DESTREG_DR4
]);
141 void i830DumpStippleState( i830ContextPtr imesa
)
143 GLuint
*Buffer
= imesa
->BufferSetup
;
145 fprintf(stderr
, "%s\n", __FUNCTION__
);
146 fprintf(stderr
, "ST1 : 0x%08x\n", Buffer
[I830_STPREG_ST1
]);
149 void i830DumpTextureState( i830ContextPtr imesa
, int unit
)
151 i830TextureObjectPtr t
= imesa
->CurrentTexObj
[unit
];
154 fprintf(stderr
, "%s : unit %d\n", __FUNCTION__
, unit
);
155 fprintf(stderr
, "TM0LI : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0LI
]);
156 fprintf(stderr
, "TM0S0 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S0
]);
157 fprintf(stderr
, "TM0S1 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S1
]);
158 fprintf(stderr
, "TM0S2 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S2
]);
159 fprintf(stderr
, "TM0S3 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S3
]);
160 fprintf(stderr
, "TM0S4 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S4
]);
161 fprintf(stderr
, "NOP0 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP0
]);
162 fprintf(stderr
, "NOP1 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP1
]);
163 fprintf(stderr
, "NOP2 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP2
]);
164 fprintf(stderr
, "MCS : 0x%08x\n", t
->Setup
[I830_TEXREG_MCS
]);
168 void i830DumpTextureBlendState( i830ContextPtr imesa
, int unit
)
170 GLuint
*TexBlend
= imesa
->TexBlend
[unit
];
171 GLuint length
= imesa
->TexBlendWordsUsed
[unit
];
174 fprintf(stderr
, "%s : unit %d : length %d\n", __FUNCTION__
, unit
, length
);
175 for(i
= 0; i
< length
; i
++) {
176 fprintf(stderr
, "[%d] : 0x%08x\n", i
, TexBlend
[i
]);
180 void i830VertexSanity( i830ContextPtr imesa
, drmI830Vertex vertex
)
182 I830SAREAPtr sarea
= imesa
->sarea
;
186 int hw_nr_vertex
= 0;
187 int hw_start_vertex
= 0;
189 /* Do a bunch of sanity checks on the vertices sent to the hardware */
191 size
= vertex
.used
- 4;
192 if(imesa
->vertex_size
&& (size
% imesa
->vertex_size
) != 0) {
193 fprintf(stderr
, "\n\nVertex size does not match imesa "
195 fprintf(stderr
, "Buffer size : %d\n", size
);
196 fprintf(stderr
, "Vertex size : %d\n", imesa
->vertex_size
);
199 /* Check to see if the vertex format is good, and get its size */
200 if (sarea
->ContextState
[I830_CTXREG_VF
] == TINY_VERTEX_FORMAT
) {
201 vfmt_size
= 16; /* 4 dwords */
202 } else if (sarea
->ContextState
[I830_CTXREG_VF
] ==
203 NOTEX_VERTEX_FORMAT
) {
204 vfmt_size
= 24; /* 6 dwords */
205 } else if (sarea
->ContextState
[I830_CTXREG_VF
] ==
206 TEX0_VERTEX_FORMAT
) {
207 vfmt_size
= 32; /* 8 dwords */
208 if (sarea
->ContextState
[I830_CTXREG_VF2
] != NON_PROJ_VF2
) {
209 fprintf(stderr
, "\n\nTex 0 vertex format, but proj "
212 } else if(sarea
->ContextState
[I830_CTXREG_VF
] ==
213 TEX1_VERTEX_FORMAT
) {
214 if (sarea
->ContextState
[I830_CTXREG_VF2
] == NON_PROJ_VF2
)
215 vfmt_size
= 40; /* 10 dwords */
217 vfmt_size
= 48; /* 12 dwords */
219 fprintf(stderr
, "\n\nUnknown vertex format : vf : %08x "
221 sarea
->ContextState
[I830_CTXREG_VF
],
222 sarea
->ContextState
[I830_CTXREG_VF2
]);
225 if(vfmt_size
&& (size
% vfmt_size
) != 0) {
226 fprintf(stderr
, "\n\nVertex size does not match hardware "
228 fprintf(stderr
, "Buffer size : %d\n", size
);
229 fprintf(stderr
, "Vertex size : %d\n", vfmt_size
);
232 switch(sarea
->vertex_prim
) {
233 case PRIM3D_POINTLIST
:
236 prim_name
= "PointList";
239 case PRIM3D_LINELIST
:
242 prim_name
= "LineList";
245 case PRIM3D_LINESTRIP
:
248 prim_name
= "LineStrip";
254 prim_name
= "TriList";
257 case PRIM3D_TRISTRIP
:
260 prim_name
= "TriStrip";
266 prim_name
= "TriFan";
272 prim_name
= "Polygons";
275 prim_name
= "Unknown";
276 fprintf(stderr
, "\n\nUnknown primitive type : %08x\n",
280 if (hw_nr_vertex
&& vfmt_size
) {
281 int temp_size
= size
- (hw_start_vertex
* vfmt_size
);
282 int remaining
= (temp_size
% (hw_nr_vertex
* vfmt_size
));
284 if (remaining
!= 0) {
285 fprintf(stderr
, "\n\nThis buffer contains an improper"
286 " multiple of vertices for this primitive : %s\n",
288 fprintf(stderr
, "Number of vertices in buffer : %d\n",
290 fprintf(stderr
, "temp_size : %d\n", temp_size
);
291 fprintf(stderr
, "remaining vertices : %d",
292 remaining
/ vfmt_size
);
296 fprintf(stderr
, "\n\nPrim name (%s), vertices (%d)\n",
302 void i830EmitHwStateLockedDebug( i830ContextPtr imesa
)
306 if ((imesa
->dirty
& I830_UPLOAD_TEX0_IMAGE
) && imesa
->CurrentTexObj
[0]) {
307 i830UploadTexImagesLocked(imesa
, imesa
->CurrentTexObj
[0]);
310 if ((imesa
->dirty
& I830_UPLOAD_TEX1_IMAGE
) && imesa
->CurrentTexObj
[1]) {
311 i830UploadTexImagesLocked(imesa
, imesa
->CurrentTexObj
[1]);
314 if (imesa
->dirty
& I830_UPLOAD_CTX
) {
315 memcpy( imesa
->sarea
->ContextState
,
316 imesa
->Setup
, sizeof(imesa
->Setup
) );
317 i830DumpContextState(imesa
);
320 for(i
= 0; i
< I830_TEXTURE_COUNT
; i
++) {
321 if ((imesa
->dirty
& I830_UPLOAD_TEX_N(i
)) && imesa
->CurrentTexObj
[i
]) {
322 imesa
->sarea
->dirty
|= I830_UPLOAD_TEX_N(i
);
323 memcpy(imesa
->sarea
->TexState
[i
],
324 imesa
->CurrentTexObj
[i
]->Setup
,
325 sizeof(imesa
->sarea
->TexState
[i
]));
326 i830DumpTextureState(imesa
, i
);
329 /* Need to figure out if texturing state, or enable changed. */
331 for(i
= 0; i
< I830_TEXBLEND_COUNT
; i
++) {
332 if (imesa
->dirty
& I830_UPLOAD_TEXBLEND_N(i
)) {
333 imesa
->sarea
->dirty
|= I830_UPLOAD_TEXBLEND_N(i
);
334 memcpy(imesa
->sarea
->TexBlendState
[i
],imesa
->TexBlend
[i
],
335 imesa
->TexBlendWordsUsed
[i
] * 4);
336 imesa
->sarea
->TexBlendStateWordsUsed
[i
] =
337 imesa
->TexBlendWordsUsed
[i
];
338 i830DumpTextureBlendState(imesa
, i
);
342 if (imesa
->dirty
& I830_UPLOAD_BUFFERS
) {
343 memcpy( imesa
->sarea
->BufferState
,imesa
->BufferSetup
,
344 sizeof(imesa
->BufferSetup
) );
345 i830DumpBufferState(imesa
);
348 if (imesa
->dirty
& I830_UPLOAD_STIPPLE
) {
349 fprintf(stderr
, "UPLOAD_STIPPLE\n");
350 memcpy( imesa
->sarea
->StippleState
,imesa
->StippleSetup
,
351 sizeof(imesa
->StippleSetup
) );
352 i830DumpStippleState(imesa
);
355 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_SHARED
) {
356 memcpy( imesa
->sarea
->Palette
[0],imesa
->palette
,
357 sizeof(imesa
->sarea
->Palette
[0]));
359 i830TextureObjectPtr p
;
360 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_N(0)) {
361 p
= imesa
->CurrentTexObj
[0];
362 memcpy( imesa
->sarea
->Palette
[0],p
->palette
,
363 sizeof(imesa
->sarea
->Palette
[0]));
365 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_N(1)) {
366 p
= imesa
->CurrentTexObj
[1];
367 memcpy( imesa
->sarea
->Palette
[1],
369 sizeof(imesa
->sarea
->Palette
[1]));
372 imesa
->sarea
->dirty
|= (imesa
->dirty
& ~(I830_UPLOAD_TEX_MASK
|
373 I830_UPLOAD_TEXBLEND_MASK
));
375 imesa
->upload_cliprects
= GL_TRUE
;