aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/swr/rasterizer/common
diff options
context:
space:
mode:
authorTim Rowley <[email protected]>2016-11-22 19:50:00 -0600
committerTim Rowley <[email protected]>2016-11-29 19:36:46 -0600
commitf7ab0e4b7ea9d9334af38d6ba5680d326c5fd1eb (patch)
treee4dff24df7e5245daddb8b3d8d5a436c8bbfd529 /src/gallium/drivers/swr/rasterizer/common
parent662b9c24d0bfcabb2b78dec787ab899a97643330 (diff)
swr: [rasterizer common] add SwrTrace() and macros
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium/drivers/swr/rasterizer/common')
-rw-r--r--src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp96
-rw-r--r--src/gallium/drivers/swr/rasterizer/common/swr_assert.h14
2 files changed, 95 insertions, 15 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp b/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
index 72501014de4..98a5a52957f 100644
--- a/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
+++ b/src/gallium/drivers/swr/rasterizer/common/swr_assert.cpp
@@ -25,6 +25,8 @@
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
+#include <algorithm>
+#include <mutex>
#if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
@@ -111,30 +113,24 @@ void ResetTextColor(FILE* stream)
#endif
}
-bool SwrAssert(
- bool chkDebugger,
- bool& enabled,
- const char* pExpression,
+static std::mutex g_stderrMutex;
+
+void SwrTrace(
const char* pFileName,
uint32_t lineNum,
- const char* pFunction,
- const char* pFmtString /* = nullptr */,
+ const char* function,
+ const char* pFmtString,
...)
{
- SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
+ std::lock_guard<std::mutex> l(g_stderrMutex);
- fprintf(stderr, "%s(%d): ", pFileName, lineNum);
-
- SetTextColor(stderr, TEXT_RED, TEXT_INTENSITY);
-
- fprintf(stderr, "ASSERT: %s\n", pExpression);
+ SetTextColor(stderr, TEXT_CYAN, TEXT_NORMAL);
- SetTextColor(stderr, TEXT_CYAN, TEXT_INTENSITY);
- fprintf(stderr, "\t%s\n", pFunction);
+ fprintf(stderr, "%s(%d): TRACE in %s:\n", pFileName, lineNum, function);
if (pFmtString)
{
- SetTextColor(stderr, TEXT_YELLOW, TEXT_INTENSITY);
+ SetTextColor(stderr, TEXT_PURPLE, TEXT_INTENSITY);
fprintf(stderr, "\t");
va_list args;
va_start(args, pFmtString);
@@ -149,6 +145,76 @@ bool SwrAssert(
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 chkDebugger,
+ bool& enabled,
+ const char* pExpression,
+ const char* pFileName,
+ uint32_t lineNum,
+ const char* pFunction,
+ const char* pFmtString /* = nullptr */,
+ ...)
+{
+ {
+ std::lock_guard<std::mutex> l(g_stderrMutex);
+
+ 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);
+ 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): ASSERT: %s\n", pFileName, lineNum, pExpression);
msgBuf[MAX_MESSAGE_LEN - 2] = '\n';
msgBuf[MAX_MESSAGE_LEN - 1] = 0;
diff --git a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
index 04d768191b4..bd6833615a1 100644
--- a/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
+++ b/src/gallium/drivers/swr/rasterizer/common/swr_assert.h
@@ -104,6 +104,13 @@ bool SwrAssert(
const char* pFmtString = nullptr,
...);
+void SwrTrace(
+ const char* pFileName,
+ uint32_t lineNum,
+ const char* function,
+ const char* pFmtString,
+ ...);
+
#define _SWR_ASSERT(chkDebugger, e, ...) {\
bool expFailed = !(e);\
if (expFailed) {\
@@ -113,9 +120,13 @@ bool SwrAssert(
}\
}
+#define _SWR_TRACE(_fmtstr, ...) \
+ SwrTrace(__FILE__, __LINE__, __FUNCTION__, _fmtstr, ##__VA_ARGS__);
+
#if SWR_ENABLE_ASSERTS
#define SWR_ASSERT(e, ...) _SWR_ASSERT(true, 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)
#undef assert
@@ -127,6 +138,7 @@ bool SwrAssert(
#if SWR_ENABLE_REL_ASSERTS
#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_TRACE(_fmtstr, ...) _SWR_TRACE(_fmtstr, ##__VA_ARGS__)
#endif
#endif // C++
@@ -136,11 +148,13 @@ bool SwrAssert(
#if !SWR_ENABLE_ASSERTS
#define SWR_ASSERT(e, ...) (void)(0)
#define SWR_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
+#define SWR_TRACE(_fmtstr, ...) (void)(0)
#endif
#if !SWR_ENABLE_REL_ASSERTS
#define SWR_REL_ASSERT(e, ...) (void)(0)
#define SWR_REL_ASSUME_ASSERT(e, ...) SWR_ASSUME(e, ##__VA_ARGS__)
+#define SWR_REL_TRACE(_fmtstr, ...) (void)(0)
#endif
#define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)