1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
|
/*==============================================================================
Copyright(c) 2017 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files(the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and / or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
============================================================================
**
** File Name: gfxDebug.h
**
** Description:
**
** Environment:
**
** Notes:
**
============================================================================*/
#pragma once
#ifndef _GFXDEBUG_H_
#define _GFXDEBUG_H_
#include <stdint.h>
#if defined(D3D) && !defined (USERMODE_DRIVER)
// The D3D XP Kernel Mode driver will continue to use the old scheme until it
// has been updated.
#else
// This portion is used by new stile debug scheme.
// NOTE: There is some overlap between defines.
//========================================================================
// Controlling Debug Messages: There are two types of output messages -
// debug or release output message. These are controlled through the two
// flags listed below.
#ifdef _DEBUG
#define __DEBUG_MESSAGE 1
#define __RELEASE_MESSAGE 1
#else
#define __DEBUG_MESSAGE 0
#define __RELEASE_MESSAGE 1
#endif
// !!! HAVE TO FIGURE OOUT HOW TO INCLUDE THIS CORRECTLY
// #include "video.h"
//==== Define global debug message routine ===================
#if __DEBUG_MESSAGE || __RELEASE_MESSAGE
#ifdef __UMD
#include "stdlib.h"
#define MESSAGE_FUNCTION(FUNCTION_NAME,COMPONENT_ID) \
\
void FUNCTION_NAME(unsigned long MessageLevel, const char *MessageFmt, ...) \
{ \
uint32_t Length = 0; \
char *PrintBuffer = NULL; \
char *Prefix = NULL; \
va_list ArgList; \
\
unsigned long ComponentId = COMPONENT_ID; \
unsigned long ComponentMask = 1 << COMPONENT_ID; \
\
/* Ensure that CRITICAL messages are printed if the setting of the */ \
/* global debug variables flag is NORMAL or VERBOSE. Similarly, if */ \
/* the setting of the debug variables flag is NORMAL, ensure that */ \
/* the VERBOSE message are printed out too! */ \
\
if (MessageLevel & GFXDBG_CRITICAL) \
{ \
MessageLevel |= GFXDBG_NORMAL | GFXDBG_VERBOSE; \
} \
else if (MessageLevel & GFXDBG_NORMAL) \
{ \
MessageLevel |= GFXDBG_VERBOSE; \
} \
\
/* Some of routines need to call the debug message functionality */ \
/* before the DebugControl variable has been initialized. Hence, if */ \
/* pDebugControl is NULL, unconditionally print the debug message. */ \
\
if ((pDebugControl == NULL) || \
((pDebugControl->DebugEnableMask & ComponentMask) && \
(MessageLevel & pDebugControl->DebugLevel[ComponentId]))) \
{ \
va_start (ArgList, MessageFmt); \
Length = _vscprintf(MessageFmt, ArgList) + 1; \
PrintBuffer = malloc(Length * sizeof(char)); \
if (PrintBuffer) \
{ \
vsprintf_s(PrintBuffer, Length, MessageFmt, ArgList); \
Prefix = ComponentIdStrings[ComponentId]; \
__MESSAGE_PRINT(Prefix, PrintBuffer); \
free(PrintBuffer); \
} \
else \
{ \
__MESSAGE_PRINT("INTC DEBUG: ", \
"Can not allocate print buffer\n"); \
__debugbreak(); \
} \
va_end(ArgList); \
} \
}
#else
#ifndef __linux__
#include "igdKrnlEtwMacros.h"
#endif
#define MESSAGE_FUNCTION(FUNCTION_NAME,COMPONENT_ID) \
\
void FUNCTION_NAME(unsigned long MessageLevel, const char *MessageFmt, ...) \
{ \
int32_t Length = 0; \
char PrintBuffer[GFX_MAX_MESSAGE_LENGTH]; \
char *Prefix = NULL; \
va_list ArgList; \
unsigned long GfxDbgLvl = MessageLevel; \
unsigned long ComponentId = COMPONENT_ID; \
unsigned long ComponentMask = 1 << COMPONENT_ID; \
\
/* Ensure that CRITICAL messages are printed if the setting of the */ \
/* global debug variables flag is NORMAL or VERBOSE. Similarly, if */ \
/* the setting of the debug variables flag is NORMAL, ensure that */ \
/* the VERBOSE message are printed out too! */ \
\
if (MessageLevel & GFXDBG_CRITICAL) \
{ \
MessageLevel |= GFXDBG_NORMAL | GFXDBG_VERBOSE; \
} \
else if (MessageLevel & GFXDBG_NORMAL) \
{ \
MessageLevel |= GFXDBG_VERBOSE; \
} \
\
/* Some of routines need to call the debug message functionality */ \
/* before the DebugControl variable has been initialized. Hence, if */ \
/* pDebugControl is NULL, unconditionally print the debug message. */ \
\
va_start(ArgList, MessageFmt); \
Length = _vsnprintf_s(PrintBuffer, GFX_MAX_MESSAGE_LENGTH, \
sizeof(PrintBuffer), \
MessageFmt, ArgList); \
if (Length >= 0) \
{ \
EtwDebugPrint((uint16_t)GfxDbgLvl, (uint16_t)ComponentId, PrintBuffer); \
\
if ((pDebugControl == NULL) || \
((pDebugControl->DebugEnableMask & ComponentMask) && \
(MessageLevel & pDebugControl->DebugLevel[ComponentId]))) \
{ \
Prefix = ComponentIdStrings[ComponentId]; \
__MESSAGE_PRINT(Prefix, PrintBuffer); \
} \
} \
else \
{ \
__MESSAGE_PRINT("INTC DEBUG: ", \
"The print buffer is to small\n"); \
__debugbreak(); \
} \
va_end(ArgList); \
} \
#endif
#endif // __DEBUG_MESSAGE || __RELEASE_MESSAGE
// Define a max size for the intermediate buffer for storing the
// debug error message string.
#define GFX_MAX_MESSAGE_LENGTH (512)
//==============================================================================
// From winnt.h
//
// C_ASSERT() can be used to perform many COMPILE-TIME assertions:
// type sizes, field offsets, etc.
//
// An assertion failure results in error C2118: negative subscript.
//
// When this assertion is to be used in the middle of a code block,
// use it within {} - e.g. {__GL_C_ASSERT (__GL_NUM == 0);}
//
// Since all components may not want to include "winnt.h", define a
// C_ASSERT that can be used by all components.
#ifndef GFX_C_ASSERT
#define GFX_C_ASSERT(e) typedef char __GFX_C_ASSERT__[(e)?1:-1]
#endif
// Unfortunately, we cannot include "g_debug.h" before this structure
// definition since it needs this structure - but then this structure
// requires the number of components. We get around this by using a
// large enough number for the component count.
#define MAX_COMPONENT_COUNT_DONOTUSE (20)
//------------------------------------------------------------------------------
// Debug and assert control structure. Note that each component has
// a separate variable to control its debug level.
//------------------------------------------------------------------------------
typedef struct GFX_DEBUG_CONTROL_REC
{
unsigned long Version;
unsigned long Size;
unsigned long AssertEnableMask;
unsigned long EnableDebugFileDump;
unsigned long DebugEnableMask;
unsigned long RingBufDbgMask;
unsigned long ReportAssertEnable;
unsigned long AssertBreakDisable;
#ifndef __UMD
unsigned long DebugLevel[MAX_COMPONENT_COUNT_DONOTUSE];
#endif
} GFX_DEBUG_CONTROL, *PGFX_DEBUG_CONTROL;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __GFXDEBUG_C__ // Only to be defined by "gfxDebug.c" file.
GFX_DEBUG_CONTROL *pDebugControl = NULL;
#else
extern GFX_DEBUG_CONTROL *pDebugControl;
#endif
#ifdef __cplusplus
}
#endif
void InitializeDebugVariables(PGFX_DEBUG_CONTROL pDebugControl);
#if (defined(_DEBUG) || defined( _RELEASE_INTERNAL ))
#if ( !defined(REPORT_ASSERT) || !defined(REPORT_ASSERT_ETW)) && defined( _WIN32 )
#include "AssertTracer.h"
#elif !defined(REPORT_ASSERT)
#define REPORT_ASSERT( expr )
#define REPORT_ASSERT_ETW(compId, componentMask, expr)
#endif
#endif
#ifdef _DEBUG
// This function doesn't do anything, it exists so you can put
// a break point at the XXX_ASSERT and when you step into it
// you will step into this function and then you can
// disable/enable the assert by setting AssertOn to FALSE/TRUE.
#ifdef _MSC_VER
static __inline int ToggleAssert(int AssertOn)
#else
static inline int ToggleAssert(int AssertOn)
#endif
{
return AssertOn;
};
#define __ASSERT(pDebugControl, compId, componentMask, expr) \
{ \
static int __assertOn = TRUE; \
__assertOn = ToggleAssert(__assertOn); \
REPORT_ASSERT_ETW(compId, componentMask, expr); \
if (__assertOn) \
{ \
if(!(pDebugControl)) \
{ \
if(!(expr)) \
{ \
REPORT_ASSERT(expr); \
__debugbreak(); \
} \
} \
else \
{ \
if (((componentMask) & pDebugControl->AssertEnableMask) && \
!(expr)) \
{ \
if(pDebugControl->ReportAssertEnable) \
{ \
REPORT_ASSERT(expr); \
} \
if(!pDebugControl->AssertBreakDisable) \
{ \
__debugbreak(); \
} \
} \
\
} \
} \
}
#define __ASSERTPTR(pDebugControl, compId, componentMask, expr, ret) \
{ \
__ASSERT(pDebugControl, compId, componentMask, expr); \
if (!expr) \
{ \
return ret; \
} \
}
#elif defined(_RELEASE_INTERNAL)
#define __ASSERT(pDebugControl, compId, compMask, expr) \
{ \
REPORT_ASSERT_ETW(compId, compMask, expr); \
}
#define __ASSERTPTR(pDebugControl, compId, compMask, expr, ret) \
{ \
__ASSERT(pDebugControl, compId, compMask, expr); \
if (!expr) \
{ \
return ret; \
} \
}
#else
#define __ASSERT(pDebugControl, compId, compMask, expr)
#define __ASSERTPTR(pDebugControl, compId, compMask ,expr, ret)
#endif // _DEBUG
#define __RELEASEASSERT(pDebugControl, componentMask, expr) \
{ \
if (((componentMask) & pDebugControl->AssertEnableMask) && !(expr)) \
{ \
__debugbreak(); \
} \
}
// The common code may use a macro such as "GFXASSERT". This is defined
// to be UMD or KMD ASSERT based on the component being compiled.
#ifdef __UMD
#define GFXASSERT UMDASSERT
#else
#define GFXASSERT KM_ASSERT
#endif
#include <stdint.h>
#include "g_gfxDebug.h" // Include automatically generated component
// specific macros etc.
GFX_C_ASSERT(MAX_COMPONENT_COUNT_DONOTUSE >= GFX_COMPONENT_COUNT);
// !!! WE MIGHT BE ABLE TO DELETE THE FOLLOWING, DOUBLE CHECK FIRST
// Ring buffer proxy
#define ENABLE_RINGBUF_PROXY_IN_RELEASE_BUILD 0
#endif // D3D not defined
#endif // _GFXDEBUG_H_
|