diff --git a/Source/Engine/Core/Log.h b/Source/Engine/Core/Log.h index f09099d11..e10fc50a0 100644 --- a/Source/Engine/Core/Log.h +++ b/Source/Engine/Core/Log.h @@ -56,6 +56,8 @@ API_ENUM() enum class LogType #define LOG_FLUSH() Log::Logger::Flush() #endif +#define LOG_FLOOR() Log::Logger::WriteFloor() + extern const Char* ToString(LogType e); namespace Log @@ -191,8 +193,9 @@ namespace Log #else -#define LOG(messageType, format, ...) -#define LOG_STR(messageType, str) -#define LOG_FLUSH() +#define LOG(messageType, format, ...) {} +#define LOG_STR(messageType, str) {} +#define LOG_FLUSH() {} +#define LOG_FLOOR() {} #endif diff --git a/Source/Engine/Engine/Engine.cpp b/Source/Engine/Engine/Engine.cpp index d9a4173c8..5607432c2 100644 --- a/Source/Engine/Engine/Engine.cpp +++ b/Source/Engine/Engine/Engine.cpp @@ -170,10 +170,8 @@ int32 Engine::Main(const Char* cmdLine) #if !USE_EDITOR && (PLATFORM_WINDOWS || PLATFORM_LINUX || PLATFORM_MAC) EngineImpl::RunInBackground = PlatformSettings::Get()->RunInBackground; #endif -#if LOG_ENABLE - Log::Logger::WriteFloor(); + LOG_FLOOR(); LOG_FLUSH(); -#endif Time::Synchronize(); EngineImpl::IsReady = true; PROFILE_MEM_END(); @@ -557,6 +555,7 @@ void Engine::OnExit() #if COMPILE_WITH_PROFILER ProfilerCPU::Dispose(); ProfilerGPU::Dispose(); + ProfilerMemory::Enabled = false; #endif #if LOG_ENABLE diff --git a/Source/Engine/Graphics/Graphics.cpp b/Source/Engine/Graphics/Graphics.cpp index 733e8c222..bf17970ea 100644 --- a/Source/Engine/Graphics/Graphics.cpp +++ b/Source/Engine/Graphics/Graphics.cpp @@ -101,10 +101,8 @@ bool GraphicsService::Init() PROFILE_MEM(Graphics); // Create and initialize graphics device -#if LOG_ENABLE - Log::Logger::WriteFloor(); + LOG_FLOOR(); LOG(Info, "Creating Graphics Device..."); -#endif PixelFormatExtensions::Init(); GPUDevice* device = nullptr; @@ -218,9 +216,7 @@ bool GraphicsService::Init() { return true; } -#if LOG_ENABLE - Log::Logger::WriteFloor(); -#endif + LOG_FLOOR(); return false; } diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp index c578fd295..411d9dd92 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUDeviceDX11.cpp @@ -765,7 +765,7 @@ void GPUDeviceDX11::DrawEnd() { GPUDeviceDX::DrawEnd(); -#if GPU_ENABLE_DIAGNOSTICS +#if GPU_ENABLE_DIAGNOSTICS && LOG_ENABLE // Flush debug messages queue ComPtr infoQueue; VALIDATE_DIRECTX_CALL(_device->QueryInterface(IID_PPV_ARGS(&infoQueue))); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp index dd2bc3da4..5f278a8ae 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUContextDX12.cpp @@ -39,7 +39,7 @@ #include "Engine/Threading/Threading.h" #define DX12_ENABLE_RESOURCE_BARRIERS_BATCHING 1 -#define DX12_ENABLE_RESOURCE_BARRIERS_DEBUGGING 0 +#define DX12_ENABLE_RESOURCE_BARRIERS_DEBUGGING (0 && LOG_ENABLE) inline bool operator!=(const D3D12_VERTEX_BUFFER_VIEW& l, const D3D12_VERTEX_BUFFER_VIEW& r) { diff --git a/Source/Engine/GraphicsDevice/DirectX/RenderToolsDX.cpp b/Source/Engine/GraphicsDevice/DirectX/RenderToolsDX.cpp index f4bf4a3df..f195b8b41 100644 --- a/Source/Engine/GraphicsDevice/DirectX/RenderToolsDX.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/RenderToolsDX.cpp @@ -387,10 +387,14 @@ void RenderToolsDX::LogD3DResult(HRESULT result, const char* file, uint32 line, if (removedReason == DXGI_ERROR_DEVICE_HUNG) errorType = FatalErrorType::GPUHang; } + else if (fatal) + errorType = FatalErrorType::Unknown; if (errorType != FatalErrorType::None) Platform::Fatal(msg, nullptr, errorType); +#if LOG_ENABLE else - Log::Logger::Write(fatal ? LogType::Fatal : LogType::Error, msg); + Log::Logger::Write(LogType::Error, msg); +#endif } LPCSTR RenderToolsDX::GetVertexInputSemantic(VertexElement::Types type, UINT& semanticIndex) diff --git a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp index d535f6ea1..604b8a612 100644 --- a/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp +++ b/Source/Engine/GraphicsDevice/Vulkan/RenderToolsVulkan.cpp @@ -248,11 +248,13 @@ void RenderToolsVulkan::LogVkResult(VkResult result, const char* file, uint32 li errorType = FatalErrorType::GPUHang; else if (result == VK_ERROR_DEVICE_LOST || result == VK_ERROR_SURFACE_LOST_KHR || result == VK_ERROR_MEMORY_MAP_FAILED) errorType = FatalErrorType::GPUCrash; + else if (fatal) + errorType = FatalErrorType::Unknown; if (errorType != FatalErrorType::None) Platform::Fatal(msg, nullptr, errorType); #if LOG_ENABLE else - Log::Logger::Write(fatal ? LogType::Fatal : LogType::Error, msg); + Log::Logger::Write(LogType::Error, msg); #endif } diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 7e8428e64..0bde861c7 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -314,7 +314,7 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er { // Log separation for crash info LOG_FLUSH(); - Log::Logger::WriteFloor(); + LOG_FLOOR(); LOG(Error, ""); LOG(Error, "Critical error! Reason: {0}", msg); LOG(Error, ""); @@ -400,12 +400,12 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er // Capture the original log file LOG(Error, ""); - Log::Logger::WriteFloor(); + LOG_FLOOR(); LOG_FLUSH(); FileSystem::CopyFile(crashDataFolder / TEXT("Log.txt"), Log::Logger::LogFilePath); LOG(Error, "Crash info collected."); - Log::Logger::WriteFloor(); + LOG_FLOOR(); } #endif diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 44e5a313d..4b55f8bd5 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -3029,8 +3029,10 @@ int32 LinuxPlatform::CreateProcess(CreateProcessSettings& settings) String line(lineBuffer); if (settings.SaveOutput) settings.Output.Add(line.Get(), line.Length()); +#if LOG_ENABLE if (settings.LogOutput) Log::Logger::Write(LogType::Info, line); +#endif } } int stat_loc; diff --git a/Source/Engine/Platform/Mac/MacPlatform.cpp b/Source/Engine/Platform/Mac/MacPlatform.cpp index 6cb8b1153..6c7fbf533 100644 --- a/Source/Engine/Platform/Mac/MacPlatform.cpp +++ b/Source/Engine/Platform/Mac/MacPlatform.cpp @@ -485,15 +485,15 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings) String line((const char*)data.bytes, data.length); if (settings.SaveOutput) settings.Output.Add(line.Get(), line.Length()); +#if LOG_ENABLE if (settings.LogOutput) { StringView lineView(line); if (line[line.Length() - 1] == '\n') lineView = StringView(line.Get(), line.Length() - 1); -#if LOG_ENABLE Log::Logger::Write(LogType::Info, lineView); -#endif } +#endif [[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify]; } } @@ -514,15 +514,15 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings) String line((const char*)data.bytes, data.length); if (settings.SaveOutput) settings.Output.Add(line.Get(), line.Length()); +#if LOG_ENABLE if (settings.LogOutput) { StringView lineView(line); if (line[line.Length() - 1] == '\n') lineView = StringView(line.Get(), line.Length() - 1); -#if LOG_ENABLE Log::Logger::Write(LogType::Error, lineView); -#endif } +#endif [[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify]; } } diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index 277927af3..697174a47 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -1054,8 +1054,10 @@ void ReadPipe(HANDLE pipe, Array& rawData, Array& logData, LogType l int32 tmp; StringUtils::ConvertANSI2UTF16(rawData.Get(), logData.Get(), rawData.Count(), tmp); logData.Last() = '\0'; +#if LOG_ENABLE if (settings.LogOutput) Log::Logger::Write(logType, StringView(logData.Get(), rawData.Count())); +#endif if (settings.SaveOutput) settings.Output.Add(logData.Get(), rawData.Count()); } diff --git a/Source/Engine/Profiler/ProfilerMemory.cpp b/Source/Engine/Profiler/ProfilerMemory.cpp index ed1a825d5..972dd6646 100644 --- a/Source/Engine/Profiler/ProfilerMemory.cpp +++ b/Source/Engine/Profiler/ProfilerMemory.cpp @@ -310,12 +310,12 @@ void TickProfilerMemory() // Update profiler memory PointersLocker.Lock(); - GroupMemory[(int32)ProfilerMemory::Groups::Profiler] = - sizeof(GroupMemory) + sizeof(GroupNames) + sizeof(GroupStack) + + GroupMemory[(int32)ProfilerMemory::Groups::Profiler] = + sizeof(GroupMemory) + sizeof(GroupNames) + sizeof(GroupStack) + #ifdef USE_TRACY_MEMORY_PLOTS - sizeof(GroupTracyPlotEnable) + + sizeof(GroupTracyPlotEnable) + #endif - Pointers.Capacity() * sizeof(Dictionary::Bucket); + Pointers.Capacity() * sizeof(Dictionary::Bucket); PointersLocker.Unlock(); // Get total system memory and update untracked amount @@ -431,8 +431,8 @@ void ProfilerMemory::OnMemoryAlloc(void* ptr, uint64 size) // Update group memory const int64 add = (int64)size; AddGroupMemory((Groups)ptrData.Group, add); - Platform::InterlockedAdd(&GroupMemory[(int32)ProfilerMemory::Groups::Malloc], add); - Platform::InterlockedIncrement(&GroupMemoryCount[(int32)ProfilerMemory::Groups::Malloc]); + Platform::InterlockedAdd(&GroupMemory[(int32)Groups::Malloc], add); + Platform::InterlockedIncrement(&GroupMemoryCount[(int32)Groups::Malloc]); UPDATE_PEEK(ProfilerMemory::Groups::Malloc); stack.SkipRecursion = false; @@ -453,16 +453,16 @@ void ProfilerMemory::OnMemoryFree(void* ptr) bool found = it.IsNotEnd(); if (found) ptrData = it->Value; - Pointers.Remove(it); - PointersLocker.Unlock(); + Pointers.Remove(it); + PointersLocker.Unlock(); if (found) { // Update group memory const int64 add = -(int64)ptrData.Size; SubGroupMemory((Groups)ptrData.Group, add); - Platform::InterlockedAdd(&GroupMemory[(int32)ProfilerMemory::Groups::Malloc], add); - Platform::InterlockedDecrement(&GroupMemoryCount[(int32)ProfilerMemory::Groups::Malloc]); + Platform::InterlockedAdd(&GroupMemory[(int32)Groups::Malloc], add); + Platform::InterlockedDecrement(&GroupMemoryCount[(int32)Groups::Malloc]); } stack.SkipRecursion = false; diff --git a/Source/Engine/Tests/TestMain.cpp b/Source/Engine/Tests/TestMain.cpp index 88db6144c..061f1343b 100644 --- a/Source/Engine/Tests/TestMain.cpp +++ b/Source/Engine/Tests/TestMain.cpp @@ -40,14 +40,14 @@ void TestsRunnerService::Update() return; // Runs tests - Log::Logger::WriteFloor(); + LOG_FLOOR(); LOG(Info, "Running Flax Tests..."); const int result = Catch::Session().run(); if (result == 0) LOG(Info, "Flax Tests result: {0}", result); else LOG(Error, "Flax Tests result: {0}", result); - Log::Logger::WriteFloor(); + LOG_FLOOR(); Engine::RequestExit(result); }