swr: [rasterizer common] add SwrTrace() and macros
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
|
#if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
|
||||||
|
|
||||||
@@ -111,6 +113,66 @@ void ResetTextColor(FILE* stream)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::mutex g_stderrMutex;
|
||||||
|
|
||||||
|
void SwrTrace(
|
||||||
|
const char* pFileName,
|
||||||
|
uint32_t lineNum,
|
||||||
|
const char* function,
|
||||||
|
const char* pFmtString,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> l(g_stderrMutex);
|
||||||
|
|
||||||
|
SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s(%d): TRACE in %s:\n", pFileName, lineNum, function);
|
||||||
|
|
||||||
|
if (pFmtString)
|
||||||
|
{
|
||||||
|
SetTextColor(stderr, TEXT_PURPLE, TEXT_INTENSITY);
|
||||||
|
fprintf(stderr, "\t");
|
||||||
|
va_list args;
|
||||||
|
va_start(args, pFmtString);
|
||||||
|
vfprintf(stderr, pFmtString, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
ResetTextColor(stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
static const int MAX_MESSAGE_LEN = 2048;
|
||||||
|
char msgBuf[MAX_MESSAGE_LEN];
|
||||||
|
|
||||||
|
sprintf_s(msgBuf, "%s(%d): TRACE in %s\n", pFileName, lineNum, function);
|
||||||
|
msgBuf[MAX_MESSAGE_LEN - 2] = '\n';
|
||||||
|
msgBuf[MAX_MESSAGE_LEN - 1] = 0;
|
||||||
|
OutputDebugStringA(msgBuf);
|
||||||
|
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
if (pFmtString)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, pFmtString);
|
||||||
|
offset = _vsnprintf_s(
|
||||||
|
msgBuf,
|
||||||
|
sizeof(msgBuf),
|
||||||
|
sizeof(msgBuf),
|
||||||
|
pFmtString,
|
||||||
|
args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
if (offset < 0) { return; }
|
||||||
|
|
||||||
|
OutputDebugStringA("\t");
|
||||||
|
OutputDebugStringA(msgBuf);
|
||||||
|
OutputDebugStringA("\n");
|
||||||
|
}
|
||||||
|
#endif // _WIN32
|
||||||
|
}
|
||||||
|
|
||||||
bool SwrAssert(
|
bool SwrAssert(
|
||||||
bool chkDebugger,
|
bool chkDebugger,
|
||||||
bool& enabled,
|
bool& enabled,
|
||||||
@@ -121,29 +183,33 @@ bool SwrAssert(
|
|||||||
const char* pFmtString /* = nullptr */,
|
const char* pFmtString /* = nullptr */,
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
|
|
||||||
|
|
||||||
fprintf(stderr, "%s(%d): ", pFileName, lineNum);
|
|
||||||
|
|
||||||
SetTextColor(stderr, TEXT_RED, TEXT_INTENSITY);
|
|
||||||
|
|
||||||
fprintf(stderr, "ASSERT: %s\n", pExpression);
|
|
||||||
|
|
||||||
SetTextColor(stderr, TEXT_CYAN, TEXT_INTENSITY);
|
|
||||||
fprintf(stderr, "\t%s\n", pFunction);
|
|
||||||
|
|
||||||
if (pFmtString)
|
|
||||||
{
|
{
|
||||||
SetTextColor(stderr, TEXT_YELLOW, TEXT_INTENSITY);
|
std::lock_guard<std::mutex> l(g_stderrMutex);
|
||||||
fprintf(stderr, "\t");
|
|
||||||
va_list args;
|
SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
|
||||||
va_start(args, pFmtString);
|
|
||||||
vfprintf(stderr, pFmtString, args);
|
fprintf(stderr, "%s(%d): ", pFileName, lineNum);
|
||||||
va_end(args);
|
|
||||||
fprintf(stderr, "\n");
|
SetTextColor(stderr, TEXT_RED, TEXT_INTENSITY);
|
||||||
|
|
||||||
|
fprintf(stderr, "ASSERT: %s\n", pExpression);
|
||||||
|
|
||||||
|
SetTextColor(stderr, TEXT_CYAN, TEXT_INTENSITY);
|
||||||
|
fprintf(stderr, "\t%s\n", pFunction);
|
||||||
|
|
||||||
|
if (pFmtString)
|
||||||
|
{
|
||||||
|
SetTextColor(stderr, TEXT_YELLOW, TEXT_INTENSITY);
|
||||||
|
fprintf(stderr, "\t");
|
||||||
|
va_list args;
|
||||||
|
va_start(args, pFmtString);
|
||||||
|
vfprintf(stderr, pFmtString, args);
|
||||||
|
va_end(args);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
}
|
||||||
|
ResetTextColor(stderr);
|
||||||
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
ResetTextColor(stderr);
|
|
||||||
fflush(stderr);
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static const int MAX_MESSAGE_LEN = 2048;
|
static const int MAX_MESSAGE_LEN = 2048;
|
||||||
|
@@ -104,6 +104,13 @@ bool SwrAssert(
|
|||||||
const char* pFmtString = nullptr,
|
const char* pFmtString = nullptr,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
|
void SwrTrace(
|
||||||
|
const char* pFileName,
|
||||||
|
uint32_t lineNum,
|
||||||
|
const char* function,
|
||||||
|
const char* pFmtString,
|
||||||
|
...);
|
||||||
|
|
||||||
#define _SWR_ASSERT(chkDebugger, e, ...) {\
|
#define _SWR_ASSERT(chkDebugger, e, ...) {\
|
||||||
bool expFailed = !(e);\
|
bool expFailed = !(e);\
|
||||||
if (expFailed) {\
|
if (expFailed) {\
|
||||||
@@ -113,9 +120,13 @@ bool SwrAssert(
|
|||||||
}\
|
}\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define _SWR_TRACE(_fmtstr, ...) \
|
||||||
|
SwrTrace(__FILE__, __LINE__, __FUNCTION__, _fmtstr, ##__VA_ARGS__);
|
||||||
|
|
||||||
#if SWR_ENABLE_ASSERTS
|
#if SWR_ENABLE_ASSERTS
|
||||||
#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
|
#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
|
||||||
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSERT(e, ##__VA_ARGS__)
|
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSERT(e, ##__VA_ARGS__)
|
||||||
|
#define SWR_TRACE(_fmtstr, ...) _SWR_TRACE(_fmtstr, ##__VA_ARGS__)
|
||||||
|
|
||||||
#if defined(assert)
|
#if defined(assert)
|
||||||
#undef assert
|
#undef assert
|
||||||
@@ -127,6 +138,7 @@ bool SwrAssert(
|
|||||||
#if SWR_ENABLE_REL_ASSERTS
|
#if SWR_ENABLE_REL_ASSERTS
|
||||||
#define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
|
#define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
|
||||||
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_REL_ASSERT(e, ##__VA_ARGS__)
|
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_REL_ASSERT(e, ##__VA_ARGS__)
|
||||||
|
#define SWR_REL_TRACE(_fmtstr, ...) _SWR_TRACE(_fmtstr, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // C++
|
#endif // C++
|
||||||
@@ -136,11 +148,13 @@ bool SwrAssert(
|
|||||||
#if !SWR_ENABLE_ASSERTS
|
#if !SWR_ENABLE_ASSERTS
|
||||||
#define SWR_ASSERT(e, ...) (void)(0)
|
#define SWR_ASSERT(e, ...) (void)(0)
|
||||||
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
|
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
|
||||||
|
#define SWR_TRACE(_fmtstr, ...) (void)(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !SWR_ENABLE_REL_ASSERTS
|
#if !SWR_ENABLE_REL_ASSERTS
|
||||||
#define SWR_REL_ASSERT(e, ...) (void)(0)
|
#define SWR_REL_ASSERT(e, ...) (void)(0)
|
||||||
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
|
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
|
||||||
|
#define SWR_REL_TRACE(_fmtstr, ...) (void)(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)
|
#define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)
|
||||||
|
Reference in New Issue
Block a user