Fix editor hang on level load (#6323)
Make View::SortFinalizedDrawLists use child jobs so they don't block the worker thread from doing other work while waiting. Implement a TaskGraph version of the view draw list sort. Fix a misc bug where the scene was waiting on a task graph event twice and so hanging. Enable MeshFeatureProcessor::Simulate to be able to use jobs when no parent job is specified because the parent job is a task. Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <AzCore/Serialization/SerializeContext.h>
|
||||
#include <AzCore/Jobs/JobCompletion.h>
|
||||
#include <AzCore/Jobs/JobFunction.h>
|
||||
#include <AzCore/Task/TaskGraph.h>
|
||||
#include <Atom_RPI_Traits_Platform.h>
|
||||
|
||||
#if AZ_TRAIT_MASKED_OCCLUSION_CULLING_SUPPORTED
|
||||
@@ -253,14 +254,45 @@ namespace AZ
|
||||
return m_drawListContext.GetList(drawListTag);
|
||||
}
|
||||
|
||||
void View::FinalizeDrawLists()
|
||||
void View::FinalizeDrawListsTG(AZ::TaskGraphEvent& finalizeDrawListsTGEvent)
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "View: FinalizeDrawLists");
|
||||
m_drawListContext.FinalizeLists();
|
||||
SortFinalizedDrawLists();
|
||||
SortFinalizedDrawListsTG(finalizeDrawListsTGEvent);
|
||||
}
|
||||
void View::FinalizeDrawListsJob(AZ::Job* parentJob)
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "View: FinalizeDrawLists");
|
||||
m_drawListContext.FinalizeLists();
|
||||
SortFinalizedDrawListsJob(parentJob);
|
||||
}
|
||||
|
||||
void View::SortFinalizedDrawLists()
|
||||
void View::SortFinalizedDrawListsTG(AZ::TaskGraphEvent& finalizeDrawListsTGEvent)
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "View: SortFinalizedDrawLists");
|
||||
RHI::DrawListsByTag& drawListsByTag = m_drawListContext.GetMergedDrawListsByTag();
|
||||
|
||||
AZ::TaskGraph drawListSortTG;
|
||||
AZ::TaskDescriptor drawListSortTGDescriptor{"RPI_View_SortFinalizedDrawLists", "Graphics"};
|
||||
for (size_t idx = 0; idx < drawListsByTag.size(); ++idx)
|
||||
{
|
||||
if (drawListsByTag[idx].size() > 1)
|
||||
{
|
||||
drawListSortTG.AddTask(drawListSortTGDescriptor, [this, &drawListsByTag, idx]()
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "View: SortDrawList Task");
|
||||
SortDrawList(drawListsByTag[idx], RHI::DrawListTag(idx));
|
||||
});
|
||||
}
|
||||
}
|
||||
if (!drawListSortTG.IsEmpty())
|
||||
{
|
||||
drawListSortTG.Detach();
|
||||
drawListSortTG.Submit(&finalizeDrawListsTGEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void View::SortFinalizedDrawListsJob(AZ::Job* parentJob)
|
||||
{
|
||||
AZ_PROFILE_SCOPE(RPI, "View: SortFinalizedDrawLists");
|
||||
RHI::DrawListsByTag& drawListsByTag = m_drawListContext.GetMergedDrawListsByTag();
|
||||
@@ -276,11 +308,25 @@ namespace AZ
|
||||
SortDrawList(drawListsByTag[idx], RHI::DrawListTag(idx));
|
||||
};
|
||||
Job* jobSortDrawList = aznew JobFunction<decltype(jobLambda)>(jobLambda, true, nullptr); // Auto-deletes
|
||||
jobSortDrawList->SetDependent(&jobCompletion);
|
||||
jobSortDrawList->Start();
|
||||
if (parentJob)
|
||||
{
|
||||
parentJob->StartAsChild(jobSortDrawList);
|
||||
}
|
||||
else
|
||||
{
|
||||
jobSortDrawList->SetDependent(&jobCompletion);
|
||||
jobSortDrawList->Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
jobCompletion.StartAndWaitForCompletion();
|
||||
if (parentJob)
|
||||
{
|
||||
parentJob->WaitForChildren();
|
||||
}
|
||||
else
|
||||
{
|
||||
jobCompletion.StartAndWaitForCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
void View::SortDrawList(RHI::DrawList& drawList, RHI::DrawListTag tag)
|
||||
|
||||
Reference in New Issue
Block a user