v3d: Add a "precompile" debug flag for shader-db.
[mesa.git] / src / broadcom / common / v3d_debug.c
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/debug.h"
38 #include "c11/threads.h"
39
40 uint32_t V3D_DEBUG = 0;
41
42 static const struct debug_control debug_control[] = {
43 { "cl", V3D_DEBUG_CL},
44 { "clif", V3D_DEBUG_CLIF},
45 { "qpu", V3D_DEBUG_QPU},
46 { "vir", V3D_DEBUG_VIR},
47 { "nir", V3D_DEBUG_NIR},
48 { "tgsi", V3D_DEBUG_TGSI},
49 { "shaderdb", V3D_DEBUG_SHADERDB},
50 { "surface", V3D_DEBUG_SURFACE},
51 { "perf", V3D_DEBUG_PERF},
52 { "norast", V3D_DEBUG_NORAST},
53 { "fs", V3D_DEBUG_FS},
54 { "vs", V3D_DEBUG_VS},
55 { "cs", V3D_DEBUG_CS},
56 { "always_flush", V3D_DEBUG_ALWAYS_FLUSH},
57 { "precompile", V3D_DEBUG_PRECOMPILE},
58 { NULL, 0 }
59 };
60
61 uint32_t
62 v3d_debug_flag_for_shader_stage(gl_shader_stage stage)
63 {
64 uint32_t flags[] = {
65 [MESA_SHADER_VERTEX] = V3D_DEBUG_VS,
66 [MESA_SHADER_TESS_CTRL] = 0,
67 [MESA_SHADER_TESS_EVAL] = 0,
68 [MESA_SHADER_GEOMETRY] = 0,
69 [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS,
70 [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS,
71 };
72 STATIC_ASSERT(MESA_SHADER_STAGES == 6);
73 return flags[stage];
74 }
75
76 static void
77 v3d_process_debug_variable_once(void)
78 {
79 V3D_DEBUG = parse_debug_string(getenv("V3D_DEBUG"), debug_control);
80
81 if (V3D_DEBUG & V3D_DEBUG_SHADERDB)
82 V3D_DEBUG |= V3D_DEBUG_NORAST;
83 }
84
85 void
86 v3d_process_debug_variable(void)
87 {
88 static once_flag v3d_process_debug_variable_flag = ONCE_FLAG_INIT;
89
90 call_once(&v3d_process_debug_variable_flag,
91 v3d_process_debug_variable_once);
92 }