diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-09-23 03:51:25 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-09-23 03:51:25 +0000 |
| commit | 2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331 (patch) | |
| tree | 2d5e8fecedb2d728c026a06ebb1930badd4aeccc | |
| parent | Reworked vulkan dynamic heap deallocation to use main release queue (diff) | |
| download | DiligentCore-2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331.tar.gz DiligentCore-2f5b2dd6bb2db2464d9b9c9d95fc0a57559fa331.zip | |
Reworked message formatting
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/include/D3DErrors.h | 7 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp | 5 | ||||
| -rw-r--r-- | Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp | 9 | ||||
| -rw-r--r-- | Platforms/Android/src/AndroidDebug.cpp | 2 | ||||
| -rw-r--r-- | Platforms/Basic/interface/DebugUtilities.h | 7 | ||||
| -rw-r--r-- | Platforms/Basic/src/BasicPlatformDebug.cpp | 6 | ||||
| -rw-r--r-- | Platforms/Linux/src/LinuxDebug.cpp | 2 | ||||
| -rw-r--r-- | Platforms/UWP/src/UWPDebug.cpp | 2 | ||||
| -rw-r--r-- | Platforms/Win32/src/Win32Debug.cpp | 2 | ||||
| -rw-r--r-- | Primitives/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Primitives/interface/Errors.h | 17 | ||||
| -rw-r--r-- | Primitives/interface/FormatString.h (renamed from Primitives/interface/FormatMessage.h) | 20 | ||||
| -rw-r--r-- | Primitives/src/test.cpp | 2 |
13 files changed, 40 insertions, 43 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h b/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h index b1d1e068..d3d3792f 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h +++ b/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h @@ -81,10 +81,9 @@ do{ \ HRESULT _hr_ = Expr; \ if(FAILED(_hr_)) \ { \ - Diligent::MsgStream ms; \ - Diligent::FormatMsg(ms, __VA_ARGS__); \ - ComErrorDesc ErrDesc( _hr_ ); \ - LOG_ERROR_AND_THROW( ms.str(), "\nHRESULT Desc: ", ErrDesc.Get());\ + auto msg = Diligent::FormatString(__VA_ARGS__); \ + ComErrorDesc ErrDesc( _hr_ ); \ + LOG_ERROR_AND_THROW( msg, "\nHRESULT Desc: ", ErrDesc.Get());\ } \ }while(false) diff --git a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp index 973b1add..65e138b6 100644 --- a/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp +++ b/Graphics/GraphicsEngineVulkan/src/VulkanUtilities/VulkanMemoryManager.cpp @@ -49,9 +49,8 @@ VulkanMemoryPage::VulkanMemoryPage(VulkanMemoryManager& ParentMemoryMgr, MemAlloc.allocationSize = PageSize; MemAlloc.memoryTypeIndex = MemoryTypeIndex; - std::stringstream ss; - Diligent::FormatMsg(ss, "Device memory page. Size: ", Diligent::FormatMemorySize(PageSize, 2), ", type: ", MemoryTypeIndex); - m_VkMemory = ParentMemoryMgr.m_LogicalDevice.AllocateDeviceMemory(MemAlloc, ss.str().c_str()); + auto MemoryName = Diligent::FormatString("Device memory page. Size: ", Diligent::FormatMemorySize(PageSize, 2), ", type: ", MemoryTypeIndex); + m_VkMemory = ParentMemoryMgr.m_LogicalDevice.AllocateDeviceMemory(MemAlloc, MemoryName.c_str()); if (IsHostVisible) { diff --git a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp index 6eaa5497..bd032a06 100644 --- a/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp +++ b/Graphics/HLSL2GLSLConverterLib/src/HLSL2GLSLConverterImpl.cpp @@ -916,11 +916,10 @@ String HLSL2GLSLConverterImpl::ConversionStream::PrintTokenContext( IteratorType #define VERIFY_PARSER_STATE( Token, Condition, ... )\ - if( !(Condition) ) \ - { \ - MsgStream ss; \ - FormatMsg( ss, __VA_ARGS__ ); \ - LOG_ERROR_AND_THROW( ss.str(), "\n", PrintTokenContext(Token, 4) );\ + if( !(Condition) ) \ + { \ + auto err = FormatString(__VA_ARGS__ ); \ + LOG_ERROR_AND_THROW( err, "\n", PrintTokenContext(Token, 4) );\ } template<typename IterType> diff --git a/Platforms/Android/src/AndroidDebug.cpp b/Platforms/Android/src/AndroidDebug.cpp index 6480b614..52658ba0 100644 --- a/Platforms/Android/src/AndroidDebug.cpp +++ b/Platforms/Android/src/AndroidDebug.cpp @@ -22,7 +22,7 @@ */ #include "AndroidDebug.h" -#include "FormatMessage.h" +#include "FormatString.h" #include <android/log.h> #include <csignal> diff --git a/Platforms/Basic/interface/DebugUtilities.h b/Platforms/Basic/interface/DebugUtilities.h index 0ecc6c81..20eee447 100644 --- a/Platforms/Basic/interface/DebugUtilities.h +++ b/Platforms/Basic/interface/DebugUtilities.h @@ -23,7 +23,7 @@ #pragma once -#include "../../../Primitives/interface/FormatMessage.h" +#include "../../../Primitives/interface/FormatString.h" #include "../../../Primitives/interface/Errors.h" #include "BasicPlatformDebug.h" @@ -33,9 +33,8 @@ #define ASSERTION_FAILED(Message, ...)\ do{ \ - Diligent::MsgStream ms; \ - Diligent::FormatMsg( ms, Message, ##__VA_ARGS__);\ - DebugAssertionFailed( ms.str().c_str(), __FUNCTION__, __FILE__, __LINE__); \ + auto msg = Diligent::FormatString(Message, ##__VA_ARGS__);\ + DebugAssertionFailed( msg.c_str(), __FUNCTION__, __FILE__, __LINE__); \ }while(false) # define VERIFY(Expr, Message, ...)\ diff --git a/Platforms/Basic/src/BasicPlatformDebug.cpp b/Platforms/Basic/src/BasicPlatformDebug.cpp index 31e46692..0d649070 100644 --- a/Platforms/Basic/src/BasicPlatformDebug.cpp +++ b/Platforms/Basic/src/BasicPlatformDebug.cpp @@ -22,7 +22,7 @@ */ #include "BasicPlatformDebug.h" -#include "FormatMessage.h" +#include "FormatString.h" #include "BasicFileSystem.h" #include <iostream> @@ -35,9 +35,7 @@ String BasicPlatformDebug :: FormatAssertionFailedMessage( const Char *Message, { String FileName; BasicFileSystem::SplitFilePath( File, nullptr, &FileName ); - std::stringstream msgss; - Diligent::FormatMsg( msgss, "Debug assertion failed in ", Function, "(), file ", FileName, ", line ", Line, ":\n", Message); - return msgss.str(); + return Diligent::FormatString("Debug assertion failed in ", Function, "(), file ", FileName, ", line ", Line, ":\n", Message); } String BasicPlatformDebug::FormatDebugMessage(DebugMessageSeverity Severity, diff --git a/Platforms/Linux/src/LinuxDebug.cpp b/Platforms/Linux/src/LinuxDebug.cpp index 00a6554d..4ab433a4 100644 --- a/Platforms/Linux/src/LinuxDebug.cpp +++ b/Platforms/Linux/src/LinuxDebug.cpp @@ -25,7 +25,7 @@ #include <iostream> #include "LinuxDebug.h" -#include "FormatMessage.h" +#include "FormatString.h" using namespace Diligent; diff --git a/Platforms/UWP/src/UWPDebug.cpp b/Platforms/UWP/src/UWPDebug.cpp index ed78587e..3dca028e 100644 --- a/Platforms/UWP/src/UWPDebug.cpp +++ b/Platforms/UWP/src/UWPDebug.cpp @@ -24,7 +24,7 @@ #include "pch.h" #include "UWPDebug.h" -#include "FormatMessage.h" +#include "FormatString.h" #include <csignal> #define NOMINMAX diff --git a/Platforms/Win32/src/Win32Debug.cpp b/Platforms/Win32/src/Win32Debug.cpp index c1483c4a..7c8aa2b4 100644 --- a/Platforms/Win32/src/Win32Debug.cpp +++ b/Platforms/Win32/src/Win32Debug.cpp @@ -24,7 +24,7 @@ #include "pch.h" #include "Win32Debug.h" -#include "FormatMessage.h" +#include "FormatString.h" #include <csignal> #include <iostream> #include <Windows.h> diff --git a/Primitives/CMakeLists.txt b/Primitives/CMakeLists.txt index 82e0fefb..2f87b4cb 100644 --- a/Primitives/CMakeLists.txt +++ b/Primitives/CMakeLists.txt @@ -13,7 +13,7 @@ set(INTERFACE interface/DebugOutput.h interface/Errors.h interface/FileStream.h - interface/FormatMessage.h + interface/FormatString.h interface/InterfaceID.h interface/MemoryAllocator.h interface/Object.h diff --git a/Primitives/interface/Errors.h b/Primitives/interface/Errors.h index 187a55ce..d38d4cc5 100644 --- a/Primitives/interface/Errors.h +++ b/Primitives/interface/Errors.h @@ -28,7 +28,7 @@ #include <iostream> #include "DebugOutput.h" -#include "FormatMessage.h" +#include "FormatString.h" namespace Diligent { @@ -44,16 +44,14 @@ inline void ThrowIf<true>(std::string &&msg) throw std::runtime_error( std::move(msg) ); } -template<bool bThrowException, typename FirstArgType, typename... RestArgsType> -void LogError( const char *Function, const char *FullFilePath, int Line, const FirstArgType& first, const RestArgsType&... RestArgs ) +template<bool bThrowException, typename... ArgsType> +void LogError( const char *Function, const char *FullFilePath, int Line, const ArgsType&... Args ) { std::string FileName(FullFilePath); auto LastSlashPos = FileName.find_last_of("/\\"); if(LastSlashPos != std::string::npos) FileName.erase(0, LastSlashPos+1); - Diligent::MsgStream ss; - Diligent::FormatMsg( ss, first, RestArgs... ); - auto Msg = ss.str(); + auto Msg = Diligent::FormatString(Args...); if(DebugMessageCallback != nullptr) { DebugMessageCallback( bThrowException ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line); @@ -94,10 +92,9 @@ do{ \ #define LOG_DEBUG_MESSAGE(Severity, ...)\ -do{ \ - Diligent::MsgStream _msg_ss; \ - Diligent::FormatMsg( _msg_ss, ##__VA_ARGS__ );\ - if(Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback( Severity, _msg_ss.str().c_str(), nullptr, nullptr, 0 );\ +do{ \ + auto _msg = Diligent::FormatString(##__VA_ARGS__ );\ + if(Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback( Severity, _msg.c_str(), nullptr, nullptr, 0 );\ }while(false) #define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) diff --git a/Primitives/interface/FormatMessage.h b/Primitives/interface/FormatString.h index bd4c20c7..08d1ca85 100644 --- a/Primitives/interface/FormatMessage.h +++ b/Primitives/interface/FormatString.h @@ -28,19 +28,25 @@ namespace Diligent { - typedef std::stringstream MsgStream; - template<typename SSType, typename ArgType> - void FormatMsg( SSType &ss, const ArgType& Arg ) + void FormatStrSS(SSType &ss, const ArgType& Arg) { ss << Arg; } template<typename SSType, typename FirstArgType, typename... RestArgsType> - void FormatMsg( SSType &ss, const FirstArgType& FirstArg, const RestArgsType&... RestArgs ) + void FormatStrSS(SSType &ss, const FirstArgType& FirstArg, const RestArgsType&... RestArgs) + { + FormatStrSS( ss, FirstArg ); + FormatStrSS( ss, RestArgs... ); // recursive call using pack expansion syntax + } + + template<typename... RestArgsType> + std::string FormatString(const RestArgsType&... Args) { - FormatMsg( ss, FirstArg ); - FormatMsg( ss, RestArgs... ); // recursive call using pack expansion syntax + std::stringstream ss; + FormatStrSS(ss, Args...); + return ss.str(); } template<typename Type> @@ -58,7 +64,7 @@ namespace Diligent } template<typename SSType, typename Type> - void FormatMsg(SSType& ss, const MemorySizeFormatter<Type>& Arg) + void FormatStrSS(SSType& ss, const MemorySizeFormatter<Type>& Arg) { auto ref_size = Arg.ref_size != 0 ? Arg.ref_size : Arg.size; if (ref_size >= (1 << 30)) diff --git a/Primitives/src/test.cpp b/Primitives/src/test.cpp index c578e76f..67a6eb34 100644 --- a/Primitives/src/test.cpp +++ b/Primitives/src/test.cpp @@ -26,6 +26,6 @@ #include "ReferenceCounters.h" #include "Object.h" #include "MemoryAllocator.h" -#include "FormatMessage.h" +#include "FormatString.h" #include "FileStream.h" #include "DataBlob.h" |
