Namespace Log.h/cpp in dawn::

The LogMessage::LogMessage constructor was redefining a symbol that
exists in re2 inside of Chromium. So we namespace Log inside dawn:: to
avoid the conflict.

BUG=dawn:302

Change-Id: Ida349208e2c6fe9ac032e1bd8cd442dff0b3f6bc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14320
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2019-12-06 18:21:39 +00:00 committed by Commit Bot service account
parent dd4584340d
commit dc3317da6c
12 changed files with 170 additions and 158 deletions

View File

@ -49,11 +49,11 @@ void PrintDeviceError(WGPUErrorType errorType, const char* message, void*) {
UNREACHABLE(); UNREACHABLE();
return; return;
} }
ErrorLog() << errorTypeName << " error: " << message; dawn::ErrorLog() << errorTypeName << " error: " << message;
} }
void PrintGLFWError(int code, const char* message) { void PrintGLFWError(int code, const char* message) {
ErrorLog() << "GLFW error: " << code << " - " << message; dawn::ErrorLog() << "GLFW error: " << code << " - " << message;
} }
enum class CmdBufType { enum class CmdBufType {

View File

@ -19,7 +19,7 @@ void HandleAssertionFailure(const char* file,
const char* function, const char* function,
int line, int line,
const char* condition) { const char* condition) {
ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function dawn::ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function
<< "): " << condition; << "): " << condition;
DAWN_BREAKPOINT(); DAWN_BREAKPOINT();
} }

View File

@ -23,90 +23,94 @@
# include <android/log.h> # include <android/log.h>
#endif #endif
namespace { namespace dawn {
const char* SeverityName(LogSeverity severity) { namespace {
switch (severity) {
case LogSeverity::Debug: const char* SeverityName(LogSeverity severity) {
return "Debug"; switch (severity) {
case LogSeverity::Info: case LogSeverity::Debug:
return "Info"; return "Debug";
case LogSeverity::Warning: case LogSeverity::Info:
return "Warning"; return "Info";
case LogSeverity::Error: case LogSeverity::Warning:
return "Error"; return "Warning";
default: case LogSeverity::Error:
UNREACHABLE(); return "Error";
return ""; default:
UNREACHABLE();
return "";
}
} }
}
#if defined(DAWN_PLATFORM_ANDROID) #if defined(DAWN_PLATFORM_ANDROID)
android_LogPriority AndroidLogPriority(LogSeverity severity) { android_LogPriority AndroidLogPriority(LogSeverity severity) {
switch (severity) { switch (severity) {
case LogSeverity::Debug: case LogSeverity::Debug:
return ANDROID_LOG_INFO; return ANDROID_LOG_INFO;
case LogSeverity::Info: case LogSeverity::Info:
return ANDROID_LOG_INFO; return ANDROID_LOG_INFO;
case LogSeverity::Warning: case LogSeverity::Warning:
return ANDROID_LOG_WARN; return ANDROID_LOG_WARN;
case LogSeverity::Error: case LogSeverity::Error:
return ANDROID_LOG_ERROR; return ANDROID_LOG_ERROR;
default: default:
UNREACHABLE(); UNREACHABLE();
return ANDROID_LOG_ERROR; return ANDROID_LOG_ERROR;
}
} }
}
#endif // defined(DAWN_PLATFORM_ANDROID) #endif // defined(DAWN_PLATFORM_ANDROID)
} // anonymous namespace } // anonymous namespace
LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) { LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) {
}
LogMessage::~LogMessage() {
std::string fullMessage = mStream.str();
// If this message has been moved, its stream is empty.
if (fullMessage.empty()) {
return;
} }
const char* severityName = SeverityName(mSeverity); LogMessage::~LogMessage() {
std::string fullMessage = mStream.str();
FILE* outputStream = stdout; // If this message has been moved, its stream is empty.
if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) { if (fullMessage.empty()) {
outputStream = stderr; return;
} }
const char* severityName = SeverityName(mSeverity);
FILE* outputStream = stdout;
if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) {
outputStream = stderr;
}
#if defined(DAWN_PLATFORM_ANDROID) #if defined(DAWN_PLATFORM_ANDROID)
android_LogPriority androidPriority = AndroidLogPriority(mSeverity); android_LogPriority androidPriority = AndroidLogPriority(mSeverity);
__android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str()); __android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str());
#else // defined(DAWN_PLATFORM_ANDROID) #else // defined(DAWN_PLATFORM_ANDROID)
// Note: we use fprintf because <iostream> includes static initializers. // Note: we use fprintf because <iostream> includes static initializers.
fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str());
fflush(outputStream); fflush(outputStream);
#endif // defined(DAWN_PLATFORM_ANDROID) #endif // defined(DAWN_PLATFORM_ANDROID)
} }
LogMessage DebugLog() { LogMessage DebugLog() {
return {LogSeverity::Debug}; return {LogSeverity::Debug};
} }
LogMessage InfoLog() { LogMessage InfoLog() {
return {LogSeverity::Info}; return {LogSeverity::Info};
} }
LogMessage WarningLog() { LogMessage WarningLog() {
return {LogSeverity::Warning}; return {LogSeverity::Warning};
} }
LogMessage ErrorLog() { LogMessage ErrorLog() {
return {LogSeverity::Error}; return {LogSeverity::Error};
} }
LogMessage DebugLog(const char* file, const char* function, int line) { LogMessage DebugLog(const char* file, const char* function, int line) {
LogMessage message = DebugLog(); LogMessage message = DebugLog();
message << file << ":" << line << "(" << function << ")"; message << file << ":" << line << "(" << function << ")";
return message; return message;
} }
} // namespace dawn

View File

@ -45,46 +45,51 @@
#include <sstream> #include <sstream>
// Log levels mostly used to signal intent where the log message is produced and used to route the namespace dawn {
// message to the correct output.
enum class LogSeverity {
Debug,
Info,
Warning,
Error,
};
// Essentially an ostringstream that will print itself in its destructor. // Log levels mostly used to signal intent where the log message is produced and used to route
class LogMessage { // the message to the correct output.
public: enum class LogSeverity {
LogMessage(LogSeverity severity); Debug,
~LogMessage(); Info,
Warning,
Error,
};
LogMessage(LogMessage&& other) = default; // Essentially an ostringstream that will print itself in its destructor.
LogMessage& operator=(LogMessage&& other) = default; class LogMessage {
public:
LogMessage(LogSeverity severity);
~LogMessage();
template <typename T> LogMessage(LogMessage&& other) = default;
LogMessage& operator<<(T&& value) { LogMessage& operator=(LogMessage&& other) = default;
mStream << value;
return *this;
}
private: template <typename T>
LogMessage(const LogMessage& other) = delete; LogMessage& operator<<(T&& value) {
LogMessage& operator=(const LogMessage& other) = delete; mStream << value;
return *this;
}
LogSeverity mSeverity; private:
std::ostringstream mStream; LogMessage(const LogMessage& other) = delete;
}; LogMessage& operator=(const LogMessage& other) = delete;
// Short-hands to create a LogMessage with the respective severity. LogSeverity mSeverity;
LogMessage DebugLog(); std::ostringstream mStream;
LogMessage InfoLog(); };
LogMessage WarningLog();
LogMessage ErrorLog();
// DAWN_DEBUG is a helper macro that creates a DebugLog and outputs file/line/function information // Short-hands to create a LogMessage with the respective severity.
LogMessage DebugLog(const char* file, const char* function, int line); LogMessage DebugLog();
#define DAWN_DEBUG() DebugLog(__FILE__, __func__, __LINE__) LogMessage InfoLog();
LogMessage WarningLog();
LogMessage ErrorLog();
// DAWN_DEBUG is a helper macro that creates a DebugLog and outputs file/line/function
// information
LogMessage DebugLog(const char* file, const char* function, int line);
#define DAWN_DEBUG() ::dawn::DebugLog(__FILE__, __func__, __LINE__)
} // namespace dawn
#endif // COMMON_LOG_H_ #endif // COMMON_LOG_H_

View File

@ -167,7 +167,7 @@ namespace dawn_native {
ErrorData* error = maybeError.AcquireError(); ErrorData* error = maybeError.AcquireError();
ASSERT(error != nullptr); ASSERT(error != nullptr);
InfoLog() << error->GetMessage(); dawn::InfoLog() << error->GetMessage();
delete error; delete error;
return true; return true;

View File

@ -102,11 +102,11 @@ namespace dawn_native { namespace opengl {
} }
if (type == GL_DEBUG_TYPE_ERROR) { if (type == GL_DEBUG_TYPE_ERROR) {
WarningLog() << "OpenGL error:" dawn::WarningLog() << "OpenGL error:"
<< "\n Source: " << sourceText // << "\n Source: " << sourceText //
<< "\n ID: " << id // << "\n ID: " << id //
<< "\n Severity: " << severityText // << "\n Severity: " << severityText //
<< "\n Message: " << message; << "\n Message: " << message;
// Abort on an error when in Debug mode. // Abort on an error when in Debug mode.
UNREACHABLE(); UNREACHABLE();

View File

@ -64,7 +64,8 @@ namespace dawn_native { namespace opengl {
if (infoLogLength > 1) { if (infoLogLength > 1) {
std::vector<char> buffer(infoLogLength); std::vector<char> buffer(infoLogLength);
gl.GetShaderInfoLog(shader, infoLogLength, nullptr, &buffer[0]); gl.GetShaderInfoLog(shader, infoLogLength, nullptr, &buffer[0]);
ErrorLog() << source << "\nProgram compilation failed:\n" << buffer.data(); dawn::ErrorLog() << source << "\nProgram compilation failed:\n"
<< buffer.data();
} }
} }
return shader; return shader;
@ -95,7 +96,7 @@ namespace dawn_native { namespace opengl {
if (infoLogLength > 1) { if (infoLogLength > 1) {
std::vector<char> buffer(infoLogLength); std::vector<char> buffer(infoLogLength);
gl.GetProgramInfoLog(mProgram, infoLogLength, nullptr, &buffer[0]); gl.GetProgramInfoLog(mProgram, infoLogLength, nullptr, &buffer[0]);
ErrorLog() << "Program link failed:\n" << buffer.data(); dawn::ErrorLog() << "Program link failed:\n" << buffer.data();
} }
} }

View File

@ -253,7 +253,7 @@ namespace dawn_native { namespace vulkan {
const char* /*pLayerPrefix*/, const char* /*pLayerPrefix*/,
const char* pMessage, const char* pMessage,
void* /*pUserdata*/) { void* /*pUserdata*/) {
WarningLog() << pMessage; dawn::WarningLog() << pMessage;
ASSERT((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) == 0); ASSERT((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) == 0);
return VK_FALSE; return VK_FALSE;

View File

@ -159,16 +159,17 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
} }
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
InfoLog() << "\n\nUsage: " << argv[0] dawn::InfoLog()
<< " [GTEST_FLAGS...] [-w] [-d] [-c] [--adapter-vendor-id=x]\n" << "\n\nUsage: " << argv[0]
" -w, --use-wire: Run the tests through the wire (defaults to no wire)\n" << " [GTEST_FLAGS...] [-w] [-d] [-c] [--adapter-vendor-id=x]\n"
" -d, --enable-backend-validation: Enable backend validation (defaults" " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n"
" to disabled)\n" " -d, --enable-backend-validation: Enable backend validation (defaults"
" -c, --begin-capture-on-startup: Begin debug capture on startup " " to disabled)\n"
"(defaults to no capture)\n" " -c, --begin-capture-on-startup: Begin debug capture on startup "
" --skip-validation: Skip Dawn validation\n" "(defaults to no capture)\n"
" --adapter-vendor-id: Select adapter by vendor id to run end2end tests" " --skip-validation: Skip Dawn validation\n"
"on multi-GPU systems \n"; " --adapter-vendor-id: Select adapter by vendor id to run end2end tests"
"on multi-GPU systems \n";
continue; continue;
} }
} }
@ -187,25 +188,25 @@ void DawnTestEnvironment::SetUp() {
mInstance.get()->DiscoverDefaultAdapters(); mInstance.get()->DiscoverDefaultAdapters();
DiscoverOpenGLAdapter(); DiscoverOpenGLAdapter();
InfoLog() << "Testing configuration\n" dawn::InfoLog() << "Testing configuration\n"
"---------------------\n" "---------------------\n"
"UseWire: " "UseWire: "
<< (mUseWire ? "true" : "false") << (mUseWire ? "true" : "false")
<< "\n" << "\n"
"EnableBackendValidation: " "EnableBackendValidation: "
<< (mEnableBackendValidation ? "true" : "false") << (mEnableBackendValidation ? "true" : "false")
<< "\n" << "\n"
"SkipDawnValidation: " "SkipDawnValidation: "
<< (mSkipDawnValidation ? "true" : "false") << (mSkipDawnValidation ? "true" : "false")
<< "\n" << "\n"
"UseSpvc: " "UseSpvc: "
<< (mUseSpvc ? "true" : "false") << (mUseSpvc ? "true" : "false")
<< "\n" << "\n"
"BeginCaptureOnStartup: " "BeginCaptureOnStartup: "
<< (mBeginCaptureOnStartup ? "true" : "false") << (mBeginCaptureOnStartup ? "true" : "false")
<< "\n" << "\n"
"\n" "\n"
<< "System adapters: \n"; << "System adapters: \n";
for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) { for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) {
const dawn_native::PCIInfo& pci = adapter.GetPCIInfo(); const dawn_native::PCIInfo& pci = adapter.GetPCIInfo();
@ -217,14 +218,15 @@ void DawnTestEnvironment::SetUp() {
<< pci.deviceId; << pci.deviceId;
// Preparing for outputting hex numbers // Preparing for outputting hex numbers
InfoLog() << std::showbase << std::hex << std::setfill('0') << std::setw(4) dawn::InfoLog() << std::showbase << std::hex << std::setfill('0') << std::setw(4)
<< " - \"" << pci.name << "\"\n" << " - \"" << pci.name << "\"\n"
<< " type: " << DeviceTypeName(adapter.GetDeviceType()) << " type: " << DeviceTypeName(adapter.GetDeviceType())
<< ", backend: " << ParamName(adapter.GetBackendType()) << "\n" << ", backend: " << ParamName(adapter.GetBackendType()) << "\n"
<< " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str() << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
<< (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]" : "") << (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]"
<< "\n"; : "")
<< "\n";
} }
} }

View File

@ -295,11 +295,11 @@ class DawnTestBase {
}; };
// Skip a test when the given condition is satisfied. // Skip a test when the given condition is satisfied.
#define DAWN_SKIP_TEST_IF(condition) \ #define DAWN_SKIP_TEST_IF(condition) \
if (condition) { \ if (condition) { \
InfoLog() << "Test skipped: " #condition "."; \ dawn::InfoLog() << "Test skipped: " #condition "."; \
GTEST_SKIP(); \ GTEST_SKIP(); \
return; \ return; \
} }
template <typename Params = DawnTestParam> template <typename Params = DawnTestParam>

View File

@ -113,7 +113,7 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
} }
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
InfoLog() dawn::InfoLog()
<< "Additional flags:" << "Additional flags:"
<< " [--calibration] [--override-steps=x] [--enable-tracing] [--trace-file=file]\n" << " [--calibration] [--override-steps=x] [--enable-tracing] [--trace-file=file]\n"
<< " --calibration: Only run calibration. Calibration allows the perf test" << " --calibration: Only run calibration. Calibration allows the perf test"

View File

@ -67,7 +67,7 @@ namespace utils {
shaderc::Compiler compiler; shaderc::Compiler compiler;
auto result = compiler.CompileGlslToSpv(source, strlen(source), kind, "myshader?"); auto result = compiler.CompileGlslToSpv(source, strlen(source), kind, "myshader?");
if (result.GetCompilationStatus() != shaderc_compilation_status_success) { if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
ErrorLog() << result.GetErrorMessage(); dawn::ErrorLog() << result.GetErrorMessage();
return {}; return {};
} }
#ifdef DUMP_SPIRV_ASSEMBLY #ifdef DUMP_SPIRV_ASSEMBLY
@ -106,7 +106,7 @@ namespace utils {
shaderc::Compiler compiler; shaderc::Compiler compiler;
shaderc::SpvCompilationResult result = compiler.AssembleToSpv(source, strlen(source)); shaderc::SpvCompilationResult result = compiler.AssembleToSpv(source, strlen(source));
if (result.GetCompilationStatus() != shaderc_compilation_status_success) { if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
ErrorLog() << result.GetErrorMessage(); dawn::ErrorLog() << result.GetErrorMessage();
return {}; return {};
} }