• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2003 VMware, Inc.
3  * Copyright © 2006 Intel Corporation
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 /**
26  * \file intel_debug.c
27  *
28  * Support for the INTEL_DEBUG environment variable, along with other
29  * miscellaneous debugging code.
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #include "dev/intel_debug.h"
37 #include "util/macros.h"
38 #include "util/u_debug.h"
39 #include "util/u_math.h"
40 #include "c11/threads.h"
41 
42 uint64_t intel_debug = 0;
43 
44 #define DEBUG_NO16                (1ull << 16)
45 #define DEBUG_NO8                 (1ull << 20)
46 #define DEBUG_NO32                (1ull << 39)
47 
48 static const struct debug_control debug_control[] = {
49    { "tex",         DEBUG_TEXTURE},
50    { "blit",        DEBUG_BLIT},
51    { "fall",        DEBUG_PERF},
52    { "perf",        DEBUG_PERF},
53    { "perfmon",     DEBUG_PERFMON},
54    { "bat",         DEBUG_BATCH},
55    { "buf",         DEBUG_BUFMGR},
56    { "fs",          DEBUG_WM },
57    { "gs",          DEBUG_GS},
58    { "sync",        DEBUG_SYNC},
59    { "sf",          DEBUG_SF },
60    { "submit",      DEBUG_SUBMIT },
61    { "wm",          DEBUG_WM },
62    { "urb",         DEBUG_URB },
63    { "vs",          DEBUG_VS },
64    { "clip",        DEBUG_CLIP },
65    { "no16",        DEBUG_NO16 },
66    { "blorp",       DEBUG_BLORP },
67    { "nodualobj",   DEBUG_NO_DUAL_OBJECT_GS },
68    { "optimizer",   DEBUG_OPTIMIZER },
69    { "ann",         DEBUG_ANNOTATION },
70    { "no8",         DEBUG_NO8 },
71    { "no-oaconfig", DEBUG_NO_OACONFIG },
72    { "spill_fs",    DEBUG_SPILL_FS },
73    { "spill_vec4",  DEBUG_SPILL_VEC4 },
74    { "cs",          DEBUG_CS },
75    { "hex",         DEBUG_HEX },
76    { "nocompact",   DEBUG_NO_COMPACTION },
77    { "hs",          DEBUG_TCS },
78    { "tcs",         DEBUG_TCS },
79    { "ds",          DEBUG_TES },
80    { "tes",         DEBUG_TES },
81    { "l3",          DEBUG_L3 },
82    { "do32",        DEBUG_DO32 },
83    { "norbc",       DEBUG_NO_CCS },
84    { "noccs",       DEBUG_NO_CCS },
85    { "nohiz",       DEBUG_NO_HIZ },
86    { "color",       DEBUG_COLOR },
87    { "reemit",      DEBUG_REEMIT },
88    { "soft64",      DEBUG_SOFT64 },
89    { "bt",          DEBUG_BT },
90    { "pc",          DEBUG_PIPE_CONTROL },
91    { "nofc",        DEBUG_NO_FAST_CLEAR },
92    { "no32",        DEBUG_NO32 },
93    { "shaders",     DEBUG_WM | DEBUG_VS | DEBUG_TCS |
94                     DEBUG_TES | DEBUG_GS | DEBUG_CS |
95                     DEBUG_RT | DEBUG_TASK | DEBUG_MESH },
96    { "rt",          DEBUG_RT },
97    { "bvh_blas",    DEBUG_BVH_BLAS},
98    { "bvh_tlas",    DEBUG_BVH_TLAS},
99    { "bvh_blas_ir_hdr", DEBUG_BVH_BLAS_IR_HDR},
100    { "bvh_tlas_ir_hdr", DEBUG_BVH_TLAS_IR_HDR},
101    { "bvh_blas_ir_as",  DEBUG_BVH_BLAS_IR_AS},
102    { "bvh_tlas_ir_as",  DEBUG_BVH_TLAS_IR_AS},
103    { "bvh_no_build",    DEBUG_BVH_NO_BUILD},
104    { "task",        DEBUG_TASK },
105    { "mesh",        DEBUG_MESH },
106    { "stall",       DEBUG_STALL },
107    { "capture-all", DEBUG_CAPTURE_ALL },
108    { "perf-symbol-names", DEBUG_PERF_SYMBOL_NAMES },
109    { "swsb-stall",  DEBUG_SWSB_STALL },
110    { "heaps",       DEBUG_HEAPS },
111    { "isl",         DEBUG_ISL },
112    { "sparse",      DEBUG_SPARSE },
113    { "draw_bkp",    DEBUG_DRAW_BKP },
114    { "bat-stats",   DEBUG_BATCH_STATS },
115    { "reg-pressure", DEBUG_REG_PRESSURE },
116    { "shader-print", DEBUG_SHADER_PRINT },
117    { "cl-quiet",     DEBUG_CL_QUIET },
118    { NULL,    0 }
119 };
120 
121 uint64_t intel_simd = 0;
122 
123 static const struct debug_control simd_control[] = {
124    { "fs8",    DEBUG_FS_SIMD8 },
125    { "fs16",   DEBUG_FS_SIMD16 },
126    { "fs32",   DEBUG_FS_SIMD32 },
127    { "fs2x8",  DEBUG_FS_SIMD2X8 },
128    { "fs4x8",  DEBUG_FS_SIMD4X8 },
129    { "fs2x16", DEBUG_FS_SIMD2X16 },
130    { "cs8",    DEBUG_CS_SIMD8 },
131    { "cs16",   DEBUG_CS_SIMD16 },
132    { "cs32",   DEBUG_CS_SIMD32 },
133    { "ts8",    DEBUG_TS_SIMD8 },
134    { "ts16",   DEBUG_TS_SIMD16 },
135    { "ts32",   DEBUG_TS_SIMD32 },
136    { "ms8",    DEBUG_MS_SIMD8 },
137    { "ms16",   DEBUG_MS_SIMD16 },
138    { "ms32",   DEBUG_MS_SIMD32 },
139    { "rt8",    DEBUG_RT_SIMD8 },
140    { "rt16",   DEBUG_RT_SIMD16 },
141    { "rt32",   DEBUG_RT_SIMD32 },
142    { NULL,     0 }
143 };
144 
145 uint64_t
intel_debug_flag_for_shader_stage(gl_shader_stage stage)146 intel_debug_flag_for_shader_stage(gl_shader_stage stage)
147 {
148    uint64_t flags[] = {
149       [MESA_SHADER_VERTEX] = DEBUG_VS,
150       [MESA_SHADER_TESS_CTRL] = DEBUG_TCS,
151       [MESA_SHADER_TESS_EVAL] = DEBUG_TES,
152       [MESA_SHADER_GEOMETRY] = DEBUG_GS,
153       [MESA_SHADER_FRAGMENT] = DEBUG_WM,
154       [MESA_SHADER_COMPUTE] = DEBUG_CS,
155       [MESA_SHADER_KERNEL] = DEBUG_CS,
156 
157       [MESA_SHADER_TASK]         = DEBUG_TASK,
158       [MESA_SHADER_MESH]         = DEBUG_MESH,
159 
160       [MESA_SHADER_RAYGEN]       = DEBUG_RT,
161       [MESA_SHADER_ANY_HIT]      = DEBUG_RT,
162       [MESA_SHADER_CLOSEST_HIT]  = DEBUG_RT,
163       [MESA_SHADER_MISS]         = DEBUG_RT,
164       [MESA_SHADER_INTERSECTION] = DEBUG_RT,
165       [MESA_SHADER_CALLABLE]     = DEBUG_RT,
166    };
167    return flags[stage];
168 }
169 
170 #define DEBUG_FS_SIMD  (DEBUG_FS_SIMD8  | DEBUG_FS_SIMD16  | \
171                         DEBUG_FS_SIMD32)
172 #define DEBUG_CS_SIMD  (DEBUG_CS_SIMD8  | DEBUG_CS_SIMD16  | DEBUG_CS_SIMD32)
173 #define DEBUG_TS_SIMD  (DEBUG_TS_SIMD8  | DEBUG_TS_SIMD16  | DEBUG_TS_SIMD32)
174 #define DEBUG_MS_SIMD  (DEBUG_MS_SIMD8  | DEBUG_MS_SIMD16  | DEBUG_MS_SIMD32)
175 #define DEBUG_RT_SIMD  (DEBUG_RT_SIMD8  | DEBUG_RT_SIMD16  | DEBUG_RT_SIMD32)
176 
177 #define DEBUG_SIMD8_ALL \
178    (DEBUG_FS_SIMD8  | \
179     DEBUG_CS_SIMD8  | \
180     DEBUG_TS_SIMD8  | \
181     DEBUG_MS_SIMD8  | \
182     DEBUG_RT_SIMD8)
183 
184 #define DEBUG_SIMD16_ALL \
185    (DEBUG_FS_SIMD16 | \
186     DEBUG_CS_SIMD16 | \
187     DEBUG_TS_SIMD16 | \
188     DEBUG_MS_SIMD16 | \
189     DEBUG_RT_SIMD16)
190 
191 #define DEBUG_SIMD32_ALL \
192    (DEBUG_FS_SIMD32 | \
193     DEBUG_CS_SIMD32 | \
194     DEBUG_TS_SIMD32 | \
195     DEBUG_MS_SIMD32 | \
196     DEBUG_RT_SIMD32)
197 
198 uint64_t intel_debug_batch_frame_start = 0;
199 uint64_t intel_debug_batch_frame_stop = -1;
200 
201 uint32_t intel_debug_bkp_before_draw_count = 0;
202 uint32_t intel_debug_bkp_after_draw_count = 0;
203 
204 static void
process_intel_debug_variable_once(void)205 process_intel_debug_variable_once(void)
206 {
207    intel_debug = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);
208    intel_simd = parse_debug_string(getenv("INTEL_SIMD_DEBUG"), simd_control);
209    intel_debug_batch_frame_start =
210       debug_get_num_option("INTEL_DEBUG_BATCH_FRAME_START", 0);
211    intel_debug_batch_frame_stop =
212       debug_get_num_option("INTEL_DEBUG_BATCH_FRAME_STOP", -1);
213 
214    intel_debug_bkp_before_draw_count =
215       debug_get_num_option("INTEL_DEBUG_BKP_BEFORE_DRAW_COUNT", 0);
216    intel_debug_bkp_after_draw_count =
217       debug_get_num_option("INTEL_DEBUG_BKP_AFTER_DRAW_COUNT", 0);
218 
219    if (!(intel_simd & DEBUG_FS_SIMD))
220       intel_simd |=   DEBUG_FS_SIMD;
221    if (!(intel_simd & DEBUG_CS_SIMD))
222       intel_simd |=   DEBUG_CS_SIMD;
223    if (!(intel_simd & DEBUG_TS_SIMD))
224       intel_simd |=   DEBUG_TS_SIMD;
225    if (!(intel_simd & DEBUG_MS_SIMD))
226       intel_simd |=   DEBUG_MS_SIMD;
227    if (!(intel_simd & DEBUG_RT_SIMD))
228       intel_simd |=   DEBUG_RT_SIMD;
229 
230    if (intel_debug & DEBUG_NO8)
231       intel_simd &= ~DEBUG_SIMD8_ALL;
232    if (intel_debug & DEBUG_NO16)
233       intel_simd &= ~DEBUG_SIMD16_ALL;
234    if (intel_debug & DEBUG_NO32)
235       intel_simd &= ~DEBUG_SIMD32_ALL;
236    intel_debug &= ~(DEBUG_NO8 | DEBUG_NO16 | DEBUG_NO32);
237 }
238 
239 void
process_intel_debug_variable(void)240 process_intel_debug_variable(void)
241 {
242    static once_flag process_intel_debug_variable_flag = ONCE_FLAG_INIT;
243 
244    call_once(&process_intel_debug_variable_flag,
245              process_intel_debug_variable_once);
246 }
247