convert atom to task graph (#4230)

* Intial attempt to convert the Atom/RHI/FrameScheduler to use the new TaskGraph api

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Avoid enqueuing work on the active task thread if the submitted task
graph is waitable

When submitting a task graph, supplying a wait event implies that
dependent jobs must occur on threads that do not wait on the event (in
the absence of work stealing). This change prevents this by adding a
notion of a task thread enable/disable state, and prohibiting dependent
jobs from being enqueued on waiting threads.

Signed-off-by: Jeremy Ong <jcong@amazon.com>

* Convert RPI/Scene to use TaskGraph pass 1, Culling jobs remain on the old system

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* RemoveTask Graph changes from the FrameScheduler::ExecuteGroups, use old job system instead

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Per review, removing commented out code

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Cleanup debug code, & build fix

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Add a cvar & interface to query whether to use jobs or task graph

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Make TaskGraph assert if you try to wait inside a job

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Fix TaskTest SpawnSubgraph to account for the new TaskGraphEvent assert on wait in a running task

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* 3 minor cleanups. 1) Events always store a ptr to their executor 2) Fix clang compile error 3) remove an early out.

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Fix double group end that was causing assert/crash plus misc minor diff's with development

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Fix deallocation failure on deactivation of the TaskGraphSystemComponent. Also make the system component account for multiple creation in Unit Tests.

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Update with PR feedback
1) Rename UseTaskGraph to IsTaskGraphActive & update related code
2) prefer TaskExecutor::SetInstance
3) add comments and remove commented out code

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Fix incorrect RTTI name for TaskGraphActiveInterface

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Move TaskGraphSystemComponent CRC calculation to a shared variable

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

Co-authored-by: Jeremy Ong <jcong@amazon.com>
This commit is contained in:
rgba16f [Amazon]
2021-09-30 17:45:33 -05:00
committed by GitHub
parent 60a0d2ba01
commit e1c49e436d
18 changed files with 652 additions and 130 deletions
@@ -29,6 +29,7 @@
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Script/ScriptTimePoint.h>
#include <AzCore/Task/TaskGraph.h>
#include <AzFramework/Scene/Scene.h>
#include <AzFramework/Scene/SceneSystemInterface.h>
@@ -194,6 +195,9 @@ namespace AZ
// This function is called every time scene's render pipelines change.
void RebuildPipelineStatesLookup();
// Helper function to wait for end of TaskGraph
void WaitTGEvent(AZ::TaskGraphEvent& completionTGEvent, AZStd::atomic_bool* workToWaitOn = nullptr);
// Helper function for wait and clean up a completion job
void WaitAndCleanCompletionJob(AZ::JobCompletion*& completionJob);
@@ -204,12 +208,26 @@ namespace AZ
// This happens in UpdateSrgs()
void PrepareSceneSrg();
// Implementation functions that allow scene to switch between using Jobs or TaskGraphs
void SimulateTaskGraph();
void SimulateJobs();
void CollectDrawPacketsTaskGraph();
void CollectDrawPacketsJobs();
void FinalizeDrawListsTaskGraph();
void FinalizeDrawListsJobs();
// List of feature processors that are active for this scene
AZStd::vector<FeatureProcessorPtr> m_featureProcessors;
// List of pipelines of this scene. Each pipeline has an unique pipeline Id.
AZStd::vector<RenderPipelinePtr> m_pipelines;
// CPU simulation TaskGraphEvent to wait for completion of all the simulation tasks
AZ::TaskGraphEvent m_simulationFinishedTGEvent;
AZStd::atomic_bool m_simulationFinishedWorkActive = false;
// CPU simulation job completion for track all feature processors' simulation jobs
AZ::JobCompletion* m_simulationCompletion = nullptr;
@@ -228,6 +246,7 @@ namespace AZ
SceneId m_id;
bool m_activated = false;
bool m_taskGraphActive = false; // update during tick, to ensure it only changes on frame boundaries
RenderPipelinePtr m_defaultPipeline;