1b8e80941Smrg/* 2b8e80941Smrg * Copyright 2003 VMware, Inc. 3b8e80941Smrg * Copyright © 2006 Intel Corporation 4b8e80941Smrg * Copyright © 2017 Broadcom 5b8e80941Smrg * 6b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 8b8e80941Smrg * to deal in the Software without restriction, including without limitation 9b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the 11b8e80941Smrg * Software is furnished to do so, subject to the following conditions: 12b8e80941Smrg * 13b8e80941Smrg * The above copyright notice and this permission notice (including the next 14b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 15b8e80941Smrg * Software. 16b8e80941Smrg * 17b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23b8e80941Smrg * IN THE SOFTWARE. 24b8e80941Smrg */ 25b8e80941Smrg 26b8e80941Smrg/** 27b8e80941Smrg * \file v3d_debug.c 28b8e80941Smrg * 29b8e80941Smrg * Support for the V3D_DEBUG environment variable, along with other 30b8e80941Smrg * miscellaneous debugging code. 31b8e80941Smrg */ 32b8e80941Smrg 33b8e80941Smrg#include <stdlib.h> 34b8e80941Smrg 35b8e80941Smrg#include "common/v3d_debug.h" 36b8e80941Smrg#include "util/macros.h" 37b8e80941Smrg#include "util/debug.h" 38b8e80941Smrg#include "c11/threads.h" 39b8e80941Smrg 40b8e80941Smrguint32_t V3D_DEBUG = 0; 41b8e80941Smrg 42b8e80941Smrgstatic const struct debug_control debug_control[] = { 43b8e80941Smrg { "cl", V3D_DEBUG_CL}, 44b8e80941Smrg { "clif", V3D_DEBUG_CLIF}, 45b8e80941Smrg { "qpu", V3D_DEBUG_QPU}, 46b8e80941Smrg { "vir", V3D_DEBUG_VIR}, 47b8e80941Smrg { "nir", V3D_DEBUG_NIR}, 48b8e80941Smrg { "tgsi", V3D_DEBUG_TGSI}, 49b8e80941Smrg { "shaderdb", V3D_DEBUG_SHADERDB}, 50b8e80941Smrg { "surface", V3D_DEBUG_SURFACE}, 51b8e80941Smrg { "perf", V3D_DEBUG_PERF}, 52b8e80941Smrg { "norast", V3D_DEBUG_NORAST}, 53b8e80941Smrg { "fs", V3D_DEBUG_FS}, 54b8e80941Smrg { "vs", V3D_DEBUG_VS}, 55b8e80941Smrg { "cs", V3D_DEBUG_CS}, 56b8e80941Smrg { "always_flush", V3D_DEBUG_ALWAYS_FLUSH}, 57b8e80941Smrg { "precompile", V3D_DEBUG_PRECOMPILE}, 58b8e80941Smrg { NULL, 0 } 59b8e80941Smrg}; 60b8e80941Smrg 61b8e80941Smrguint32_t 62b8e80941Smrgv3d_debug_flag_for_shader_stage(gl_shader_stage stage) 63b8e80941Smrg{ 64b8e80941Smrg uint32_t flags[] = { 65b8e80941Smrg [MESA_SHADER_VERTEX] = V3D_DEBUG_VS, 66b8e80941Smrg [MESA_SHADER_TESS_CTRL] = 0, 67b8e80941Smrg [MESA_SHADER_TESS_EVAL] = 0, 68b8e80941Smrg [MESA_SHADER_GEOMETRY] = 0, 69b8e80941Smrg [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS, 70b8e80941Smrg [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS, 71b8e80941Smrg }; 72b8e80941Smrg STATIC_ASSERT(MESA_SHADER_STAGES == 6); 73b8e80941Smrg return flags[stage]; 74b8e80941Smrg} 75b8e80941Smrg 76b8e80941Smrgstatic void 77b8e80941Smrgv3d_process_debug_variable_once(void) 78b8e80941Smrg{ 79b8e80941Smrg V3D_DEBUG = parse_debug_string(getenv("V3D_DEBUG"), debug_control); 80b8e80941Smrg 81b8e80941Smrg if (V3D_DEBUG & V3D_DEBUG_SHADERDB) 82b8e80941Smrg V3D_DEBUG |= V3D_DEBUG_NORAST; 83b8e80941Smrg} 84b8e80941Smrg 85b8e80941Smrgvoid 86b8e80941Smrgv3d_process_debug_variable(void) 87b8e80941Smrg{ 88b8e80941Smrg static once_flag v3d_process_debug_variable_flag = ONCE_FLAG_INIT; 89b8e80941Smrg 90b8e80941Smrg call_once(&v3d_process_debug_variable_flag, 91b8e80941Smrg v3d_process_debug_variable_once); 92b8e80941Smrg} 93