Provide dummy definitions of __driConfig externs
[mesa.git] / src / mesa / drivers / dri / i830 / i830_debug.c
1 /**************************************************************************
2
3 Copyright 2001 2d3d Inc., Delray Beach, FL
4
5 All Rights Reserved.
6
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:
13
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
16 Software.
17
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.
25
26 **************************************************************************/
27
28 /* $XFree86: xc/lib/GL/mesa/src/drv/i830/i830_debug.c,v 1.3 2002/12/10 01:26:53 dawes Exp $ */
29
30 /*
31 * Author:
32 * Jeff Hartmann <jhartmann@2d3d.com>
33 */
34
35 #include "glheader.h"
36 #include "context.h"
37 #include "macros.h"
38 #include "enums.h"
39 #include "dd.h"
40
41 #include "mm.h"
42
43 #include "i830_screen.h"
44 #include "i830_dri.h"
45
46 #include "i830_context.h"
47 #include "i830_state.h"
48 #include "i830_tex.h"
49 #include "i830_vb.h"
50 #include "i830_tris.h"
51 #include "i830_ioctl.h"
52 #include "i830_debug.h"
53
54 #include "swrast/swrast.h"
55 #include "array_cache/acache.h"
56 #include "tnl/tnl.h"
57 #include "swrast_setup/swrast_setup.h"
58
59 #include "tnl/t_pipeline.h"
60
61
62 #define TINY_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
63 VRTX_TEX_COORD_COUNT(0) | \
64 VRTX_HAS_DIFFUSE | \
65 VRTX_HAS_XYZ)
66
67 #define NOTEX_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
68 VRTX_TEX_COORD_COUNT(0) | \
69 VRTX_HAS_DIFFUSE | \
70 VRTX_HAS_SPEC | \
71 VRTX_HAS_XYZW)
72
73 #define TEX0_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
74 VRTX_TEX_COORD_COUNT(1) | \
75 VRTX_HAS_DIFFUSE | \
76 VRTX_HAS_SPEC | \
77 VRTX_HAS_XYZW)
78
79 #define TEX1_VERTEX_FORMAT (STATE3D_VERTEX_FORMAT_CMD | \
80 VRTX_TEX_COORD_COUNT(2) | \
81 VRTX_HAS_DIFFUSE | \
82 VRTX_HAS_SPEC | \
83 VRTX_HAS_XYZW)
84
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))
90
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))
96
97 void i830DumpContextState( i830ContextPtr imesa )
98 {
99 GLuint *Context = imesa->Setup;
100
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]);
119 }
120
121 void i830DumpBufferState( i830ContextPtr imesa )
122 {
123 GLuint *Buffer = imesa->BufferSetup;
124
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]);
139 }
140
141 void i830DumpStippleState( i830ContextPtr imesa )
142 {
143 GLuint *Buffer = imesa->BufferSetup;
144
145 fprintf(stderr, "%s\n", __FUNCTION__);
146 fprintf(stderr, "ST1 : 0x%08x\n", Buffer[I830_STPREG_ST1]);
147 }
148
149 void i830DumpTextureState( i830ContextPtr imesa, int unit )
150 {
151 i830TextureObjectPtr t = imesa->CurrentTexObj[unit];
152
153 if(t) {
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]);
165 }
166 }
167
168 void i830DumpTextureBlendState( i830ContextPtr imesa, int unit )
169 {
170 GLuint *TexBlend = imesa->TexBlend[unit];
171 GLuint length = imesa->TexBlendWordsUsed[unit];
172 int i;
173
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]);
177 }
178 }
179
180 void i830VertexSanity( i830ContextPtr imesa, drmI830Vertex vertex )
181 {
182 I830SAREAPtr sarea = imesa->sarea;
183 char *prim_name;
184 int size = 0;
185 int vfmt_size = 0;
186 int hw_nr_vertex = 0;
187 int hw_start_vertex = 0;
188
189 /* Do a bunch of sanity checks on the vertices sent to the hardware */
190
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 "
194 "internal state\n");
195 fprintf(stderr, "Buffer size : %d\n", size);
196 fprintf(stderr, "Vertex size : %d\n", imesa->vertex_size);
197 }
198
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 "
210 "texturing\n");
211 }
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 */
216 else
217 vfmt_size = 48; /* 12 dwords */
218 } else {
219 fprintf(stderr, "\n\nUnknown vertex format : vf : %08x "
220 "vf2 : %08x\n",
221 sarea->ContextState[I830_CTXREG_VF],
222 sarea->ContextState[I830_CTXREG_VF2]);
223 }
224
225 if(vfmt_size && (size % vfmt_size) != 0) {
226 fprintf(stderr, "\n\nVertex size does not match hardware "
227 "internal state\n");
228 fprintf(stderr, "Buffer size : %d\n", size);
229 fprintf(stderr, "Vertex size : %d\n", vfmt_size);
230 }
231
232 switch(sarea->vertex_prim) {
233 case PRIM3D_POINTLIST:
234 hw_start_vertex = 0;
235 hw_nr_vertex = 1;
236 prim_name = "PointList";
237 break;
238
239 case PRIM3D_LINELIST:
240 hw_start_vertex = 0;
241 hw_nr_vertex = 2;
242 prim_name = "LineList";
243 break;
244
245 case PRIM3D_LINESTRIP:
246 hw_start_vertex = 2;
247 hw_nr_vertex = 1;
248 prim_name = "LineStrip";
249 break;
250
251 case PRIM3D_TRILIST:
252 hw_start_vertex = 0;
253 hw_nr_vertex = 3;
254 prim_name = "TriList";
255 break;
256
257 case PRIM3D_TRISTRIP:
258 hw_start_vertex = 3;
259 hw_nr_vertex = 1;
260 prim_name = "TriStrip";
261 break;
262
263 case PRIM3D_TRIFAN:
264 hw_start_vertex = 3;
265 hw_nr_vertex = 1;
266 prim_name = "TriFan";
267 break;
268
269 case PRIM3D_POLY:
270 hw_start_vertex = 3;
271 hw_nr_vertex = 1;
272 prim_name = "Polygons";
273 break;
274 default:
275 prim_name = "Unknown";
276 fprintf(stderr, "\n\nUnknown primitive type : %08x\n",
277 sarea->vertex_prim);
278 }
279
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));
283
284 if (remaining != 0) {
285 fprintf(stderr, "\n\nThis buffer contains an improper"
286 " multiple of vertices for this primitive : %s\n",
287 prim_name);
288 fprintf(stderr, "Number of vertices in buffer : %d\n",
289 size / vfmt_size);
290 fprintf(stderr, "temp_size : %d\n", temp_size);
291 fprintf(stderr, "remaining vertices : %d",
292 remaining / vfmt_size);
293 }
294 }
295 if (1) {
296 fprintf(stderr, "\n\nPrim name (%s), vertices (%d)\n",
297 prim_name,
298 size / vfmt_size);
299 }
300 }
301
302 void i830EmitHwStateLockedDebug( i830ContextPtr imesa )
303 {
304 int i;
305
306 if ((imesa->dirty & I830_UPLOAD_TEX0_IMAGE) && imesa->CurrentTexObj[0]) {
307 i830UploadTexImagesLocked(imesa, imesa->CurrentTexObj[0]);
308 }
309
310 if ((imesa->dirty & I830_UPLOAD_TEX1_IMAGE) && imesa->CurrentTexObj[1]) {
311 i830UploadTexImagesLocked(imesa, imesa->CurrentTexObj[1]);
312 }
313
314 if (imesa->dirty & I830_UPLOAD_CTX) {
315 memcpy( imesa->sarea->ContextState,
316 imesa->Setup, sizeof(imesa->Setup) );
317 i830DumpContextState(imesa);
318 }
319
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);
327 }
328 }
329 /* Need to figure out if texturing state, or enable changed. */
330
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);
339 }
340 }
341
342 if (imesa->dirty & I830_UPLOAD_BUFFERS) {
343 memcpy( imesa->sarea->BufferState,imesa->BufferSetup,
344 sizeof(imesa->BufferSetup) );
345 i830DumpBufferState(imesa);
346 }
347
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);
353 }
354
355 if (imesa->dirty & I830_UPLOAD_TEX_PALETTE_SHARED) {
356 memcpy( imesa->sarea->Palette[0],imesa->palette,
357 sizeof(imesa->sarea->Palette[0]));
358 } else {
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]));
364 }
365 if (imesa->dirty & I830_UPLOAD_TEX_PALETTE_N(1)) {
366 p = imesa->CurrentTexObj[1];
367 memcpy( imesa->sarea->Palette[1],
368 p->palette,
369 sizeof(imesa->sarea->Palette[1]));
370 }
371 }
372 imesa->sarea->dirty |= (imesa->dirty & ~(I830_UPLOAD_TEX_MASK |
373 I830_UPLOAD_TEXBLEND_MASK));
374
375 imesa->upload_cliprects = GL_TRUE;
376 imesa->dirty = 0;
377 }