Remove stray printfs.
SwiftShader shouldn't print anything to stdout in Release builds.
Also refactor UNIMPLEMENTED macro to be able to take a formatted string
with arguments.
Bug b/73656151
Change-Id: Ibadbfba3371324ba1bd608bd51bdac5e5923a20e
Reviewed-on: https://swiftshader-review.googlesource.com/21108
Reviewed-by: Merck Hung <merckhung@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Common/Configurator.cpp b/src/Common/Configurator.cpp
index 445305c..ead1d28 100644
--- a/src/Common/Configurator.cpp
+++ b/src/Common/Configurator.cpp
@@ -66,7 +66,7 @@
if(!isprint(line[0]))
{
- printf("Failing on char %d\n", line[0]);
+ // printf("Failing on char %d\n", line[0]);
file.close();
return false;
}
diff --git a/src/Common/Debug.cpp b/src/Common/Debug.cpp
index c3a1921..acf469e 100644
--- a/src/Common/Debug.cpp
+++ b/src/Common/Debug.cpp
@@ -17,6 +17,8 @@
#include <stdio.h>
#include <stdarg.h>
+namespace sw
+{
void trace(const char *format, ...)
{
if(false)
@@ -34,3 +36,4 @@
}
}
}
+}
diff --git a/src/Common/Debug.hpp b/src/Common/Debug.hpp
index 436854c..5033bc5 100644
--- a/src/Common/Debug.hpp
+++ b/src/Common/Debug.hpp
@@ -25,25 +25,34 @@
#undef min
#undef max
+namespace sw
+{
void trace(const char *format, ...);
+inline void trace() {}
+}
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define TRACE(format, ...) trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
+ #define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
#else
#define TRACE(...) ((void)0)
#endif
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define UNIMPLEMENTED() {trace("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); ASSERT(false);}
+ #define UNIMPLEMENTED(...) do { \
+ sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
+ sw::trace(##__VA_ARGS__); \
+ sw::trace("\n"); \
+ ASSERT(false); \
+ } while(0)
#else
- #define UNIMPLEMENTED() ((void)0)
+ #define UNIMPLEMENTED(...) ((void)0)
#endif
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
- #define ASSERT(expression) {if(!(expression)) trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);}
+ #define ASSERT(expression) {if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);}
#else
#define ASSERT assert
#endif
-#endif // __ANDROID__
+#endif // !__ANDROID__
#endif // Debug_hpp
diff --git a/src/Common/DebugAndroid.hpp b/src/Common/DebugAndroid.hpp
index 6dfb61d..f5ce468 100644
--- a/src/Common/DebugAndroid.hpp
+++ b/src/Common/DebugAndroid.hpp
@@ -66,7 +66,8 @@
AndroidEnterDebugger(); \
} while(0)
-#define UNIMPLEMENTED() do { \
+// TODO: Handle __VA_ARGS__ (can be empty)
+#define UNIMPLEMENTED(...) do { \
ALOGE("badness: unimplemented: %s %s:%d", \
__FUNCTION__, __FILE__, __LINE__); \
AndroidEnterDebugger(); \
diff --git a/src/OpenGL/common/debug.cpp b/src/OpenGL/common/debug.cpp
index 3ef2885..9303260 100644
--- a/src/OpenGL/common/debug.cpp
+++ b/src/OpenGL/common/debug.cpp
@@ -34,7 +34,7 @@
#else
static void output(const char *format, va_list vararg)
{
- if(false)
+ if(true)
{
static FILE* file = nullptr;
if(!file)
@@ -45,6 +45,7 @@
if(file)
{
vfprintf(file, format, vararg);
+ fflush(file);
}
}
}
diff --git a/src/OpenGL/common/debug.h b/src/OpenGL/common/debug.h
index a5653b7..d44d8d7 100644
--- a/src/OpenGL/common/debug.h
+++ b/src/OpenGL/common/debug.h
@@ -29,8 +29,9 @@
namespace es
{
- // Outputs text to the debugging log
- void trace(const char *format, ...);
+// Outputs text to the debugging log
+void trace(const char *format, ...);
+inline void trace() {}
}
// A macro to output a trace of a function call and its arguments to the debugging log
@@ -69,12 +70,14 @@
// A macro to indicate unimplemented functionality
#undef UNIMPLEMENTED
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
-#define UNIMPLEMENTED() do { \
- FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
+#define UNIMPLEMENTED(...) do { \
+ es::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
+ es::trace(##__VA_ARGS__); \
+ es::trace("\n"); \
assert(false); \
} while(0)
#else
- #define UNIMPLEMENTED() FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
+ #define UNIMPLEMENTED(...) FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__)
#endif
// A macro for code which is not expected to be reached under valid assumptions
diff --git a/src/OpenGL/compiler/debug.cpp b/src/OpenGL/compiler/debug.cpp
index 61943a3..6517346 100644
--- a/src/OpenGL/compiler/debug.cpp
+++ b/src/OpenGL/compiler/debug.cpp
@@ -23,7 +23,7 @@
#include "ParseHelper.h"
#ifdef TRACE_ENABLED
-extern "C" {
+namespace sh {
void Trace(const char *format, ...) {
if (!format) return;
@@ -39,6 +39,6 @@
parseContext->trace(buf);
}
}
-} // extern "C"
+} // namespace sh
#endif // TRACE_ENABLED
diff --git a/src/OpenGL/compiler/debug.h b/src/OpenGL/compiler/debug.h
index 77798ef..f9f92d5 100644
--- a/src/OpenGL/compiler/debug.h
+++ b/src/OpenGL/compiler/debug.h
@@ -30,42 +30,37 @@
#endif // _DEBUG
// Outputs text to the debug log
+namespace sh {
#ifdef TRACE_ENABLED
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
void Trace(const char* format, ...);
-#ifdef __cplusplus
+#else
+inline void Trace(const char* format, ...) {}
+#endif
+inline void Trace() {}
}
-#endif // __cplusplus
-
-#else // TRACE_ENABLED
-
-#define Trace(...) ((void)0)
-
-#endif // TRACE_ENABLED
// A macro asserting a condition and outputting failures to the debug log
#undef ASSERT
#define ASSERT(expression) do { \
if(!(expression)) \
- Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
+ sh::Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
assert(expression); \
} while(0)
#undef UNIMPLEMENTED
-#define UNIMPLEMENTED() do { \
- Trace("Unimplemented invoked: %s(%d)\n", __FUNCTION__, __LINE__); \
+#define UNIMPLEMENTED(...) do { \
+ sh::Trace("Unimplemented invoked: %s(%d): ", __FUNCTION__, __LINE__); \
+ sh::Trace(##__VA_ARGS__); \
+ sh::Trace("\n"); \
assert(false); \
} while(0)
#undef UNREACHABLE
#define UNREACHABLE(value) do { \
- Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
+ sh::Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
assert(false); \
} while(0)
-#endif // __ANDROID__
+#endif // !__ANDROID__
#endif // COMPILER_DEBUG_H_
diff --git a/src/OpenGL/libGLESv2/libGLESv2.cpp b/src/OpenGL/libGLESv2/libGLESv2.cpp
index 541b116..d8a4a8f 100644
--- a/src/OpenGL/libGLESv2/libGLESv2.cpp
+++ b/src/OpenGL/libGLESv2/libGLESv2.cpp
@@ -962,8 +962,7 @@
}
else
{
- printf("internalformat = %x, colorbufferFormat = %X\n", internalformat, colorbufferFormat);
- UNIMPLEMENTED();
+ UNIMPLEMENTED("internalformat = %x, colorbufferFormat = %X", internalformat, colorbufferFormat);
return error(GL_INVALID_OPERATION);
}
diff --git a/src/Vulkan/VkDebug.hpp b/src/Vulkan/VkDebug.hpp
index c436b3e..4210ee5 100644
--- a/src/Vulkan/VkDebug.hpp
+++ b/src/Vulkan/VkDebug.hpp
@@ -28,6 +28,7 @@
{
// Outputs text to the debugging log
void trace(const char *format, ...);
+inline void trace() {}
}
// A macro to output a trace of a function call and its arguments to the debugging log
@@ -66,8 +67,10 @@
// A macro to indicate unimplemented functionality
#undef UNIMPLEMENTED
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
-#define UNIMPLEMENTED() do { \
- FIXME("\t! Unimplemented: %s(%d)\n", __FUNCTION__, __LINE__); \
+#define UNIMPLEMENTED(...) do { \
+ vk::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
+ vk::trace(##__VA_ARGS__); \
+ vk::trace("\n"); \
assert(false); \
} while(0)
#else