Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -29,6 +29,28 @@
|
||||
const Char* WindowsPlatform::ApplicationWindowClass = TEXT("FlaxWindow");
|
||||
void* WindowsPlatform::Instance = nullptr;
|
||||
|
||||
#if CRASH_LOG_ENABLE || TRACY_ENABLE
|
||||
// Lock for symbols list, shared with Tracy
|
||||
extern "C" {
|
||||
static HANDLE dbgHelpLock;
|
||||
|
||||
void DbgHelpInit()
|
||||
{
|
||||
dbgHelpLock = CreateMutexW(nullptr, FALSE, nullptr);
|
||||
}
|
||||
|
||||
void DbgHelpLock()
|
||||
{
|
||||
WaitForSingleObject(dbgHelpLock, INFINITE);
|
||||
}
|
||||
|
||||
void DbgHelpUnlock()
|
||||
{
|
||||
ReleaseMutex(dbgHelpLock);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
String UserLocale, ComputerName, UserName, WindowsName;
|
||||
@@ -39,7 +61,6 @@ namespace
|
||||
int32 VersionBuild = 0;
|
||||
int32 SystemDpi = 96;
|
||||
#if CRASH_LOG_ENABLE
|
||||
CriticalSection SymLocker;
|
||||
#if TRACY_ENABLE
|
||||
bool SymInitialized = true;
|
||||
#else
|
||||
@@ -501,7 +522,7 @@ void WindowsPlatform::PreInit(void* hInstance)
|
||||
|
||||
#if CRASH_LOG_ENABLE
|
||||
TCHAR buffer[MAX_PATH] = { 0 };
|
||||
SymLocker.Lock();
|
||||
DbgHelpLock();
|
||||
if (::GetModuleFileNameW(::GetModuleHandleW(nullptr), buffer, MAX_PATH))
|
||||
SymbolsPath.Add(StringUtils::GetDirectoryName(buffer));
|
||||
if (::GetEnvironmentVariableW(TEXT("_NT_SYMBOL_PATH"), buffer, MAX_PATH))
|
||||
@@ -510,7 +531,7 @@ void WindowsPlatform::PreInit(void* hInstance)
|
||||
options |= SYMOPT_LOAD_LINES | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS;
|
||||
SymSetOptions(options);
|
||||
OnSymbolsPathModified();
|
||||
SymLocker.Unlock();
|
||||
DbgHelpUnlock();
|
||||
#endif
|
||||
|
||||
GetWindowsVersion(WindowsName, VersionMajor, VersionMinor, VersionBuild);
|
||||
@@ -654,7 +675,7 @@ void WindowsPlatform::BeforeExit()
|
||||
void WindowsPlatform::Exit()
|
||||
{
|
||||
#if CRASH_LOG_ENABLE
|
||||
SymLocker.Lock();
|
||||
DbgHelpLock();
|
||||
#if !TRACY_ENABLE
|
||||
if (SymInitialized)
|
||||
{
|
||||
@@ -663,7 +684,7 @@ void WindowsPlatform::Exit()
|
||||
}
|
||||
#endif
|
||||
SymbolsPath.Resize(0);
|
||||
SymLocker.Unlock();
|
||||
DbgHelpUnlock();
|
||||
#endif
|
||||
|
||||
// Unregister app class
|
||||
@@ -1170,13 +1191,13 @@ void* WindowsPlatform::LoadLibrary(const Char* filename)
|
||||
|
||||
#if CRASH_LOG_ENABLE
|
||||
// Refresh modules info during next stack trace collecting to have valid debug symbols information
|
||||
SymLocker.Lock();
|
||||
DbgHelpLock();
|
||||
if (folder.HasChars() && !SymbolsPath.Contains(folder))
|
||||
{
|
||||
SymbolsPath.Add(folder);
|
||||
OnSymbolsPathModified();
|
||||
}
|
||||
SymLocker.Unlock();
|
||||
DbgHelpUnlock();
|
||||
#endif
|
||||
|
||||
return handle;
|
||||
@@ -1186,7 +1207,7 @@ Array<PlatformBase::StackFrame> WindowsPlatform::GetStackFrames(int32 skipCount,
|
||||
{
|
||||
Array<StackFrame> result;
|
||||
#if CRASH_LOG_ENABLE
|
||||
SymLocker.Lock();
|
||||
DbgHelpLock();
|
||||
|
||||
// Initialize
|
||||
HANDLE process = GetCurrentProcess();
|
||||
@@ -1310,7 +1331,7 @@ Array<PlatformBase::StackFrame> WindowsPlatform::GetStackFrames(int32 skipCount,
|
||||
}
|
||||
}
|
||||
|
||||
SymLocker.Unlock();
|
||||
DbgHelpUnlock();
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace
|
||||
JobSystemService JobSystemInstance;
|
||||
Thread* Threads[32] = {};
|
||||
int32 ThreadsCount = 0;
|
||||
bool JobStartingOnDispatch = true;
|
||||
volatile int64 ExitFlag = 0;
|
||||
volatile int64 DoneLabel = 0;
|
||||
volatile int64 NextLabel = 0;
|
||||
@@ -234,10 +235,13 @@ int64 JobSystem::Dispatch(const Function<void(int32)>& job, int32 jobCount)
|
||||
LOG(Info, "Job enqueue time: {0} cycles", (int64)(Platform::GetTimeCycles() - start));
|
||||
#endif
|
||||
|
||||
if (jobCount == 1)
|
||||
JobsSignal.NotifyOne();
|
||||
else
|
||||
JobsSignal.NotifyAll();
|
||||
if (JobStartingOnDispatch)
|
||||
{
|
||||
if (jobCount == 1)
|
||||
JobsSignal.NotifyOne();
|
||||
else
|
||||
JobsSignal.NotifyAll();
|
||||
}
|
||||
|
||||
return label;
|
||||
#else
|
||||
@@ -278,3 +282,21 @@ void JobSystem::Wait(int64 label)
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void JobSystem::SetJobStartingOnDispatch(bool value)
|
||||
{
|
||||
#if JOB_SYSTEM_ENABLED
|
||||
JobStartingOnDispatch = value;
|
||||
|
||||
if (value)
|
||||
{
|
||||
JobsLocker.Lock();
|
||||
const int32 count = Jobs.Count();
|
||||
JobsLocker.Unlock();
|
||||
if (count == 1)
|
||||
JobsSignal.NotifyOne();
|
||||
else if (count != 0)
|
||||
JobsSignal.NotifyAll();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -29,4 +29,9 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(JobSystem);
|
||||
/// </summary>
|
||||
/// <param name="label">The label.</param>
|
||||
API_FUNCTION() static void Wait(int64 label);
|
||||
|
||||
/// <summary>
|
||||
/// Sets whether automatically start jobs execution on Dispatch. If disabled jobs won't be executed until it gets re-enabled. Can be used to optimize execution of multiple dispatches that should overlap.
|
||||
/// </summary>
|
||||
API_FUNCTION() static void SetJobStartingOnDispatch(bool value);
|
||||
};
|
||||
|
||||
@@ -94,6 +94,7 @@ void TaskGraph::Execute()
|
||||
|
||||
// Execute in order
|
||||
Sorting::QuickSort(_queue.Get(), _queue.Count(), &SortTaskGraphSystem);
|
||||
JobSystem::SetJobStartingOnDispatch(false);
|
||||
_currentLabel = 0;
|
||||
for (int32 i = 0; i < _queue.Count(); i++)
|
||||
{
|
||||
@@ -104,6 +105,7 @@ void TaskGraph::Execute()
|
||||
_queue.Clear();
|
||||
|
||||
// Wait for async jobs to finish
|
||||
JobSystem::SetJobStartingOnDispatch(true);
|
||||
JobSystem::Wait(_currentLabel);
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -33,6 +33,8 @@ public class tracy : ThirdPartyModule
|
||||
options.SourceFiles.Add(Path.Combine(FolderPath, "TracyClient.cpp"));
|
||||
|
||||
options.PublicDefinitions.Add("TRACY_ENABLE");
|
||||
if (options.Platform.Target == TargetPlatform.Windows)
|
||||
options.PrivateDefinitions.Add("TRACY_DBGHELP_LOCK=DbgHelp");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user