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_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", V3D_DEBUG_SHADERDB,
58 "Dump program compile information for shader-db analysis" },
59 { "surface", V3D_DEBUG_SURFACE,
60 /* FIXME: evaluate to implement it on v3dv */
61 "Print resource layout information (v3d only)" },
62 { "perf", V3D_DEBUG_PERF,
63 "Print performance-related events during runtime" },
64 { "norast", V3D_DEBUG_NORAST,
65 /* FIXME: evaluate to implement on v3dv*/
66 "Skip actual hardware execution of commands (v3d only)" },
67 { "fs", V3D_DEBUG_FS,
68 "Dump fragment shaders" },
69 { "gs", V3D_DEBUG_GS,
70 "Dump geometry shaders" },
71 { "vs", V3D_DEBUG_VS,
72 "Dump vertex shaders" },
73 { "cs", V3D_DEBUG_CS,
74 "Dump computer shaders" },
75 { "always_flush", V3D_DEBUG_ALWAYS_FLUSH,
76 "Flush after each draw call" },
77 { "precompile", V3D_DEBUG_PRECOMPILE,
78 "Precompiles shader variant at shader state creation time (v3d only)" },
79 { "ra", V3D_DEBUG_RA,
80 "Dump register allocation failures" },
81 { "dump_spirv", V3D_DEBUG_DUMP_SPIRV,
82 "Dump SPIR-V code (v3dv only)" },
83 { "tmu32", V3D_DEBUG_TMU_32BIT,
84 "Force 32-bit precision on all TMU operations" },
85 /* This can lead to incorrect behavior for applications that do
86 * require full 32-bit precision, but can improve performance
87 * for those that don't.
88 */
89 { "tmu16", V3D_DEBUG_TMU_16BIT,
90 "Force 16-bit precision on all TMU operations" },
91 { "noloopunroll", V3D_DEBUG_NO_LOOP_UNROLL,
92 "Disable loop unrolling" },
93 { "db", V3D_DEBUG_DOUBLE_BUFFER,
94 "Enable double buffer for Tile Buffer when MSAA is disabled" },
95 #ifdef ENABLE_SHADER_CACHE
96 { "cache", V3D_DEBUG_CACHE,
97 "Print on-disk cache events (only with cache enabled)" },
98 #endif
99 { "no_merge_jobs", V3D_DEBUG_NO_MERGE_JOBS,
100 "Don't try to merge subpasses in the same job even if they share framebuffer configuration (v3dv only)" },
101 { NULL }
102 };
103
104 DEBUG_GET_ONCE_FLAGS_OPTION(v3d_debug, "V3D_DEBUG", debug_control, 0)
105
106 uint32_t
v3d_debug_flag_for_shader_stage(gl_shader_stage stage)107 v3d_debug_flag_for_shader_stage(gl_shader_stage stage)
108 {
109 uint32_t flags[] = {
110 [MESA_SHADER_VERTEX] = V3D_DEBUG_VS,
111 [MESA_SHADER_TESS_CTRL] = 0,
112 [MESA_SHADER_TESS_EVAL] = 0,
113 [MESA_SHADER_GEOMETRY] = V3D_DEBUG_GS,
114 [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS,
115 [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS,
116 };
117 STATIC_ASSERT(MESA_SHADER_STAGES == 6);
118 return flags[stage];
119 }
120
121 void
v3d_process_debug_variable(void)122 v3d_process_debug_variable(void)
123 {
124 V3D_DEBUG = debug_get_option_v3d_debug();
125 }
126