2 * Copyright © 2007 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 #include "main/mtypes.h"
30 #include "brw_context.h"
31 #include "brw_defines.h"
34 * Prints out a header, the contents, and the message associated with
35 * the hardware state data given.
37 * \param name Name of the state object
38 * \param data Pointer to the base of the state object
39 * \param hw_offset Hardware offset of the base of the state data.
40 * \param index Index of the DWORD being output.
43 state_out(const char *name
, void *data
, uint32_t hw_offset
, int index
,
48 fprintf(stderr
, "%8s: 0x%08x: 0x%08x: ",
49 name
, hw_offset
+ index
* 4, ((uint32_t *)data
)[index
]);
51 vfprintf(stderr
, fmt
, va
);
55 /** Generic, undecoded state buffer debug printout */
57 state_struct_out(const char *name
, dri_bo
*buffer
, unsigned int state_size
)
64 dri_bo_map(buffer
, GL_FALSE
);
65 for (i
= 0; i
< state_size
/ 4; i
++) {
66 state_out(name
, buffer
->virtual, buffer
->offset
, i
,
73 get_965_surfacetype(unsigned int surfacetype
)
75 switch (surfacetype
) {
79 case 3: return "CUBE";
80 case 4: return "BUFFER";
81 case 7: return "NULL";
82 default: return "unknown";
87 get_965_surface_format(unsigned int surface_format
)
89 switch (surface_format
) {
90 case 0x000: return "r32g32b32a32_float";
91 case 0x0c1: return "b8g8r8a8_unorm";
92 case 0x100: return "b5g6r5_unorm";
93 case 0x102: return "b5g5r5a1_unorm";
94 case 0x104: return "b4g4r4a4_unorm";
95 default: return "unknown";
99 static void dump_wm_surface_state(struct brw_context
*brw
)
103 for (i
= 0; i
< brw
->wm
.nr_surfaces
; i
++) {
104 dri_bo
*surf_bo
= brw
->wm
.surf_bo
[i
];
105 unsigned int surfoff
;
106 struct brw_surface_state
*surf
;
109 if (surf_bo
== NULL
) {
110 fprintf(stderr
, " WM SS%d: NULL\n", i
);
113 dri_bo_map(surf_bo
, GL_FALSE
);
114 surfoff
= surf_bo
->offset
;
115 surf
= (struct brw_surface_state
*)(surf_bo
->virtual);
117 sprintf(name
, "WM SS%d", i
);
118 state_out(name
, surf
, surfoff
, 0, "%s %s\n",
119 get_965_surfacetype(surf
->ss0
.surface_type
),
120 get_965_surface_format(surf
->ss0
.surface_format
));
121 state_out(name
, surf
, surfoff
, 1, "offset\n");
122 state_out(name
, surf
, surfoff
, 2, "%dx%d size, %d mips\n",
123 surf
->ss2
.width
+ 1, surf
->ss2
.height
+ 1, surf
->ss2
.mip_count
);
124 state_out(name
, surf
, surfoff
, 3, "pitch %d, %stiled\n",
125 surf
->ss3
.pitch
+ 1, surf
->ss3
.tiled_surface
? "" : "not ");
126 state_out(name
, surf
, surfoff
, 4, "mip base %d\n",
128 state_out(name
, surf
, surfoff
, 5, "x,y offset: %d,%d\n",
129 surf
->ss5
.x_offset
, surf
->ss5
.y_offset
);
131 dri_bo_unmap(surf_bo
);
135 static void dump_sf_viewport_state(struct brw_context
*brw
)
137 const char *name
= "SF VP";
138 struct brw_sf_viewport
*vp
;
141 if (brw
->sf
.vp_bo
== NULL
)
144 dri_bo_map(brw
->sf
.vp_bo
, GL_FALSE
);
146 vp
= brw
->sf
.vp_bo
->virtual;
147 vp_off
= brw
->sf
.vp_bo
->offset
;
149 state_out(name
, vp
, vp_off
, 0, "m00 = %f\n", vp
->viewport
.m00
);
150 state_out(name
, vp
, vp_off
, 1, "m11 = %f\n", vp
->viewport
.m11
);
151 state_out(name
, vp
, vp_off
, 2, "m22 = %f\n", vp
->viewport
.m22
);
152 state_out(name
, vp
, vp_off
, 3, "m30 = %f\n", vp
->viewport
.m30
);
153 state_out(name
, vp
, vp_off
, 4, "m31 = %f\n", vp
->viewport
.m31
);
154 state_out(name
, vp
, vp_off
, 5, "m32 = %f\n", vp
->viewport
.m32
);
156 state_out(name
, vp
, vp_off
, 6, "top left = %d,%d\n",
157 vp
->scissor
.xmin
, vp
->scissor
.ymin
);
158 state_out(name
, vp
, vp_off
, 7, "bottom right = %d,%d\n",
159 vp
->scissor
.xmax
, vp
->scissor
.ymax
);
161 dri_bo_unmap(brw
->sf
.vp_bo
);
164 static void brw_debug_prog(const char *name
, dri_bo
*prog
)
172 dri_bo_map(prog
, GL_FALSE
);
174 data
= prog
->virtual;
176 for (i
= 0; i
< prog
->size
/ 4 / 4; i
++) {
177 fprintf(stderr
, "%8s: 0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
178 name
, (unsigned int)prog
->offset
+ i
* 4 * 4,
179 data
[i
* 4], data
[i
* 4 + 1], data
[i
* 4 + 2], data
[i
* 4 + 3]);
180 /* Stop at the end of the program. It'd be nice to keep track of the actual
181 * intended program size instead of guessing like this.
183 if (data
[i
* 4 + 0] == 0 &&
184 data
[i
* 4 + 1] == 0 &&
185 data
[i
* 4 + 2] == 0 &&
186 data
[i
* 4 + 3] == 0)
195 * Print additional debug information associated with the batchbuffer
196 * when DEBUG_BATCH is set.
198 * For 965, this means mapping the state buffers that would have been referenced
199 * by the batchbuffer and dumping them.
201 * The buffer offsets printed rely on the buffer containing the last offset
202 * it was validated at.
204 void brw_debug_batch(struct intel_context
*intel
)
206 struct brw_context
*brw
= brw_context(&intel
->ctx
);
208 state_struct_out("WM bind", brw
->wm
.bind_bo
, 4 * brw
->wm
.nr_surfaces
);
209 dump_wm_surface_state(brw
);
211 state_struct_out("VS", brw
->vs
.state_bo
, sizeof(struct brw_vs_unit_state
));
212 brw_debug_prog("VS prog", brw
->vs
.prog_bo
);
214 state_struct_out("GS", brw
->gs
.state_bo
, sizeof(struct brw_gs_unit_state
));
215 brw_debug_prog("GS prog", brw
->gs
.prog_bo
);
217 state_struct_out("SF", brw
->sf
.state_bo
, sizeof(struct brw_sf_unit_state
));
218 dump_sf_viewport_state(brw
);
219 brw_debug_prog("SF prog", brw
->sf
.prog_bo
);
221 state_struct_out("WM", brw
->wm
.state_bo
, sizeof(struct brw_wm_unit_state
));
222 brw_debug_prog("WM prog", brw
->wm
.prog_bo
);