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/u_debug.h" 38#include "c11/threads.h" 39 40uint32_t V3D_DEBUG = 0; 41 42static const struct debug_named_value debug_control[] = { 43 { "cl", V3D_DEBUG_CL, 44 "Dump command list during creation" }, 45 { "cl_nobin", V3D_DEBUG_CL_NO_BIN, 46 "Dump command listduring creation, excluding binary resources" }, 47 { "clif", V3D_DEBUG_CLIF, 48 "Dump command list (CLIF format) during creation", }, 49 { "qpu", V3D_DEBUG_QPU, 50 "Dump generated QPU instructions" }, 51 { "vir", V3D_DEBUG_VIR, 52 "Dump VIR during program compile" }, 53 { "nir", V3D_DEBUG_NIR, 54 "Dump NIR during program compile" }, 55 { "tgsi", V3D_DEBUG_TGSI, 56 "Dump TGSI during program compile" }, 57 { "shaderdb", V3D_DEBUG_SHADERDB, 58 "Dump program compile information for shader-db analysis" }, 59 { "surface", V3D_DEBUG_SURFACE, 60 "Print resource layout information" }, 61 { "perf", V3D_DEBUG_PERF, 62 "Print during runtime performance-related events" }, 63 { "norast", V3D_DEBUG_NORAST, 64 "Skip actual hardware execution of commands" }, 65 { "fs", V3D_DEBUG_FS, 66 "Dump fragment shaders" }, 67 { "gs", V3D_DEBUG_GS, 68 "Dump geometry shaders" }, 69 { "vs", V3D_DEBUG_VS, 70 "Dump vertex shaders" }, 71 { "cs", V3D_DEBUG_CS, 72 "Dump computer shaders" }, 73 { "always_flush", V3D_DEBUG_ALWAYS_FLUSH, 74 "Flush after each draw call" }, 75 { "precompile", V3D_DEBUG_PRECOMPILE, 76 "Precompiles shader variant at shader state creation time" }, 77 { "ra", V3D_DEBUG_RA, 78 "Dump register allocation failures" }, 79 { "dump_spirv", V3D_DEBUG_DUMP_SPIRV, 80 "Dump SPIR-V code" }, 81 { "tmu32", V3D_DEBUG_TMU_32BIT, 82 "Force 32-bit precision on all TMU operations" }, 83 /* This can lead to incorrect behavior for applications that do 84 * require full 32-bit precision, but can improve performance 85 * for those that don't. 86 */ 87 { "tmu16", V3D_DEBUG_TMU_16BIT, 88 "Force 16-bit precision on all TMU operations" }, 89 { "noloopunroll", V3D_DEBUG_NO_LOOP_UNROLL, 90 "Disable loop unrolling" }, 91 { NULL } 92}; 93 94DEBUG_GET_ONCE_FLAGS_OPTION(v3d_debug, "V3D_DEBUG", debug_control, 0) 95 96uint32_t 97v3d_debug_flag_for_shader_stage(gl_shader_stage stage) 98{ 99 uint32_t flags[] = { 100 [MESA_SHADER_VERTEX] = V3D_DEBUG_VS, 101 [MESA_SHADER_TESS_CTRL] = 0, 102 [MESA_SHADER_TESS_EVAL] = 0, 103 [MESA_SHADER_GEOMETRY] = V3D_DEBUG_GS, 104 [MESA_SHADER_FRAGMENT] = V3D_DEBUG_FS, 105 [MESA_SHADER_COMPUTE] = V3D_DEBUG_CS, 106 }; 107 STATIC_ASSERT(MESA_SHADER_STAGES == 6); 108 return flags[stage]; 109} 110 111void 112v3d_process_debug_variable(void) 113{ 114 V3D_DEBUG = debug_get_option_v3d_debug(); 115 116 if (V3D_DEBUG & V3D_DEBUG_SHADERDB) 117 V3D_DEBUG |= V3D_DEBUG_NORAST; 118} 119