Optimize multiple dispatches on JobSystem done via TaskGraph
This commit is contained in:
@@ -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 (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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user