1b8e80941Smrg/*
2b8e80941Smrg * Copyright 2003 VMware, Inc.
3b8e80941Smrg * Copyright © 2006 Intel Corporation
4b8e80941Smrg *
5b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
7b8e80941Smrg * to deal in the Software without restriction, including without limitation
8b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
10b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
11b8e80941Smrg *
12b8e80941Smrg * The above copyright notice and this permission notice (including the next
13b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
14b8e80941Smrg * Software.
15b8e80941Smrg *
16b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22b8e80941Smrg * IN THE SOFTWARE.
23b8e80941Smrg */
24b8e80941Smrg
25b8e80941Smrg/**
26b8e80941Smrg * \file gen_debug.c
27b8e80941Smrg *
28b8e80941Smrg * Support for the INTEL_DEBUG environment variable, along with other
29b8e80941Smrg * miscellaneous debugging code.
30b8e80941Smrg */
31b8e80941Smrg
32b8e80941Smrg#include <stdlib.h>
33b8e80941Smrg
34b8e80941Smrg#include "dev/gen_debug.h"
35b8e80941Smrg#include "util/macros.h"
36b8e80941Smrg#include "util/debug.h"
37b8e80941Smrg#include "c11/threads.h"
38b8e80941Smrg
39b8e80941Smrguint64_t INTEL_DEBUG = 0;
40b8e80941Smrg
41b8e80941Smrgstatic const struct debug_control debug_control[] = {
42b8e80941Smrg   { "tex",         DEBUG_TEXTURE},
43b8e80941Smrg   { "state",       DEBUG_STATE},
44b8e80941Smrg   { "blit",        DEBUG_BLIT},
45b8e80941Smrg   { "mip",         DEBUG_MIPTREE},
46b8e80941Smrg   { "fall",        DEBUG_PERF},
47b8e80941Smrg   { "perf",        DEBUG_PERF},
48b8e80941Smrg   { "perfmon",     DEBUG_PERFMON},
49b8e80941Smrg   { "bat",         DEBUG_BATCH},
50b8e80941Smrg   { "pix",         DEBUG_PIXEL},
51b8e80941Smrg   { "buf",         DEBUG_BUFMGR},
52b8e80941Smrg   { "fbo",         DEBUG_FBO},
53b8e80941Smrg   { "fs",          DEBUG_WM },
54b8e80941Smrg   { "gs",          DEBUG_GS},
55b8e80941Smrg   { "sync",        DEBUG_SYNC},
56b8e80941Smrg   { "prim",        DEBUG_PRIMS },
57b8e80941Smrg   { "vert",        DEBUG_VERTS },
58b8e80941Smrg   { "dri",         DEBUG_DRI },
59b8e80941Smrg   { "sf",          DEBUG_SF },
60b8e80941Smrg   { "submit",      DEBUG_SUBMIT },
61b8e80941Smrg   { "wm",          DEBUG_WM },
62b8e80941Smrg   { "urb",         DEBUG_URB },
63b8e80941Smrg   { "vs",          DEBUG_VS },
64b8e80941Smrg   { "clip",        DEBUG_CLIP },
65b8e80941Smrg   { "shader_time", DEBUG_SHADER_TIME },
66b8e80941Smrg   { "no16",        DEBUG_NO16 },
67b8e80941Smrg   { "blorp",       DEBUG_BLORP },
68b8e80941Smrg   { "nodualobj",   DEBUG_NO_DUAL_OBJECT_GS },
69b8e80941Smrg   { "optimizer",   DEBUG_OPTIMIZER },
70b8e80941Smrg   { "ann",         DEBUG_ANNOTATION },
71b8e80941Smrg   { "no8",         DEBUG_NO8 },
72b8e80941Smrg   { "no-oaconfig", DEBUG_NO_OACONFIG },
73b8e80941Smrg   { "spill_fs",    DEBUG_SPILL_FS },
74b8e80941Smrg   { "spill_vec4",  DEBUG_SPILL_VEC4 },
75b8e80941Smrg   { "cs",          DEBUG_CS },
76b8e80941Smrg   { "hex",         DEBUG_HEX },
77b8e80941Smrg   { "nocompact",   DEBUG_NO_COMPACTION },
78b8e80941Smrg   { "hs",          DEBUG_TCS },
79b8e80941Smrg   { "tcs",         DEBUG_TCS },
80b8e80941Smrg   { "ds",          DEBUG_TES },
81b8e80941Smrg   { "tes",         DEBUG_TES },
82b8e80941Smrg   { "l3",          DEBUG_L3 },
83b8e80941Smrg   { "do32",        DEBUG_DO32 },
84b8e80941Smrg   { "norbc",       DEBUG_NO_RBC },
85b8e80941Smrg   { "nohiz",       DEBUG_NO_HIZ },
86b8e80941Smrg   { "color",       DEBUG_COLOR },
87b8e80941Smrg   { "reemit",      DEBUG_REEMIT },
88b8e80941Smrg   { "soft64",      DEBUG_SOFT64 },
89b8e80941Smrg   { NULL,    0 }
90b8e80941Smrg};
91b8e80941Smrg
92b8e80941Smrguint64_t
93b8e80941Smrgintel_debug_flag_for_shader_stage(gl_shader_stage stage)
94b8e80941Smrg{
95b8e80941Smrg   uint64_t flags[] = {
96b8e80941Smrg      [MESA_SHADER_VERTEX] = DEBUG_VS,
97b8e80941Smrg      [MESA_SHADER_TESS_CTRL] = DEBUG_TCS,
98b8e80941Smrg      [MESA_SHADER_TESS_EVAL] = DEBUG_TES,
99b8e80941Smrg      [MESA_SHADER_GEOMETRY] = DEBUG_GS,
100b8e80941Smrg      [MESA_SHADER_FRAGMENT] = DEBUG_WM,
101b8e80941Smrg      [MESA_SHADER_COMPUTE] = DEBUG_CS,
102b8e80941Smrg   };
103b8e80941Smrg   STATIC_ASSERT(MESA_SHADER_STAGES == 6);
104b8e80941Smrg   return flags[stage];
105b8e80941Smrg}
106b8e80941Smrg
107b8e80941Smrgstatic void
108b8e80941Smrgbrw_process_intel_debug_variable_once(void)
109b8e80941Smrg{
110b8e80941Smrg   INTEL_DEBUG = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);
111b8e80941Smrg}
112b8e80941Smrg
113b8e80941Smrgvoid
114b8e80941Smrgbrw_process_intel_debug_variable(void)
115b8e80941Smrg{
116b8e80941Smrg   static once_flag process_intel_debug_variable_flag = ONCE_FLAG_INIT;
117b8e80941Smrg
118b8e80941Smrg   call_once(&process_intel_debug_variable_flag,
119b8e80941Smrg             brw_process_intel_debug_variable_once);
120b8e80941Smrg}
121