Path: blob/21.2-virgl/src/intel/dev/intel_debug.c
7080 views
/*1* Copyright 2003 VMware, Inc.2* Copyright © 2006 Intel Corporation3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS21* IN THE SOFTWARE.22*/2324/**25* \file intel_debug.c26*27* Support for the INTEL_DEBUG environment variable, along with other28* miscellaneous debugging code.29*/3031#include <stdio.h>32#include <stdlib.h>33#include <string.h>3435#include "dev/intel_debug.h"36#include "git_sha1.h"37#include "util/macros.h"38#include "util/debug.h"39#include "c11/threads.h"4041uint64_t intel_debug = 0;4243static const struct debug_control debug_control[] = {44{ "tex", DEBUG_TEXTURE},45{ "state", DEBUG_STATE},46{ "blit", DEBUG_BLIT},47{ "mip", DEBUG_MIPTREE},48{ "fall", DEBUG_PERF},49{ "perf", DEBUG_PERF},50{ "perfmon", DEBUG_PERFMON},51{ "bat", DEBUG_BATCH},52{ "pix", DEBUG_PIXEL},53{ "buf", DEBUG_BUFMGR},54{ "fbo", DEBUG_FBO},55{ "fs", DEBUG_WM },56{ "gs", DEBUG_GS},57{ "sync", DEBUG_SYNC},58{ "prim", DEBUG_PRIMS },59{ "vert", DEBUG_VERTS },60{ "dri", DEBUG_DRI },61{ "sf", DEBUG_SF },62{ "submit", DEBUG_SUBMIT },63{ "wm", DEBUG_WM },64{ "urb", DEBUG_URB },65{ "vs", DEBUG_VS },66{ "clip", DEBUG_CLIP },67{ "shader_time", DEBUG_SHADER_TIME },68{ "no16", DEBUG_NO16 },69{ "blorp", DEBUG_BLORP },70{ "nodualobj", DEBUG_NO_DUAL_OBJECT_GS },71{ "optimizer", DEBUG_OPTIMIZER },72{ "ann", DEBUG_ANNOTATION },73{ "no8", DEBUG_NO8 },74{ "no-oaconfig", DEBUG_NO_OACONFIG },75{ "spill_fs", DEBUG_SPILL_FS },76{ "spill_vec4", DEBUG_SPILL_VEC4 },77{ "cs", DEBUG_CS },78{ "hex", DEBUG_HEX },79{ "nocompact", DEBUG_NO_COMPACTION },80{ "hs", DEBUG_TCS },81{ "tcs", DEBUG_TCS },82{ "ds", DEBUG_TES },83{ "tes", DEBUG_TES },84{ "l3", DEBUG_L3 },85{ "do32", DEBUG_DO32 },86{ "norbc", DEBUG_NO_RBC },87{ "nohiz", DEBUG_NO_HIZ },88{ "color", DEBUG_COLOR },89{ "reemit", DEBUG_REEMIT },90{ "soft64", DEBUG_SOFT64 },91{ "tcs8", DEBUG_TCS_EIGHT_PATCH },92{ "bt", DEBUG_BT },93{ "pc", DEBUG_PIPE_CONTROL },94{ "nofc", DEBUG_NO_FAST_CLEAR },95{ "no32", DEBUG_NO32 },96{ "shaders", DEBUG_WM | DEBUG_VS | DEBUG_TCS |97DEBUG_TES | DEBUG_GS | DEBUG_CS |98DEBUG_RT },99{ "rt", DEBUG_RT },100{ NULL, 0 }101};102103uint64_t104intel_debug_flag_for_shader_stage(gl_shader_stage stage)105{106uint64_t flags[] = {107[MESA_SHADER_VERTEX] = DEBUG_VS,108[MESA_SHADER_TESS_CTRL] = DEBUG_TCS,109[MESA_SHADER_TESS_EVAL] = DEBUG_TES,110[MESA_SHADER_GEOMETRY] = DEBUG_GS,111[MESA_SHADER_FRAGMENT] = DEBUG_WM,112[MESA_SHADER_COMPUTE] = DEBUG_CS,113114[MESA_SHADER_RAYGEN] = DEBUG_RT,115[MESA_SHADER_ANY_HIT] = DEBUG_RT,116[MESA_SHADER_CLOSEST_HIT] = DEBUG_RT,117[MESA_SHADER_MISS] = DEBUG_RT,118[MESA_SHADER_INTERSECTION] = DEBUG_RT,119[MESA_SHADER_CALLABLE] = DEBUG_RT,120};121return flags[stage];122}123124static void125brw_process_intel_debug_variable_once(void)126{127intel_debug = parse_debug_string(getenv("INTEL_DEBUG"), debug_control);128}129130void131brw_process_intel_debug_variable(void)132{133static once_flag process_intel_debug_variable_flag = ONCE_FLAG_INIT;134135call_once(&process_intel_debug_variable_flag,136brw_process_intel_debug_variable_once);137}138139static uint64_t debug_identifier[4] = {1400xffeeddccbbaa9988,1410x7766554433221100,1420xffeeddccbbaa9988,1430x7766554433221100,144};145146void *147intel_debug_identifier(void)148{149return debug_identifier;150}151152uint32_t153intel_debug_identifier_size(void)154{155return sizeof(debug_identifier);156}157158uint32_t159intel_debug_write_identifiers(void *_output,160uint32_t output_size,161const char *driver_name)162{163void *output = _output, *output_end = _output + output_size;164165assert(output_size > intel_debug_identifier_size());166167memcpy(output, intel_debug_identifier(), intel_debug_identifier_size());168output += intel_debug_identifier_size();169170for (uint32_t id = INTEL_DEBUG_BLOCK_TYPE_DRIVER; id < INTEL_DEBUG_BLOCK_TYPE_MAX; id++) {171switch (id) {172case INTEL_DEBUG_BLOCK_TYPE_DRIVER: {173struct intel_debug_block_driver driver_desc = {174.base = {175.type = id,176},177};178int len = snprintf(output + sizeof(driver_desc),179output_end - (output + sizeof(driver_desc)),180"%s " PACKAGE_VERSION " build " MESA_GIT_SHA1,181driver_name);182driver_desc.base.length = sizeof(driver_desc) + len + 1;183memcpy(output, &driver_desc, sizeof(driver_desc));184output += driver_desc.base.length;185break;186}187188case INTEL_DEBUG_BLOCK_TYPE_FRAME: {189struct intel_debug_block_frame frame_desc = {190.base = {191.type = INTEL_DEBUG_BLOCK_TYPE_FRAME,192.length = sizeof(frame_desc),193},194};195memcpy(output, &frame_desc, sizeof(frame_desc));196output += sizeof(frame_desc);197break;198}199200default:201unreachable("Missing identifier write");202}203204assert(output < output_end);205}206207struct intel_debug_block_base end = {208.type = INTEL_DEBUG_BLOCK_TYPE_END,209.length = sizeof(end),210};211memcpy(output, &end, sizeof(end));212output += sizeof(end);213214assert(output < output_end);215216/* Return the how many bytes where written, so that the rest of the buffer217* can be used for other things.218*/219return output - _output;220}221222void *223intel_debug_get_identifier_block(void *_buffer,224uint32_t buffer_size,225enum intel_debug_block_type type)226{227void *buffer = _buffer + intel_debug_identifier_size(),228*end_buffer = _buffer + buffer_size;229230while (buffer < end_buffer) {231struct intel_debug_block_base *item = buffer;232233if (item->type == type)234return item;235if (item->type == INTEL_DEBUG_BLOCK_TYPE_END)236return NULL;237238buffer += item->length;239}240241return NULL;242}243244245