Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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 "brw_context.h"
  33. #include "intel_debug.h"
  34. #include "utils.h"
  35. #include "util/u_atomic.h" /* for p_atomic_cmpxchg */
  36.  
  37. uint64_t INTEL_DEBUG = 0;
  38.  
  39. static const struct dri_debug_control debug_control[] = {
  40.    { "tex",         DEBUG_TEXTURE},
  41.    { "state",       DEBUG_STATE},
  42.    { "blit",        DEBUG_BLIT},
  43.    { "mip",         DEBUG_MIPTREE},
  44.    { "fall",        DEBUG_PERF},
  45.    { "perf",        DEBUG_PERF},
  46.    { "perfmon",     DEBUG_PERFMON},
  47.    { "bat",         DEBUG_BATCH},
  48.    { "pix",         DEBUG_PIXEL},
  49.    { "buf",         DEBUG_BUFMGR},
  50.    { "fbo",         DEBUG_FBO},
  51.    { "fs",          DEBUG_WM },
  52.    { "gs",          DEBUG_GS},
  53.    { "sync",        DEBUG_SYNC},
  54.    { "prim",        DEBUG_PRIMS },
  55.    { "vert",        DEBUG_VERTS },
  56.    { "dri",         DEBUG_DRI },
  57.    { "sf",          DEBUG_SF },
  58.    { "stats",       DEBUG_STATS },
  59.    { "wm",          DEBUG_WM },
  60.    { "urb",         DEBUG_URB },
  61.    { "vs",          DEBUG_VS },
  62.    { "clip",        DEBUG_CLIP },
  63.    { "aub",         DEBUG_AUB },
  64.    { "shader_time", DEBUG_SHADER_TIME },
  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.    { "vec4vs",      DEBUG_VEC4VS },
  72.    { "spill",       DEBUG_SPILL },
  73.    { "cs",          DEBUG_CS },
  74.    { NULL,    0 }
  75. };
  76.  
  77. uint64_t
  78. intel_debug_flag_for_shader_stage(gl_shader_stage stage)
  79. {
  80.    uint64_t flags[] = {
  81.       [MESA_SHADER_VERTEX] = DEBUG_VS,
  82.       [MESA_SHADER_GEOMETRY] = DEBUG_GS,
  83.       [MESA_SHADER_FRAGMENT] = DEBUG_WM,
  84.       [MESA_SHADER_COMPUTE] = DEBUG_CS,
  85.    };
  86.    STATIC_ASSERT(MESA_SHADER_STAGES == 4);
  87.    return flags[stage];
  88. }
  89.  
  90. void
  91. brw_process_intel_debug_variable(struct brw_context *brw)
  92. {
  93.    uint64_t intel_debug = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
  94.    (void) p_atomic_cmpxchg(&INTEL_DEBUG, 0, intel_debug);
  95.  
  96.    if (INTEL_DEBUG & DEBUG_BUFMGR)
  97.       dri_bufmgr_set_debug(brw->bufmgr, true);
  98.  
  99.    if ((INTEL_DEBUG & DEBUG_SHADER_TIME) && brw->gen < 7) {
  100.       fprintf(stderr,
  101.               "shader_time debugging requires gen7 (Ivybridge) or better.\n");
  102.       INTEL_DEBUG &= ~DEBUG_SHADER_TIME;
  103.    }
  104.  
  105.    if (INTEL_DEBUG & DEBUG_PERF)
  106.       brw->perf_debug = true;
  107.  
  108.    if (INTEL_DEBUG & DEBUG_AUB)
  109.       drm_intel_bufmgr_gem_set_aub_dump(brw->bufmgr, true);
  110. }
  111.  
  112. /**
  113.  * Reads an environment variable and interprets its value as a boolean.
  114.  *
  115.  * Recognizes 0/false/no and 1/true/yes.  Other values result in the default value.
  116.  */
  117. bool
  118. brw_env_var_as_boolean(const char *var_name, bool default_value)
  119. {
  120.    const char *str = getenv(var_name);
  121.    if (str == NULL)
  122.       return default_value;
  123.  
  124.    if (strcmp(str, "1") == 0 ||
  125.        strcasecmp(str, "true") == 0 ||
  126.        strcasecmp(str, "yes") == 0) {
  127.       return true;
  128.    } else if (strcmp(str, "0") == 0 ||
  129.               strcasecmp(str, "false") == 0 ||
  130.               strcasecmp(str, "no") == 0) {
  131.       return false;
  132.    } else {
  133.       return default_value;
  134.    }
  135. }
  136.