radeon/r200/r300: cleanup some of the renderbuffer code
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_dump.c
1 /*
2 * Copyright © 2007 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #include "main/mtypes.h"
29
30 #include "brw_context.h"
31 #include "brw_state.h"
32 #include "brw_defines.h"
33
34 /**
35 * Prints out a header, the contents, and the message associated with
36 * the hardware state data given.
37 *
38 * \param name Name of the state object
39 * \param data Pointer to the base of the state object
40 * \param hw_offset Hardware offset of the base of the state data.
41 * \param index Index of the DWORD being output.
42 */
43 static void
44 state_out(const char *name, void *data, uint32_t hw_offset, int index,
45 char *fmt, ...)
46 {
47 va_list va;
48
49 fprintf(stderr, "%8s: 0x%08x: 0x%08x: ",
50 name, hw_offset + index * 4, ((uint32_t *)data)[index]);
51 va_start(va, fmt);
52 vfprintf(stderr, fmt, va);
53 va_end(va);
54 }
55
56 /** Generic, undecoded state buffer debug printout */
57 static void
58 state_struct_out(const char *name, dri_bo *buffer, unsigned int state_size)
59 {
60 int i;
61
62 if (buffer == NULL)
63 return;
64
65 dri_bo_map(buffer, GL_FALSE);
66 for (i = 0; i < state_size / 4; i++) {
67 state_out(name, buffer->virtual, buffer->offset, i,
68 "dword %d\n", i);
69 }
70 dri_bo_unmap(buffer);
71 }
72
73 static const char *
74 get_965_surfacetype(unsigned int surfacetype)
75 {
76 switch (surfacetype) {
77 case 0: return "1D";
78 case 1: return "2D";
79 case 2: return "3D";
80 case 3: return "CUBE";
81 case 4: return "BUFFER";
82 case 7: return "NULL";
83 default: return "unknown";
84 }
85 }
86
87 static void dump_wm_surface_state(struct brw_context *brw)
88 {
89 int i;
90
91 for (i = 0; i < brw->wm.nr_surfaces; i++) {
92 dri_bo *surf_bo = brw->wm.surf_bo[i];
93 unsigned int surfoff;
94 struct brw_surface_state *surf;
95 char name[20];
96
97 if (surf_bo == NULL) {
98 fprintf(stderr, "WM SS%d: NULL\n", i);
99 continue;
100 }
101 dri_bo_map(surf_bo, GL_FALSE);
102 surfoff = surf_bo->offset;
103 surf = (struct brw_surface_state *)(surf_bo->virtual);
104
105 sprintf(name, "WM SS%d", i);
106 state_out(name, surf, surfoff, 0, "%s\n",
107 get_965_surfacetype(surf->ss0.surface_type));
108 state_out(name, surf, surfoff, 1, "offset\n");
109 state_out(name, surf, surfoff, 2, "%dx%d size, %d mips\n",
110 surf->ss2.width + 1, surf->ss2.height + 1, surf->ss2.mip_count);
111 state_out(name, surf, surfoff, 3, "pitch %d, %stiled\n",
112 surf->ss3.pitch + 1, surf->ss3.tiled_surface ? "" : "not ");
113 state_out(name, surf, surfoff, 4, "mip base %d\n",
114 surf->ss4.min_lod);
115
116 dri_bo_unmap(surf_bo);
117 }
118 }
119
120 static void dump_sf_viewport_state(struct brw_context *brw)
121 {
122 const char *name = "SF VP";
123 struct brw_sf_viewport *vp;
124 uint32_t vp_off;
125
126 if (brw->sf.vp_bo == NULL)
127 return;
128
129 dri_bo_map(brw->sf.vp_bo, GL_FALSE);
130
131 vp = brw->sf.vp_bo->virtual;
132 vp_off = brw->sf.vp_bo->offset;
133
134 state_out(name, vp, vp_off, 0, "m00 = %f\n", vp->viewport.m00);
135 state_out(name, vp, vp_off, 1, "m11 = %f\n", vp->viewport.m11);
136 state_out(name, vp, vp_off, 2, "m22 = %f\n", vp->viewport.m22);
137 state_out(name, vp, vp_off, 3, "m30 = %f\n", vp->viewport.m30);
138 state_out(name, vp, vp_off, 4, "m31 = %f\n", vp->viewport.m31);
139 state_out(name, vp, vp_off, 5, "m32 = %f\n", vp->viewport.m32);
140
141 state_out(name, vp, vp_off, 6, "top left = %d,%d\n",
142 vp->scissor.xmin, vp->scissor.ymin);
143 state_out(name, vp, vp_off, 7, "bottom right = %d,%d\n",
144 vp->scissor.xmax, vp->scissor.ymax);
145
146 dri_bo_unmap(brw->sf.vp_bo);
147 }
148
149 static void brw_debug_prog(const char *name, dri_bo *prog)
150 {
151 unsigned int i;
152 uint32_t *data;
153
154 if (prog == NULL)
155 return;
156
157 dri_bo_map(prog, GL_FALSE);
158
159 data = prog->virtual;
160
161 for (i = 0; i < prog->size / 4 / 4; i++) {
162 fprintf(stderr, "%8s: 0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
163 name, (unsigned int)prog->offset + i * 4 * 4,
164 data[i * 4], data[i * 4 + 1], data[i * 4 + 2], data[i * 4 + 3]);
165 }
166
167 dri_bo_unmap(prog);
168 }
169
170
171 /**
172 * Print additional debug information associated with the batchbuffer
173 * when DEBUG_BATCH is set.
174 *
175 * For 965, this means mapping the state buffers that would have been referenced
176 * by the batchbuffer and dumping them.
177 *
178 * The buffer offsets printed rely on the buffer containing the last offset
179 * it was validated at.
180 */
181 void brw_debug_batch(struct intel_context *intel)
182 {
183 struct brw_context *brw = brw_context(&intel->ctx);
184
185 state_struct_out("WM bind", brw->wm.bind_bo, 4 * brw->wm.nr_surfaces);
186 dump_wm_surface_state(brw);
187
188 state_struct_out("VS", brw->vs.state_bo, sizeof(struct brw_vs_unit_state));
189 brw_debug_prog("VS prog", brw->vs.prog_bo);
190
191 state_struct_out("GS", brw->gs.state_bo, sizeof(struct brw_gs_unit_state));
192 brw_debug_prog("GS prog", brw->gs.prog_bo);
193
194 state_struct_out("SF", brw->sf.state_bo, sizeof(struct brw_sf_unit_state));
195 dump_sf_viewport_state(brw);
196 brw_debug_prog("SF prog", brw->sf.prog_bo);
197
198 state_struct_out("WM", brw->wm.state_bo, sizeof(struct brw_wm_unit_state));
199 brw_debug_prog("WM prog", brw->wm.prog_bo);
200 }