@@ -38,15 +38,19 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3838
3939#include " common/Common.h"
4040
41+ #include " ../Thread/ThreadMemory.h"
42+
4143namespace LogExtendedFunctionMode {
4244 enum {
45+ GLOBAL_NAME ,
4346 NAME ,
4447 TEMPLATE ,
4548 FULL
4649 };
4750};
4851
4952extern Cvar::Range<Cvar::Cvar<int >> r_vkLogExtendedFunctionNames;
53+ extern Cvar::Cvar<bool > r_vkLogShowThreadID;
5054
5155// This is kinda ugly, but it's the only way we can make it constexpr
5256
@@ -104,14 +108,18 @@ constexpr const std::string_view FunctionNameTemplate( const std::string_view na
104108 #endif
105109}
106110
107- inline std::string Tagged ( const std::string& message, const std::source_location& loc = std::source_location::current() ) {
111+ inline std::string Tagged ( const std::string& message, const bool useThreadID,
112+ const std::source_location& loc = std::source_location::current() ) {
113+ const std::string threadID = useThreadID ? Str::Format ( " Thread %s" , TLM .id ) : " " ;
114+
108115 switch ( r_vkLogExtendedFunctionNames.Get () ) {
116+ case LogExtendedFunctionMode::GLOBAL_NAME :
109117 case LogExtendedFunctionMode::NAME :
110- return Str::Format ( " %s(): %s" , FunctionName ( loc.function_name () ), message );
118+ return Str::Format ( " %s:%s (): %s" , threadID , FunctionName ( loc.function_name () ), message );
111119 case LogExtendedFunctionMode::TEMPLATE :
112- return Str::Format ( " %s(): %s" , FunctionNameTemplate ( loc.function_name () ), message );
120+ return Str::Format ( " %s:%s (): %s" , threadID , FunctionNameTemplate ( loc.function_name () ), message );
113121 case LogExtendedFunctionMode::FULL :
114- return Str::Format ( " %s(): %s" , loc.function_name (), message );
122+ return Str::Format ( " %s:%s (): %s" , threadID , loc.function_name (), message );
115123 default :
116124 ASSERT_UNREACHABLE ();
117125 }
@@ -120,14 +128,19 @@ inline std::string Tagged( const std::string& message, const std::source_locatio
120128/* Add this as a base class to be able to use Log::WarnTag() etc.
121129Allows either specifying a custom name for an object, or otherwise automatically using the class name */
122130struct Tag {
123- std::string Tagged ( const std::string& message, const std::source_location& loc = std::source_location::current() ) {
131+ std::string Tagged ( const std::string& message, const bool useThreadID,
132+ const std::source_location& loc = std::source_location::current() ) {
133+ const std::string threadID = useThreadID ? Str::Format ( " Thread %s" , TLM .id ) : " " ;
134+
124135 switch ( r_vkLogExtendedFunctionNames.Get () ) {
136+ case LogExtendedFunctionMode::GLOBAL_NAME :
137+ return Str::Format ( " %s:%s: %s" , threadID, name, message );
125138 case LogExtendedFunctionMode::NAME :
126- return Str::Format ( " %s:%s(): %s" , name, FunctionName ( loc.function_name () ), message );
139+ return Str::Format ( " %s:%s:%s (): %s" , threadID , name, FunctionName ( loc.function_name () ), message );
127140 case LogExtendedFunctionMode::TEMPLATE :
128- return Str::Format ( " %s:%s(): %s" , name, FunctionNameTemplate ( loc.function_name () ), message );
141+ return Str::Format ( " %s:%s:%s (): %s" , threadID , name, FunctionNameTemplate ( loc.function_name () ), message );
129142 case LogExtendedFunctionMode::FULL :
130- return Str::Format ( " %s(): %s" , loc.function_name (), message );
143+ return Str::Format ( " %s:%s (): %s" , threadID , loc.function_name (), message );
131144 default :
132145 ASSERT_UNREACHABLE ();
133146 }
@@ -148,9 +161,14 @@ struct Tag {
148161 }
149162};
150163
151- #define WarnTag ( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
152- #define NoticeTag ( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
153- #define VerboseTag ( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
154- #define DebugTag ( format, ... ) Warn( Tagged( format ), __VA_ARGS__ )
164+ #define WarnTag ( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
165+ #define NoticeTag ( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
166+ #define VerboseTag ( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
167+ #define DebugTag ( format, ... ) Warn( Tagged( format, r_vkLogShowThreadID.Get() ), __VA_ARGS__ )
168+
169+ #define WarnTagT ( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
170+ #define NoticeTagT ( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
171+ #define VerboseTagT ( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
172+ #define DebugTagT ( format, ... ) Warn( Tagged( format, true ), __VA_ARGS__ )
155173
156174#endif // TAG_H
0 commit comments