1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2009 Nicolai Haehnle <nhaehnle@gmail.com>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci#include "r300_context.h"
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#include "util/u_debug.h"
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <stdio.h>
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_cistatic const struct debug_named_value r300_debug_options[] = {
30bf215546Sopenharmony_ci    { "info", DBG_INFO, "Print hardware info (printed by default on debug builds"},
31bf215546Sopenharmony_ci    { "fp", DBG_FP, "Log fragment program compilation" },
32bf215546Sopenharmony_ci    { "vp", DBG_VP, "Log vertex program compilation" },
33bf215546Sopenharmony_ci    { "draw", DBG_DRAW, "Log draw calls" },
34bf215546Sopenharmony_ci    { "swtcl", DBG_SWTCL, "Log SWTCL-specific info" },
35bf215546Sopenharmony_ci    { "rsblock", DBG_RS_BLOCK, "Log rasterizer registers" },
36bf215546Sopenharmony_ci    { "psc", DBG_PSC, "Log vertex stream registers" },
37bf215546Sopenharmony_ci    { "tex", DBG_TEX, "Log basic info about textures" },
38bf215546Sopenharmony_ci    { "texalloc", DBG_TEXALLOC, "Log texture mipmap tree info" },
39bf215546Sopenharmony_ci    { "rs", DBG_RS, "Log rasterizer" },
40bf215546Sopenharmony_ci    { "fb", DBG_FB, "Log framebuffer" },
41bf215546Sopenharmony_ci    { "cbzb", DBG_CBZB, "Log fast color clear info" },
42bf215546Sopenharmony_ci    { "hyperz", DBG_HYPERZ, "Log HyperZ info" },
43bf215546Sopenharmony_ci    { "scissor", DBG_SCISSOR, "Log scissor info" },
44bf215546Sopenharmony_ci    { "msaa", DBG_MSAA, "Log MSAA resources"},
45bf215546Sopenharmony_ci    { "anisohq", DBG_ANISOHQ, "Use high quality anisotropic filtering" },
46bf215546Sopenharmony_ci    { "notiling", DBG_NO_TILING, "Disable tiling" },
47bf215546Sopenharmony_ci    { "noimmd", DBG_NO_IMMD, "Disable immediate mode" },
48bf215546Sopenharmony_ci    { "noopt", DBG_NO_OPT, "Disable shader optimizations" },
49bf215546Sopenharmony_ci    { "nocbzb", DBG_NO_CBZB, "Disable fast color clear" },
50bf215546Sopenharmony_ci    { "nozmask", DBG_NO_ZMASK, "Disable zbuffer compression" },
51bf215546Sopenharmony_ci    { "nohiz", DBG_NO_HIZ, "Disable hierarchical zbuffer" },
52bf215546Sopenharmony_ci    { "nocmask", DBG_NO_CMASK, "Disable AA compression and fast AA clear" },
53bf215546Sopenharmony_ci    { "use_tgsi", DBG_USE_TGSI, "Request TGSI shaders from the state tracker" },
54bf215546Sopenharmony_ci    { "notcl", DBG_NO_TCL, "Disable hardware accelerated Transform/Clip/Lighting" },
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci    /* must be last */
57bf215546Sopenharmony_ci    DEBUG_NAMED_VALUE_END
58bf215546Sopenharmony_ci};
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_civoid r300_init_debug(struct r300_screen * screen)
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci    screen->debug = debug_get_flags_option("RADEON_DEBUG", r300_debug_options, 0);
63bf215546Sopenharmony_ci}
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_civoid r500_dump_rs_block(struct r300_rs_block *rs)
66bf215546Sopenharmony_ci{
67bf215546Sopenharmony_ci    unsigned count, ip, it_count, ic_count, i, j;
68bf215546Sopenharmony_ci    unsigned tex_ptr;
69bf215546Sopenharmony_ci    unsigned col_ptr, col_fmt;
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci    count = rs->inst_count & 0xf;
72bf215546Sopenharmony_ci    count++;
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci    it_count = rs->count & 0x7f;
75bf215546Sopenharmony_ci    ic_count = (rs->count >> 7) & 0xf;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci    fprintf(stderr, "RS Block: %d texcoords (linear), %d colors (perspective)\n",
78bf215546Sopenharmony_ci        it_count, ic_count);
79bf215546Sopenharmony_ci    fprintf(stderr, "%d instructions\n", count);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci    for (i = 0; i < count; i++) {
82bf215546Sopenharmony_ci        if (rs->inst[i] & 0x10) {
83bf215546Sopenharmony_ci            ip = rs->inst[i] & 0xf;
84bf215546Sopenharmony_ci            fprintf(stderr, "texture: ip %d to psf %d\n",
85bf215546Sopenharmony_ci                ip, (rs->inst[i] >> 5) & 0x7f);
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci            tex_ptr = rs->ip[ip] & 0xffffff;
88bf215546Sopenharmony_ci            fprintf(stderr, "       : ");
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci            j = 3;
91bf215546Sopenharmony_ci            do {
92bf215546Sopenharmony_ci                if ((tex_ptr & 0x3f) == 63) {
93bf215546Sopenharmony_ci                    fprintf(stderr, "1.0");
94bf215546Sopenharmony_ci                } else if ((tex_ptr & 0x3f) == 62) {
95bf215546Sopenharmony_ci                    fprintf(stderr, "0.0");
96bf215546Sopenharmony_ci                } else {
97bf215546Sopenharmony_ci                    fprintf(stderr, "[%d]", tex_ptr & 0x3f);
98bf215546Sopenharmony_ci                }
99bf215546Sopenharmony_ci            } while (j-- && fprintf(stderr, "/"));
100bf215546Sopenharmony_ci            fprintf(stderr, "\n");
101bf215546Sopenharmony_ci        }
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci        if (rs->inst[i] & 0x10000) {
104bf215546Sopenharmony_ci            ip = (rs->inst[i] >> 12) & 0xf;
105bf215546Sopenharmony_ci            fprintf(stderr, "color: ip %d to psf %d\n",
106bf215546Sopenharmony_ci                ip, (rs->inst[i] >> 18) & 0x7f);
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci            col_ptr = (rs->ip[ip] >> 24) & 0x7;
109bf215546Sopenharmony_ci            col_fmt = (rs->ip[ip] >> 27) & 0xf;
110bf215546Sopenharmony_ci            fprintf(stderr, "     : offset %d ", col_ptr);
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci            switch (col_fmt) {
113bf215546Sopenharmony_ci                case 0:
114bf215546Sopenharmony_ci                    fprintf(stderr, "(R/G/B/A)");
115bf215546Sopenharmony_ci                    break;
116bf215546Sopenharmony_ci                case 1:
117bf215546Sopenharmony_ci                    fprintf(stderr, "(R/G/B/0)");
118bf215546Sopenharmony_ci                    break;
119bf215546Sopenharmony_ci                case 2:
120bf215546Sopenharmony_ci                    fprintf(stderr, "(R/G/B/1)");
121bf215546Sopenharmony_ci                    break;
122bf215546Sopenharmony_ci                case 4:
123bf215546Sopenharmony_ci                    fprintf(stderr, "(0/0/0/A)");
124bf215546Sopenharmony_ci                    break;
125bf215546Sopenharmony_ci                case 5:
126bf215546Sopenharmony_ci                    fprintf(stderr, "(0/0/0/0)");
127bf215546Sopenharmony_ci                    break;
128bf215546Sopenharmony_ci                case 6:
129bf215546Sopenharmony_ci                    fprintf(stderr, "(0/0/0/1)");
130bf215546Sopenharmony_ci                    break;
131bf215546Sopenharmony_ci                case 8:
132bf215546Sopenharmony_ci                    fprintf(stderr, "(1/1/1/A)");
133bf215546Sopenharmony_ci                    break;
134bf215546Sopenharmony_ci                case 9:
135bf215546Sopenharmony_ci                    fprintf(stderr, "(1/1/1/0)");
136bf215546Sopenharmony_ci                    break;
137bf215546Sopenharmony_ci                case 10:
138bf215546Sopenharmony_ci                    fprintf(stderr, "(1/1/1/1)");
139bf215546Sopenharmony_ci                    break;
140bf215546Sopenharmony_ci            }
141bf215546Sopenharmony_ci            fprintf(stderr, "\n");
142bf215546Sopenharmony_ci        }
143bf215546Sopenharmony_ci    }
144bf215546Sopenharmony_ci}
145