From dc3317da6cd5242e525d3230516cfd2bbff25fe9 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 6 Dec 2019 18:21:39 +0000 Subject: [PATCH] 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 Reviewed-by: Austin Eng --- examples/SampleUtils.cpp | 4 +- src/common/Assert.cpp | 4 +- src/common/Log.cpp | 138 +++++++++++++------------- src/common/Log.h | 73 +++++++------- src/dawn_native/Instance.cpp | 2 +- src/dawn_native/opengl/BackendGL.cpp | 10 +- src/dawn_native/opengl/PipelineGL.cpp | 5 +- src/dawn_native/vulkan/BackendVk.cpp | 2 +- src/tests/DawnTest.cpp | 74 +++++++------- src/tests/DawnTest.h | 10 +- src/tests/perf_tests/DawnPerfTest.cpp | 2 +- src/utils/WGPUHelpers.cpp | 4 +- 12 files changed, 170 insertions(+), 158 deletions(-) diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 56597f0eb5..3dcf0e5502 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -49,11 +49,11 @@ void PrintDeviceError(WGPUErrorType errorType, const char* message, void*) { UNREACHABLE(); return; } - ErrorLog() << errorTypeName << " error: " << message; + dawn::ErrorLog() << errorTypeName << " error: " << message; } void PrintGLFWError(int code, const char* message) { - ErrorLog() << "GLFW error: " << code << " - " << message; + dawn::ErrorLog() << "GLFW error: " << code << " - " << message; } enum class CmdBufType { diff --git a/src/common/Assert.cpp b/src/common/Assert.cpp index dd829c829c..c4d7528872 100644 --- a/src/common/Assert.cpp +++ b/src/common/Assert.cpp @@ -19,7 +19,7 @@ void HandleAssertionFailure(const char* file, const char* function, int line, const char* condition) { - ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function - << "): " << condition; + dawn::ErrorLog() << "Assertion failure at " << file << ":" << line << " (" << function + << "): " << condition; DAWN_BREAKPOINT(); } diff --git a/src/common/Log.cpp b/src/common/Log.cpp index 6b52ef6cd3..04aeb08a95 100644 --- a/src/common/Log.cpp +++ b/src/common/Log.cpp @@ -23,90 +23,94 @@ # include #endif -namespace { +namespace dawn { - const char* SeverityName(LogSeverity severity) { - switch (severity) { - case LogSeverity::Debug: - return "Debug"; - case LogSeverity::Info: - return "Info"; - case LogSeverity::Warning: - return "Warning"; - case LogSeverity::Error: - return "Error"; - default: - UNREACHABLE(); - return ""; + namespace { + + const char* SeverityName(LogSeverity severity) { + switch (severity) { + case LogSeverity::Debug: + return "Debug"; + case LogSeverity::Info: + return "Info"; + case LogSeverity::Warning: + return "Warning"; + case LogSeverity::Error: + return "Error"; + default: + UNREACHABLE(); + return ""; + } } - } #if defined(DAWN_PLATFORM_ANDROID) - android_LogPriority AndroidLogPriority(LogSeverity severity) { - switch (severity) { - case LogSeverity::Debug: - return ANDROID_LOG_INFO; - case LogSeverity::Info: - return ANDROID_LOG_INFO; - case LogSeverity::Warning: - return ANDROID_LOG_WARN; - case LogSeverity::Error: - return ANDROID_LOG_ERROR; - default: - UNREACHABLE(); - return ANDROID_LOG_ERROR; + android_LogPriority AndroidLogPriority(LogSeverity severity) { + switch (severity) { + case LogSeverity::Debug: + return ANDROID_LOG_INFO; + case LogSeverity::Info: + return ANDROID_LOG_INFO; + case LogSeverity::Warning: + return ANDROID_LOG_WARN; + case LogSeverity::Error: + return ANDROID_LOG_ERROR; + default: + UNREACHABLE(); + return ANDROID_LOG_ERROR; + } } - } #endif // defined(DAWN_PLATFORM_ANDROID) -} // anonymous namespace + } // anonymous namespace -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; + LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) { } - const char* severityName = SeverityName(mSeverity); + LogMessage::~LogMessage() { + std::string fullMessage = mStream.str(); - FILE* outputStream = stdout; - if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) { - outputStream = stderr; - } + // If this message has been moved, its stream is empty. + if (fullMessage.empty()) { + return; + } + + const char* severityName = SeverityName(mSeverity); + + FILE* outputStream = stdout; + if (mSeverity == LogSeverity::Warning || mSeverity == LogSeverity::Error) { + outputStream = stderr; + } #if defined(DAWN_PLATFORM_ANDROID) - android_LogPriority androidPriority = AndroidLogPriority(mSeverity); - __android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str()); + android_LogPriority androidPriority = AndroidLogPriority(mSeverity); + __android_log_print(androidPriority, "Dawn", "%s: %s\n", severityName, fullMessage.c_str()); #else // defined(DAWN_PLATFORM_ANDROID) - // Note: we use fprintf because includes static initializers. - fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); - fflush(outputStream); + // Note: we use fprintf because includes static initializers. + fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); + fflush(outputStream); #endif // defined(DAWN_PLATFORM_ANDROID) -} + } -LogMessage DebugLog() { - return {LogSeverity::Debug}; -} + LogMessage DebugLog() { + return {LogSeverity::Debug}; + } -LogMessage InfoLog() { - return {LogSeverity::Info}; -} + LogMessage InfoLog() { + return {LogSeverity::Info}; + } -LogMessage WarningLog() { - return {LogSeverity::Warning}; -} + LogMessage WarningLog() { + return {LogSeverity::Warning}; + } -LogMessage ErrorLog() { - return {LogSeverity::Error}; -} + LogMessage ErrorLog() { + return {LogSeverity::Error}; + } -LogMessage DebugLog(const char* file, const char* function, int line) { - LogMessage message = DebugLog(); - message << file << ":" << line << "(" << function << ")"; - return message; -} + LogMessage DebugLog(const char* file, const char* function, int line) { + LogMessage message = DebugLog(); + message << file << ":" << line << "(" << function << ")"; + return message; + } + +} // namespace dawn diff --git a/src/common/Log.h b/src/common/Log.h index 2d2411a8f1..0504af61ed 100644 --- a/src/common/Log.h +++ b/src/common/Log.h @@ -45,46 +45,51 @@ #include -// Log levels mostly used to signal intent where the log message is produced and used to route the -// message to the correct output. -enum class LogSeverity { - Debug, - Info, - Warning, - Error, -}; +namespace dawn { -// Essentially an ostringstream that will print itself in its destructor. -class LogMessage { - public: - LogMessage(LogSeverity severity); - ~LogMessage(); + // Log levels mostly used to signal intent where the log message is produced and used to route + // the message to the correct output. + enum class LogSeverity { + Debug, + Info, + Warning, + Error, + }; - LogMessage(LogMessage&& other) = default; - LogMessage& operator=(LogMessage&& other) = default; + // Essentially an ostringstream that will print itself in its destructor. + class LogMessage { + public: + LogMessage(LogSeverity severity); + ~LogMessage(); - template - LogMessage& operator<<(T&& value) { - mStream << value; - return *this; - } + LogMessage(LogMessage&& other) = default; + LogMessage& operator=(LogMessage&& other) = default; - private: - LogMessage(const LogMessage& other) = delete; - LogMessage& operator=(const LogMessage& other) = delete; + template + LogMessage& operator<<(T&& value) { + mStream << value; + return *this; + } - LogSeverity mSeverity; - std::ostringstream mStream; -}; + private: + LogMessage(const LogMessage& other) = delete; + LogMessage& operator=(const LogMessage& other) = delete; -// Short-hands to create a LogMessage with the respective severity. -LogMessage DebugLog(); -LogMessage InfoLog(); -LogMessage WarningLog(); -LogMessage ErrorLog(); + LogSeverity mSeverity; + std::ostringstream mStream; + }; -// 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() DebugLog(__FILE__, __func__, __LINE__) + // Short-hands to create a LogMessage with the respective severity. + LogMessage DebugLog(); + 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_ diff --git a/src/dawn_native/Instance.cpp b/src/dawn_native/Instance.cpp index a5f8294bf0..d7589870d4 100644 --- a/src/dawn_native/Instance.cpp +++ b/src/dawn_native/Instance.cpp @@ -167,7 +167,7 @@ namespace dawn_native { ErrorData* error = maybeError.AcquireError(); ASSERT(error != nullptr); - InfoLog() << error->GetMessage(); + dawn::InfoLog() << error->GetMessage(); delete error; return true; diff --git a/src/dawn_native/opengl/BackendGL.cpp b/src/dawn_native/opengl/BackendGL.cpp index 64a32a82c1..a8f98ae74a 100644 --- a/src/dawn_native/opengl/BackendGL.cpp +++ b/src/dawn_native/opengl/BackendGL.cpp @@ -102,11 +102,11 @@ namespace dawn_native { namespace opengl { } if (type == GL_DEBUG_TYPE_ERROR) { - WarningLog() << "OpenGL error:" - << "\n Source: " << sourceText // - << "\n ID: " << id // - << "\n Severity: " << severityText // - << "\n Message: " << message; + dawn::WarningLog() << "OpenGL error:" + << "\n Source: " << sourceText // + << "\n ID: " << id // + << "\n Severity: " << severityText // + << "\n Message: " << message; // Abort on an error when in Debug mode. UNREACHABLE(); diff --git a/src/dawn_native/opengl/PipelineGL.cpp b/src/dawn_native/opengl/PipelineGL.cpp index 68e3bce0f5..e727e9b29d 100644 --- a/src/dawn_native/opengl/PipelineGL.cpp +++ b/src/dawn_native/opengl/PipelineGL.cpp @@ -64,7 +64,8 @@ namespace dawn_native { namespace opengl { if (infoLogLength > 1) { std::vector buffer(infoLogLength); 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; @@ -95,7 +96,7 @@ namespace dawn_native { namespace opengl { if (infoLogLength > 1) { std::vector buffer(infoLogLength); gl.GetProgramInfoLog(mProgram, infoLogLength, nullptr, &buffer[0]); - ErrorLog() << "Program link failed:\n" << buffer.data(); + dawn::ErrorLog() << "Program link failed:\n" << buffer.data(); } } diff --git a/src/dawn_native/vulkan/BackendVk.cpp b/src/dawn_native/vulkan/BackendVk.cpp index 37efa40a2b..924753ca09 100644 --- a/src/dawn_native/vulkan/BackendVk.cpp +++ b/src/dawn_native/vulkan/BackendVk.cpp @@ -253,7 +253,7 @@ namespace dawn_native { namespace vulkan { const char* /*pLayerPrefix*/, const char* pMessage, void* /*pUserdata*/) { - WarningLog() << pMessage; + dawn::WarningLog() << pMessage; ASSERT((flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) == 0); return VK_FALSE; diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 5c3ca2984c..8df1cd830e 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -159,16 +159,17 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) { } if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { - InfoLog() << "\n\nUsage: " << argv[0] - << " [GTEST_FLAGS...] [-w] [-d] [-c] [--adapter-vendor-id=x]\n" - " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n" - " -d, --enable-backend-validation: Enable backend validation (defaults" - " to disabled)\n" - " -c, --begin-capture-on-startup: Begin debug capture on startup " - "(defaults to no capture)\n" - " --skip-validation: Skip Dawn validation\n" - " --adapter-vendor-id: Select adapter by vendor id to run end2end tests" - "on multi-GPU systems \n"; + dawn::InfoLog() + << "\n\nUsage: " << argv[0] + << " [GTEST_FLAGS...] [-w] [-d] [-c] [--adapter-vendor-id=x]\n" + " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n" + " -d, --enable-backend-validation: Enable backend validation (defaults" + " to disabled)\n" + " -c, --begin-capture-on-startup: Begin debug capture on startup " + "(defaults to no capture)\n" + " --skip-validation: Skip Dawn validation\n" + " --adapter-vendor-id: Select adapter by vendor id to run end2end tests" + "on multi-GPU systems \n"; continue; } } @@ -187,25 +188,25 @@ void DawnTestEnvironment::SetUp() { mInstance.get()->DiscoverDefaultAdapters(); DiscoverOpenGLAdapter(); - InfoLog() << "Testing configuration\n" - "---------------------\n" - "UseWire: " - << (mUseWire ? "true" : "false") - << "\n" - "EnableBackendValidation: " - << (mEnableBackendValidation ? "true" : "false") - << "\n" - "SkipDawnValidation: " - << (mSkipDawnValidation ? "true" : "false") - << "\n" - "UseSpvc: " - << (mUseSpvc ? "true" : "false") - << "\n" - "BeginCaptureOnStartup: " - << (mBeginCaptureOnStartup ? "true" : "false") - << "\n" - "\n" - << "System adapters: \n"; + dawn::InfoLog() << "Testing configuration\n" + "---------------------\n" + "UseWire: " + << (mUseWire ? "true" : "false") + << "\n" + "EnableBackendValidation: " + << (mEnableBackendValidation ? "true" : "false") + << "\n" + "SkipDawnValidation: " + << (mSkipDawnValidation ? "true" : "false") + << "\n" + "UseSpvc: " + << (mUseSpvc ? "true" : "false") + << "\n" + "BeginCaptureOnStartup: " + << (mBeginCaptureOnStartup ? "true" : "false") + << "\n" + "\n" + << "System adapters: \n"; for (const dawn_native::Adapter& adapter : mInstance->GetAdapters()) { const dawn_native::PCIInfo& pci = adapter.GetPCIInfo(); @@ -217,14 +218,15 @@ void DawnTestEnvironment::SetUp() { << pci.deviceId; // 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" - << " type: " << DeviceTypeName(adapter.GetDeviceType()) - << ", backend: " << ParamName(adapter.GetBackendType()) << "\n" - << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str() - << (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]" : "") - << "\n"; + << " - \"" << pci.name << "\"\n" + << " type: " << DeviceTypeName(adapter.GetDeviceType()) + << ", backend: " << ParamName(adapter.GetBackendType()) << "\n" + << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str() + << (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]" + : "") + << "\n"; } } diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index 73fe149f79..3f23d4ea1c 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -295,11 +295,11 @@ class DawnTestBase { }; // Skip a test when the given condition is satisfied. -#define DAWN_SKIP_TEST_IF(condition) \ - if (condition) { \ - InfoLog() << "Test skipped: " #condition "."; \ - GTEST_SKIP(); \ - return; \ +#define DAWN_SKIP_TEST_IF(condition) \ + if (condition) { \ + dawn::InfoLog() << "Test skipped: " #condition "."; \ + GTEST_SKIP(); \ + return; \ } template diff --git a/src/tests/perf_tests/DawnPerfTest.cpp b/src/tests/perf_tests/DawnPerfTest.cpp index 5d0aa1b719..fd4db8acc8 100644 --- a/src/tests/perf_tests/DawnPerfTest.cpp +++ b/src/tests/perf_tests/DawnPerfTest.cpp @@ -113,7 +113,7 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv) } if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { - InfoLog() + dawn::InfoLog() << "Additional flags:" << " [--calibration] [--override-steps=x] [--enable-tracing] [--trace-file=file]\n" << " --calibration: Only run calibration. Calibration allows the perf test" diff --git a/src/utils/WGPUHelpers.cpp b/src/utils/WGPUHelpers.cpp index d232949b14..e56ef1b80c 100644 --- a/src/utils/WGPUHelpers.cpp +++ b/src/utils/WGPUHelpers.cpp @@ -67,7 +67,7 @@ namespace utils { shaderc::Compiler compiler; auto result = compiler.CompileGlslToSpv(source, strlen(source), kind, "myshader?"); if (result.GetCompilationStatus() != shaderc_compilation_status_success) { - ErrorLog() << result.GetErrorMessage(); + dawn::ErrorLog() << result.GetErrorMessage(); return {}; } #ifdef DUMP_SPIRV_ASSEMBLY @@ -106,7 +106,7 @@ namespace utils { shaderc::Compiler compiler; shaderc::SpvCompilationResult result = compiler.AssembleToSpv(source, strlen(source)); if (result.GetCompilationStatus() != shaderc_compilation_status_success) { - ErrorLog() << result.GetErrorMessage(); + dawn::ErrorLog() << result.GetErrorMessage(); return {}; }