r300g: fix an invalid pointer in free
[mesa.git] / src / gallium / drivers / r300 / r300_debug.c
1 /*
2 * Copyright 2009 Nicolai Haehnle <nhaehnle@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "r300_context.h"
24
25 #include "util/u_debug.h"
26
27 #include <stdio.h>
28
29 static const struct debug_named_value debug_options[] = {
30 { "fp", DBG_FP, "Fragment program handling (for debugging)" },
31 { "vp", DBG_VP, "Vertex program handling (for debugging)" },
32 { "draw", DBG_DRAW, "Draw calls (for debugging)" },
33 { "swtcl", DBG_SWTCL, "SWTCL-specific info (for debugging)" },
34 { "rsblock", DBG_RS_BLOCK, "Rasterizer registers (for debugging)" },
35 { "psc", DBG_PSC, "Vertex stream registers (for debugging)" },
36 { "tex", DBG_TEX, "Textures (for debugging)" },
37 { "texalloc", DBG_TEXALLOC, "Texture allocation (for debugging)" },
38 { "fall", DBG_FALL, "Fallbacks (for debugging)" },
39 { "rs", DBG_RS, "Rasterizer (for debugging)" },
40 { "fb", DBG_FB, "Framebuffer (for debugging)" },
41 { "cbzb", DBG_CBZB, "Fast color clear info (for debugging)" },
42 { "fakeocc", DBG_FAKE_OCC, "Use fake occlusion queries (for debugging)" },
43 { "anisohq", DBG_ANISOHQ, "High quality anisotropic filtering (for benchmarking)" },
44 { "notiling", DBG_NO_TILING, "Disable tiling (for benchmarking)" },
45 { "noimmd", DBG_NO_IMMD, "Disable immediate mode (for benchmarking)" },
46 { "stats", DBG_STATS, "Gather statistics" },
47 { "hyperz", DBG_HYPERZ, "HyperZ (for debugging)" },
48
49 /* must be last */
50 DEBUG_NAMED_VALUE_END
51 };
52
53 void r300_init_debug(struct r300_screen * screen)
54 {
55 screen->debug = debug_get_flags_option("RADEON_DEBUG", debug_options, 0);
56 }
57
58 void r500_dump_rs_block(struct r300_rs_block *rs)
59 {
60 unsigned count, ip, it_count, ic_count, i, j;
61 unsigned tex_ptr;
62 unsigned col_ptr, col_fmt;
63
64 count = rs->inst_count & 0xf;
65 count++;
66
67 it_count = rs->count & 0x7f;
68 ic_count = (rs->count >> 7) & 0xf;
69
70 fprintf(stderr, "RS Block: %d texcoords (linear), %d colors (perspective)\n",
71 it_count, ic_count);
72 fprintf(stderr, "%d instructions\n", count);
73
74 for (i = 0; i < count; i++) {
75 if (rs->inst[i] & 0x10) {
76 ip = rs->inst[i] & 0xf;
77 fprintf(stderr, "texture: ip %d to psf %d\n",
78 ip, (rs->inst[i] >> 5) & 0x7f);
79
80 tex_ptr = rs->ip[ip] & 0xffffff;
81 fprintf(stderr, " : ");
82
83 j = 3;
84 do {
85 if ((tex_ptr & 0x3f) == 63) {
86 fprintf(stderr, "1.0");
87 } else if ((tex_ptr & 0x3f) == 62) {
88 fprintf(stderr, "0.0");
89 } else {
90 fprintf(stderr, "[%d]", tex_ptr & 0x3f);
91 }
92 } while (j-- && fprintf(stderr, "/"));
93 fprintf(stderr, "\n");
94 }
95
96 if (rs->inst[i] & 0x10000) {
97 ip = (rs->inst[i] >> 12) & 0xf;
98 fprintf(stderr, "color: ip %d to psf %d\n",
99 ip, (rs->inst[i] >> 18) & 0x7f);
100
101 col_ptr = (rs->ip[ip] >> 24) & 0x7;
102 col_fmt = (rs->ip[ip] >> 27) & 0xf;
103 fprintf(stderr, " : offset %d ", col_ptr);
104
105 switch (col_fmt) {
106 case 0:
107 fprintf(stderr, "(R/G/B/A)");
108 break;
109 case 1:
110 fprintf(stderr, "(R/G/B/0)");
111 break;
112 case 2:
113 fprintf(stderr, "(R/G/B/1)");
114 break;
115 case 4:
116 fprintf(stderr, "(0/0/0/A)");
117 break;
118 case 5:
119 fprintf(stderr, "(0/0/0/0)");
120 break;
121 case 6:
122 fprintf(stderr, "(0/0/0/1)");
123 break;
124 case 8:
125 fprintf(stderr, "(1/1/1/A)");
126 break;
127 case 9:
128 fprintf(stderr, "(1/1/1/0)");
129 break;
130 case 10:
131 fprintf(stderr, "(1/1/1/1)");
132 break;
133 }
134 fprintf(stderr, "\n");
135 }
136 }
137 }