Fix various code to improve quality
This commit is contained in:
@@ -56,6 +56,8 @@ API_ENUM() enum class LogType
|
|||||||
#define LOG_FLUSH() Log::Logger::Flush()
|
#define LOG_FLUSH() Log::Logger::Flush()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LOG_FLOOR() Log::Logger::WriteFloor()
|
||||||
|
|
||||||
extern const Char* ToString(LogType e);
|
extern const Char* ToString(LogType e);
|
||||||
|
|
||||||
namespace Log
|
namespace Log
|
||||||
@@ -191,8 +193,9 @@ namespace Log
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define LOG(messageType, format, ...)
|
#define LOG(messageType, format, ...) {}
|
||||||
#define LOG_STR(messageType, str)
|
#define LOG_STR(messageType, str) {}
|
||||||
#define LOG_FLUSH()
|
#define LOG_FLUSH() {}
|
||||||
|
#define LOG_FLOOR() {}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -170,10 +170,8 @@ int32 Engine::Main(const Char* cmdLine)
|
|||||||
#if !USE_EDITOR && (PLATFORM_WINDOWS || PLATFORM_LINUX || PLATFORM_MAC)
|
#if !USE_EDITOR && (PLATFORM_WINDOWS || PLATFORM_LINUX || PLATFORM_MAC)
|
||||||
EngineImpl::RunInBackground = PlatformSettings::Get()->RunInBackground;
|
EngineImpl::RunInBackground = PlatformSettings::Get()->RunInBackground;
|
||||||
#endif
|
#endif
|
||||||
#if LOG_ENABLE
|
LOG_FLOOR();
|
||||||
Log::Logger::WriteFloor();
|
|
||||||
LOG_FLUSH();
|
LOG_FLUSH();
|
||||||
#endif
|
|
||||||
Time::Synchronize();
|
Time::Synchronize();
|
||||||
EngineImpl::IsReady = true;
|
EngineImpl::IsReady = true;
|
||||||
PROFILE_MEM_END();
|
PROFILE_MEM_END();
|
||||||
@@ -557,6 +555,7 @@ void Engine::OnExit()
|
|||||||
#if COMPILE_WITH_PROFILER
|
#if COMPILE_WITH_PROFILER
|
||||||
ProfilerCPU::Dispose();
|
ProfilerCPU::Dispose();
|
||||||
ProfilerGPU::Dispose();
|
ProfilerGPU::Dispose();
|
||||||
|
ProfilerMemory::Enabled = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if LOG_ENABLE
|
#if LOG_ENABLE
|
||||||
|
|||||||
@@ -101,10 +101,8 @@ bool GraphicsService::Init()
|
|||||||
PROFILE_MEM(Graphics);
|
PROFILE_MEM(Graphics);
|
||||||
|
|
||||||
// Create and initialize graphics device
|
// Create and initialize graphics device
|
||||||
#if LOG_ENABLE
|
LOG_FLOOR();
|
||||||
Log::Logger::WriteFloor();
|
|
||||||
LOG(Info, "Creating Graphics Device...");
|
LOG(Info, "Creating Graphics Device...");
|
||||||
#endif
|
|
||||||
PixelFormatExtensions::Init();
|
PixelFormatExtensions::Init();
|
||||||
GPUDevice* device = nullptr;
|
GPUDevice* device = nullptr;
|
||||||
|
|
||||||
@@ -218,9 +216,7 @@ bool GraphicsService::Init()
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#if LOG_ENABLE
|
LOG_FLOOR();
|
||||||
Log::Logger::WriteFloor();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -765,7 +765,7 @@ void GPUDeviceDX11::DrawEnd()
|
|||||||
{
|
{
|
||||||
GPUDeviceDX::DrawEnd();
|
GPUDeviceDX::DrawEnd();
|
||||||
|
|
||||||
#if GPU_ENABLE_DIAGNOSTICS
|
#if GPU_ENABLE_DIAGNOSTICS && LOG_ENABLE
|
||||||
// Flush debug messages queue
|
// Flush debug messages queue
|
||||||
ComPtr<ID3D11InfoQueue> infoQueue;
|
ComPtr<ID3D11InfoQueue> infoQueue;
|
||||||
VALIDATE_DIRECTX_CALL(_device->QueryInterface(IID_PPV_ARGS(&infoQueue)));
|
VALIDATE_DIRECTX_CALL(_device->QueryInterface(IID_PPV_ARGS(&infoQueue)));
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
#include "Engine/Threading/Threading.h"
|
#include "Engine/Threading/Threading.h"
|
||||||
|
|
||||||
#define DX12_ENABLE_RESOURCE_BARRIERS_BATCHING 1
|
#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)
|
inline bool operator!=(const D3D12_VERTEX_BUFFER_VIEW& l, const D3D12_VERTEX_BUFFER_VIEW& r)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -387,10 +387,14 @@ void RenderToolsDX::LogD3DResult(HRESULT result, const char* file, uint32 line,
|
|||||||
if (removedReason == DXGI_ERROR_DEVICE_HUNG)
|
if (removedReason == DXGI_ERROR_DEVICE_HUNG)
|
||||||
errorType = FatalErrorType::GPUHang;
|
errorType = FatalErrorType::GPUHang;
|
||||||
}
|
}
|
||||||
|
else if (fatal)
|
||||||
|
errorType = FatalErrorType::Unknown;
|
||||||
if (errorType != FatalErrorType::None)
|
if (errorType != FatalErrorType::None)
|
||||||
Platform::Fatal(msg, nullptr, errorType);
|
Platform::Fatal(msg, nullptr, errorType);
|
||||||
|
#if LOG_ENABLE
|
||||||
else
|
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)
|
LPCSTR RenderToolsDX::GetVertexInputSemantic(VertexElement::Types type, UINT& semanticIndex)
|
||||||
|
|||||||
@@ -248,11 +248,13 @@ void RenderToolsVulkan::LogVkResult(VkResult result, const char* file, uint32 li
|
|||||||
errorType = FatalErrorType::GPUHang;
|
errorType = FatalErrorType::GPUHang;
|
||||||
else if (result == VK_ERROR_DEVICE_LOST || result == VK_ERROR_SURFACE_LOST_KHR || result == VK_ERROR_MEMORY_MAP_FAILED)
|
else if (result == VK_ERROR_DEVICE_LOST || result == VK_ERROR_SURFACE_LOST_KHR || result == VK_ERROR_MEMORY_MAP_FAILED)
|
||||||
errorType = FatalErrorType::GPUCrash;
|
errorType = FatalErrorType::GPUCrash;
|
||||||
|
else if (fatal)
|
||||||
|
errorType = FatalErrorType::Unknown;
|
||||||
if (errorType != FatalErrorType::None)
|
if (errorType != FatalErrorType::None)
|
||||||
Platform::Fatal(msg, nullptr, errorType);
|
Platform::Fatal(msg, nullptr, errorType);
|
||||||
#if LOG_ENABLE
|
#if LOG_ENABLE
|
||||||
else
|
else
|
||||||
Log::Logger::Write(fatal ? LogType::Fatal : LogType::Error, msg);
|
Log::Logger::Write(LogType::Error, msg);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
|||||||
{
|
{
|
||||||
// Log separation for crash info
|
// Log separation for crash info
|
||||||
LOG_FLUSH();
|
LOG_FLUSH();
|
||||||
Log::Logger::WriteFloor();
|
LOG_FLOOR();
|
||||||
LOG(Error, "");
|
LOG(Error, "");
|
||||||
LOG(Error, "Critical error! Reason: {0}", msg);
|
LOG(Error, "Critical error! Reason: {0}", msg);
|
||||||
LOG(Error, "");
|
LOG(Error, "");
|
||||||
@@ -400,12 +400,12 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
|||||||
|
|
||||||
// Capture the original log file
|
// Capture the original log file
|
||||||
LOG(Error, "");
|
LOG(Error, "");
|
||||||
Log::Logger::WriteFloor();
|
LOG_FLOOR();
|
||||||
LOG_FLUSH();
|
LOG_FLUSH();
|
||||||
FileSystem::CopyFile(crashDataFolder / TEXT("Log.txt"), Log::Logger::LogFilePath);
|
FileSystem::CopyFile(crashDataFolder / TEXT("Log.txt"), Log::Logger::LogFilePath);
|
||||||
|
|
||||||
LOG(Error, "Crash info collected.");
|
LOG(Error, "Crash info collected.");
|
||||||
Log::Logger::WriteFloor();
|
LOG_FLOOR();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -3029,8 +3029,10 @@ int32 LinuxPlatform::CreateProcess(CreateProcessSettings& settings)
|
|||||||
String line(lineBuffer);
|
String line(lineBuffer);
|
||||||
if (settings.SaveOutput)
|
if (settings.SaveOutput)
|
||||||
settings.Output.Add(line.Get(), line.Length());
|
settings.Output.Add(line.Get(), line.Length());
|
||||||
|
#if LOG_ENABLE
|
||||||
if (settings.LogOutput)
|
if (settings.LogOutput)
|
||||||
Log::Logger::Write(LogType::Info, line);
|
Log::Logger::Write(LogType::Info, line);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int stat_loc;
|
int stat_loc;
|
||||||
|
|||||||
@@ -485,15 +485,15 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
|
|||||||
String line((const char*)data.bytes, data.length);
|
String line((const char*)data.bytes, data.length);
|
||||||
if (settings.SaveOutput)
|
if (settings.SaveOutput)
|
||||||
settings.Output.Add(line.Get(), line.Length());
|
settings.Output.Add(line.Get(), line.Length());
|
||||||
|
#if LOG_ENABLE
|
||||||
if (settings.LogOutput)
|
if (settings.LogOutput)
|
||||||
{
|
{
|
||||||
StringView lineView(line);
|
StringView lineView(line);
|
||||||
if (line[line.Length() - 1] == '\n')
|
if (line[line.Length() - 1] == '\n')
|
||||||
lineView = StringView(line.Get(), line.Length() - 1);
|
lineView = StringView(line.Get(), line.Length() - 1);
|
||||||
#if LOG_ENABLE
|
|
||||||
Log::Logger::Write(LogType::Info, lineView);
|
Log::Logger::Write(LogType::Info, lineView);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
[[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
[[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,15 +514,15 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
|
|||||||
String line((const char*)data.bytes, data.length);
|
String line((const char*)data.bytes, data.length);
|
||||||
if (settings.SaveOutput)
|
if (settings.SaveOutput)
|
||||||
settings.Output.Add(line.Get(), line.Length());
|
settings.Output.Add(line.Get(), line.Length());
|
||||||
|
#if LOG_ENABLE
|
||||||
if (settings.LogOutput)
|
if (settings.LogOutput)
|
||||||
{
|
{
|
||||||
StringView lineView(line);
|
StringView lineView(line);
|
||||||
if (line[line.Length() - 1] == '\n')
|
if (line[line.Length() - 1] == '\n')
|
||||||
lineView = StringView(line.Get(), line.Length() - 1);
|
lineView = StringView(line.Get(), line.Length() - 1);
|
||||||
#if LOG_ENABLE
|
|
||||||
Log::Logger::Write(LogType::Error, lineView);
|
Log::Logger::Write(LogType::Error, lineView);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
[[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
[[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1054,8 +1054,10 @@ void ReadPipe(HANDLE pipe, Array<char>& rawData, Array<Char>& logData, LogType l
|
|||||||
int32 tmp;
|
int32 tmp;
|
||||||
StringUtils::ConvertANSI2UTF16(rawData.Get(), logData.Get(), rawData.Count(), tmp);
|
StringUtils::ConvertANSI2UTF16(rawData.Get(), logData.Get(), rawData.Count(), tmp);
|
||||||
logData.Last() = '\0';
|
logData.Last() = '\0';
|
||||||
|
#if LOG_ENABLE
|
||||||
if (settings.LogOutput)
|
if (settings.LogOutput)
|
||||||
Log::Logger::Write(logType, StringView(logData.Get(), rawData.Count()));
|
Log::Logger::Write(logType, StringView(logData.Get(), rawData.Count()));
|
||||||
|
#endif
|
||||||
if (settings.SaveOutput)
|
if (settings.SaveOutput)
|
||||||
settings.Output.Add(logData.Get(), rawData.Count());
|
settings.Output.Add(logData.Get(), rawData.Count());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -431,8 +431,8 @@ void ProfilerMemory::OnMemoryAlloc(void* ptr, uint64 size)
|
|||||||
// Update group memory
|
// Update group memory
|
||||||
const int64 add = (int64)size;
|
const int64 add = (int64)size;
|
||||||
AddGroupMemory((Groups)ptrData.Group, add);
|
AddGroupMemory((Groups)ptrData.Group, add);
|
||||||
Platform::InterlockedAdd(&GroupMemory[(int32)ProfilerMemory::Groups::Malloc], add);
|
Platform::InterlockedAdd(&GroupMemory[(int32)Groups::Malloc], add);
|
||||||
Platform::InterlockedIncrement(&GroupMemoryCount[(int32)ProfilerMemory::Groups::Malloc]);
|
Platform::InterlockedIncrement(&GroupMemoryCount[(int32)Groups::Malloc]);
|
||||||
UPDATE_PEEK(ProfilerMemory::Groups::Malloc);
|
UPDATE_PEEK(ProfilerMemory::Groups::Malloc);
|
||||||
|
|
||||||
stack.SkipRecursion = false;
|
stack.SkipRecursion = false;
|
||||||
@@ -461,8 +461,8 @@ void ProfilerMemory::OnMemoryFree(void* ptr)
|
|||||||
// Update group memory
|
// Update group memory
|
||||||
const int64 add = -(int64)ptrData.Size;
|
const int64 add = -(int64)ptrData.Size;
|
||||||
SubGroupMemory((Groups)ptrData.Group, add);
|
SubGroupMemory((Groups)ptrData.Group, add);
|
||||||
Platform::InterlockedAdd(&GroupMemory[(int32)ProfilerMemory::Groups::Malloc], add);
|
Platform::InterlockedAdd(&GroupMemory[(int32)Groups::Malloc], add);
|
||||||
Platform::InterlockedDecrement(&GroupMemoryCount[(int32)ProfilerMemory::Groups::Malloc]);
|
Platform::InterlockedDecrement(&GroupMemoryCount[(int32)Groups::Malloc]);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.SkipRecursion = false;
|
stack.SkipRecursion = false;
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ void TestsRunnerService::Update()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Runs tests
|
// Runs tests
|
||||||
Log::Logger::WriteFloor();
|
LOG_FLOOR();
|
||||||
LOG(Info, "Running Flax Tests...");
|
LOG(Info, "Running Flax Tests...");
|
||||||
const int result = Catch::Session().run();
|
const int result = Catch::Session().run();
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
LOG(Info, "Flax Tests result: {0}", result);
|
LOG(Info, "Flax Tests result: {0}", result);
|
||||||
else
|
else
|
||||||
LOG(Error, "Flax Tests result: {0}", result);
|
LOG(Error, "Flax Tests result: {0}", result);
|
||||||
Log::Logger::WriteFloor();
|
LOG_FLOOR();
|
||||||
Engine::RequestExit(result);
|
Engine::RequestExit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user