• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         { "qpu",         V3D_DEBUG_QPU},
45         { "vir",         V3D_DEBUG_VIR},
46         { "nir",         V3D_DEBUG_NIR},
47         { "tgsi",        V3D_DEBUG_TGSI},
48         { "shaderdb",    V3D_DEBUG_SHADERDB},
49         { "surface",     V3D_DEBUG_SURFACE},
50         { "perf",        V3D_DEBUG_PERF},
51         { "norast",      V3D_DEBUG_NORAST},
52         { "fs",          V3D_DEBUG_FS},
53         { "vs",          V3D_DEBUG_VS},
54         { "cs",          V3D_DEBUG_CS},
55         { NULL,    0 }
56 };
57 
58 uint32_t
v3d_debug_flag_for_shader_stage(gl_shader_stage stage)59 v3d_debug_flag_for_shader_stage(gl_shader_stage stage)
60 {
61         uint32_t flags[] = {
62                 [MESA_SHADER_VERTEX] = V3D_DEBUG_VS,
63                 [MESA_SHADER_TESS_CTRL] = 0,
64                 [MESA_SHADER_TESS_EVAL] = 0,
65                 [MESA_SHADER_GEOMETRY] = 0,
66                 [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS,
67                 [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS,
68         };
69         STATIC_ASSERT(MESA_SHADER_STAGES == 6);
70         return flags[stage];
71 }
72 
73 static void
v3d_process_debug_variable_once(void)74 v3d_process_debug_variable_once(void)
75 {
76         V3D_DEBUG = parse_debug_string(getenv("V3D_DEBUG"), debug_control);
77 
78         if (V3D_DEBUG & V3D_DEBUG_SHADERDB)
79                 V3D_DEBUG |= V3D_DEBUG_NORAST;
80 }
81 
82 void
v3d_process_debug_variable(void)83 v3d_process_debug_variable(void)
84 {
85         static once_flag v3d_process_debug_variable_flag = ONCE_FLAG_INIT;
86 
87         call_once(&v3d_process_debug_variable_flag,
88                   v3d_process_debug_variable_once);
89 }
90