xref: /aosp_15_r20/external/mesa3d/src/broadcom/common/v3d_debug.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2003 VMware, Inc.
3  * Copyright © 2006 Intel Corporation
4  * Copyright © 2017 Broadcom
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23  * IN THE SOFTWARE.
24  */
25 
26 /**
27  * \file v3d_debug.c
28  *
29  * Support for the V3D_DEBUG environment variable, along with other
30  * miscellaneous debugging code.
31  */
32 
33 #include <stdlib.h>
34 
35 #include "common/v3d_debug.h"
36 #include "util/macros.h"
37 #include "util/u_debug.h"
38 #include "c11/threads.h"
39 
40 uint32_t v3d_mesa_debug = 0;
41 
42 static const struct debug_named_value debug_control[] = {
43         { "cl",          V3D_DEBUG_CL,
44           "Dump command list during creation" },
45         { "cl_nobin",    V3D_DEBUG_CL_NO_BIN,
46           "Dump command list during creation, excluding binary resources" },
47         { "clif",        V3D_DEBUG_CLIF,
48           "Dump command list (CLIF format) during creation", },
49         { "qpu",         V3D_DEBUG_QPU,
50           "Dump generated QPU instructions" },
51         { "vir",         V3D_DEBUG_VIR,
52           "Dump VIR during program compile" },
53         { "nir",         V3D_DEBUG_NIR,
54           "Dump NIR during program compile" },
55         { "tgsi",        V3D_DEBUG_TGSI,
56           "Dump TGSI during program compile (v3d only)" },
57         /* `shaderdb` is *not* used by shader-db, but is here so that any other
58          * game/app can dump its stats in the shader-db format, allowing them
59          * to be compared using shader-db's report.py tool.
60          */
61         { "shaderdb",    V3D_DEBUG_SHADERDB,
62           "Dump program compile information for shader-db analysis" },
63         { "surface",     V3D_DEBUG_SURFACE,
64           /* FIXME: evaluate to implement it on v3dv */
65           "Print resource layout information (v3d only)" },
66         { "perf",        V3D_DEBUG_PERF,
67           "Print performance-related events during runtime" },
68         { "norast",      V3D_DEBUG_NORAST,
69           /* FIXME: evaluate to implement on v3dv*/
70           "Skip actual hardware execution of commands (v3d only)" },
71         { "fs",          V3D_DEBUG_FS,
72           "Dump fragment shaders" },
73         { "gs",          V3D_DEBUG_GS,
74           "Dump geometry shaders" },
75         { "vs",          V3D_DEBUG_VS,
76           "Dump vertex shaders" },
77         { "cs",          V3D_DEBUG_CS,
78           "Dump computer shaders" },
79         { "always_flush", V3D_DEBUG_ALWAYS_FLUSH,
80           "Flush after each draw call" },
81         { "precompile",  V3D_DEBUG_PRECOMPILE,
82           "Precompiles shader variant at shader state creation time (v3d only)" },
83         { "ra",          V3D_DEBUG_RA,
84           "Dump register allocation failures" },
85         { "tmu32",  V3D_DEBUG_TMU_32BIT,
86           "Force 32-bit precision on all TMU operations" },
87         /* This can lead to incorrect behavior for applications that do
88          * require full 32-bit precision, but can improve performance
89          * for those that don't.
90          */
91         { "tmu16",  V3D_DEBUG_TMU_16BIT,
92           "Force 16-bit precision on all TMU operations" },
93         { "noloopunroll",  V3D_DEBUG_NO_LOOP_UNROLL,
94           "Disable loop unrolling" },
95         { "db", V3D_DEBUG_DOUBLE_BUFFER,
96           "Enable double buffer for Tile Buffer when MSAA is disabled" },
97 #ifdef ENABLE_SHADER_CACHE
98         { "cache", V3D_DEBUG_CACHE,
99           "Print on-disk cache events (only with cache enabled)" },
100 #endif
101         { "no_merge_jobs", V3D_DEBUG_NO_MERGE_JOBS,
102           "Don't try to merge subpasses in the same job even if they share framebuffer configuration (v3dv only)" },
103         { "opt_compile_time", V3D_DEBUG_OPT_COMPILE_TIME,
104           "Don't try to reduce shader spilling, might improve compile times with expensive shaders." },
105         /* disable_tfu is v3dv only because v3d has some uses of the TFU without alternative codepaths */
106         { "disable_tfu", V3D_DEBUG_DISABLE_TFU,
107           "Disable TFU (v3dv only)" },
108         DEBUG_NAMED_VALUE_END
109 };
110 
111 DEBUG_GET_ONCE_FLAGS_OPTION(v3d_debug, "V3D_DEBUG", debug_control, 0)
112 
113 bool
v3d_debug_flag_for_shader_stage(gl_shader_stage stage)114 v3d_debug_flag_for_shader_stage(gl_shader_stage stage)
115 {
116         uint32_t flags[] = {
117                 [MESA_SHADER_VERTEX] = V3D_DEBUG_VS,
118                 [MESA_SHADER_TESS_CTRL] = 0,
119                 [MESA_SHADER_TESS_EVAL] = 0,
120                 [MESA_SHADER_GEOMETRY] = V3D_DEBUG_GS,
121                 [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS,
122                 [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS,
123         };
124         STATIC_ASSERT(MESA_SHADER_STAGES == 6);
125         return v3d_mesa_debug & flags[stage];
126 }
127 
128 void
v3d_process_debug_variable(void)129 v3d_process_debug_variable(void)
130 {
131         v3d_mesa_debug = debug_get_option_v3d_debug();
132 }
133