Fix various code to improve quality

This commit is contained in:
Wojtek Figat
2025-06-06 11:19:32 +02:00
parent 0670c0bbd3
commit 9d8e75caa3
13 changed files with 43 additions and 35 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -765,7 +765,7 @@ void GPUDeviceDX11::DrawEnd()
{
GPUDeviceDX::DrawEnd();
#if GPU_ENABLE_DIAGNOSTICS
#if GPU_ENABLE_DIAGNOSTICS && LOG_ENABLE
// Flush debug messages queue
ComPtr<ID3D11InfoQueue> infoQueue;
VALIDATE_DIRECTX_CALL(_device->QueryInterface(IID_PPV_ARGS(&infoQueue)));

View File

@@ -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)
{

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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];
}
}

View File

@@ -1054,8 +1054,10 @@ void ReadPipe(HANDLE pipe, Array<char>& rawData, Array<Char>& 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());
}

View File

@@ -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<void*, PointerData>::Bucket);
Pointers.Capacity() * sizeof(Dictionary<void*, PointerData>::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;

View File

@@ -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);
}