• 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    { "no-send-gather", DEBUG_NO_SEND_GATHER },
119    { NULL,    0 }
120 };
121 
122 uint64_t intel_simd = 0;
123 
124 static const struct debug_control simd_control[] = {
125    { "fs8",    DEBUG_FS_SIMD8 },
126    { "fs16",   DEBUG_FS_SIMD16 },
127    { "fs32",   DEBUG_FS_SIMD32 },
128    { "fs2x8",  DEBUG_FS_SIMD2X8 },
129    { "fs4x8",  DEBUG_FS_SIMD4X8 },
130    { "fs2x16", DEBUG_FS_SIMD2X16 },
131    { "cs8",    DEBUG_CS_SIMD8 },
132    { "cs16",   DEBUG_CS_SIMD16 },
133    { "cs32",   DEBUG_CS_SIMD32 },
134    { "ts8",    DEBUG_TS_SIMD8 },
135    { "ts16",   DEBUG_TS_SIMD16 },
136    { "ts32",   DEBUG_TS_SIMD32 },
137    { "ms8",    DEBUG_MS_SIMD8 },
138    { "ms16",   DEBUG_MS_SIMD16 },
139    { "ms32",   DEBUG_MS_SIMD32 },
140    { "rt8",    DEBUG_RT_SIMD8 },
141    { "rt16",   DEBUG_RT_SIMD16 },
142    { "rt32",   DEBUG_RT_SIMD32 },
143    { NULL,     0 }
144 };
145 
146 uint64_t
intel_debug_flag_for_shader_stage(gl_shader_stage stage)147 intel_debug_flag_for_shader_stage(gl_shader_stage stage)
148 {
149    uint64_t flags[] = {
150       [MESA_SHADER_VERTEX] = DEBUG_VS,
151       [MESA_SHADER_TESS_CTRL] = DEBUG_TCS,
152       [MESA_SHADER_TESS_EVAL] = DEBUG_TES,
153       [MESA_SHADER_GEOMETRY] = DEBUG_GS,
154       [MESA_SHADER_FRAGMENT] = DEBUG_WM,
155       [MESA_SHADER_COMPUTE] = DEBUG_CS,
156       [MESA_SHADER_KERNEL] = DEBUG_CS,
157 
158       [MESA_SHADER_TASK]         = DEBUG_TASK,
159       [MESA_SHADER_MESH]         = DEBUG_MESH,
160 
161       [MESA_SHADER_RAYGEN]       = DEBUG_RT,
162       [MESA_SHADER_ANY_HIT]      = DEBUG_RT,
163       [MESA_SHADER_CLOSEST_HIT]  = DEBUG_RT,
164       [MESA_SHADER_MISS]         = DEBUG_RT,
165       [MESA_SHADER_INTERSECTION] = DEBUG_RT,
166       [MESA_SHADER_CALLABLE]     = DEBUG_RT,
167    };
168    return flags[stage];
169 }
170 
171 #define DEBUG_FS_SIMD  (DEBUG_FS_SIMD8  | DEBUG_FS_SIMD16  | \
172                         DEBUG_FS_SIMD32)
173 #define DEBUG_CS_SIMD  (DEBUG_CS_SIMD8  | DEBUG_CS_SIMD16  | DEBUG_CS_SIMD32)
174 #define DEBUG_TS_SIMD  (DEBUG_TS_SIMD8  | DEBUG_TS_SIMD16  | DEBUG_TS_SIMD32)
175 #define DEBUG_MS_SIMD  (DEBUG_MS_SIMD8  | DEBUG_MS_SIMD16  | DEBUG_MS_SIMD32)
176 #define DEBUG_RT_SIMD  (DEBUG_RT_SIMD8  | DEBUG_RT_SIMD16  | DEBUG_RT_SIMD32)
177 
178 #define DEBUG_SIMD8_ALL \
179    (DEBUG_FS_SIMD8  | \
180     DEBUG_CS_SIMD8  | \
181     DEBUG_TS_SIMD8  | \
182     DEBUG_MS_SIMD8  | \
183     DEBUG_RT_SIMD8)
184 
185 #define DEBUG_SIMD16_ALL \
186    (DEBUG_FS_SIMD16 | \
187     DEBUG_CS_SIMD16 | \
188     DEBUG_TS_SIMD16 | \
189     DEBUG_MS_SIMD16 | \
190     DEBUG_RT_SIMD16)
191 
192 #define DEBUG_SIMD32_ALL \
193    (DEBUG_FS_SIMD32 | \
194     DEBUG_CS_SIMD32 | \
195     DEBUG_TS_SIMD32 | \
196     DEBUG_MS_SIMD32 | \
197     DEBUG_RT_SIMD32)
198 
199 uint64_t intel_debug_batch_frame_start = 0;
200 uint64_t intel_debug_batch_frame_stop = -1;
201 
202 uint32_t intel_debug_bkp_before_draw_count = 0;
203 uint32_t intel_debug_bkp_after_draw_count = 0;
204 
205 static void
process_intel_debug_variable_once(void)206 process_intel_debug_variable_once(void)
207 {
208    intel_debug = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);
209    intel_simd = parse_debug_string(getenv("INTEL_SIMD_DEBUG"), simd_control);
210    intel_debug_batch_frame_start =
211       debug_get_num_option("INTEL_DEBUG_BATCH_FRAME_START", 0);
212    intel_debug_batch_frame_stop =
213       debug_get_num_option("INTEL_DEBUG_BATCH_FRAME_STOP", -1);
214 
215    intel_debug_bkp_before_draw_count =
216       debug_get_num_option("INTEL_DEBUG_BKP_BEFORE_DRAW_COUNT", 0);
217    intel_debug_bkp_after_draw_count =
218       debug_get_num_option("INTEL_DEBUG_BKP_AFTER_DRAW_COUNT", 0);
219 
220    if (!(intel_simd & DEBUG_FS_SIMD))
221       intel_simd |=   DEBUG_FS_SIMD;
222    if (!(intel_simd & DEBUG_CS_SIMD))
223       intel_simd |=   DEBUG_CS_SIMD;
224    if (!(intel_simd & DEBUG_TS_SIMD))
225       intel_simd |=   DEBUG_TS_SIMD;
226    if (!(intel_simd & DEBUG_MS_SIMD))
227       intel_simd |=   DEBUG_MS_SIMD;
228    if (!(intel_simd & DEBUG_RT_SIMD))
229       intel_simd |=   DEBUG_RT_SIMD;
230 
231    if (intel_debug & DEBUG_NO8)
232       intel_simd &= ~DEBUG_SIMD8_ALL;
233    if (intel_debug & DEBUG_NO16)
234       intel_simd &= ~DEBUG_SIMD16_ALL;
235    if (intel_debug & DEBUG_NO32)
236       intel_simd &= ~DEBUG_SIMD32_ALL;
237    intel_debug &= ~(DEBUG_NO8 | DEBUG_NO16 | DEBUG_NO32);
238 }
239 
240 void
process_intel_debug_variable(void)241 process_intel_debug_variable(void)
242 {
243    static once_flag process_intel_debug_variable_flag = ONCE_FLAG_INIT;
244 
245    call_once(&process_intel_debug_variable_flag,
246              process_intel_debug_variable_once);
247 }
248