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"
49 #include "i830_tris.h"
50 #include "i830_ioctl.h"
51 #include "i830_debug.h"
53 #include "swrast/swrast.h"
54 #include "array_cache/acache.h"
56 #include "swrast_setup/swrast_setup.h"
58 #include "tnl/t_pipeline.h"
61 #define TINY_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
62 VRTX_TEX_COORD_COUNT(0) | \
66 #define NOTEX_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
67 VRTX_TEX_COORD_COUNT(0) | \
72 #define TEX0_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
73 VRTX_TEX_COORD_COUNT(1) | \
78 #define TEX1_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
79 VRTX_TEX_COORD_COUNT(2) | \
84 #define PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
85 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_3D) | \
86 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_3D) | \
87 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_3D) | \
88 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_3D))
90 #define NON_PROJ_VF2 (STATE3D_VERTEX_FORMAT_2_CMD | \
91 VRTX_TEX_SET_0_FMT(TEXCOORDFMT_2D) | \
92 VRTX_TEX_SET_1_FMT(TEXCOORDFMT_2D) | \
93 VRTX_TEX_SET_2_FMT(TEXCOORDFMT_2D) | \
94 VRTX_TEX_SET_3_FMT(TEXCOORDFMT_2D))
96 void i830DumpContextState( i830ContextPtr imesa
)
98 GLuint
*Context
= imesa
->Setup
;
100 fprintf(stderr
, "%s\n", __FUNCTION__
);
101 fprintf(stderr
, "STATE1 : 0x%08x\n", Context
[I830_CTXREG_STATE1
]);
102 fprintf(stderr
, "STATE2 : 0x%08x\n", Context
[I830_CTXREG_STATE2
]);
103 fprintf(stderr
, "STATE3 : 0x%08x\n", Context
[I830_CTXREG_STATE3
]);
104 fprintf(stderr
, "STATE4 : 0x%08x\n", Context
[I830_CTXREG_STATE4
]);
105 fprintf(stderr
, "STATE5 : 0x%08x\n", Context
[I830_CTXREG_STATE5
]);
106 fprintf(stderr
, "IALPHAB : 0x%08x\n", Context
[I830_CTXREG_IALPHAB
]);
107 fprintf(stderr
, "STENCILTST : 0x%08x\n", Context
[I830_CTXREG_STENCILTST
]);
108 fprintf(stderr
, "ENABLES_1 : 0x%08x\n", Context
[I830_CTXREG_ENABLES_1
]);
109 fprintf(stderr
, "ENABLES_2 : 0x%08x\n", Context
[I830_CTXREG_ENABLES_2
]);
110 fprintf(stderr
, "AA : 0x%08x\n", Context
[I830_CTXREG_AA
]);
111 fprintf(stderr
, "FOGCOLOR : 0x%08x\n", Context
[I830_CTXREG_FOGCOLOR
]);
112 fprintf(stderr
, "BCOLOR0 : 0x%08x\n", Context
[I830_CTXREG_BLENDCOLR0
]);
113 fprintf(stderr
, "BCOLOR : 0x%08x\n", Context
[I830_CTXREG_BLENDCOLR
]);
114 fprintf(stderr
, "VF : 0x%08x\n", Context
[I830_CTXREG_VF
]);
115 fprintf(stderr
, "VF2 : 0x%08x\n", Context
[I830_CTXREG_VF2
]);
116 fprintf(stderr
, "MCSB0 : 0x%08x\n", Context
[I830_CTXREG_MCSB0
]);
117 fprintf(stderr
, "MCSB1 : 0x%08x\n", Context
[I830_CTXREG_MCSB1
]);
120 void i830DumpBufferState( i830ContextPtr imesa
)
122 GLuint
*Buffer
= imesa
->BufferSetup
;
124 fprintf(stderr
, "%s\n", __FUNCTION__
);
125 fprintf(stderr
, "CBUFADDR : 0x%08x\n", Buffer
[I830_DESTREG_CBUFADDR
]);
126 fprintf(stderr
, "DBUFADDR : 0x%08x\n", Buffer
[I830_DESTREG_DBUFADDR
]);
127 fprintf(stderr
, "DV0 : 0x%08x\n", Buffer
[I830_DESTREG_DV0
]);
128 fprintf(stderr
, "DV1 : 0x%08x\n", Buffer
[I830_DESTREG_DV1
]);
129 fprintf(stderr
, "SENABLE : 0x%08x\n", Buffer
[I830_DESTREG_SENABLE
]);
130 fprintf(stderr
, "SR0 : 0x%08x\n", Buffer
[I830_DESTREG_SR0
]);
131 fprintf(stderr
, "SR1 : 0x%08x\n", Buffer
[I830_DESTREG_SR1
]);
132 fprintf(stderr
, "SR2 : 0x%08x\n", Buffer
[I830_DESTREG_SR2
]);
133 fprintf(stderr
, "DR0 : 0x%08x\n", Buffer
[I830_DESTREG_DR0
]);
134 fprintf(stderr
, "DR1 : 0x%08x\n", Buffer
[I830_DESTREG_DR1
]);
135 fprintf(stderr
, "DR2 : 0x%08x\n", Buffer
[I830_DESTREG_DR2
]);
136 fprintf(stderr
, "DR3 : 0x%08x\n", Buffer
[I830_DESTREG_DR3
]);
137 fprintf(stderr
, "DR4 : 0x%08x\n", Buffer
[I830_DESTREG_DR4
]);
140 void i830DumpStippleState( i830ContextPtr imesa
)
142 GLuint
*Buffer
= imesa
->BufferSetup
;
144 fprintf(stderr
, "%s\n", __FUNCTION__
);
145 fprintf(stderr
, "ST1 : 0x%08x\n", Buffer
[I830_STPREG_ST1
]);
148 void i830DumpTextureState( i830ContextPtr imesa
, int unit
)
150 i830TextureObjectPtr t
= imesa
->CurrentTexObj
[unit
];
153 fprintf(stderr
, "%s : unit %d\n", __FUNCTION__
, unit
);
154 fprintf(stderr
, "TM0LI : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0LI
]);
155 fprintf(stderr
, "TM0S0 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S0
]);
156 fprintf(stderr
, "TM0S1 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S1
]);
157 fprintf(stderr
, "TM0S2 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S2
]);
158 fprintf(stderr
, "TM0S3 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S3
]);
159 fprintf(stderr
, "TM0S4 : 0x%08x\n", t
->Setup
[I830_TEXREG_TM0S4
]);
160 fprintf(stderr
, "NOP0 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP0
]);
161 fprintf(stderr
, "NOP1 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP1
]);
162 fprintf(stderr
, "NOP2 : 0x%08x\n", t
->Setup
[I830_TEXREG_NOP2
]);
163 fprintf(stderr
, "MCS : 0x%08x\n", t
->Setup
[I830_TEXREG_MCS
]);
167 void i830DumpTextureBlendState( i830ContextPtr imesa
, int unit
)
169 GLuint
*TexBlend
= imesa
->TexBlend
[unit
];
170 GLuint length
= imesa
->TexBlendWordsUsed
[unit
];
173 fprintf(stderr
, "%s : unit %d : length %d\n", __FUNCTION__
, unit
, length
);
174 for(i
= 0; i
< length
; i
++) {
175 fprintf(stderr
, "[%d] : 0x%08x\n", i
, TexBlend
[i
]);
179 void i830VertexSanity( i830ContextPtr imesa
, drmI830Vertex vertex
)
181 I830SAREAPtr sarea
= imesa
->sarea
;
185 int hw_nr_vertex
= 0;
186 int hw_start_vertex
= 0;
188 /* Do a bunch of sanity checks on the vertices sent to the hardware */
190 size
= vertex
.used
- 4;
191 if(imesa
->vertex_size
&& (size
% imesa
->vertex_size
) != 0) {
192 fprintf(stderr
, "\n\nVertex size does not match imesa "
194 fprintf(stderr
, "Buffer size : %d\n", size
);
195 fprintf(stderr
, "Vertex size : %d\n", imesa
->vertex_size
);
198 /* Check to see if the vertex format is good, and get its size */
199 if (sarea
->ContextState
[I830_CTXREG_VF
] == TINY_VERTEX_FORMAT
) {
200 vfmt_size
= 16; /* 4 dwords */
201 } else if (sarea
->ContextState
[I830_CTXREG_VF
] ==
202 NOTEX_VERTEX_FORMAT
) {
203 vfmt_size
= 24; /* 6 dwords */
204 } else if (sarea
->ContextState
[I830_CTXREG_VF
] ==
205 TEX0_VERTEX_FORMAT
) {
206 vfmt_size
= 32; /* 8 dwords */
207 if (sarea
->ContextState
[I830_CTXREG_VF2
] != NON_PROJ_VF2
) {
208 fprintf(stderr
, "\n\nTex 0 vertex format, but proj "
211 } else if(sarea
->ContextState
[I830_CTXREG_VF
] ==
212 TEX1_VERTEX_FORMAT
) {
213 if (sarea
->ContextState
[I830_CTXREG_VF2
] == NON_PROJ_VF2
)
214 vfmt_size
= 40; /* 10 dwords */
216 vfmt_size
= 48; /* 12 dwords */
218 fprintf(stderr
, "\n\nUnknown vertex format : vf : %08x "
220 sarea
->ContextState
[I830_CTXREG_VF
],
221 sarea
->ContextState
[I830_CTXREG_VF2
]);
224 if(vfmt_size
&& (size
% vfmt_size
) != 0) {
225 fprintf(stderr
, "\n\nVertex size does not match hardware "
227 fprintf(stderr
, "Buffer size : %d\n", size
);
228 fprintf(stderr
, "Vertex size : %d\n", vfmt_size
);
231 switch(sarea
->vertex_prim
) {
232 case PRIM3D_POINTLIST
:
235 prim_name
= "PointList";
238 case PRIM3D_LINELIST
:
241 prim_name
= "LineList";
244 case PRIM3D_LINESTRIP
:
247 prim_name
= "LineStrip";
253 prim_name
= "TriList";
256 case PRIM3D_TRISTRIP
:
259 prim_name
= "TriStrip";
265 prim_name
= "TriFan";
271 prim_name
= "Polygons";
274 prim_name
= "Unknown";
275 fprintf(stderr
, "\n\nUnknown primitive type : %08x\n",
279 if (hw_nr_vertex
&& vfmt_size
) {
280 int temp_size
= size
- (hw_start_vertex
* vfmt_size
);
281 int remaining
= (temp_size
% (hw_nr_vertex
* vfmt_size
));
283 if (remaining
!= 0) {
284 fprintf(stderr
, "\n\nThis buffer contains an improper"
285 " multiple of vertices for this primitive : %s\n",
287 fprintf(stderr
, "Number of vertices in buffer : %d\n",
289 fprintf(stderr
, "temp_size : %d\n", temp_size
);
290 fprintf(stderr
, "remaining vertices : %d",
291 remaining
/ vfmt_size
);
295 fprintf(stderr
, "\n\nPrim name (%s), vertices (%d)\n",
301 void i830EmitHwStateLockedDebug( i830ContextPtr imesa
)
305 if ((imesa
->dirty
& I830_UPLOAD_TEX0_IMAGE
) && imesa
->CurrentTexObj
[0]) {
306 i830UploadTexImagesLocked(imesa
, imesa
->CurrentTexObj
[0]);
309 if ((imesa
->dirty
& I830_UPLOAD_TEX1_IMAGE
) && imesa
->CurrentTexObj
[1]) {
310 i830UploadTexImagesLocked(imesa
, imesa
->CurrentTexObj
[1]);
313 if (imesa
->dirty
& I830_UPLOAD_CTX
) {
314 memcpy( imesa
->sarea
->ContextState
,
315 imesa
->Setup
, sizeof(imesa
->Setup
) );
316 i830DumpContextState(imesa
);
319 for(i
= 0; i
< I830_TEXTURE_COUNT
; i
++) {
320 if ((imesa
->dirty
& I830_UPLOAD_TEX_N(i
)) && imesa
->CurrentTexObj
[i
]) {
323 imesa
->sarea
->dirty
|= I830_UPLOAD_TEX_N(i
);
328 TexState
= imesa
->sarea
->TexState
[i
];
332 TexState
= imesa
->sarea
->TexState2
;
336 TexState
= imesa
->sarea
->TexState3
;
340 memcpy(TexState
, imesa
->CurrentTexObj
[i
]->Setup
,
341 sizeof(imesa
->sarea
->TexState
[i
]));
342 i830DumpTextureState(imesa
, i
);
345 /* Need to figure out if texturing state, or enable changed. */
347 for(i
= 0; i
< I830_TEXBLEND_COUNT
; i
++) {
348 if (imesa
->dirty
& I830_UPLOAD_TEXBLEND_N(i
)) {
349 unsigned * TexBlendState
;
350 unsigned * words_used
;
352 imesa
->sarea
->dirty
|= I830_UPLOAD_TEXBLEND_N(i
);
357 TexBlendState
= imesa
->sarea
->TexBlendState
[i
];
358 words_used
= & imesa
->sarea
->TexBlendStateWordsUsed
[i
];
362 TexBlendState
= imesa
->sarea
->TexBlendState2
;
363 words_used
= & imesa
->sarea
->TexBlendStateWordsUsed2
;
367 TexBlendState
= imesa
->sarea
->TexBlendState3
;
368 words_used
= & imesa
->sarea
->TexBlendStateWordsUsed3
;
372 memcpy(TexBlendState
, imesa
->TexBlend
[i
],
373 imesa
->TexBlendWordsUsed
[i
] * 4);
374 *words_used
= imesa
->TexBlendWordsUsed
[i
];
376 i830DumpTextureBlendState(imesa
, i
);
380 if (imesa
->dirty
& I830_UPLOAD_BUFFERS
) {
381 memcpy( imesa
->sarea
->BufferState
,imesa
->BufferSetup
,
382 sizeof(imesa
->BufferSetup
) );
383 i830DumpBufferState(imesa
);
386 if (imesa
->dirty
& I830_UPLOAD_STIPPLE
) {
387 fprintf(stderr
, "UPLOAD_STIPPLE\n");
388 memcpy( imesa
->sarea
->StippleState
,imesa
->StippleSetup
,
389 sizeof(imesa
->StippleSetup
) );
390 i830DumpStippleState(imesa
);
393 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_SHARED
) {
394 memcpy( imesa
->sarea
->Palette
[0],imesa
->palette
,
395 sizeof(imesa
->sarea
->Palette
[0]));
397 i830TextureObjectPtr p
;
398 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_N(0)) {
399 p
= imesa
->CurrentTexObj
[0];
400 memcpy( imesa
->sarea
->Palette
[0],p
->palette
,
401 sizeof(imesa
->sarea
->Palette
[0]));
403 if (imesa
->dirty
& I830_UPLOAD_TEX_PALETTE_N(1)) {
404 p
= imesa
->CurrentTexObj
[1];
405 memcpy( imesa
->sarea
->Palette
[1],
407 sizeof(imesa
->sarea
->Palette
[1]));
410 imesa
->sarea
->dirty
|= (imesa
->dirty
& ~(I830_UPLOAD_TEX_MASK
|
411 I830_UPLOAD_TEXBLEND_MASK
));
413 imesa
->upload_cliprects
= GL_TRUE
;